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:
ModMaker101
2026-03-07 21:56:03 -05:00
committed by GitHub
parent 1be5faaea7
commit a9be52c41a
1373 changed files with 19903 additions and 19449 deletions

View File

@@ -65,7 +65,7 @@ void PlayerChunkMap::PlayerChunk::add(shared_ptr<ServerPlayer> player, bool send
player->seenChunks.insert(pos);
// 4J Added the sendPacket check. See PlayerChunkMap::add for the usage
if( sendPacket ) player->connection->send( shared_ptr<ChunkVisibilityPacket>( new ChunkVisibilityPacket(pos.x, pos.z, true) ) );
if( sendPacket ) player->connection->send(std::make_shared<ChunkVisibilityPacket>(pos.x, pos.z, true));
if (players.empty())
{
@@ -83,7 +83,7 @@ void PlayerChunkMap::PlayerChunk::add(shared_ptr<ServerPlayer> player, bool send
void PlayerChunkMap::PlayerChunk::remove(shared_ptr<ServerPlayer> player)
{
PlayerChunkMap::PlayerChunk *toDelete = NULL;
PlayerChunkMap::PlayerChunk *toDelete = nullptr;
//app.DebugPrintf("--- PlayerChunkMap::PlayerChunk::remove x=%d\tz=%d\n",x,z);
auto it = find(players.begin(), players.end(), player);
@@ -122,7 +122,7 @@ void PlayerChunkMap::PlayerChunk::remove(shared_ptr<ServerPlayer> player)
// 4J - I don't think there's any point sending these anymore, as we don't need to unload chunks with fixed sized maps
// 4J - We do need to send these to unload entities in chunks when players are dead. If we do not and the entity is removed
// while they are dead, that entity will remain in the clients world
if (player->connection != NULL && player->seenChunks.find(pos) != player->seenChunks.end())
if (player->connection != nullptr && player->seenChunks.find(pos) != player->seenChunks.end())
{
INetworkPlayer *thisNetPlayer = player->connection->getNetworkPlayer();
bool noOtherPlayersFound = true;
@@ -134,7 +134,7 @@ void PlayerChunkMap::PlayerChunk::remove(shared_ptr<ServerPlayer> player)
if ( currPlayer )
{
INetworkPlayer *currNetPlayer = currPlayer->connection->getNetworkPlayer();
if( currNetPlayer != NULL && currNetPlayer->IsSameSystem( thisNetPlayer ) && currPlayer->seenChunks.find(pos) != currPlayer->seenChunks.end() )
if( currNetPlayer != nullptr && currNetPlayer->IsSameSystem( thisNetPlayer ) && currPlayer->seenChunks.find(pos) != currPlayer->seenChunks.end() )
{
noOtherPlayersFound = false;
break;
@@ -144,12 +144,12 @@ void PlayerChunkMap::PlayerChunk::remove(shared_ptr<ServerPlayer> player)
if(noOtherPlayersFound)
{
//wprintf(L"Sending ChunkVisiblity packet false for chunk (%d,%d) to player %ls\n", x, z, player->name.c_str() );
player->connection->send( shared_ptr<ChunkVisibilityPacket>( new ChunkVisibilityPacket(pos.x, pos.z, false) ) );
player->connection->send(std::make_shared<ChunkVisibilityPacket>(pos.x, pos.z, false));
}
}
else
{
//app.DebugPrintf("PlayerChunkMap::PlayerChunk::remove - QNetPlayer is NULL\n");
//app.DebugPrintf("PlayerChunkMap::PlayerChunk::remove - QNetPlayer is nullptr\n");
}
}
@@ -188,7 +188,7 @@ void PlayerChunkMap::PlayerChunk::tileChanged(int x, int y, int z)
if (changes < MAX_CHANGES_BEFORE_RESEND)
{
short id = (short) ((x << 12) | (z << 8) | (y));
short id = static_cast<short>((x << 12) | (z << 8) | (y));
for (int i = 0; i < changes; i++)
{
@@ -208,7 +208,7 @@ void PlayerChunkMap::PlayerChunk::prioritiseTileChanges()
// One system id per machine so we send at most once per system. Local = 256, remote = GetSmallId().
static int getSystemIdForSentTo(INetworkPlayer* np)
{
if (np == NULL) return -1;
if (np == nullptr) return -1;
return np->IsLocal() ? 256 : (int)np->GetSmallId();
}
@@ -219,7 +219,7 @@ void PlayerChunkMap::PlayerChunk::broadcast(shared_ptr<Packet> packet)
{
shared_ptr<ServerPlayer> player = players[i];
INetworkPlayer* thisPlayer = player->connection->getNetworkPlayer();
if (thisPlayer == NULL) continue;
if (thisPlayer == nullptr) continue;
int sysId = getSystemIdForSentTo(thisPlayer);
if (sysId >= 0 && sentToSystemIds.find(sysId) != sentToSystemIds.end())
continue;
@@ -239,15 +239,15 @@ void PlayerChunkMap::PlayerChunk::broadcast(shared_ptr<Packet> packet)
for (size_t i = 0; i < allPlayers.size(); i++)
{
shared_ptr<ServerPlayer> player = allPlayers[i];
if (player->connection == NULL || player->connection->isLocal()) continue;
if (player->connection == nullptr || player->connection->isLocal()) continue;
INetworkPlayer* thisPlayer = player->connection->getNetworkPlayer();
if (thisPlayer == NULL) continue;
if (thisPlayer == nullptr) continue;
int sysId = getSystemIdForSentTo(thisPlayer);
if (sysId >= 0 && sentToSystemIds.find(sysId) != sentToSystemIds.end())
continue;
int flagIndex = ServerPlayer::getFlagIndexForChunk(pos, parent->dimension);
const int flagIndex = ServerPlayer::getFlagIndexForChunk(pos, parent->dimension);
if (!g_NetworkManager.SystemFlagGet(thisPlayer, flagIndex)) continue;
player->connection->send(packet);
@@ -270,7 +270,7 @@ bool PlayerChunkMap::PlayerChunk::broadcastChanges(bool allowRegionUpdate)
int x = pos.x * 16 + xChangeMin;
int y = yChangeMin;
int z = pos.z * 16 + zChangeMin;
broadcast( shared_ptr<TileUpdatePacket>( new TileUpdatePacket(x, y, z, level) ) );
broadcast(std::make_shared<TileUpdatePacket>(x, y, z, level));
if (level->isEntityTile(x, y, z))
{
broadcast(level->getTileEntity(x, y, z));
@@ -300,7 +300,7 @@ bool PlayerChunkMap::PlayerChunk::broadcastChanges(bool allowRegionUpdate)
// Block region update packets can only encode ys in a range of 1 - 256
if( ys > 256 ) ys = 256;
broadcast( shared_ptr<BlockRegionUpdatePacket>( new BlockRegionUpdatePacket(xp, yp, zp, xs, ys, zs, level) ) );
broadcast(std::make_shared<BlockRegionUpdatePacket>(xp, yp, zp, xs, ys, zs, level));
vector<shared_ptr<TileEntity> > *tes = level->getTileEntitiesInRegion(xp, yp, zp, xp + xs, yp + ys, zp + zs);
for (unsigned int i = 0; i < tes->size(); i++)
{
@@ -313,7 +313,7 @@ bool PlayerChunkMap::PlayerChunk::broadcastChanges(bool allowRegionUpdate)
else
{
// 4J As we only get here if changes is less than MAX_CHANGES_BEFORE_RESEND (10) we only need to send a byte value in the packet
broadcast( shared_ptr<ChunkTilesUpdatePacket>( new ChunkTilesUpdatePacket(pos.x, pos.z, changedTiles, (byte)changes, level) ) );
broadcast(std::make_shared<ChunkTilesUpdatePacket>(pos.x, pos.z, changedTiles, static_cast<byte>(changes), level));
for (int i = 0; i < changes; i++)
{
int x = pos.x * 16 + ((changedTiles[i] >> 12) & 15);
@@ -334,10 +334,10 @@ bool PlayerChunkMap::PlayerChunk::broadcastChanges(bool allowRegionUpdate)
void PlayerChunkMap::PlayerChunk::broadcast(shared_ptr<TileEntity> te)
{
if (te != NULL)
if (te != nullptr)
{
shared_ptr<Packet> p = te->getUpdatePacket();
if (p != NULL)
if (p != nullptr)
{
broadcast(p);
}
@@ -375,7 +375,7 @@ void PlayerChunkMap::tick()
{
lastInhabitedUpdate = time;
for (int i = 0; i < knownChunks.size(); i++)
for (size_t i = 0; i < knownChunks.size(); i++)
{
PlayerChunk *chunk = knownChunks.at(i);
@@ -492,8 +492,8 @@ void PlayerChunkMap::tickAddRequests(shared_ptr<ServerPlayer> player)
if( addRequests.size() )
{
// Find the nearest chunk request to the player
int px = (int)player->x;
int pz = (int)player->z;
int px = static_cast<int>(player->x);
int pz = static_cast<int>(player->z);
int minDistSq = -1;
auto itNearest = addRequests.end();
@@ -527,7 +527,7 @@ void PlayerChunkMap::broadcastTileUpdate(shared_ptr<Packet> packet, int x, int y
int xc = x >> 4;
int zc = z >> 4;
PlayerChunk *chunk = getChunk(xc, zc, false);
if (chunk != NULL)
if (chunk != nullptr)
{
chunk->broadcast(packet);
}
@@ -538,7 +538,7 @@ void PlayerChunkMap::tileChanged(int x, int y, int z)
int xc = x >> 4;
int zc = z >> 4;
PlayerChunk *chunk = getChunk(xc, zc, false);
if (chunk != NULL)
if (chunk != nullptr)
{
chunk->tileChanged(x & 15, y, z & 15);
}
@@ -559,7 +559,7 @@ void PlayerChunkMap::prioritiseTileChanges(int x, int y, int z)
int xc = x >> 4;
int zc = z >> 4;
PlayerChunk *chunk = getChunk(xc, zc, false);
if (chunk != NULL)
if (chunk != nullptr)
{
chunk->prioritiseTileChanges();
}
@@ -569,8 +569,8 @@ void PlayerChunkMap::add(shared_ptr<ServerPlayer> player)
{
static int direction[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, {0, -1} };
int xc = (int) player->x >> 4;
int zc = (int) player->z >> 4;
int xc = static_cast<int>(player->x) >> 4;
int zc = static_cast<int>(player->z) >> 4;
player->lastMoveX = player->x;
player->lastMoveZ = player->z;
@@ -660,7 +660,7 @@ void PlayerChunkMap::add(shared_ptr<ServerPlayer> player)
}
// CraftBukkit end
player->connection->send( shared_ptr<ChunkVisibilityAreaPacket>( new ChunkVisibilityAreaPacket(minX, maxX, minZ, maxZ) ) );
player->connection->send(std::make_shared<ChunkVisibilityAreaPacket>(minX, maxX, minZ, maxZ));
#ifdef _LARGE_WORLDS
getLevel()->cache->dontDrop(xc,zc);
@@ -672,14 +672,14 @@ void PlayerChunkMap::add(shared_ptr<ServerPlayer> player)
void PlayerChunkMap::remove(shared_ptr<ServerPlayer> player)
{
int xc = ((int) player->lastMoveX) >> 4;
int zc = ((int) player->lastMoveZ) >> 4;
int xc = static_cast<int>(player->lastMoveX) >> 4;
int zc = static_cast<int>(player->lastMoveZ) >> 4;
for (int x = xc - radius; x <= xc + radius; x++)
for (int z = zc - radius; z <= zc + radius; z++)
{
PlayerChunk *playerChunk = getChunk(x, z, false);
if (playerChunk != NULL) playerChunk->remove(player);
if (playerChunk != nullptr) playerChunk->remove(player);
}
auto it = find(players.begin(), players.end(), player);
@@ -715,16 +715,16 @@ bool PlayerChunkMap::chunkInRange(int x, int z, int xc, int zc)
// need to be created, so that we aren't creating potentially 20 chunks per player per tick
void PlayerChunkMap::move(shared_ptr<ServerPlayer> player)
{
int xc = ((int) player->x) >> 4;
int zc = ((int) player->z) >> 4;
int xc = static_cast<int>(player->x) >> 4;
int zc = static_cast<int>(player->z) >> 4;
double _xd = player->lastMoveX - player->x;
double _zd = player->lastMoveZ - player->z;
double dist = _xd * _xd + _zd * _zd;
if (dist < 8 * 8) return;
int last_xc = ((int) player->lastMoveX) >> 4;
int last_zc = ((int) player->lastMoveZ) >> 4;
int last_xc = static_cast<int>(player->lastMoveX) >> 4;
int last_zc = static_cast<int>(player->lastMoveZ) >> 4;
int xd = xc - last_xc;
int zd = zc - last_zc;
@@ -759,7 +759,7 @@ bool PlayerChunkMap::isPlayerIn(shared_ptr<ServerPlayer> player, int xChunk, int
{
PlayerChunk *chunk = getChunk(xChunk, zChunk, false);
if(chunk == NULL)
if(chunk == nullptr)
{
return false;
}
@@ -770,7 +770,7 @@ bool PlayerChunkMap::isPlayerIn(shared_ptr<ServerPlayer> player, int xChunk, int
return it1 != chunk->players.end() && it2 == player->chunksToSend.end();
}
//return chunk == NULL ? false : chunk->players->contains(player) && !player->chunksToSend->contains(chunk->pos);
//return chunk == nullptr ? false : chunk->players->contains(player) && !player->chunksToSend->contains(chunk->pos);
}
int PlayerChunkMap::convertChunkRangeToBlock(int radius)
@@ -784,13 +784,13 @@ void PlayerChunkMap::setRadius(int newRadius)
if( radius != newRadius )
{
PlayerList* players = level->getServer()->getPlayerList();
for( int i = 0;i < players->players.size();i += 1 )
for( size_t i = 0;i < players->players.size();i += 1 )
{
shared_ptr<ServerPlayer> player = players->players[i];
if( player->level == level )
{
int xc = ((int) player->x) >> 4;
int zc = ((int) player->z) >> 4;
int xc = static_cast<int>(player->x) >> 4;
int zc = static_cast<int>(player->z) >> 4;
for (int x = xc - newRadius; x <= xc + newRadius; x++)
for (int z = zc - newRadius; z <= zc + newRadius; z++)