aboutsummaryrefslogtreecommitdiff
path: root/source/App.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-25 20:22:07 -0700
committerrtk0c <[email protected]>2022-04-25 20:22:07 -0700
commit855da86feae1a5cc14dc2d486ccf115f484dbc2e (patch)
tree8284c6a6bdfb1a919eb1a22f466f4180a329c7f3 /source/App.cpp
parentd78a55de5003dbb040f1d1c369409e63a2c806d8 (diff)
Changeset: 16 Initial work on rendering sprites to screen
Diffstat (limited to 'source/App.cpp')
-rw-r--r--source/App.cpp103
1 files changed, 78 insertions, 25 deletions
diff --git a/source/App.cpp b/source/App.cpp
index ac5b319..dc38342 100644
--- a/source/App.cpp
+++ b/source/App.cpp
@@ -2,44 +2,102 @@
#include <utility>
-void App::Init() {
- if (mInitialized) return;
- mInitialized = true;
-
- mCurrentWorld = std::make_unique<GameWorld>();
- auto& worldRoot = mCurrentWorld->GetRoot();
+App::App() {
+ auto& worldRoot = mWorld.GetRoot();
constexpr int kPlayerCount = 2;
for (int i = 0; i < kPlayerCount; ++i) {
- auto player = new Player(mCurrentWorld.get(), i);
+ auto player = new Player(&mWorld, i);
worldRoot.AddChild(player);
mPlayers.push_back(player);
+ };
+
+#if defined(BRUSSEL_DEV_ENV)
+ SetGameRunning(false);
+ SetEditorVisible(true);
+#else
+ SetGameRunning(true);
+#endif
+
+ // TODO this renders nothing, fix
+ mGameCamera.Move(glm::vec3(0, 0, 1));
+ mGameCamera.LookAt(glm::vec3(0, 0, 0));
+ mGameCamera.SetHasPerspective(false);
+ mEditorCamera.Move(glm::vec3(0, 0, 1));
+ mEditorCamera.LookAt(glm::vec3(0, 0, 0));
+ mGameCamera.SetHasPerspective(false);
+}
+
+App::~App() {
+}
+
+bool App::IsGameRunning() const {
+ return mGameRunning;
+}
+
+void App::SetGameRunning(bool running) {
+ if (mGameRunning != running) {
+ mGameRunning = running;
+ if (running) {
+ mWorld.Awaken();
+ } else {
+ mWorld.Resleep();
+ }
}
+}
- mCurrentWorld->Awaken();
- mEditor = std::make_unique<EditorInstance>(this, mCurrentWorld.get());
+bool App::IsEditorVisible() const {
+ return mEditorVisible;
}
-void App::Shutdown() {
- if (!mInitialized) return;
- mInitialized = false;
- mEditor = nullptr;
- mCurrentWorld->Resleep();
- mCurrentWorld = nullptr;
- mPlayers.clear();
+void App::SetEditorVisible(bool visible) {
+ if (mEditorVisible != visible) {
+ mEditorVisible = visible;
+ if (visible) {
+ if (mEditor == nullptr) {
+ mEditor = std::make_unique<EditorInstance>(this, &mWorld);
+ }
+ }
+ }
}
void App::Show() {
- if (mEditorShown) {
+ if (mEditorVisible) {
mEditor->Show();
}
}
void App::Update() {
+ if (IsGameRunning()) {
+ mWorld.Update();
+ }
}
-void App::Draw() {
- mCurrentWorld->Draw();
+void App::Draw(float currentTime, float deltaTime) {
+ Camera* camera;
+ if (IsGameRunning()) {
+ camera = &mGameCamera;
+ } else {
+ camera = &mEditorCamera;
+ }
+ mRenderer.BeginFrame(*camera, currentTime, deltaTime);
+
+ PodVector<GameObject*> stack;
+ stack.push_back(&mWorld.GetRoot());
+
+ while (!stack.empty()) {
+ auto obj = stack.back();
+ stack.pop_back();
+
+ for (auto child : obj->GetChildren()) {
+ stack.push_back(child);
+ }
+
+ auto renderObjects = obj->GetRenderObjects();
+ mRenderer.Draw(renderObjects.data(), renderObjects.size());
+ }
+
+ mRenderer.EndFrame();
}
void App::HandleMouse(int button, int action) {
@@ -60,15 +118,10 @@ void App::HandleKey(GLFWkeyboard* keyboard, int key, int action) {
switch (key) {
case GLFW_KEY_F3: {
if (action == GLFW_PRESS) {
- mEditorShown = !mEditorShown;
+ SetEditorVisible(!IsEditorVisible());
}
return;
}
-
- case GLFW_KEY_F11: {
- // TODO fullscreen
- return;
- }
}
for (auto& player : mPlayers) {