Sign in to follow this  

UDP - Client and Server only update when I move mouse

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I am diving into networked multiplayer and am simply trying to get what the server does to show on the client. This sort of works but only when I move my mouse as I play....

 

The idea is I just send the servers gamestate over the network every frame at a fixed timestep at 60fps. I have my code uploaded to my github. Run the game first with the command "server" to start as a server then "client" to start it as a client. To build just run build.bat. It should build if you have VS 2015 community.

 

https://github.com/mojobojo/BrickBreaker/tree/master/src

 

Executable can be found here

https://github.com/mojobojo/BrickBreaker/tree/master/build

 

https://youtu.be/TQgIQyHlefM

Edited by mojobojo

Share this post


Link to post
Share on other sites

I believe that it has to do with the way that SDL polls events. It may be blocking the rest of the application at this while loop until an event is polled. That is why when you move your mouse it sends the data. I see that you're still learning the ropes of networking, but you'll soon learn that you'll want to separate the networking logic from the application logic by placing the network logic in a separate thread. This is what I would recommend. Create a new thread and have all of the network logic run within that thread. This would solve your problem.

Share this post


Link to post
Share on other sites

I believe that it has to do with the way that SDL polls events. It may be blocking the rest of the application at this while loop until an event is polled. That is why when you move your mouse it sends the data. I see that you're still learning the ropes of networking, but you'll soon learn that you'll want to separate the networking logic from the application logic by placing the network logic in a separate thread. This is what I would recommend. Create a new thread and have all of the network logic run within that thread. This would solve your problem.

I had suspected mutlithreading could have fixed that. It seemed odd to me that the game wasn't effected by the polling of events until I added the networking. I will add some multithreading and see how that goes.

Share this post


Link to post
Share on other sites

 

I believe that it has to do with the way that SDL polls events. It may be blocking the rest of the application at this while loop until an event is polled. That is why when you move your mouse it sends the data. I see that you're still learning the ropes of networking, but you'll soon learn that you'll want to separate the networking logic from the application logic by placing the network logic in a separate thread. This is what I would recommend. Create a new thread and have all of the network logic run within that thread. This would solve your problem.

I had suspected mutlithreading could have fixed that. It seemed odd to me that the game wasn't effected by the polling of events until I added the networking. I will add some multithreading and see how that goes.

 

 

Great. Let me know how it goes! It should fix your problem.

Share this post


Link to post
Share on other sites

 

 

I believe that it has to do with the way that SDL polls events. It may be blocking the rest of the application at this while loop until an event is polled. That is why when you move your mouse it sends the data. I see that you're still learning the ropes of networking, but you'll soon learn that you'll want to separate the networking logic from the application logic by placing the network logic in a separate thread. This is what I would recommend. Create a new thread and have all of the network logic run within that thread. This would solve your problem.

I had suspected mutlithreading could have fixed that. It seemed odd to me that the game wasn't effected by the polling of events until I added the networking. I will add some multithreading and see how that goes.

 

 

Great. Let me know how it goes! It should fix your problem.

 

 

It worked great. The server is sending the client the information pretty good, a little bit of choppyness (something I assume I have to compensate for with interpolation) I can tell but overall threading fixed the issue.

 

Changes can be found here.

https://github.com/mojobojo/BrickBreaker/commit/5bf00ed22a49b5a788d828d5ce9e2e828ba1afd9

 

https://youtu.be/8_aqj4Ncjfk

Edited by mojobojo

Share this post


Link to post
Share on other sites

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this