-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
803 lines (681 loc) · 21.1 KB
/
Main.cpp
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <SDL.h>
#include <SDL_main.h>
#include <cmath>
#include <cstdint>
#include <cstdio>
using namespace std;
#define FLIP
#define VSYNC
#define MULTITHREAD
const int ScreenWidth = 1280;
const int ScreenHeight = 720;
#ifdef NDEBUG
#define myassert(cond)
#else
#define myassert(cond) if (!(cond)) { __debugbreak(); }
#endif
template <typename T>
T min(const T x, const T y)
{
return x < y ? x : y;
}
template <typename T>
T max(const T x, const T y)
{
return x > y ? x : y;
}
const float Pi = 3.1415926535897932f;
const float Infinity = 1.0e20f;
float dtor(float d)
{
return d * Pi / 180.0f;
}
struct ScreenPixel
{
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
};
ScreenPixel rgb(uint8_t r, uint8_t g, uint8_t b)
{
return { b, g, r, 255 };
}
void setpix(ScreenPixel* pixels, const int x, const int y, const ScreenPixel& color)
{
#ifdef FLIP
pixels[x * ScreenHeight + y] = color;
#else
pixels[y * ScreenWidth + x] = color;
#endif
}
#if 0
const int MapW = 4;
const int MapH = 4;
// (0,0) at bottom left.
const uint8_t Map[MapW * MapH] =
{
1, 1, 1, 1,
1, 0, 0, 1,
1, 0, 0, 1,
1, 1, 1, 1
};
#else
const int MapW = 8;
const int MapH = 8;
// (0,0) at bottom left.
const uint8_t Map[MapW * MapH] =
{
1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 1, 1, 1, 0, 1,
1, 0, 0, 0, 0, 1, 0, 1,
1, 0, 0, 1, 0, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 1,
1, 0, 0, 1, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1
};
#endif
uint8_t safemap(const int ix, const int iy)
{
return
ix >= 0 &&
iy >= 0 &&
ix <= MapW - 1 &&
iy <= MapH - 1
? Map[(MapH - 1 - iy) * MapW + ix]
: 1;
}
uint8_t map(const int ix, const int iy)
{
myassert(
ix >= 0 &&
iy >= 0 &&
ix <= MapW - 1 &&
iy <= MapH - 1);
return safemap(ix, iy);
}
const float HFov = dtor(90.0f);
const float VFov = HFov * ScreenHeight / ScreenWidth;
const float FilmWidth = 0.01f;
const float FilmHeight = FilmWidth * ScreenHeight / ScreenWidth;
const float FocalLength = FilmWidth / 2.0f * tan(HFov / 2.0f);
const float WallHeight = 1.0f;
const float WallPadding = 0.1f;
const float PlayerWalkSpeed = 0.03f;
const float PlayerRunSpeed = 0.06f;
const float PlayerRotateSpeed = dtor(5.0f);
struct Player
{
float x, y, a;
void reset()
{
x = 2.0f;
y = 2.0f;
a = dtor(90.0f);
}
};
struct Texture
{
int w, h, n;
uint8_t* data;
};
void load_texture(Texture* tex, const char* filepath)
{
tex->data = stbi_load(filepath, &tex->w, &tex->h, &tex->n, 4);
}
const uint8_t* lookup_texture(const Texture* tex, int x, int y)
{
if (x < 0) x += tex->w;
if (y < 0) y += tex->h;
if (x > tex->w - 1) x -= tex->w;
if (y > tex->h - 1) y -= tex->h;
return &tex->data[(y * tex->w + x) * 4];
}
const int NumTextures = 1;
const char* TextureFilePaths[NumTextures] =
{
"textures/407.png"
};
Texture textures[1];
Player player;
bool texture = true;
bool bilinear = false;
bool minimap = false;
void init()
{
for (int i = 0; i < NumTextures; ++i)
load_texture(&textures[i], TextureFilePaths[i]);
player.reset();
}
void done()
{
for (int i = 0; i < NumTextures; ++i)
stbi_image_free(textures[i].data);
}
bool cast_ray(
const float x0, const float y0,
const float x1, const float y1,
float* hx, float* hy,
float* u)
{
myassert(x0 >= 0.0f && x0 < static_cast<float>(MapW));
myassert(y0 >= 0.0f && y0 < static_cast<float>(MapH));
float x = x0;
float y = y0;
int ix = static_cast<int>(x);
int iy = static_cast<int>(y);
if (x == ix && x1 < x0)
ix -= 1;
if (y == iy && y1 < y0)
iy -= 1;
myassert(map(ix, iy) == 0);
const int ix1 = static_cast<int>(x1);
const int iy1 = static_cast<int>(y1);
while (true)
{
const float dx = x1 - x;
const float dy = y1 - y;
float wallx, tx;
if (dx > 0.0f)
{
wallx = ceil(x);
if (x == wallx)
wallx += 1.0f;
myassert(x < wallx);
tx = (wallx - x) / dx;
myassert(tx > 0.0f);
}
else if (dx < 0.0f)
{
wallx = floor(x);
if (x == wallx)
wallx -= 1.0f;
myassert(x > wallx);
tx = (wallx - x) / dx;
myassert(tx > 0.0f);
}
else tx = Infinity;
float wally, ty;
if (dy > 0.0f)
{
wally = ceil(y);
if (y == wally)
wally += 1.0f;
myassert(y < wally);
ty = (wally - y) / dy;
myassert(ty > 0.0f);
}
else if (dy < 0.0f)
{
wally = floor(y);
if (y == wally)
wally -= 1.0f;
myassert(y > wally);
ty = (wally - y) / dy;
myassert(ty > 0.0f);
}
else ty = Infinity;
myassert(tx < Infinity || ty < Infinity);
if (tx < ty)
{
x = wallx;
y += tx * dy;
myassert(dx != 0.0f);
if (dx > 0.0f)
{
ix += 1;
myassert(ix == static_cast<int>(x));
myassert(ix <= MapW - 1);
iy = static_cast<int>(y);
}
else
{
ix -= 1;
//myassert(ix == static_cast<int>(x));
myassert(ix >= 0);
iy = static_cast<int>(y);
}
if (map(ix, iy) != 0)
{
*hx = x;
*hy = y;
*u = y - iy;
return true;
}
}
else
{
x += ty * dx;
y = wally;
myassert(dy != 0.0f);
if (dy > 0.0f)
{
iy += 1;
myassert(iy == static_cast<int>(y));
myassert(iy <= MapH - 1);
ix = static_cast<int>(x);
}
else
{
iy -= 1;
//myassert(iy == static_cast<int>(y));
myassert(iy >= 0);
ix = static_cast<int>(x);
}
if (map(ix, iy) != 0)
{
*hx = x;
*hy = y;
*u = x - ix;
return true;
}
}
if (ix == ix1 && iy == iy1)
return false;
}
}
void update()
{
const uint8_t* keys = SDL_GetKeyboardState(nullptr);
float dx = 0.0f, dy = 0.0f;
const float movespeed =
(keys[SDL_SCANCODE_LSHIFT] | keys[SDL_SCANCODE_RSHIFT]) ? PlayerRunSpeed : PlayerWalkSpeed;
if (keys[SDL_SCANCODE_LEFT])
{
if (keys[SDL_SCANCODE_LALT])
{
dx += movespeed * cos(player.a + Pi / 2.0f);
dy += movespeed * sin(player.a + Pi / 2.0f);
}
else player.a += PlayerRotateSpeed;
}
if (keys[SDL_SCANCODE_RIGHT])
{
if (keys[SDL_SCANCODE_LALT])
{
dx += movespeed * cos(player.a - Pi / 2.0f);
dy += movespeed * sin(player.a - Pi / 2.0f);
}
else player.a -= PlayerRotateSpeed;
}
if (keys[SDL_SCANCODE_UP])
{
dx += movespeed * cos(player.a);
dy += movespeed * sin(player.a);
}
if (keys[SDL_SCANCODE_DOWN])
{
dx -= movespeed * cos(player.a);
dy -= movespeed * sin(player.a);
}
const int ix = static_cast<int>(player.x);
const int iy = static_cast<int>(player.y);
myassert(map(ix, iy) == 0);
for (int y = iy - 1; y <= iy + 1; ++y)
{
for (int x = ix - 1; x <= ix + 1; ++x)
{
if (x == ix && y == iy)
continue;
if (safemap(x, y) != 0)
{
const float blockx0 = x - WallPadding;
const float blocky0 = y - WallPadding;
const float blockx1 = x + 1 + WallPadding;
const float blocky1 = y + 1 + WallPadding;
if (dx > 0.0f && safemap(x - 1, y) == 0)
{
const float t = (blockx0 - player.x) / dx;
if (t >= 0.0f && t < 1.0f)
{
const float ay = player.y + t * dy;
if (ay >= blocky0 && ay <= blocky1)
{
dx = blockx0 - player.x;
}
}
}
if (dx < 0.0f && safemap(x + 1, y) == 0)
{
const float t = (blockx1 - player.x) / dx;
if (t >= 0.0f && t < 1.0f)
{
const float ay = player.y + t * dy;
if (ay >= blocky0 && ay <= blocky1)
{
dx = blockx1 - player.x;
}
}
}
if (dy > 0.0f && safemap(x, y - 1) == 0)
{
const float t = (blocky0 - player.y) / dy;
if (t >= 0.0f && t < 1.0f)
{
const float ax = player.x + t * dx;
if (ax >= blockx0 && ax <= blockx1)
{
dy = blocky0 - player.y;
}
}
}
if (dy < 0.0f && safemap(x, y + 1) == 0)
{
const float t = (blocky1 - player.y) / dy;
if (t >= 0.0f && t < 1.0f)
{
const float ax = player.x + t * dx;
if (ax >= blockx0 && ax <= blockx1)
{
dy = blocky1 - player.y;
}
}
}
}
}
}
player.x += dx;
player.y += dy;
}
void renderview(ScreenPixel* pixels)
{
#ifdef MULTITHREAD
#pragma omp parallel for
#endif
for (int x = 0; x < ScreenWidth; ++x)
{
const float sx = (FilmWidth * 0.5f) - (x + 0.5f) * (FilmWidth / ScreenWidth);
const float a = player.a + atan2(sx, FocalLength);
const float MaxDist = 1000.0f;
float hx, hy;
float u;
if (cast_ray(
player.x, player.y,
player.x + MaxDist * cos(a),
player.y + MaxDist * sin(a),
&hx, &hy,
&u))
{
const float dx = hx - player.x;
const float dy = hy - player.y;
const float d = sqrt(dx * dx + dy * dy) * cos(a - player.a);
const float h = FocalLength * WallHeight / d;
const int wallheight = static_cast<int>(h / FilmHeight * ScreenHeight);
const float rcpwallheight = 1.0f / wallheight;
const int wallstarty = ScreenHeight / 2 - wallheight / 2;
const int wallendy = ScreenHeight / 2 + wallheight / 2;
const int starty = max(wallstarty, 0);
const int endy = min(wallendy, ScreenHeight);
// Sky.
for (int y = 0; y < starty; ++y)
{
#ifdef FLIP
pixels[x * ScreenHeight + y] = rgb(155, 226, 255);
#else
pixels[y * ScreenWidth + x] = rgb(155, 226, 255);
#endif
}
// Floor.
for (int y = endy; y < ScreenHeight; ++y)
{
#ifdef FLIP
pixels[x * ScreenHeight + y] = rgb(53, 37, 26);
#else
pixels[y * ScreenWidth + x] = rgb(53, 37, 26);
#endif
}
// Walls.
if (texture)
{
const float shade = 1.0f - min(d / 8.0f, 1.0f);
if (bilinear)
{
const float su = u * textures[0].w - 0.5f;
const int iu = static_cast<int>(floor(su));
const float fu0 = su - iu;
const float fu1 = 1.0f - fu0;
myassert(fu0 >= 0.0f && fu0 < 1.0f);
for (int y = starty; y < endy; ++y)
{
const float v = (y - wallstarty + 0.5f) * rcpwallheight;
const float sv = v * textures[0].h - 0.5f;
const int iv = static_cast<int>(floor(sv));
const float fv0 = sv - iv;
const float fv1 = 1.0f - fv0;
myassert(fv0 >= 0.0f && fv0 < 1.0f);
const Texture* tex = &textures[0];
const uint8_t* data00 = lookup_texture(tex, iu + 0, iv + 0);
const uint8_t* data10 = lookup_texture(tex, iu + 1, iv + 0);
const uint8_t* data01 = lookup_texture(tex, iu + 0, iv + 1);
const uint8_t* data11 = lookup_texture(tex, iu + 1, iv + 1);
float r = (data00[0] * fu1 + data10[0] * fu0) * fv1 + (data01[0] * fu1 + data11[0] * fu0) * fv0;
float g = (data00[1] * fu1 + data10[1] * fu0) * fv1 + (data01[1] * fu1 + data11[1] * fu0) * fv0;
float b = (data00[2] * fu1 + data10[2] * fu0) * fv1 + (data01[2] * fu1 + data11[2] * fu0) * fv0;
r *= shade;
g *= shade;
b *= shade;
#ifdef FLIP
pixels[x * ScreenHeight + y] =
#else
pixels[y * ScreenWidth + x] =
#endif
rgb(
static_cast<uint8_t>(r),
static_cast<uint8_t>(g),
static_cast<uint8_t>(b));
}
}
else
{
const float su = u * textures[0].w;
const int iu = static_cast<int>(su);
myassert(iu >= 0 && iu < textures[0].w);
const float fu = su - iu;
myassert(fu >= 0.0f && fu < 1.0f);
for (int y = starty; y < endy; ++y)
{
const float v = (y - wallstarty + 0.5f) * rcpwallheight;
const float sv = v * textures[0].h;
const int iv = static_cast<int>(sv);
myassert(iv >= 0 && iv < textures[0].h);
const float fv = sv - iv;
myassert(fv >= 0.0f && fv < 1.0f);
const Texture* tex = &textures[0];
const uint8_t* data = &tex->data[(iv * tex->w + iu) * 4];
#ifdef FLIP
pixels[x * ScreenHeight + y] =
#else
pixels[y * ScreenWidth + x] =
#endif
rgb(
static_cast<uint8_t>(data[0] * shade),
static_cast<uint8_t>(data[1] * shade),
static_cast<uint8_t>(data[2] * shade));
}
}
}
else
{
for (int y = starty; y < endy; ++y)
{
#ifdef FLIP
pixels[x * ScreenHeight + y] = rgb(80, 80, 80);
#else
pixels[y * ScreenWidth + x] = rgb(80, 80, 80);
#endif
}
}
}
}
}
void rendermap(ScreenPixel* pixels)
{
const int CellSize = 40;
for (int y = 0; y < MapH * CellSize; ++y)
{
for (int x = 0; x < MapW * CellSize; ++x)
{
ScreenPixel color;
const float wx = static_cast<float>(x) / CellSize;
const float wy = static_cast<float>(y) / CellSize;
const int ix = static_cast<int>(wx);
const int iy = static_cast<int>(wy);
const uint8_t cell = map(ix, iy);
color = cell == 0 ? rgb(150, 150, 150) : rgb(220, 220, 220);
const float fx = wx - ix;
const float fy = wy - iy;
if (cell == 0)
{
if ((fx <= WallPadding && safemap(ix - 1, iy) != 0) ||
(fx >= 1.0f - WallPadding && safemap(ix + 1, iy) != 0) ||
(fy <= WallPadding && safemap(ix, iy - 1) != 0) ||
(fy >= 1.0f - WallPadding && safemap(ix, iy + 1) != 0) ||
(fx <= WallPadding && fy <= WallPadding && safemap(ix - 1, iy - 1) != 0) ||
(fx >= 1.0f - WallPadding && fy <= WallPadding && safemap(ix + 1, iy - 1) != 0) ||
(fx <= WallPadding && fy >= 1.0f - WallPadding && safemap(ix - 1, iy + 1)) ||
(fx >= 1.0f - WallPadding && fy >= 1.0f - WallPadding && safemap(ix + 1, iy + 1) != 0))
color = rgb(150, 180, 150);
}
const float dpx = wx - player.x;
const float dpy = wy - player.y;
if (sqrt(dpx * dpx + dpy * dpy) <= 0.05f)
color = rgb(255, 0, 0);
setpix(pixels, x, MapH * CellSize - 1 - y, color);
}
}
}
void render(ScreenPixel* pixels)
{
renderview(pixels);
if (minimap)
rendermap(pixels);
}
extern "C" int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
return 1;
}
for (int i = 0, e = SDL_GetNumRenderDrivers(); i < e; ++i)
{
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
fprintf(stderr, "Driver #%d:\n", i);
fprintf(stderr, " Name : %s\n", info.name);
fprintf(stderr, " Software fallback : %s\n", (info.flags & SDL_RENDERER_SOFTWARE) != 0 ? "yes" : "no");
fprintf(stderr, " Hardware accelerated : %s\n", (info.flags & SDL_RENDERER_ACCELERATED) != 0 ? "yes" : "no");
fprintf(stderr, " VSync : %s\n", (info.flags & SDL_RENDERER_PRESENTVSYNC) != 0 ? "yes" : "no");
fprintf(stderr, " Render-to-texture : %s\n", (info.flags & SDL_RENDERER_TARGETTEXTURE) != 0 ? "yes" : "no");
fprintf(stderr, "\n");
}
SDL_Window* window =
SDL_CreateWindow(
"Wolfie",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
static_cast<int>(ScreenWidth),
static_cast<int>(ScreenHeight),
SDL_WINDOW_SHOWN);
if (window == nullptr)
{
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_Renderer* renderer =
SDL_CreateRenderer(
window,
-1,
#ifdef VSYNC
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
#else
SDL_RENDERER_ACCELERATED
#endif
);
if (renderer == nullptr)
{
SDL_DestroyWindow(window);
fprintf(stderr, "SDL_CreateRenderer Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_Texture* screen_texture =
SDL_CreateTexture(
renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
#ifdef FLIP
static_cast<int>(ScreenHeight),
static_cast<int>(ScreenWidth)
#else
static_cast<int>(ScreenWidth),
static_cast<int>(ScreenHeight)
#endif
);
ScreenPixel* pixels = new ScreenPixel[ScreenWidth * ScreenHeight];
init();
bool quit = false;
while (!quit)
{
const uint32_t starttime = SDL_GetTicks();
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
quit = true;
break;
case SDL_KEYDOWN:
switch (e.key.keysym.sym)
{
case SDLK_ESCAPE:
quit = true;
break;
case SDLK_b:
bilinear = !bilinear;
break;
case SDLK_r:
player.reset();
break;
case SDLK_t:
texture = !texture;
break;
case SDLK_TAB:
minimap = !minimap;
break;
}
default:
break;
}
}
update();
render(pixels);
#ifdef FLIP
SDL_UpdateTexture(screen_texture, nullptr, pixels, ScreenHeight * sizeof(ScreenPixel));
#else
SDL_UpdateTexture(screen_texture, nullptr, pixels, ScreenWidth * sizeof(ScreenPixel));
#endif
SDL_RenderClear(renderer);
#ifdef FLIP
SDL_Rect dstrect;
dstrect.x = (ScreenWidth - ScreenHeight) / 2 - 1;
dstrect.y = (ScreenHeight - ScreenWidth) / 2;
dstrect.w = ScreenHeight;
dstrect.h = ScreenWidth;
SDL_RenderCopyEx(renderer, screen_texture, nullptr, &dstrect, 90, nullptr, SDL_FLIP_VERTICAL);
#else
SDL_RenderCopy(renderer, screen_texture, nullptr, nullptr);
#endif
SDL_RenderPresent(renderer);
const uint32_t elapsed = SDL_GetTicks() - starttime;
const uint32_t fps = 1000 / elapsed;
fprintf(stderr, "fps: %u\n", fps);
}
done();
SDL_Quit();
return 0;
}