Jump to content
  • Advertisement
Sign in to follow this  
Farraj

Online game loop

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

I don’t know if this topic belongs here or in the multiplayer’s forum. I kept searching for a while on how a client’s and server’s game loop looks like in an MO game. I couldn’t find much in the design it self. Put in mind that I only want to know the game loop for both client and server. Assume that the client already connected to the server and ‘handshake’ed and everything. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The loop it's self should look pretty darn normal.

Network I/O could be read each pass through the loop and update the world accordingly. But this could come w\ some issues if the loop slowed down.

So really the actual Network I/O code should probably run in it's own thread, and either post updates to the world state on a que which the main game thread will read during it's game loop, or update the world asynchronously. That can be very dangerous.

Hope that helps.

Share this post


Link to post
Share on other sites
Well, thanks but, I sorta know that. I was hopping for more details on the matter. Like how to account for the "issues" you were talking about.

I have a simple uderstanding on how they work and made. I just don't know the problems that come with them and how to deal with them.

I was hopping a game loop design of a client/server would show me how it's done.

Anyone else??

Share this post


Link to post
Share on other sites
Hidden
Well, what are the "problems"? In order to present a solution to you, you must first explain the problem. :-)

This is how my loops look like, nothing fancy really:


//server
while (program_running) {
gettimeofday(&time_start, NULL);

/* make sure it always runs at 60 "fps" */
tick_timer += scale_rate;
if (tick_timer >= 60) {
DoTick();
tick_timer = tick_timer - 60;
}

HandleDisconnects();
CheckSockets();
ReadBufferedPackets();
DoRespawns();
DoSpells();
DoFights();
DoCharacterMovement();
DoMobAI();
SendBufferedPackets();

usleep(1000);
gettimeofday(&time_end, NULL);
ms_start = (double)time_start.tv_sec + (double)time_start.tv_usec / 1000000;
ms_end = (double)time_end.tv_sec + (double)time_end.tv_usec / 1000000;
scale_rate = ((ms_end - ms_start) * 1000) / (1000 / FRAMES_PER_SECOND);
}




//client

while (program_running) {
ClearScreen();
ReadServerSocket();
ReadBufferedPackets();
RedrawWindows();
ReadInput();
GUIReadInput();
DoCharacterMovement();
DoSpellCooldown();
FocusCamera();
DoLighting();
DoTileAnimation();
DrawMap();
DrawWater();
DrawRadiation();
DoParticleEffects(0);
DrawObjectsOnGround();
DrawFakeShadows();
DrawLightmaps(0);
DrawCharactersInRoom();
DoParticleEffects(1);
DrawLightmaps(1);
DrawCharacterNames();
DrawGroundObjectNames();
DrawDialogueBubbles();
DrawMessages();
DrawStatusMeter();
DrawGUI();
DrawMouseCursor();
SendBufferedPackets();
Render();
CountFPS();
}

Share this post


Link to post
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!