-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanager.cpp
More file actions
89 lines (79 loc) · 2.06 KB
/
manager.cpp
File metadata and controls
89 lines (79 loc) · 2.06 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
#include "manager.hpp"
#include "opengl.hpp"
#include "renderer.hpp"
Manager manager;
Manager::Manager()
{
fprintf(stderr, "CEO hired (project development time +3 months, morale -2\n");
debug = true;
running = true;
gameTime = 0.0f;
std::shared_ptr<Opengl> tempPtr1(new Opengl());
openglPtr = tempPtr1;
if (!openglPtr->start())
stop();
std::shared_ptr<RoomManager> tempPtr2(new RoomManager());
roomManagerPtr = tempPtr2;
if (!roomManagerPtr->init())
stop();
inputManagerPtr = std::shared_ptr<Inputmanager>(new Inputmanager());
inputReaderPtr = std::shared_ptr<InputReader>(new InputReader());
}
Manager::~Manager()
{
fprintf(stderr, "CEO fired, project finished\n");
}
void Manager::stop()
{
running = false;
}
int Manager::run()
{
float time = openglPtr->giveTicks();
nextFPS = time + 1000;
fprintf(stderr, "Entering main loop\n");
while (running)
{
time = 0.001f * openglPtr->giveTicks();
float delta = time-gameTime;
if (delta > 0.5)
delta = 0;
gameTime = time;
if (openglPtr->giveTicks() > nextFPS && debug == true)
{
// fprintf(stderr, "FPS: %f\n", (1.0f/delta));
nextFPS += 1000;
}
inputManagerPtr->resetKeys();
inputManagerPtr->checkInput();
inputReaderPtr->readInput();
renderer.render();
if (openglPtr->getLimitFPS() == 1)
{
// Limit the FPS
while (delta < 1.0f/openglPtr->getFPS())
{
inputManagerPtr->checkInput();
delta = (0.001f*openglPtr->giveTicks())-time;
}
}
}
fprintf(stderr, "Manager exiting naturally\n");
return 0;
}
void Manager::setParams(int input_argc, char** input_argv)
{
argc = input_argc;
argv = input_argv;
}
void Manager::getEnter()
{
#ifdef WIN32
fprintf(stderr, "Press return to continue\n");
std::cin.get();
#else
fprintf(stderr, "Press any key + enter to continue");
std::string dummystr;
std::cin >> dummystr;
#endif
}