Ticket #1886: CGameView_without_CJSObject_2.diff
File CGameView_without_CJSObject_2.diff, 7.0 KB (added by , 11 years ago) |
---|
-
GameView.cpp
34 34 #include "graphics/TerritoryTexture.h" 35 35 #include "graphics/Unit.h" 36 36 #include "graphics/UnitManager.h" 37 #include "graphics/scripting/JSInterface_GameView.h" 37 38 #include "lib/input.h" 38 39 #include "lib/timer.h" 39 40 #include "maths/BoundingBoxAligned.h" … … 54 55 #include "ps/World.h" 55 56 #include "renderer/Renderer.h" 56 57 #include "renderer/WaterManager.h" 57 #include "scripting/ScriptableObject.h"58 58 #include "simulation2/Simulation2.h" 59 59 #include "simulation2/components/ICmpPosition.h" 60 60 #include "simulation2/components/ICmpRangeManager.h" … … 148 148 float m_Smoothness; 149 149 }; 150 150 151 class CGameViewImpl : public CJSObject<CGameViewImpl>151 class CGameViewImpl 152 152 { 153 153 NONCOPYABLE(CGameViewImpl); 154 154 public: … … 160 160 TerritoryTexture(*game->GetSimulation2()), 161 161 ViewCamera(), 162 162 CullCamera(), 163 FollowEntity(INVALID_ENTITY), 164 FollowFirstPerson(false), 163 165 LockCullCamera(false), 164 166 ConstrainCamera(true), 165 167 Culling(true), 166 FollowEntity(INVALID_ENTITY),167 FollowFirstPerson(false),168 168 169 169 // Dummy values (these will be filled in by the config file) 170 170 ViewScrollSpeed(0), … … 308 308 CSmoothedValue Zoom; 309 309 CSmoothedValue RotateX; // inclination around x axis (relative to camera) 310 310 CSmoothedValue RotateY; // rotation around y (vertical) axis 311 312 static void ScriptingInit();313 311 }; 314 312 313 #define BLN_GET_SET(NAME) \ 314 bool CGameView::Get##NAME##Enabled() \ 315 { \ 316 return m->NAME; \ 317 } \ 318 \ 319 void CGameView::Set##NAME##Enabled(bool Enabled) \ 320 { \ 321 m->NAME = Enabled; \ 322 } 323 324 BLN_GET_SET(Culling); 325 BLN_GET_SET(LockCullCamera); 326 BLN_GET_SET(ConstrainCamera); 327 328 #undef BLN_GET_SET 329 315 330 static void SetupCameraMatrixSmooth(CGameViewImpl* m, CMatrix3D* orientation) 316 331 { 317 332 orientation->SetIdentity(); … … 372 387 return m->ObjectManager; 373 388 } 374 389 375 JSObject* CGameView::GetScript()376 {377 return m->GetScript();378 }390 //JSObject* CGameView::GetScript() 391 //{ 392 // return m->GetScript(); 393 //} 379 394 380 /*static*/ void CGameView::ScriptingInit()381 {382 return CGameViewImpl::ScriptingInit();383 }384 385 395 CCamera* CGameView::GetCamera() 386 396 { 387 397 return &m->ViewCamera; … … 402 412 return m->TerritoryTexture; 403 413 } 404 414 415 #define REG_BLN_GET_SET(NAME) \ 416 scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get##NAME##Enabled"); \ 417 scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set##NAME##Enabled"); 405 418 406 void CGameView Impl::ScriptingInit()419 void CGameView::RegisterScriptFunctions(ScriptInterface& scriptInterface) 407 420 { 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); 413 424 } 414 425 426 #undef REG_BLN_GET_SET 427 415 428 int CGameView::Initialize() 416 429 { 417 430 CFG_GET_VAL("view.scroll.speed", Float, m->ViewScrollSpeed); -
GameView.h
19 19 #define INCLUDED_GAMEVIEW 20 20 21 21 #include "renderer/Scene.h" 22 #include "scriptinterface/ScriptInterface.h" 22 23 #include "simulation2/system/Entity.h" 23 24 24 25 #include "lib/input.h" // InReaction - can't forward-declare enum … … 94 95 float GetFar() const; 95 96 float GetFOV() const; 96 97 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 97 110 111 98 112 // Set projection of current camera using near, far, and FOV values 99 113 void SetCameraProjection(); 100 114 … … 102 116 CCinemaManager* GetCinema(); 103 117 104 118 JSObject* GetScript(); 105 static void ScriptingInit();106 119 }; 107 120 extern InReaction game_view_handler(const SDL_Event_* ev); 108 121 -
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) \ 25 bool JSI_GameView::Get##NAME##Enabled(ScriptInterface* UNUSED(scriptInterface), void* UNUSED(cbdata)) \ 26 { \ 27 return g_Game->GetView()->Get##NAME##Enabled(); \ 28 } \ 29 \ 30 void JSI_GameView::Set##NAME##Enabled(ScriptInterface* UNUSED(scriptInterface), void* UNUSED(cbdata), bool Enabled) \ 31 { \ 32 g_Game->GetView()->Set##NAME##Enabled(Enabled); \ 33 } 34 35 BLN_GET_SET(Culling); 36 BLN_GET_SET(LockCullCamera); 37 BLN_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 29 namespace 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