Make ResourceManager a part of Game.
This commit is contained in:
@@ -12,14 +12,16 @@ public class TestGame : Game
|
|||||||
{
|
{
|
||||||
public override string ResourceRoot => "Resources/";
|
public override string ResourceRoot => "Resources/";
|
||||||
|
|
||||||
|
public TestGame() : base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
_renderer = new RaylibRenderer();
|
_renderer = new RaylibRenderer();
|
||||||
_audioBackend = new FmodAudioBackend();
|
_audioBackend = new FmodAudioBackend();
|
||||||
_inputHandler = new RaylibInputHandler();
|
_inputHandler = new RaylibInputHandler();
|
||||||
|
|
||||||
_resourceManager.AddResourceSaverAssociation(new SerializedSceneSaver());
|
|
||||||
|
|
||||||
_renderer.CreateAndInitialize(new WindowSettings()
|
_renderer.CreateAndInitialize(new WindowSettings()
|
||||||
{
|
{
|
||||||
Title = "Test Game",
|
Title = "Test Game",
|
||||||
@@ -37,29 +39,23 @@ public class TestGame : Game
|
|||||||
Renderer = _renderer,
|
Renderer = _renderer,
|
||||||
AudioBackend = _audioBackend,
|
AudioBackend = _audioBackend,
|
||||||
InputHandler = _inputHandler,
|
InputHandler = _inputHandler,
|
||||||
ResourceManager = _resourceManager
|
ResourceManager = ResourceManager
|
||||||
});
|
});
|
||||||
|
|
||||||
_uiLayer = new UiLayer();
|
_uiLayer = new UiLayer();
|
||||||
_worldLayer = new EntityLayer();
|
_worldLayer = new EntityLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
|
||||||
{
|
|
||||||
_renderer!.Shutdown();
|
|
||||||
_audioBackend?.Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadResources()
|
protected override void LoadResources()
|
||||||
{
|
{
|
||||||
if (_resourceManager.TryLoad<Sound>("my_sound", "sounds/test_sound.ogg"))
|
if (ResourceManager.TryLoad<Sound>("my_sound", "sounds/test_sound.ogg"))
|
||||||
{
|
{
|
||||||
_resourceManager.TryGetResource("my_sound", out _testSound);
|
ResourceManager.TryGetResource("my_sound", out _testSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_resourceManager.TryLoad<Font>("inter_regular", "fonts/Inter-Regular.ttf"))
|
if (ResourceManager.TryLoad<Font>("inter_regular", "fonts/Inter-Regular.ttf"))
|
||||||
{
|
{
|
||||||
_resourceManager.TryGetResource("inter_regular", out _font);
|
ResourceManager.TryGetResource("inter_regular", out _font);
|
||||||
|
|
||||||
if (_font is not null)
|
if (_font is not null)
|
||||||
{
|
{
|
||||||
@@ -93,8 +89,13 @@ public class TestGame : Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
_renderer!.Shutdown();
|
||||||
|
_audioBackend?.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
private Renderer? _renderer;
|
private Renderer? _renderer;
|
||||||
private ResourceManager _resourceManager = new();
|
|
||||||
private Sound? _testSound;
|
private Sound? _testSound;
|
||||||
private Font? _font;
|
private Font? _font;
|
||||||
private FmodAudioBackend? _audioBackend;
|
private FmodAudioBackend? _audioBackend;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Folder", "Solution
|
|||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestGame", "TestGame\TestGame.csproj", "{DBA85D7B-0A91-405B-9078-5463F49AE47E}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -28,5 +30,9 @@ Global
|
|||||||
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Release|Any CPU.Build.0 = Release|Any CPU
|
{DA4FDEDC-AA81-4336-844F-562F9E763974}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DBA85D7B-0A91-405B-9078-5463F49AE47E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DBA85D7B-0A91-405B-9078-5463F49AE47E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DBA85D7B-0A91-405B-9078-5463F49AE47E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DBA85D7B-0A91-405B-9078-5463F49AE47E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
|
using Voile.Resources;
|
||||||
|
|
||||||
namespace Voile
|
namespace Voile
|
||||||
{
|
{
|
||||||
public abstract class Game
|
public abstract class Game
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ResourceManager associated with this game.
|
||||||
|
/// </summary>
|
||||||
|
protected ResourceManager ResourceManager { get; private set; }
|
||||||
public abstract string ResourceRoot { get; }
|
public abstract string ResourceRoot { get; }
|
||||||
|
public virtual string EngineConfigPath => "engine.config";
|
||||||
|
|
||||||
|
public Game()
|
||||||
|
{
|
||||||
|
ResourceManager = new ResourceManager();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the game application.
|
/// Starts the game application.
|
||||||
@@ -10,6 +22,8 @@ namespace Voile
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
|
Configure();
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
LoadResources();
|
LoadResources();
|
||||||
Ready();
|
Ready();
|
||||||
@@ -37,5 +51,10 @@ namespace Voile
|
|||||||
/// Called when the application quits and it's safe to clean up.
|
/// Called when the application quits and it's safe to clean up.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract void Shutdown();
|
public abstract void Shutdown();
|
||||||
|
|
||||||
|
private void Configure()
|
||||||
|
{
|
||||||
|
ResourceManager.ResourceRoot = ResourceRoot;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using Voile.Utils;
|
using Voile.Utils;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user