1
0
Fork 0

Initial Lua cChunkStay export.

This commit is contained in:
madmaxoft 2014-02-09 18:56:16 +01:00
parent 310a25c456
commit 9455f59b11
4 changed files with 123 additions and 1 deletions

View File

@ -24,6 +24,7 @@ $cfile "Plugin.h"
$cfile "PluginLua.h"
$cfile "WebPlugin.h"
$cfile "LuaWindow.h"
$cfile "LuaChunkStay.h"
$cfile "../BlockID.h"
$cfile "../StringUtils.h"
@ -70,6 +71,7 @@ $cfile "../Generating/ChunkDesc.h"
$cfile "../CraftingRecipes.h"
$cfile "../UI/Window.h"
$cfile "../Mobs/Monster.h"
$cfile "../ChunkStay.h"

View File

@ -0,0 +1,52 @@
// LuaChunkStay.cpp
// Implements the cLuaChunkStay class representing a cChunkStay binding for plugins
#include "Globals.h"
#include "LuaChunkStay.h"
#include "../World.h"
void cLuaChunkStay::Enable(
cWorld & a_World, cLuaState & a_LuaState,
const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable
)
{
if (m_LuaState != NULL)
{
LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call.");
a_LuaState.LogStackTrace();
return;
}
m_LuaState = &a_LuaState;
m_OnChunkAvailable = a_OnAllChunksAvailable;
m_OnAllChunksAvailable = a_OnAllChunksAvailable;
super::Enable(*a_World.GetChunkMap());
}
void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
{
m_LuaState->Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ);
}
void cLuaChunkStay::OnAllChunksAvailable(void)
{
m_LuaState->Call(m_OnAllChunksAvailable);
}

View File

@ -0,0 +1,58 @@
// LuaChunkStay.h
// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins
#pragma once
#include "LuaState.h"
#include "../ChunkStay.h"
// tolua_begin
class cLuaChunkStay
: public cChunkStay
{
typedef cChunkStay super;
public:
// Allow Lua to construct objects of this class:
cLuaChunkStay(void) {}
// Allow Lua to garbage-collect objects of this class:
~cLuaChunkStay() {}
// tolua_end
/** Enabled the ChunkStay for the specified world, with the specified Lua callbacks.
Exported in ManualBindings. */
void Enable(
cWorld & a_World, cLuaState & a_LuaState,
const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable
);
protected:
/** The Lua state associated with the callbacks. Only valid when enabled. */
cLuaState * m_LuaState;
/** The Lua function to call in OnChunkAvailable. Only valid when enabled. */
cLuaState::cRef m_OnChunkAvailable;
/** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */
cLuaState::cRef m_OnAllChunksAvailable;
// cChunkStay overrides:
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override;
virtual void OnAllChunksAvailable(void) override;
} ; // tolua_export

View File

@ -32,12 +32,16 @@ This class is abstract, the descendants are expected to provide the OnChunkAvail
the OnAllChunksAvailable() callback implementations. Note that those are called from the contexts of
different threads' - the caller, the Loader or the Generator thread.
*/
// tolua_begin
class cChunkStay
{
public:
// tolua_end
cChunkStay(void);
~cChunkStay();
// tolua_begin
void Clear(void);
/** Adds a chunk to be locked from unloading.
@ -48,14 +52,20 @@ public:
To be used only while the ChunkStay object is not enabled. */
void Remove(int a_ChunkX, int a_ChunkZ);
// tolua_end
/** Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.
All the contained chunks are queued for loading / generating. */
void Enable (cChunkMap & a_ChunkMap);
// tolua_begin
/** Disables the ChunkStay, the chunks are released and the ChunkStay
object can be edited with Add() and Remove() again*/
void Disable(void);
// tolua_end
/** Returns all the chunks that should be kept */
const cChunkCoordsVector & GetChunks(void) const { return m_Chunks; }
@ -84,7 +94,7 @@ protected:
/** Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks.
May be called for chunks outside this ChunkStay. */
void ChunkAvailable(int a_ChunkX, int a_ChunkZ);
} ;
} ; // tolua_export