summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/LuaState.cpp36
-rw-r--r--src/Bindings/LuaState.h3
-rw-r--r--src/Bindings/ManualBindings.cpp8
-rw-r--r--src/World.cpp22
-rw-r--r--src/World.h17
-rw-r--r--src/WorldStorage/WSSAnvil.cpp8
6 files changed, 81 insertions, 13 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 24e64d9b2..c6be7be3c 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -944,10 +944,42 @@ bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam)
lua_Debug entry;
VERIFY(lua_getstack(m_LuaState, 0, &entry));
VERIFY(lua_getinfo (m_LuaState, "n", &entry));
- AString ErrMsg = Printf("Error in function '%s' parameter #%d. Function expected, got %s",
+ luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s",
+ (entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str()
+ );
+ return false;
+ } // for i - Param
+
+ // All params checked ok
+ return true;
+}
+
+
+
+
+
+bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam)
+{
+ ASSERT(IsValid());
+
+ if (a_EndParam < 0)
+ {
+ a_EndParam = a_StartParam;
+ }
+
+ for (int i = a_StartParam; i <= a_EndParam; i++)
+ {
+ if (lua_isfunction(m_LuaState, i) || lua_isnil(m_LuaState, i))
+ {
+ continue;
+ }
+ // Not the correct parameter
+ lua_Debug entry;
+ VERIFY(lua_getstack(m_LuaState, 0, &entry));
+ VERIFY(lua_getinfo (m_LuaState, "n", &entry));
+ luaL_error(m_LuaState, "Error in function '%s' parameter #%d. Function expected, got %s",
(entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str()
);
- LogStackTrace();
return false;
} // for i - Param
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 1c9c99e69..b9bf10142 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -833,6 +833,9 @@ public:
/** Returns true if the specified parameters on the stack are functions; also logs warning if not */
bool CheckParamFunction(int a_StartParam, int a_EndParam = -1);
+ /** Returns true if the specified parameters on the stack are functions or nils; also logs warning if not */
+ bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam = -1);
+
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
bool CheckParamEnd(int a_Param);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index f0bad92e8..2a7631120 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1648,9 +1648,9 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
cLuaState L(tolua_S);
if (
- !L.CheckParamUserType(1, "cWorld") ||
- !L.CheckParamTable (2) ||
- !L.CheckParamFunction(3, 4)
+ !L.CheckParamUserType (1, "cWorld") ||
+ !L.CheckParamTable (2) ||
+ !L.CheckParamFunctionOrNil(3, 4)
)
{
return 0;
@@ -1671,12 +1671,10 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
L.LogStackTrace();
return 0;
}
- L.LogStack("Before AddChunks()");
if (!ChunkStay->AddChunks(2))
{
return 0;
}
- L.LogStack("After params read");
ChunkStay->Enable(*World->GetChunkMap(), 3, 4);
return 0;
diff --git a/src/World.cpp b/src/World.cpp
index f8c1091f0..cb07caa5d 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2213,6 +2213,15 @@ void cWorld::UnloadUnusedChunks(void)
+void cWorld::QueueUnloadUnusedChunks(void)
+{
+ QueueTask(new cWorld::cTaskUnloadUnusedChunks);
+}
+
+
+
+
+
void cWorld::CollectPickupsByPlayer(cPlayer * a_Player)
{
m_ChunkMap->CollectPickupsByPlayer(a_Player);
@@ -2945,6 +2954,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cWorld::cTaskSaveAllChunks:
@@ -2958,6 +2968,18 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cWorld::cTaskUnloadUnusedChunks
+
+void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World)
+{
+ a_World.UnloadUnusedChunks();
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cWorld::cChunkGeneratorCallbacks:
cWorld::cChunkGeneratorCallbacks::cChunkGeneratorCallbacks(cWorld & a_World) :
diff --git a/src/World.h b/src/World.h
index fa83fe73e..ca1b7dcc5 100644
--- a/src/World.h
+++ b/src/World.h
@@ -99,6 +99,15 @@ public:
} ;
+ class cTaskUnloadUnusedChunks :
+ public cTask
+ {
+ protected:
+ // cTask overrides:
+ virtual void Run(cWorld & a_World) override;
+ };
+
+
static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
{
return "cWorld";
@@ -183,7 +192,7 @@ public:
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
- void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL);
+ void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
void BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
@@ -243,7 +252,8 @@ public:
bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const;
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const;
- void UnloadUnusedChunks(void); // tolua_export
+ /** Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/
+ void QueueUnloadUnusedChunks(void); // tolua_export
void CollectPickupsByPlayer(cPlayer * a_Player);
@@ -866,6 +876,9 @@ private:
/** Ticks all clients that are in this world */
void TickClients(float a_Dt);
+ /** Unloads all chunks immediately.*/
+ void UnloadUnusedChunks(void);
+
void UpdateSkyDarkness(void);
/** <summary>Generates a random spawnpoint on solid land by walking chunks and finding their biomes</summary> */
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index d72165c46..e95813a3c 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -1083,6 +1083,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadHorseFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
+ else if (strncmp(a_IDTag, "Villager", a_IDTagLength) == 0)
+ {
+ LoadVillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
else if (strncmp(a_IDTag, "VillagerGolem", a_IDTagLength) == 0)
{
LoadIronGolemFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
@@ -1131,10 +1135,6 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadSquidFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
- else if (strncmp(a_IDTag, "Villager", a_IDTagLength) == 0)
- {
- LoadVillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
- }
else if (strncmp(a_IDTag, "Witch", a_IDTagLength) == 0)
{
LoadWitchFromNBT(a_Entities, a_NBT, a_EntityTagIdx);