-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (61 loc) · 2.54 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
#include <iostream>
#include <thread>
#include <array>
#include "Vector.h"
#include "Clocks.h"
#include "Entity.h"
#include "RandomizeJob.h"
#include "SimulateMotionJob.h"
#include "RenderJob.h"
#define RUN_ASYNC
int main()
{
std::array<Entity::Position, Entity::numEntities> positions {};
std::array<Entity::Velocity, Entity::numEntities> velocities {};
std::array<Entity::Physics, Entity::numEntities> physics {};
RandomizeJob::Run(positions, velocities, physics);
RenderJob renderJob(velocities);
size_t numFrames = 0;
constexpr float simTimeSeconds = 4.0f;
Clocks::StartAppClock();
while (Clocks::GetTotalTime() < simTimeSeconds)
{
Clocks::Update();
std::array<Entity::Position, Entity::numEntities> lastPositions = positions;
#ifdef RUN_ASYNC
std::thread* renderThread = renderJob.Run(lastPositions);
std::thread* simulateMotionThread = SimulateMotionJob::Run(positions, velocities, physics);
renderThread->join();
simulateMotionThread->join();
#else
std::thread* renderThread = renderJob.Run(lastPositions);
renderThread->join();
std::thread* simulateMotionThread = SimulateMotionJob::Run(positions, velocities, physics);
simulateMotionThread->join();
#endif
delete renderThread;
delete simulateMotionThread;
Clocks::SavePreviousFrameClock();
numFrames++;
}
RenderJob::ShutDownConsole();
if (system("clear") == -1)
{
return 0;
}
const float numFramesFloat = static_cast<float>(numFrames);
const float fps = numFramesFloat / simTimeSeconds;
const float averageFrameTime = (Clocks::GetTotalTime() * 1000.0f) / numFramesFloat;
const float averageSimTime = (Clocks::GetSimTime() * 1000.0f) / numFramesFloat;
const float averageRenderTime = (Clocks::GetRenderTime() * 1000.0f) / numFramesFloat;
const float highestTime = averageSimTime > averageRenderTime ? averageSimTime : averageRenderTime;
const float lowestTime = averageSimTime < averageRenderTime ? averageSimTime : averageRenderTime;
std::cout << "Num frames: " << numFrames << ", Average FPS: " << fps << std::endl;
std::cout << "Average Frame Time: " << averageFrameTime << "ms" << std::endl;
std::cout << "Average Sim Thread Time: " << averageSimTime << "ms" << std::endl;
std::cout << "Average Render Thread Time: " << averageRenderTime << "ms" << std::endl;
#ifdef RUN_ASYNC
std::cout << "Average Waiting Time: " << highestTime - lowestTime << "ms" << std::endl;
#endif
return 0;
}