Skip to content

Commit

Permalink
reenable improved reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Mar 15, 2012
1 parent 1d22412 commit 2124e51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
6 changes: 5 additions & 1 deletion rts/Game/Game.cpp
Expand Up @@ -139,6 +139,7 @@
#include "System/Exceptions.h"
#include "System/Sync/FPUCheck.h"
#include "System/GlobalConfig.h"
#include "System/myMath.h"
#include "System/NetProtocol.h"
#include "System/SpringApp.h"
#include "System/Util.h"
Expand Down Expand Up @@ -919,7 +920,6 @@ bool CGame::UpdateUnsynced()

// Update simFPS
{
const bool newSimFrame_ = (lastSimFrame != gs->frameNum);
static int lsf = gs->frameNum;
static spring_time lsft = currentTime;
const float diffsecs_ = spring_diffsecs(currentTime, lsft);
Expand Down Expand Up @@ -1296,6 +1296,8 @@ bool CGame::Draw() {

CTeamHighlight::Disable();

gu->avgDrawFrameTime = mix(gu->avgDrawFrameTime, float(spring_tomsecs(spring_gettime() - currentTime)), 0.1f);

return true;
}

Expand Down Expand Up @@ -1500,6 +1502,8 @@ void CGame::SimFrame() {

DumpState(-1, -1, 1);

gu->avgSimFrameTime = mix(gu->avgSimFrameTime, float(spring_tomsecs(spring_gettime() - lastFrameTime)), 0.1f);

LEAVE_SYNCED_CODE();
}

Expand Down
3 changes: 3 additions & 0 deletions rts/Game/GlobalUnsynced.cpp
Expand Up @@ -54,6 +54,9 @@ CGlobalUnsynced::CGlobalUnsynced()

simFPS = 0.0f;

avgSimFrameTime = 0.0f;
avgDrawFrameTime = 0.0f;

modGameTime = 0;
gameTime = 0;
startTime = 0;
Expand Down
12 changes: 9 additions & 3 deletions rts/Game/GlobalUnsynced.h
Expand Up @@ -45,11 +45,11 @@ class CGlobalUnsynced {
* for simulation is minimum spend for
* drawing.
* This is important when reconnecting,
* i.e. it means that 20% of the total
* cpu time is spend for drawing and 80%
* i.e. it means that 15% of the total
* cpu time is spend for drawing and 85%
* for reconnecting/simulation.
*/
static const float simDrawBalance = 0.2f;
static const float reconnectSimDrawBalance = 0.15f;

/**
* @brief simulation frames per second
Expand All @@ -60,6 +60,12 @@ class CGlobalUnsynced {
*/
float simFPS;

/**
* @brief average frame time (in ms)
*/
float avgSimFrameTime;
float avgDrawFrameTime;

/**
* @brief mod game time
*
Expand Down
14 changes: 7 additions & 7 deletions rts/Game/NetCommands.cpp
Expand Up @@ -109,17 +109,17 @@ void CGame::ClientReadNet()

// balance the time spend in simulation & drawing (esp. when reconnecting)
// always render at least 2FPS (will otherwise be highly unresponsive when catching up after a reconnection)
//const float curSimFPS = gs->userSpeedFactor * GAME_SPEED; FIXME this returns incorrect data when reconnecting
//const float msPerDrawFrame = 1000.0f * profiler.GetPercent("GameController::Draw") / std::max(1.0f, globalRendering->FPS); FIXME this returns incorrect data when reconnecting (>60ms per frame during reconnect, and <6ms normally)
//const float msPerSimFrame = 1000.0f * profiler.GetPercent("Game::SimFrame") / std::max(1.0f, curSimFPS);
//const float wantedDrawFPS = (msPerSimFrame * gu->simDrawBalance) / std::max(1.0f, msPerDrawFrame);
//const float wantedFPS = std::max(float(gu->minFPS), wantedDrawFPS);
const float wantedFPS = gu->minFPS;
// else use the following algo: i.e. with gu->reconnectSimDrawBalance = 0.2f
// -> try to spend minimum 20% of the time in drawing
// -> use remaining 80% for reconnecting
const float maxSimFPS = (1.0f - gu->reconnectSimDrawBalance) * 1000.0f / std::max(0.01f, gu->avgSimFrameTime);
const float minDrawFPS = gu->reconnectSimDrawBalance * 1000.0f / std::max(0.01f, gu->avgDrawFrameTime);
const float drawMinimumEachMS = std::min(1000.0f / gu->minFPS, (maxSimFPS / minDrawFPS) * gu->avgSimFrameTime);

// really process the messages
while (
timeLeft > 0.0f // smooths simframes across the full second
&& spring_tomsecs(spring_gettime() - procstarttime) < (1000.0f / wantedFPS) // balance the time spend in sim & drawing
&& spring_tomsecs(spring_gettime() - procstarttime) < drawMinimumEachMS // balance the time spend in sim & drawing
&& (packet = net->GetData(gs->frameNum)) // get netpacket from the stack
){
const unsigned char* inbuf = packet->data;
Expand Down

0 comments on commit 2124e51

Please sign in to comment.