-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
89 lines (80 loc) · 2.47 KB
/
Application.cpp
File metadata and controls
89 lines (80 loc) · 2.47 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 "Application.h"
#include "Box.h"
#include "Cube.h"
#include "Ball.h"
#include "Sheet.h"
#include "Math.h"
#include <memory>
#include <algorithm>
#include <random>
#include "GDIPlus.h"
#include "imgui/imgui.h"
GDIPlus gdi;
Application::Application() : wnd(SCREEN_W, SCREEN_H, "CorsaEngine") {
class Factory {
private:
Graphics& g;
std::default_random_engine rng{ std::random_device{}() };
std::uniform_real_distribution<float> adist{ 0.0f,PI * 2.0f };
std::uniform_real_distribution<float> ddist{ 0.0f,PI * 0.5f };
std::uniform_real_distribution<float> odist{ 0.0f,PI * 0.08f };
std::uniform_real_distribution<float> rdist{ 6.0f,20.0f };
std::uniform_real_distribution<float> bdist{ 0.4f,3.0f };
std::uniform_int_distribution<int> latdist{ 5,20 };
std::uniform_int_distribution<int> longdist{ 10,40 };
std::uniform_int_distribution<int> typedist{ 0,2 };
public:
Factory(Graphics& g) : g(g) {};
std::unique_ptr<Drawable> operator()() {
switch (typedist(rng)) {
case 0:
return std::make_unique<Box>(
g, rng, adist, ddist,
odist, rdist, bdist
);
case 1:
return std::make_unique<Ball>(
g, rng, adist, ddist,
odist, rdist, longdist, latdist
);
case 2:
return std::make_unique<Sheet>(
g, rng, adist, ddist,
odist, rdist
);
default:
assert(false && "Application.cpp: Wrong drawable type passed into the Factory");
return {};
}
}
};
Factory factory(wnd.accessGraphics());
drawables.reserve(nDrawables); //Fancy c++ vector features
std::generate_n(std::back_inserter(drawables), nDrawables, factory);
wnd.accessGraphics().setProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 0.75f, 0.5f, 40.0f));
}
Application::~Application() {};
void Application::frame() {
wnd.accessGraphics().beginFrame(0.07f, .0f, .12f);
wnd.accessGraphics().setCamera(camera.getMatrix());
for (auto& d : drawables) {
d->update(wnd.keybd.keyDown(VK_SPACE) ? .0f : 0.01f); //Press space to pause
d->draw(wnd.accessGraphics());
}
//Simulation Status - any additional information about the simulation will be displayed here
if (ImGui::Begin("Simulation Status")) {
ImGui::Text("Paused?: %s", wnd.keybd.keyDown(VK_SPACE) ? "PAUSED" : "UNPAUSED");
ImGui::Text("Average FPS: %.1f ", ImGui::GetIO().Framerate);
}
ImGui::End();
camera.spawnControlWindow();
wnd.accessGraphics().endFrame();
}
int Application::start() {
while (true) {
if (const auto ecode = Window::ProcessMessages()) {
return *ecode;
}
frame();
}
}