|
Drag[en]gine Script Module DragonScript 1.35
|
Load game worlds using a loading screen. More...
Public Member Functions | |
| void | cancelLoading () |
| Cancel loading. | |
| void | dispose () |
| Dispose of game world loader to break reference loops. | |
| Console | getConsole () |
| Console console. | |
| DebugVerifyStubProperties | getDebugVerifyStubProperties () |
| Debug verify stub properties while loading or null if not used. | |
| DecalBuilder | getDecalBuilder () |
| Decal builder used for world decals. | |
| ElementClassList | getElementClassList () |
| Element classes list. | |
| bool | getEnableNetworking () |
| Enable networking. | |
| MutableID | getIDGenerator () |
| ID Generator or null. | |
| bool | getIgnorePersistableElements () |
| Ignore persistable elements. | |
| Loaders | getLoaders () |
| Loaders. | |
| String | getPathWorld () |
| World file path. | |
| PersistencyEnvironment | getPersistencyEnvironment () |
| Persistency environment or null. | |
| FileReader | getPersistencyReader () |
| Persistency reader or null. | |
| PreloadManager | getPreloadManager () |
| Preload manager. | |
| StubGameWorld | getStubWorld () |
| Game world stub. | |
| WindowLoading | getWindowLoading () |
| Loading window window. | |
| GameWorldLoader | new () |
| Create game world loader using BaseGameApp parameters. | |
| GameWorldLoader | new (Console console, Loaders loaders, ElementClassList elementClassList) |
| Create game world loader. | |
| GameWorldLoader | new (Console console, Loaders loaders, ElementClassList elementClassList, MutableID idGenerator) |
| Create game world loader. | |
| void | onLoadWorldFailed () |
| Loading world failed. | |
| void | onLoadWorldFinished () |
| Loading world finished. | |
| void | setDebugVerifyStubProperties (DebugVerifyStubProperties debug) |
| Set debug verify stub properties while loading or null if not used. | |
| void | setDecalBuilder (DecalBuilder decalBuilder) |
| Set decal builder used for world decals. | |
| void | setEnableNetworking (bool enable) |
| Set if networking is enabled. | |
| void | setIgnorePersistableElements (bool ignorePersistableElements) |
| Set if persistable elements are ignored. | |
| void | setPathWorld (String path) |
| Set world file path. | |
| void | setPersistency (PersistencyEnvironment environment, FileReader reader) |
| Set persistency environment and reader. | |
| void | setWindowLoading (WindowLoading window) |
| Set loading window. | |
| void | startLoading () |
| Start loading game world. | |
| void | updateLoading () |
| Update loading. | |
Protected Member Functions | |
| void | cleanUp () |
| Cleaning up. | |
| void | createContentFromStub () |
| Create world content from stubs. | |
| GameWorld | createGameWorld () |
| Create GameWorld instance. | |
| void | createLoadingWindow () |
| Create loading window. | |
| bool | getCleanUpStubWorld () |
| Clean up world stub. | |
| void | loadWorld () |
| Load world. | |
| void | persistencyCreateContentFromStub () |
| Create world content from stubs using persistency. | |
| void | persistencyReadWorld () |
| Read world from persistency reader. | |
| void | preloadResources () |
| Preload resources. | |
| bool | reportPreloadProblems () |
| Log preloading problems. | |
| void | setCleanUpStubWorld (bool cleanUpStubWorld) |
| Set clean up world stub. | |
| void | setStubWorld (StubGameWorld stub) |
| Set game world stub. | |
| void | startFrameUpdater () |
| Start frame updater if not started. | |
| void | stopFrameUpdater () |
| Stop frame updater if running. | |
| void | worldStoreNextIDAndRemapEntry () |
| Set world next object ID and add ID Remapper entry if required. | |
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().
References pIgnorePersistableElements, and setIgnorePersistableElements().
Referenced by onLoadWorldFailed().
|
protected |
Cleaning up.
Reimplemented in Dragengine.Gui.WindowGameWorld.Loader.
References getPathWorld(), and pStubWorld.
Referenced by onLoadWorldFailed(), and persistencyCreateContentFromStub().
|
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.
References createLoadingWindow(), loadWorld(), pCleanUpStubWorld, preloadResources(), pStubWorld, pWindowLoading, and startFrameUpdater().
Referenced by onLoadWorldFailed(), and onLoadWorldFinished().
|
protected |
Create GameWorld instance.
Default implementation creates instance of GameWorld. Overwrite in subclass to create instance of your own class if used.
Reimplemented in Dragengine.GABehaviorStateMachine.SMAWindowLogoUpdate.SMGameWorldLoader.
References new(), pPathWorld, pStubWorld, and startLoading().
Referenced by onLoadWorldFailed().
|
protected |
Create loading window.
Reimplemented in Dragengine.GABehaviorStateMachine.SMAWindowLogoUpdate.SMGameWorldLoader.
Referenced by createContentFromStub(), and onLoadWorldFailed().
| void Dragengine.Utils.GameWorldLoader.dispose | ( | ) |
Dispose of game world loader to break reference loops.
Reimplemented in Dragengine.GABehaviorStateMachine.SMAWindowLogoUpdate.SMGameWorldLoader, and Dragengine.Gui.WindowGameWorld.Loader.
Referenced by getIgnorePersistableElements(), onLoadWorldFailed(), setIgnorePersistableElements(), and setPersistency().
|
protected |
Clean up world stub.
Referenced by onLoadWorldFailed().
| Console Dragengine.Utils.GameWorldLoader.getConsole | ( | ) |
| DebugVerifyStubProperties Dragengine.Utils.GameWorldLoader.getDebugVerifyStubProperties | ( | ) |
Debug verify stub properties while loading or null if not used.
References getWindowLoading().
Referenced by onLoadWorldFailed(), and preloadResources().
| DecalBuilder Dragengine.Utils.GameWorldLoader.getDecalBuilder | ( | ) |
Decal builder used for world decals.
References new(), pConsole, pElementClassList, and pLoaders.
Referenced by getPersistencyEnvironment().
| ElementClassList Dragengine.Utils.GameWorldLoader.getElementClassList | ( | ) |
| bool Dragengine.Utils.GameWorldLoader.getEnableNetworking | ( | ) |
| MutableID Dragengine.Utils.GameWorldLoader.getIDGenerator | ( | ) |
ID Generator or null.
References getElementClassList(), and pElementClassList.
Referenced by loadWorld().
| bool Dragengine.Utils.GameWorldLoader.getIgnorePersistableElements | ( | ) |
Ignore persistable elements.
References dispose(), setWindowLoading(), and stopFrameUpdater().
Referenced by updateLoading().
| Loaders Dragengine.Utils.GameWorldLoader.getLoaders | ( | ) |
| String Dragengine.Utils.GameWorldLoader.getPathWorld | ( | ) |
| PersistencyEnvironment Dragengine.Utils.GameWorldLoader.getPersistencyEnvironment | ( | ) |
Persistency environment or null.
References getDecalBuilder(), and pDecalBuilder.
Referenced by loadWorld().
| FileReader Dragengine.Utils.GameWorldLoader.getPersistencyReader | ( | ) |
Persistency reader or null.
References pDecalBuilder, and setDecalBuilder().
Referenced by loadWorld().
| PreloadManager Dragengine.Utils.GameWorldLoader.getPreloadManager | ( | ) |
Preload manager.
Referenced by updateLoading().
| StubGameWorld Dragengine.Utils.GameWorldLoader.getStubWorld | ( | ) |
Game world stub.
Referenced by setCleanUpStubWorld().
| WindowLoading Dragengine.Utils.GameWorldLoader.getWindowLoading | ( | ) |
Loading window window.
References pEnableNetworking, and pIgnorePersistableElements.
Referenced by getDebugVerifyStubProperties().
|
protected |
Load world.
References getIDGenerator(), getPersistencyEnvironment(), getPersistencyReader(), pIDGenerator, pPersistencyReader, and pPersistEnvironment.
Referenced by createContentFromStub(), and onLoadWorldFailed().
| GameWorldLoader Dragengine.Utils.GameWorldLoader.new | ( | ) |
Create game world loader using BaseGameApp parameters.
Creates a DecalBuilder and an AddDecalVisitor.
Reimplemented in Dragengine.GABehaviorStateMachine.SMAWindowLogoUpdate.SMGameWorldLoader.
References new().
Referenced by createGameWorld(), getConsole(), getDecalBuilder(), getElementClassList(), getLoaders(), new(), new(), onLoadWorldFailed(), onLoadWorldFinished(), persistencyReadWorld(), setDecalBuilder(), and setWindowLoading().
| 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 ) |
Create game world loader.
Creates a DecalBuilder and an AddDecalVisitor.
References new().
| 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.GABehaviorStateMachine.SMAWindowLogoUpdate.SMGameWorldLoader, and Dragengine.Gui.WindowGameWorld.Loader.
References cancelLoading(), cleanUp(), createContentFromStub(), createGameWorld(), createLoadingWindow(), dispose(), getCleanUpStubWorld(), getDebugVerifyStubProperties(), loadWorld(), Dragengine.Scenery.logPreloadProblems(), new(), onLoadWorldFailed(), onLoadWorldFinished(), pCleanUpStubWorld, pConsole, pDebugVerifyStubProperties, pElementClassList, persistencyCreateContentFromStub(), persistencyReadWorld(), pFrameUpdater, pIDGenerator, pLoaders, pPersistencyReader, pPersistEnvironment, pPreloadManager, preloadResources(), pStubWorld, reportPreloadProblems(), setCleanUpStubWorld(), setStubWorld(), setWindowLoading(), startFrameUpdater(), stopFrameUpdater(), and worldStoreNextIDAndRemapEntry().
Referenced by onLoadWorldFailed().
| 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.
References createContentFromStub(), new(), pCleanUpStubWorld, pPreloadManager, pStubWorld, and reportPreloadProblems().
Referenced by onLoadWorldFailed().
|
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. |
References cleanUp(), pConsole, and updateLoading().
Referenced by onLoadWorldFailed().
|
protected |
Read world from persistency reader.
Does nothing if persistency environment, reader or ID Generator is null.
Called by loadWorld().
References new(), pPersistencyReader, and pPersistEnvironment.
Referenced by onLoadWorldFailed().
|
protected |
Preload resources.
Preloads resources from all elements classes.
References getDebugVerifyStubProperties(), and pDebugVerifyStubProperties.
Referenced by createContentFromStub(), and onLoadWorldFailed().
|
protected |
Log preloading problems.
References pDebugVerifyStubProperties, and setDebugVerifyStubProperties().
Referenced by onLoadWorldFailed(), and onLoadWorldFinished().
|
protected |
Set clean up world stub.
References getStubWorld(), pEnableNetworking, and setEnableNetworking().
Referenced by onLoadWorldFailed().
| void Dragengine.Utils.GameWorldLoader.setDebugVerifyStubProperties | ( | DebugVerifyStubProperties | debug | ) |
Set debug verify stub properties while loading or null if not used.
References pWindowLoading, and setWindowLoading().
Referenced by reportPreloadProblems().
| void Dragengine.Utils.GameWorldLoader.setDecalBuilder | ( | DecalBuilder | decalBuilder | ) |
Set decal builder used for world decals.
The old decal builder is disposed of if present.
References new(), pDecalBuilder, and pIDGenerator.
Referenced by getPersistencyReader().
| void Dragengine.Utils.GameWorldLoader.setEnableNetworking | ( | bool | enable | ) |
Set if networking is enabled.
References pDebugVerifyStubProperties, and pPreloadManager.
Referenced by setCleanUpStubWorld().
| void Dragengine.Utils.GameWorldLoader.setIgnorePersistableElements | ( | bool | ignorePersistableElements | ) |
Set if persistable elements are ignored.
References dispose(), and pDecalBuilder.
Referenced by cancelLoading().
| void Dragengine.Utils.GameWorldLoader.setPathWorld | ( | String | 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. |
References dispose(), and pDecalBuilder.
Referenced by worldStoreNextIDAndRemapEntry().
|
protected |
Set game world stub.
References getEnableNetworking(), and pEnableNetworking.
Referenced by onLoadWorldFailed().
| void Dragengine.Utils.GameWorldLoader.setWindowLoading | ( | WindowLoading | window | ) |
Set loading window.
References new(), pCleanUpStubWorld, and pPreloadManager.
Referenced by getIgnorePersistableElements(), onLoadWorldFailed(), and setDebugVerifyStubProperties().
|
protected |
Start frame updater if not started.
References pPathWorld.
Referenced by createContentFromStub(), and onLoadWorldFailed().
| void Dragengine.Utils.GameWorldLoader.startLoading | ( | ) |
Start loading game world.
Set up all required parameters before calling this method, in particular setPathWorld().
References pWindowLoading.
Referenced by createGameWorld().
|
protected |
Stop frame updater if running.
References pPathWorld, and setPathWorld().
Referenced by getIgnorePersistableElements(), and onLoadWorldFailed().
| void Dragengine.Utils.GameWorldLoader.updateLoading | ( | ) |
Update loading.
For use by FrameUpdater.
References getIgnorePersistableElements(), getPreloadManager(), pIgnorePersistableElements, and pPreloadManager.
Referenced by persistencyCreateContentFromStub().
|
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().
References setPersistency().
Referenced by onLoadWorldFailed().
| bool Dragengine.Utils.GameWorldLoader.pCleanUpStubWorld |
Referenced by createContentFromStub(), onLoadWorldFailed(), onLoadWorldFinished(), and setWindowLoading().
| Console Dragengine.Utils.GameWorldLoader.pConsole |
Referenced by getDecalBuilder(), getPathWorld(), onLoadWorldFailed(), and persistencyCreateContentFromStub().
| DebugVerifyStubProperties Dragengine.Utils.GameWorldLoader.pDebugVerifyStubProperties |
Referenced by onLoadWorldFailed(), preloadResources(), reportPreloadProblems(), and setEnableNetworking().
| DecalBuilder Dragengine.Utils.GameWorldLoader.pDecalBuilder |
| ElementClassList Dragengine.Utils.GameWorldLoader.pElementClassList |
Referenced by getDecalBuilder(), getIDGenerator(), and onLoadWorldFailed().
| bool Dragengine.Utils.GameWorldLoader.pEnableNetworking |
Referenced by getWindowLoading(), setCleanUpStubWorld(), and setStubWorld().
| FrameUpdater Dragengine.Utils.GameWorldLoader.pFrameUpdater |
Referenced by onLoadWorldFailed().
| MutableID Dragengine.Utils.GameWorldLoader.pIDGenerator |
Referenced by loadWorld(), onLoadWorldFailed(), and setDecalBuilder().
| bool Dragengine.Utils.GameWorldLoader.pIgnorePersistableElements |
Referenced by cancelLoading(), getWindowLoading(), and updateLoading().
| Loaders Dragengine.Utils.GameWorldLoader.pLoaders |
Referenced by getDecalBuilder(), onLoadWorldFailed(), and setPathWorld().
| String Dragengine.Utils.GameWorldLoader.pPathWorld |
Referenced by createGameWorld(), startFrameUpdater(), and stopFrameUpdater().
| FileReader Dragengine.Utils.GameWorldLoader.pPersistencyReader |
Referenced by loadWorld(), onLoadWorldFailed(), and persistencyReadWorld().
| PersistencyEnvironment Dragengine.Utils.GameWorldLoader.pPersistEnvironment |
Referenced by loadWorld(), onLoadWorldFailed(), and persistencyReadWorld().
| PreloadManager Dragengine.Utils.GameWorldLoader.pPreloadManager |
Referenced by onLoadWorldFailed(), onLoadWorldFinished(), setEnableNetworking(), setWindowLoading(), and updateLoading().
| StubGameWorld Dragengine.Utils.GameWorldLoader.pStubWorld |
Referenced by cleanUp(), createContentFromStub(), createGameWorld(), onLoadWorldFailed(), and onLoadWorldFinished().
| WindowLoading Dragengine.Utils.GameWorldLoader.pWindowLoading |
Referenced by createContentFromStub(), setDebugVerifyStubProperties(), and startLoading().