Drag[en]gine Script Module DragonScript
1.23
|
Load game worlds using a loading screen. More...
Public Member Functions | |
void | cancelLoading () |
Cancel loading. More... | |
void | dispose () |
Dispose of game world loader to break reference loops. More... | |
Console | getConsole () |
Console console. More... | |
DebugVerifyStubProperties | getDebugVerifyStubProperties () |
Debug verify stub properties while loading or null if not used. More... | |
DecalBuilder | getDecalBuilder () |
Decal builder used for world decals. More... | |
ElementClassList | getElementClassList () |
Element classes list. More... | |
bool | getEnableNetworking () |
Enable networking. More... | |
MutableID | getIDGenerator () |
ID Generator or null. More... | |
bool | getIgnorePersistableElements () |
Ignore persistable elements. More... | |
Loaders | getLoaders () |
Loaders. More... | |
String | getPathWorld () |
World file path. More... | |
PersistencyEnvironment | getPersistencyEnvironment () |
Persistency environment or null. More... | |
FileReader | getPersistencyReader () |
Persistency reader or null. More... | |
PreloadManager | getPreloadManager () |
Preload manager. More... | |
StubGameWorld | getStubWorld () |
Game world stub. More... | |
WindowLoading | getWindowLoading () |
Loading window window. More... | |
GameWorldLoader | new () |
Create game world loader using BaseGameApp parameters. More... | |
GameWorldLoader | new (Console console, Loaders loaders, ElementClassList elementClassList) |
Create game world loader. More... | |
GameWorldLoader | new (Console console, Loaders loaders, ElementClassList elementClassList, MutableID idGenerator) |
Create game world loader. More... | |
void | onLoadWorldFailed () |
Loading world failed. More... | |
void | onLoadWorldFinished () |
Loading world finished. More... | |
void | setDebugVerifyStubProperties (DebugVerifyStubProperties debug) |
Set debug verify stub properties while loading or null if not used. More... | |
void | setDecalBuilder (DecalBuilder decalBuilder) |
Set decal builder used for world decals. More... | |
void | setEnableNetworking (bool enable) |
Set if networking is enabled. More... | |
void | setIgnorePersistableElements (bool ignorePersistableElements) |
Set if persistable elements are ignored. More... | |
void | setPathWorld (String path) |
Set world file path. More... | |
void | setPersistency (PersistencyEnvironment environment, FileReader reader) |
Set persistency environment and reader. More... | |
void | setWindowLoading (WindowLoading window) |
Set loading window. More... | |
void | startLoading () |
Start loading game world. More... | |
void | updateLoading () |
Update loading. More... | |
Protected Member Functions | |
void | cleanUp () |
Cleaning up. More... | |
void | createContentFromStub () |
Create world content from stubs. More... | |
GameWorld | createGameWorld () |
Create GameWorld instance. More... | |
void | createLoadingWindow () |
Create loading window. More... | |
bool | getCleanUpStubWorld () |
Clean up world stub. More... | |
void | loadWorld () |
Load world. More... | |
void | persistencyCreateContentFromStub () |
Create world content from stubs using persistency. More... | |
void | persistencyReadWorld () |
Read world from persistency reader. More... | |
void | preloadResources () |
Preload resources. More... | |
bool | reportPreloadProblems () |
Log preloading problems. More... | |
void | setCleanUpStubWorld (bool cleanUpStubWorld) |
Set clean up world stub. More... | |
void | setStubWorld (StubGameWorld stub) |
Set game world stub. More... | |
void | startFrameUpdater () |
Start frame updater if not started. More... | |
void | stopFrameUpdater () |
Stop frame updater if running. More... | |
void | worldStoreNextIDAndRemapEntry () |
Set world next object ID and add ID Remapper entry if required. More... | |
Load game worlds using a loading screen.
Helps loading game worlds without doing all the heavy lifting yourself.
The loading process starts by calling createLoadingWindow(). The default implementation creates a WindowLoading, shows it on the BaseGameApp desktop and sets an input processor forwarding input to the the desktop. If you are not using BaseGameApp reimplement the method to fit your needs.
Then the world file is loaded using LoadWorld into a StubGameWorld. Subclasses can modify the stubs if required by overwriting loadWorld() and modifying the stub after super call.
Then all element classes from a list of element classes are preloaded. Element class properties are responsible to preload resources only once. Optionally only element classes used by element stubs can be preloaded. Depending on he game structure this can be faster. By default all element classes are loaded.
After all resources to preload have been determined the loadGameWorld() metho returns. This class updates every frame update to show preloading progress in the loading window.
Once all resources are preloaded onLoadWorldFinished() will be called. Before this method is called all preloading problems are reported using reportPreloadProblems(). Preload problems are not considered errors. Exceptions thrown during preloading are logged and preloading continues to not break preload tracking of element classes. If any exceptions have been thrown onLoadWorldFailed() will be called instead.
Afterwards onPreloadingFinished() is called the loading window will be closed. Subclass is only responsible to properly set up the game window and to take over input control.
For creating world decals a DecalBuilder is required. The class creates a DecalBuilder by default and sets the CollisionFilter to have bit 0 enabled. Subclass has to change this to fit their use case. A typical solution is to designate a bit to decals projecting so you can choose for all elements if they can receive a decal or not. The decal build requires an ElementVisitor to actually create decals. This is required since the DecalBuilder visits the world along the projection box with this visitor. The default AddDecalVisitor set visits only SimpleElement instances. Subclass can set an own AddDecalVisitor subclass to add decal creation support to other element classes.
This class is designed as single use with new instances created for each loading process. Only one GameWorldLoader should be active at once. If you need to run multiple instances in parallel you have to carefully manage the loading windows (for example use hidden ones).
Added default handling for loading world using persistency. This requires two additional parameters to be set.
The setIDGenerator(MutableID) sets the ID Generator to use. This initializes the GameWorld with the next object ID while loading and adds an ID Remapper entry to assign world objects unique IDs starting with the next free ID.
The setPersistency(PersistencyEnvironment,FileReader) sets the persistency to load from. If set loading is slightly different loading the world content and restoring persisted states. Use this to load save states.
void Dragengine.Utils.GameWorldLoader.cancelLoading | ( | ) |
Cancel loading.
Call this after loadGameWorld() returned successfully to cancel the loading. Calls onLoadWorldFailed().
|
protected |
Cleaning up.
|
protected |
Create world content from stubs.
If persistency environment and reader are not null calls persistencyCreateContentFromStub().
Otherwise calls verifyPreloading(), createAndAddElements() and createWorldDecals() on the world stub.
|
protected |
Create GameWorld instance.
Default implementation creates instance of GameWorld. Overwrite in subclass to create instance of your own class if used.
|
protected |
Create loading window.
void Dragengine.Utils.GameWorldLoader.dispose | ( | ) |
Dispose of game world loader to break reference loops.
Reimplemented in Dragengine.Gui.WindowGameWorld.Loader.
|
protected |
Clean up world stub.
DebugVerifyStubProperties Dragengine.Utils.GameWorldLoader.getDebugVerifyStubProperties | ( | ) |
Debug verify stub properties while loading or null if not used.
DecalBuilder Dragengine.Utils.GameWorldLoader.getDecalBuilder | ( | ) |
Decal builder used for world decals.
ElementClassList Dragengine.Utils.GameWorldLoader.getElementClassList | ( | ) |
Element classes list.
bool Dragengine.Utils.GameWorldLoader.getEnableNetworking | ( | ) |
Enable networking.
MutableID Dragengine.Utils.GameWorldLoader.getIDGenerator | ( | ) |
ID Generator or null.
bool Dragengine.Utils.GameWorldLoader.getIgnorePersistableElements | ( | ) |
Ignore persistable elements.
Loaders Dragengine.Utils.GameWorldLoader.getLoaders | ( | ) |
Loaders.
String Dragengine.Utils.GameWorldLoader.getPathWorld | ( | ) |
World file path.
PersistencyEnvironment Dragengine.Utils.GameWorldLoader.getPersistencyEnvironment | ( | ) |
Persistency environment or null.
FileReader Dragengine.Utils.GameWorldLoader.getPersistencyReader | ( | ) |
Persistency reader or null.
PreloadManager Dragengine.Utils.GameWorldLoader.getPreloadManager | ( | ) |
Preload manager.
StubGameWorld Dragengine.Utils.GameWorldLoader.getStubWorld | ( | ) |
Game world stub.
WindowLoading Dragengine.Utils.GameWorldLoader.getWindowLoading | ( | ) |
Loading window window.
|
protected |
Load world.
GameWorldLoader Dragengine.Utils.GameWorldLoader.new | ( | ) |
Create game world loader using BaseGameApp parameters.
Creates a DecalBuilder and an AddDecalVisitor.
GameWorldLoader Dragengine.Utils.GameWorldLoader.new | ( | Console | console, |
Loaders | loaders, | ||
ElementClassList | elementClassList | ||
) |
Create game world loader.
Creates a DecalBuilder and an AddDecalVisitor.
GameWorldLoader Dragengine.Utils.GameWorldLoader.new | ( | Console | console, |
Loaders | loaders, | ||
ElementClassList | elementClassList, | ||
MutableID | idGenerator | ||
) |
void Dragengine.Utils.GameWorldLoader.onLoadWorldFailed | ( | ) |
Loading world failed.
Game loader has been cleaned up before calling this method. It is safe to dispose() of the game loader upon entering this method.
Subclasses of BaseGameApp should call
at the end of the implementation.
Reimplemented in Dragengine.Gui.WindowGameWorld.Loader.
void Dragengine.Utils.GameWorldLoader.onLoadWorldFinished | ( | ) |
Loading world finished.
Game loader has been cleaned up before calling this method. For this reason the result of loading is provided as parameters. It is safe to dispose() of the game loader upon entering this method.
Subclasses of BaseGameApp should call
at the end of the implementation.
Reimplemented in Dragengine.Gui.WindowGameWorld.Loader.
|
protected |
Create world content from stubs using persistency.
Calls verifyPreloading(), createAndAddNonPersistableElements(), createAndAddPersistableElements(), loadAndAddPersistableElements and createWorldDecals() on the world stub.
Called by createContentFromStub() if persistency environment and reader is not null.
EInvalidAction | persistency environment or reader is null. |
|
protected |
Read world from persistency reader.
Does nothing if persistency environment, reader or ID Generator is null.
Called by loadWorld().
|
protected |
Preload resources.
Preloads resources from all elements classes.
|
protected |
Log preloading problems.
|
protected |
Set clean up world stub.
void Dragengine.Utils.GameWorldLoader.setDebugVerifyStubProperties | ( | DebugVerifyStubProperties | debug | ) |
Set debug verify stub properties while loading or null if not used.
void Dragengine.Utils.GameWorldLoader.setDecalBuilder | ( | DecalBuilder | decalBuilder | ) |
Set decal builder used for world decals.
The old decal builder is disposed of if present.
void Dragengine.Utils.GameWorldLoader.setEnableNetworking | ( | bool | enable | ) |
Set if networking is enabled.
void Dragengine.Utils.GameWorldLoader.setIgnorePersistableElements | ( | bool | ignorePersistableElements | ) |
Set if persistable elements are ignored.
void Dragengine.Utils.GameWorldLoader.setPathWorld | ( | String | path | ) |
Set world file path.
void Dragengine.Utils.GameWorldLoader.setPersistency | ( | PersistencyEnvironment | environment, |
FileReader | reader | ||
) |
Set persistency environment and reader.
Set both to non-null to enable loading game world using persisted state.
EInvalidParam | environment or reader is null but not both. |
|
protected |
Set game world stub.
void Dragengine.Utils.GameWorldLoader.setWindowLoading | ( | WindowLoading | window | ) |
Set loading window.
|
protected |
Start frame updater if not started.
void Dragengine.Utils.GameWorldLoader.startLoading | ( | ) |
Start loading game world.
Set up all required parameters before calling this method, in particular setPathWorld().
|
protected |
Stop frame updater if running.
void Dragengine.Utils.GameWorldLoader.updateLoading | ( | ) |
Update loading.
For use by FrameUpdater.
|
protected |
Set world next object ID and add ID Remapper entry if required.
Set world next object ID is always done.
The ID mapper and ID generator is only adjusted if persistency environment and reader are null. If persistency is present the read and updated during readElementStubsFromFile() call later on. Make sure ID Generator has been read from persisted state before this function is called.
Remapper entry is added if the ID generator next ID is larger than 1. The ID Generator is always incremented by the last used object ID (next object ID - 1).
If ID Generator or persistency is null only sets the next object ID.
Called by loadWorld().