Skip to content

Add an asset server#257

Merged
waynemwashuma merged 25 commits into
wimaengine:devfrom
waynemwashuma:asset-server
Sep 17, 2025
Merged

Add an asset server#257
waynemwashuma merged 25 commits into
wimaengine:devfrom
waynemwashuma:asset-server

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

@waynemwashuma waynemwashuma commented Sep 17, 2025

Objective

Introduces an asset management system refactor, replacing the previous asset loading approach with a centralized asset server.

Solution

The previous asset system had loading logic distributed across multiple systems and plugins. This PR consolidates all asset loading management into a centralized AssetServer that:

  • Handles asset loading, caching, and lifecycle management
  • Provides a unified API for loading assets of any type
  • Manages asset parsers and their verification
  • Tracks asset load states (Unloaded, Loading, Failed, Loaded)
  • Emits load events for success and failure scenarios

Other changes include:

  • Adding more details to success (AssetLoadSuccess) and failure (AssetLoadFail) events(now carrying typeId, assetId, and path).
  • Removing the obsolete AssetBasePath.
  • Introducing systems to flush and forward load events to the ECS event queue.
  • Added AssetServerPlugin to set up the server and its supporting systems.
  • Updated AssetPlugin and AssetParserPlugin to interact with the server.

The solution was taken to:

  • Reduce code duplication in asset loading logic
  • Provide consistent asset handling across all asset types
  • Improve error reporting and debugging capabilities
  • Enable proper asset caching and reuse
  • Simplify the API for developers using assets

Showcase

Loading assets with the new AssetServer:

// Before
import { AudioAssets } from 'wima'
const audioSources = world.getResource(AudioAssets)
const handle = audioSources.load('assets/audio/hit.mp3')

// After  
import { AssetServer, Audio } from 'wima'
const server = world.getResource(AssetServer)
const handle = server.load(Audio, 'assets/audio/hit.mp3')

MigrationGuide

Several breaking changes have been introduced:

  • All instances of Assets.load() should be replaced with AssetServer.load()
  • Asset load events are now managed through the AssetServer instead of individual asset systems
  • AssetBasePath resource has been removed, an alternative will be provided later.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 17, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 17, 2025 04:07
@waynemwashuma waynemwashuma merged commit ee7b3f6 into wimaengine:dev Sep 17, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the asset-server branch September 17, 2025 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant