-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (76 loc) · 2.02 KB
/
main.cpp
File metadata and controls
95 lines (76 loc) · 2.02 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
/*
Text Tracer - A real-time raytracer
TODO:
Recursive Ray-kD Tree intersection
Fix AABB slice issue, backface rendering & cleanup
Material class for storing colour, lighting factors, reflectiveness etc
Universal portal transport for all ray types (shadow esp.)
PhysicsObject
Reflectiveness
Separate 2D geometry into it's own base class (or use PlaneObject)
Sphere orientation calculation (L should be camera-oriented, not viewport-oriented)?
Preprocessor definitions:
LOW_RES
Disabled: Run in full resolution
Enabled: Run in half resolution
REALTIME
Disabled: Update/Draw one frame, then quit
Enabled: Update/Draw according to FPS constants until user quits
DISABLE_LIGHTING:
Disabled: All objects will be rendered at full brightness
Enabled: All objects will be smoothly lit with hard shadows
*/
#define REALTIME
#include <ctime>
#include "TextTracer.h"
const int RENDER_FPS = 60;
const int UPDATE_FPS = 60;
int worldClock = 0;
int prevRenderTicks = 0;
int prevUpdateTicks = 0;
bool redraw = true;
bool update = true;
bool quit = false;
int main()
{
// Initialization
TextTracer textTracer;
#ifdef REALTIME
while(!quit)
{
#endif
// Cap update to tick rate
worldClock = clock();
int updateTicks = worldClock % (CLOCKS_PER_SEC / UPDATE_FPS);
if(updateTicks == 0 && prevUpdateTicks != 0)
{
update = true;
}
prevUpdateTicks = updateTicks;
if(update)
{
// Quit
if(textTracer.IsKeyDown(0x1B)) // Esc
{
quit = true;
}
textTracer.Update(worldClock);
update = false;
}
// Cap rendering to frame rate
int renderTicks = worldClock % (CLOCKS_PER_SEC / RENDER_FPS);
if(renderTicks == 0 && prevRenderTicks != 0)
{
redraw = true;
}
prevRenderTicks = renderTicks;
if(redraw)
{
textTracer.Draw();
redraw = false;
}
#ifdef REALTIME
}
#endif
return 0;
}