# Multiplayer synchronization fixes.
This was SVN commit r5429.
This commit is contained in:
parent
eda58ed2f2
commit
6ba71202c9
@ -268,8 +268,7 @@ void CMessageSocket::StartReadMessage()
|
||||
m_pRdBuffer=(u8 *)malloc(m_RdBufferSize);
|
||||
}
|
||||
m_ReadingData=true;
|
||||
printf("CMessageSocket::StartReadMessage(): Got type %d, trying to read %u\n", hdr.m_MsgType, hdr.m_MsgLength);
|
||||
|
||||
|
||||
if (hdr.m_MsgLength == 0)
|
||||
{
|
||||
ReadComplete(PS_OK);
|
||||
|
@ -68,7 +68,7 @@ CNetServer::CNetServer(CGame *pGame, CGameAttributes *pGameAttribs):
|
||||
|
||||
// Set an incredibly long turn length for debugging - less command batch spam that way
|
||||
for (int i=0; i<3; i++)
|
||||
CTurnManager::SetTurnLength(i, 150);
|
||||
CTurnManager::SetTurnLength(i, CTurnManager::DEFAULT_TURN_LENGTH);
|
||||
|
||||
g_ScriptingHost.SetGlobal("g_NetServer", OBJECT_TO_JSVAL(GetScript()));
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ CGame::CGame():
|
||||
m_pLocalPlayer(NULL),
|
||||
m_GameStarted(false),
|
||||
m_Paused(false),
|
||||
m_Time(0),
|
||||
m_SimRate(1.0f)
|
||||
{
|
||||
// Need to set the CObjectManager references after various objects have
|
||||
@ -215,7 +214,6 @@ bool CGame::Update(double deltaTime, bool doInterpolate)
|
||||
return true;
|
||||
|
||||
deltaTime *= m_SimRate;
|
||||
m_Time += deltaTime;
|
||||
|
||||
bool ok = m_Simulation->Update(deltaTime);
|
||||
if (doInterpolate)
|
||||
|
@ -59,10 +59,6 @@ class CGame : boost::noncopyable
|
||||
* the game has been initialized and ready for use if true.
|
||||
**/
|
||||
bool m_GameStarted;
|
||||
/**
|
||||
* total elapsed game time in seconds.
|
||||
**/
|
||||
double m_Time; // needs to be double to get enough precision
|
||||
/**
|
||||
* scale multiplier for simulation rate.
|
||||
**/
|
||||
@ -172,14 +168,6 @@ public:
|
||||
**/
|
||||
inline CSimulation *GetSimulation()
|
||||
{ return m_Simulation; }
|
||||
|
||||
/**
|
||||
* Get the current game elapsed time.
|
||||
*
|
||||
* @return double value of m_Time.
|
||||
**/
|
||||
inline double GetTime() const
|
||||
{ return m_Time; }
|
||||
|
||||
/**
|
||||
* Set the simulation scale multiplier.
|
||||
|
@ -1325,7 +1325,7 @@ JSBool GetGameTime( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, js
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = ToJSVal(g_Game->GetTime());
|
||||
*rval = ToJSVal(g_Game->GetSimulation()->GetTime());
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "FormationManager.h"
|
||||
#include "PathfindEngine.h"
|
||||
#include "ProductionQueue.h"
|
||||
#include "Simulation.h"
|
||||
#include "Stance.h"
|
||||
#include "TechnologyCollection.h"
|
||||
#include "TerritoryManager.h"
|
||||
@ -459,7 +460,7 @@ void CEntity::UpdateOrders( size_t timestep )
|
||||
|
||||
if( entf_get(ENTF_IS_RUNNING) )
|
||||
{
|
||||
m_lastRunTime = g_Game->GetTime();
|
||||
m_lastRunTime = g_Game->GetSimulation()->GetTime();
|
||||
}
|
||||
|
||||
if( m_orderQueue.empty() )
|
||||
@ -1092,7 +1093,7 @@ void CEntity::CalculateRegen(float timestep)
|
||||
// Health regen
|
||||
if(entf_get(ENTF_HEALTH_DECAY))
|
||||
m_healthCurr = decay(m_healthCurr, m_healthMax, timestep, m_healthDecayRate);
|
||||
else if(g_Game->GetTime() - m_lastCombatTime > m_healthRegenStart)
|
||||
else if(g_Game->GetSimulation()->GetTime() - m_lastCombatTime > m_healthRegenStart)
|
||||
m_healthCurr = regen(m_healthCurr, m_healthMax, timestep, m_healthRegenRate);
|
||||
|
||||
// Stamina regen
|
||||
|
@ -32,7 +32,8 @@ CSimulation::CSimulation(CGame *pGame):
|
||||
m_pGame(pGame),
|
||||
m_pWorld(pGame->GetWorld()),
|
||||
m_pTurnManager((g_SinglePlayerTurnManager=new CSinglePlayerTurnManager())),
|
||||
m_DeltaTime(0)
|
||||
m_DeltaTime(0),
|
||||
m_Time(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -95,6 +96,7 @@ bool CSimulation::Update(double frameTime)
|
||||
// cutting down on Interpolate and rendering, and call us a few times
|
||||
// with frameTime == 0 to give us a chance to catch up.
|
||||
ok = false;
|
||||
debug_printf("WARNING: missing a simulation turn due to low FPS");
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +139,9 @@ void CSimulation::Interpolate(double frameTime, double offset)
|
||||
void CSimulation::Simulate()
|
||||
{
|
||||
uint time = m_pTurnManager->GetTurnLength();
|
||||
|
||||
m_Time += time / 1000.0f;
|
||||
//debug_printf("Simulation turn: %.3lf\n", m_Time);
|
||||
|
||||
PROFILE_START( "scheduler tick" );
|
||||
g_Scheduler.Update(time);
|
||||
|
@ -15,6 +15,9 @@ class CSimulation
|
||||
CWorld *m_pWorld;
|
||||
CTurnManager *m_pTurnManager;
|
||||
|
||||
// Current game time; store as double for precision
|
||||
double m_Time;
|
||||
|
||||
double m_DeltaTime;
|
||||
|
||||
// Random number generator
|
||||
@ -66,6 +69,9 @@ public:
|
||||
|
||||
// Get a random float in [0, 1) from the simulation's random number generator
|
||||
float RandFloat();
|
||||
|
||||
// Get game time
|
||||
inline double GetTime() { return m_Time; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@ CSinglePlayerTurnManager *g_SinglePlayerTurnManager=NULL;
|
||||
CTurnManager::CTurnManager()
|
||||
{
|
||||
for (int i=0;i<3;i++)
|
||||
m_Batches[i].m_TurnLength=40;
|
||||
m_Batches[i].m_TurnLength=DEFAULT_TURN_LENGTH;
|
||||
}
|
||||
|
||||
void CTurnManager::ClearBatch(uint batch)
|
||||
|
@ -12,6 +12,9 @@ class IMessagePipeEnd;
|
||||
class CTurnManager
|
||||
{
|
||||
public:
|
||||
// Default turn length
|
||||
static const uint DEFAULT_TURN_LENGTH = 150;
|
||||
|
||||
// Used with IterateBatch() to iterate a command batch and set the sync mask
|
||||
// for each message. If the iterating function doesn't wish to change the
|
||||
// mask, it should return oldMask unchanged.
|
||||
|
Loading…
Reference in New Issue
Block a user