Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sol::lib::jit to actually enable JIT ( resolves #899 ) #900

Merged
merged 4 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CET::CET()
, m_bindings(m_paths, m_options)
, m_window(&m_bindings, &m_d3d12)
, m_d3d12(m_window, m_paths, m_options)
, m_vm(m_paths, m_bindings, m_d3d12)
, m_vm(m_paths, m_options, m_bindings, m_d3d12)
, m_overlay(m_bindings, m_options, m_persistentState, m_vm)
{
}
Expand Down
16 changes: 6 additions & 10 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ void PatchesSettings::Load(const nlohmann::json& aConfig)
nlohmann::json PatchesSettings::Save() const
{
return {
{"disable_async_compute", AsyncCompute},
{"disable_antialiasing", Antialiasing},
{"skip_start_menu", SkipStartMenu},
{"disable_intro_movies", DisableIntroMovies},
{"disable_vignette", DisableVignette},
{"disable_boundary_teleport", DisableBoundaryTeleport},
{"disable_win7_vsync", DisableWin7Vsync},
{"minimap_flicker", MinimapFlicker},
{"disable_async_compute", AsyncCompute}, {"disable_antialiasing", Antialiasing}, {"skip_start_menu", SkipStartMenu},
{"disable_intro_movies", DisableIntroMovies}, {"disable_vignette", DisableVignette}, {"disable_boundary_teleport", DisableBoundaryTeleport},
{"disable_win7_vsync", DisableWin7Vsync}, {"minimap_flicker", MinimapFlicker},
};
}

Expand Down Expand Up @@ -60,6 +55,7 @@ void DeveloperSettings::Load(const nlohmann::json& aConfig)
DumpGameOptions = aConfig.value("dump_game_options", DumpGameOptions);
MaxLinesConsoleHistory = aConfig.value("max_lines_console_history", MaxLinesConsoleHistory);
PersistentConsole = aConfig.value("persistent_console", PersistentConsole);
EnableJIT = aConfig.value("enable_jit", EnableJIT);

// set global "Enable ImGui Assertions"
g_ImGuiAssertionsEnabled = EnableImGuiAssertions;
Expand All @@ -70,8 +66,8 @@ nlohmann::json DeveloperSettings::Save() const
// set global "Enable ImGui Assertions"
g_ImGuiAssertionsEnabled = EnableImGuiAssertions;

return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions},
{"dump_game_options", DumpGameOptions}, {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}};
return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, {"dump_game_options", DumpGameOptions},
{"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}, {"enable_jit", EnableJIT}};
}

void DeveloperSettings::ResetToDefaults()
Expand Down
1 change: 1 addition & 0 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct DeveloperSettings
bool DumpGameOptions{false};
uint64_t MaxLinesConsoleHistory{1000};
bool PersistentConsole{true};
bool EnableJIT{true};
};

struct Options
Expand Down
3 changes: 3 additions & 0 deletions src/overlay/widgets/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void Settings::OnUpdate()
UpdateAndDrawSetting(
"Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions,
developerSettings.DumpGameOptions);
UpdateAndDrawSetting(
"Enable JIT for Lua", "Enables JIT compiler for Lua VM, which may majorly speed up the mods. Disable it in case you experience issues as a troubleshooting step (requires restart to take effect).", m_developer.EnableJIT,
developerSettings.EnableJIT);

ImGui::EndTable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/LuaVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct TDBIDLookupEntry
struct Image;
struct LuaVM
{
LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12);
LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12);
~LuaVM() = default;

[[nodiscard]] const VKBind* GetBind(const VKModBind& acModBind) const;
Expand Down
4 changes: 2 additions & 2 deletions src/scripting/LuaVM_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ void LuaVM::HookLogChannel(RED4ext::IScriptable*, RED4ext::CStackFrame* apStack,
}
}

LuaVM::LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12)
: m_scripting(aPaths, aBindings, aD3D12)
LuaVM::LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12)
: m_scripting(aPaths, aOptions, aBindings, aD3D12)
, m_d3d12(aD3D12)
{
Hook();
Expand Down
7 changes: 6 additions & 1 deletion src/scripting/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ static constexpr bool s_cThrowLuaErrors = true;
static RTTILocator s_stringType{RED4ext::FNV1a64("String")};
static RTTILocator s_resRefType{RED4ext::FNV1a64("redResourceReferenceScriptToken")};

Scripting::Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12)
Scripting::Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12)
: m_sandbox(this, aBindings)
, m_mapper(m_lua.AsRef(), m_sandbox)
, m_store(m_sandbox, aPaths, aBindings)
, m_override(this)
, m_paths(aPaths)
, m_options(aOptions)
, m_d3d12(aD3D12)
{
CreateLogger(aPaths.CETRoot() / "scripting.log", "scripting");
Expand All @@ -50,6 +51,10 @@ void Scripting::Initialize()
auto& luaVm = lua.Get();

luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32);

if (m_options.Developer.EnableJIT)
luaVm.open_libraries(sol::lib::jit);

luaVm.require("sqlite3", luaopen_lsqlite3);

// make sure to set package path to current directory scope
Expand Down
3 changes: 2 additions & 1 deletion src/scripting/Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Scripting
{
using LockedState = TiltedPhoques::Locked<sol::state, std::recursive_mutex>;

Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12);
Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12);
~Scripting() = default;

void Initialize();
Expand Down Expand Up @@ -61,5 +61,6 @@ struct Scripting
ScriptStore m_store;
FunctionOverride m_override;
const Paths& m_paths;
const Options& m_options;
D3D12& m_d3d12;
};
Loading