30 if (!lua_istable(a_LuaState, -1))
32 LOGWARNING(
"%s: Element #%d is not a table (got %s). Ignoring the element.",
33 __FUNCTION__, a_Index, lua_typename(a_LuaState, -1)
36 lua_pop(a_LuaState, 1);
47 LOGWARNING(
"%s: No valid chunk coords.", __FUNCTION__);
63 int NumCoords = luaL_getn(L, -1);
66 LOGWARNING(
"%s: Element #%d doesn't contain 2 coords (got %d). Ignoring the element.",
67 __FUNCTION__, a_Index, NumCoords
73 lua_rawgeti(L, -1, 1);
74 lua_rawgeti(L, -2, 2);
75 int ChunkX = luaL_checkint(L, -2);
76 int ChunkZ = luaL_checkint(L, -1);
80 for (cChunkCoordsVector::iterator itr =
m_Chunks.begin(), end =
m_Chunks.end(); itr != end; ++itr)
82 if ((itr->m_ChunkX == ChunkX) && (itr->m_ChunkZ == ChunkZ))
84 LOGWARNING(
"%s: Element #%d is a duplicate, ignoring it.",
91 m_Chunks.emplace_back(ChunkX, ChunkZ);
void LOGWARNING(std::string_view a_Format, const Args &... args)
cLuaState::cCallbackPtr m_OnChunkAvailable
The Lua function to call in OnChunkAvailable.
cLuaState::cCallbackPtr m_OnAllChunksAvailable
The Lua function to call in OnAllChunksAvailable.
bool AddChunks(const cLuaState::cStackTable &a_ChunkCoords)
Adds chunks in the specified Lua table.
void AddChunkCoord(cLuaState &a_LuaState, int a_Index)
Adds a single chunk coord from the table at the top of the Lua stack.
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override
Called when a specific chunk become available.
virtual bool OnAllChunksAvailable(void) override
Called once all of the contained chunks are available.
void Enable(cChunkMap &a_ChunkMap, cLuaState::cCallbackPtr a_OnChunkAvailable, cLuaState::cCallbackPtr a_OnAllChunksAvailable)
Enables the ChunkStay for the specified chunkmap, with the specified Lua callbacks.
virtual void OnDisabled(void) override
Called by the ChunkMap when the ChunkStay is disabled.
Encapsulates a Lua state and provides some syntactic sugar for common operations.
void LogStackTrace(int a_StartingDepth=0)
Logs all items in the current stack trace to the server console.
std::unique_ptr< cCallback > cCallbackPtr
Represents a table on the Lua stack.
cLuaState & GetLuaState(void) const
void ForEachArrayElement(cFunctionRef< bool(cLuaState &a_LuaState, int a_Index)> a_ElementCallback) const
Iterates over all array elements in the table consecutively and calls the a_ElementCallback for each.
void Enable(cChunkMap &a_ChunkMap)
Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.
cChunkCoordsVector m_Chunks
The list of chunks to lock from unloading.