From 7a0aed29e7f1eb45975992a540a694e2ca61bdce Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 1 Dec 2024 13:31:36 +0200 Subject: [PATCH] lua: expose polygon offset settings progress #373 --- Misc/qs_pak/scripts/defs.lua | 1 + Quake/ls_main.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Misc/qs_pak/scripts/defs.lua b/Misc/qs_pak/scripts/defs.lua index 857a43521..da05df581 100644 --- a/Misc/qs_pak/scripts/defs.lua +++ b/Misc/qs_pak/scripts/defs.lua @@ -6,6 +6,7 @@ expmode = {} host = {} player = {} progs = {} +render = {} sounds = {} text = {} textures = {} diff --git a/Quake/ls_main.cpp b/Quake/ls_main.cpp index 12988ef0a..9442306e4 100644 --- a/Quake/ls_main.cpp +++ b/Quake/ls_main.cpp @@ -30,6 +30,8 @@ extern "C" const sfx_t* LS_GetSounds(int* count); const gltexture_t* LS_GetTextures(); + +extern cvar_t gl_polyoffset_factor, gl_polyoffset_units; } #ifdef USE_TLSF @@ -1090,6 +1092,38 @@ static void LS_InitTexturesTable(lua_State* state) } +template +static int LS_NumberCVarFunction(lua_State* state) +{ + if (lua_gettop(state) >= 1) + { + const float value = luaL_checknumber(state, 1); + Cvar_SetValueQuick(&cvar, value); + return 0; + } + + lua_pushnumber(state, cvar.value); + return 1; +} + +static void LS_InitRenderTable(lua_State* state) +{ + lua_newtable(state); + lua_pushstring(state, "polyoffset"); + + static const luaL_Reg functions[] = + { + { "factor", LS_NumberCVarFunction }, + { "units", LS_NumberCVarFunction }, + { nullptr, nullptr } + }; + + luaL_newlib(state, functions); + lua_rawset(state, -3); + lua_setglobal(state, "render"); +} + + static lua_CFunction ls_loadfunc; // Calls original load() function with mode explicitly set to text @@ -1157,6 +1191,7 @@ static void LS_InitGlobalTables(lua_State* state) { LS_InitHostTable(state); LS_InitPlayerTable(state); + LS_InitRenderTable(state); LS_InitSoundsTable(state); LS_InitTextTable(state); LS_InitTexturesTable(state);