move more services into engineState
This commit is contained in:
parent
bcf76c692e
commit
263312c761
@ -1829,6 +1829,7 @@ Move fluidCellManager into clientState
|
|||||||
Move engine flags under engineState
|
Move engine flags under engineState
|
||||||
Move rendering flags under renderingEngine
|
Move rendering flags under renderingEngine
|
||||||
Move database connection into serverState
|
Move database connection into serverState
|
||||||
|
Move more services into engineState
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,9 @@ public class ClientScriptUtils {
|
|||||||
* @param args The arguments provided alongside the signal
|
* @param args The arguments provided alongside the signal
|
||||||
*/
|
*/
|
||||||
public static void fireSignal(String signalName, Object ... args){
|
public static void fireSignal(String signalName, Object ... args){
|
||||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||||
if(Globals.scriptEngine != null && Globals.scriptEngine.isInitialized()){
|
if(Globals.engineState.scriptEngine != null && Globals.engineState.scriptEngine.isInitialized()){
|
||||||
Globals.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
Globals.engineState.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,14 @@ package electrosphere.engine;
|
|||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
|
import electrosphere.engine.os.fs.FileWatcherService;
|
||||||
import electrosphere.engine.service.ServiceManager;
|
import electrosphere.engine.service.ServiceManager;
|
||||||
import electrosphere.engine.signal.SignalSystem;
|
import electrosphere.engine.signal.SignalSystem;
|
||||||
import electrosphere.engine.signal.sync.MainThreadSignalService;
|
import electrosphere.engine.signal.sync.MainThreadSignalService;
|
||||||
import electrosphere.engine.threads.ThreadManager;
|
import electrosphere.engine.threads.ThreadManager;
|
||||||
import electrosphere.engine.time.Timekeeper;
|
import electrosphere.engine.time.Timekeeper;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
import electrosphere.script.ScriptEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State of the engine
|
* State of the engine
|
||||||
@ -44,6 +46,16 @@ public class EngineState {
|
|||||||
*/
|
*/
|
||||||
public final MainThreadSignalService mainThreadSignalService;
|
public final MainThreadSignalService mainThreadSignalService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scripting engine
|
||||||
|
*/
|
||||||
|
public final ScriptEngine scriptEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file watcher service
|
||||||
|
*/
|
||||||
|
public final FileWatcherService fileWatcherService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Engine-wide flags
|
* Engine-wide flags
|
||||||
*/
|
*/
|
||||||
@ -63,6 +75,8 @@ public class EngineState {
|
|||||||
this.threadManager.init();
|
this.threadManager.init();
|
||||||
this.signalSystem = (SignalSystem)this.serviceManager.registerService(new SignalSystem());
|
this.signalSystem = (SignalSystem)this.serviceManager.registerService(new SignalSystem());
|
||||||
this.mainThreadSignalService = (MainThreadSignalService)this.serviceManager.registerService(new MainThreadSignalService());
|
this.mainThreadSignalService = (MainThreadSignalService)this.serviceManager.registerService(new MainThreadSignalService());
|
||||||
|
this.scriptEngine = (ScriptEngine)this.serviceManager.registerService(new ScriptEngine());
|
||||||
|
this.fileWatcherService = (FileWatcherService)this.serviceManager.registerService(new FileWatcherService());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import electrosphere.controls.cursor.CursorState;
|
|||||||
import electrosphere.data.voxel.VoxelType;
|
import electrosphere.data.voxel.VoxelType;
|
||||||
import electrosphere.engine.assetmanager.AssetDataStrings;
|
import electrosphere.engine.assetmanager.AssetDataStrings;
|
||||||
import electrosphere.engine.assetmanager.AssetManager;
|
import electrosphere.engine.assetmanager.AssetManager;
|
||||||
import electrosphere.engine.os.fs.FileWatcherService;
|
|
||||||
import electrosphere.engine.profiler.Profiler;
|
import electrosphere.engine.profiler.Profiler;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.net.config.NetConfig;
|
import electrosphere.net.config.NetConfig;
|
||||||
@ -32,7 +31,6 @@ import electrosphere.renderer.texture.TextureMap;
|
|||||||
import electrosphere.renderer.ui.ElementService;
|
import electrosphere.renderer.ui.ElementService;
|
||||||
import electrosphere.renderer.ui.elements.ImagePanel;
|
import electrosphere.renderer.ui.elements.ImagePanel;
|
||||||
import electrosphere.renderer.ui.font.FontManager;
|
import electrosphere.renderer.ui.font.FontManager;
|
||||||
import electrosphere.script.ScriptEngine;
|
|
||||||
import electrosphere.server.ServerState;
|
import electrosphere.server.ServerState;
|
||||||
import electrosphere.server.entity.poseactor.PoseModel;
|
import electrosphere.server.entity.poseactor.PoseModel;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
@ -71,6 +69,16 @@ public class Globals {
|
|||||||
* The audio engine
|
* The audio engine
|
||||||
*/
|
*/
|
||||||
public static AudioEngine audioEngine;
|
public static AudioEngine audioEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The asset manager
|
||||||
|
*/
|
||||||
|
public static AssetManager assetManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authentication manager
|
||||||
|
*/
|
||||||
|
public static AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -90,15 +98,6 @@ public class Globals {
|
|||||||
//
|
//
|
||||||
public static int WINDOW_WIDTH;
|
public static int WINDOW_WIDTH;
|
||||||
public static int WINDOW_HEIGHT;
|
public static int WINDOW_HEIGHT;
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
//Engine-adjacent stuff to move into engine state eventually
|
|
||||||
//
|
|
||||||
public static AuthenticationManager authenticationManager;
|
|
||||||
public static AssetManager assetManager;
|
|
||||||
public static ScriptEngine scriptEngine;
|
|
||||||
public static FileWatcherService fileWatcherService;
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -181,8 +180,6 @@ public class Globals {
|
|||||||
//add services here
|
//add services here
|
||||||
Globals.elementService = (ElementService)Globals.engineState.serviceManager.registerService(new ElementService());
|
Globals.elementService = (ElementService)Globals.engineState.serviceManager.registerService(new ElementService());
|
||||||
Globals.particleService = (ParticleService)Globals.engineState.serviceManager.registerService(new ParticleService());
|
Globals.particleService = (ParticleService)Globals.engineState.serviceManager.registerService(new ParticleService());
|
||||||
Globals.scriptEngine = (ScriptEngine)Globals.engineState.serviceManager.registerService(new ScriptEngine());
|
|
||||||
Globals.fileWatcherService = (FileWatcherService)Globals.engineState.serviceManager.registerService(new FileWatcherService());
|
|
||||||
Globals.engineState.serviceManager.instantiate();
|
Globals.engineState.serviceManager.instantiate();
|
||||||
//
|
//
|
||||||
//End service manager
|
//End service manager
|
||||||
@ -367,7 +364,6 @@ public class Globals {
|
|||||||
Globals.audioEngine = null;
|
Globals.audioEngine = null;
|
||||||
Globals.engineState = null;
|
Globals.engineState = null;
|
||||||
Globals.renderingEngine = null;
|
Globals.renderingEngine = null;
|
||||||
Globals.fileWatcherService = null;
|
|
||||||
LoggerInterface.destroyLoggers();
|
LoggerInterface.destroyLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -264,11 +264,11 @@ public class Main {
|
|||||||
///
|
///
|
||||||
/// E N G I N E S E R V I C E S
|
/// E N G I N E S E R V I C E S
|
||||||
///
|
///
|
||||||
if(Globals.fileWatcherService != null){
|
if(Globals.engineState.fileWatcherService != null){
|
||||||
Globals.fileWatcherService.poll();
|
Globals.engineState.fileWatcherService.poll();
|
||||||
}
|
}
|
||||||
if(EngineState.EngineFlags.RUN_SCRIPTS && Globals.scriptEngine != null){
|
if(EngineState.EngineFlags.RUN_SCRIPTS && Globals.engineState.scriptEngine != null){
|
||||||
Globals.scriptEngine.scanScriptDir();
|
Globals.engineState.scriptEngine.scanScriptDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class ChunkGenerationTestLoading {
|
|||||||
//wait on script engine to load
|
//wait on script engine to load
|
||||||
if(ProceduralChunkGenerator.DEFAULT_USE_JAVASCRIPT){
|
if(ProceduralChunkGenerator.DEFAULT_USE_JAVASCRIPT){
|
||||||
WindowUtils.updateLoadingWindow("Waiting on scripting engine");
|
WindowUtils.updateLoadingWindow("Waiting on scripting engine");
|
||||||
while(!Globals.scriptEngine.isInitialized()){
|
while(!Globals.engineState.scriptEngine.isInitialized()){
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(1);
|
TimeUnit.MILLISECONDS.sleep(1);
|
||||||
} catch (InterruptedException ex) {}
|
} catch (InterruptedException ex) {}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public class EngineInitLoading {
|
|||||||
* Loads the core assets of the scripting engine from disk and initializes the engine
|
* Loads the core assets of the scripting engine from disk and initializes the engine
|
||||||
*/
|
*/
|
||||||
protected static void loadScriptingEngine(Object[] params){
|
protected static void loadScriptingEngine(Object[] params){
|
||||||
Globals.scriptEngine.initScripts();
|
Globals.engineState.scriptEngine.initScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class OSDragAndDrop {
|
|||||||
|
|
||||||
//watch the asset for file updates
|
//watch the asset for file updates
|
||||||
LoggerInterface.loggerEngine.WARNING("Tracking " + rawPath);
|
LoggerInterface.loggerEngine.WARNING("Tracking " + rawPath);
|
||||||
Globals.fileWatcherService.trackFile(new FileWatcher(rawPath).setOnWrite(updatedPath -> {
|
Globals.engineState.fileWatcherService.trackFile(new FileWatcher(rawPath).setOnWrite(updatedPath -> {
|
||||||
LoggerInterface.loggerFileIO.WARNING("File updated: " + updatedPath.toString());
|
LoggerInterface.loggerFileIO.WARNING("File updated: " + updatedPath.toString());
|
||||||
Globals.assetManager.updateAsset(updatedPath.toString());
|
Globals.assetManager.updateAsset(updatedPath.toString());
|
||||||
}).setOnDelete(updatedPath -> {
|
}).setOnDelete(updatedPath -> {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public class SynchronousSignalHandling {
|
|||||||
* Runs the main thread signal handlers
|
* Runs the main thread signal handlers
|
||||||
*/
|
*/
|
||||||
public static void runMainThreadSignalHandlers(){
|
public static void runMainThreadSignalHandlers(){
|
||||||
Globals.scriptEngine.handleAllSignals();
|
Globals.engineState.scriptEngine.handleAllSignals();
|
||||||
Globals.engineState.mainThreadSignalService.handleAllSignals();
|
Globals.engineState.mainThreadSignalService.handleAllSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -156,8 +156,8 @@ public class SceneLoader {
|
|||||||
//load scripts
|
//load scripts
|
||||||
if(!isLevelEditor && file.getInitScriptPath() != null){
|
if(!isLevelEditor && file.getInitScriptPath() != null){
|
||||||
Realm finalRealm = realm;
|
Realm finalRealm = realm;
|
||||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||||
int sceneInstanceId = Globals.scriptEngine.getScriptContext().initScene(file.getInitScriptPath());
|
int sceneInstanceId = Globals.engineState.scriptEngine.getScriptContext().initScene(file.getInitScriptPath());
|
||||||
finalRealm.setSceneInstanceId(sceneInstanceId);
|
finalRealm.setSceneInstanceId(sceneInstanceId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -291,8 +291,8 @@ public class ScriptContext {
|
|||||||
*/
|
*/
|
||||||
protected void recompile(Runnable onCompletion){
|
protected void recompile(Runnable onCompletion){
|
||||||
Thread recompileThread = new Thread(() -> {
|
Thread recompileThread = new Thread(() -> {
|
||||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||||
Globals.scriptEngine.initScripts();
|
Globals.engineState.scriptEngine.initScripts();
|
||||||
});
|
});
|
||||||
if(onCompletion != null){
|
if(onCompletion != null){
|
||||||
onCompletion.run();
|
onCompletion.run();
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import electrosphere.client.script.ScriptClientVoxelUtils;
|
|||||||
import electrosphere.client.ui.menu.script.ScriptLevelEditorUtils;
|
import electrosphere.client.ui.menu.script.ScriptLevelEditorUtils;
|
||||||
import electrosphere.client.ui.menu.script.ScriptMenuUtils;
|
import electrosphere.client.ui.menu.script.ScriptMenuUtils;
|
||||||
import electrosphere.client.ui.menu.tutorial.TutorialMenus;
|
import electrosphere.client.ui.menu.tutorial.TutorialMenus;
|
||||||
import electrosphere.engine.Globals;
|
|
||||||
import electrosphere.engine.Main;
|
import electrosphere.engine.Main;
|
||||||
import electrosphere.engine.signal.Signal;
|
import electrosphere.engine.signal.Signal;
|
||||||
import electrosphere.engine.signal.Signal.SignalType;
|
import electrosphere.engine.signal.Signal.SignalType;
|
||||||
@ -126,8 +125,6 @@ public class ScriptEngine extends SignalServiceImpl {
|
|||||||
* singletons from the host that are provided to the javascript context
|
* singletons from the host that are provided to the javascript context
|
||||||
*/
|
*/
|
||||||
public static final Object[][] hostSingletops = new Object[][]{
|
public static final Object[][] hostSingletops = new Object[][]{
|
||||||
{"timekeeper",Globals.engineState.timekeeper},
|
|
||||||
{"currentPlayer",Globals.clientState.clientPlayer},
|
|
||||||
{"loggerScripts",LoggerInterface.loggerScripts},
|
{"loggerScripts",LoggerInterface.loggerScripts},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -345,12 +345,12 @@ public class Realm {
|
|||||||
* @param args The arguments provided alongside the signal
|
* @param args The arguments provided alongside the signal
|
||||||
*/
|
*/
|
||||||
public void fireSignal(String signalName, Object ... args){
|
public void fireSignal(String signalName, Object ... args){
|
||||||
if(Globals.scriptEngine != null && Globals.scriptEngine.isInitialized()){
|
if(Globals.engineState.scriptEngine != null && Globals.engineState.scriptEngine.isInitialized()){
|
||||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||||
if(this.sceneInstanceId != NO_SCENE_INSTANCE){
|
if(this.sceneInstanceId != NO_SCENE_INSTANCE){
|
||||||
Globals.scriptEngine.getScriptContext().fireSignal(signalName, sceneInstanceId, args);
|
Globals.engineState.scriptEngine.getScriptContext().fireSignal(signalName, sceneInstanceId, args);
|
||||||
} else {
|
} else {
|
||||||
Globals.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
Globals.engineState.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -167,11 +167,11 @@ public class JSChunkGenerator implements ChunkGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||||
int firstType = -2;
|
int firstType = -2;
|
||||||
boolean homogenous = true;
|
boolean homogenous = true;
|
||||||
GeneratedVoxel voxel = new GeneratedVoxel();
|
GeneratedVoxel voxel = new GeneratedVoxel();
|
||||||
Value getVoxelFunc = Globals.scriptEngine.getScriptContext().invokeEngineMember("chunkGeneratorManager", "getVoxelFunction", SCRIPT_GEN_TEST_TAG);
|
Value getVoxelFunc = Globals.engineState.scriptEngine.getScriptContext().invokeEngineMember("chunkGeneratorManager", "getVoxelFunction", SCRIPT_GEN_TEST_TAG);
|
||||||
for(int x = 0; x < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; x++){
|
for(int x = 0; x < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; x++){
|
||||||
Globals.profiler.beginAggregateCpuSample("TestGenerationChunkGenerator - Generate slice");
|
Globals.profiler.beginAggregateCpuSample("TestGenerationChunkGenerator - Generate slice");
|
||||||
for(int y = 0; y < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; y++){
|
for(int y = 0; y < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; y++){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user