Table of Contents

Namespace OmegaEngine.Assets

Assets are content files loaded by the engine at runtime. This includes textures, models, sounds, etc..

Loading assets

Many asset types provide static Get() methods for easy loading from the content directories:

// Load a 3D model
var model = XMesh.Get(engine, "Character.x");

// Load a texture
var texture = XTexture.Get(engine, "Concrete.png");

The Get() method:

  1. Searches for the file in the filesystem
  2. Loads and parses the file
  3. Adds the asset to the cache
  4. Returns the asset ready for use

Cache

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. The CacheManager (accessible via the Engine.Cache property) implements this through reference counting.

When you load an asset:

  1. The cache is checked for an existing instance with that name
  2. If found, the reference count is incremented and the cached instance is returned
  3. If not found, the asset is loaded, added to the cache with reference count of 1

When you dispose an asset:

  1. The reference count is decremented
  2. If the count reaches zero, the asset remains in cache but is marked for potential cleanup
  3. 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);

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.