package electrosphere.engine.loadingthreads; import java.util.concurrent.Semaphore; /** * Threads for loading engine state */ public class LoadingThread extends Thread { public static final int LOAD_TITLE_MENU = 0; //loads the main game title menu public static final int LOAD_MAIN_GAME = 1; //loads the main game public static final int LOAD_ARENA = 2; //loads the arena public static final int LOAD_CHARACTER_SERVER = 3; //loads the character creation menus on the client public static final int LOAD_CLIENT_WORLD = 4; //loads the client world public static final int LOAD_DEBUG_RANDOM_SP_WORLD = 5; //loads a random singleplayer debug world public static final int LOAD_LEVEL_EDITOR = 6; //loads the level editor public static final int LOAD_LEVEL = 7; //loads a level public static final int LOAD_DEMO_MENU = 8; //loads the main menu ui for the demo version of the client //the type of loading to do int threadType; //a lock to track when the loading had completed and block until then Semaphore lock; /** * Creates the work for a loading thread * @param type The type of thread */ public LoadingThread(int type){ threadType = type; lock = new Semaphore(1); } @Override public void run(){ lock.acquireUninterruptibly(); switch(threadType){ case LOAD_TITLE_MENU: { ClientLoading.loadMainMenu(); } break; case LOAD_MAIN_GAME: { ServerLoading.loadMainGameServer(); } break; case LOAD_ARENA: { ArenaLoading.loadArenaGameServer(); } break; case LOAD_CHARACTER_SERVER: { ClientLoading.loadCharacterServer(); } break; case LOAD_CLIENT_WORLD: { ClientLoading.loadClientWorld(); } break; //intended to act like you went through the steps of setting up a vanilla settings SP world case LOAD_DEBUG_RANDOM_SP_WORLD: { DebugSPWorldLoading.loadDebugSPWorld(); } break; //loads the level editor case LOAD_LEVEL_EDITOR: { LevelEditorLoading.loadLevelEditor(); } break; //loads the save in Globals.currentSave as a level case LOAD_LEVEL: { LevelLoading.loadLevel(); } break; //the demo menu ui case LOAD_DEMO_MENU: { DemoLoading.loadDemoMenu(); } break; } lock.release(); } /** * Checks if the thread has finished loading * @return true if it has finished, false otherwise */ public boolean isDone(){ boolean rVal = lock.tryAcquire(); if(rVal == true){ lock.release(); } return rVal; } }