-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleCommands.h
363 lines (297 loc) · 14.5 KB
/
ConsoleCommands.h
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#ifndef RR_CONSOLECOMMANDS
#define RR_CONSOLECOMMANDS
static char lorum[] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
static void HelloHelper(StringArray args)
{
ConsoleOutput("Hello!");
}
static void LorumHelper(StringArray args)
{
ConsoleOutput(lorum);
}
static void AddHelper(StringArray args)
{
b32 success = true;
u32 inp1 = StoU(args[0], &success);
u32 inp2 = StoU(args[1], &success);
if (!success)
{
ConsoleOutput("Arguments did not match!");
return;
}
u32 sum = inp1 + inp2;
ConsoleOutput("%i32 + %i32 = %i32", inp1, inp2, sum);
}
static void ClearHelper(StringArray args)
{
console.commandHistory->length = 0;
console.historyLength = 0;
console.historyPos = 0;
Clear(console.arena);
}
static void HelpHelper(StringArray args)
{
ConsoleOutput("Console Commands are:");
For(console.commands)
{
ConsoleOutput(" %s", it->name);
}
}
static void WriteDebugVariables();
static void WriteSingleTweeker(Tweeker tweeker);
// todo : make this need file names
static void TweekHelper(StringArray args)
{
if (args.amount == 0)
{
For(globalTweekers.tweekers)
{
ConsoleOutput("%s %s", it->name, TweekerToString(*it));
}
return;
}
Tweeker *toTweek = GetTweeker(args[0]);
if(!toTweek)
{
ConsoleOutputError("Error: Tweeker not found!", HistoryEntry_Error); // todo : nearest match?
return;
}
if (args.amount == 1)
{
if (toTweek->type == Tweeker_v4)
{
ColorPicker picker = CreateColorPicker(&toTweek->vec4);
picker.tweeker = toTweek;
picker.isTweeker = true;
ArrayAdd(&gameState.editor.colorPickers, picker);
}
ConsoleOutput("Current Tweeker Value is: %s", TweekerToString(*toTweek));
return;
}
Tweeker save = *toTweek;
b32 success = true;
switch (toTweek->type)
{
case Tweeker_b32:
{
b32 val = StoB(args[1], &success);
if (success) toTweek->b = val;
}break;
case Tweeker_u32:
{
u32 val = StoU(args[1], &success);
if (success) toTweek->u = val;
}break;
case Tweeker_f32:
{
f32 val = StoF(args[1], &success);
if (success) toTweek->f = val;
}break;
case Tweeker_v2:
{
v2 val = StoV2(args[1], &success);
if (success) toTweek->vec2 = val;
}break;
case Tweeker_v3:
{
v3 val = StoV3(args[1], &success);
if (success) toTweek->vec3 = val;
}break;
case Tweeker_v4:
{
v4 val = StoV4(args[1], &success);
if (success) toTweek->vec4 = val;
}break;
default:
ConsoleOutputError("Unhandled Tweeker Type in Tweek Helper!");
return;
}
if (!success)
{
ConsoleOutputError("Could not parse the value for tweeker %s", toTweek->name);
ConsoleOutputError("Value remains: %s", TweekerToString(*toTweek));
return;
}
ConsoleOutput("Tweeked %s: %s -> %s!", toTweek->name, TweekerToString(save), TweekerToString(*toTweek));
WriteSingleTweeker(*toTweek);
}
static void SaveTweekersHelper(StringArray args)
{
if (args[0] == "tweekers")
{
WriteDebugVariables();
ConsoleOutput("Saved Tweekers!");
return;
}
ConsoleOutput("Don't know what to save! (Could not read input).");
}
static void TweekersHelper(StringArray args)
{
For(globalTweekers.tweekers)
{
ConsoleOutput("%s %s", it->name, TweekerToString(*it));
}
}
static void GrisuHelper(StringArray args)
{
b32 success = true;
f32 ret = StoF(args[0], &success);
if (success)
{
ConsoleOutput("parsed float is %f32", ret);
Grisu(frameArena, ret);
}
else
{
ConsoleOutput("Could not read float");
}
}
static void ConvertHelper(StringArray args)
{
DeferRestore(frameArena);
String head = args[0];
String type = EatToCharFromBackReturnTail(&head, '.');
if (!head.length)
{
ConsoleOutputError("No filetype found!");
return;
}
char* nameToLoad = ToNullTerminated(frameArena, args[0]);
String name = EatToCharFromBackReturnTail(&head, '/');
if (type == "bmp")
{
String nameToSave = FormatString("textures/%stexture\n", name);
nameToSave[nameToSave.length - 1] = '\0'; // todo hack... maybe make this a version of format string
Bitmap bitmap = CreateBitmap(nameToLoad, frameArena);
if (!bitmap.pixels)
{
ConsoleOutputError("Could not find bitmap %c*.", nameToLoad);
return;
}
if (bitmap.height != Asset_Bitmap_Size || bitmap.width != Asset_Bitmap_Size)
{
ConsoleOutputError("Bitmap does not have standart bitmap size.", nameToLoad);
return;
}
WriteTexture((char *)nameToSave.data, bitmap);
ConsoleOutput("Converted bitmap %c* to texture %s", nameToLoad, nameToSave);
return;
}
else if(type == "obj")
{
char *nameToSave = FormatCString("mesh/%smesh", name);
TriangleMesh mesh = ReadObj(nameToLoad, frameArena);
if (!mesh.positions.amount)
{
ConsoleOutputError("Probably file name wrong. Might have loaded a mesh w/0 vertices.");
return;
}
WriteTriangleMesh(mesh, nameToSave);
ConsoleOutput("Converted .obj %c* to .mesh %c*", nameToLoad, nameToSave);
return;
}
ConsoleOutputError("Unrecognized Format!");
}
static void SaveLevelHelper(StringArray args)
{
if(gameState.mode != Game_Editor)
{
ConsoleOutputError("Saving Levels only allowed in Editor.");
return;
}
if(args[0] == "")
{
ConsoleOutputError("Empty Name not allowed.");
return;
}
char *fileName = FormatCString("level/%s.level", args[0]);
Level level = EditorStateToLevel(&gameState.editor);
if(!WriteLevel(fileName, level, &gameState.assetHandler))
{
ConsoleOutputError("An error accured while trying to save the level.!");
}
gameState.entityManager.levelName = CopyString(args[0], gameState.currentStateArena); // todo leak
ConsoleOutputError("Done!");
}
static void LoadLevelHelper(StringArray args)
{
if(gameState.mode != Game_Editor)
{
ConsoleOutputError("Loading Levels only allowed in Editor.");
return;
}
if(args[0] == "")
{
ConsoleOutputError("Empty Name not allowed.");
return;
}
Level level = LoadLevel(args[0], frameArena, &gameState.assetHandler);
if (!level.name.amount)
{
ConsoleOutputError("Tried to load \"level/%s.level\", no such file or directory!", args[0]);
return;
}
Clear(gameState.currentStateArena);
EditorLoadLevel(&gameState.editor, gameState.currentStateArena, &level);
ConsoleOutput("Loaded level %s!", args[0]);
}
static void NewLevelHelper(StringArray args)
{
if(gameState.mode != Game_Editor)
{
ConsoleOutputError("Loading Levels only allowed in Editor.");
return;
}
NewLevel(&gameState.editor);
ConsoleOutput("New Level! Save with 'saveLevel' command.");
}
static void AddMeshHelper(StringArray args)
{
if (gameState.editor.state != EditorState_Default)
{
ConsoleOutputError("Editor is in a mode other then 'Default'. This is not 'yet' allowed.");
return;
}
b32 succsess = true;
String name = FormatString("%s.mesh", args[0]);
u32 id = RegisterAsset(&gameState.assetHandler, Asset_Mesh, name, &succsess);
if (succsess)
{
//TriangleMesh *mesh = GetMesh(&gameState.assetHandler, id);
EntityData data;
data.color = V4(1, 1, 1, 1);
data.meshId = id;
data.orientation = { 1, 0, 0, 0 };
data.physicalPos = V3i();
data.offset = V3();
data.scale = 1.0f;
data.type = Entity_None;
data.flags = 0;
gameState.editor.clipBoard.amount = 1;
gameState.editor.clipBoard[0] = data;
gameState.editor.state = EditorState_PlacingNewMesh;
EditorSelectNothing(&gameState.editor);
}
}
static void SaveCameraHelper(StringArray args)
{
gameState.editor.levelInfo.camera = gameState.editor.camera;
}
static void SetLightHelper(StringArray args)
{
gameState.editor.levelInfo.lightSource.orientation = gameState.editor.camera.orientation;
gameState.editor.levelInfo.lightSource.pos = gameState.editor.camera.pos;
}
static void LevelsHelper(StringArray args)
{
StringArray levels = FindAllFiles("level\\", ".level", frameArena);
For(levels)
{
ConsoleOutput(*it);
}
}
static void NoteHelper(StringArray args)
{
ConsoleOutput("Noted.");
}
#endif // ! RR_CONSOLECOMMANDS