Sign in to follow this  
Farraj

Online game loop

Recommended Posts

Farraj    152
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
Wavesonics    330
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
Farraj    152
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
Kada2k6    108
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

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