main menu backout test and fix
This commit is contained in:
parent
eff082ca76
commit
969e49251e
@ -623,9 +623,9 @@ public class Globals {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets global values
|
||||
* Unloads scene
|
||||
*/
|
||||
public static void resetGlobals(){
|
||||
public static void unloadScene(){
|
||||
Globals.playerEntity = null;
|
||||
Globals.playerCamera = null;
|
||||
Globals.firstPersonEntity = null;
|
||||
@ -635,6 +635,15 @@ public class Globals {
|
||||
Globals.clientSceneWrapper = new ClientSceneWrapper(Globals.clientScene, new CollisionEngine());
|
||||
Globals.clientSynchronizationManager = new ClientSynchronizationManager();
|
||||
Globals.realmManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets global values
|
||||
*/
|
||||
public static void resetGlobals(){
|
||||
Globals.unloadScene();
|
||||
//
|
||||
//Actual globals to destroy
|
||||
Globals.assetManager = null;
|
||||
//
|
||||
//Destroy services
|
||||
|
||||
@ -103,8 +103,8 @@ public class ClientLoading {
|
||||
*/
|
||||
protected static void loadViewport(Object[] params){
|
||||
Window loadingWindow = (Window)Globals.elementService.getWindow(WindowStrings.WINDOW_LOADING);
|
||||
WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
|
||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
|
||||
WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
|
||||
loadingWindow.setVisible(true);
|
||||
//disable menu input
|
||||
Globals.controlHandler.hintUpdateControlState(ControlHandler.ControlsState.NO_INPUT);
|
||||
|
||||
@ -90,61 +90,70 @@ public class LoadingThread extends Thread {
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
switch(threadType){
|
||||
execSync(this.threadType, this.params);
|
||||
isDone = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a loading task in the current thread
|
||||
* @param type The type of loading task
|
||||
* @param params The params for the loading task
|
||||
*/
|
||||
public static void execSync(LoadingThreadType type, Object ... params){
|
||||
switch(type){
|
||||
|
||||
case TITLE_MENU: {
|
||||
MainMenuLoading.loadMainMenu(this.params);
|
||||
MainMenuLoading.loadMainMenu(params);
|
||||
} break;
|
||||
|
||||
case RETURN_TITLE_MENU: {
|
||||
MainMenuLoading.returnToMainMenu(this.params);
|
||||
MainMenuLoading.returnToMainMenu(params);
|
||||
} break;
|
||||
|
||||
case MAIN_GAME: {
|
||||
ServerLoading.loadMainGameServer(this.params);
|
||||
ServerLoading.loadMainGameServer(params);
|
||||
} break;
|
||||
|
||||
case CHARACTER_SERVER: {
|
||||
ClientLoading.loadCharacterServer(this.params);
|
||||
ClientLoading.loadCharacterServer(params);
|
||||
} break;
|
||||
|
||||
case CLIENT_WORLD: {
|
||||
ClientLoading.loadClientWorld(this.params);
|
||||
ClientLoading.loadClientWorld(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);
|
||||
DebugSPWorldLoading.loadDebugSPWorld(params);
|
||||
} break;
|
||||
|
||||
//loads the level editor
|
||||
case LEVEL_EDITOR: {
|
||||
LevelEditorLoading.loadLevelEditor(this.params);
|
||||
LevelEditorLoading.loadLevelEditor(params);
|
||||
} break;
|
||||
|
||||
//loads the save in Globals.currentSave as a level
|
||||
case LEVEL: {
|
||||
LevelLoading.loadLevel(this.params);
|
||||
LevelLoading.loadLevel(params);
|
||||
} break;
|
||||
|
||||
//the demo menu ui
|
||||
case DEMO_MENU: {
|
||||
DemoLoading.loadDemoMenu(this.params);
|
||||
DemoLoading.loadDemoMenu(params);
|
||||
} break;
|
||||
|
||||
//Inits the script engine
|
||||
case SCRIPT_ENGINE: {
|
||||
EngineInitLoading.loadScriptingEngine(this.params);
|
||||
EngineInitLoading.loadScriptingEngine(params);
|
||||
} break;
|
||||
|
||||
//Loads the viewport
|
||||
case LOAD_VIEWPORT: {
|
||||
ViewportLoading.loadViewport(this.params);
|
||||
ViewportLoading.loadViewport(params);
|
||||
} break;
|
||||
|
||||
}
|
||||
isDone = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -31,7 +31,7 @@ public class MainMenuLoading {
|
||||
//reset state
|
||||
MainMenuLoading.resetClientState();
|
||||
MainMenuLoading.resetServerState();
|
||||
Globals.resetGlobals();
|
||||
Globals.unloadScene();
|
||||
Globals.threadManager.interruptLabel(ThreadLabel.NETWORKING_CLIENT);
|
||||
Globals.threadManager.interruptLabel(ThreadLabel.NETWORKING_SERVER);
|
||||
|
||||
|
||||
@ -56,6 +56,19 @@ public class WindowUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the window string is visible
|
||||
* @param windowString The window string
|
||||
* @return true if is visible, false otherwise
|
||||
*/
|
||||
public static boolean windowIsVisible(String windowString){
|
||||
Element windowElement = Globals.elementService.getWindow(windowString);
|
||||
if(windowElement instanceof DrawableElement){
|
||||
return ((DrawableElement)windowElement).getVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the window registered to the provided string is open
|
||||
* @param windowString The window string
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package electrosphere.engine.loadingthreads;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
||||
import electrosphere.test.annotations.IntegrationTest;
|
||||
import electrosphere.test.testutils.EngineInit;
|
||||
import electrosphere.test.testutils.TestEngineUtils;
|
||||
|
||||
/**
|
||||
* Tests (re)loading the main menu
|
||||
*/
|
||||
public class MainMenuLoadingTests {
|
||||
|
||||
@AfterEach
|
||||
public void clearTest(){
|
||||
Main.shutdown();
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testBackout_ThrowsError_False(){
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load viewport
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//make sure backout doesn't crash
|
||||
assertDoesNotThrow(()->{
|
||||
LoadingThread.execSync(LoadingThreadType.RETURN_TITLE_MENU);
|
||||
|
||||
//guarantees the engine can continue to execute after the thread resolves)
|
||||
TestEngineUtils.simulateFrames(1);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,22 +1,31 @@
|
||||
package electrosphere.engine.loadingthreads;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
import electrosphere.test.annotations.IntegrationTest;
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.menu.WindowStrings;
|
||||
import electrosphere.menu.WindowUtils;
|
||||
import electrosphere.test.testutils.EngineInit;
|
||||
import electrosphere.test.testutils.TestEngineUtils;
|
||||
|
||||
/**
|
||||
* Tests loading viewport
|
||||
*/
|
||||
public class ViewportLoadingTests {
|
||||
|
||||
@AfterEach
|
||||
public void clearTest(){
|
||||
Main.shutdown();
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testViewportLoading(){
|
||||
Assertions.assertDoesNotThrow(() -> {
|
||||
public void testViewportLoading_ThrowsError_False(){
|
||||
assertDoesNotThrow(() -> {
|
||||
//init engine
|
||||
TestEngineUtils.initGraphicalEngine();
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
@ -26,4 +35,98 @@ public class ViewportLoadingTests {
|
||||
});
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testViewportLoading_MainMenuVisible_False(){
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should see viewport here
|
||||
assertEquals(false,WindowUtils.windowIsVisible(WindowStrings.WINDOW_MENU_MAIN));
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testViewportLoadingTwice_MainMenuVisible_False(){
|
||||
//init engine once
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should see viewport here
|
||||
|
||||
//shutdown engine
|
||||
Main.shutdown();
|
||||
|
||||
//init engine second time
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should still see viewport here
|
||||
assertEquals(false,WindowUtils.windowIsVisible(WindowStrings.WINDOW_MENU_MAIN));
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testViewportLoadingTwice_LoadingMenuVisible_False(){
|
||||
//init engine once
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should see viewport here
|
||||
|
||||
//shutdown engine
|
||||
Main.shutdown();
|
||||
|
||||
//init engine second time
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should still see viewport here
|
||||
assertEquals(false,WindowUtils.windowIsVisible(WindowStrings.WINDOW_LOADING));
|
||||
}
|
||||
|
||||
@IntegrationTest
|
||||
public void testViewportLoadingTwice_ScreenFramebufferFlags_True(){
|
||||
//init engine once
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should see viewport here
|
||||
|
||||
//shutdown engine
|
||||
Main.shutdown();
|
||||
|
||||
//init engine second time
|
||||
|
||||
//init engine
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
//should still see viewport here
|
||||
assertEquals(true,Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER);
|
||||
assertEquals(true,Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.test.testutils.EngineInit;
|
||||
import electrosphere.test.testutils.TestEngineUtils;
|
||||
|
||||
/**
|
||||
* Spins up and tears down entity testing environment
|
||||
@ -16,7 +15,7 @@ public class EntityExtension implements BeforeEachCallback, AfterEachCallback {
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext context) throws Exception {
|
||||
//init engine
|
||||
TestEngineUtils.initGraphicalEngine();
|
||||
EngineInit.initGraphicalEngine();
|
||||
|
||||
//load scene
|
||||
EngineInit.setupConnectedTestViewport();
|
||||
|
||||
@ -6,7 +6,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.test.testutils.TestEngineUtils;
|
||||
import electrosphere.test.testutils.EngineInit;
|
||||
|
||||
/**
|
||||
* Spins up an tears down generic rendering environment
|
||||
@ -20,7 +20,7 @@ public class RenderingExtension implements BeforeEachCallback, AfterEachCallback
|
||||
Globals.RUN_AUDIO = false;
|
||||
Globals.WINDOW_WIDTH = 1920;
|
||||
Globals.WINDOW_HEIGHT = 1080;
|
||||
TestEngineUtils.initGraphicalEngine();
|
||||
EngineInit.initGraphicalEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -3,14 +3,43 @@ package electrosphere.test.testutils;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.engine.loadingthreads.LoadingThread;
|
||||
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
||||
import electrosphere.engine.profiler.Profiler;
|
||||
import electrosphere.net.NetUtils;
|
||||
|
||||
public class EngineInit {
|
||||
|
||||
//The maximum number of frames to wait before failing the startup routine
|
||||
public static final int MAX_FRAMES_TO_WAIT = 100;
|
||||
|
||||
/**
|
||||
* Initializes the engine
|
||||
*/
|
||||
public static void initHeadlessEngine(){
|
||||
Globals.RUN_CLIENT = true;
|
||||
Globals.RUN_SERVER = true;
|
||||
Globals.RUN_AUDIO = false;
|
||||
Globals.HEADLESS = true;
|
||||
Profiler.PROFILE = false;
|
||||
NetUtils.setPort(0);
|
||||
Main.startUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the engine
|
||||
*/
|
||||
public static void initGraphicalEngine(){
|
||||
Globals.RUN_CLIENT = true;
|
||||
Globals.RUN_SERVER = true;
|
||||
Globals.RUN_AUDIO = false;
|
||||
Globals.HEADLESS = false;
|
||||
Profiler.PROFILE = false;
|
||||
NetUtils.setPort(0);
|
||||
Main.startUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups up a locally-connected client and server that have loaded a test scene
|
||||
*/
|
||||
|
||||
@ -6,41 +6,13 @@ import java.util.function.Supplier;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.engine.profiler.Profiler;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.net.NetUtils;
|
||||
|
||||
/**
|
||||
* Utils for testing the engine
|
||||
*/
|
||||
public class TestEngineUtils {
|
||||
|
||||
/**
|
||||
* Initializes the engine
|
||||
*/
|
||||
public static void initHeadlessEngine(){
|
||||
Globals.RUN_CLIENT = true;
|
||||
Globals.RUN_SERVER = true;
|
||||
Globals.RUN_AUDIO = false;
|
||||
Globals.HEADLESS = true;
|
||||
Profiler.PROFILE = false;
|
||||
NetUtils.setPort(0);
|
||||
Main.startUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the engine
|
||||
*/
|
||||
public static void initGraphicalEngine(){
|
||||
Globals.RUN_CLIENT = true;
|
||||
Globals.RUN_SERVER = true;
|
||||
Globals.RUN_AUDIO = false;
|
||||
Globals.HEADLESS = false;
|
||||
Profiler.PROFILE = false;
|
||||
NetUtils.setPort(0);
|
||||
Main.startUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a logging message
|
||||
* @param log the message to print
|
||||
|
||||
Loading…
Reference in New Issue
Block a user