Line data Source code
1 : /* Copyright (C) 2021 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_Renderer.h"
21 :
22 : #include "graphics/TextureManager.h"
23 : #include "renderer/RenderingOptions.h"
24 : #include "renderer/Renderer.h"
25 : #include "scriptinterface/FunctionWrapper.h"
26 :
27 : namespace JSI_Renderer
28 : {
29 : #define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
30 : bool Get##NAME##Enabled() \
31 : { \
32 : return g_RenderingOptions.Get##NAME(); \
33 : } \
34 : \
35 : void Set##NAME##Enabled(bool enabled) \
36 : { \
37 : g_RenderingOptions.Set##NAME(enabled); \
38 : }
39 :
40 0 : IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
41 0 : IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
42 :
43 : #undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING
44 :
45 0 : std::string GetRenderPath()
46 : {
47 0 : return RenderPathEnum::ToString(g_RenderingOptions.GetRenderPath());
48 : }
49 :
50 0 : std::string GetRenderDebugMode()
51 : {
52 0 : return RenderDebugModeEnum::ToString(g_RenderingOptions.GetRenderDebugMode()).c_str();
53 : }
54 :
55 0 : void SetRenderDebugMode(const std::string& mode)
56 : {
57 0 : g_RenderingOptions.SetRenderDebugMode(RenderDebugModeEnum::FromString(mode));
58 0 : }
59 :
60 0 : bool TextureExists(const std::wstring& filename)
61 : {
62 0 : return g_Renderer.GetTextureManager().TextureExists(filename);
63 : }
64 :
65 : #define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
66 : ScriptFunction::Register<&Get##NAME##Enabled>(rq, "Renderer_Get" #NAME "Enabled"); \
67 : ScriptFunction::Register<&Set##NAME##Enabled>(rq, "Renderer_Set" #NAME "Enabled");
68 :
69 12 : void RegisterScriptFunctions(const ScriptRequest& rq)
70 : {
71 12 : ScriptFunction::Register<&GetRenderPath>(rq, "Renderer_GetRenderPath");
72 12 : ScriptFunction::Register<&TextureExists>(rq, "TextureExists");
73 12 : ScriptFunction::Register<&GetRenderDebugMode>(rq, "Renderer_GetRenderDebugMode");
74 12 : ScriptFunction::Register<&SetRenderDebugMode>(rq, "Renderer_SetRenderDebugMode");
75 12 : REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
76 12 : REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
77 12 : }
78 :
79 : #undef REGISTER_BOOLEAN_SCRIPT_SETTING
80 3 : }
|