feat: add play / editor mode
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef LIGHTKEEPER_H
|
||||
#define LIGHTKEEPER_H
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <destrum/App.h>
|
||||
@@ -28,6 +29,7 @@ public:
|
||||
|
||||
void onWindowResize(int newWidth, int newHeight) override;
|
||||
void customWindowsMenu() override;
|
||||
void onPlayModeChanged(bool nowPlaying) override;
|
||||
|
||||
private:
|
||||
void setupSkybox();
|
||||
@@ -53,6 +55,7 @@ private:
|
||||
void submitColliderDebugLines();
|
||||
|
||||
Camera camera{glm::vec3(0.f, 0.f, -5.f), glm::vec3(0, 1, 0)};
|
||||
std::optional<Camera> editorCamera;
|
||||
|
||||
std::unique_ptr<CubeMap> skyboxCubemap;
|
||||
MainSceneObjects mainScene{};
|
||||
|
||||
@@ -83,7 +83,7 @@ void LightKeeper::updateViewMode()
|
||||
auto& input = InputManager::GetInstance();
|
||||
FirstPersonController* player = mainScene.playerController;
|
||||
|
||||
if (player != nullptr && input.WasKeyPressed(SDL_SCANCODE_F5))
|
||||
if (isPlaying() && player != nullptr && input.WasKeyPressed(SDL_SCANCODE_F6))
|
||||
{
|
||||
player->SetPossessed(!player->IsPossessed());
|
||||
}
|
||||
@@ -100,13 +100,13 @@ void LightKeeper::updateViewMode()
|
||||
|
||||
bool LightKeeper::isPlayerViewActive() const
|
||||
{
|
||||
return mainScene.playerController != nullptr && mainScene.playerController->IsPossessed();
|
||||
return isPlaying() && mainScene.playerController != nullptr && mainScene.playerController->IsPossessed();
|
||||
}
|
||||
|
||||
CameraComponent* LightKeeper::getSceneCamera() const
|
||||
{
|
||||
const auto& activeScenes = SceneManager::GetInstance().GetActiveScenes();
|
||||
if (useFreeCamera || activeScenes.empty()) {
|
||||
if (!isPlaying() || useFreeCamera || activeScenes.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return activeScenes.front()->GetCurrentCamera();
|
||||
@@ -187,6 +187,23 @@ void LightKeeper::customFixedUpdate(float dt)
|
||||
SceneManager::GetInstance().FixedUpdate(dt);
|
||||
}
|
||||
|
||||
void LightKeeper::onPlayModeChanged(bool nowPlaying)
|
||||
{
|
||||
findPlayer();
|
||||
if (nowPlaying) {
|
||||
// The player view moves the free camera, put it back where the editor left it on Stop
|
||||
editorCamera = camera;
|
||||
if (mainScene.playerController != nullptr) {
|
||||
mainScene.playerController->SetPossessed(true);
|
||||
}
|
||||
} else if (editorCamera) {
|
||||
const float aspectRatio = camera.GetAspectRatio();
|
||||
camera = *editorCamera;
|
||||
camera.setAspectRatio(aspectRatio);
|
||||
editorCamera.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void LightKeeper::onWindowResize(int newWidth, int newHeight)
|
||||
{
|
||||
renderer.resize(gfxDevice, glm::ivec2{newWidth, newHeight});
|
||||
|
||||
@@ -28,6 +28,7 @@ int main(int argc, char* argv[]) {
|
||||
.appName = "Destrum Engine",
|
||||
.windowTitle = "Lightkeeper",
|
||||
.exeDir = exeDir,
|
||||
.startInEditMode = true,
|
||||
});
|
||||
app.run();
|
||||
app.cleanup();
|
||||
|
||||
Reference in New Issue
Block a user