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
|
|
|
|
2005-01-19 23:32:25 +01:00
|
|
|
#include "scripting/SynchedJSObject.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
|
|
|
|
2005-01-23 05:14:49 +01:00
|
|
|
// Hard player limit (not counting the Gaia player)
|
|
|
|
#define PS_MAX_PLAYERS 6
|
|
|
|
|
2005-01-19 23:32:25 +01:00
|
|
|
namespace PlayerArray_JS
|
2004-07-27 23:00:53 +02:00
|
|
|
{
|
2005-01-19 23:32:25 +01:00
|
|
|
JSBool GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
|
|
|
};
|
|
|
|
|
|
|
|
#define g_GameAttributes CGameAttributes::GetSingleton()
|
|
|
|
class CGameAttributes:
|
|
|
|
public CSynchedJSObject<CGameAttributes>,
|
|
|
|
public Singleton<CGameAttributes>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void (UpdateCallback)(CStrW name, CStrW newValue, void *data);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend JSBool PlayerArray_JS::GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
|
|
|
|
|
|
|
virtual void Update(CStrW name, ISynchedJSProperty *attrib);
|
|
|
|
|
|
|
|
UpdateCallback *m_UpdateCB;
|
|
|
|
void *m_UpdateCBData;
|
|
|
|
|
|
|
|
CPlayer::UpdateCallback *m_PlayerUpdateCB;
|
|
|
|
void *m_PlayerUpdateCBData;
|
|
|
|
|
|
|
|
jsval JSGetPlayers();
|
2004-08-16 17:19:17 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
public:
|
2005-01-19 23:32:25 +01:00
|
|
|
CStrW m_MapFile;
|
|
|
|
uint m_NumPlayers;
|
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
CGameAttributes();
|
|
|
|
virtual ~CGameAttributes();
|
2005-01-19 23:32:25 +01:00
|
|
|
|
|
|
|
void SetValue(CStrW name, CStrW value);
|
|
|
|
|
|
|
|
inline void SetUpdateCallback(UpdateCallback *cb, void *userdata)
|
2004-08-16 17:19:17 +02:00
|
|
|
{
|
2005-01-19 23:32:25 +01:00
|
|
|
m_UpdateCB=cb;
|
|
|
|
m_UpdateCBData=userdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPlayerUpdateCallback(CPlayer::UpdateCallback *cb, void *userdata);
|
|
|
|
|
|
|
|
std::vector <CPlayer *> m_Players;
|
2004-08-16 17:19:17 +02:00
|
|
|
JSObject *m_PlayerArrayJS;
|
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-19 23:32:25 +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
|