Skip to content

Commit

Permalink
fix initial ids
Browse files Browse the repository at this point in the history
  • Loading branch information
RevenantX committed Mar 2, 2024
1 parent bc03ba6 commit 3280490
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LiteEntitySystem/EntitySharedReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public readonly struct EntitySharedReference

public static readonly EntitySharedReference Empty;

internal EntitySharedReference(ushort id, byte version)
public EntitySharedReference(ushort id, byte version)
{
Id = id;
Version = version;
Expand Down
13 changes: 4 additions & 9 deletions LiteEntitySystem/ServerEntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public sealed class ServerEntityManager : EntityManager
{
public const int MaxStoredInputs = 30;

private readonly IdGeneratorUShort _entityIdQueue = new(MaxSyncedEntityCount);
private readonly IdGeneratorByte _playerIdQueue = new(MaxPlayers);
private readonly IdGeneratorUShort _entityIdQueue = new(MaxSyncedEntityCount-1);
private readonly IdGeneratorByte _playerIdQueue = new(MaxPlayers-1);
private readonly Queue<RemoteCallPacket> _rpcPool = new();
private readonly Queue<byte[]> _inputPool = new();
private readonly Queue<byte[]> _pendingClientRequests = new();
Expand Down Expand Up @@ -80,11 +80,6 @@ public ServerEntityManager(
: base(typesMap, inputProcessor, NetworkMode.Server, framesPerSecond, packetHeader)
{
InternalPlayerId = ServerPlayerId;
for (int i = 1; i <= byte.MaxValue; i++)
_playerIdQueue.ReuseId((byte)i);
for (ushort i = FirstEntityId; i < MaxSyncedEntityCount; i++)
_entityIdQueue.ReuseId(i);

_packetBuffer[0] = packetHeader;
SendRate = sendRate;
}
Expand Down Expand Up @@ -120,7 +115,7 @@ public NetPlayer AddPlayer(AbstractNetPeer peer)
{
if (_netPlayersCount == MaxPlayers)
return null;
var player = new NetPlayer(peer, _playerIdQueue.GetNewId()) { State = NetPlayerState.RequestBaseline };
var player = new NetPlayer(peer, (byte)(_playerIdQueue.GetNewId()+1)) { State = NetPlayerState.RequestBaseline };
_netPlayersDict[player.Id] = player;
player.ArrayIndex = _netPlayersCount;
_netPlayersArray[_netPlayersCount++] = player;
Expand Down Expand Up @@ -549,7 +544,7 @@ private T Add<T>(Action<T> initMethod) where T : InternalEntity
Logger.Log($"Cannot add entity. Max entity count reached: {MaxSyncedEntityCount}");
return null;
}
ushort entityId = _entityIdQueue.GetNewId();
ushort entityId = (ushort)(_entityIdQueue.GetNewId()+1);
ref var stateSerializer = ref _stateSerializers[entityId];

entity = (T)AddEntity(new EntityParams(
Expand Down

0 comments on commit 3280490

Please sign in to comment.