-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
140 lines (120 loc) · 4.77 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Input;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OlegEngine;
namespace WheelOfSteamGames
{
class Program : GameWindow
{
public const string SettingsFile = "settings.cfg";
public Engine engine;
public Program(Settings settings)
: base(settings.Width, settings.Height, new GraphicsMode(32, 24, 0, settings.Samples), "Wheel of Steam Games", settings.WindowMode == WindowState.Fullscreen && settings.NoBorder ? GameWindowFlags.Fullscreen : GameWindowFlags.Default )
{
Utilities.EngineSettings = settings;
VSync = settings.VSync;
if (settings.NoBorder)
{
this.WindowBorder = OpenTK.WindowBorder.Hidden;
}
if (!settings.NoBorder && settings.WindowMode == OpenTK.WindowState.Fullscreen)
this.WindowState = settings.WindowMode;
else if (settings.NoBorder) this.WindowState = OpenTK.WindowState.Normal;
engine = new Engine(this); //Create the engine class that'll do all the heavy lifting
engine.OnRenderSceneOpaque += new Action<FrameEventArgs>(RenderSceneOpaque);
engine.OnRenderSceneTranslucent += new Action<FrameEventArgs>(RenderSceneTranslucent);
try
{
this.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
}
catch (Exception e)
{
Utilities.Print("Failed to load icon! {0}", Utilities.PrintCode.WARNING, e.Message);
}
if (!settings.ShowConsole)
{
IntPtr consoleHandle = ConsoleManager.GetConsoleWindow();
ConsoleManager.ShowWindow(consoleHandle, ConsoleManager.SW_HIDE);
}
}
/// <summary>Load resources here.</summary>
/// <param name="e">Not used.</param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
engine.OnLoad(e);
Splash.Initialize();
}
/// <summary>
/// Called when your window is resized. Set your viewport here. It is also
/// a good place to set up your projection matrix (which probably changes
/// along when the aspect ratio of your window).
/// </summary>
/// <param name="e">Not used.</param>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
engine.OnResize(e);
}
/// <summary>
/// Called when it is time to setup the next frame. Add you game logic here.
/// </summary>
/// <param name="e">Contains timing information for framerate independent logic.</param>
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
engine.OnUpdateFrame(e);
MainRoom.Think();
//if (this.Keyboard[Key.Escape]) this.Exit();
}
/// <summary>
/// Called when it is time to render the next frame. Add your rendering code here.
/// </summary>
/// <param name="e">Contains timing information.</param>
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
engine.OnRenderFrame(e);
SwapBuffers();
}
/// <summary>
/// Called by the engine when it is time to render opaque renderables
/// </summary>
/// <param name="e"></param>
private void RenderSceneOpaque(FrameEventArgs e)
{
//Draw opaque geometry
MainRoom.Draw();
OlegEngine.Entity.EntManager.DrawOpaque(e);
//Draw debug stuff
Graphics.DrawDebug();
}
/// <summary>
/// Called by the engine when it is time to render potentially-translucent renderables
/// </summary>
/// <param name="e"></param>
void RenderSceneTranslucent(FrameEventArgs e)
{
//Now draw geometry that is potentially transcluent
GL.Enable(EnableCap.Blend);
OlegEngine.Entity.EntManager.DrawTranslucent(e);
GL.Disable(EnableCap.Blend);
}
[STAThread]
static void Main(string[] args)
{
Utilities.Print("==================================", Utilities.PrintCode.INFO);
Utilities.Print("ENGINE STARTUP", Utilities.PrintCode.INFO);
Utilities.Print("==================================\n", Utilities.PrintCode.INFO);
using (Program game = new Program(new Settings(SettingsFile)))
{
game.Run(60.0);
}
}
}
}