Ticket #2126: gameview_global_functions_v1.0.diff
File gameview_global_functions_v1.0.diff, 10.1 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.xml
290 290 291 291 <object size="0 128 100%-18 144" type="text" style="devCommandsText">Restrict camera</object> 292 292 <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> 294 294 </object> 295 295 296 296 <object size="0 144 100%-18 160" type="text" style="devCommandsText">Reveal map</object> -
source/ps/GameSetup/GameSetup.cpp
321 321 // maths 322 322 JSI_Vector3D::init(); 323 323 324 // graphics325 CGameView::ScriptingInit();326 327 324 // renderer 328 325 CRenderer::ScriptingInit(); 329 326 -
source/gui/scripting/ScriptFunctions.cpp
23 23 #include "graphics/GameView.h" 24 24 #include "graphics/MapReader.h" 25 25 #include "gui/GUIManager.h" 26 #include "graphics/scripting/JSInterface_GameView.h" 26 27 #include "lib/timer.h" 27 28 #include "lib/utf8.h" 28 29 #include "lib/sysdep/sysdep.h" … … 650 651 651 652 void GuiScriptingInit(ScriptInterface& scriptInterface) 652 653 { 654 JSI_GameView::RegisterScriptFunctions(scriptInterface); 655 653 656 // GUI manager functions: 654 657 scriptInterface.RegisterFunction<CScriptVal, &GetActiveGui>("GetActiveGui"); 655 658 scriptInterface.RegisterFunction<void, std::wstring, CScriptVal, &PushGuiPage>("PushGuiPage"); -
source/graphics/GameView.h
96 96 float GetFar() const; 97 97 float GetFOV() const; 98 98 float GetCullFOV() const; 99 100 #define DECLARE_BOOLEAN_SETTING(NAME) \ 101 bool Get##NAME##Enabled(); \ 102 void Set##NAME##Enabled(bool Enabled); 99 103 104 DECLARE_BOOLEAN_SETTING(Culling); 105 DECLARE_BOOLEAN_SETTING(LockCullCamera); 106 DECLARE_BOOLEAN_SETTING(ConstrainCamera); 107 108 #undef DECLARE_BOOLEAN_SETTING 109 100 110 // Set projection of current camera using near, far, and FOV values 101 111 void SetCameraProjection(); 102 112 … … 104 114 CCinemaManager* GetCinema(); 105 115 106 116 JSObject* GetScript(); 107 static void ScriptingInit();108 117 }; 109 118 extern InReaction game_view_handler(const SDL_Event_* ev); 110 111 119 #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) \ 27 bool 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 \ 37 void 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 47 IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Culling); 48 IMPLEMENT_BOOLEAN_SCRIPT_SETTING(LockCullCamera); 49 IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera); 50 51 #undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING 52 53 54 #define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \ 55 scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get" #NAME "Enabled"); \ 56 scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set" #NAME "Enabled"); 57 58 void 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" 23 class 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 29 namespace 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
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: … … 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 IMPLEMENT_BOOLEAN_SETTING(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 IMPLEMENT_BOOLEAN_SETTING(Culling); 325 IMPLEMENT_BOOLEAN_SETTING(LockCullCamera); 326 IMPLEMENT_BOOLEAN_SETTING(ConstrainCamera); 327 328 #undef IMPLEMENT_BOOLEAN_SETTING 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 }379 380 /*static*/ void CGameView::ScriptingInit()381 {382 return CGameViewImpl::ScriptingInit();383 }384 385 390 CCamera* CGameView::GetCamera() 386 391 { 387 392 return &m->ViewCamera; … … 402 407 return m->TerritoryTexture; 403 408 } 404 409 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 415 410 int CGameView::Initialize() 416 411 { 417 412 CFG_GET_VAL("view.scroll.speed", Float, m->ViewScrollSpeed); -
source/scripting/ScriptGlue.cpp
408 408 // property accessors 409 409 //----------------------------------------------------------------------------- 410 410 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 else416 *vp = JSVAL_NULL;417 return JS_TRUE;418 }419 420 411 JSBool GetRenderer(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid UNUSED(id), jsval* vp) 421 412 { 422 413 if (CRenderer::IsInitialised()) … … 439 430 JSPropertySpec ScriptGlobalTable[] = 440 431 { 441 432 { "console" , GLOBAL_CONSOLE, JSPROP_PERMANENT|JSPROP_READONLY, JSI_Console::getConsole, 0 }, 442 { "gameView" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetGameView, 0 },443 433 { "renderer" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetRenderer, 0 }, 444 434 445 435 // end of table marker