CUGL 2.3
Cornell University Game Library
|
#include <CUAsset.h>
Public Member Functions | |
virtual bool | init (const std::string file) |
virtual bool | init (const std::shared_ptr< JsonValue > &json) |
virtual bool | preload (const std::string file) |
virtual bool | preload (const std::shared_ptr< JsonValue > &json) |
virtual bool | materialize () |
An abstract class for a generic asset
This class is the base class for any generic asset (such as a model file or level layout) not explicitly included in the existing asset classes. It has abstract methods for loading and unloading from a file, which any subclass should implement.
To support both synchronous and asynchronous loading, the asset splits loading into two phases: preloading and materialization. Preloading is the part of asset loading that can safely take place outside of the main CUGL thread. The second phase, materialization, will take place in the main CUGL thread. Any operations that require access to an OpenGL or audio context should take place in that phase.
This class SHOULD NOT make any references to AssetManager
in the load/unload methods. Assets should be treated as if they load in parallel, not in sequence. Therefore, it is unsafe to assume that one asset loads before another. If this asset needs to connect to other assets (sound, images, etc.) this should take place after asset loading, such as during scene graph initialization or the like.
|
inlinevirtual |
Initializes this asset defined by the given directory entry.
This version of initialization provides support for JSON directories. The exact format of the directory entry is up to you. However, the directory entry must be loaded manually via GenericLoader
, as AssetManager
does not yet support generic JSON directory entries.
The initializer will load the asset synchronously, first calling preload
and then calling materialize
.
json | The directory entry for this asset |
|
inlinevirtual |
Initializes this asset from the given file.
The initializer will load the asset synchronously, first calling preload
and then calling materialize
.
file | The path to the asset to load. |
|
inlinevirtual |
Finishes loading within the main CUGL thread.
This method is the final step to asset loading. It is the part of asset loading that is not safe to be done asynchronously. If the asset needs access to OpenGL or the audio engine to complete loading, that should be done here.
|
inlinevirtual |
Loads the portion of this asset that is safe to load outside the main thread.
This method is abstract. All subclasses should provide an implementation of this method. This method is necessary for an asset to be used with an instance of GenericLoader
.
This version of preloading provides support for JSON directories. The exact format of the directory entry is up to you. However, the directory entry must be loaded manually via GenericLoader
, as AssetManager
does not yet support generic JSON directory entries.
This method is similar to TextureLoader#preload
. It safely loads the portion of the asset that can be loaded outside of the main CUGL thread. That means, if the asset needs access to OpenGL or the audio engine as part of its loading, that should not take place in this method.
This class SHOULD NOT make any references to AssetManager
in the load/unload methods. Assets should be treated as if they load in parallel, not in sequence. Therefore, it is unsafe to assume that one asset loads before another. If this asset needs to connect to other assets (sound, images, etc.) this should take place after asset loading, such as during scene graph initialization or the like.
|
inlinevirtual |
Loads the portion of this asset that is safe to load outside the main thread.
This method is abstract. All subclasses should provide an implementation of this method. This method is necessary for an asset to be used with an instance of GenericLoader
.
This method is similar to TextureLoader#preload
. It safely loads the portion of the asset that can be loaded outside of the main CUGL thread. That means, if the asset needs access to OpenGL or the audio engine as part of its loading, that should not take place in this method.
This class SHOULD NOT make any references to AssetManager
in the load/unload methods. Assets should be treated as if they load in parallel, not in sequence. Therefore, it is unsafe to assume that one asset loads before another. If this asset needs to connect to other assets (sound, images, etc.) this should take place after asset loading, such as during scene graph initialization or the like.