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.

Messages - enigma22134

Pages: [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. :)

Correct,  4.9.2 and 4.9.3; I was in a bit of a rush yesterday. :)

I suppose I will be learning cmake over the next few days. I had a feeling I would eventually need to learn how to use this; I just wasn't wanting to postpone work on my project. Oh well, thanks for the responses guys. :)

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?


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

Network / Re: Advice for TCP sending?
« on: June 11, 2016, 01:12:13 am »
eXpl0it3r's understanding of my issue is correct. What I'm thinking about doing is moving most of my game-related data to being transferred over UDP. I will only use TCP for pinging.

Here's how I'm thinking of doing it,

I will have the server check (wait) for a ping packet every X seconds from a TCP socket; thus not needing to do a blocking send. If it doesn't arrive, it will tally a missed ping. At some threshold (say, maybe 10 missed pings) it will prompt to disconnect the client and make that socket available for another player to join.

So, as to my problem with blocking. I think I will continue to use a timeout(polling) on the server end; however, I will make the socket non-blocking on the client's end. That way the client doesn't freeze when it attempts to send the TCP ping packet to a dead server. I guess I will have to learn how to handle partial packets.

I wonder, is it a bad idea to expect a UDP packet from the clients every server cycle? With some packets lost occasionally, of course. There would probably be 30-60 cycles per second. I'm thinking of sending nearly blank packets if there is no useful data to send, but I have no idea if this will interfere with other networking on the computer.

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.
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. :)

Unless you use the same exact compiler which has been used to create the SFML binaries, you'll have to recompile.

The setup should similar to Code::Blocks or most other IDE. Specify the include dir, specify the lib dir, add the required libs, compile, link and run (and for dynamic linking copy the DLLs next to the exe).
I got it compiling and I am able to run the executable with the above setup. :) I guess I lucked out on the compiler version.

However, for some reason, I cannot access the network library; it's probably an error on my part.

Just compile sfml yourself and you should be good to go.
Is there a tutorial or documentation on how to do this? I see the tutorial for compiling SFML with CMake http://www.sfml-dev.org/tutorials/2.3/compile-with-cmake.php. Admittedly, I am relatively new to programming (3 years self taught experience, 4 months of class); so, I'm not sure if that is how I go about compiling SFML myself. 

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. |)


OS: windows 7 64bit
SFML: 2.3 32bit

I'm currently using windows with eclipse. Though, I am hoping that I can have my project run on all platforms. Setting up a new linux system is on my todo list for this break. :)

Thanks again. :)

That's definitely understandable. I'm not really familiar with the details with using c++ and java together, so I cannot pretend to know the complexities of what you're describing. Do you think sometime after new years you will be able to investigate the bug? And perhaps create a fix? Hopefully it is isn't too large of an issue?

I know you're probably extremely busy with life. My university uses java as its main teaching language, hence the reason I switched from using c++ to using this library in java. Let me know if you think this is something that might be fixed in the somewhat near future. :)

There is a pattern I've identified. It returns NaN when the mouse is to the left of the sprite (position 0,0). That is, when the returned x falls below 0 (negative), it returns NaN for the Y value (suprisingly, not the x value). Here's my console output (code is in previous message).

Below results from dragging the mouse from the right to the left.

x: 560 y: 125 relX: 160.0  relY -175.0
x: 504 y: 125 relX: 104.0  relY -175.0
x: 455 y: 122 relX: 55.0    relY -177.99998
x: 413 y: 119 relX: 13.0    relY -181.0
x: 413 y: 119 relX: 13.0    relY -181.0
x: 354 y: 112 relX: -46.0   relY NaN
x: 259 y: 101 relX: -141.0 relY NaN
x: 193 y: 91   relX: -207.0 relY NaN
x: 193 y: 91   relX: -207.0 relY NaN
x: 123 y: 84   relX: -277.0 relY NaN

relX and relY are the values returned by the mapPixelToCoords

The function seems to be limited only to x coordinates above 0; i.e. when the method returns negative x values, it corrupts the returned y value and y become NaN. restated:it cannot return number y values when returned x is 0 or lower.

This happens when the mouse is in the left portion of the screen.However, If I move the sprite(and the view) to the right far enough, I can get the function to work flawlessly; it works because all x values are positive. It as if there is an imaginary boundary for anything less than the x-value of  0.

For a bit, I thought this might be due using the View class and not passing it in as a parameter (for an overloaded version of the mapPixelToCoords that accepts (RenderWindow, const View). But I disabled my view and it did not fix the problem. I also tried passing in my view object using the overloaded function and could not get it to work.

Here's a video of what is happening (had to use my phone on this computer, sorry).
I have the sprite being rotated using the value returned from mapPixelToCoords. When it is NaN the sprite disappears (I guess because the rotation value is not possible).
Thanks so much for your help!

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 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.

Thanks for all the replies, they really helped! For now, I'm going to try and limit the frame rate. That seems like the quick fix, but I will probably have to get a bit more into it later. 

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]