Startup unit test
This commit is contained in:
parent
69b8f86647
commit
bbb2325e86
10
pom.xml
10
pom.xml
@ -181,7 +181,7 @@
|
|||||||
</os>
|
</os>
|
||||||
</activation>
|
</activation>
|
||||||
<properties>
|
<properties>
|
||||||
<!-- <maven.compiler.target>17</maven.compiler.target> -->
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
<lwjgl.natives>natives-macos</lwjgl.natives>
|
<lwjgl.natives>natives-macos</lwjgl.natives>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
@ -259,6 +259,14 @@
|
|||||||
<!-- <classesDirectory>${project.basedir}/target/classes</classesDirectory> -->
|
<!-- <classesDirectory>${project.basedir}/target/classes</classesDirectory> -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.12.4</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>-XstartOnFirstThread</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@ -1,33 +0,0 @@
|
|||||||
import electrosphere.controls.ControlHandler;
|
|
||||||
import electrosphere.game.config.UserSettings;
|
|
||||||
import electrosphere.logger.LoggerInterface;
|
|
||||||
import electrosphere.main.Globals;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class LoadingTest extends TestCase {
|
|
||||||
// @BeforeClass
|
|
||||||
|
|
||||||
public void testABC(){
|
|
||||||
//initialize logging interfaces
|
|
||||||
LoggerInterface.initLoggers();
|
|
||||||
|
|
||||||
//load user settings
|
|
||||||
UserSettings.loadUserSettings();
|
|
||||||
|
|
||||||
//controls
|
|
||||||
if(Globals.RUN_CLIENT){
|
|
||||||
initControlHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
//init global variables
|
|
||||||
Globals.initGlobals();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initControlHandler(){
|
|
||||||
LoggerInterface.loggerStartup.INFO("Initialize control handler");
|
|
||||||
Globals.controlHandler = ControlHandler.generateExampleControlsMap();
|
|
||||||
Globals.controlHandler.setCallbacks();
|
|
||||||
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
22
src/test/java/StartupTest.java
Normal file
22
src/test/java/StartupTest.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import junit.framework.TestCase;
|
||||||
|
import testingutils.MainLoop;
|
||||||
|
|
||||||
|
public class StartupTest extends TestCase {
|
||||||
|
|
||||||
|
public void testStartupHeadless(){
|
||||||
|
System.out.println("[Test] Startup Headless");
|
||||||
|
MainLoop.startup(true);
|
||||||
|
MainLoop.timedMainLoop(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStartupGUI(){
|
||||||
|
System.out.println("[Test] Startup GUI");
|
||||||
|
MainLoop.startup(false);
|
||||||
|
MainLoop.timedMainLoop(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmpty() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ import org.junit.runner.notification.Failure;
|
|||||||
|
|
||||||
public class TestRunner {
|
public class TestRunner {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
Result result = JUnitCore.runClasses(LoadingTest.class);
|
Result result = JUnitCore.runClasses(StartupTest.class);
|
||||||
for(Failure failure : result.getFailures()){
|
for(Failure failure : result.getFailures()){
|
||||||
System.out.println(failure);
|
System.out.println(failure);
|
||||||
}
|
}
|
||||||
|
|||||||
237
src/test/java/testingutils/MainLoop.java
Normal file
237
src/test/java/testingutils/MainLoop.java
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
package testingutils;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.glfwGetTime;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import electrosphere.audio.AudioEngine;
|
||||||
|
import electrosphere.controls.ControlHandler;
|
||||||
|
import electrosphere.engine.LoadingThread;
|
||||||
|
import electrosphere.engine.cli.CLIParser;
|
||||||
|
import electrosphere.game.client.ClientFunctions;
|
||||||
|
import electrosphere.game.config.UserSettings;
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import electrosphere.renderer.RenderingEngine;
|
||||||
|
|
||||||
|
public class MainLoop {
|
||||||
|
|
||||||
|
//
|
||||||
|
//Visualization Controls
|
||||||
|
//
|
||||||
|
//These are used in calculating the time between frames for visualization (camera) control and such
|
||||||
|
static double deltaTime = 0.0f;
|
||||||
|
static double lastFrame = 0.0f;
|
||||||
|
static long frameCount = 0;
|
||||||
|
public static float deltaFrames = 0;
|
||||||
|
|
||||||
|
//target amount of time per frame
|
||||||
|
public static float targetFrameRate = 60.0f;
|
||||||
|
static float targetFramePeriod = 1.0f/targetFrameRate;
|
||||||
|
|
||||||
|
//framestep variable
|
||||||
|
static int framestep = 2;
|
||||||
|
|
||||||
|
|
||||||
|
public static void startup(boolean headless){
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// I N I T I A L I Z A T I O N
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
//parse command line arguments
|
||||||
|
String[] args = new String[]{
|
||||||
|
"Renderer"
|
||||||
|
};
|
||||||
|
CLIParser.parseCLIArgs(args);
|
||||||
|
|
||||||
|
//initialize logging interfaces
|
||||||
|
LoggerInterface.initLoggers();
|
||||||
|
|
||||||
|
//load user settings
|
||||||
|
UserSettings.loadUserSettings();
|
||||||
|
|
||||||
|
//controls
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
initControlHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
//init global variables
|
||||||
|
Globals.initGlobals();
|
||||||
|
|
||||||
|
//create the drawing context
|
||||||
|
if(Globals.RUN_CLIENT && !headless){
|
||||||
|
Globals.renderingEngine = new RenderingEngine();
|
||||||
|
Globals.renderingEngine.createOpenglContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the audio context
|
||||||
|
if(Globals.RUN_CLIENT && !headless){
|
||||||
|
Globals.audioEngine = new AudioEngine();
|
||||||
|
Globals.audioEngine.init();
|
||||||
|
// Globals.audioEngine.setGain(0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
//init default resources
|
||||||
|
if(Globals.RUN_CLIENT && !headless){
|
||||||
|
Globals.initDefaultGraphicalResources();
|
||||||
|
Globals.initDefaultAudioResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
//fire off a loading thread for the title menus/screen
|
||||||
|
LoggerInterface.loggerStartup.INFO("Fire off loading thread");
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_TITLE_MENU);
|
||||||
|
Globals.loadingThreadsList.add(serverThread);
|
||||||
|
serverThread.start();
|
||||||
|
} else {
|
||||||
|
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
||||||
|
Globals.loadingThreadsList.add(clientThread);
|
||||||
|
clientThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
//recapture the screen for rendering
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
LoggerInterface.loggerStartup.INFO("Recapture screen");
|
||||||
|
Globals.controlHandler.setShouldRecapture(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initControlHandler(){
|
||||||
|
LoggerInterface.loggerStartup.INFO("Initialize control handler");
|
||||||
|
Globals.controlHandler = ControlHandler.generateExampleControlsMap();
|
||||||
|
Globals.controlHandler.setCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void run(MainLoop.MainLoopHaltingCallback haltingCallback){
|
||||||
|
|
||||||
|
|
||||||
|
//main loop
|
||||||
|
while (haltingCallback.shouldRun()) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Frame calculation
|
||||||
|
*/
|
||||||
|
double currentTime = glfwGetTime();
|
||||||
|
deltaTime = currentTime - lastFrame;
|
||||||
|
deltaFrames = targetFrameRate * (float)deltaTime;
|
||||||
|
lastFrame = currentTime;
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// A S S E T M A N A G E R S T U F F
|
||||||
|
///
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
Globals.assetManager.loadAssetsInQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// C L I E N T N E T W O R K I N G S T U F F
|
||||||
|
///
|
||||||
|
//Why is this its own function? Just to get the networking code out of main()
|
||||||
|
if(Globals.RUN_CLIENT && Globals.clientConnection != null){
|
||||||
|
Globals.clientConnection.parseMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//handle framestep
|
||||||
|
if(framestep == 1){
|
||||||
|
framestep = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// I N P U T C O N T R O L S
|
||||||
|
///
|
||||||
|
//Poll controls
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
Globals.controlHandler.pollControls();
|
||||||
|
Globals.controlHandler.recaptureIfNecessary();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// C L I E N T S I M U L A T I O N S T U F F
|
||||||
|
///
|
||||||
|
if(Globals.RUN_CLIENT && framestep > 0){
|
||||||
|
ClientFunctions.runBeforeSimulationFunctions();
|
||||||
|
}
|
||||||
|
if(Globals.microSimulation != null && Globals.microSimulation.isReady() && framestep > 0){
|
||||||
|
Globals.microSimulation.simulate();
|
||||||
|
}
|
||||||
|
if(Globals.RUN_CLIENT && framestep > 0){
|
||||||
|
ClientFunctions.runClientFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// M A C R O S I M U L A T I O N S T U F F
|
||||||
|
///
|
||||||
|
if(Globals.macroSimulation != null && Globals.macroSimulation.isReady() && framestep > 0){
|
||||||
|
Globals.macroSimulation.simulate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(Globals.RUN_CLIENT){
|
||||||
|
Globals.renderingEngine.drawScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(deltaTime < targetFramePeriod){
|
||||||
|
sleep((int)(1000.0 * (targetFramePeriod - deltaTime)));
|
||||||
|
} else {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
frameCount++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sleep(int i) {
|
||||||
|
try {
|
||||||
|
TimeUnit.MILLISECONDS.sleep(i);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
System.out.println("Sleep somehow interrupted?!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean shouldRun = true;
|
||||||
|
|
||||||
|
public static void timedMainLoop(int seconds){
|
||||||
|
|
||||||
|
Thread stopMainLoopThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(3);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
shouldRun = false;
|
||||||
|
}});
|
||||||
|
stopMainLoopThread.start();
|
||||||
|
|
||||||
|
Globals.RUN_CLIENT = false;
|
||||||
|
|
||||||
|
MainLoopHaltingCallback haltingCallback = new MainLoop.MainLoopHaltingCallback() {
|
||||||
|
@Override
|
||||||
|
public boolean shouldRun() {
|
||||||
|
return shouldRun;
|
||||||
|
}};
|
||||||
|
|
||||||
|
MainLoop.run(haltingCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class MainLoopHaltingCallback {
|
||||||
|
|
||||||
|
public abstract boolean shouldRun();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user