-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change world loading to only spawn entities in view range, and refact…
…ored of WorldEntityManager
- Loading branch information
1 parent
0caa209
commit 10d1535
Showing
11 changed files
with
370 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
NitroxPatcher/Patches/Dynamic/LargeWorldStreamer_LoadBatchTask_Execute_Patch.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
NitroxPatcher/Patches/Dynamic/LargeWorldStreamer_UnloadBatch_Patch.cs
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
NitroxServer/Communication/Packets/Processors/BatchVisibilityChangedProcessor.cs
This file was deleted.
Oops, something went wrong.
46 changes: 37 additions & 9 deletions
46
NitroxServer/Communication/Packets/Processors/CellVisibilityChangedProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
using System.Collections.Generic; | ||
using NitroxModel.DataStructures; | ||
using NitroxModel.DataStructures.GameLogic; | ||
using NitroxModel.Packets; | ||
using NitroxServer.Communication.Packets.Processors.Abstract; | ||
using NitroxServer.GameLogic.Entities; | ||
|
||
namespace NitroxServer.Communication.Packets.Processors | ||
namespace NitroxServer.Communication.Packets.Processors; | ||
|
||
public class CellVisibilityChangedProcessor : AuthenticatedPacketProcessor<CellVisibilityChanged> | ||
{ | ||
class CellVisibilityChangedProcessor : AuthenticatedPacketProcessor<CellVisibilityChanged> | ||
private readonly EntitySimulation entitySimulation; | ||
private readonly WorldEntityManager worldEntityManager; | ||
|
||
public CellVisibilityChangedProcessor(EntitySimulation entitySimulation, WorldEntityManager worldEntityManager) | ||
{ | ||
this.entitySimulation = entitySimulation; | ||
this.worldEntityManager = worldEntityManager; | ||
} | ||
|
||
public override void Process(CellVisibilityChanged packet, Player player) | ||
{ | ||
private readonly EntitySimulation entitySimulation; | ||
player.AddCells(packet.Added); | ||
player.RemoveCells(packet.Removed); | ||
|
||
List<Entity> totalEntities = []; | ||
List<SimulatedEntity> totalSimulationChanges = []; | ||
|
||
public CellVisibilityChangedProcessor(EntitySimulation entitySimulation) | ||
foreach (AbsoluteEntityCell addedCell in packet.Added) | ||
{ | ||
this.entitySimulation = entitySimulation; | ||
worldEntityManager.LoadUnspawnedEntities(addedCell.BatchId, false); | ||
|
||
totalSimulationChanges.AddRange(entitySimulation.GetSimulationChangesForCell(player, addedCell)); | ||
totalEntities.AddRange(worldEntityManager.GetEntities(addedCell)); | ||
} | ||
|
||
public override void Process(CellVisibilityChanged packet, Player player) | ||
foreach (AbsoluteEntityCell removedCell in packet.Removed) | ||
{ | ||
player.AddCells(packet.Added); | ||
player.RemoveCells(packet.Removed); | ||
entitySimulation.FillWithRemovedCells(player, removedCell, totalSimulationChanges); | ||
} | ||
|
||
entitySimulation.BroadcastSimulationChangesForCellUpdates(player, packet.Added, packet.Removed); | ||
if (totalEntities.Count > 0) | ||
{ | ||
SpawnEntities batchEntities = new(totalEntities); | ||
player.SendPacket(batchEntities); | ||
} | ||
if (totalSimulationChanges.Count > 0) | ||
{ | ||
entitySimulation.BroadcastSimulationChanges(new(totalSimulationChanges)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.