Project modernization (#630)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
|
||||
WeighedTreasureArray ServerLevel::RANDOM_BONUS_ITEMS;
|
||||
|
||||
C4JThread* ServerLevel::m_updateThread = NULL;
|
||||
C4JThread* ServerLevel::m_updateThread = nullptr;
|
||||
C4JThread::EventArray* ServerLevel::m_updateTrigger;
|
||||
CRITICAL_SECTION ServerLevel::m_updateCS[3];
|
||||
|
||||
@@ -63,7 +63,7 @@ void ServerLevel::staticCtor()
|
||||
InitializeCriticalSection(&m_updateCS[1]);
|
||||
InitializeCriticalSection(&m_updateCS[2]);
|
||||
|
||||
m_updateThread = new C4JThread(runUpdate, NULL, "Tile update");
|
||||
m_updateThread = new C4JThread(runUpdate, nullptr, "Tile update");
|
||||
m_updateThread->SetProcessor(CPU_CORE_TILE_UPDATE);
|
||||
#ifdef __ORBIS__
|
||||
m_updateThread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL); // On Orbis, this core is also used for Matching 2, and that priority of that seems to be always at default no matter what we set it to. Prioritise this below Matching 2.
|
||||
@@ -123,7 +123,7 @@ ServerLevel::ServerLevel(MinecraftServer *server, shared_ptr<LevelStorage>levelS
|
||||
scoreboard = new ServerScoreboard(server);
|
||||
|
||||
//shared_ptr<ScoreboardSaveData> scoreboardSaveData = dynamic_pointer_cast<ScoreboardSaveData>( savedDataStorage->get(typeid(ScoreboardSaveData), ScoreboardSaveData::FILE_ID) );
|
||||
//if (scoreboardSaveData == NULL)
|
||||
//if (scoreboardSaveData == nullptr)
|
||||
//{
|
||||
// scoreboardSaveData = shared_ptr<ScoreboardSaveData>( new ScoreboardSaveData() );
|
||||
// savedDataStorage->set(ScoreboardSaveData::FILE_ID, scoreboardSaveData);
|
||||
@@ -258,7 +258,7 @@ void ServerLevel::tick()
|
||||
{
|
||||
//app.DebugPrintf("Incremental save\n");
|
||||
PIXBeginNamedEvent(0,"Incremental save");
|
||||
save(false, NULL);
|
||||
save(false, nullptr);
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
|
||||
@@ -313,9 +313,9 @@ void ServerLevel::tick()
|
||||
Biome::MobSpawnerData *ServerLevel::getRandomMobSpawnAt(MobCategory *mobCategory, int x, int y, int z)
|
||||
{
|
||||
vector<Biome::MobSpawnerData *> *mobList = getChunkSource()->getMobsAt(mobCategory, x, y, z);
|
||||
if (mobList == NULL || mobList->empty()) return NULL;
|
||||
if (mobList == nullptr || mobList->empty()) return nullptr;
|
||||
|
||||
return (Biome::MobSpawnerData *) WeighedRandom::getRandomItem(random, (vector<WeighedRandomItem *> *)mobList);
|
||||
return static_cast<Biome::MobSpawnerData *>(WeighedRandom::getRandomItem(random, (vector<WeighedRandomItem *> *)mobList));
|
||||
}
|
||||
|
||||
void ServerLevel::updateSleepingPlayerList()
|
||||
@@ -433,7 +433,7 @@ void ServerLevel::tickTiles()
|
||||
if( hasChunkAt(x,y,z) )
|
||||
{
|
||||
int id = getTile(x,y,z);
|
||||
if (Tile::tiles[id] != NULL && Tile::tiles[id]->isTicking())
|
||||
if (Tile::tiles[id] != nullptr && Tile::tiles[id]->isTicking())
|
||||
{
|
||||
/*if(id == 2) ++grassTicks;
|
||||
else if(id == 11) ++lavaTicks;
|
||||
@@ -497,7 +497,7 @@ void ServerLevel::tickTiles()
|
||||
|
||||
if (isRainingAt(x, y, z))
|
||||
{
|
||||
addGlobalEntity( shared_ptr<LightningBolt>( new LightningBolt(this, x, y, z) ) );
|
||||
addGlobalEntity(std::make_shared<LightningBolt>(this, x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,8 +640,8 @@ void ServerLevel::resetEmptyTime()
|
||||
bool ServerLevel::tickPendingTicks(bool force)
|
||||
{
|
||||
EnterCriticalSection(&m_tickNextTickCS);
|
||||
int count = (int)tickNextTickList.size();
|
||||
int count2 = (int)tickNextTickSet.size();
|
||||
int count = static_cast<int>(tickNextTickList.size());
|
||||
int count2 = static_cast<int>(tickNextTickSet.size());
|
||||
if (count != tickNextTickSet.size())
|
||||
{
|
||||
// TODO 4J Stu - Add new exception types
|
||||
@@ -685,8 +685,8 @@ bool ServerLevel::tickPendingTicks(bool force)
|
||||
|
||||
toBeTicked.clear();
|
||||
|
||||
int count3 = (int)tickNextTickList.size();
|
||||
int count4 = (int)tickNextTickSet.size();
|
||||
int count3 = static_cast<int>(tickNextTickList.size());
|
||||
int count4 = static_cast<int>(tickNextTickSet.size());
|
||||
|
||||
bool retval = tickNextTickList.size() != 0;
|
||||
LeaveCriticalSection(&m_tickNextTickCS);
|
||||
@@ -776,7 +776,7 @@ void ServerLevel::tick(shared_ptr<Entity> e, bool actual)
|
||||
{
|
||||
e->remove();
|
||||
}
|
||||
if (!server->isNpcsEnabled() && (dynamic_pointer_cast<Npc>(e) != NULL))
|
||||
if (!server->isNpcsEnabled() && (dynamic_pointer_cast<Npc>(e) != nullptr))
|
||||
{
|
||||
e->remove();
|
||||
}
|
||||
@@ -860,7 +860,7 @@ void ServerLevel::setInitialSpawn(LevelSettings *levelSettings)
|
||||
int minXZ = - (dimension->getXZSize() * 16 ) / 2;
|
||||
int maxXZ = (dimension->getXZSize() * 16 ) / 2 - 1;
|
||||
|
||||
if (findBiome != NULL)
|
||||
if (findBiome != nullptr)
|
||||
{
|
||||
xSpawn = findBiome->x;
|
||||
zSpawn = findBiome->z;
|
||||
@@ -914,7 +914,7 @@ void ServerLevel::generateBonusItemsNearSpawn()
|
||||
if( getTile( x, y, z ) == Tile::chest_Id )
|
||||
{
|
||||
shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(getTileEntity(x, y, z));
|
||||
if (chest != NULL)
|
||||
if (chest != nullptr)
|
||||
{
|
||||
if( chest->isBonusChest )
|
||||
{
|
||||
@@ -960,7 +960,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
|
||||
if(StorageManager.GetSaveDisabled()) return;
|
||||
|
||||
|
||||
if (progressListener != NULL)
|
||||
if (progressListener != nullptr)
|
||||
{
|
||||
if(bAutosave)
|
||||
{
|
||||
@@ -976,7 +976,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
|
||||
saveLevelData();
|
||||
PIXEndNamedEvent();
|
||||
|
||||
if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_CHUNKS);
|
||||
if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_CHUNKS);
|
||||
|
||||
#if defined(_XBOX_ONE) || defined(__ORBIS__)
|
||||
// Our autosave is a minimal save. All the chunks are saves by the constant save process
|
||||
@@ -1009,7 +1009,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
|
||||
|
||||
//if( force && !isClientSide )
|
||||
//{
|
||||
// if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
|
||||
// if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
|
||||
// levelStorage->flushSaveFile();
|
||||
//}
|
||||
}
|
||||
@@ -1024,7 +1024,7 @@ void ServerLevel::saveToDisc(ProgressListener *progressListener, bool autosave)
|
||||
if(!Minecraft::GetInstance()->skins->isUsingDefaultSkin())
|
||||
{
|
||||
TexturePack *tPack = Minecraft::GetInstance()->skins->getSelected();
|
||||
DLCTexturePack *pDLCTexPack=(DLCTexturePack *)tPack;
|
||||
DLCTexturePack *pDLCTexPack=static_cast<DLCTexturePack *>(tPack);
|
||||
|
||||
DLCPack * pDLCPack=pDLCTexPack->getDLCInfoParentPack();
|
||||
|
||||
@@ -1034,7 +1034,7 @@ void ServerLevel::saveToDisc(ProgressListener *progressListener, bool autosave)
|
||||
}
|
||||
}
|
||||
|
||||
if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
|
||||
if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
|
||||
levelStorage->flushSaveFile(autosave);
|
||||
}
|
||||
|
||||
@@ -1085,7 +1085,7 @@ bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e)
|
||||
{
|
||||
if (Level::addGlobalEntity(e))
|
||||
{
|
||||
server->getPlayers()->broadcast(e->x, e->y, e->z, 512, dimension->id, shared_ptr<AddGlobalEntityPacket>( new AddGlobalEntityPacket(e) ) );
|
||||
server->getPlayers()->broadcast(e->x, e->y, e->z, 512, dimension->id, std::make_shared<AddGlobalEntityPacket>(e));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1093,7 +1093,7 @@ bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e)
|
||||
|
||||
void ServerLevel::broadcastEntityEvent(shared_ptr<Entity> e, byte event)
|
||||
{
|
||||
shared_ptr<Packet> p = shared_ptr<EntityEventPacket>( new EntityEventPacket(e->entityId, event) );
|
||||
shared_ptr<Packet> p = std::make_shared<EntityEventPacket>(e->entityId, event);
|
||||
server->getLevel(dimension->id)->getTracker()->broadcastAndSend(e, p);
|
||||
}
|
||||
|
||||
@@ -1101,7 +1101,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
|
||||
{
|
||||
// instead of calling super, we run the same explosion code here except
|
||||
// we don't generate any particles
|
||||
shared_ptr<Explosion> explosion = shared_ptr<Explosion>( new Explosion(this, source, x, y, z, r) );
|
||||
shared_ptr<Explosion> explosion = std::make_shared<Explosion>(this, source, x, y, z, r);
|
||||
explosion->fire = fire;
|
||||
explosion->destroyBlocks = destroyBlocks;
|
||||
explosion->explode();
|
||||
@@ -1122,7 +1122,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
|
||||
if( sentTo.size() )
|
||||
{
|
||||
INetworkPlayer *thisPlayer = player->connection->getNetworkPlayer();
|
||||
if( thisPlayer == NULL )
|
||||
if( thisPlayer == nullptr )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1131,7 +1131,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
|
||||
for(auto& player2 : sentTo)
|
||||
{
|
||||
INetworkPlayer *otherPlayer = player2->connection->getNetworkPlayer();
|
||||
if( otherPlayer != NULL && thisPlayer->IsSameSystem(otherPlayer) )
|
||||
if( otherPlayer != nullptr && thisPlayer->IsSameSystem(otherPlayer) )
|
||||
{
|
||||
knockbackOnly = true;
|
||||
}
|
||||
@@ -1144,7 +1144,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
|
||||
Vec3 *knockbackVec = explosion->getHitPlayerKnockback(player);
|
||||
//app.DebugPrintf("Sending %s with knockback (%f,%f,%f)\n", knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z);
|
||||
// If the player is not the primary on the system, then we only want to send info for the knockback
|
||||
player->connection->send( shared_ptr<ExplodePacket>( new ExplodePacket(x, y, z, r, &explosion->toBlow, knockbackVec, knockbackOnly)));
|
||||
player->connection->send(std::make_shared<ExplodePacket>(x, y, z, r, &explosion->toBlow, knockbackVec, knockbackOnly));
|
||||
sentTo.push_back( player );
|
||||
}
|
||||
}
|
||||
@@ -1182,7 +1182,7 @@ void ServerLevel::runTileEvents()
|
||||
if (doTileEvent(&it))
|
||||
{
|
||||
TileEventData te = it;
|
||||
server->getPlayers()->broadcast(te.getX(), te.getY(), te.getZ(), 64, dimension->id, shared_ptr<TileEventPacket>( new TileEventPacket(te.getX(), te.getY(), te.getZ(), te.getTile(), te.getParamA(), te.getParamB())));
|
||||
server->getPlayers()->broadcast(te.getX(), te.getY(), te.getZ(), 64, dimension->id, std::make_shared<TileEventPacket>(te.getX(), te.getY(), te.getZ(), te.getTile(), te.getParamA(), te.getParamB()));
|
||||
}
|
||||
}
|
||||
tileEvents[runList].clear();
|
||||
@@ -1212,11 +1212,11 @@ void ServerLevel::tickWeather()
|
||||
{
|
||||
if (wasRaining)
|
||||
{
|
||||
server->getPlayers()->broadcastAll( shared_ptr<GameEventPacket>( new GameEventPacket(GameEventPacket::STOP_RAINING, 0) ) );
|
||||
server->getPlayers()->broadcastAll(std::make_shared<GameEventPacket>(GameEventPacket::STOP_RAINING, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
server->getPlayers()->broadcastAll( shared_ptr<GameEventPacket>( new GameEventPacket(GameEventPacket::START_RAINING, 0) ) );
|
||||
server->getPlayers()->broadcastAll(std::make_shared<GameEventPacket>(GameEventPacket::START_RAINING, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1268,7 +1268,7 @@ void ServerLevel::sendParticles(const wstring &name, double x, double y, double
|
||||
|
||||
void ServerLevel::sendParticles(const wstring &name, double x, double y, double z, int count, double xDist, double yDist, double zDist, double speed)
|
||||
{
|
||||
shared_ptr<Packet> packet = std::make_shared<LevelParticlesPacket>( name, (float) x, (float) y, (float) z, (float) xDist, (float) yDist, (float) zDist, (float) speed, count );
|
||||
shared_ptr<Packet> packet = std::make_shared<LevelParticlesPacket>( name, static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(xDist), static_cast<float>(yDist), static_cast<float>(zDist), static_cast<float>(speed), count );
|
||||
|
||||
for(auto& it : players)
|
||||
{
|
||||
@@ -1578,7 +1578,7 @@ int ServerLevel::runUpdate(void* lpParam)
|
||||
if( (id == Tile::grass_Id && grassTicks >= MAX_GRASS_TICKS) || (id == Tile::calmLava_Id && lavaTicks >= MAX_LAVA_TICKS) ) continue;
|
||||
|
||||
// 4J Stu - Added shouldTileTick as some tiles won't even do anything if they are set to tick and use up one of our updates
|
||||
if (Tile::tiles[id] != NULL && Tile::tiles[id]->isTicking() && Tile::tiles[id]->shouldTileTick(m_level[iLev],x + (cx * 16), y, z + (cz * 16) ) )
|
||||
if (Tile::tiles[id] != nullptr && Tile::tiles[id]->isTicking() && Tile::tiles[id]->shouldTileTick(m_level[iLev],x + (cx * 16), y, z + (cz * 16) ) )
|
||||
{
|
||||
if(id == Tile::grass_Id) ++grassTicks;
|
||||
else if(id == Tile::calmLava_Id) ++lavaTicks;
|
||||
|
||||
Reference in New Issue
Block a user