From 935ee0e416c887540d7b0a9e3e869002eb602c35 Mon Sep 17 00:00:00 2001 From: austin Date: Sat, 24 May 2025 21:36:04 -0400 Subject: [PATCH] ai lod work --- docs/src/progress/renderertodo.md | 1 + .../electrosphere/renderer/model/Mesh.java | 7 ++++- src/main/java/electrosphere/server/ai/AI.java | 29 ++++++++----------- .../electrosphere/server/ai/AIManager.java | 4 +++ .../ai/services/NearbyEntityService.java | 3 ++ 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index de7dcda9..38c2573f 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1969,6 +1969,7 @@ Performance improvements - Normal outline pipeline use draw accumulator - Reduced the visual LOD cutoff - Multiple visual LOD levels + - AI does not simulate for low-lod server entities Lod emitter service checker function diff --git a/src/main/java/electrosphere/renderer/model/Mesh.java b/src/main/java/electrosphere/renderer/model/Mesh.java index 3e8468e0..35c10076 100644 --- a/src/main/java/electrosphere/renderer/model/Mesh.java +++ b/src/main/java/electrosphere/renderer/model/Mesh.java @@ -427,6 +427,7 @@ public class Mesh { Globals.renderingEngine.checkError(); if(renderPipelineState.getUseMeshShader()){ + Globals.profiler.beginAggregateCpuSample("Mesh shader"); VisualShader selectedProgram = null; switch(renderPipelineState.getSelectedShader()){ case PRIMARY: { @@ -440,6 +441,7 @@ public class Mesh { selectedProgram = shader; } openGLState.setActiveShader(renderPipelineState, selectedProgram); + Globals.profiler.endCpuSample(); } if(renderPipelineState.getUseLight()){ @@ -464,13 +466,14 @@ public class Mesh { } if(renderPipelineState.getUseMaterial() && textureMask == null){ - Globals.renderingEngine.checkError(); + Globals.profiler.beginAggregateCpuSample("applyMaterial"); if(material == null){ Globals.renderingEngine.getDefaultMaterial().applyMaterial(openGLState); } else { material.applyMaterial(openGLState); } Globals.renderingEngine.checkError(); + Globals.profiler.endCpuSample(); } @@ -507,12 +510,14 @@ public class Mesh { } if(renderPipelineState.getUseShadowMap()){ + Globals.profiler.beginAggregateCpuSample("Shadow map"); int shadowMapTextureUnit = 3; openGLState.glActiveTexture(GL45.GL_TEXTURE0 + shadowMapTextureUnit); Globals.renderingEngine.checkError(); openGLState.glBindTexture(GL45.GL_TEXTURE_2D, RenderingEngine.lightBufferDepthTexture.getTexturePointer()); Globals.renderingEngine.checkError(); openGLState.getActiveShader().setUniform(openGLState, "shadowMap", shadowMapTextureUnit); + Globals.profiler.endCpuSample(); } diff --git a/src/main/java/electrosphere/server/ai/AI.java b/src/main/java/electrosphere/server/ai/AI.java index 7ce8cbe1..592e780a 100644 --- a/src/main/java/electrosphere/server/ai/AI.java +++ b/src/main/java/electrosphere/server/ai/AI.java @@ -1,6 +1,5 @@ package electrosphere.server.ai; -import java.util.LinkedList; import java.util.List; import electrosphere.data.entity.creature.ai.AITreeData; @@ -9,6 +8,7 @@ import electrosphere.data.entity.creature.ai.BlockerTreeData; import electrosphere.data.entity.creature.ai.StandardCharacterTreeData; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.state.lod.ServerLODComponent; import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.logger.LoggerInterface; @@ -25,40 +25,30 @@ import electrosphere.server.ai.trees.test.BlockerAITree; */ public class AI { - /** - * The error checking threshold for ai mutation - */ - static final float ERROR_CHECK_ROT_THRESHOLD = 0.999f; - /** * The entity this ai is associated with */ - Entity parent; + private Entity parent; /** * The root node of the behavior tree */ - AITreeNode rootNode; + private AITreeNode rootNode; /** * The blackboard for the tree */ - Blackboard blackboard = new Blackboard(); - - /** - * Internal usage, used to track the nodes that have been evaluated and ensure we're not looping - */ - List evaluatedNodes = new LinkedList(); + private Blackboard blackboard = new Blackboard(); /** * Tracks whether this should apply even if there is a controlling player */ - boolean applyToPlayer = false; + private boolean applyToPlayer = false; /** * The status of the ai */ - String status = "Idle"; + private String status = "Idle"; /** * Constructs an AI from a list of trees that should be present on the ai @@ -150,7 +140,12 @@ public class AI { * Checks if the ai should simulate or not * @return true if should simulate, false otherwise */ - private boolean shouldExecute(){ + public boolean shouldExecute(){ + if(ServerLODComponent.hasServerLODComponent(this.parent)){ + if(ServerLODComponent.getServerLODComponent(this.parent).getLodLevel() == ServerLODComponent.LOW_RES){ + return false; + } + } return this.applyToPlayer || !CreatureUtils.hasControllerPlayerId(this.parent); } diff --git a/src/main/java/electrosphere/server/ai/AIManager.java b/src/main/java/electrosphere/server/ai/AIManager.java index 0ac80868..49ecde43 100644 --- a/src/main/java/electrosphere/server/ai/AIManager.java +++ b/src/main/java/electrosphere/server/ai/AIManager.java @@ -80,9 +80,12 @@ public class AIManager { Globals.profiler.beginCpuSample("AIManager.simulate"); lock.lock(); //exec the services + Globals.profiler.beginCpuSample("AIManager.simulate - services"); this.execServices(); + Globals.profiler.endCpuSample(); //simulate each tree + Globals.profiler.beginCpuSample("AIManager.simulate - ai logic"); if(this.isActive()){ for(AI ai : aiList){ try { @@ -92,6 +95,7 @@ public class AIManager { } } } + Globals.profiler.endCpuSample(); lock.unlock(); Globals.profiler.endCpuSample(); } diff --git a/src/main/java/electrosphere/server/ai/services/NearbyEntityService.java b/src/main/java/electrosphere/server/ai/services/NearbyEntityService.java index 4faa720e..824a45e9 100644 --- a/src/main/java/electrosphere/server/ai/services/NearbyEntityService.java +++ b/src/main/java/electrosphere/server/ai/services/NearbyEntityService.java @@ -25,6 +25,9 @@ public class NearbyEntityService implements AIService { @Override public void exec(){ for(AI ai : Globals.serverState.aiManager.getAIList()){ + if(!ai.shouldExecute()){ + continue; + } Entity entity = ai.getParent(); Realm realm = Globals.serverState.realmManager.getEntityRealm(entity); if(realm != null){