WIP: ResourceManager refactor, hot reloading using ResourceRef, API changes.

This commit is contained in:
2024-10-15 02:44:12 +02:00
parent a1d282908a
commit 851abd7c90
16 changed files with 394 additions and 117 deletions

View File

@@ -0,0 +1,11 @@
[ParticleEmitterSettings]
MaxParticles = 1024
EmitRadius = 128
LifeTime = 0.5
Direction = { x = 0.0, y = 1.0 }
LinearVelocity = 980.0
ScaleBegin = 1.0
ScaleEnd = 0.0
ColorBegin = { r = 0.0, g = 1.0, b = 0.0, a = 1.0 }
ColorEnd = { r = 1.0, g = 0.0, b = 0.0, a = 1.0 }

View File

@@ -15,16 +15,25 @@ public class TestGame : Game
{
InitializeDefault();
_particleSystem = new ParticleSystem();
ResourceManager.AddResourceLoaderAssociation(new ParticleEmitterSettingsResourceLoader());
Input.AddInputMapping("reload", new InputAction[] { new KeyInputAction(KeyboardKey.R) });
}
protected override void LoadResources()
{
if (!ResourceManager.TryLoad("my_sound", "sounds/test_sound.ogg", out Sound? _testSound))
{
// if (!ResourceManager.TryLoad("my_sound", "sounds/test_sound.ogg", out Sound? _testSound))
// {
}
// }
if (!ResourceManager.TryLoad("inter_regular", "fonts/Inter-Regular.ttf", out Font? _font))
// if (!ResourceManager.TryLoad("inter_regular", "fonts/Inter-Regular.ttf", out Font? _font))
// {
// }
if (!ResourceManager.TryLoad("test_emitter.toml", out _emitterSettings))
{
}
@@ -32,19 +41,19 @@ public class TestGame : Game
protected override void Ready()
{
_particleSystem!.CreateEmitter(Renderer.WindowSize / 2, new ParticleEmitterSettings()
{
ColorBegin = Color.Green,
ColorEnd = Color.Red,
EmitRadius = 128,
MaxParticles = 256
});
_emitterId = _particleSystem!.CreateEmitter(Renderer.WindowSize / 2, _emitterSettings);
}
protected override void Run()
{
while (Renderer.ShouldRun)
{
if (Input.IsActionPressed("reload"))
{
ResourceManager.Reload();
_particleSystem!.RestartEmitter(_emitterId);
}
_particleSystem!.Update(Renderer.FrameTime);
Renderer.BeginFrame();
@@ -77,5 +86,7 @@ public class TestGame : Game
}
private ParticleSystem? _particleSystem;
private int _emitterId;
private ResourceRef<ParticleEmitterSettingsResource>? _emitterSettings;
private Logger _logger = new(nameof(TestGame));
}