Advertisement

UDP - Client and Server only update when I move mouse

Started by February 16, 2016 06:52 AM
3 comments, last by mojobojo 8 years, 9 months ago

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

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.

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.

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.

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.

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

This topic is closed to new replies.

Advertisement