Skip to content

[FEATURE] Unify embedded and direct file asset loading system #474

@Miou-zora

Description

@Miou-zora

Problem Statement

Asset loading in EngineSquared requires developers to always load files directly from disk. There is no mechanism to embed assets into the executable for production builds, nor a unified API that transparently handles both embedded and disk-based loading. Developers must change their asset-loading code depending on the deployment target.

Proposed Solution

Implement a unified asset loading system that:

  • Transparently loads assets whether they are embedded in the binary or present on the filesystem.
  • Provides a build-time switch (flag or config) to toggle between production mode (embedded assets) and development mode (direct disk access).
  • Requires no code changes when switching between modes.

Example API:

engine.loadAsset("textures/player.png"); // Loads embedded or disk asset based on mode

Alternative Solutions

  • Use a virtual filesystem library (e.g., PhysFS) to abstract asset sources — proven approach but adds a dependency.
  • Only support embedded assets via a resource-compiler step — simpler but removes the fast-iteration development mode.

Use Cases

  • Use case 1: In production, all assets are bundled into the executable for a single-file distribution.
  • Use case 2: During development, assets are read directly from disk so artists can edit them without a rebuild.

Impact

  • New asset loading API — potentially breaking if the current direct file loading API is replaced.
  • May require a resource-compiler step integrated into the xmake build.
  • Performance benefit in production (no filesystem overhead for asset lookups).

Implementation Details (optional)

  • Define an IAssetSource interface with Embedded and DiskFile implementations.
  • Add a build-time ASSET_EMBED flag in xmake.lua to switch modes.
  • Use xxd or a similar tool to generate C++ byte arrays from assets at build time for the embedded mode.
  • Update documentation with usage and build instructions for both modes.

Additional Context

N/A

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Not planned

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions