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