Repository navigation
Expand file tree
/
Copy pathMainWindow.cs
More file actions
148 lines (120 loc) · 5.26 KB
/
Copy pathMainWindow.cs
File metadata and controls
148 lines (120 loc) · 5.26 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
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
148
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using ProjectOdyssey.Diagnostic;
using ProjectOdyssey.Input;
using ProjectOdyssey.Input.Native;
using ProjectOdyssey.Screens;
namespace ProjectOdyssey
{
public class MainWindow : GameWindow
{
private readonly ScreenManager screenManager = new();
private Win32KeyInputListener inputListener = new Win32KeyInputListener();
private InputHistory inputHistory = new InputHistory();
private readonly FrameProfiler profiler = new(isEnabled: false);
public MainWindow(int width, int height, string title, bool vsync = true)
: base(
new GameWindowSettings
{
UpdateFrequency = vsync ? 0 : 240
},
new NativeWindowSettings
{
ClientSize = new Vector2i(width, height),
Title = title,
APIVersion = new Version(4, 1)
})
{
WindowState = WindowState.Maximized;
//WindowState = WindowState.Fullscreen;
Context.SwapInterval = vsync ? 1 : 0;
}
protected unsafe override void OnLoad()
{
base.OnLoad();
GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GL.Viewport(0, 0, ClientSize.X, ClientSize.Y);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
inputListener.Initialise((IntPtr)WindowPtr, WndProcHook);
inputListener.OnInputEvent += inputHistory.RecordInputEvent;
inputListener.OnInputEvent += _ => profiler.CountInputEvent();
// Loads all skin textures/glyphs once. Needs the GL context, so it can't happen in the constructor.
screenManager.Initialise(Path.Combine(AppContext.BaseDirectory, "Skins", "Skin 1"));
// ScreenManager needs to know the viewport before the first
// screen is pushed, so Resize() is used here instead of it
// reading ClientSize on its own.
screenManager.Resize(ClientSize.X, ClientSize.Y);
string chartPath = ""; // put the path to your chart file here temporaily
string songPath = "";
//ChartData chartData = ChartBinaryReader.ReadChartBinary(chartPath);
//screenManager.Push(new GameplayScreen(chartData, songPath, inputHistory, audioManager));
screenManager.Push(new ChartBrowserScreen(inputHistory));
//screenManager.Push(new ChartManagerScreen());
//Task.Run(() => ChartImportService.ImportChartsFromOsu()); // imports all charts from the osu! Songs directory into the Odyssey's own database
Console.WriteLine($"[INFO] ClientSize = {ClientSize.X} x {ClientSize.Y}");
}
protected override void OnUpdateFrame(FrameEventArgs args)
{
long start = FrameProfiler.Timestamp();
base.OnUpdateFrame(args);
screenManager.Update((float)args.Time * 1000f);
profiler.RecordUpdate(start);
}
protected override void OnRenderFrame(FrameEventArgs args)
{
long renderStart = FrameProfiler.Timestamp();
base.OnRenderFrame(args);
GL.Clear(ClearBufferMask.ColorBufferBit);
screenManager.Render();
long beforeSwap = FrameProfiler.Timestamp();
SwapBuffers();
long afterSwap = FrameProfiler.Timestamp();
profiler.RecordFrame(args.Time * 1000.0, screenManager.CurrentScreen, renderStart, beforeSwap, afterSwap);
}
protected unsafe override void OnUnload()
{
base.OnUnload();
screenManager.Dispose(); // unloads screens, then the skin, then audio
inputListener.Dispose((IntPtr)WindowPtr);
profiler.WriteCsv(Path.Combine(AppContext.BaseDirectory, "Profiling"));
}
protected override void OnFramebufferResize(FramebufferResizeEventArgs args)
{
base.OnFramebufferResize(args);
GL.Viewport(0, 0, args.Width, args.Height);
screenManager.Resize(args.Width, args.Height);
}
protected override void OnKeyDown(KeyboardKeyEventArgs e)
{
base.OnKeyDown(e);
if (e.IsRepeat) return; // ignore OS key-repeat while held
screenManager.OnKeyDown(e.Key);
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
screenManager.OnMouseDown(e);
}
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
screenManager.OnMouseMove(e);
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
screenManager.OnMouseWheel(e);
}
private IntPtr WndProcHook(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
if (msg == 0x00FF) // WM_INPUT
{
inputListener.HandleRawInput(lParam);
}
return inputListener.CallNextWindowProc(hWnd, msg, wParam, lParam);
}
}
}