summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp87
1 files changed, 84 insertions, 3 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 28c46c27e..1cf82d641 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -10,6 +10,7 @@
#include "Root.h"
#include "inifile/iniFile.h"
#include "ChunkMap.h"
+#include "Generating/ChunkDesc.h"
#include "OSSupport/Timer.h"
// Entities (except mobs):
@@ -238,6 +239,7 @@ cWorld::cWorld(const AString & a_WorldName) :
m_SkyDarkness(0),
m_Weather(eWeather_Sunny),
m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
+ m_GeneratorCallbacks(*this),
m_TickThread(*this)
{
LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str());
@@ -367,10 +369,13 @@ void cWorld::InitializeSpawn(void)
cWorldLoadProgress Progress(this);
// Wait for the loader to finish loading
- m_Storage.WaitForQueuesEmpty();
+ m_Storage.WaitForLoadQueueEmpty();
// Wait for the generator to finish generating
m_Generator.WaitForQueueEmpty();
+
+ // Wait for the loader to finish saving
+ m_Storage.WaitForSaveQueueEmpty();
Progress.Stop();
}
@@ -580,7 +585,7 @@ void cWorld::Start(void)
m_Lighting.Start(this);
m_Storage.Start(this, m_StorageSchema);
- m_Generator.Start(this, IniFile);
+ m_Generator.Start(m_GeneratorCallbacks, m_GeneratorCallbacks, IniFile);
m_ChunkSender.Start(this);
m_TickThread.Start();
@@ -723,6 +728,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
void cWorld::TickWeather(float a_Dt)
{
+ UNUSED(a_Dt);
// There are no weather changes anywhere but in the Overworld:
if (GetDimension() != dimOverworld)
{
@@ -794,7 +800,7 @@ void cWorld::TickMobs(float a_Dt)
cMonster::mfAmbient,
cMonster::mfWater,
} ;
- for (int i = 0; i < ARRAYCOUNT(AllFamilies); i++)
+ for (size_t i = 0; i < ARRAYCOUNT(AllFamilies); i++)
{
cMonster::eFamily Family = AllFamilies[i];
int SpawnDelay = cMonster::GetSpawnDelay(Family);
@@ -1643,6 +1649,7 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward)
void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff)
{
+ UNUSED(a_InitialVelocityCoeff);
cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec);
TNT->Initialize(this);
// TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff
@@ -2838,3 +2845,77 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World)
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cWorld::cChunkGeneratorCallbacks:
+
+cWorld::cChunkGeneratorCallbacks::cChunkGeneratorCallbacks(cWorld & a_World) :
+ m_World(&a_World)
+{
+}
+
+
+
+
+
+void cWorld::cChunkGeneratorCallbacks::OnChunkGenerated(cChunkDesc & a_ChunkDesc)
+{
+ cChunkDef::BlockNibbles BlockMetas;
+ a_ChunkDesc.CompressBlockMetas(BlockMetas);
+
+ m_World->SetChunkData(
+ a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(),
+ a_ChunkDesc.GetBlockTypes(), BlockMetas,
+ NULL, NULL, // We don't have lighting, chunk will be lighted when needed
+ &a_ChunkDesc.GetHeightMap(), &a_ChunkDesc.GetBiomeMap(),
+ a_ChunkDesc.GetEntities(), a_ChunkDesc.GetBlockEntities(),
+ true
+ );
+
+ // Save the chunk right after generating, so that we don't have to generate it again on next run
+ m_World->GetStorage().QueueSaveChunk(a_ChunkDesc.GetChunkX(), 0, a_ChunkDesc.GetChunkZ());
+}
+
+
+
+
+
+bool cWorld::cChunkGeneratorCallbacks::IsChunkValid(int a_ChunkX, int a_ChunkZ)
+{
+ return m_World->IsChunkValid(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
+bool cWorld::cChunkGeneratorCallbacks::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ)
+{
+ return m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
+void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerating(cChunkDesc & a_ChunkDesc)
+{
+ cPluginManager::Get()->CallHookChunkGenerating(
+ m_World, a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), &a_ChunkDesc
+ );
+}
+
+
+
+
+
+void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerated (cChunkDesc & a_ChunkDesc)
+{
+ cPluginManager::Get()->CallHookChunkGenerated(
+ m_World, a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), &a_ChunkDesc
+ );
+}
+
+
+
+
+