-
Notifications
You must be signed in to change notification settings - Fork 0
Core.Resource
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.
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.
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:
-
Interchangeability: You can swap this implementation with something like an
AssetPackageResource(which would read from encrypted.pakfiles) without changing a single line of code in your factories or managers. -
Bypassing Complexity: While an
AssetPackagermight handle encryption (using yourAesResourceSink) and compression, theFallbackResourceskips all that "processing" to give you the raw data immediately.
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
Assetsfolder 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.pakfile. -
No Packaging Overhead: During prototyping, you might not have a final structure for your assets.
FallbackResourceallows 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.
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.