Skip to content

Expose type registry to exporters and parsers#331

Merged
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:expose-world-to-exporters-importers
Jun 3, 2026
Merged

Expose type registry to exporters and parsers#331
waynemwashuma merged 3 commits into
wimaengine:devfrom
waynemwashuma:expose-world-to-exporters-importers

Conversation

@waynemwashuma

Copy link
Copy Markdown
Collaborator

Objective

Introduce TypeRegistry access to asset parsers and exporters, enabling serialization and deserialization logic to leverage runtime type information. As part of this work, asset loading and saving responsibilities were moved out of AssetServer and into the asset update system, making asset I/O execution part of the ECS pipeline rather than being performed directly by the resource. Secondary changes include simplifying AssetServer into a request-driven resource and consolidating asset event handling.

Solution

Type-aware parsing and exporting

Parser.parse() and Exporter.serialize() now receive a TypeRegistry instance allowing custom asset formats to:

  • Resolve reflected types during parsing
  • Serialize type information consistently
  • Access runtime registration data without relying on global state

The TypeRegistry is retrieved from the ECS world during asset processing and passed to parsers/exporters automatically.

AssetServer refactor

Previously, AssetServer:

  • Performed fetch requests directly
  • Performed export requests directly
  • Managed success/failure buffers
  • Managed loaded asset buffers

This tightly coupled request scheduling with execution.

The implementation now follows a request-based model:

  • AssetServer.load() queues an AssetLoadRequest
  • AssetServer.save() queues an AssetSaveRequest
  • updateAssets() performs all loading/saving work
  • ECS events are emitted directly from the asset system

Benefits:

  • Centralized asset execution logic
  • Easier integration with scheduling systems
  • Cleaner separation between asset state and asset processing
  • Future support for batching, async execution, or worker-based processing

Showcase

Before

Parser and exporter implementations had no access to reflected type information:

class MyParser extends Parser {
  async parse(response) {
    return asset
  }
}

class MyExporter extends Exporter {
  async serialize(asset) {
    return body
  }
}

After

Parsers and exporters now receive the active type registry:

class MyParser extends Parser {
  async parse(response, typeRegistry) {
    return asset
  }
}

class MyExporter extends Exporter {
  async serialize(asset, typeRegistry) {
    return body
  }
}

Migration guide

Parser API

Replace:

async parse(response) {
  ...
}

with:

async parse(response, typeRegistry) {
  ...
}

Exporter API

Replace:

async serialize(asset) {
  ...
}

with:

async serialize(asset, typeRegistry) {
  ...
}

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma merged commit 9442dc4 into wimaengine:dev Jun 3, 2026
7 checks passed
@waynemwashuma waynemwashuma deleted the expose-world-to-exporters-importers branch June 3, 2026 00:06
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