2004-07-27 23:00:53 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "Game.h"
|
2004-08-05 15:07:51 +02:00
|
|
|
#include "CLogger.h"
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
CGame *g_Game=NULL;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2004-08-05 15:07:51 +02:00
|
|
|
JSBool CGameAttributes::FillFromJS(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
#define GETVAL(_name) jsval _name=g_ScriptingHost.GetObjectProperty(obj, #_name)
|
|
|
|
GETVAL(mapFile);
|
|
|
|
|
|
|
|
#define TOSTRING(_jsval) g_ScriptingHost.ValueToString(_jsval)
|
|
|
|
if (JSVAL_IS_STRING(mapFile))
|
|
|
|
m_MapFile=TOSTRING(mapFile);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGame::CGame():
|
|
|
|
m_World(this),
|
|
|
|
m_Simulation(this),
|
|
|
|
m_GameView(this),
|
|
|
|
m_pLocalPlayer(NULL)
|
|
|
|
{
|
2004-08-06 17:04:47 +02:00
|
|
|
debug_out("CGame::CGame(): Game object CREATED\n");
|
2004-08-05 15:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CGame::~CGame()
|
|
|
|
{
|
2004-08-06 17:04:47 +02:00
|
|
|
debug_out("CGame::~CGame(): Game object DESTROYED\n");
|
2004-08-05 15:07:51 +02:00
|
|
|
}
|
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
PSRETURN CGame::Initialize(CGameAttributes *pAttribs)
|
2004-07-27 23:00:53 +02:00
|
|
|
{
|
2004-07-31 17:57:18 +02:00
|
|
|
try
|
|
|
|
{
|
2004-08-04 23:03:53 +02:00
|
|
|
// RC, 040804 - GameView needs to be initialised before World, otherwise GameView initialisation
|
|
|
|
// overwrites anything stored in the map file that gets loaded by CWorld::Initialize with default
|
|
|
|
// values. At the minute, it's just lighting settings, but could be extended to store camera position.
|
|
|
|
// Storing lighting settings in the gameview seems a little odd, but it's no big deal; maybe move it at
|
|
|
|
// some point to be stored in the world object?
|
|
|
|
m_GameView.Initialize(pAttribs);
|
2004-07-31 17:57:18 +02:00
|
|
|
m_World.Initialize(pAttribs);
|
|
|
|
m_Simulation.Initialize(pAttribs);
|
|
|
|
}
|
|
|
|
catch (PSERROR_Game e)
|
|
|
|
{
|
|
|
|
return e.code;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-07-27 23:00:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGame::Update(double deltaTime)
|
|
|
|
{
|
|
|
|
m_Simulation.Update(deltaTime);
|
|
|
|
|
|
|
|
// TODO Detect game over and bring up the summary screen or something
|
|
|
|
}
|