-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cpp
More file actions
156 lines (127 loc) · 3.87 KB
/
Engine.cpp
File metadata and controls
156 lines (127 loc) · 3.87 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
#include "Engine.h"
// frame rate calculation based on www.gametutorials.com - see license.txt
#if 0
int Engine::screenWidthRT = 2560; // needs to be divisable by RENDERTILE_SIZE
int Engine::screenHeightRT = 1440; // needs to be divisable by RENDERTILE_SIZE
int Engine::screenWidthGL = 2560;
int Engine::screenHeightGL = 1440;
#else
#if 0
int Engine::screenWidthRT = 1920;
int Engine::screenHeightRT = 1080;
int Engine::screenWidthGL = 1920;
int Engine::screenHeightGL = 1080;
#else
#if 1
int Engine::screenWidthRT = 1280;
int Engine::screenHeightRT = 720;
int Engine::screenWidthGL = 1280;
int Engine::screenHeightGL = 720;
#else
#if 0
int Engine::screenWidthRT = 240;
int Engine::screenHeightRT = 240;
int Engine::screenWidthGL = 240;
int Engine::screenHeightGL = 240;
#else
int Engine::screenWidthRT = 512;
int Engine::screenHeightRT = 256;
int Engine::screenWidthGL = 512;
int Engine::screenHeightGL = 256;
#endif
#endif
#endif
#endif
int Engine::RENDERLINE_SIZE = 4;
// keys & mouse
bool Engine::upKey = false;
bool Engine::downKey = false;
bool Engine::leftKey = false;
bool Engine::rightKey = false;
bool Engine::leftButton = false;
bool Engine::rightButton = false;
bool Engine::jumpKey = false;
bool Engine::crouchKey = false;
bool Engine::done = false;
float Engine::currentTime = 0.0f;
int Engine::numAccelerometerHits = 0;
int Engine::previousNumAccelerometerHits = 0;
bool Engine::accelerometerChangedThisFrame = false;
#if 1
bool Engine::server = true;
bool Engine::dedicated = true;
#else
bool Engine::server = false;
bool Engine::dedicated = false;
#endif
TCPsocket Engine::sd = NULL;
TCPsocket Engine::csd = NULL;
IPaddress Engine::ip;
IPaddress* Engine::remoteIP = NULL;
int Engine::serverPort = 2000;
MultiThreadMethods Engine::methodToMultiThread = MultiThreadMethods::TASKDISPATCH;
bool Engine::debugLatency = false;
int Engine::debugNumCameraChanges = 0;
float Engine::framesPerSecond = 1.0f;
int Engine::numFramesRendered = 0;
int Engine::embreeIntersect = 8;
float Engine::cg_fov = 65.0f;
float Engine::frameInterval = 0.3f;
float Engine::frameTime = 0.0f;
float Engine::lastTime = 0.0f;
int Engine::rectLeft = -1;
int Engine::rectTop = -1;
int Engine::rectRight = -1;
int Engine::rectBottom = -1;
int Engine::rectSizeX = -1;
int Engine::rectSizeY = -1;
bool Engine::rectMode = false;
CVector2i Engine::relativeMouseMotion;
void Engine::init(int argc, char *argv[]){
cout << "Engine initialized." << endl;
if (screenHeightRT % RENDERLINE_SIZE != 0){
cout << "Invalid screenWidthRT or screenHeightRT for RENDERTILE_SIZE" << endl;
exit(1);
}
parseArgv(argc, argv);
}
void Engine::calculateFrameRate(){
float backupCurrentTime = currentTime;
float totalCurrentTime = SDL_GetTicks() * 0.001f;
float localCurrentTime = totalCurrentTime;
currentTime = localCurrentTime;
float backupFrameInterval = frameInterval;
frameInterval = currentTime - frameTime;
frameTime = currentTime;
framesPerSecond++;
if(currentTime - lastTime > 1.0f){
lastTime = currentTime;
framesPerSecond = 0;
}
if(server){
frameInterval = backupFrameInterval;
currentTime = backupCurrentTime;
}
}
void Engine::parseArgv(int argc, char *argv[]){
for(int i = 1; i < argc; i++){
//
// port
//
if(!strcmp(argv[i], "-port")){
serverPort = atoi(argv[i + 1]);
cout << "Overwriting port to: " << serverPort << endl;
}
}
}
bool Engine::isPointInsideRect(int x, int y){
if (x < rectLeft)
return false;
if (x > rectRight)
return false;
if (y < rectBottom)
return false;
if (y > rectTop)
return false;
return true;
}