Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - enigma22134

Pages: [1]
1
Network / Extracting polymoprhic object from packet.
« on: August 02, 2016, 08:49:29 pm »
I'm overloading the packet class and running into a bit of an issue.
I have an Actor class that many classes will inherit from; e.g. player class and enemy class.

I would like to extract a generic Actor class from a packet.

packet >> actorObject;

However, if the object is a derived class, then I believe it will be truncated (or crash?) if it is assigned to a super class object.

What I would like to do is get a pointer to what is to be extracted, and do a dynamic cast to check the type of object;

Actor* temporary = &(packet >> ? ? ? ? )
derived* casted = dynamic_cast<derived>(temporary)
if(derived != nullptr){
//do stuff
}


The problem is, I'm not sure how I can do this without knowing the type of the object before extracting it from the packet. I could solve this problem by extracting a flag value first, but then I would need if statments for every type of object.

Does anyone have any input?

Thanks. :)

2
Hey guys, I've gotten a new computer and I'm trying to set it up so that I can continue my old projects.

I've got mingw setup through the MinGw installer, but it is  4.9.3, not  4.9.2.

I've setup an eclipse cdt project and I got the basic circle drawing working fine! But I am wondering if it is dangerous to continue using this version (4.9.3) without rebuilding sfml?

http://www.sfml-dev.org/download/sfml/2.3.2/ says the versions must match 100%, but I was hoping that was typed when  4.9.2 was the latest DW2 version.

I tried getting  4.9.2 setup, but the only problem is I continually fail to get eclipse to see 4.9.2 when I try installing it from the link on the download page (I attempted to setup path variables, but I'm not sure what's up).

Anyways, I don't know how to compile SFML myself, so I was wondering if I should be able to use this newer version of MinGw with the libraries provided for  4.9.2?

Thanks!

edit: changed 1.9.2 and 1.9.3 to 4.9.2 and 4.9.3 respectively.

3
Network / Advice for TCP sending?
« on: June 08, 2016, 05:53:55 am »
Hey guys, I'm attempting to write a basic TCP networking class. Currently, I have a server that allows 8 clients to connect and packets can be exchanged between the server and its clients.

 I have no experience with networking, but my approach is:
1) loop through all connected clients and request data (socket.receive())
2) process the data and determine what data should be sent out
3) send (socket.send()) an identical packet to all clients for updating the clients data.
4) repeat

I've implemented a method using a socket selector that times out the TcpSocket's receive method; my idea is that to design my packets so that if one is late, the packet following it will be sufficient to bring the program up to speed.

Anyways, I'm wondering what to do about sending. I cannot create a similar timeout method using socket selectors for the TcpSocket's send. I looked at the API and I am a little bit unsure how send behaves when the recipient doesn't respond.
http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1TcpSocket.php#a0f8276e2b1c75aac4a7b0a707b250f44
Does it wait (block) until the recipient finally signals that that packet was received? What I would like to do is attempt to send a packet for X amount of time, if the send wasn't successful in that time, then the program would continue onward. Unfortunately, I'm not seeing a way to do this with TCP.

I do not want to set the send to non-blocking, because I am worried that a lag in the network would allow data to backup on one end of the network due to multiple attempts to send before the previous sends are complete.

It looks like I may have to switch to UDP, but I was hoping someone may have some ideas/knowledge.

Either way, thanks a bunch for reading. :)

4
General / Is it possible to use SFML with Eclipse CDT using MinGW (DW2)?
« on: December 28, 2015, 05:01:56 pm »
I've setup the eclipse CDT "C/C++ programming tooling" with MinGW to build c++ . I really like my custom ui setup with eclipse I was wondering if I could potentially setup SFML to work with this setup?

There's a Code::Blocks using MinGW tutorial; I was wondering if I should be able to setup SFML with my eclipse setup since the compiler is the same as Code::Blocks. Does anyone have any insight on this? The options are slightly different in the compiler settings, but I think it could work?

I've already made some attempts at getting it to work (as you can see in my pictures), but I figured I should first inquire if this is even a reasonable pursuit before I continue.

 I'm in university and still a bit of a newbie to advance computer programming and I don't yet have a deep understanding of the underlying structure (linker, etc.) behind c/c++ development.

Attached/linked are screenshots of the options I can access in MinGW through eclipse. Thank you for any insight. |)

http://i.imgur.com/sWuz2Eh.png
http://i.imgur.com/AEO4Kac.png


OS: windows 7 64bit
SFML: 2.3 32bit

5
When I make a call to mapPixelToCoords(), it functions as needed in about 70% of screen.

Here's what I am trying to do:

Use the mouse position to rotate a sprite so that it faces the mouse. I've got this to work with 100% success using the c++ sfml.

Here's my problem:

In certain positions, the function returns a NaN for the y component(float2f). I have narrowed the problem down to this function.

Here's the method's code

   public void rotateToMouse(RenderWindow window){
      mousePosWin = Mouse.getPosition(window);
      mousePos = window.mapPixelToCoords(mousePosWin);
      System.out.println("x: "+ mousePosWin.x + " y: " + mousePosWin.y + " relX: "+ mousePos.x + " relY " + mousePos.y);;
      
      actorPos = actorSprite.getPosition();
      relativeActToMouse = new Vector2f(mousePos.x - actorPos.x, mousePos.y -actorPos.y);
      playerRotation = Math.atan((double)relativeActToMouse.x/relativeActToMouse.y)*(180/3.141);
      actorSprite.setRotation((float)playerRotation);
   }
actorSprite is an instance of jsfml sprite class.

Here's an the console output when the problem is occuring:
x: 363 y: 352 relX: -37.0 relY NaN
x: 363 y: 352 relX: -37.0 relY NaN
x: 359 y: 352 relX: -41.0 relY NaN
x: 356 y: 352 relX: -44.0 relY NaN
x: 356 y: 352 relX: -44.0 relY NaN

x and y are the mouse's pixel position (i.e. where it is on the computer screen)
relX and relY are the x and y (float2f) for the mouse AFTER I have called mapPixelToCoords(RenderWindow window)[/glow]

As you can see, for some reason this results in NaN. I have no idea why. it does not always do this either.

6
Hey guys,

When I resize my window to full screen, my game runs a bit slower.


That's fine, but I was wondering if there was any way to cap the speed my game runs at a minimized screen so that it will not be faster than it running as a full screen.

I thought about putting a pause-like statement in my game loop, but I wonder if there was a better way to do this?


Pages: [1]