2020-01-14 15:51:29 -08:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2013-09-21 01:24:45 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "JSInterface_Renderer.h"
|
2018-04-27 09:48:44 -07:00
|
|
|
|
2018-08-05 14:50:00 -07:00
|
|
|
#include "graphics/TextureManager.h"
|
2019-08-04 01:28:30 -07:00
|
|
|
#include "renderer/RenderingOptions.h"
|
2013-09-21 01:24:45 -07:00
|
|
|
#include "renderer/Renderer.h"
|
2018-04-27 09:48:44 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2013-09-21 01:24:45 -07:00
|
|
|
|
2019-08-04 01:28:30 -07:00
|
|
|
#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
|
2020-11-21 03:57:14 -08:00
|
|
|
bool Get##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) \
|
2013-09-21 01:24:45 -07:00
|
|
|
{ \
|
2019-08-04 01:28:30 -07:00
|
|
|
return g_RenderingOptions.Get##NAME(); \
|
2013-09-21 01:24:45 -07:00
|
|
|
} \
|
|
|
|
|
\
|
2020-11-21 03:57:14 -08:00
|
|
|
void Set##NAME##Enabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool enabled) \
|
2013-09-21 01:24:45 -07:00
|
|
|
{ \
|
2019-08-04 01:28:30 -07:00
|
|
|
g_RenderingOptions.Set##NAME(enabled); \
|
2013-09-21 01:24:45 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-04 01:28:30 -07:00
|
|
|
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
2020-01-14 15:51:29 -08:00
|
|
|
IMPLEMENT_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
2013-09-21 01:24:45 -07:00
|
|
|
|
|
|
|
|
#undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING
|
|
|
|
|
|
2020-11-13 08:44:15 -08:00
|
|
|
std::string JSI_Renderer::GetRenderPath(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
2013-09-21 01:24:45 -07:00
|
|
|
{
|
2019-08-04 01:28:30 -07:00
|
|
|
return RenderPathEnum::ToString(g_RenderingOptions.GetRenderPath());
|
2013-09-21 01:24:45 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 08:44:15 -08:00
|
|
|
bool JSI_Renderer::TextureExists(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& filename)
|
2018-08-05 14:50:00 -07:00
|
|
|
{
|
|
|
|
|
return g_Renderer.GetTextureManager().TextureExists(filename);
|
|
|
|
|
}
|
2013-09-21 01:24:45 -07:00
|
|
|
|
|
|
|
|
#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
|
2020-11-21 03:57:14 -08:00
|
|
|
scriptInterface.RegisterFunction<bool, &Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \
|
|
|
|
|
scriptInterface.RegisterFunction<void, bool, &Set##NAME##Enabled>("Renderer_Set" #NAME "Enabled");
|
2013-09-21 01:24:45 -07:00
|
|
|
|
2017-08-23 17:32:42 -07:00
|
|
|
void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
2013-09-21 01:24:45 -07:00
|
|
|
{
|
|
|
|
|
scriptInterface.RegisterFunction<std::string, &JSI_Renderer::GetRenderPath>("Renderer_GetRenderPath");
|
2018-08-05 14:50:00 -07:00
|
|
|
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists");
|
2014-05-26 06:42:32 -07:00
|
|
|
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
|
2020-01-14 15:51:29 -08:00
|
|
|
REGISTER_BOOLEAN_SCRIPT_SETTING(DisplayShadowsFrustum);
|
2013-09-21 01:24:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef REGISTER_BOOLEAN_SCRIPT_SETTING
|