Jump to content
  • Advertisement
Sign in to follow this  
mojobojo

UDP - Client and Server only update when I move mouse

This topic is 881 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

 

Edited by mojobojo

Share this post


Link to post
Share on other sites
Advertisement

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

 

Edited by mojobojo

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!