-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Engine Initialisation and Lifecycle improvement #1770
Comments
Firstly the GameEngine needs some cleanup. It has a number of odd methods that it really shouldn't in it. Additionally, there is an obvious need for monitoring the status of engine from outside (currently the Terasology engine has a hardcoded linkage to the splashscreen which is questionable. Something like this would satisfy external needs. public interface GameEngine extends AutoCloseable {
/**
* Registers a Subsystem
* @throws IllegalStateException if the engine is running or disposed
*/
void register(EngineSubsystem subsystem);
/**
* The current status of the engine (e.g. loading config, updating asset system, etc)
*/
EngineStatus getStatus();
/**
* Subscribe for notification of engine status changes.
*/
void register(EngineStatusSubscriber subscriber);
/**
* Runs the engine, which will block the thread.
* Invalid for a disposed engine
*/
void run(Set<Name> initialModules);
/**
* Request the engine to stop running
*/
void shutdown();
/**
* Cleans up the engine. Can only be called after shutdown.
* This method should not throw exceptions.
*/
void close();
/**
* @return Whether the engine is running
*/
boolean isRunning();
/**
* @return Whether the engine is shutting down
*/
boolean isShuttingDown();
/**
* @return Whether the engine has been disposed
*/
boolean isDisposed();
} Internally I think the only methods needed are to trigger environment switch, and to access the current context: Context getCurrentContext();
void switchEnvironment(Set<Name> modules); Loading games, hosting/joining games, starting solo games and loading the menu would all sit above this. |
Some number issues, for easy replying:
|
|
|
Yes. I could rename the method to getRunningStatus() perhaps. (3) I don't know where you looking, but the definition of close() in the Autoclosable interface explicitly throws Exception. (4) Shutting down is still running. Running only is false after shutting down is complete. I think I will go with using a builder for setting subsystems and remove the register method. |
Linking this to #1797 although I assume that is just one step and doesn't complete this yet. |
Very not ready, but you can get a feel for the direction I'm heading from 90c7579 A lot of the initialization logic currently in states and their load processes would be moved into subsystems, and occur in response to well defined engine lifecycle events. This would result in logic for managing a particular aspect being self-contained, and ensure they are treated the same way in both main menu and in game. This is already solving some initialisation ordering issues which @flo highlighted (e.g. populating component libraries between environment creation and asset environment switching). The down side is that it can make the order of initialisation between subsystems unclear, especially where two subsystems need to react to the same lifecycle event and one needs to be after the other. For the moment I am seeing whether this will be an issue, and if it is considering whether additional lifecycle events would make sense and solve things. Otherwise I may add some method annotations for providing execution order, though that is a last resort. Currently there are lifecycle events for main engine initialisation, environment switching, main loop update, and shutdown. Entity system initialisation/loading and network related lifecycle events are also probable. For environment switching there is a changeModuleEnvironment() method in engine, but I'm considering having something more along the lines of createGame()/loadGame()/joinGame(), with networking and saved game options built in. The main menu would also be a game, just with a specific module. The branch is currently somewhat non-functional. I'm pretty sure you cannot actually start a game, although the menu works at least. Much work to go. |
Very cool :-) Thanks for the update. Ping: @MarcinSc @Josharias @emanuele3d @msteiger @skaldarnar |
Curiously, @immortius, is this paired with #1234 (entity system overhaul) or its own thing? Wondering if this should be a v2.0.0 item. |
This issue will deal with a restructure of the central engine initialization and lifecycle. The goal of this restructure is:
Some additional possibilities:
The text was updated successfully, but these errors were encountered: