2014-02-09 12:56:16 -05:00
|
|
|
|
|
|
|
// LuaChunkStay.h
|
|
|
|
|
2014-02-10 16:47:10 -05:00
|
|
|
// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins, used by cWorld:ChunkStay() Lua API
|
2014-02-09 12:56:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "LuaState.h"
|
|
|
|
#include "../ChunkStay.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-10 16:47:10 -05:00
|
|
|
// fwd:
|
2014-09-26 11:26:03 -04:00
|
|
|
class cChunkMap;
|
2014-02-10 16:47:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cLuaChunkStay:
|
|
|
|
public cChunkStay
|
2014-02-09 12:56:16 -05:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cChunkStay;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-09 12:56:16 -05:00
|
|
|
public:
|
2016-08-14 10:26:31 -04:00
|
|
|
cLuaChunkStay();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-05-20 02:16:28 -04:00
|
|
|
virtual ~cLuaChunkStay() override { }
|
2014-02-09 12:56:16 -05:00
|
|
|
|
2016-08-14 10:26:31 -04:00
|
|
|
/** Adds chunks in the specified Lua table.
|
|
|
|
Can be called only once.
|
2014-02-10 16:47:10 -05:00
|
|
|
Returns true if any chunk added, false (plus log warning) if none. */
|
2016-08-14 10:26:31 -04:00
|
|
|
bool AddChunks(const cLuaState::cStackTable & a_ChunkCoords);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-10 16:47:10 -05:00
|
|
|
/** Enables the ChunkStay for the specified chunkmap, with the specified Lua callbacks. */
|
2016-06-12 10:53:24 -04:00
|
|
|
void Enable(cChunkMap & a_ChunkMap, cLuaState::cCallbackPtr a_OnChunkAvailable, cLuaState::cCallbackPtr a_OnAllChunksAvailable);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-09 12:56:16 -05:00
|
|
|
protected:
|
|
|
|
/** The Lua function to call in OnChunkAvailable. Only valid when enabled. */
|
2016-06-12 10:53:24 -04:00
|
|
|
cLuaState::cCallbackPtr m_OnChunkAvailable;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-09 12:56:16 -05:00
|
|
|
/** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */
|
2016-06-12 10:53:24 -04:00
|
|
|
cLuaState::cCallbackPtr m_OnAllChunksAvailable;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2014-02-09 12:56:16 -05:00
|
|
|
// cChunkStay overrides:
|
|
|
|
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override;
|
2014-02-10 16:47:10 -05:00
|
|
|
virtual bool OnAllChunksAvailable(void) override;
|
|
|
|
virtual void OnDisabled(void) override;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-10 16:47:10 -05:00
|
|
|
/** Adds a single chunk coord from the table at the top of the Lua stack.
|
|
|
|
Expects the top element to be a table, checks that it contains two numbers.
|
|
|
|
Uses those two numbers as chunk coords appended to m_Chunks.
|
|
|
|
If the coords are already present, gives a warning and ignores the pair.
|
|
|
|
The a_Index parameter is only for the error messages. */
|
|
|
|
void AddChunkCoord(cLuaState & a_LuaState, int a_Index);
|
2014-02-09 14:39:45 -05:00
|
|
|
} ;
|
|
|
|
|
2014-02-09 12:56:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|