-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathMainApp.cpp
73 lines (61 loc) · 2.26 KB
/
MainApp.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
#include "MainApp.hpp"
#include <Files/Files.hpp>
#include <Inputs/Inputs.hpp>
#include <Graphics/Graphics.hpp>
#include <Resources/Resources.hpp>
#include <Scenes/Scenes.hpp>
#include "MainRenderer.hpp"
int main(int argc, char **argv) {
using namespace test;
// Creates the engine.
auto engine = std::make_unique<Engine>(argv[0]);
engine->SetApp(std::make_unique<MainApp>());
// Runs the game loop.
auto exitCode = engine->Run();
engine = nullptr;
// Pauses the console.
std::cout << "Press enter to continue...";
std::cin.get();
return exitCode;
}
namespace test {
MainApp::MainApp() :
App("Tutorial4", {1, 0, 0}) {
// Registers file search paths.
Log::Out("Working Directory: ", std::filesystem::current_path(), '\n');
Files::Get()->AddSearchPath("Resources/Engine");
// Loads a input scheme for this app.
Inputs::Get()->AddScheme("Default", std::make_unique<InputScheme>("InputSchemes/DefaultPBR.json"), true);
Inputs::Get()->GetButton("fullscreen")->OnButton().connect(this, [this](InputAction action, bitmask::bitmask<InputMod> mods) {
if (action == InputAction::Press)
Windows::Get()->GetWindow(0)->SetFullscreen(!Windows::Get()->GetWindow(0)->IsFullscreen());
});
Inputs::Get()->GetButton("screenshot")->OnButton().connect(this, [this](InputAction action, bitmask::bitmask<InputMod> mods) {
if (action == InputAction::Press) {
Resources::Get()->GetThreadPool().Enqueue([]() {
Graphics::Get()->CaptureScreenshot(Time::GetDateTime("Screenshots/%Y%m%d%H%M%S.png"));
});
}
});
Inputs::Get()->GetButton("exit")->OnButton().connect(this, [this](InputAction action, bitmask::bitmask<InputMod> mods) {
if (action == InputAction::Press)
Engine::Get()->RequestClose();
});
}
MainApp::~MainApp() {
Files::Get()->ClearSearchPath();
Graphics::Get()->SetRenderer(nullptr);
Scenes::Get()->SetScene(nullptr);
}
void MainApp::Start() {
// Sets values to modules.
Windows::Get()->GetWindow(0)->SetTitle("Tutorial4");
Windows::Get()->GetWindow(0)->SetIcons({
"Icons/Icon-16.png", "Icons/Icon-24.png", "Icons/Icon-32.png", "Icons/Icon-48.png", "Icons/Icon-64.png",
"Icons/Icon-96.png", "Icons/Icon-128.png", "Icons/Icon-192.png", "Icons/Icon-256.png"
});
Graphics::Get()->SetRenderer(std::make_unique<MainRenderer>());
}
void MainApp::Update() {
}
}