diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-18 21:10:51 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-18 21:10:51 +0200 |
commit | 37140ae57835680d2c4fb3aa365082622d3a150e (patch) | |
tree | 89a636c74375b3c9f0fe77b20ecbadc693bd0989 /src/World.cpp | |
parent | Merge branch 'master' of https://github.com/mc-server/MCServer into portals (diff) | |
parent | Monster fixes (diff) | |
download | cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar.gz cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar.bz2 cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar.lz cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar.xz cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.tar.zst cuberite-37140ae57835680d2c4fb3aa365082622d3a150e.zip |
Diffstat (limited to 'src/World.cpp')
-rw-r--r-- | src/World.cpp | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/src/World.cpp b/src/World.cpp index 4c57b283f..e32771353 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -73,7 +73,7 @@ const int TIME_SPAWN_DIVISOR = 148; -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorldLoadProgress: /// A simple thread that displays the progress of world loading / saving in cWorld::InitializeSpawn() @@ -102,7 +102,7 @@ protected: { for (;;) { - LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate", + LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); @@ -125,7 +125,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorldLightingProgress: /// A simple thread that displays the progress of world lighting in cWorld::InitializeSpawn() @@ -175,7 +175,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cLock: cWorld::cLock::cLock(cWorld & a_World) : @@ -187,7 +187,7 @@ cWorld::cLock::cLock(cWorld & a_World) : -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cTickThread: cWorld::cTickThread::cTickThread(cWorld & a_World) : @@ -229,7 +229,7 @@ void cWorld::cTickThread::Execute(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld: cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_OverworldName) : @@ -381,22 +381,20 @@ void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ) void cWorld::InitializeSpawn(void) { - if (!m_IsSpawnExplicitlySet) // Check if spawn position was already explicitly set or not + if (!m_IsSpawnExplicitlySet) { - GenerateRandomSpawn(); // Generate random solid-land coordinate and then write it to the world configuration - + // Spawn position wasn't already explicitly set, enerate random solid-land coordinate and then write it to the world configuration: + GenerateRandomSpawn(); cIniFile IniFile; IniFile.ReadFile(m_IniFileName); - IniFile.SetValueF("SpawnPosition", "X", m_SpawnX); IniFile.SetValueF("SpawnPosition", "Y", m_SpawnY); IniFile.SetValueF("SpawnPosition", "Z", m_SpawnZ); - IniFile.WriteFile(m_IniFileName); } - int ChunkX = 0, ChunkY = 0, ChunkZ = 0; - BlockToChunk((int)m_SpawnX, (int)m_SpawnY, (int)m_SpawnZ, ChunkX, ChunkY, ChunkZ); + int ChunkX = 0, ChunkZ = 0; + cChunkDef::BlockToChunk((int)m_SpawnX, (int)m_SpawnZ, ChunkX, ChunkZ); // For the debugging builds, don't make the server build too much world upon start: #if defined(_DEBUG) || defined(ANDROID_NDK) @@ -698,7 +696,7 @@ void cWorld::GenerateRandomSpawn(void) while (IsBlockWaterOrIce(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ))) { - if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords + if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords { m_SpawnX += cChunkDef::Width; } @@ -708,7 +706,7 @@ void cWorld::GenerateRandomSpawn(void) } } - m_SpawnY = (double)GetHeight((int)m_SpawnX, (int)m_SpawnZ) + 1.6f; // 1.6f to accomodate player height + m_SpawnY = (double)GetHeight((int)m_SpawnX, (int)m_SpawnZ) + 1.6f; // 1.6f to accomodate player height LOGD("Generated random spawnpoint %i %i %i", (int)m_SpawnX, (int)m_SpawnY, (int)m_SpawnZ); } @@ -841,12 +839,12 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) m_ChunkMap->FastSetQueuedBlocks(); - if (m_WorldAge - m_LastSave > 60 * 5 * 20) // Save each 5 minutes + if (m_WorldAge - m_LastSave > 60 * 5 * 20) // Save each 5 minutes { SaveAllChunks(); } - if (m_WorldAge - m_LastUnload > 10 * 20) // Unload every 10 seconds + if (m_WorldAge - m_LastUnload > 10 * 20) // Unload every 10 seconds { UnloadUnusedChunks(); } @@ -932,8 +930,8 @@ void cWorld::TickMobs(float a_Dt) SpawnMobFinalize(*itr2); } } - } // for i - AllFamilies[] - } // if (Spawning enabled) + } // for i - AllFamilies[] + } // if (Spawning enabled) // 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) @@ -1043,7 +1041,7 @@ void cWorld::TickClients(float a_Dt) for (cClientHandleList::iterator itr = RemoveClients.begin(); itr != RemoveClients.end(); ++itr) { delete *itr; - } // for itr - RemoveClients[] + } // for itr - RemoveClients[] } @@ -1159,7 +1157,7 @@ void cWorld::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_Blo Vector3d explosion_pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); cVector3iArray BlocksAffected; m_ChunkMap->DoExplosionAt(a_ExplosionSize, a_BlockX, a_BlockY, a_BlockZ, BlocksAffected); - BroadcastSoundEffect("random.explode", (int)floor(a_BlockX * 8), (int)floor(a_BlockY * 8), (int)floor(a_BlockZ * 8), 1.0f, 0.6f); + BroadcastSoundEffect("random.explode", (double)a_BlockX, (double)a_BlockY, (double)a_BlockZ, 1.0f, 0.6f); { cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) @@ -1948,9 +1946,9 @@ void cWorld::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer -void cWorld::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude) +void cWorld::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) { - m_ChunkMap->BroadcastCollectPickup(a_Pickup, a_Player, a_Exclude); + m_ChunkMap->BroadcastCollectEntity(a_Entity, a_Player, a_Exclude); } @@ -2145,9 +2143,9 @@ void cWorld::BroadcastDisplayObjective(const AString & a_Objective, cScoreboard: -void cWorld::BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) +void cWorld::BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) { - m_ChunkMap->BroadcastSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch, a_Exclude); + m_ChunkMap->BroadcastSoundEffect(a_SoundName, a_X, a_Y, a_Z, a_Volume, a_Pitch, a_Exclude); } @@ -2253,9 +2251,18 @@ void cWorld::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHa -void cWorld::MarkChunkDirty (int a_ChunkX, int a_ChunkZ) +void cWorld::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ) { - m_ChunkMap->MarkChunkDirty (a_ChunkX, a_ChunkZ); + m_ChunkMap->MarkRedstoneDirty(a_ChunkX, a_ChunkZ); +} + + + + + +void cWorld::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty) +{ + m_ChunkMap->MarkChunkDirty(a_ChunkX, a_ChunkZ, a_MarkRedstoneDirty); } @@ -2288,7 +2295,7 @@ void cWorld::SetChunkData( const NIBBLETYPE * a_BlockSkyLight, const cChunkDef::HeightMap * a_HeightMap, const cChunkDef::BiomeMap * a_BiomeMap, - cEntityList & a_Entities, + cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, bool a_MarkDirty ) @@ -2304,7 +2311,7 @@ void cWorld::SetChunkData( } m_ChunkMap->SetChunkData( - a_ChunkX, a_ChunkZ, + a_ChunkX, a_ChunkZ, a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, a_HeightMap, *Biomes, a_BlockEntities, @@ -2427,7 +2434,7 @@ void cWorld::RemovePlayer(cPlayer * a_Player) } { cCSLock Lock(m_CSPlayers); - LOGD("Removing player %s from world \"%s\".", a_Player->GetName().c_str(), m_WorldName.c_str()); + LOGD("Removing player %s from world \"%s\"", a_Player->GetName().c_str(), m_WorldName.c_str()); m_Players.remove(a_Player); } @@ -2532,10 +2539,13 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, if (Distance < ClosestDistance) { - if (a_CheckLineOfSight && !LineOfSight.Trace(a_Pos,(Pos - a_Pos),(int)(Pos - a_Pos).Length())) + if (a_CheckLineOfSight) { - ClosestDistance = Distance; - ClosestPlayer = *itr; + if(!LineOfSight.Trace(a_Pos,(Pos - a_Pos),(int)(Pos - a_Pos).Length())) + { + ClosestDistance = Distance; + ClosestPlayer = *itr; + } } else { @@ -2840,10 +2850,8 @@ bool cWorld::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunk void cWorld::SaveAllChunks(void) { - LOGINFO("Saving all chunks..."); m_LastSave = m_WorldAge; m_ChunkMap->SaveAllChunks(); - m_Storage.QueueSavedMessage(); } @@ -2926,7 +2934,7 @@ bool cWorld::HasEntity(int a_UniqueID) unsigned int cWorld::GetNumPlayers(void) { cCSLock Lock(m_CSPlayers); - return m_Players.size(); + return m_Players.size(); } */ @@ -2970,11 +2978,11 @@ void cWorld::TickQueuedBlocks(void) { // TODO: Handle the case when the chunk is already unloaded m_ChunkMap->TickBlock(Block->X, Block->Y, Block->Z); - delete Block; // We don't have to remove it from the vector, this will happen automatically on the next tick + delete Block; // We don't have to remove it from the vector, this will happen automatically on the next tick } else { - m_BlockTickQueue.push_back(Block); // Keep the block in the queue + m_BlockTickQueue.push_back(Block); // Keep the block in the queue } } // for itr - m_BlockTickQueueCopy[] } @@ -3055,7 +3063,7 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster) -int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem & a_Item, const Vector3d * a_Speed) +int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed) { cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Item, a_Speed); if (Projectile == NULL) @@ -3080,18 +3088,18 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) { - size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space + size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space - AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word + AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word AString PlayerName ((*itr)->GetName()); - size_t Found = PlayerName.find(LastWord); // Try to find last word in playername + size_t Found = PlayerName.find(LastWord); // Try to find last word in playername if (Found == AString::npos) { - continue; // No match + continue; // No match } - a_Results.push_back(PlayerName); // Match! + a_Results.push_back(PlayerName); // Match! } } @@ -3099,6 +3107,15 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul +void cWorld::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) +{ + m_ChunkMap->SetChunkAlwaysTicked(a_ChunkX, a_ChunkZ, a_AlwaysTicked); +} + + + + + cRedstoneSimulator * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile) { AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", ""); @@ -3251,7 +3268,7 @@ void cWorld::AddQueuedPlayers(void) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskSaveAllChunks: void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) @@ -3263,7 +3280,7 @@ void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskUnloadUnusedChunks void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World) @@ -3275,7 +3292,7 @@ void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cTaskSendBlockTo cWorld::cTaskSendBlockToAllPlayers::cTaskSendBlockToAllPlayers(std::vector<Vector3i> & a_SendQueue) : @@ -3318,7 +3335,7 @@ void cWorld::cTaskSendBlockToAllPlayers::Run(cWorld & a_World) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cWorld::cChunkGeneratorCallbacks: cWorld::cChunkGeneratorCallbacks::cChunkGeneratorCallbacks(cWorld & a_World) : |