fix: Increase entity network limit to 16k entities (#1492)

This commit is contained in:
DrPerkyLegit 2026-04-12 23:50:46 -04:00 committed by GitHub
parent c7014f6b18
commit 82c1ae1968
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 35 additions and 27 deletions

View file

@ -81,7 +81,7 @@ void EntityTracker::addEntity(shared_ptr<Entity> e, int range, int updateInterva
{
assert(false); // Entity already tracked
}
if( e->entityId >= 2048 )
if( e->entityId >= 16384 )
{
__debugbreak();
}

View file

@ -147,12 +147,12 @@ void ServerPlayer::flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFou
{
*removedFound = true;
// before this left 192 bytes uninitialized!!!!!
memset(flags, 0, (2048 / 32) * sizeof(unsigned int));
memset(flags, 0, (16384 / 32) * sizeof(unsigned int));
}
for(int index : entitiesToRemove)
{
if( index < 2048 )
if( index < 16384 )
{
unsigned int i = index / 32;
unsigned int j = index % 32;

View file

@ -494,6 +494,7 @@ set(_MINECRAFT_SERVER_COMMON_ROOT
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.Client/iob_shim.asm"
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.Client/stdafx.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.Client/stubs.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.World/Entity.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.World/ConsoleSaveFileOriginal.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Minecraft.World/ConsoleSaveFileOriginal.h"
"${CMAKE_CURRENT_SOURCE_DIR}/../include/lce_filesystem/lce_filesystem.cpp"

View file

@ -27,13 +27,17 @@
const wstring Entity::RIDING_TAG = L"Riding";
int Entity::entityCounter = 2048; // 4J - changed initialiser to 2048, as we are using range 0 - 2047 as special unique smaller ids for things that need network tracked
//int Entity::entityCounter = 2048; // 4J - changed initialiser to 2048, as we are using range 0 - 2047 as special unique smaller ids for things that need network tracked
int Entity::entityCounter = 16384; //now using full range of 0 - 16383, limit is 32k but we shouldnt need that yet
DWORD Entity::tlsIdx = TlsAlloc();
// 4J - added getSmallId & freeSmallId methods
unsigned int Entity::entityIdUsedFlags[2048/32] = {0};
unsigned int Entity::entityIdWanderFlags[2048/32] = {0};
unsigned int Entity::entityIdRemovingFlags[2048/32] = {0};
//unsigned int Entity::entityIdUsedFlags[2048/32] = {0};
//unsigned int Entity::entityIdWanderFlags[2048/32] = {0};
//unsigned int Entity::entityIdRemovingFlags[2048/32] = {0};
unsigned int Entity::entityIdUsedFlags[16384/32] = {0};
unsigned int Entity::entityIdWanderFlags[16384/32] = {0};
unsigned int Entity::entityIdRemovingFlags[16384/32] = {0};
int Entity::extraWanderIds[EXTRA_WANDER_MAX] = {0};
int Entity::extraWanderTicks = 0;
int Entity::extraWanderCount = 0;
@ -65,7 +69,7 @@ int Entity::getSmallId()
}
}
for( int i = 0; i < (2048 / 32 ); i++ )
for( int i = 0; i < (16384 / 32 ); i++ )
{
unsigned int uiFlags = *puiUsedFlags;
if( uiFlags != 0xffffffff )
@ -102,7 +106,7 @@ int Entity::getSmallId()
if (entityCounter == 0x7ffffff)
{
entityCounter = 2048;
entityCounter = 16384;
}
return fallbackId;
#else
@ -116,7 +120,7 @@ void Entity::countFlagsForPIX()
{
int freecount = 0;
unsigned int *puiUsedFlags = entityIdUsedFlags;
for( int i = 0; i < (2048 / 32 ); i++ )
for( int i = 0; i < (16384 / 32 ); i++ )
{
unsigned int uiFlags = *puiUsedFlags;
if( uiFlags != 0xffffffff )
@ -134,7 +138,7 @@ void Entity::countFlagsForPIX()
puiUsedFlags++;
}
PIXAddNamedCounter(freecount,"Small Ids free");
PIXAddNamedCounter(2048 - freecount,"Small Ids used");
PIXAddNamedCounter(16384 - freecount,"Small Ids used");
}
void Entity::resetSmallId()
@ -149,7 +153,7 @@ void Entity::resetSmallId()
void Entity::freeSmallId(int index)
{
if( ( (size_t)TlsGetValue(tlsIdx) ) == 0 ) return; // Don't do anything with small ids if this isn't the server thread
if( index >= 2048 ) return; // Don't do anything if this isn't a short id
if( index >= 16384 ) return; // Don't do anything if this isn't a short id
unsigned int i = index / 32;
unsigned int j = index % 32;
@ -172,7 +176,7 @@ void Entity::useSmallIds()
void Entity::considerForExtraWandering(bool enable)
{
if( ( (size_t)TlsGetValue(tlsIdx) ) == 0 ) return; // Don't do anything with small ids if this isn't the server thread
if( entityId >= 2048 ) return; // Don't do anything if this isn't a short id
if( entityId >= 16384 ) return; // Don't do anything if this isn't a short id
unsigned int i = entityId / 32;
unsigned int j = entityId % 32;
@ -192,7 +196,7 @@ void Entity::considerForExtraWandering(bool enable)
bool Entity::isExtraWanderingEnabled()
{
if( ( (size_t)TlsGetValue(tlsIdx) ) == 0 ) return false; // Don't do anything with small ids if this isn't the server thread
if( entityId >= 2048 ) return false; // Don't do anything if this isn't a short id
if( entityId >= 16384 ) return false; // Don't do anything if this isn't a short id
for( int i = 0; i < extraWanderCount; i++ )
{
@ -224,12 +228,12 @@ void Entity::tickExtraWandering()
int entityId = 0;
if( extraWanderCount )
{
entityId = ( extraWanderIds[ extraWanderCount - 1 ] + 1 ) % 2048;
entityId = ( extraWanderIds[ extraWanderCount - 1 ] + 1 ) % 16384;
}
extraWanderCount = 0;
for( int k = 0; ( k < 2048 ) && ( extraWanderCount < EXTRA_WANDER_MAX); k++ )
for( int k = 0; ( k < 16384 ) && ( extraWanderCount < EXTRA_WANDER_MAX); k++ )
{
unsigned int i = entityId / 32;
unsigned int j = entityId % 32;
@ -241,7 +245,7 @@ void Entity::tickExtraWandering()
// printf("%d, ", entityId);
}
entityId = ( entityId + 1 ) % 2048;
entityId = ( entityId + 1 ) % 16384;
}
// printf("\n");
}
@ -261,7 +265,7 @@ void Entity::_init(bool useSmallId, Level *level)
else
{
entityId = Entity::entityCounter++;
if(entityCounter == 0x7ffffff ) entityCounter = 2048;
if(entityCounter == 0x7ffffff ) entityCounter = 16384;
}
viewScale = 1.0;

View file

@ -382,9 +382,12 @@ private:
int getSmallId();
void freeSmallId(int index);
static unsigned int entityIdUsedFlags[2048/32];
static unsigned int entityIdWanderFlags[2048/32];
static unsigned int entityIdRemovingFlags[2048/32];
//static unsigned int entityIdUsedFlags[2048/32];
//static unsigned int entityIdWanderFlags[2048/32];
//static unsigned int entityIdRemovingFlags[2048/32];
static unsigned int entityIdUsedFlags[16384/32];
static unsigned int entityIdWanderFlags[16384/32];
static unsigned int entityIdRemovingFlags[16384/32];
static int extraWanderIds[EXTRA_WANDER_MAX];
static int extraWanderCount;
static int extraWanderTicks;

View file

@ -35,7 +35,7 @@ void MoveEntityPacket::read(DataInputStream *dis) //throws IOException
void MoveEntityPacket::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();

View file

@ -19,7 +19,7 @@ MoveEntityPacketSmall::MoveEntityPacketSmall()
MoveEntityPacketSmall::MoveEntityPacketSmall(int id)
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
@ -42,7 +42,7 @@ void MoveEntityPacketSmall::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
@ -99,7 +99,7 @@ void MoveEntityPacketSmall::PosRot::read(DataInputStream *dis) //throws IOExcept
void MoveEntityPacketSmall::PosRot::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
@ -138,7 +138,7 @@ void MoveEntityPacketSmall::Pos::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::Pos::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
@ -176,7 +176,7 @@ void MoveEntityPacketSmall::Rot::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::Rot::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
if( (id < 0 ) || (id >= 16384 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();