2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_SIMULATION
|
|
|
|
#define INCLUDED_SIMULATION
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2006-07-30 02:24:04 +02:00
|
|
|
#include <boost/random.hpp>
|
2005-01-07 01:47:44 +01:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
class CGame;
|
|
|
|
class CGameAttributes;
|
|
|
|
class CWorld;
|
2004-08-16 17:19:17 +02:00
|
|
|
class CTurnManager;
|
|
|
|
class CNetMessage;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
class CSimulation
|
|
|
|
{
|
|
|
|
CGame *m_pGame;
|
|
|
|
CWorld *m_pWorld;
|
2004-08-16 17:19:17 +02:00
|
|
|
CTurnManager *m_pTurnManager;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
double m_DeltaTime;
|
2006-07-30 02:24:04 +02:00
|
|
|
|
|
|
|
// Random number generator
|
|
|
|
boost::mt19937 m_Random;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
// Simulate: move the deterministic simulation forward by one interval
|
|
|
|
void Simulate();
|
|
|
|
|
|
|
|
// Interpolate: interpolate a data point for rendering between simulation
|
|
|
|
// frames.
|
|
|
|
void Interpolate(double frameTime, double offset);
|
2004-08-16 17:19:17 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
public:
|
2006-08-07 22:38:23 +02:00
|
|
|
CSimulation(CGame *pGame);
|
2004-08-16 17:19:17 +02:00
|
|
|
~CSimulation();
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
inline void SetTurnManager(CTurnManager *pTurnManager)
|
|
|
|
{ m_pTurnManager=pTurnManager; }
|
|
|
|
inline CTurnManager *GetTurnManager()
|
|
|
|
{ return m_pTurnManager; }
|
|
|
|
|
2005-03-22 03:17:55 +01:00
|
|
|
void RegisterInit(CGameAttributes *pGameAttributes);
|
2005-05-03 23:36:57 +02:00
|
|
|
int Initialize(CGameAttributes *pGameAttributes);
|
2005-03-22 03:17:55 +01:00
|
|
|
|
2007-01-24 21:17:28 +01:00
|
|
|
// Perform simulation updates for the specified elapsed time. If it is
|
|
|
|
// shorter than the time until the next simulation turn, nothing happens.
|
|
|
|
// Returns false if it can't keep up with the desired simulation rate.
|
|
|
|
bool Update(double frameTime);
|
|
|
|
|
2007-02-10 04:09:52 +01:00
|
|
|
// If the last Update couldn't keep up with the desired rate, ignore that
|
|
|
|
// and don't try to catch up when Update is called again. Will completely break
|
|
|
|
// synchronisation of sim time vs real time.
|
|
|
|
void DiscardMissedUpdates();
|
|
|
|
|
2007-01-24 21:17:28 +01:00
|
|
|
// Update the graphical representations of the simulation by the given time.
|
|
|
|
void Interpolate(double frameTime);
|
2004-08-16 17:19:17 +02:00
|
|
|
|
2005-09-26 07:38:40 +02:00
|
|
|
// Calculate the message mask of a message to be queued
|
|
|
|
static uint GetMessageMask(CNetMessage *, uint oldMask, void *userdata);
|
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
// Translate the command message into an entity order and queue it
|
2005-09-26 07:38:40 +02:00
|
|
|
// Returns oldMask
|
|
|
|
static uint TranslateMessage(CNetMessage *, uint oldMask, void *userdata);
|
2004-08-16 17:19:17 +02:00
|
|
|
|
|
|
|
void QueueLocalCommand(CNetMessage *pMsg);
|
2006-07-30 02:24:04 +02:00
|
|
|
|
|
|
|
// Get a random integer between 0 and maxVal-1 from the simulation's random number generator
|
2006-08-07 22:38:23 +02:00
|
|
|
int RandInt(int maxVal);
|
2006-07-30 02:24:04 +02:00
|
|
|
|
|
|
|
// Get a random float in [0, 1) from the simulation's random number generator
|
2006-08-07 22:38:23 +02:00
|
|
|
float RandFloat();
|
2004-07-27 23:00:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|