-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathStudioSystem.cs
More file actions
111 lines (89 loc) · 3.12 KB
/
Copy pathStudioSystem.cs
File metadata and controls
111 lines (89 loc) · 3.12 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GLFrameworkEngine;
namespace MapStudio.UI
{
public class StudioSystem
{
/// <summary>
/// The active instance of the studio system.
/// </summary>
public static StudioSystem Instance;
/// <summary>
/// A list of actors in the scene.
/// </summary>
public List<ActorBase> Actors = new List<ActorBase>();
/// <summary>
/// Determines if the game timer is playing or not.
/// </summary>
public bool IsPlaying => Timer.IsPlaying;
private GameTimer Timer = new GameTimer();
public StudioSystem() {
Timer.OnFrameUpdate += OnFrameUpdate;
}
/// <summary>
/// Runs the current scene during the calculation loop.
/// </summary>
public void Run() { Timer.Play(); }
/// <summary>
/// Pauses all current scene calculations.
/// </summary>
public void Pause() { Timer.Pause(); }
public void AddActor(ActorBase actor)
{
if (Actors.Contains(actor)) //Actor already added
return;
actor.CreateIdx = Actors.Count;
actor.Age = 0;
Actors.Add(actor);
}
public void RemoveActor(ActorBase actor)
{
if (!Actors.Contains(actor)) //Actor already removed
return;
Actors.Remove(actor);
actor.CreateIdx = -1;
}
private bool updating = false;
private void OnFrameUpdate(object sender, EventArgs e)
{
if (updating) return;
updating = true;
//Make sure the list is set as another list to prevent conflicts if the actor list is updated
var actors = Actors.ToList();
Begin(actors);
CalculateScene(actors);
updating = false;
}
private void Begin(List<ActorBase> actors)
{
//Reset the default settings
for (int i = 0; i < actors.Count; i++)
actors[i].BeginFrame();
}
/// <summary>
/// Calculates the current scene and is calculated each frame.
/// </summary>
public void CalculateScene(List<ActorBase> actors)
{
//Force update the viewport to update the render cache
GLContext.ActiveContext.UpdateViewport = true;
AnimationStats.Reset();
foreach (var actor in actors)
actor.Calc();
//Make sure to update the window directly during scene calculation.
//This is due to these being calculated on another thread so it is better to store them in the window.
MapStudio.UI.StatisticsWindow.SkeletalAnims = AnimationStats.SkeletalAnims;
MapStudio.UI.StatisticsWindow.MaterialAnims = AnimationStats.MaterialAnims;
}
public void Dispose()
{
this.Timer?.Dispose();
foreach (var actor in Actors)
actor.Dispose();
}
}
}