From 8784b08fe49f4acfb431f5e14caf845119eaf96e Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 27 May 2025 12:53:30 -0400 Subject: [PATCH] profiling work --- docs/src/progress/renderertodo.md | 1 + .../controls/cursor/CursorState.java | 4 +++- .../server/entity/ServerContentManager.java | 17 +++++++++++++++++ .../server/service/CharacterService.java | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index e55bf06a..d2c623c0 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2006,6 +2006,7 @@ VectorPool->JomlPool Major NetArranger architecture rework No allocations on client receiving chunk of blocks or terrain Meshgen acceleration structure for block meshgen +More profiling diff --git a/src/main/java/electrosphere/controls/cursor/CursorState.java b/src/main/java/electrosphere/controls/cursor/CursorState.java index ec4d6763..25f43b6e 100644 --- a/src/main/java/electrosphere/controls/cursor/CursorState.java +++ b/src/main/java/electrosphere/controls/cursor/CursorState.java @@ -218,7 +218,9 @@ public class CursorState { cursorPos = cursorPos.add(new Vector3d(eyePos).normalize().mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER)); } cursorPos.set(this.clampPositionToNearestBlock(cursorPos)); - EntityUtils.getPosition(Globals.cursorState.playerBlockCursor).set(cursorPos); + if(Globals.cursorState.playerBlockCursor != null){ + EntityUtils.getPosition(Globals.cursorState.playerBlockCursor).set(cursorPos); + } cursorPos.sub(BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0,BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0,BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0); EntityUtils.getPosition(CursorState.playerFabCursor).set(cursorPos); if(gridAlignmentData != null){ diff --git a/src/main/java/electrosphere/server/entity/ServerContentManager.java b/src/main/java/electrosphere/server/entity/ServerContentManager.java index 7431de89..af4459a5 100644 --- a/src/main/java/electrosphere/server/entity/ServerContentManager.java +++ b/src/main/java/electrosphere/server/entity/ServerContentManager.java @@ -77,6 +77,7 @@ public class ServerContentManager { //Block for macro data generation if relevant // List objects = null; + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - collision check macro data"); if(macroData == null){ objects = new LinkedList(); } else { @@ -98,6 +99,7 @@ public class ServerContentManager { throw new Error("Failed to generate content " + notFullResCount + " " + waitCount); } } + Globals.profiler.endCpuSample(); @@ -105,33 +107,48 @@ public class ServerContentManager { //Actual generation/loading // String fullPath = "/content/" + cellKey + ".dat"; + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Actual generation/loading"); if(generateContent){ //in other words, if not arena mode if(FileUtils.checkSavePathExists(Globals.serverState.currentSave.getName(), fullPath)){ + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Load from existing key"); //if on disk (has already been generated) ContentSerialization contentRaw = FileUtils.loadObjectFromSavePath(Globals.serverState.currentSave.getName(), fullPath, ContentSerialization.class); contentRaw.hydrateRawContent(realm,cell); + Globals.profiler.endCpuSample(); } else { + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Generate from scratch"); //else create from scratch ServerContentGenerator.generateContent(realm, this.macroData, cell, worldPos, HashUtils.hashIVec(worldPos.x, worldPos.y, worldPos.z)); + Globals.profiler.endCpuSample(); } } else { //just because content wasn't generated doesn't mean there isn't data saved under that key if(FileUtils.checkSavePathExists(Globals.serverState.currentSave.getName(), fullPath)){ + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Load from on-disk file without key"); //if on disk (has already been generated) ContentSerialization contentRaw = FileUtils.loadObjectFromSavePath(Globals.serverState.currentSave.getName(), fullPath, ContentSerialization.class); contentRaw.hydrateRawContent(realm,cell); + Globals.profiler.endCpuSample(); } } + Globals.profiler.endCpuSample(); //checking for null because there are cases where we might not have macro data to instantiate from //ie, if we load an asset-defined (not save-defined) scene that does not have save data //ie, imagine a puzzle room or something like that + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Macro data"); if(macroData != null){ + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Get nearby characters"); List nearbyCharacters = Globals.serverState.characterService.getCharacters(worldPos); + Globals.profiler.endCpuSample(); + Globals.profiler.beginCpuSample("ServerContentManager.generateContentForDataCell - Spawn characters"); for(Character character : nearbyCharacters){ this.spawnMacroObject(realm, character); } + Globals.profiler.endCpuSample(); } Globals.profiler.endCpuSample(); + + Globals.profiler.endCpuSample(); } /** diff --git a/src/main/java/electrosphere/server/service/CharacterService.java b/src/main/java/electrosphere/server/service/CharacterService.java index 373b49a8..210c4e8d 100644 --- a/src/main/java/electrosphere/server/service/CharacterService.java +++ b/src/main/java/electrosphere/server/service/CharacterService.java @@ -213,7 +213,7 @@ public class CharacterService extends SignalServiceImpl { */ public List getCharacters(Vector3i worldPos){ List rVal = new LinkedList(); - List allCharacters = this.getAllCharacters(); + List allCharacters = this.getLoadedCharacters(); for(Character character : allCharacters){ if(ServerWorldData.convertRealToChunkSpace(character.getPos()).equals(worldPos.x, worldPos.y, worldPos.z)){ rVal.add(character);