structure scanning work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-06 15:12:11 -04:00
parent 99402e5656
commit 6ab5c3de67
7 changed files with 66 additions and 15 deletions

View File

@ -1690,6 +1690,11 @@ Code cleanup
More code cleanup More code cleanup
Cleanup some TODOs Cleanup some TODOs
(05/06/2025)
Refactor block actions
Placing fabs/blocks triggers structure scanning service
Try closing ai manager threads on engine close

View File

@ -134,6 +134,9 @@ public class ThreadManager {
TerrainChunk.haltThreads(); TerrainChunk.haltThreads();
FoliageModel.haltThreads(); FoliageModel.haltThreads();
BlockChunkEntity.haltThreads(); BlockChunkEntity.haltThreads();
if(Globals.aiManager != null && Globals.aiManager.getPathfindingService() != null){
Globals.aiManager.getPathfindingService().shutdown();
}
// //
//interrupt all threads //interrupt all threads

View File

@ -13,7 +13,6 @@ import electrosphere.client.block.BlockChunkData;
import electrosphere.client.terrain.cache.ChunkData; import electrosphere.client.terrain.cache.ChunkData;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.state.item.ServerChargeState;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.TerrainMessage; import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.server.ServerConnectionHandler;
@ -22,7 +21,6 @@ import electrosphere.net.template.ServerProtocolTemplate;
import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.datacell.ServerWorldData;
import electrosphere.server.datacell.utils.EntityLookupUtils; import electrosphere.server.datacell.utils.EntityLookupUtils;
import electrosphere.server.physics.block.editing.ServerBlockEditing;
import electrosphere.server.physics.fluid.manager.ServerFluidChunk; import electrosphere.server.physics.fluid.manager.ServerFluidChunk;
import electrosphere.server.physics.terrain.editing.TerrainEditing; import electrosphere.server.physics.terrain.editing.TerrainEditing;
import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk;
@ -89,20 +87,15 @@ public class TerrainProtocol implements ServerProtocolTemplate<TerrainMessage> {
case REQUESTEDITBLOCK: { case REQUESTEDITBLOCK: {
LoggerInterface.loggerNetworking.DEBUG("(Server) Received request to edit block at " + message.getworldX() + " " + message.getworldY() + " " + message.getworldZ()); LoggerInterface.loggerNetworking.DEBUG("(Server) Received request to edit block at " + message.getworldX() + " " + message.getworldY() + " " + message.getworldZ());
Entity targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); Entity targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId());
// Realm playerRealm = Globals.realmManager.getEntityRealm(targetEntity);
Vector3i worldPos = new Vector3i(message.getworldX(),message.getworldY(),message.getworldZ()); Vector3i worldPos = new Vector3i(message.getworldX(),message.getworldY(),message.getworldZ());
Vector3i blockPos = new Vector3i(message.getvoxelX(),message.getvoxelY(),message.getvoxelZ()); Vector3i blockPos = new Vector3i(message.getvoxelX(),message.getvoxelY(),message.getvoxelZ());
BlockActions.editBlock(targetEntity, worldPos, blockPos, (short)message.getblockType(), message.getblockEditSize()); BlockActions.editBlockArea(targetEntity, worldPos, blockPos, (short)message.getblockType(), message.getblockEditSize());
// ServerBlockEditing.editBlockArea(playerRealm, worldPos, blockPos, (short)message.getblockType(), (short)message.getblockMetadata(), message.getblockEditSize());
// ServerChargeState.attemptRemoveCharges(targetEntity, 1);
} break; } break;
case REQUESTPLACEFAB: { case REQUESTPLACEFAB: {
Vector3i worldPos = new Vector3i(message.getworldX(),message.getworldY(),message.getworldZ()); Vector3i worldPos = new Vector3i(message.getworldX(),message.getworldY(),message.getworldZ());
Vector3i blockPos = new Vector3i(message.getvoxelX(),message.getvoxelY(),message.getvoxelZ()); Vector3i blockPos = new Vector3i(message.getvoxelX(),message.getvoxelY(),message.getvoxelZ());
Entity targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); Entity targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId());
Realm playerRealm = Globals.realmManager.getEntityRealm(targetEntity); BlockActions.placeFab(targetEntity, worldPos, blockPos, message.getblockRotation(), message.getfabPath());
ServerBlockEditing.placeBlockFab(playerRealm, worldPos, blockPos, message.getblockRotation(), message.getfabPath());
ServerChargeState.attemptRemoveCharges(targetEntity, 1);
} break; } break;
//all ignored message types //all ignored message types
case UPDATEFLUIDDATA: case UPDATEFLUIDDATA:

View File

@ -16,6 +16,11 @@ import electrosphere.server.player.BlockActions;
*/ */
public class PlaceBlockNode implements AITreeNode { public class PlaceBlockNode implements AITreeNode {
/**
* Size of the edit to apply
*/
static final int EDIT_SIZE = 1;
@Override @Override
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) { public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) {
Vector3d position = BeginStructureNode.getStructureBuildTarget(blackboard); Vector3d position = BeginStructureNode.getStructureBuildTarget(blackboard);
@ -24,7 +29,7 @@ public class PlaceBlockNode implements AITreeNode {
short blockType = BeginStructureNode.getBuildBlock(blackboard); short blockType = BeginStructureNode.getBuildBlock(blackboard);
BlockActions.editBlock(entity, chunkPos, blockPos, blockType, 1); BlockActions.editBlockArea(entity, chunkPos, blockPos, blockType, EDIT_SIZE);
SolveBuildMaterialNode.clearBuildTarget(blackboard); SolveBuildMaterialNode.clearBuildTarget(blackboard);

View File

@ -27,11 +27,13 @@ public class NearbyEntityService implements AIService {
for(AI ai : Globals.aiManager.getAIList()){ for(AI ai : Globals.aiManager.getAIList()){
Entity entity = ai.getParent(); Entity entity = ai.getParent();
Realm realm = Globals.realmManager.getEntityRealm(entity); Realm realm = Globals.realmManager.getEntityRealm(entity);
if(realm != null){
Vector3d position = EntityUtils.getPosition(entity); Vector3d position = EntityUtils.getPosition(entity);
Collection<Entity> nearbyEntities = realm.getDataCellManager().entityLookup(position, NearbyEntityService.SEARCH_DIST); Collection<Entity> nearbyEntities = realm.getDataCellManager().entityLookup(position, NearbyEntityService.SEARCH_DIST);
NearbyEntityService.setNearbyEntities(ai.getBlackboard(), nearbyEntities); NearbyEntityService.setNearbyEntities(ai.getBlackboard(), nearbyEntities);
} }
} }
}
/** /**
* Sets the nearby entities * Sets the nearby entities

View File

@ -7,9 +7,12 @@ import electrosphere.entity.Entity;
import electrosphere.entity.state.equip.ServerToolbarState; import electrosphere.entity.state.equip.ServerToolbarState;
import electrosphere.entity.state.item.ServerChargeState; import electrosphere.entity.state.item.ServerChargeState;
import electrosphere.entity.types.common.CommonEntityUtils; import electrosphere.entity.types.common.CommonEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.data.block.BlockType; import electrosphere.game.data.block.BlockType;
import electrosphere.game.data.item.Item; import electrosphere.game.data.item.Item;
import electrosphere.net.server.player.Player;
import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.ServerWorldData;
import electrosphere.server.physics.block.editing.ServerBlockEditing; import electrosphere.server.physics.block.editing.ServerBlockEditing;
/** /**
@ -25,7 +28,7 @@ public class BlockActions {
* @param blockType The type of block to edit to * @param blockType The type of block to edit to
* @param editSize The size of the edit * @param editSize The size of the edit
*/ */
public static void editBlock(Entity creature, Vector3i chunkPos, Vector3i blockPos, short blockType, int editSize){ public static void editBlockArea(Entity creature, Vector3i chunkPos, Vector3i blockPos, short blockType, int editSize){
Realm playerRealm = Globals.realmManager.getEntityRealm(creature); Realm playerRealm = Globals.realmManager.getEntityRealm(creature);
if(ServerToolbarState.hasServerToolbarState(creature)){ if(ServerToolbarState.hasServerToolbarState(creature)){
//check that we have the block equipped //check that we have the block equipped
@ -34,6 +37,10 @@ public class BlockActions {
String equippedItemType = CommonEntityUtils.getEntitySubtype(equippedItem); String equippedItemType = CommonEntityUtils.getEntitySubtype(equippedItem);
BlockType blockTypeData = Globals.gameConfigCurrent.getBlockData().getTypeFromId((int)blockType); BlockType blockTypeData = Globals.gameConfigCurrent.getBlockData().getTypeFromId((int)blockType);
String goalBlockEntityId = Item.getBlockTypeId(blockTypeData); String goalBlockEntityId = Item.getBlockTypeId(blockTypeData);
if(CreatureUtils.hasControllerPlayerId(creature)){
Player player = Globals.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature));
Globals.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos));
}
if(equippedItemType.equals(goalBlockEntityId)){ if(equippedItemType.equals(goalBlockEntityId)){
//place the block //place the block
@ -43,4 +50,22 @@ public class BlockActions {
} }
} }
/**
* Places a fab
* @param creature The creature placing the fab
* @param chunkPos The chunk position to place at
* @param blockPos The block position to place at
* @param blockRotation The rotation to apply to the fab
* @param fabPath The path to the fab itself
*/
public static void placeFab(Entity creature, Vector3i chunkPos, Vector3i blockPos, int blockRotation, String fabPath){
Realm playerRealm = Globals.realmManager.getEntityRealm(creature);
ServerBlockEditing.placeBlockFab(playerRealm, chunkPos, blockPos, blockRotation, fabPath);
ServerChargeState.attemptRemoveCharges(creature, 1);
if(CreatureUtils.hasControllerPlayerId(creature)){
Player player = Globals.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature));
Globals.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos));
}
}
} }

View File

@ -2,10 +2,13 @@ package electrosphere.server.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.joml.Vector3d; import org.joml.Vector3d;
import electrosphere.engine.signal.Signal.SignalType; import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.logger.LoggerInterface;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.signal.SignalServiceImpl; import electrosphere.engine.signal.SignalServiceImpl;
import electrosphere.net.server.player.Player; import electrosphere.net.server.player.Player;
@ -55,7 +58,22 @@ public class StructureScanningService extends SignalServiceImpl {
* Simulates the service * Simulates the service
*/ */
public void simulate(){ public void simulate(){
Set<Entry<Player,ScanningJob>> jobs = playerTimeoutMap.entrySet();
for(Entry<Player,ScanningJob> job : jobs){
if(job.getValue().targetFrame <= Globals.timekeeper.getNumberOfSimFramesElapsed()){
//run this job
playerTimeoutMap.remove(job.getKey());
StructureScanningService.scanForStructure(job.getValue());
}
}
}
/**
* Executes a scanning job
* @param job The job
*/
protected static void scanForStructure(ScanningJob job){
LoggerInterface.loggerEngine.WARNING("Scan structure at " + job.position);
} }
/** /**