1
0
forked from 0ad/0ad
0ad/source/ps/Game.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 18:48:32 +00:00

197 lines
4.6 KiB
C++

/**
* File : Game.h
* Project : engine
* Description : Contains the CGame Class which is a representation of the game itself.
*
**/
#ifndef INCLUDED_GAME
#define INCLUDED_GAME
#include "ps/Errors.h"
#include <vector>
class CWorld;
class CSimulation;
class CGameView;
class CSimulation;
class CPlayer;
class CGameAttributes;
/**
* Default player limit (not counting the Gaia player)
* This may be overridden by system.cfg ("max_players")
**/
#define PS_MAX_PLAYERS 8
/**
* The container that holds the rules, resources and attributes of the game.
* The CGame object is responsible for creating a game that is defined by
* a set of attributes provided. The CGame object is also responsible for
* maintaining the relations between CPlayer and CWorld, CSimulation and CWorld.
**/
class CGame : boost::noncopyable
{
/**
* pointer to the CWorld object representing the game world.
**/
CWorld *m_World;
/**
* pointer to the CSimulation object operating on the game world.
**/
CSimulation *m_Simulation;
/**
* pointer to the CGameView object representing the view into the game world.
**/
CGameView *m_GameView;
/**
* pointer to the local CPlayer object operating on the game world.
**/
CPlayer *m_pLocalPlayer;
/**
* STL vectors of pointers to all CPlayer objects(including gaia) operating on the game world.
**/
std::vector<CPlayer *> m_Players;
/**
* number of players operating on the game world(not including gaia).
**/
size_t m_NumPlayers;
/**
* the game has been initialized and ready for use if true.
**/
bool m_GameStarted;
/**
* scale multiplier for simulation rate.
**/
float m_SimRate;
/**
* enumerated values for game status.
**/
enum EOG
{
EOG_NEUTRAL, /// Game is in progress
EOG_DRAW, /// Game is over as a Draw by means of agreement of civilizations
EOG_SPECIAL_DRAW, /// Game is over by players dying at the same time...?
EOG_LOSE, /// Game is over, local player loses
EOG_WIN /// Game is over, local player wins
} GameStatus;
public:
CGame();
~CGame();
/**
* the game is paused and no updates will be performed if true.
**/
bool m_Paused;
/*
Initialize all local state and members for playing a game described by
the attribute class, and start the game.
Return: 0 on OK - a PSRETURN code otherwise
*/
PSRETURN StartGame(CGameAttributes *pGameAttributes);
PSRETURN ReallyStartGame();
/*
Perform all per-frame updates
*/
bool Update(double deltaTime, bool doInterpolate = true);
void UpdateGameStatus();
void EndGame();
/**
* Get pointer to the local player object.
*
* @return CPlayer * the value of m_pLocalPlayer.
**/
inline CPlayer *GetLocalPlayer()
{ return m_pLocalPlayer; }
/**
* Change the pointer to the local player object.
*
* @param CPlayer * pLocalPlayer pointer to a valid player object.
**/
inline void SetLocalPlayer(CPlayer *pLocalPlayer)
{ m_pLocalPlayer=pLocalPlayer; }
// PT: No longer inline, because it does too much error checking. When
// everything stops trying to access players before they're loaded, feel
// free to put the inline version back.
CPlayer *GetPlayer(size_t idx);
/**
* Get a reference to the m_Players vector.
*
* @return std::vector<CPlayer*> * reference to m_Players.
**/
inline std::vector<CPlayer*>* GetPlayers()
{ return( &m_Players ); }
/**
* Get m_NumPlayers.
*
* @return the number of players (not including gaia)
**/
inline size_t GetNumPlayers() const
{ return m_NumPlayers; }
/**
* Get m_GameStarted.
*
* @return bool the value of m_GameStarted.
**/
inline bool IsGameStarted() const
{
return m_GameStarted;
}
/**
* Get the pointer to the game world object.
*
* @return CWorld * the value of m_World.
**/
inline CWorld *GetWorld()
{ return m_World; }
/**
* Get the pointer to the game view object.
*
* @return CGameView * the value of m_GameView.
**/
inline CGameView *GetView()
{ return m_GameView; }
/**
* Get the pointer to the simulation object.
*
* @return CSimulation * the value of m_Simulation.
**/
inline CSimulation *GetSimulation()
{ return m_Simulation; }
/**
* Set the simulation scale multiplier.
*
* @param float simRate value to set m_SimRate to.
* Because m_SimRate is also used to
* scale TimeSinceLastFrame it must be
* clamped to 0.0f.
**/
inline void SetSimRate(float simRate)
{ m_SimRate = std::max(simRate, 0.0f); }
/**
* Get the simulation scale multiplier.
*
* @return float value of m_SimRate.
**/
inline float GetSimRate() const
{ return m_SimRate; }
private:
PSRETURN RegisterInit(CGameAttributes* pAttribs);
};
extern CGame *g_Game;
#endif