-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.cs
147 lines (119 loc) · 4.67 KB
/
GUI.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Numerics;
using System.Collections.Generic;
using ImGuiNET;
using Raylib_cs;
namespace MasterSpark
{
class GUI
{
static Queue<float> Frametimes = new Queue<float>();
static Queue<float> GCHist = new Queue<float>();
static int LastGC = 0;
public static IntPtr FrameBufferPointer = new IntPtr(8);
static bool FlipFrameBuffer = true;
public unsafe static void SubmitUI()
{
ImGui.DockSpaceOverViewport(ImGui.GetMainViewport());
{
ImGui.Begin("FrameBuffer");
float width;
float height;
// float contentWidth = ImGui.GetWindowWidth();
// float contentHeight = ImGui.GetWindowHeight();
Vector2 contentMin = ImGui.GetWindowContentRegionMin();
Vector2 contentMax = ImGui.GetWindowContentRegionMax();
float contentWidth = contentMax.X - contentMin.X;
float contentHeight = contentMax.Y - contentMin.Y;
if (contentHeight > contentWidth * 0.75f) {
width = contentWidth;
height = width * 3/4;
}
else {
height = contentHeight;
width = height * 4/3;
}
int ptr = (int)FrameBufferPointer;
ImGui.SliderInt("PTR", ref ptr, 1, 15); ImGui.SameLine();
ImGui.Checkbox("Flip", ref FlipFrameBuffer);
FrameBufferPointer = new IntPtr(ptr);
if (FlipFrameBuffer)
{
ImGui.Image(
FrameBufferPointer,
new Vector2(width, height),
new Vector2(0, 1),
new Vector2(1, 0)
);
}
else
{
ImGui.Image(
FrameBufferPointer,
new Vector2(width, height),
new Vector2(0, -1),
new Vector2(1, 0)
);
}
ImGui.End();
}
{
var memInfo = GC.GetGCMemoryInfo();
if (memInfo.Index > LastGC)
{
LastGC = (int)memInfo.Index;
GCHist.Enqueue(memInfo.Generation + 1);
}
else
{
GCHist.Enqueue(0f);
}
Frametimes.Enqueue(Raylib.GetFrameTime());
if (Frametimes.Count > 100) { Frametimes.Dequeue(); GCHist.Dequeue(); }
float[] frameArray = Frametimes.ToArray();
float[] GCHistArray = GCHist.ToArray();
ImGui.Begin("Performance");
ImGui.PlotLines("", ref frameArray[0], frameArray.Length, 0, "", 0.016665f, 0.01667f, new Vector2(0, 60));
ImGui.PlotHistogram("", ref GCHistArray[0], GCHistArray.Length, 0,"", 0f, 3f, new Vector2(0, 20));
ImGui.Text($"{System.GC.GetTotalMemory(false) / 1000000f:00.00}MB");
float framerate = ImGui.GetIO().Framerate;
ImGui.Text($"Application average {1000.0f / framerate:0.##} ms/frame ({framerate:0.#} FPS)");
Game.SubmitUI();
ImGui.End();
}
{
ImGui.ShowDemoWindow();
}
{
ImGui.BeginMainMenuBar();
bool Test = ImGui.MenuItem("Test");
bool About = ImGui.MenuItem("About");
ImGui.EndMainMenuBar();
}
{
ImGui.Begin("StageTree");
Game.CurrentStage.SubmitUI();
ImGui.End();
}
{
ImGui.Begin("EntityInspector");
if (Game.CurrentStage.EntitySelection > -1)
{
Game.CurrentStage.Entities[Game.CurrentStage.EntitySelection].SubmitUI();
}
ImGui.End();
}
{
ImGui.Begin("CameraController");
Program.MainCamera.SubmitUI();
Game.GameCamera.SubmitUI();
ImGui.End();
}
{
ImGui.Begin("Console");
Console.SubmitUI();
ImGui.End();
}
}
}
}