Skip to content

Core.Resource

Dennis Steffen edited this page Jan 4, 2026 · 1 revision

The FallbackResource class serves as a direct, transparent implementation of the IResource interface. It essentially acts as a wrapper around the standard .NET System.IO file system operations.

Explanation of FallbackResource

This class maps the high-level resource requests (like LoadText or GetFiles) directly to the physical disk using File and Directory classes.

  • Exists / DirectoryExists: Directly checks the local file system for the presence of a file or folder.
  • GetFiles: Scans a physical directory for files matching a pattern.
  • LoadText / LoadBytes: Reads the raw contents of a file directly from the path provided.

Why it acts as "Middleware" (Abstraction)

In the context of your engine, IResource is the abstraction layer. By using this interface, the rest of the game (like your GameSpriteFactory) doesn't need to know how or where a file is stored—it just asks for "Assets/GameSprites.png".

The FallbackResource is a "middleware-like" implementation because:

  1. Interchangeability: You can swap this implementation with something like an AssetPackageResource (which would read from encrypted .pak files) without changing a single line of code in your factories or managers.
  2. Bypassing Complexity: While an AssetPackager might handle encryption (using your AesResourceSink) and compression, the FallbackResource skips all that "processing" to give you the raw data immediately.

Usage in Debugging and Prototyping

As you noted, this implementation is primarily used during development for several reasons:

  • Rapid Iteration: You can modify a texture or a JSON config file in your Assets folder and restart the game (or even hot-reload) to see changes instantly. You don't have to wait for an "Asset Packaging" step to bundle everything into a .pak file.
  • No Packaging Overhead: During prototyping, you might not have a final structure for your assets. FallbackResource allows you to move files around freely on your disk.
  • Easier Debugging: If a resource fails to load, it's much easier to check if the file exists on the disk than to debug why an entry is missing from a binary package or why a decryption key is failing.

Relationship with AssetPackager

In a production build, your AssetConfig defines how assets are bundled into Asset.pak. At that stage, you would likely register an implementation of IResource into your ObjectManager that knows how to extract data from those packages.

By having FallbackResource, you maintain a "Development Mode" where the engine treats the local Assets folder as the source of truth, effectively "falling back" to the raw file system instead of the optimized production packages.

Clone this wiki locally