-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.h
90 lines (65 loc) · 1.54 KB
/
simulation.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
/* *
* @project nbodies
* @file simulation.cpp
*
* @author Braden Nicholson
* @date 3/28/21, 4/28/22
*/
#ifndef SIMULATION_H
#define SIMULATION_H
#include "body.h"
#include "tester.h"
#include <utility>
#include <vector>
using std::vector;
struct Settings {
int maxTicks = 0;
bool useParallel = true;
bool useCollisions = true;
bool realtime = true;
int targetFps = 60;
int numThreads = 1;
int maxThreads = 1;
float radius = 1024;
float scale = 1;
float stepSize = 1;
bool showControls = false;
float rotP = 0, rotY = 0;
};
class Simulation {
private:
vector<Body *> bodies;
Graphics *graphics;
Settings *settings = new Settings;
TestManager *testManager;
double tickBegin = 0.0;
float currentStep = 0.0;
float maxRSS = 0.0;
bool running = true;
float fps = 0.0;
float ups = 0.0;
int cycles = 0;
// Core scaling
double underflow{}, overflow{};
void simulate();
void showStats();
void handleEvents();
static float fmap(float value,
float istart,
float istop,
float ostart,
float ostop) {
if (value < istart) return 0;
if (value > istop) return istop / 2;
return ostart +
(ostop - ostart) * ((value - istart) / (istop - istart));
}
public:
Simulation();
Simulation(Settings *s);
void runHeadless();
void run();
void render();
void recalculateCores();
};
#endif // SIMULATION_H