Skip to content

Commit

Permalink
lua: move engine tables into own source file
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Dec 26, 2024
1 parent 6eb81ba commit c223afa
Show file tree
Hide file tree
Showing 6 changed files with 684 additions and 640 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(COMMON_SOURCES
Quake/lodepng.h
Quake/ls_common.h
Quake/ls_edict.cpp
Quake/ls_engine.cpp
Quake/ls_imgui.cpp
Quake/ls_imgui.h
Quake/ls_imgui_enums.h
Expand Down Expand Up @@ -747,6 +748,7 @@ if(QUAKE_BUILD_ENGINE_PAK)
scripts/aliases/common.cfg
scripts/aliases/expmode.cfg
scripts/edicts.lua
scripts/engine.lua
scripts/expmode_base.lua
scripts/expmode_edicts.lua
scripts/expmode_engine.lua
Expand Down
17 changes: 0 additions & 17 deletions Misc/qs_pak/scripts/edicts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,3 @@ function edicts.boxsearch(halfedge, origin)

return result
end


---
--- Host helpers
---

function host.levelname()
local world = edicts[1]
return world and world.message
end

function host.mapname()
local world = edicts[1]

-- Remove leading 'maps/' and trailing '.bsp'
return world and world.model:sub(6):sub(1, -5)
end
16 changes: 16 additions & 0 deletions Misc/qs_pak/scripts/engine.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

---
--- Host helpers
---

function host.levelname()
local world = edicts[1]
return world and world.message
end

function host.mapname()
local world = edicts[1]

-- Remove leading 'maps/' and trailing '.bsp'
return world and world.model:sub(6):sub(1, -5)
end
16 changes: 7 additions & 9 deletions Quake/ls_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "lua.hpp"

class LS_TempAllocatorBase
{
protected:
static void* Alloc(size_t size);
static void Free(void* pointer);
};
char* LS_tempalloc(lua_State* state, size_t size);
void LS_tempfree(void* ptr);

template <typename T>
class LS_TempAllocator : LS_TempAllocatorBase
class LS_TempAllocator
{
public:
using value_type = T;

static T* allocate(const size_t count)
{
return static_cast<T*>(Alloc(sizeof(T) * count));
return reinterpret_cast<T*>(LS_tempalloc(nullptr, sizeof(T) * count));
}

static void deallocate(T* pointer, size_t) noexcept
{
Free(pointer);
LS_tempfree(pointer);
}
};

Expand Down Expand Up @@ -135,6 +131,8 @@ void LS_InitEdictType(lua_State* state);
void LS_PushEdictValue(lua_State* state, int edictindex);
void LS_PushEdictValue(lua_State* state, const struct edict_s* edict);

void LS_InitEngineTables(lua_State* state);

void LS_InitProgsType(lua_State* state);
void LS_ResetProgsType();

Expand Down
Loading

0 comments on commit c223afa

Please sign in to comment.