janwas
c0ed950657
this snowballed into a massive search+destroy of the hodgepodge of mostly equivalent types we had in use (int, uint, unsigned, unsigned int, i32, u32, ulong, uintN). it is more efficient to use 64-bit types in 64-bit mode, so the preferred default is size_t (for anything remotely resembling a size or index). tile coordinates are ssize_t to allow more efficient conversion to/from floating point. flags are int because we almost never need more than 15 distinct bits, bit test/set is not slower and int is fastest to type. finally, some data that is pretty much directly passed to OpenGL is now typed accordingly. after several hours, the code now requires fewer casts and less guesswork. other changes: - unit and player IDs now have an "invalid id" constant in the respective class to avoid casting and -1 - fix some endian/64-bit bugs in the map (un)packing. added a convenience function to write/read a size_t. - ia32: change CPUID interface to allow passing in ecx (required for cache topology detection, which I need at work). remove some unneeded functions from asm, replace with intrinsics where possible. This was SVN commit r5942.
78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
#ifndef INCLUDED_SIMULATION
|
|
#define INCLUDED_SIMULATION
|
|
|
|
#include <boost/random.hpp>
|
|
|
|
class CGame;
|
|
class CGameAttributes;
|
|
class CWorld;
|
|
class CTurnManager;
|
|
class CNetMessage;
|
|
|
|
class CSimulation
|
|
{
|
|
CGame *m_pGame;
|
|
CWorld *m_pWorld;
|
|
CTurnManager *m_pTurnManager;
|
|
|
|
// Current game time; store as double for precision
|
|
double m_Time;
|
|
|
|
double m_DeltaTime;
|
|
|
|
// Random number generator
|
|
boost::mt19937 m_Random;
|
|
|
|
// 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);
|
|
|
|
public:
|
|
CSimulation(CGame *pGame);
|
|
~CSimulation();
|
|
|
|
inline void SetTurnManager(CTurnManager *pTurnManager)
|
|
{ m_pTurnManager=pTurnManager; }
|
|
inline CTurnManager *GetTurnManager()
|
|
{ return m_pTurnManager; }
|
|
|
|
void RegisterInit(CGameAttributes *pGameAttributes);
|
|
int Initialize(CGameAttributes *pGameAttributes);
|
|
|
|
// 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);
|
|
|
|
// 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();
|
|
|
|
// Update the graphical representations of the simulation by the given time.
|
|
void Interpolate(double frameTime);
|
|
|
|
// Calculate the message mask of a message to be queued
|
|
static size_t GetMessageMask(CNetMessage *, size_t oldMask, void *userdata);
|
|
|
|
// Translate the command message into an entity order and queue it
|
|
// Returns oldMask
|
|
static size_t TranslateMessage(CNetMessage *, size_t oldMask, void *userdata);
|
|
|
|
void QueueLocalCommand(CNetMessage *pMsg);
|
|
|
|
// Get a random integer between 0 and maxVal-1 from the simulation's random number generator
|
|
int RandInt(int maxVal);
|
|
|
|
// 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
|