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 rendering flags under renderingEngine
|
||||
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
|
||||
*/
|
||||
public static void fireSignal(String signalName, Object ... args){
|
||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
if(Globals.scriptEngine != null && Globals.scriptEngine.isInitialized()){
|
||||
Globals.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
||||
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
if(Globals.engineState.scriptEngine != null && Globals.engineState.scriptEngine.isInitialized()){
|
||||
Globals.engineState.scriptEngine.getScriptContext().fireSignal(signalName, ScriptEngine.GLOBAL_SCENE, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,12 +2,14 @@ package electrosphere.engine;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import electrosphere.engine.os.fs.FileWatcherService;
|
||||
import electrosphere.engine.service.ServiceManager;
|
||||
import electrosphere.engine.signal.SignalSystem;
|
||||
import electrosphere.engine.signal.sync.MainThreadSignalService;
|
||||
import electrosphere.engine.threads.ThreadManager;
|
||||
import electrosphere.engine.time.Timekeeper;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.script.ScriptEngine;
|
||||
|
||||
/**
|
||||
* State of the engine
|
||||
@ -44,6 +46,16 @@ public class EngineState {
|
||||
*/
|
||||
public final MainThreadSignalService mainThreadSignalService;
|
||||
|
||||
/**
|
||||
* The scripting engine
|
||||
*/
|
||||
public final ScriptEngine scriptEngine;
|
||||
|
||||
/**
|
||||
* The file watcher service
|
||||
*/
|
||||
public final FileWatcherService fileWatcherService;
|
||||
|
||||
/**
|
||||
* Engine-wide flags
|
||||
*/
|
||||
@ -63,6 +75,8 @@ public class EngineState {
|
||||
this.threadManager.init();
|
||||
this.signalSystem = (SignalSystem)this.serviceManager.registerService(new SignalSystem());
|
||||
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.engine.assetmanager.AssetDataStrings;
|
||||
import electrosphere.engine.assetmanager.AssetManager;
|
||||
import electrosphere.engine.os.fs.FileWatcherService;
|
||||
import electrosphere.engine.profiler.Profiler;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.net.config.NetConfig;
|
||||
@ -32,7 +31,6 @@ import electrosphere.renderer.texture.TextureMap;
|
||||
import electrosphere.renderer.ui.ElementService;
|
||||
import electrosphere.renderer.ui.elements.ImagePanel;
|
||||
import electrosphere.renderer.ui.font.FontManager;
|
||||
import electrosphere.script.ScriptEngine;
|
||||
import electrosphere.server.ServerState;
|
||||
import electrosphere.server.entity.poseactor.PoseModel;
|
||||
import electrosphere.util.FileUtils;
|
||||
@ -71,6 +69,16 @@ public class Globals {
|
||||
* The audio engine
|
||||
*/
|
||||
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_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
|
||||
Globals.elementService = (ElementService)Globals.engineState.serviceManager.registerService(new ElementService());
|
||||
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();
|
||||
//
|
||||
//End service manager
|
||||
@ -367,7 +364,6 @@ public class Globals {
|
||||
Globals.audioEngine = null;
|
||||
Globals.engineState = null;
|
||||
Globals.renderingEngine = null;
|
||||
Globals.fileWatcherService = null;
|
||||
LoggerInterface.destroyLoggers();
|
||||
}
|
||||
|
||||
|
||||
@ -264,11 +264,11 @@ public class Main {
|
||||
///
|
||||
/// E N G I N E S E R V I C E S
|
||||
///
|
||||
if(Globals.fileWatcherService != null){
|
||||
Globals.fileWatcherService.poll();
|
||||
if(Globals.engineState.fileWatcherService != null){
|
||||
Globals.engineState.fileWatcherService.poll();
|
||||
}
|
||||
if(EngineState.EngineFlags.RUN_SCRIPTS && Globals.scriptEngine != null){
|
||||
Globals.scriptEngine.scanScriptDir();
|
||||
if(EngineState.EngineFlags.RUN_SCRIPTS && Globals.engineState.scriptEngine != null){
|
||||
Globals.engineState.scriptEngine.scanScriptDir();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ public class ChunkGenerationTestLoading {
|
||||
//wait on script engine to load
|
||||
if(ProceduralChunkGenerator.DEFAULT_USE_JAVASCRIPT){
|
||||
WindowUtils.updateLoadingWindow("Waiting on scripting engine");
|
||||
while(!Globals.scriptEngine.isInitialized()){
|
||||
while(!Globals.engineState.scriptEngine.isInitialized()){
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
} catch (InterruptedException ex) {}
|
||||
|
||||
@ -11,7 +11,7 @@ public class EngineInitLoading {
|
||||
* Loads the core assets of the scripting engine from disk and initializes the engine
|
||||
*/
|
||||
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
|
||||
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());
|
||||
Globals.assetManager.updateAsset(updatedPath.toString());
|
||||
}).setOnDelete(updatedPath -> {
|
||||
|
||||
@ -11,7 +11,7 @@ public class SynchronousSignalHandling {
|
||||
* Runs the main thread signal handlers
|
||||
*/
|
||||
public static void runMainThreadSignalHandlers(){
|
||||
Globals.scriptEngine.handleAllSignals();
|
||||
Globals.engineState.scriptEngine.handleAllSignals();
|
||||
Globals.engineState.mainThreadSignalService.handleAllSignals();
|
||||
}
|
||||
|
||||
|
||||
@ -156,8 +156,8 @@ public class SceneLoader {
|
||||
//load scripts
|
||||
if(!isLevelEditor && file.getInitScriptPath() != null){
|
||||
Realm finalRealm = realm;
|
||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
int sceneInstanceId = Globals.scriptEngine.getScriptContext().initScene(file.getInitScriptPath());
|
||||
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
int sceneInstanceId = Globals.engineState.scriptEngine.getScriptContext().initScene(file.getInitScriptPath());
|
||||
finalRealm.setSceneInstanceId(sceneInstanceId);
|
||||
});
|
||||
}
|
||||
|
||||
@ -291,8 +291,8 @@ public class ScriptContext {
|
||||
*/
|
||||
protected void recompile(Runnable onCompletion){
|
||||
Thread recompileThread = new Thread(() -> {
|
||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
Globals.scriptEngine.initScripts();
|
||||
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
Globals.engineState.scriptEngine.initScripts();
|
||||
});
|
||||
if(onCompletion != null){
|
||||
onCompletion.run();
|
||||
|
||||
@ -17,7 +17,6 @@ import electrosphere.client.script.ScriptClientVoxelUtils;
|
||||
import electrosphere.client.ui.menu.script.ScriptLevelEditorUtils;
|
||||
import electrosphere.client.ui.menu.script.ScriptMenuUtils;
|
||||
import electrosphere.client.ui.menu.tutorial.TutorialMenus;
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.engine.signal.Signal;
|
||||
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
|
||||
*/
|
||||
public static final Object[][] hostSingletops = new Object[][]{
|
||||
{"timekeeper",Globals.engineState.timekeeper},
|
||||
{"currentPlayer",Globals.clientState.clientPlayer},
|
||||
{"loggerScripts",LoggerInterface.loggerScripts},
|
||||
};
|
||||
|
||||
|
||||
@ -345,12 +345,12 @@ public class Realm {
|
||||
* @param args The arguments provided alongside the signal
|
||||
*/
|
||||
public void fireSignal(String signalName, Object ... args){
|
||||
if(Globals.scriptEngine != null && Globals.scriptEngine.isInitialized()){
|
||||
Globals.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
if(Globals.engineState.scriptEngine != null && Globals.engineState.scriptEngine.isInitialized()){
|
||||
Globals.engineState.scriptEngine.getScriptContext().executeSynchronously(() -> {
|
||||
if(this.sceneInstanceId != NO_SCENE_INSTANCE){
|
||||
Globals.scriptEngine.getScriptContext().fireSignal(signalName, sceneInstanceId, args);
|
||||
Globals.engineState.scriptEngine.getScriptContext().fireSignal(signalName, sceneInstanceId, args);
|
||||
} 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;
|
||||
boolean homogenous = true;
|
||||
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++){
|
||||
Globals.profiler.beginAggregateCpuSample("TestGenerationChunkGenerator - Generate slice");
|
||||
for(int y = 0; y < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; y++){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user