From 091805a16e9e827cc687d6f39c0de7744df2eb0c Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 6 Oct 2024 17:28:44 +0300 Subject: [PATCH] refactor scripting_world_generation.cpp --- .../scripting/scripting_world_generation.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/logic/scripting/scripting_world_generation.cpp b/src/logic/scripting/scripting_world_generation.cpp index dd4d8ad1..e935d818 100644 --- a/src/logic/scripting/scripting_world_generation.cpp +++ b/src/logic/scripting/scripting_world_generation.cpp @@ -15,20 +15,22 @@ #include "util/timeutil.hpp" class LuaGeneratorScript : public GeneratorScript { + lua::State* L; const GeneratorDef& def; scriptenv env; public: LuaGeneratorScript( + lua::State* L, const GeneratorDef& def, scriptenv env) - : def(def), + : L(L), + def(def), env(std::move(env)) {} std::shared_ptr generateHeightmap( const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, uint bpd ) override { - auto L = lua::get_main_thread(); lua::pushenv(L, *env); if (lua::getfield(L, "generate_heightmap")) { lua::pushivec_stack(L, offset); @@ -51,7 +53,6 @@ public: std::vector> maps; uint biomeParameters = def.biomeParameters; - auto L = lua::get_main_thread(); lua::pushenv(L, *env); if (lua::getfield(L, "generate_biome_parameters")) { lua::pushivec_stack(L, offset); @@ -80,7 +81,6 @@ public: ) override { std::vector placements; - auto L = lua::get_main_thread(); lua::stackguard _(L); lua::pushenv(L, *env); if (lua::getfield(L, "place_structures")) { @@ -97,7 +97,9 @@ public: lua::rawgeti(L, 1); int structIndex = 0; if (lua::isstring(L, -1)) { - const auto& found = def.structuresIndices.find(lua::require_string(L, -1)); + const auto& found = def.structuresIndices.find( + lua::require_string(L, -1) + ); if (found != def.structuresIndices.end()) { structIndex = found->second; } @@ -144,11 +146,10 @@ std::unique_ptr scripting::load_generator( lua::pop(L, load_script(*env, "generator", file)); } else { // Use default (empty) script - lua::pop(L, lua::execute(lua::get_main_thread(), *env, "", "")); + lua::pop(L, lua::execute(L, *env, "", "")); } return std::make_unique( - def, - std::move(env) + L, def, std::move(env) ); }