From af6694262a35520a1a8322adca8fb94b07b801f4 Mon Sep 17 00:00:00 2001 From: janwas Date: Sun, 6 Apr 2008 14:03:23 +0000 Subject: [PATCH] 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. --- source/graphics/GameView.cpp | 7 ++- source/graphics/GameView.h | 1 + source/network/ServerSession.h | 3 +- source/ps/GameAttributes.cpp | 8 --- source/ps/GameAttributes.h | 7 +-- source/ps/GameSetup/GameSetup.cpp | 86 ++++++++++++++++++------------ source/ps/Player.h | 3 ++ source/ps/scripting/JSCollection.h | 3 -- source/renderer/Renderer.cpp | 2 - source/renderer/Renderer.h | 3 +- source/simulation/Entity.h | 3 ++ source/simulation/Projectile.cpp | 2 +- 12 files changed, 74 insertions(+), 54 deletions(-) diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index f076816cb5..6f620d2422 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -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; diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 2259319284..feb06d6fd5 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -88,6 +88,7 @@ public: CCinemaManager* GetCinema(); JSObject* GetScript(); + static void ScriptingInit(); }; extern InReaction game_view_handler(const SDL_Event_* ev); diff --git a/source/network/ServerSession.h b/source/network/ServerSession.h index 1241b0d192..a4e6f60cfb 100644 --- a/source/network/ServerSession.h +++ b/source/network/ServerSession.h @@ -25,7 +25,6 @@ class CNetServerSession: public CNetSession, public CJSObject 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() diff --git a/source/ps/GameAttributes.cpp b/source/ps/GameAttributes.cpp index 0f92a905cf..d7c8c64fc2 100644 --- a/source/ps/GameAttributes.cpp +++ b/source/ps/GameAttributes.cpp @@ -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); diff --git a/source/ps/GameAttributes.h b/source/ps/GameAttributes.h index ba0bf21922..44ba2a87be 100644 --- a/source/ps/GameAttributes.h +++ b/source/ps/GameAttributes.h @@ -49,8 +49,6 @@ class CPlayerSlot: public CJSObject 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() diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 458e22fab7..24551eb32c 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -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 we use, but we know CJSPropertyAccessor is + // already being compiled for T = CEntity. + ScriptableComplex_InitComplexPropertyAccessor(); + + // 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 we use, but we know CJSPropertyAccessor is - // already being compiled for T = CEntity. - ScriptableComplex_InitComplexPropertyAccessor(); - - 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; } diff --git a/source/ps/Player.h b/source/ps/Player.h index bceaae7499..9889d7f126 100644 --- a/source/ps/Player.h +++ b/source/ps/Player.h @@ -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 PlayerCollection; + #endif diff --git a/source/ps/scripting/JSCollection.h b/source/ps/scripting/JSCollection.h index dbc56448d4..64564eb518 100644 --- a/source/ps/scripting/JSCollection.h +++ b/source/ps/scripting/JSCollection.h @@ -427,7 +427,4 @@ template JSBool CJSCollection::R return( JS_TRUE ); } -#define EntityCollection CJSCollection -#define PlayerCollection CJSCollection -#define JSObjectCollection #endif diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 73241a6cfa..8cb8428967 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -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); diff --git a/source/renderer/Renderer.h b/source/renderer/Renderer.h index df627dfd65..f612374655 100644 --- a/source/renderer/Renderer.h +++ b/source/renderer/Renderer.h @@ -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*); diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index 55298ba9bd..afe8e15f46 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -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 EntityCollection; + // General entity globals diff --git a/source/simulation/Projectile.cpp b/source/simulation/Projectile.cpp index d23b636532..cc86da97dd 100644 --- a/source/simulation/Projectile.cpp +++ b/source/simulation/Projectile.cpp @@ -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 ); }