forked from StarOpenSource/Engine
Encapsulate Main#run logic in try-catch block
This commit is contained in:
parent
b277587ec8
commit
bca45488d1
2 changed files with 50 additions and 43 deletions
|
@ -1,23 +1,25 @@
|
||||||
/*
|
/*
|
||||||
STAROPENSOURCE ENGINE SOURCE FILE
|
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||||
Copyright (c) 2024 The StarOpenSource Engine Contributors
|
* Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||||
Licensed under the GNU Affero General Public License v3
|
* Licensed under the GNU Affero General Public License v3
|
||||||
|
*
|
||||||
This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
published by the Free Software Foundation, either version 3 of the
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Affero General Public License for more details.
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the code required for drawing things to a screen.
|
* Contains the code required for drawing things to a screen.
|
||||||
|
*
|
||||||
|
* @since v1-alpha0
|
||||||
*/
|
*/
|
||||||
package de.staropensource.sosengine.graphics;
|
package de.staropensource.sosengine.graphics;
|
||||||
|
|
|
@ -96,35 +96,40 @@ public class Main {
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void run(String[] args) {
|
public void run(String[] args) {
|
||||||
// Initialize sos!engine
|
|
||||||
engine = new Engine();
|
|
||||||
|
|
||||||
// Say hello to the world!
|
|
||||||
logger.info("Hello world!");
|
|
||||||
|
|
||||||
// Choose Graphics API to use
|
|
||||||
if (!GraphicsSubsystem.getInstance().setGraphicsApi())
|
|
||||||
logger.crash("No Graphics API is compatible");
|
|
||||||
|
|
||||||
// Define 'api' & 'management' variables
|
|
||||||
ApiMainClass api = GraphicsSubsystem.getInstance().getApi();
|
|
||||||
ApiManagementClass management = api.getManagement();
|
|
||||||
|
|
||||||
// Create window
|
|
||||||
try {
|
try {
|
||||||
Window window = new Window.Builder()
|
// Initialize sos!engine
|
||||||
.setTitle("test application window")
|
engine = new Engine();
|
||||||
.setSize(new Vec2i(960, 540))
|
|
||||||
.setPosition(new Vec2i(10, 10))
|
// Say hello to the world!
|
||||||
.build();
|
logger.info("Hello world!");
|
||||||
|
|
||||||
|
// Choose Graphics API to use
|
||||||
|
if (!GraphicsSubsystem.getInstance().setGraphicsApi())
|
||||||
|
logger.crash("No Graphics API is compatible");
|
||||||
|
|
||||||
|
// Define 'api' & 'management' variables
|
||||||
|
ApiMainClass api = GraphicsSubsystem.getInstance().getApi();
|
||||||
|
ApiManagementClass management = api.getManagement();
|
||||||
|
|
||||||
|
// Create window
|
||||||
|
try {
|
||||||
|
Window window = new Window.Builder()
|
||||||
|
.setTitle("test application window")
|
||||||
|
.setSize(new Vec2i(960, 540))
|
||||||
|
.setPosition(new Vec2i(10, 10))
|
||||||
|
.build();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
logger.crash("Window.Builder#build() failed", throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sleep for five seconds
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
// Shutdown
|
||||||
|
Engine.getInstance().shutdown(0);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
logger.crash("Window.Builder#build() failed", throwable);
|
Thread.ofVirtual().start(() -> Engine.getInstance().shutdown(69));
|
||||||
|
throw throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep for five seconds
|
|
||||||
Thread.sleep(5000);
|
|
||||||
|
|
||||||
// Shutdown
|
|
||||||
Engine.getInstance().shutdown(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue