Ticket #2126: gameview_global_functions_v1.0.diff

File gameview_global_functions_v1.0.diff, 10.1 KB (added by Yves, 11 years ago)
  • binaries/data/mods/public/gui/session/session.xml

     
    290290
    291291        <object size="0 128 100%-18 144" type="text" style="devCommandsText">Restrict camera</object>
    292292        <object size="100%-16 128 100% 144" type="checkbox" style="StoneCrossBox" checked="true">
    293         <action on="Press">gameView.constrainCamera = this.checked;</action>
     293        <action on="Press">Engine.GameView_SetConstrainCameraEnabled(this.checked);</action>
    294294        </object>
    295295
    296296        <object size="0 144 100%-18 160" type="text" style="devCommandsText">Reveal map</object>
  • source/ps/GameSetup/GameSetup.cpp

     
    321321    // maths
    322322    JSI_Vector3D::init();
    323323
    324     // graphics
    325     CGameView::ScriptingInit();
    326 
    327324    // renderer
    328325    CRenderer::ScriptingInit();
    329326
  • source/gui/scripting/ScriptFunctions.cpp

     
    2323#include "graphics/GameView.h"
    2424#include "graphics/MapReader.h"
    2525#include "gui/GUIManager.h"
     26#include "graphics/scripting/JSInterface_GameView.h"
    2627#include "lib/timer.h"
    2728#include "lib/utf8.h"
    2829#include "lib/sysdep/sysdep.h"
     
    650651
    651652void GuiScriptingInit(ScriptInterface& scriptInterface)
    652653{
     654    JSI_GameView::RegisterScriptFunctions(scriptInterface);
     655
    653656    // GUI manager functions:
    654657    scriptInterface.RegisterFunction<CScriptVal, &GetActiveGui>("GetActiveGui");
    655658    scriptInterface.RegisterFunction<void, std::wstring, CScriptVal, &PushGuiPage>("PushGuiPage");
  • source/graphics/GameView.h

     
    9696    float GetFar() const;
    9797    float GetFOV() const;
    9898    float GetCullFOV() const;
     99   
     100    #define DECLARE_BOOLEAN_SETTING(NAME) \
     101    bool Get##NAME##Enabled(); \
     102    void Set##NAME##Enabled(bool Enabled);
    99103
     104    DECLARE_BOOLEAN_SETTING(Culling);
     105    DECLARE_BOOLEAN_SETTING(LockCullCamera);
     106    DECLARE_BOOLEAN_SETTING(ConstrainCamera);
     107
     108    #undef DECLARE_BOOLEAN_SETTING
     109
    100110    // Set projection of current camera using near, far, and FOV values
    101111    void SetCameraProjection();
    102112
     
    104114    CCinemaManager* GetCinema();
    105115
    106116    JSObject* GetScript();
    107     static void ScriptingInit();
    108117};
    109118extern InReaction game_view_handler(const SDL_Event_* ev);
    110 
    111119#endif
  • source/graphics/scripting/JSInterface_GameView.cpp

     
     1/* Copyright (C) 2013 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include "precompiled.h"
     19
     20#include "JSInterface_GameView.h"
     21#include "graphics/GameView.h"
     22#include "ps/Game.h"
     23#include "ps/CLogger.h"
     24#include "scriptinterface/ScriptInterface.h"
     25
     26#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
     27bool JSI_GameView::Get##NAME##Enabled(void* UNUSED(cbdata)) \
     28{ \
     29    if (!g_Game || !g_Game->GetView()) \
     30    { \
     31        LOGERROR(L"Trying to get a setting from GameView when it's not initialized!"); \
     32        return false; \
     33    } \
     34    return g_Game->GetView()->Get##NAME##Enabled(); \
     35} \
     36\
     37void JSI_GameView::Set##NAME##Enabled(void* UNUSED(cbdata), bool Enabled) \
     38{ \
     39    if (!g_Game || !g_Game->GetView()) \
     40    { \
     41        LOGERROR(L"Trying to set a setting of GameView when it's not initialized!"); \
     42        return; \
     43    } \
     44    g_Game->GetView()->Set##NAME##Enabled(Enabled); \
     45}
     46
     47IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Culling);
     48IMPLEMENT_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
     49IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
     50
     51#undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING
     52
     53
     54#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
     55scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get" #NAME "Enabled"); \
     56scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set" #NAME "Enabled");
     57
     58void JSI_GameView::RegisterScriptFunctions(ScriptInterface& scriptInterface)
     59{
     60    REGISTER_BOOLEAN_SCRIPT_SETTING(Culling);
     61    REGISTER_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
     62    REGISTER_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
     63}
     64
     65#undef REGISTER_BOOLEAN_SCRIPT_SETTING
     66
     67
     68
  • source/graphics/scripting/JSInterface_GameView.h

     
     1/* Copyright (C) 2013 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18
     19#ifndef INCLUDED_JSINTERFACE_GAMEVIEW
     20#define INCLUDED_JSINTERFACE_GAMEVIEW
     21
     22#include "ps/CStr.h"
     23class ScriptInterface;
     24
     25#define DECLARE_BOOLEAN_SCRIPT_SETTING(NAME) \
     26    bool Get##NAME##Enabled(void* cbdata); \
     27    void Set##NAME##Enabled(void* cbdata, bool Enabled);
     28
     29namespace JSI_GameView
     30{
     31    void RegisterScriptFunctions(ScriptInterface& ScriptInterface);
     32   
     33    DECLARE_BOOLEAN_SCRIPT_SETTING(Culling);
     34    DECLARE_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
     35    DECLARE_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
     36}
     37
     38#undef DECLARE_BOOLEAN_SCRIPT_SETTING
     39
     40#endif
     41
  • source/graphics/GameView.cpp

     
    3434#include "graphics/TerritoryTexture.h"
    3535#include "graphics/Unit.h"
    3636#include "graphics/UnitManager.h"
     37#include "graphics/scripting/JSInterface_GameView.h"
    3738#include "lib/input.h"
    3839#include "lib/timer.h"
    3940#include "maths/BoundingBoxAligned.h"
     
    5455#include "ps/World.h"
    5556#include "renderer/Renderer.h"
    5657#include "renderer/WaterManager.h"
    57 #include "scripting/ScriptableObject.h"
    5858#include "simulation2/Simulation2.h"
    5959#include "simulation2/components/ICmpPosition.h"
    6060#include "simulation2/components/ICmpRangeManager.h"
     
    148148    float m_Smoothness;
    149149};
    150150
    151 class CGameViewImpl : public CJSObject<CGameViewImpl>
     151class CGameViewImpl
    152152{
    153153    NONCOPYABLE(CGameViewImpl);
    154154public:
     
    308308    CSmoothedValue Zoom;
    309309    CSmoothedValue RotateX; // inclination around x axis (relative to camera)
    310310    CSmoothedValue RotateY; // rotation around y (vertical) axis
    311 
    312     static void ScriptingInit();
    313311};
    314312
     313#define IMPLEMENT_BOOLEAN_SETTING(NAME) \
     314bool CGameView::Get##NAME##Enabled() \
     315{ \
     316    return m->NAME; \
     317} \
     318\
     319void CGameView::Set##NAME##Enabled(bool Enabled) \
     320{ \
     321    m->NAME = Enabled; \
     322}
     323
     324IMPLEMENT_BOOLEAN_SETTING(Culling);
     325IMPLEMENT_BOOLEAN_SETTING(LockCullCamera);
     326IMPLEMENT_BOOLEAN_SETTING(ConstrainCamera);
     327
     328#undef IMPLEMENT_BOOLEAN_SETTING
     329
    315330static void SetupCameraMatrixSmooth(CGameViewImpl* m, CMatrix3D* orientation)
    316331{
    317332    orientation->SetIdentity();
     
    372387    return m->ObjectManager;
    373388}
    374389
    375 JSObject* CGameView::GetScript()
    376 {
    377     return m->GetScript();
    378 }
    379 
    380 /*static*/ void CGameView::ScriptingInit()
    381 {
    382     return CGameViewImpl::ScriptingInit();
    383 }
    384 
    385390CCamera* CGameView::GetCamera()
    386391{
    387392    return &m->ViewCamera;
     
    402407    return m->TerritoryTexture;
    403408}
    404409
    405 
    406 void CGameViewImpl::ScriptingInit()
    407 {
    408     AddProperty(L"culling", &CGameViewImpl::Culling);
    409     AddProperty(L"lockCullCamera", &CGameViewImpl::LockCullCamera);
    410     AddProperty(L"constrainCamera", &CGameViewImpl::ConstrainCamera);
    411 
    412     CJSObject<CGameViewImpl>::ScriptingInit("GameView");
    413 }
    414 
    415410int CGameView::Initialize()
    416411{
    417412    CFG_GET_VAL("view.scroll.speed", Float, m->ViewScrollSpeed);
  • source/scripting/ScriptGlue.cpp

     
    408408// property accessors
    409409//-----------------------------------------------------------------------------
    410410
    411 JSBool GetGameView(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid UNUSED(id), jsval* vp)
    412 {
    413     if (g_Game)
    414         *vp = OBJECT_TO_JSVAL(g_Game->GetView()->GetScript());
    415     else
    416         *vp = JSVAL_NULL;
    417     return JS_TRUE;
    418 }
    419 
    420411JSBool GetRenderer(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid UNUSED(id), jsval* vp)
    421412{
    422413    if (CRenderer::IsInitialised())
     
    439430JSPropertySpec ScriptGlobalTable[] =
    440431{
    441432    { "console"    , GLOBAL_CONSOLE,     JSPROP_PERMANENT|JSPROP_READONLY, JSI_Console::getConsole, 0 },
    442     { "gameView"   , 0,                  JSPROP_PERMANENT|JSPROP_READONLY, GetGameView, 0 },
    443433    { "renderer"   , 0,                  JSPROP_PERMANENT|JSPROP_READONLY, GetRenderer, 0 },
    444434
    445435    // end of table marker