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

This commit is contained in:
austin 2025-05-05 16:06:59 -04:00
parent 66eb3a7586
commit 4a9d8a4f90
5 changed files with 114 additions and 9 deletions

View File

@ -1678,6 +1678,9 @@ Recipe adjustment + voxel work
Recursive recipe item sourcing solver that keeps searching if a recipe fails to source
Block pathing work
(05/05/2025)
Scaffolding for structure scanning service

View File

@ -85,6 +85,7 @@ import electrosphere.server.datacell.RealmManager;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.entity.poseactor.PoseModel;
import electrosphere.server.saves.Save;
import electrosphere.server.service.StructureScanningService;
import electrosphere.server.simulation.MacroSimulation;
import electrosphere.server.simulation.MicroSimulation;
import electrosphere.util.FileUtils;
@ -388,6 +389,9 @@ public class Globals {
//file service
public static FileWatcherService fileWatcherService;
//structure scanning service
public static StructureScanningService structureScanningService;
//collision world data
public static CollisionWorldData commonWorldData;
@ -548,20 +552,12 @@ public class Globals {
Globals.scriptEngine = (ScriptEngine)serviceManager.registerService(new ScriptEngine());
Globals.mainThreadSignalService = (MainThreadSignalService)serviceManager.registerService(new MainThreadSignalService());
Globals.fileWatcherService = (FileWatcherService)serviceManager.registerService(new FileWatcherService());
Globals.structureScanningService = (StructureScanningService)serviceManager.registerService(new StructureScanningService());
serviceManager.instantiate();
//
//End service manager
//
//Register all signals
Globals.signalSystem.registerService(Globals.elementService);
Globals.signalSystem.registerService(Globals.particleService);
Globals.signalSystem.registerService(Globals.scriptEngine);
Globals.signalSystem.registerService(Globals.mainThreadSignalService);
Globals.signalSystem.registerService(Globals.fileWatcherService);
}
/**

View File

@ -3,6 +3,8 @@ package electrosphere.engine.service;
import java.util.LinkedList;
import java.util.List;
import electrosphere.engine.Globals;
import electrosphere.engine.signal.SignalService;
import electrosphere.logger.LoggerInterface;
/**
@ -42,6 +44,11 @@ public class ServiceManager {
LoggerInterface.loggerEngine.DEBUG("[ServiceManager] Instantiate service " + service.getName());
service.init();
}
for(Service service : trackedServices){
if(service instanceof SignalService){
Globals.signalSystem.registerService((SignalService)service);
}
}
}
/**

View File

@ -37,6 +37,10 @@ public class MainServerFunctions {
//Update AI
Globals.aiManager.simulate();
//
//Services
MainServerFunctions.simulateServices();
//
//Micro simulation (ie simulating each scene on the server)
Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server micro simulation");
@ -57,5 +61,12 @@ public class MainServerFunctions {
Globals.profiler.endCpuSample();
}
/**
* Simulates server services
*/
private static void simulateServices(){
Globals.structureScanningService.simulate();
}
}

View File

@ -0,0 +1,88 @@
package electrosphere.server.service;
import java.util.HashMap;
import java.util.Map;
import org.joml.Vector3d;
import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.engine.Globals;
import electrosphere.engine.signal.SignalServiceImpl;
import electrosphere.net.server.player.Player;
/**
* Service that scans areas where players are placing blocks to see if they have formed a complete structure or not
*/
public class StructureScanningService extends SignalServiceImpl {
/**
* Number of frames to offset jobs by
*/
static final int FRAME_OFFSET_FOR_JOBS = 50;
/**
* Map of players to the jobs that are scheduled for them
*/
Map<Player,ScanningJob> playerTimeoutMap = new HashMap<Player,ScanningJob>();
/**
* Constructor
*/
public StructureScanningService(){
super("StructureScanningService", new SignalType[]{
});
}
/**
* Queues a job to scan a player's construction to see if it is a structure
* @param player The player
* @param position The position
*/
public void queue(Player player, Vector3d position){
ScanningJob existing = this.playerTimeoutMap.get(player);
if(existing == null){
existing = new ScanningJob(Globals.timekeeper.getNumberOfRenderFramesElapsed() + StructureScanningService.FRAME_OFFSET_FOR_JOBS, position);
} else {
//debounce
existing.targetFrame = Globals.timekeeper.getNumberOfRenderFramesElapsed() + StructureScanningService.FRAME_OFFSET_FOR_JOBS;
existing.position = position;
}
this.playerTimeoutMap.put(player,existing);
}
/**
* Simulates the service
*/
public void simulate(){
}
/**
* A job to scan a region
*/
static class ScanningJob {
/**
* Frame to perform this job
*/
long targetFrame;
/**
* The position to begin scanning from
*/
Vector3d position;
/**
* Constructor
* @param targetFrame
* @param position
*/
public ScanningJob(long targetFrame, Vector3d position){
this.targetFrame = targetFrame;
this.position = position;
}
}
}