cleanup:
remove ONCE(ScriptingInit) constructs, replace with direct call from GameSetup revised GameSetup's InitScripting (organize into groups) JSCollection: remove #define of two concrete collection types (made typedef, moved to their respective entity.h and player.h) This was SVN commit r5871.
This commit is contained in:
parent
90aeccd122
commit
af6694262a
@ -181,8 +181,6 @@ CGameView::CGameView(CGame *pGame):
|
||||
|
||||
m->UnitView=NULL;
|
||||
m->UnitAttach=NULL;
|
||||
|
||||
ONCE( m->ScriptingInit(); );
|
||||
}
|
||||
|
||||
CGameView::~CGameView()
|
||||
@ -205,6 +203,11 @@ JSObject* CGameView::GetScript()
|
||||
return m->GetScript();
|
||||
}
|
||||
|
||||
/*static*/ void CGameView::ScriptingInit()
|
||||
{
|
||||
return CGameViewImpl::ScriptingInit();
|
||||
}
|
||||
|
||||
CCamera* CGameView::GetCamera()
|
||||
{
|
||||
return &m->ViewCamera;
|
||||
|
@ -88,6 +88,7 @@ public:
|
||||
CCinemaManager* GetCinema();
|
||||
|
||||
JSObject* GetScript();
|
||||
static void ScriptingInit();
|
||||
};
|
||||
extern InReaction game_view_handler(const SDL_Event_* ev);
|
||||
|
||||
|
@ -25,7 +25,6 @@ class CNetServerSession: public CNetSession, public CJSObject<CNetServerSession>
|
||||
bool m_ReadyForTurn; // Is the last turn acknowledged?
|
||||
|
||||
// JS INTERFACE
|
||||
static void ScriptingInit();
|
||||
bool JSI_Close(JSContext *cx, uintN argc, jsval *argv);
|
||||
|
||||
protected:
|
||||
@ -44,6 +43,8 @@ public:
|
||||
CNetServerSession(CNetServer *pServer, CSocketInternal *pInt, MessageHandler *pMsgHandler=HandshakeHandler);
|
||||
virtual ~CNetServerSession();
|
||||
|
||||
static void ScriptingInit();
|
||||
|
||||
inline bool IsObserver()
|
||||
{ return m_IsObserver; }
|
||||
inline CPlayer *GetPlayer()
|
||||
|
@ -19,10 +19,6 @@ CPlayerSlot::CPlayerSlot(int slotID, CPlayer *pPlayer):
|
||||
m_pPlayer(pPlayer),
|
||||
m_Callback(NULL)
|
||||
{
|
||||
ONCE(
|
||||
ScriptingInit();
|
||||
);
|
||||
|
||||
//AddProperty(L"session", (GetFn)&CPlayerSlot::JSI_GetSession);
|
||||
AddLocalProperty(L"session", &m_pSession, true );
|
||||
AddLocalProperty(L"player", &m_pPlayer, true );
|
||||
@ -194,10 +190,6 @@ CGameAttributes::CGameAttributes():
|
||||
m_PlayerUpdateCB(NULL),
|
||||
m_PlayerSlotAssignmentCB(NULL)
|
||||
{
|
||||
ONCE(
|
||||
ScriptingInit();
|
||||
);
|
||||
|
||||
m_PlayerSlotArrayJS=g_ScriptingHost.CreateCustomObject("PlayerSlotArray");
|
||||
JS_AddRoot(g_ScriptingHost.GetContext(), &m_PlayerSlotArrayJS);
|
||||
JS_SetPrivate(g_ScriptingHost.GetContext(), m_PlayerSlotArrayJS, this);
|
||||
|
@ -49,8 +49,6 @@ class CPlayerSlot: public CJSObject<CPlayerSlot>
|
||||
void CallCallback();
|
||||
void SetAssignment(EPlayerSlotAssignment, CNetServerSession *pSession, int sessionID);
|
||||
|
||||
static void ScriptingInit();
|
||||
|
||||
protected:
|
||||
friend class CGameAttributes;
|
||||
inline void SetSlotID(int slotID)
|
||||
@ -101,6 +99,8 @@ public:
|
||||
|
||||
// TODO This will wait until there actually is AI to set up
|
||||
// void AssignAI();
|
||||
|
||||
static void ScriptingInit();
|
||||
};
|
||||
|
||||
namespace PlayerSlotArray_JS
|
||||
@ -151,7 +151,6 @@ private:
|
||||
|
||||
jsval JSI_GetPlayerSlots(JSContext* cx);
|
||||
jsval_t JSI_GetOpenSlot(JSContext *cx, uintN argc, jsval *argv);
|
||||
static void ScriptingInit();
|
||||
|
||||
public:
|
||||
CGameAttributes();
|
||||
@ -183,6 +182,8 @@ public:
|
||||
|
||||
void SetPlayerUpdateCallback(CPlayer::UpdateCallback *cb, void *userdata);
|
||||
void SetPlayerSlotAssignmentCallback(PlayerSlotAssignmentCB *cb, void *userdata);
|
||||
|
||||
static void ScriptingInit();
|
||||
};
|
||||
#define g_GameAttributes CGameAttributes::GetSingleton()
|
||||
|
||||
|
@ -74,6 +74,7 @@
|
||||
# include "gui/scripting/JSInterface_GUITypes.h"
|
||||
# include "gui/GUI.h"
|
||||
#endif
|
||||
#include "network/ServerSession.h"
|
||||
|
||||
#include "sound/CMusicPlayer.h"
|
||||
#include "sound/JSI_Sound.h"
|
||||
@ -462,6 +463,57 @@ void Render()
|
||||
}
|
||||
|
||||
|
||||
static void RegisterJavascriptInterfaces()
|
||||
{
|
||||
// maths
|
||||
JSI_Vector3D::init();
|
||||
|
||||
// graphics
|
||||
JSI_Camera::init();
|
||||
JSI_LightEnv::init();
|
||||
CGameView::ScriptingInit();
|
||||
|
||||
// renderer
|
||||
CRenderer::ScriptingInit();
|
||||
|
||||
// sound
|
||||
JSI_Sound::ScriptingInit();
|
||||
|
||||
// ps
|
||||
JSI_Console::init();
|
||||
CProfileNode::ScriptingInit();
|
||||
CGameAttributes::ScriptingInit();
|
||||
CPlayerSlot::ScriptingInit();
|
||||
CPlayer::ScriptingInit();
|
||||
|
||||
// network
|
||||
CNetMessage::ScriptingInit();
|
||||
CNetServerSession::ScriptingInit();
|
||||
|
||||
// simulation
|
||||
CJSProgressTimer::ScriptingInit();
|
||||
CEntityTemplate::ScriptingInit();
|
||||
CEntity::ScriptingInit();
|
||||
CProjectile::ScriptingInit();
|
||||
CTrigger::ScriptingInit();
|
||||
|
||||
// scripting
|
||||
SColour::ScriptingInit();
|
||||
CScriptEvent::ScriptingInit();
|
||||
EntityCollection::Init( "EntityCollection" );
|
||||
PlayerCollection::Init( "PlayerCollection" );
|
||||
// call CJSComplexPropertyAccessor's ScriptingInit. doesn't really
|
||||
// matter which <T> we use, but we know CJSPropertyAccessor<T> is
|
||||
// already being compiled for T = CEntity.
|
||||
ScriptableComplex_InitComplexPropertyAccessor<CEntity>();
|
||||
|
||||
// GUI
|
||||
#ifndef NO_GUI
|
||||
JSI_IGUIObject::init();
|
||||
JSI_GUITypes::init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void InitScripting()
|
||||
{
|
||||
@ -474,33 +526,7 @@ static void InitScripting()
|
||||
// It would be nice for onLoad code to be able to access the setTimeout() calls.
|
||||
new CScheduler;
|
||||
|
||||
// Register the JavaScript interfaces with the runtime
|
||||
SColour::ScriptingInit();
|
||||
CEntity::ScriptingInit();
|
||||
CTrigger::ScriptingInit();
|
||||
CEntityTemplate::ScriptingInit();
|
||||
|
||||
JSI_Sound::ScriptingInit();
|
||||
CProfileNode::ScriptingInit();
|
||||
|
||||
#ifndef NO_GUI
|
||||
JSI_IGUIObject::init();
|
||||
JSI_GUITypes::init();
|
||||
#endif
|
||||
JSI_Vector3D::init();
|
||||
EntityCollection::Init( "EntityCollection" );
|
||||
CPlayer::ScriptingInit();
|
||||
|
||||
PlayerCollection::Init( "PlayerCollection" );
|
||||
|
||||
// call CJSComplexPropertyAccessor's ScriptingInit. doesn't really
|
||||
// matter which <T> we use, but we know CJSPropertyAccessor<T> is
|
||||
// already being compiled for T = CEntity.
|
||||
ScriptableComplex_InitComplexPropertyAccessor<CEntity>();
|
||||
|
||||
CScriptEvent::ScriptingInit();
|
||||
CJSProgressTimer::ScriptingInit();
|
||||
CProjectile::ScriptingInit();
|
||||
RegisterJavascriptInterfaces();
|
||||
|
||||
g_ScriptingHost.DefineConstant( "FORMATION_ENTER", CFormationEvent::FORMATION_ENTER );
|
||||
g_ScriptingHost.DefineConstant( "FORMATION_LEAVE", CFormationEvent::FORMATION_LEAVE );
|
||||
@ -537,12 +563,6 @@ static void InitScripting()
|
||||
REG_JS_CONSTANT(SDL_BUTTON_WHEELDOWN);
|
||||
#undef REG_JS_CONSTANT
|
||||
|
||||
CNetMessage::ScriptingInit();
|
||||
|
||||
JSI_Camera::init();
|
||||
JSI_Console::init();
|
||||
JSI_LightEnv::init();
|
||||
|
||||
new CGameEvents;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "scripting/SynchedJSObject.h"
|
||||
#include "scripting/ScriptableObject.h"
|
||||
#include "scripting/ScriptCustomTypes.h"
|
||||
#include "ps/scripting/JSCollection.h"
|
||||
#include "Game.h"
|
||||
|
||||
class CNetMessage;
|
||||
@ -98,4 +99,6 @@ public:
|
||||
static void ScriptingInit();
|
||||
};
|
||||
|
||||
typedef CJSCollection<CPlayer*, &CPlayer::JSI_class> PlayerCollection;
|
||||
|
||||
#endif
|
||||
|
@ -427,7 +427,4 @@ template<typename T, JSClass* ScriptType> JSBool CJSCollection<T, ScriptType>::R
|
||||
return( JS_TRUE );
|
||||
}
|
||||
|
||||
#define EntityCollection CJSCollection<HEntity, &CEntity::JSI_class>
|
||||
#define PlayerCollection CJSCollection<CPlayer*, &CPlayer::JSI_class>
|
||||
#define JSObjectCollection
|
||||
#endif
|
||||
|
@ -361,8 +361,6 @@ CRenderer::CRenderer()
|
||||
m_ActiveTextures[i]=0;
|
||||
}
|
||||
|
||||
ONCE( ScriptingInit(); );
|
||||
|
||||
AddLocalProperty(L"fancyWater", &m_Options.m_FancyWater, false);
|
||||
AddLocalProperty(L"horizonHeight", &m->skyManager.m_HorizonHeight, false);
|
||||
AddLocalProperty(L"waterMurkiness", &m->waterManager.m_Murkiness, false);
|
||||
|
@ -296,6 +296,8 @@ public:
|
||||
|
||||
bool GetDisableCopyShadow() const { return m_DisableCopyShadow; }
|
||||
|
||||
static void ScriptingInit();
|
||||
|
||||
protected:
|
||||
friend struct CRendererInternals;
|
||||
friend class CVertexBuffer;
|
||||
@ -312,7 +314,6 @@ protected:
|
||||
// scripting
|
||||
// TODO: Perhaps we could have a version of AddLocalProperty for function-driven
|
||||
// properties? Then we could hide these function in the private implementation class.
|
||||
static void ScriptingInit();
|
||||
jsval JSI_GetFastPlayerColor(JSContext*);
|
||||
void JSI_SetFastPlayerColor(JSContext* ctx, jsval newval);
|
||||
jsval JSI_GetRenderPath(JSContext*);
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "EntitySupport.h"
|
||||
#include "scripting/DOMEvent.h"
|
||||
#include "scripting/ScriptCustomTypes.h"
|
||||
#include "ps/scripting/JSCollection.h"
|
||||
|
||||
class CAura;
|
||||
class CEntityTemplate;
|
||||
@ -493,6 +494,8 @@ public:
|
||||
int GetAttackAction( HEntity target );
|
||||
};
|
||||
|
||||
typedef CJSCollection<HEntity, &CEntity::JSI_class> EntityCollection;
|
||||
|
||||
// General entity globals
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ CProjectile::CProjectile( const CModel* Actor, const CVector3D& Position, const
|
||||
|
||||
CProjectile::~CProjectile()
|
||||
{
|
||||
CProjectileManager& projectileManager = g_Game->GetWorld()->GetProjectileManager();
|
||||
//CProjectileManager& projectileManager = g_Game->GetWorld()->GetProjectileManager();
|
||||
delete( m_Actor );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user