Ticket #1886: CGameView_without_CJSObject_2.diff

File CGameView_without_CJSObject_2.diff, 7.0 KB (added by Yves, 11 years ago)

just for reference and discussion in the associate thread

  • 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:
     
    160160        TerritoryTexture(*game->GetSimulation2()),
    161161        ViewCamera(),
    162162        CullCamera(),
     163        FollowEntity(INVALID_ENTITY),
     164        FollowFirstPerson(false),
    163165        LockCullCamera(false),
    164166        ConstrainCamera(true),
    165167        Culling(true),
    166         FollowEntity(INVALID_ENTITY),
    167         FollowFirstPerson(false),
    168168
    169169        // Dummy values (these will be filled in by the config file)
    170170        ViewScrollSpeed(0),
     
    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 BLN_GET_SET(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
     324BLN_GET_SET(Culling);
     325BLN_GET_SET(LockCullCamera);
     326BLN_GET_SET(ConstrainCamera);
     327
     328#undef BLN_GET_SET
     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 }
     390//JSObject* CGameView::GetScript()
     391//{
     392//  return m->GetScript();
     393//}
    379394
    380 /*static*/ void CGameView::ScriptingInit()
    381 {
    382     return CGameViewImpl::ScriptingInit();
    383 }
    384 
    385395CCamera* CGameView::GetCamera()
    386396{
    387397    return &m->ViewCamera;
     
    402412    return m->TerritoryTexture;
    403413}
    404414
     415#define REG_BLN_GET_SET(NAME) \
     416scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get##NAME##Enabled"); \
     417scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set##NAME##Enabled");
    405418
    406 void CGameViewImpl::ScriptingInit()
     419void CGameView::RegisterScriptFunctions(ScriptInterface& scriptInterface)
    407420{
    408     AddProperty(L"culling", &CGameViewImpl::Culling);
    409     AddProperty(L"lockCullCamera", &CGameViewImpl::LockCullCamera);
    410     AddProperty(L"constrainCamera", &CGameViewImpl::ConstrainCamera);
    411 
    412     CJSObject<CGameViewImpl>::ScriptingInit("GameView");
     421    REG_BLN_GET_SET(Culling);
     422    REG_BLN_GET_SET(LockCullCamera);
     423    REG_BLN_GET_SET(ConstrainCamera);
    413424}
    414425
     426#undef REG_BLN_GET_SET
     427
    415428int CGameView::Initialize()
    416429{
    417430    CFG_GET_VAL("view.scroll.speed", Float, m->ViewScrollSpeed);
  • GameView.h

     
    1919#define INCLUDED_GAMEVIEW
    2020
    2121#include "renderer/Scene.h"
     22#include "scriptinterface/ScriptInterface.h"
    2223#include "simulation2/system/Entity.h"
    2324
    2425#include "lib/input.h" // InReaction - can't forward-declare enum
     
    9495    float GetFar() const;
    9596    float GetFOV() const;
    9697    float GetCullFOV() const;
     98   
     99    void RegisterScriptFunctions(ScriptInterface& scriptInterface);
     100   
     101    #define BLN_GET_SET(NAME) \
     102    bool Get##NAME##Enabled(); \
     103    void Set##NAME##Enabled(bool Enabled);
     104   
     105    BLN_GET_SET(Culling);
     106    BLN_GET_SET(LockCullCamera);
     107    BLN_GET_SET(ConstrainCamera);
     108   
     109    #undef BLN_GET_SET
    97110
     111
    98112    // Set projection of current camera using near, far, and FOV values
    99113    void SetCameraProjection();
    100114
     
    102116    CCinemaManager* GetCinema();
    103117
    104118    JSObject* GetScript();
    105     static void ScriptingInit();
    106119};
    107120extern InReaction game_view_handler(const SDL_Event_* ev);
    108121
  • 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
     24#define BLN_GET_SET(NAME) \
     25bool JSI_GameView::Get##NAME##Enabled(ScriptInterface* UNUSED(scriptInterface), void* UNUSED(cbdata)) \
     26{ \
     27    return g_Game->GetView()->Get##NAME##Enabled(); \
     28} \
     29\
     30void JSI_GameView::Set##NAME##Enabled(ScriptInterface* UNUSED(scriptInterface), void* UNUSED(cbdata), bool Enabled) \
     31{ \
     32    g_Game->GetView()->Set##NAME##Enabled(Enabled); \
     33}
     34
     35BLN_GET_SET(Culling);
     36BLN_GET_SET(LockCullCamera);
     37BLN_GET_SET(ConstrainCamera);
     38
     39
  • 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"
     23#include "scriptinterface/ScriptInterface.h"
     24
     25#define BLN_GET_SET(NAME) \
     26    bool Get##NAME##Enabled(ScriptInterface* scriptInterface, void* cbdata); \
     27    void Set##NAME##Enabled(ScriptInterface* scriptInterface, void* cbdata, bool Enabled);
     28
     29namespace JSI_GameView
     30{
     31    BLN_GET_SET(Culling);
     32    BLN_GET_SET(LockCullCamera);
     33    BLN_GET_SET(ConstrainCamera);
     34}
     35
     36#undef BLN_GET_SET
     37
     38#endif