CUGL 2.0
Cornell University Game Library
Public Member Functions | List of all members
cugl::Asset Class Reference

#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 ()
 

Detailed Description

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.

Member Function Documentation

◆ init() [1/2]

virtual bool cugl::Asset::init ( const std::shared_ptr< JsonValue > &  json)
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.

Parameters
jsonThe directory entry for this asset
Returns
true if the asset was loaded successfully

◆ init() [2/2]

virtual bool cugl::Asset::init ( const std::string &  file)
inlinevirtual

Initializes this asset from the given file.

The initializer will load the asset synchronously, first calling preload and then calling materialize.

Parameters
fileThe path to the asset to load.
Returns
true if the asset was loaded successfully

◆ materialize()

virtual bool cugl::Asset::materialize ( )
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.

Returns
true if the asset was loaded successfully

◆ preload() [1/2]

virtual bool cugl::Asset::preload ( const std::shared_ptr< JsonValue > &  json)
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.

Returns
true if the asset was preloaded successfully

◆ preload() [2/2]

virtual bool cugl::Asset::preload ( const std::string &  file)
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.

Returns
true if the asset was preloaded successfully

The documentation for this class was generated from the following file: