blob: ac5b319031b80346d1ebf1f2d36dcb6eacae1aae (
plain)
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
|
#include "App.hpp"
#include <utility>
void App::Init() {
if (mInitialized) return;
mInitialized = true;
mCurrentWorld = std::make_unique<GameWorld>();
auto& worldRoot = mCurrentWorld->GetRoot();
constexpr int kPlayerCount = 2;
for (int i = 0; i < kPlayerCount; ++i) {
auto player = new Player(mCurrentWorld.get(), i);
worldRoot.AddChild(player);
mPlayers.push_back(player);
}
mCurrentWorld->Awaken();
mEditor = std::make_unique<EditorInstance>(this, mCurrentWorld.get());
}
void App::Shutdown() {
if (!mInitialized) return;
mInitialized = false;
mEditor = nullptr;
mCurrentWorld->Resleep();
mCurrentWorld = nullptr;
mPlayers.clear();
}
void App::Show() {
if (mEditorShown) {
mEditor->Show();
}
}
void App::Update() {
}
void App::Draw() {
mCurrentWorld->Draw();
}
void App::HandleMouse(int button, int action) {
}
void App::HandleMouseMotion(double xOff, double yOff) {
}
void App::HandleKey(GLFWkeyboard* keyboard, int key, int action) {
if (!mKeyCaptureCallbacks.empty()) {
auto& callback = mKeyCaptureCallbacks.front();
bool remove = callback(key, action);
if (remove) {
mKeyCaptureCallbacks.pop_front();
}
}
switch (key) {
case GLFW_KEY_F3: {
if (action == GLFW_PRESS) {
mEditorShown = !mEditorShown;
}
return;
}
case GLFW_KEY_F11: {
// TODO fullscreen
return;
}
}
for (auto& player : mPlayers) {
for (auto playerKeyboard : player->boundKeyboards) {
if (playerKeyboard == keyboard) {
player->HandleKeyInput(key, action);
}
}
}
}
void App::PushKeyCaptureCallback(KeyCaptureCallback callback) {
mKeyCaptureCallbacks.push_back(std::move(callback));
}
|