-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCore.cs
More file actions
97 lines (78 loc) · 2.51 KB
/
GameCore.cs
File metadata and controls
97 lines (78 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Friflo.Engine.ECS;
using Friflo.Engine.ECS.Systems;
using Hopeful.Asset;
using Hopeful.Injection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using TinyMessenger;
namespace Hopeful;
public class GameCore : Game
{
public static Vault RootVault { get; private set; } = null!;
[Inject]
public SystemRoot SystemRoot { get; } = null!;
[Inject]
public AssetManager Assets { get; } = null!;
public GameTime CurrentGameTime { get; private set; } = null!;
protected override void Initialize()
{
RootVault = new();
RootVault.ExtractService<TinyMessengerHub>();
RootVault.ExtractService<EntityStore>();
RootVault.ExtractService(new SystemRoot(RootVault.InjectService<EntityStore>()));
RootVault.LoadServices(Assembly.GetExecutingAssembly());
RootVault.LoadInjections(Assembly.GetExecutingAssembly());
base.Initialize();
}
/*private void InitializeMods()
{
List<string> paths = new();
foreach (var path in paths)
{
if (!_modLoader.TryLoadModAssembly(path, out var assembly) || !_modLoader.TryGetBaseMod(assembly!, out var mod)) continue;
var modContainer = c.CreateChild();
var store = InjectionData.GetService<EntityStore>();
modContainer.Register<SystemRoot>(Made.Of(() => new SystemRoot(store, mod!.ModId)), serviceKey: mod!.ModId); // make Lazy
c.RegisterExports(assembly);
// add to some list, later execute in GameCore.Update();
}
}*/
protected override void LoadContent()
{
Task.Run(LoadAssets);
}
private async Task LoadAssets()
{
try
{
Stopwatch sw = Stopwatch.StartNew();
await Assets.LoadAllAssetsAsync("Assets");
sw.Stop();
Debug.WriteLine($"All assets loaded. Time: {sw.ElapsedMilliseconds} ms");
}
catch (Exception ex)
{
Debug.WriteLine($"Error loading assets: {ex.Message}");
}
}
protected override void Update(GameTime gameTime)
{
CurrentGameTime = gameTime;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
base.Draw(gameTime);
}
protected override void UnloadContent()
{
Assets.Dispose();
RootVault.Dispose();
base.UnloadContent();
}
}