server state variable

This commit is contained in:
austin 2025-05-15 13:07:35 -04:00
parent 4e488e43cd
commit 96f6577f95
26 changed files with 71 additions and 67 deletions

View File

@ -17,7 +17,7 @@ public class ImGuiEntityServerTab {
public static void drawServerView(boolean show, Entity detailViewEntity){
if(show && ImGui.collapsingHeader("Server Details")){
ImGui.indent();
ServerDataCell serverDataCell = Globals.entityDataCellMapper.getEntityDataCell(detailViewEntity);
ServerDataCell serverDataCell = Globals.serverState.entityDataCellMapper.getEntityDataCell(detailViewEntity);
if(serverDataCell == null){
ImGui.text("Entity's data cell is null!");
} else {

View File

@ -68,14 +68,14 @@ public class ImGuiAI {
ImGui.text("AI");
//ai manager stuff
ImGui.text("AI Manager active: " + Globals.aiManager.isActive());
ImGui.text("AI Manager active: " + Globals.serverState.aiManager.isActive());
if(ImGui.button("Toggle AI Manager")){
Globals.aiManager.setActive(!Globals.aiManager.isActive());
Globals.serverState.aiManager.setActive(!Globals.serverState.aiManager.isActive());
}
if(ImGui.collapsingHeader("Statuses")){
for(AI ai : Globals.aiManager.getAIList()){
for(AI ai : Globals.serverState.aiManager.getAIList()){
ImGui.indent();
if(ImGui.collapsingHeader(ai.getParent().getId() + " - " + ai.getStatus())){
if(ImGui.button("Draw current pathing")){

View File

@ -43,7 +43,6 @@ import electrosphere.net.config.NetConfig;
import electrosphere.net.monitor.NetMonitor;
import electrosphere.net.server.player.PlayerManager;
import electrosphere.net.synchronization.server.EntityValueTrackingService;
import electrosphere.net.synchronization.server.ServerSynchronizationManager;
import electrosphere.renderer.RenderUtils;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.actor.instance.InstanceManager;
@ -60,8 +59,6 @@ import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.font.FontManager;
import electrosphere.script.ScriptEngine;
import electrosphere.server.ServerState;
import electrosphere.server.ai.AIManager;
import electrosphere.server.datacell.EntityDataCellMapper;
import electrosphere.server.datacell.RealmManager;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.entity.poseactor.PoseModel;
@ -166,7 +163,6 @@ public class Globals {
//
//Server manager thing
//
public static ServerSynchronizationManager serverSynchronizationManager;
public static boolean RUN_SERVER = true;
//
@ -212,7 +208,6 @@ public class Globals {
//Server scene management
//
public static RealmManager realmManager;
public static EntityDataCellMapper entityDataCellMapper;
//
//behavior tree tracking service
@ -342,10 +337,6 @@ public class Globals {
//collision world data
public static CollisionWorldData commonWorldData;
//ai manager
public static AIManager aiManager;
/**
* State for the client
@ -433,11 +424,8 @@ public class Globals {
skyboxColors = new ArrayList<Vector3f>();
//load asset manager
assetManager = new AssetManager();
//ai manager
aiManager = new AIManager(0);
//realm & data cell manager
realmManager = new RealmManager();
entityDataCellMapper = new EntityDataCellMapper();
//game config
gameConfigDefault = electrosphere.data.Config.loadDefaultConfig();
gameConfigCurrent = gameConfigDefault;
@ -456,7 +444,6 @@ public class Globals {
}
//profiler
profiler = new Profiler();
Globals.serverSynchronizationManager = new ServerSynchronizationManager();
Globals.movementAudioService = new MovementAudioService();
Globals.hitboxAudioService = new HitboxAudioService();
@ -634,13 +621,11 @@ public class Globals {
* Unloads scene
*/
public static void unloadScene(){
Globals.serverState.aiManager.shutdown();
Globals.playerManager = new PlayerManager();
Globals.clientState = new ClientState();
Globals.serverState = new ServerState();
Globals.serverSynchronizationManager = new ServerSynchronizationManager();
if(Globals.aiManager != null){
Globals.aiManager.shutdown();
}
if(Globals.realmManager != null){
Globals.realmManager.reset();
}
@ -653,8 +638,8 @@ public class Globals {
*/
public static void resetGlobals(){
Globals.unloadScene();
if(Globals.aiManager != null){
Globals.aiManager.shutdown();
if(Globals.serverState != null && Globals.serverState.aiManager != null){
Globals.serverState.aiManager.shutdown();
}
//
//Actual globals to destroy
@ -669,8 +654,6 @@ public class Globals {
Globals.signalSystem = null;
Globals.serviceManager = null;
Globals.fileWatcherService = null;
Globals.serverSynchronizationManager = null;
Globals.aiManager = null;
Globals.playerManager = null;
Globals.javaPID = null;
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;

View File

@ -31,7 +31,7 @@ public class ChunkGenerationTestLoading {
//
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.aiManager.setActive(false);
Globals.serverState.aiManager.setActive(false);
Globals.signalSystem.post(SignalType.UI_MODIFICATION, ()->{

View File

@ -51,7 +51,7 @@ public class LevelEditorLoading {
//
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
Globals.aiManager.setActive(false);
Globals.serverState.aiManager.setActive(false);
Globals.signalSystem.post(SignalType.UI_MODIFICATION, ()->{

View File

@ -1,5 +1,6 @@
package electrosphere.engine.loadingthreads;
import electrosphere.client.ClientState;
import electrosphere.client.ui.menu.WindowStrings;
import electrosphere.client.ui.menu.WindowUtils;
import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsTitleMenu;
@ -7,6 +8,7 @@ import electrosphere.engine.Globals;
import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
import electrosphere.renderer.ui.elements.Window;
import electrosphere.server.ServerState;
import electrosphere.server.datacell.RealmManager;
/**
@ -50,9 +52,8 @@ public class MainMenuLoading {
* Resets the client state
*/
private static void resetClientState(){
Globals.clientState.playerEntity = null;
Globals.clientState.clientSimulation = null;
Globals.clientState.clientConnection.setShouldDisconnect(true);
Globals.clientState = new ClientState();
Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(false);
}
@ -61,9 +62,7 @@ public class MainMenuLoading {
*/
private static void resetServerState(){
Globals.serverState.server.close();
Globals.serverState.server = null;
Globals.serverSynchronizationManager = null;
Globals.realmManager.reset();
Globals.serverState = new ServerState();
Globals.realmManager = new RealmManager();
}

View File

@ -50,11 +50,11 @@ public class EntityCreationUtils {
throw new IllegalStateException("Failed to create a server data cell");
}
//register to entity data cell mapper
Globals.entityDataCellMapper.registerEntity(rVal, cell);
Globals.serverState.entityDataCellMapper.registerEntity(rVal, cell);
//enable behavior tree tracking
ServerBehaviorTreeUtils.registerEntity(rVal);
if(Globals.entityDataCellMapper.getEntityDataCell(rVal) == null){
if(Globals.serverState.entityDataCellMapper.getEntityDataCell(rVal) == null){
throw new Error("Failed to map entity to cell!");
}
@ -79,11 +79,11 @@ public class EntityCreationUtils {
throw new IllegalStateException("Realm inventory data cell undefined!");
}
//register to entity data cell mapper
Globals.entityDataCellMapper.registerEntity(rVal, cell);
Globals.serverState.entityDataCellMapper.registerEntity(rVal, cell);
//enable behavior tree tracking
ServerBehaviorTreeUtils.registerEntity(rVal);
if(Globals.entityDataCellMapper.getEntityDataCell(rVal) == null){
if(Globals.serverState.entityDataCellMapper.getEntityDataCell(rVal) == null){
throw new Error("Failed to map entity to cell!");
}

View File

@ -43,14 +43,14 @@ public class EntityUtils {
Realm realm = Globals.realmManager.getEntityRealm(e);
if(realm != null){
//get data cell
ServerDataCell dataCell = Globals.entityDataCellMapper.getEntityDataCell(e);
ServerDataCell dataCell = Globals.serverState.entityDataCellMapper.getEntityDataCell(e);
if(dataCell != null){
dataCell.getScene().deregisterEntity(e);
}
}
Globals.realmManager.removeEntity(e);
}
Globals.entityDataCellMapper.ejectEntity(e);
Globals.serverState.entityDataCellMapper.ejectEntity(e);
EntityLookupUtils.removeEntity(e);
}

View File

@ -94,7 +94,7 @@ public class ServerEntityUtils {
*/
protected static void repositionEntityRecursive(Realm realm, Entity entity, Vector3d position){
//if server, get current server data cell
ServerDataCell oldDataCell = Globals.entityDataCellMapper.getEntityDataCell(entity);
ServerDataCell oldDataCell = Globals.serverState.entityDataCellMapper.getEntityDataCell(entity);
ServerDataCell newDataCell = realm.getDataCellManager().getDataCellAtPoint(position);
if(oldDataCell == null){
LoggerInterface.loggerEngine.WARNING(
@ -164,8 +164,8 @@ public class ServerEntityUtils {
HitboxCollectionState.destroyHitboxState(entity,true);
Globals.realmManager.removeEntity(entity);
EntityLookupUtils.removeEntity(entity);
if(Globals.aiManager != null){
Globals.aiManager.removeAI(entity);
if(Globals.serverState.aiManager != null){
Globals.serverState.aiManager.removeAI(entity);
}
if(ServerCharacterData.hasServerCharacterDataTree(entity)){
Globals.characterService.removeEntity(ServerCharacterData.getServerCharacterData(entity).getCharacterData());

View File

@ -514,7 +514,7 @@ public class ServerInventoryState implements BehaviorTree {
Realm realm = Globals.realmManager.getEntityRealm(realWorldItem);
if(realm != null){
//get closest chunk
ServerDataCell dataCell = Globals.entityDataCellMapper.getEntityDataCell(realWorldItem);
ServerDataCell dataCell = Globals.serverState.entityDataCellMapper.getEntityDataCell(realWorldItem);
//broadcast destroy item
NetworkMessage unequipMessage = InventoryMessage.constructserverCommandUnequipItemMessage(creature.getId(), InventoryProtocol.INVENTORY_TYPE_EQUIP, inventorySlot);
dataCell.broadcastNetworkMessage(unequipMessage);

View File

@ -772,7 +772,7 @@ public class CommonEntityUtils {
///
///
if(rawType.getAITrees() != null){
Globals.aiManager.attachAI(entity, rawType.getAITrees());
Globals.serverState.aiManager.attachAI(entity, rawType.getAITrees());
}
//add health system
@ -781,7 +781,7 @@ public class CommonEntityUtils {
ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.LIFE_STATE);
}
if(Globals.entityDataCellMapper.getEntityDataCell(entity) == null){
if(Globals.serverState.entityDataCellMapper.getEntityDataCell(entity) == null){
throw new Error("Failed to map entity to cell!");
}

View File

@ -583,7 +583,7 @@ public class ItemUtils {
if(Globals.realmManager.getEntityRealm(rVal) == null){
LoggerInterface.loggerEngine.ERROR(new IllegalStateException("Created item without it being assigned to a realm!"));
}
if(Globals.entityDataCellMapper.getEntityDataCell(rVal) == null){
if(Globals.serverState.entityDataCellMapper.getEntityDataCell(rVal) == null){
throw new Error("Failed to get data cell or the entity");
}
@ -628,7 +628,7 @@ public class ItemUtils {
if(Globals.realmManager.getEntityRealm(rVal) == null){
LoggerInterface.loggerEngine.ERROR(new IllegalStateException("Created item without it being assigned to a realm!"));
}
if(Globals.entityDataCellMapper.getEntityDataCell(rVal) == null){
if(Globals.serverState.entityDataCellMapper.getEntityDataCell(rVal) == null){
throw new Error("Failed to get data cell or the entity");
}

View File

@ -35,7 +35,7 @@ public class SynchronizationProtocol implements ServerProtocolTemplate<Synchroni
public void handleSyncMessage(ServerConnectionHandler connectionHandler, SynchronizationMessage message) {
switch(message.getMessageSubtype()){
case CLIENTREQUESTBTREEACTION:{
Globals.serverSynchronizationManager.pushMessage(message);
Globals.serverState.serverSynchronizationManager.pushMessage(message);
} break;
case UPDATECLIENTSTATE:
case UPDATECLIENTSTRINGSTATE:

View File

@ -12,6 +12,11 @@ public class MainServerFunctions {
* Calls the main server routines that should fire each frame
*/
public static void simulate(){
//check dependencies
if(Globals.serverState == null){
return;
}
Globals.profiler.beginCpuSample("MainServerFunctions.simulate");
//
@ -28,14 +33,14 @@ public class MainServerFunctions {
}
Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server process synchronization messages");
if(Globals.serverSynchronizationManager != null){
Globals.serverSynchronizationManager.processMessages();
if(Globals.serverState.serverSynchronizationManager != null){
Globals.serverState.serverSynchronizationManager.processMessages();
}
Globals.profiler.endCpuSample();
//
//Update AI
Globals.aiManager.simulate();
Globals.serverState.aiManager.simulate();
//
//Services

View File

@ -1,6 +1,9 @@
package electrosphere.server;
import electrosphere.net.server.Server;
import electrosphere.net.synchronization.server.ServerSynchronizationManager;
import electrosphere.server.ai.AIManager;
import electrosphere.server.datacell.EntityDataCellMapper;
/**
* Server state
@ -12,4 +15,19 @@ public class ServerState {
*/
public Server server;
/**
* Synchronization manager on the server
*/
public final ServerSynchronizationManager serverSynchronizationManager = new ServerSynchronizationManager();
/**
* ai manager
*/
public AIManager aiManager = new AIManager(0);
/**
* The entity->datacell mapper
*/
public final EntityDataCellMapper entityDataCellMapper = new EntityDataCellMapper();
}

View File

@ -32,12 +32,12 @@ public class StartTimerNode implements AITreeNode {
}
this.frameCount = frameCount;
//create the timer
Globals.aiManager.getTimerService().createTimer(this.frameCount);
Globals.serverState.aiManager.getTimerService().createTimer(this.frameCount);
}
@Override
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) {
TimerService timerService = Globals.aiManager.getTimerService();
TimerService timerService = Globals.serverState.aiManager.getTimerService();
if(timerService.isActive(this.timerId)){
return AITreeNodeResult.RUNNING;
} else {

View File

@ -56,7 +56,7 @@ public class RandomizerNode implements CollectionNode {
@Override
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) {
if(this.currentChild == null){
Random random = Globals.aiManager.getRandom();
Random random = Globals.serverState.aiManager.getRandom();
int selectedChild = random.nextInt(children.size());
this.currentChild = this.children.get(selectedChild);
}

View File

@ -43,19 +43,19 @@ public class TimerNode implements DecoratorNode {
}
this.child = child;
this.frameCount = frameCount;
this.timerId = Globals.aiManager.getTimerService().createTimer();
this.timerId = Globals.serverState.aiManager.getTimerService().createTimer();
}
@Override
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard) {
if(Globals.aiManager.getTimerService().isActive(timerId)){
if(Globals.serverState.aiManager.getTimerService().isActive(timerId)){
return AITreeNodeResult.RUNNING;
}
if(hasReset){
this.hasReset = false;
return AITreeNodeResult.SUCCESS;
} else {
Globals.aiManager.getTimerService().resetTimer(timerId, frameCount);
Globals.serverState.aiManager.getTimerService().resetTimer(timerId, frameCount);
this.hasReset = true;
return AITreeNodeResult.RUNNING;
}

View File

@ -24,7 +24,7 @@ public class NearbyEntityService implements AIService {
@Override
public void exec(){
for(AI ai : Globals.aiManager.getAIList()){
for(AI ai : Globals.serverState.aiManager.getAIList()){
Entity entity = ai.getParent();
Realm realm = Globals.realmManager.getEntityRealm(entity);
if(realm != null){

View File

@ -161,7 +161,7 @@ public class Realm {
*/
public void sendNetworkMessageToChunk(NetworkMessage message, Entity e){
//solve for what data cell the entitiy is in
ServerDataCell cell = Globals.entityDataCellMapper.getEntityDataCell(e);
ServerDataCell cell = Globals.serverState.entityDataCellMapper.getEntityDataCell(e);
cell.broadcastNetworkMessage(message);
}
@ -180,7 +180,7 @@ public class Realm {
//send the entity to all players
cell.initializeEntityForNewPlayers(entity, null);
//register to entity data cell mapper
Globals.entityDataCellMapper.registerEntity(entity, cell);
Globals.serverState.entityDataCellMapper.registerEntity(entity, cell);
}

View File

@ -209,7 +209,7 @@ public class ServerDataCell {
newCell.getScene().registerEntity(entity);
newCell.getScene().registerEntityToTags(entity, tags);
//update entity data cell mapper
Globals.entityDataCellMapper.updateEntityCell(entity, newCell);
Globals.serverState.entityDataCellMapper.updateEntityCell(entity, newCell);
//send the entity to new players that should care about it
for(Player player : newCell.activePlayers){
if(player.getPlayerEntity() == null || player.getPlayerEntity() != entity){

View File

@ -1183,7 +1183,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
@Override
public PathingProgressiveData findPathAsync(Vector3d start, Vector3d end) {
return Globals.aiManager.getPathfindingService().queuePathfinding(start, end, this.pathfinder, this);
return Globals.serverState.aiManager.getPathfindingService().queuePathfinding(start, end, this.pathfinder, this);
}
@Override

View File

@ -29,7 +29,7 @@ public class DataCellSearchUtils {
LoggerInterface.loggerEngine.ERROR(new IllegalArgumentException("Trying to get entity data cell of an entity that is not assigned to a realm!"));
return null;
}
return Globals.entityDataCellMapper.getEntityDataCell(entity);
return Globals.serverState.entityDataCellMapper.getEntityDataCell(entity);
}
/**

View File

@ -15,7 +15,7 @@ public class ServerEntityTagUtils {
* @param tag The tag
*/
public static void attachTagToEntity(Entity entity, String tag){
ServerDataCell cell = Globals.entityDataCellMapper.getEntityDataCell(entity);
ServerDataCell cell = Globals.serverState.entityDataCellMapper.getEntityDataCell(entity);
cell.getScene().registerEntityToTag(entity, tag);
}
@ -25,7 +25,7 @@ public class ServerEntityTagUtils {
* @param tag The tag
*/
public static void removeTagFromEntity(Entity entity, String tag){
ServerDataCell cell = Globals.entityDataCellMapper.getEntityDataCell(entity);
ServerDataCell cell = Globals.serverState.entityDataCellMapper.getEntityDataCell(entity);
cell.getScene().removeEntityFromTag(entity, tag);
}

View File

@ -44,8 +44,8 @@ public class UnitUtils {
//optionally apply ai
if(unitDefinition.getAI() != null){
Globals.aiManager.removeAI(rVal);
Globals.aiManager.attachAI(rVal, unitDefinition.getAI());
Globals.serverState.aiManager.removeAI(rVal);
Globals.serverState.aiManager.attachAI(rVal, unitDefinition.getAI());
}
//optionally add equipment

View File

@ -21,7 +21,6 @@ public class StateCleanupCheckerExtension implements AfterEachCallback {
Globals.renderingEngine,
Globals.audioEngine,
Globals.javaPID,
Globals.serverSynchronizationManager,
Globals.playerManager,
LoggerInterface.loggerEngine,
RenderingEngine.screenFramebuffer,