Namespace OmegaEngine.Assets
Assets are content files loaded by the engine at runtime. This includes textures, models, sounds, etc..
Asset files are often referenced many times during an application's runtime. To prevent repeated load delays the engine keeps loaded and parsed content in an in-memory cache that can be flushed, e.g. after switching maps.
Cache
The CacheManager (accessible via the Engine.Cache property) automatically caches loaded assets to improve performance through reference counting.
When you load an asset:
- The cache is checked for an existing instance with that name
- If found, the reference count is incremented and the cached instance is returned
- If not found, the asset is loaded, added to the cache with reference count of 1
When you dispose an asset:
- The reference count is decremented
- If the count reaches zero, the asset remains in cache but is marked for potential cleanup
- Calling Clean() removes all assets with zero references
For scenarios like level transitions:
// Load level 1 assets
var level1Assets = LoadLevel1Assets(engine);
// ... play level 1 ...
// Dispose level 1 assets
foreach (var asset in level1Assets)
asset.Dispose();
// Clean cache to free memory before loading level 2
engine.Cache.Clean();
// Load level 2 assets
var level2Assets = LoadLevel2Assets(engine);
Filesystem
The filesystem combines multiple directory structures into a single view used to load assets.
Search order:
- Mod
- Directory specified via the
/modcommand-line argument
(only if implemented by the game) - Directories specified in the
OMEGAENGINE_CONTENT_MODenvironment variable
(only if the/modcommand-line argument was not used)
- Directory specified via the
- Base
- Directory specified in game settings
(only if implemented by the game) - Directories specified in the
OMEGAENGINE_CONTENTenvironment variable
(only if not overriden by game settings) - The
contentdirectory next to the game's executable
(only if not overriden by theOMEGAENGINE_CONTENTenvironment variable or game settings)
- Directory specified in game settings
Base directory
The base directory is usually located in the directory of the application EXE and named base. This location can be overridden in the engine configuration.
Mods
A game modification (mod) is a set of changes based on an existing game used to modify existing gameplay, add additional content or create an entirely new game.
API
Classes
- Asset
Data loaded from a file and cached for use by one or more Renderables, Sounds, etc..
- CacheManager
Keeps a cache of Assets that have been loaded and provides type-safe access to them.
- XAnimatedMesh
An animated mesh loaded from an .X file.
- XMesh
A mesh loaded from an .X file.
- XOggSound
A sound loaded from an OGG Vorbis file.
- XSound
Abstract base class for sound assets.
- XTexture
A texture loaded from one of DirectX's natively supported image formats (PNG, JPG, DDS, ...).
- XWaveSound
A sound loaded from a WAVE file.
Interfaces
- IReferenceCount
Represents an object that tracks whether it is still needed by increasing and decreasing a reference counter.