WIP: ResourceManager refactor, hot reloading using ResourceRef, API changes.
This commit is contained in:
11
TestGame/Resources/test_emitter.toml
Normal file
11
TestGame/Resources/test_emitter.toml
Normal 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 }
|
||||
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user