Skip to content

Commit

Permalink
Further improvements and cleanup in frametime syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 6, 2004
1 parent a730afe commit e5eee52
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 287 deletions.
1 change: 1 addition & 0 deletions doomsday/Include/r_main.h
Expand Up @@ -52,5 +52,6 @@ void R_Shutdown(void);
void R_RenderPlayerView(ddplayer_t *player);
void R_ResetViewer(void);
void R_ViewWindow(int x, int y, int w, int h);
void R_NewSharpWorld(void);

#endif
123 changes: 15 additions & 108 deletions doomsday/Src/dd_loop.c
Expand Up @@ -63,7 +63,6 @@ void DD_RunTics(void);
// PUBLIC DATA DEFINITIONS -------------------------------------------------

int maxFrameRate = 200; // Zero means 'unlimited'.
int numSharpTics;

timespan_t sysTime, gameTime, demoTime, levelTime;
timespan_t frameStartTime;
Expand Down Expand Up @@ -232,6 +231,7 @@ float DD_GetFrameRate(void)
void DD_Ticker(timespan_t time)
{
static trigger_t fixed = { 1 / 35.0 };
static float realFrameTimePos = 0;

// Demo ticker. Does stuff like smoothing of view angles.
Net_BuildLocalCommands(time);
Expand All @@ -240,11 +240,13 @@ void DD_Ticker(timespan_t time)

if(!ui_active || netgame)
{
// Advance frametime. It will be reduced when new sharp world
// positions are calculated, so that frametime always stays within
// the range 0..1.
realFrameTimePos += time * TICSPERSEC;

if(M_CheckTrigger(&fixed, time))
{
extern int sharpWorldUpdated; // in r_main.c
extern double lastSharpFrameTime;

gx.Ticker( /* time */ ); // Game DLL.

// Server ticks. These are placed here because
Expand All @@ -258,22 +260,23 @@ void DD_Ticker(timespan_t time)
// This is needed by rend_camera_smooth. It needs to know
// when the world tic has occured so the next sharp
// position can be processed.
sharpWorldUpdated = true;
lastSharpFrameTime = Sys_GetTimef();

numSharpTics++;
// Frametime will be set back by one tick.
realFrameTimePos -= 1;

R_NewSharpWorld();
}

// While paused, don't modify frametime so things keep still.
if(!clientPaused)
frameTimePos = realFrameTimePos;

Con_Ticker(time); // Console.

// We can't sent FixAngles messages to ourselves, so it's
// done here.
Sv_FixLocalAngles();
}
else
{
resyncFrameTimePos = true;
}

if(ui_active)
{
Expand All @@ -287,23 +290,18 @@ void DD_Ticker(timespan_t time)
*/
void DD_AdvanceTime(timespan_t time)
{
//systics++;
sysTime += time;

if(!ui_active || netgame)
{
//if(availabletics > 0) availabletics--;

// The difference between gametic and demotic is that demotic
// is not altered at any point. Gametic changes at handshakes.
/*gametic++;
demotic++; */
gameTime += time;
demoTime += time;

// Leveltic is reset to zero at every map change.
// The level time only advances when the game is not paused.
if(!clientPaused) /*leveltic++; */
if(!clientPaused)
{
levelTime += time;
}
Expand All @@ -319,7 +317,6 @@ static boolean firstTic = true;
void DD_ResetTimer(void)
{
firstTic = true;
resyncFrameTimePos = true;
Net_ResetTimer();
}

Expand Down Expand Up @@ -378,94 +375,4 @@ void DD_RunTics(void)
// Various global variables are used for counting time.
DD_AdvanceTime(ticLength);
}

// Do one final network update. (Network needs its own thread...)
Net_Update();
}

#if 0
//===========================================================================
// DD_TryRunTics
// Run at least one tic.
//===========================================================================
void DD_TryRunTics(void)
{
int counts;

// Low-level network update.
N_Update();

// High-level network update.
Net_Update();

// Wait for at least one tic. (realtics >= availabletics)
while(!
(counts =
(isDedicated || netgame || ui_active ? realtics : availabletics)))
{
if((!isDedicated && rend_camera_smooth) || net_dontsleep ||
!net_ticsync)
break;
Sys_Sleep(3);
Net_Update();
}

// If we are running in timedemo mode, always run only one tic.
if(!net_ticsync)
counts = 1;

// We'll tick away all the tics we can.
// Zero the real tics counter.
realtics = 0;

// Run the tics.
while(counts--)
{
// Client/server ticks.
if(isClient)
Cl_Ticker();
else
Sv_Ticker();

// Demo ticker. Does stuff like smoothing of view angles.
Demo_Ticker();
P_Ticker();

if(!ui_active || netgame)
{
gx.Ticker(); // Game DLL.
Con_Ticker(); // Console.
// We can't sent FixAngles messages to ourselves, so it's
// done here.
Sv_FixLocalAngles();
}
if(ui_active)
{
// User interface ticks.
UI_Ticker();
}
// The netcode gets to tick.
Net_Ticker();
Net_Update();

// This tick is done, advance time.
systics++;
if(!ui_active || netgame)
{
if(availabletics > 0)
availabletics--;

// The difference between gametic and demotic is that demotic
// is not altered at any point. Gametic changes at handshakes.
gametic++;
demotic++;

// Leveltic is reset to zero at every map change.
// The level time only advances when the game is not paused.
if(!clientPaused)
leveltic++;
}
}
}

#endif
29 changes: 2 additions & 27 deletions doomsday/Src/net_main.c
Expand Up @@ -221,18 +221,6 @@ boolean Net_GetPacket(void)
return true;
}

/*boolean Net_GetLatestFramePacket(void)
{
if(!isClient || !latest_frame_size) return false;
// Place the latest frame packet to the netBuffer.
memcpy(&netBuffer.msg, &latest_frame_packet, latest_frame_size);
netBuffer.cursor = netBuffer.msg.data;
netBuffer.length = latest_frame_size - netBuffer.headerLength;
// Clear the buffer.
latest_frame_size = 0;
return true;
} */

//===========================================================================
// Net_SendPacket
// This is the public interface of the message sender.
Expand Down Expand Up @@ -362,19 +350,6 @@ int CCmdChat(int argc, char **argv)
return true;
}

#if 0
// Returns a pointer to a new local ticcmd so it can be built.
// Returns NULL if the buffer is full.
ticcmd_t *Net_LocalCmd()
{
// Check that the localtics buffer still has room.
if(numlocal == LOCALTICS)
return NULL;
// One more command. The counter is cleared when the cmds are sent.
return (ticcmd_t *) & localticcmds[TICCMD_IDX(numlocal++)];
}
#endif

/*
* After a long period with no updates (map setup), calling this will
* reset the tictimer so that no time seems to have passed.
Expand Down Expand Up @@ -1139,7 +1114,7 @@ int CCmdSetName(int argc, char **argv)
//===========================================================================
int CCmdSetTicks(int argc, char **argv)
{
extern double lastSharpFrameTime;
// extern double lastSharpFrameTime;

if(argc != 2)
{
Expand All @@ -1149,7 +1124,7 @@ int CCmdSetTicks(int argc, char **argv)
}
firstNetUpdate = true;
Sys_TicksPerSecond(strtod(argv[1], 0));
lastSharpFrameTime = Sys_GetTimef();
// lastSharpFrameTime = Sys_GetTimef();
return true;
}

Expand Down

0 comments on commit e5eee52

Please sign in to comment.