Ticket #1886: CGameView_without_CJSObject_1.diff

File CGameView_without_CJSObject_1.diff, 3.9 KB (added by Yves, 6 years ago)

just for reference and discussion in the associate thread

  • GameView.cpp

     
    5454#include "ps/World.h"
    5555#include "renderer/Renderer.h"
    5656#include "renderer/WaterManager.h"
    57 #include "scripting/ScriptableObject.h"
    5857#include "simulation2/Simulation2.h"
    5958#include "simulation2/components/ICmpPosition.h"
    6059#include "simulation2/components/ICmpRangeManager.h"
     
    148147    float m_Smoothness;
    149148};
    150149
    151 class CGameViewImpl : public CJSObject<CGameViewImpl>
     150class CGameViewImpl
    152151{
    153152    NONCOPYABLE(CGameViewImpl);
    154153public:
     
    160159        TerritoryTexture(*game->GetSimulation2()),
    161160        ViewCamera(),
    162161        CullCamera(),
    163         LockCullCamera(false),
    164         ConstrainCamera(true),
    165         Culling(true),
    166162        FollowEntity(INVALID_ENTITY),
    167163        FollowFirstPerson(false),
    168164
     
    234230     *
    235231     * Exposed to JS as gameView.lockCullCamera
    236232     */
    237     bool LockCullCamera;
     233    static bool m_LockCullCamera;
    238234
    239235    /**
    240236     * When @c true, culling is enabled so that only models that have a chance of
     
    243239     *
    244240     * Exposed to JS as gameView.culling
    245241     */
    246     bool Culling;
     242    static bool m_Culling;
    247243
    248244    /**
    249245     * Whether the camera movement should be constrained by min/max limits
    250246     * and terrain avoidance.
    251247     */
    252     bool ConstrainCamera;
     248    static bool m_ConstrainCamera;
    253249
    254250    /**
    255251     * Cache global lighting environment. This is used  to check whether the
     
    309305    CSmoothedValue RotateX; // inclination around x axis (relative to camera)
    310306    CSmoothedValue RotateY; // rotation around y (vertical) axis
    311307
    312     static void ScriptingInit();
     308    static void RegisterScriptFunctions(ScriptInterface& scriptInterface);
     309    static void SetCulling(ScriptInterface* UNUSED(ScriptInterface), void* UNUSED(cbdata), bool Enabled) { CGameViewImpl::m_Culling = Enabled; }
     310    static void LockCullCamera(ScriptInterface* UNUSED(ScriptInterface), void* UNUSED(cbdata), bool Enabled) { CGameViewImpl::m_LockCullCamera = Enabled; }
     311    static void ConstrainCamera(ScriptInterface* UNUSED(ScriptInterface), void* UNUSED(cbdata), bool Enabled) { CGameViewImpl::m_ConstrainCamera = Enabled; }
     312
    313313};
    314314
     315bool CGameViewImpl::m_LockCullCamera = false;
     316bool CGameViewImpl::m_ConstrainCamera = true;
     317bool CGameViewImpl::m_Culling = true;
     318
    315319static void SetupCameraMatrixSmooth(CGameViewImpl* m, CMatrix3D* orientation)
    316320{
    317321    orientation->SetIdentity();
     
    372376    return m->ObjectManager;
    373377}
    374378
    375 JSObject* CGameView::GetScript()
    376 {
    377     return m->GetScript();
    378 }
     379//JSObject* CGameView::GetScript()
     380//{
     381//  return m->GetScript();
     382//}
    379383
    380 /*static*/ void CGameView::ScriptingInit()
    381 {
    382     return CGameViewImpl::ScriptingInit();
    383 }
    384 
    385384CCamera* CGameView::GetCamera()
    386385{
    387386    return &m->ViewCamera;
     
    402401    return m->TerritoryTexture;
    403402}
    404403
    405 
    406 void CGameViewImpl::ScriptingInit()
     404void CGameViewImpl::RegisterScriptFunctions(ScriptInterface& scriptInterface)
    407405{
    408     AddProperty(L"culling", &CGameViewImpl::Culling);
    409     AddProperty(L"lockCullCamera", &CGameViewImpl::LockCullCamera);
    410     AddProperty(L"constrainCamera", &CGameViewImpl::ConstrainCamera);
    411 
    412     CJSObject<CGameViewImpl>::ScriptingInit("GameView");
     406    scriptInterface.RegisterFunction<void, bool, &CGameViewImpl::SetCulling>("GameView_SetCulling");
     407    scriptInterface.RegisterFunction<void, bool, &CGameViewImpl::LockCullCamera>("GameView_LockCullCamera");
     408    scriptInterface.RegisterFunction<void, bool, &CGameViewImpl::ConstrainCamera>("GameView_ConstrainCamera");
    413409}
    414410
    415411int CGameView::Initialize()
     
    526522                bounds[1].Y = waterHeight;
    527523            }
    528524
    529             if (!m->Culling || frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) {
     525            if (!m->m_Culling || frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) {
    530526                //c->Submit(patch);
    531527
    532528                // set the renderstate for this patch
     
    577573    }
    578574    }
    579575
    580     m->Game->GetSimulation2()->RenderSubmit(*c, frustum, m->Culling);
     576    m->Game->GetSimulation2()->RenderSubmit(*c, frustum, m->m_Culling);
    581577}
    582578
    583579