Open jakubg1 opened 1 year ago
We need to consider migrating some classes, too. Here's a list of the more important resource types used in the engine: | Name | Extension | Located in | Stored as | Class name | Loaded by | Notes |
---|---|---|---|---|---|---|---|
Image | *.png |
/images |
Class | Essentials/Image |
ResourceManager | ||
Sprite | *.json |
/sprites |
Class | Essentials/Sprite |
ResourceManager | ||
Sound | *.wav/ogg/... |
/sounds |
Class | Essentials/Sound |
ResourceManager | ||
Sound Event | *.json |
/sound_events |
Class | Essentials/SoundEvent |
ResourceManager | ||
Music | *.wav/ogg/... |
/music |
Class | Essentials/Music |
ResourceManager | ||
Font | *.json |
/fonts |
Class | Essentials/Font |
ResourceManager | ||
Font File | *.ttf |
/font_files |
LOVE2D Object | (none) | Font | This is an example of very bad implementation! | |
Particle | *.json |
/particles |
Table | (none) | ResourceManager | ||
Color Palette | *.png |
--- | Class | Essentials/ColorPalette |
ResourceManager | Stored and loaded in Load List | |
Sphere | *.json |
/config/spheres |
Table | (none) | ConfigManager | ||
Sphere Effect | *.json |
/config/sphere_effects |
Table | (none) | ConfigManager | ||
Collectible | *.json |
/config/collectibles |
Table | (none) | ConfigManager | ||
Collectible Generator | *.json |
/config/collectible_generators |
Class | CollectibleGenerator/Entry |
CollectibleGeneratorManager | ||
Color Generator | *.json |
/config/color_generators |
Table | (none) | ConfigManager | ||
Level | *.json |
/config/levels |
Table | (none) | ConfigManager | ||
Map | *.json |
/maps/<map name>/config.json |
Table | (none) | ConfigManager | Load list defined by Levels |
Some insights I can see from the table:
Ideally, either:
Also:
sound_events/button_hover.json
-> button_hover
. Currently, ConfigManager does that but ResourceManager does not.
Additional key benefits by introducing this change:
An example involving the shooter data structure has been added in commit https://github.com/jakubg1/OpenSMCE/commit/77cf19b2e0519ae3f01f9fdaea05ab7d9a4cb7fa. A few notable observations one can see in my approach:
---@type
tags.API draft for the new Resource Manager:
ResourceManager:resolveAssetPath(path, [namespace])
: Resolves and outputs the entire asset path starting from the game folder. As per https://github.com/jakubg1/OpenSMCE/issues/103.
resolveAssetPath(":flame.spr", "Map1")
will return "maps/Map1/sprites/flame.spr"
.ResourceManager:resolveAssetType(path)
: Resolves and outputs the resource type of this file, based on its extension.
resolveAssetType(":flame.spr")
will return "sprite"
.ResourceManager:getAsset(path, [namespace], [batches])
: If the resource has been already loaded earlier, returns this resource. If not, immediately loads it in, optionally as a part of designated batches. (TODO: Decide whether to make variants for different asset types or not. LDoc might have a problem with this.)ResourceManager:loadAsset(path, [namespace], [batches])
: If the resource has been already loaded earlier, do nothing. Otherwise, load this asset (not immediately - treat this as queueing the resource to be loaded soon!), optionally as a part of designated batches. If many calls are performed in a quick succession, the load order will be preserved. This function will never return anything.ResourceManager:loadAssetFromServer(path, [namespace], [batches], [cache])
: Proposed way of loading resources from the server, for use in Cosmic Crash.ResourceManager:releaseAssetBatch(batch)
: Removes all mentions of the given batch from all the loaded resources. For any resource, if that was the only batch, unloads it completely.ResourceManager:startLoadCounter(name)
: Creates a counter which will be counting all resources queued from this point onwards. The total number of resources and the number of resources already loaded will be tracked.ResourceManager:stopLoadCounter(name)
: Stops counting the resources that are queued. Does not destroy the counter: the counter will be hanging around forever. The number of loaded resources will still rise when they are loaded afterwards.ResourceManager:getLoadProgress(name)
: Returns the percentage of loaded resources out of queued resources (between the startLoadCounter
and stopLoadCounter
calls).
function loadGame()
resourceManager:startLoadCounter("main")
resourceManager:loadAsset(...)
resourceManager:loadAsset(...)
resourceManager:loadAsset(...)
...
resourceManager:stopLoadCounter("main")
end
function draw() local progress = resourceManager:getLoadProgress("main") if progress == 1 then drawStartButton() else drawProgressBar(progress) end end
Notes:
getAsset
for loading the maps and the splash screen itself, and loadAsset
for all game resources which are loaded during the splash screen.A few Config Classes have been added which follow the most recent style:
All JSON structures that exist should be given their own classes. This will greatly improve code clarity and will make development easier.
Some insights: