2022-11-12 15:57:34 +00:00
|
|
|
#include "../../YoggieEngine/src/EntryPoint.h"
|
2023-01-14 20:44:48 +00:00
|
|
|
#include <mini/ini.h>
|
2022-11-05 19:50:35 +00:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
2023-01-14 16:27:37 +00:00
|
|
|
#include "AssetManagement/SceneSerializer.h"
|
2022-11-10 20:51:11 +00:00
|
|
|
#include "AssetManagement/AssetManager.h"
|
2023-01-14 16:27:37 +00:00
|
|
|
#include "Views/Viewport.h"
|
|
|
|
#include "PropertyPanels/SceneExplorer.h"
|
|
|
|
#include "AssetManagement/AssetFinder.h"
|
|
|
|
#include "MainMenuBar.h"
|
|
|
|
#include "PropertyPanels/Inspector.h"
|
|
|
|
#include "Project/ProjectInfo.h"
|
|
|
|
#include "Runtime/RuntimeControls.h"
|
2023-05-06 19:06:49 +00:00
|
|
|
#include "AssetManagement/uuid.h"
|
2023-01-14 16:27:37 +00:00
|
|
|
#include "Project/Settings.h"
|
|
|
|
#include "Console.h"
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
using namespace YoggieEngine;
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
class Editor : public Application {
|
|
|
|
public:
|
2023-01-14 21:11:09 +00:00
|
|
|
Editor() : Application("Editor"){}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
void Run() override
|
|
|
|
{
|
2023-01-14 20:44:48 +00:00
|
|
|
std::string path = (std::filesystem::current_path()).string();
|
|
|
|
project.setProjectDirectory(path);
|
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
LoadLastOrEmptyProject();
|
|
|
|
|
2023-05-06 19:06:49 +00:00
|
|
|
//ProjectInfo projectInfo(project);
|
2023-01-14 16:27:37 +00:00
|
|
|
RuntimeControls rc = RuntimeControls();
|
2023-05-06 19:06:49 +00:00
|
|
|
|
|
|
|
Viewport sceneview = Viewport(scene);
|
2023-01-14 16:27:37 +00:00
|
|
|
SceneExplorer explorer(Selected, scene);
|
2023-01-14 21:11:09 +00:00
|
|
|
Inspector inspector = Inspector(Selected);
|
2023-05-06 19:06:49 +00:00
|
|
|
//Settings settings = Settings();
|
|
|
|
AssetFinder assetsView = AssetFinder();
|
|
|
|
//Console console = Console();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-05-06 19:06:49 +00:00
|
|
|
|
2023-01-14 21:11:09 +00:00
|
|
|
Selected = YoggieEngine::Entity((entt::entity) -1, &scene);
|
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
double previous = glfwGetTime();
|
|
|
|
double lag = 0.0;
|
2023-01-31 17:41:46 +00:00
|
|
|
while (!appWindow->WindowShouldClose())
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
2023-01-14 16:27:37 +00:00
|
|
|
PollEvents();
|
|
|
|
double now = glfwGetTime();
|
|
|
|
double elapsed = now - previous ;
|
|
|
|
previous = now;
|
|
|
|
lag += elapsed;
|
2023-01-31 17:41:46 +00:00
|
|
|
|
|
|
|
scene.Update();
|
2023-01-14 16:27:37 +00:00
|
|
|
|
2023-05-03 14:40:43 +00:00
|
|
|
if (sceneview.isFocused) {
|
|
|
|
UpdateSceneCamera(sceneview);
|
2023-01-04 18:01:58 +00:00
|
|
|
|
2023-05-03 14:40:43 +00:00
|
|
|
std::cout << "Scene view in Focus!\r" ;
|
2023-01-04 18:01:58 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
GuiBegin();
|
2023-05-03 14:40:43 +00:00
|
|
|
|
|
|
|
|
2023-01-14 20:44:48 +00:00
|
|
|
{
|
|
|
|
MainMenuBar menuBar = MainMenuBar();
|
2022-11-10 20:51:11 +00:00
|
|
|
|
2023-01-14 20:44:48 +00:00
|
|
|
// Show a menu bar
|
|
|
|
menuBar.ApplicationMenu(project);
|
|
|
|
menuBar.SceneMenu(project, scene);
|
|
|
|
menuBar.SelectMenu();
|
|
|
|
menuBar.WindowMenu();
|
|
|
|
menuBar.DebugMenu();
|
|
|
|
menuBar.Help();
|
|
|
|
|
|
|
|
}
|
2023-01-14 16:27:37 +00:00
|
|
|
|
2023-05-06 19:06:49 +00:00
|
|
|
//projectInfo.Update();
|
2023-01-14 16:27:37 +00:00
|
|
|
sceneview.Update();
|
|
|
|
rc.Update();
|
|
|
|
explorer.Update();
|
2023-05-06 19:06:49 +00:00
|
|
|
//settings.Update();
|
2023-01-14 16:27:37 +00:00
|
|
|
inspector.Update();
|
2023-05-06 19:06:49 +00:00
|
|
|
//console.Update();
|
2023-01-14 16:27:37 +00:00
|
|
|
|
2023-05-06 19:06:49 +00:00
|
|
|
assetsView.Draw();
|
|
|
|
|
|
|
|
//ImGui::ShowDemoWindow();
|
|
|
|
//ImGui::ShowMetricsWindow();
|
2022-12-24 01:10:29 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
|
|
|
|
GuiEnd();
|
|
|
|
SwapBuffers();
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|
2022-12-24 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
void LoadLastOrEmptyProject() {
|
|
|
|
// Check if there is a last known loaded project and
|
|
|
|
// load that one .
|
2022-12-24 01:10:29 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
// Otherwise load no project..
|
|
|
|
// OR
|
|
|
|
// Load an empty project.
|
2023-01-14 20:44:48 +00:00
|
|
|
mINI::INIStructure ini;
|
2022-12-24 01:10:29 +00:00
|
|
|
|
2023-01-14 20:44:48 +00:00
|
|
|
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
|
|
|
{
|
|
|
|
mINI::INIFile file("build\\Debug\\Editor.ini");
|
|
|
|
file.read(ini);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spdlog::debug("Could not find an `Editor.ini` file.");
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-01-14 20:44:48 +00:00
|
|
|
if (ini["editor"]["openlastproject"] == "TRUE")
|
|
|
|
{
|
|
|
|
Project::LoadProject(ini["cache"]["project"], project);
|
|
|
|
LoadScene(ini["cache"]["scene"], scene);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2023-01-14 20:44:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spdlog::debug("Starting without a project. Please create one.");
|
|
|
|
}
|
2023-01-14 16:27:37 +00:00
|
|
|
}
|
2022-12-24 01:10:29 +00:00
|
|
|
|
2023-01-14 16:27:37 +00:00
|
|
|
private:
|
2023-01-04 14:57:08 +00:00
|
|
|
bool SimulatePhysics = true;
|
2023-01-14 21:11:09 +00:00
|
|
|
YoggieEngine::Entity Selected;
|
2023-01-14 16:27:37 +00:00
|
|
|
Project project;
|
|
|
|
Scene scene;
|
2022-12-21 18:11:27 +00:00
|
|
|
|
2023-05-03 14:40:43 +00:00
|
|
|
|
|
|
|
void UpdateSceneCamera(Viewport& sceneview) {
|
|
|
|
const float movement_speed = 0.1f;
|
|
|
|
static float lastX = 400, lastY = 300;
|
|
|
|
const float sensitivity = 0.1;
|
|
|
|
static bool firstMouse = true;
|
|
|
|
|
|
|
|
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
|
|
|
|
|
|
|
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
|
|
auto newX = getCursorPosX(appWindow);
|
|
|
|
auto newY = getCursorPosY(appWindow);
|
|
|
|
|
|
|
|
if (firstMouse)
|
|
|
|
{
|
|
|
|
lastX = newX;
|
|
|
|
lastY = newY;
|
|
|
|
firstMouse = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float xoffset = newX - lastX;
|
|
|
|
float yoffset = newY - lastY;
|
|
|
|
|
|
|
|
lastX = newX;
|
|
|
|
lastY = newY;
|
|
|
|
|
|
|
|
xoffset *= sensitivity;
|
|
|
|
yoffset *= sensitivity;
|
|
|
|
|
|
|
|
sceneview.cam.yaw += xoffset;
|
|
|
|
sceneview.cam.pitch += yoffset;
|
|
|
|
|
|
|
|
if (sceneview.cam.pitch > 89.0f)
|
|
|
|
sceneview.cam.pitch = 89.0f;
|
|
|
|
if (sceneview.cam.pitch < -89.0f)
|
|
|
|
sceneview.cam.pitch = -89.0f;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (firstMouse == false)
|
|
|
|
{
|
|
|
|
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
|
|
firstMouse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for Camara movement input here!
|
|
|
|
if (keyIsPressed(YOGGIE_KEY_W)) {
|
|
|
|
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
|
|
|
std::cout << "Pressed W !" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyIsPressed(YOGGIE_KEY_A))
|
|
|
|
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
|
|
|
|
|
|
|
if (keyIsPressed(YOGGIE_KEY_S))
|
|
|
|
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
|
|
|
|
|
|
|
if (keyIsPressed(YOGGIE_KEY_D))
|
|
|
|
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
|
|
|
}
|
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
};
|
|
|
|
|
2022-11-12 15:57:34 +00:00
|
|
|
YoggieEngine::Application* CreateApplication() {
|
|
|
|
|
|
|
|
return new Editor();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
}
|
2023-05-03 14:40:43 +00:00
|
|
|
|
|
|
|
|