From 11f8198a8054e2b50df3fdbd8a59a876d7db87f0 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 02:56:46 -0700 Subject: World.cpp: fixed not all enum fields being used in m_Dimension switch --- src/World.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 186842b20..c27fd462b 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -570,12 +570,13 @@ void cWorld::Start(void) m_TNTShrapnelLevel = (eShrapnelLevel)Clamp(TNTShrapnelLevel, (int)slNone, (int)slAll); // Load allowed mobs: - const char * DefaultMonsters = ""; + AString DefaultMonsters; switch (m_Dimension) { case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break; case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break; case dimEnd: DefaultMonsters = "enderman"; break; + case dimNotSet: break; } m_bAnimals = IniFile.GetValueSetB("Monsters", "AnimalsOn", true); AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters); -- cgit v1.2.3 From 00c524519ef6c7ceaf4ac91307617cfd65d7cf21 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 19 Jul 2014 14:53:41 +0200 Subject: Fixed style: spaces after commas. --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index c27fd462b..d90383884 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2469,7 +2469,7 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, { if (a_CheckLineOfSight) { - if(!LineOfSight.Trace(a_Pos,(Pos - a_Pos),(int)(Pos - a_Pos).Length())) + if(!LineOfSight.Trace(a_Pos, (Pos - a_Pos), (int)(Pos - a_Pos).Length())) { ClosestDistance = Distance; ClosestPlayer = *itr; -- cgit v1.2.3 From 6be79575fd50e37ac275bd0cb9d16f9e51e8a225 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 20 Jul 2014 23:10:31 +0200 Subject: Style: Normalized spaces after if, for and while. --- src/World.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index d90383884..c146338d7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -865,14 +865,14 @@ void cWorld::TickMobs(float a_Dt) // move close mobs cMobProximityCounter::sIterablePair allCloseEnoughToMoveMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(-1, 64 * 16);// MG TODO : deal with this magic number (the 16 is the size of a block) - for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allCloseEnoughToMoveMobs.m_Begin; itr != allCloseEnoughToMoveMobs.m_End; ++itr) + for (cMobProximityCounter::tDistanceToMonster::const_iterator itr = allCloseEnoughToMoveMobs.m_Begin; itr != allCloseEnoughToMoveMobs.m_End; ++itr) { itr->second.m_Monster.Tick(a_Dt, itr->second.m_Chunk); } // remove too far mobs cMobProximityCounter::sIterablePair allTooFarMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(128 * 16, -1);// MG TODO : deal with this magic number (the 16 is the size of a block) - for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allTooFarMobs.m_Begin; itr != allTooFarMobs.m_End; ++itr) + for (cMobProximityCounter::tDistanceToMonster::const_iterator itr = allTooFarMobs.m_Begin; itr != allTooFarMobs.m_End; ++itr) { itr->second.m_Monster.Destroy(true); } @@ -2469,7 +2469,7 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, { if (a_CheckLineOfSight) { - if(!LineOfSight.Trace(a_Pos, (Pos - a_Pos), (int)(Pos - a_Pos).Length())) + if (!LineOfSight.Trace(a_Pos, (Pos - a_Pos), (int)(Pos - a_Pos).Length())) { ClosestDistance = Distance; ClosestPlayer = *itr; -- cgit v1.2.3 From 93d29555e58df172bafba530afbc593c16ec66a3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 21 Jul 2014 15:19:48 +0200 Subject: Style: Normalized to no spaces before closing parenthesis. --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index c146338d7..4ddd11f59 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -617,7 +617,7 @@ void cWorld::Start(void) m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1); m_Lighting.Start(this); - m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor ); + m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor); m_Generator.Start(m_GeneratorCallbacks, m_GeneratorCallbacks, IniFile); m_ChunkSender.Start(this); m_TickThread.Start(); -- cgit v1.2.3 From 9678341a11caa08a40c3ddb562d893fc0cd2ba73 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 24 Jul 2014 12:15:48 +0200 Subject: Made the cWorld::SpawnMobFinalize function more readable. --- src/World.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 4ddd11f59..104805209 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2975,21 +2975,31 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eTyp int cWorld::SpawnMobFinalize(cMonster * a_Monster) { + // Invalid cMonster object. Bail out. if (!a_Monster) + { return -1; + } + + // Give the mob full health. a_Monster->SetHealth(a_Monster->GetMaxHealth()); + + // A plugin doesn't agree with the spawn. bail out. if (cPluginManager::Get()->CallHookSpawningMonster(*this, *a_Monster)) { delete a_Monster; a_Monster = NULL; return -1; } + + // Initialize the monster into the current world. if (!a_Monster->Initialize(*this)) { delete a_Monster; a_Monster = NULL; return -1; } + BroadcastSpawnEntity(*a_Monster); cPluginManager::Get()->CallHookSpawnedMonster(*this, *a_Monster); -- cgit v1.2.3 From c0b62ef139a65ca648135fb6999e6623438fdd71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Jul 2014 18:32:05 +0200 Subject: Added a queue for setting chunk data. Fixes #1196. --- src/World.cpp | 85 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 32 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 104805209..7ad350e24 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -11,6 +11,7 @@ #include "ChunkMap.h" #include "Generating/ChunkDesc.h" #include "OSSupport/Timer.h" +#include "SetChunkData.h" // Serializers #include "WorldStorage/ScoreboardSerializer.h" @@ -719,6 +720,17 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) // Call the plugins cPluginManager::Get()->CallHookWorldTick(*this, a_Dt, a_LastTickDurationMSec); + // Set any chunk data that has been queued for setting: + cSetChunkDataPtrs SetChunkDataQueue; + { + cCSLock Lock(m_CSSetChunkDataQueue); + std::swap(SetChunkDataQueue, m_SetChunkDataQueue); + } + for (cSetChunkDataPtrs::iterator itr = SetChunkDataQueue.begin(), end = SetChunkDataQueue.end(); itr != end; ++itr) + { + SetChunkData(**itr); + } // for itr - SetChunkDataQueue[] + // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it m_WorldAgeSecs += (double)a_Dt / 1000.0; m_TimeOfDaySecs += (double)a_Dt / 1000.0; @@ -2217,47 +2229,59 @@ void cWorld::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) -void cWorld::SetChunkData( - int a_ChunkX, int a_ChunkZ, - const BLOCKTYPE * a_BlockTypes, - const NIBBLETYPE * a_BlockMeta, - const NIBBLETYPE * a_BlockLight, - const NIBBLETYPE * a_BlockSkyLight, - const cChunkDef::HeightMap * a_HeightMap, - const cChunkDef::BiomeMap * a_BiomeMap, - cEntityList & a_Entities, - cBlockEntityList & a_BlockEntities, - bool a_MarkDirty -) +void cWorld::QueueSetChunkData(const cSetChunkDataPtr & a_SetChunkData) { // Validate biomes, if needed: - cChunkDef::BiomeMap BiomeMap; - const cChunkDef::BiomeMap * Biomes = a_BiomeMap; - if (a_BiomeMap == NULL) + if (!a_SetChunkData->AreBiomesValid()) { // The biomes are not assigned, get them from the generator: - Biomes = &BiomeMap; - m_Generator.GenerateBiomes(a_ChunkX, a_ChunkZ, BiomeMap); + m_Generator.GenerateBiomes(a_SetChunkData->GetChunkX(), a_SetChunkData->GetChunkZ(), a_SetChunkData->GetBiomes()); + a_SetChunkData->MarkBiomesValid(); } - m_ChunkMap->SetChunkData( - a_ChunkX, a_ChunkZ, - a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, - a_HeightMap, *Biomes, - a_BlockEntities, - a_MarkDirty - ); + // Validate heightmap, if needed: + if (!a_SetChunkData->IsHeightMapValid()) + { + a_SetChunkData->CalculateHeightMap(); + } + + // Store a copy of the data in the queue: + // TODO: If the queue is too large, wait for it to get processed. Not likely, though. + cCSLock Lock(m_CSSetChunkDataQueue); + m_SetChunkDataQueue.push_back(a_SetChunkData); +} + + + + + +void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) +{ + ASSERT(a_SetChunkData.AreBiomesValid()); + ASSERT(a_SetChunkData.IsHeightMapValid()); + + m_ChunkMap->SetChunkData(a_SetChunkData); // Initialize the entities (outside the m_ChunkMap's CS, to fix FS #347): - for (cEntityList::iterator itr = a_Entities.begin(), end = a_Entities.end(); itr != end; ++itr) + cEntityList Entities; + std::swap(a_SetChunkData.GetEntities(), Entities); + for (cEntityList::iterator itr = Entities.begin(), end = Entities.end(); itr != end; ++itr) { (*itr)->Initialize(*this); } // If a client is requesting this chunk, send it to them: - if (m_ChunkMap->HasChunkAnyClients(a_ChunkX, a_ChunkZ)) + int ChunkX = a_SetChunkData.GetChunkX(); + int ChunkZ = a_SetChunkData.GetChunkZ(); + if (m_ChunkMap->HasChunkAnyClients(ChunkX, ChunkZ)) + { + m_ChunkSender.ChunkReady(ChunkX, ChunkZ); + } + + // Save the chunk right after generating, so that we don't have to generate it again on next run + if (a_SetChunkData.ShouldMarkDirty()) { - m_ChunkSender.ChunkReady(a_ChunkX, a_ChunkZ); + m_Storage.QueueSaveChunk(ChunkX, 0, ChunkZ); } } @@ -3295,17 +3319,14 @@ void cWorld::cChunkGeneratorCallbacks::OnChunkGenerated(cChunkDesc & a_ChunkDesc cChunkDef::BlockNibbles BlockMetas; a_ChunkDesc.CompressBlockMetas(BlockMetas); - m_World->SetChunkData( + m_World->QueueSetChunkData(cSetChunkDataPtr(new cSetChunkData( 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()); + ))); } -- cgit v1.2.3