forked from RighteousRyan1/TanksRebirth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLauncher.cs
More file actions
50 lines (42 loc) · 1.45 KB
/
GameLauncher.cs
File metadata and controls
50 lines (42 loc) · 1.45 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
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace TanksRebirth;
// GENERAL PROBLEMS:
// Something appears to be seriously eating at the game's performance. spikes happen but i'm not sure if it's just steam or what?
// Could be expensive calculations with AI Controlled tanks in the menu
public static partial class GameLauncher
{
public static bool AutoLaunch = true;
public static bool IsRunning { get; private set; }
public static bool IsConsoleAllocated { get; private set; }
public static void LaunchGame() {
IsRunning = true;
using var game = new TankGame();
game.Run();
}
[LibraryImport("Kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool AllocConsole();
// [Conditional("DEBUG")]
public static void DebugCheck() {
/*
* Boot up console for debugging purposes and other goods.
* ...Only if a debugger is attached.
*/
if (!Debugger.IsAttached) return;
AllocConsole();
Thread.Sleep(1000);
Console.OpenStandardOutput();
Console.OpenStandardError();
IsConsoleAllocated = true;
}
//[STAThread]
static void Main() {
DebugCheck();
if (AutoLaunch)
LaunchGame();
}
public static void CloseGame() => TankGame.Instance.Exit();
}