-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cs
More file actions
96 lines (86 loc) · 2.38 KB
/
Engine.cs
File metadata and controls
96 lines (86 loc) · 2.38 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
using ECSEngine.Component;
using ECSEngine.Interface;
using System;
using System.Collections.Generic;
namespace ECSEngine
{
/// <summary>
/// COntainer for all application sub-systems.
/// </summary>
public class Engine
{
private IDictionary<string /*System Name*/, ISystem /*The system object*/> systems = null;
public Engine()
{
systems = new Dictionary<string, ISystem>();
}
/// <summary>
/// Includes a new system in the Engine.
/// </summary>
/// <param name="system"></param>
public void AddSystem(ISystem system)
{
systems.Add(system.Name, system);
}
/// <summary>
/// Removes a system from the engine.
/// </summary>
/// <param name="system"></param>
/// <returns></returns>
public bool RemoveSystem(ISystem system)
{
return systems.Remove(system.Name);
}
/// <summary>
/// Changes the active scene in the engine.
/// </summary>
/// <param name="scene"></param>
public void SetActiveScene(Scene scene)
{
foreach (var pair in systems)
{
pair.Value.CurrentScene = scene;
}
}
/// <summary>
/// Gets a system from the Engine.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ISystem GetSystem<T>() where T : ISystem
{
foreach(var pair in systems)
{
if(pair.Value is T)
{
return pair.Value;
}
}
return null;
}
/// <summary>
/// Gets a system from the Engine.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ISystem GetSystem<T>(string name) where T : ISystem
{
if(systems.TryGetValue(name, out ISystem system))
{
return system;
}
return null;
}
/// <summary>
/// Updates all systems.
/// </summary>
/// <param name="dt"></param>
public void UpdateSystems(float dt)
{
foreach(var pair in systems)
{
pair.Value.Update(dt);
}
}
}
}