2004-07-27 23:00:53 +02:00
|
|
|
#ifndef _ps_Game_H
|
|
|
|
#define _ps_Game_H
|
|
|
|
|
|
|
|
// Kludge: Our included headers might want to subgroup the Game group, so do it
|
|
|
|
// here, before including the other guys
|
2005-01-07 01:47:44 +01:00
|
|
|
#include "ps/Errors.h"
|
2004-07-27 23:00:53 +02:00
|
|
|
ERROR_GROUP(Game);
|
|
|
|
|
|
|
|
#include "World.h"
|
|
|
|
#include "Simulation.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "GameView.h"
|
2004-08-16 17:19:17 +02:00
|
|
|
|
|
|
|
#include "AttributeMap.h"
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-08-05 15:07:51 +02:00
|
|
|
#include <vector>
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
class CGameAttributes: public CAttributeMap
|
2004-07-27 23:00:53 +02:00
|
|
|
{
|
2004-08-16 17:19:17 +02:00
|
|
|
protected:
|
|
|
|
virtual void CreateJSObject();
|
|
|
|
virtual JSBool GetJSProperty(jsval id, jsval *ret);
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
public:
|
2004-08-16 17:19:17 +02:00
|
|
|
CGameAttributes();
|
|
|
|
virtual ~CGameAttributes();
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
// NOTE: Public only for JS interface
|
|
|
|
class CPlayerAttributes: public CAttributeMap
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void CreateJSObject();
|
|
|
|
public:
|
|
|
|
CPlayerAttributes();
|
|
|
|
};
|
2004-08-05 15:07:51 +02:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
JSObject *m_PlayerArrayJS;
|
|
|
|
std::vector <CPlayerAttributes *> m_PlayerAttribs;
|
2004-07-27 23:00:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CGame
|
|
|
|
{
|
|
|
|
CWorld m_World;
|
|
|
|
CSimulation m_Simulation;
|
|
|
|
CGameView m_GameView;
|
|
|
|
|
|
|
|
CPlayer *m_pLocalPlayer;
|
2004-11-07 22:59:52 +01:00
|
|
|
std::vector<CPlayer *> m_Players;
|
2004-08-16 17:19:17 +02:00
|
|
|
uint m_NumPlayers;
|
2004-09-21 16:40:43 +02:00
|
|
|
|
|
|
|
bool m_GameStarted;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
public:
|
2004-08-05 15:07:51 +02:00
|
|
|
CGame();
|
|
|
|
~CGame();
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize all local state and members for playing a game described by
|
2004-08-16 17:19:17 +02:00
|
|
|
the attribute class, and start the game.
|
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
Return: 0 on OK - a PSRETURN code otherwise
|
2004-07-27 23:00:53 +02:00
|
|
|
*/
|
2004-08-16 17:19:17 +02:00
|
|
|
PSRETURN StartGame(CGameAttributes *pGameAttributes);
|
2004-07-27 23:00:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Perform all per-frame updates
|
|
|
|
*/
|
|
|
|
void Update(double deltaTime);
|
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
inline CPlayer *GetLocalPlayer()
|
|
|
|
{ return m_pLocalPlayer; }
|
2004-11-07 22:59:52 +01:00
|
|
|
inline void SetLocalPlayer(CPlayer *pLocalPlayer)
|
|
|
|
{ m_pLocalPlayer=pLocalPlayer; }
|
|
|
|
|
|
|
|
inline CPlayer *GetPlayer(uint idx)
|
2005-01-18 13:45:56 +01:00
|
|
|
{ if (idx >= 0 && idx < m_NumPlayers) return m_Players[idx]; else { debug_warn("Invalid player ID"); return m_Players[0]; } }
|
2005-01-18 01:46:18 +01:00
|
|
|
|
|
|
|
inline std::vector<CPlayer*>* GetPlayers()
|
|
|
|
{ return( &m_Players ); }
|
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
inline uint GetNumPlayers()
|
|
|
|
{ return m_NumPlayers; }
|
|
|
|
|
2004-09-21 16:40:43 +02:00
|
|
|
inline bool IsGameStarted()
|
|
|
|
{
|
|
|
|
return m_GameStarted;
|
|
|
|
}
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
inline CWorld *GetWorld()
|
|
|
|
{ return &m_World; }
|
|
|
|
inline CGameView *GetView()
|
|
|
|
{ return &m_GameView; }
|
2004-08-16 17:19:17 +02:00
|
|
|
inline CSimulation *GetSimulation()
|
|
|
|
{ return &m_Simulation; }
|
2004-07-27 23:00:53 +02:00
|
|
|
};
|
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
extern CGame *g_Game;
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
#endif
|