-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
239 lines (210 loc) · 8.61 KB
/
Program.cs
File metadata and controls
239 lines (210 loc) · 8.61 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
using Sandbox.ModAPI.Ingame;
using System;
using System.Collections.Generic;
using VRage.Game.ModAPI.Ingame.Utilities;
namespace IngameScript
{
partial class Program : MyGridProgram
{
public Program()
{
CoyLogo.program = this;
FastDisplays = new List<Display>();
Displays = new List<Display>();
Static = new List<Display>();
Inventory = new InventoryUtilities(GCM, new DebugAPI(this));
if (DateTime.Now.Date.Year % 4 == 0)
addLarp = TimeSpan.FromDays(36524);
else addLarp = TimeSpan.FromDays(36525);
var result = new MyIniParseResult();
using (var p = new IniWrap())
if (p.CustomData(Me, out result))
{
Tag = p.String(GCM, "tag", GCM);
Name = p.String(GCM, "groupName", "Screen Control");
fast = 60 / p.Int(GCM, "maxDrawPerSecond", 4);
min = p.Int(GCM, "minFrame", 256);
isCringe = p.Bool(GCM, "vanillaFont", false);
useLogo = p.Bool(GCM, "logo", false);
larp = p.Bool(GCM, "larp", true);
var ctrl = p.String(GCM, "shipCTRL", "[I]");
GTS.GetBlocksOfType<IMyShipController>(null, b =>
{
if ((b.CustomName.Contains(ctrl) || b.IsMainCockpit) && b.IsSameConstructAs(Me))
Controller = b;
return false;
});
Utilities.Add(new GasUtilities());
Utilities.Add(new FlightUtilities(Tag));
Utilities.Add(new PowerUtilities());
// var grps = p.String(Lib.HDR, "groups").Split('\n');
// if (grps != null) foreach (var g in grps)
// _groups.Add(g, CreateGroup(g, p.String(Lib.HDR, g)));
}
else throw new Exception($" PARSE FAILURE: {Me.CustomName} cd error {result.Error} at {result.LineNo}");
Init(true);
}
public void Main(string argument, UpdateType updateSource)
{
RuntimeMS += Runtime.TimeSinceLastRun.TotalMilliseconds;
Frame++;
var rt = Runtime.LastRunTimeMs;
if (WorstRun < rt) { WorstRun = rt; WorstFrame = Frame; }
totalRt += rt;
if (runtimes.Count == rtMax)
runtimes.Dequeue();
runtimes.Enqueue(rt);
if (!SetupComplete)
RunSetup();
p = Priority.Normal;
if (Frame <= min && useLogo)
{
draw = false;
foreach (var l in logos)
l.Update();
if (Frame == min)
{
foreach (var d in FastDisplays)
d.SetPriority();
foreach (var d in Displays)
d.SetPriority();
foreach (var d in Static)
d.ForceRedraw();
draw = true;
p |= Priority.Once;
}
Echo($"RUNS - {Frame}\nRUNTIME - {rt} ms\nAVG - {AverageRun:0.####} ms\nPARSE CYCLES - {IniWrap.total}\nMYINI INSTANCES - {IniWrap.Count}\nTOTAL FAILURES - {Lib.bsodsTotal}\nFAILURES - {Lib.bsods}");
}
if (argument != "")
{
if (argument.Contains($"{Lib.CMD}"))
{
int j = 0, k;
var urg = argument.Split(Lib.CMD);
// if (urg.Length == 3)
{
for (; j < urg.Length; j++)
urg[j] = urg[j].Trim().Trim(Lib.CMD);
if (_displaysMaster.ContainsKey(urg[2]) && int.TryParse(urg[1], out j))
{
k = _displaysMaster[urg[2]].Item2;
switch (_displaysMaster[urg[2]].Item1)
{
case 0:
FastDisplays[k].MFDSwitch(j, urg[0]);
break;
case 1:
default:
Displays[k].MFDSwitch(j, urg[0]);
break;
case 2:
Static[k].MFDSwitch(j, urg[0]);
break;
}
}
}
}
else
{
argument = argument.ToLower();
switch (argument)
{
case "restart":
{
Init();
break;
}
case "reset":
case "update":
{
Init(false);
break;
}
case "vcr":
{
isCringe = !isCringe;
Init(false);
break;
}
case "freeze":
case "toggle":
{
if (frozen)
{
Runtime.UpdateFrequency = UpdateFrequency.Update1;
frozen = false;
break;
}
else
{
Runtime.UpdateFrequency = Lib.NONE;
frozen = true;
break;
}
}
case "slow":
{
Runtime.UpdateFrequency = UpdateFrequency.Update100;
break;
}
case "wipe":
{
foreach (var d in FastDisplays)
d.Reset();
foreach (var d in Displays)
d.Reset();
foreach (var d in Static)
d.Reset();
Echo("All displays wiped, ready to restart.");
Runtime.UpdateFrequency = Lib.NONE;
return;
}
default: { break; }
}
}
}
if (!SetupComplete) return;
bool fast = (updateSource & UpdateType.Update10) != 0;
if (fast)
{
p |= Priority.Fast;
foreach (var d in FastDisplays)
d.Update(ref p);
}
if (draw)
{
Displays[Lib.Next(ref dPtr, Displays.Count)].Update(ref p);
if (dPtr == 0)
{
Inventory.needsUpdate = true;
draw = false;
}
}
else if (Inventory.needsUpdate)
Inventory.Update();
else
{
Utilities[Lib.Next(ref iPtr, Utilities.Count)].Update();
draw = iPtr == 0;
}
if (Frame > min)
{
if (fast)
{
AverageRun = 0;
foreach (var qr in runtimes)
AverageRun += qr;
AverageRun /= rtMax;
}
string r = "===<GRAPHICS MANAGER>===\n\n";
if (draw) r += $">DRAWING DISPLAY {dPtr + 1}/{Displays.Count}";
else if (Inventory.needsUpdate)
r += $"INV {Inventory.Pointer}/{Inventory.Count}";
else r += $"UTILS {iPtr + 1}/{Utilities.Count} - {Utilities[iPtr].Name}";
r += $"\nRUNS - {Frame}\nRUNTIME - {rt} ms\nAVG - {AverageRun:0.####} ms\nWORST - {WorstRun} ms, F{WorstFrame}";
//r = Inventory.DebugString;
Echo(r);
}
}
}
}