Renderer/src/main/java/electrosphere/engine/loadingthreads/LoadingThread.java
austin 82027a20cb
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
more threading work
2024-08-23 09:38:12 -04:00

138 lines
3.1 KiB
Java

package electrosphere.engine.loadingthreads;
/**
* Threads for loading engine state
*/
public class LoadingThread extends Thread {
/**
* The types of threads available
*/
public static enum LoadingThreadType {
/**
* Loads the main game title menu
*/
TITLE_MENU,
/**
* Loads the main game
*/
MAIN_GAME,
/**
* Loads the character creation menus on the client
*/
CHARACTER_SERVER,
/**
* Loads the client world
*/
CLIENT_WORLD,
/**
* Loads a random singleplayer debug world
*/
DEBUG_RANDOM_SP_WORLD,
/**
* Loads the level editor
*/
LEVEL_EDITOR,
/**
* Loads a level
*/
LEVEL,
/**
* Loads the main menu ui for the demo version of the client
*/
DEMO_MENU,
}
/**
* The type of loading to run
*/
LoadingThreadType threadType;
//the params provided to this thread in particular
Object[] params;
//tracks whether the thread is done loading or not
boolean isDone = false;
/**
* Creates the work for a loading thread
* @param type The type of thread
* @param params The params provided to the thread
*/
public LoadingThread(LoadingThreadType type, Object ... params){
threadType = type;
this.params = params;
}
@Override
public void run(){
switch(threadType){
case TITLE_MENU: {
ClientLoading.loadMainMenu(this.params);
} break;
case MAIN_GAME: {
ServerLoading.loadMainGameServer(this.params);
} break;
case CHARACTER_SERVER: {
ClientLoading.loadCharacterServer(this.params);
} break;
case CLIENT_WORLD: {
ClientLoading.loadClientWorld(this.params);
} break;
//intended to act like you went through the steps of setting up a vanilla settings SP world
case DEBUG_RANDOM_SP_WORLD: {
DebugSPWorldLoading.loadDebugSPWorld(this.params);
} break;
//loads the level editor
case LEVEL_EDITOR: {
LevelEditorLoading.loadLevelEditor(this.params);
} break;
//loads the save in Globals.currentSave as a level
case LEVEL: {
LevelLoading.loadLevel(this.params);
} break;
//the demo menu ui
case DEMO_MENU: {
DemoLoading.loadDemoMenu(this.params);
} break;
}
isDone = true;
}
/**
* Checks if the thread has finished loading
* @return true if it has finished, false otherwise
*/
public boolean isDone(){
return isDone;
}
/**
* Gets the type of the loading thread
* @return The type
*/
public LoadingThreadType getType(){
return this.threadType;
}
}