YoggieEngine/Editor/src/app.cpp

170 lines
4.2 KiB
C++
Raw Normal View History

2022-11-12 15:57:34 +00:00
#include "../../YoggieEngine/src/EntryPoint.h"
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
#include <nfd.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "UI/GUIRenderer.h"
#include "UI/Widgets.h"
2022-11-10 20:51:11 +00:00
#include "Project/Project.h"
#include "SceneSerializer.h"
2022-11-10 20:51:11 +00:00
#include "AssetManagement/AssetManager.h"
#include "UI/MainMenuBar.h"
const unsigned int MS_PER_UPDATE = 2;
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
class Editor : public Application {
public:
Editor() : Application("Editor") {}
void Run() override
{
auto NativeEditorWindow = NativeWindow(1200, 700);
//auto renderer = Renderer();
auto GuiRenderer = GUIRenderer(NativeEditorWindow);
Selected = (entt::entity)-1;
CreateTestProject(CurrentProject, ActiveScene);
ActiveScene.Start();
double previous = glfwGetTime();
double lag = 0.0;
while (!NativeEditorWindow.WindowShouldClose())
{
double current = glfwGetTime();
double elapsed = current - previous;
previous = current;
lag += elapsed;
NativeEditorWindow.Poll();
while (lag >= MS_PER_UPDATE)
{
ActiveScene.Update();
lag -= MS_PER_UPDATE;
}
// renderer.Render(framebuffer, ActiveScene);
GuiRenderer.Begin();
RenderGUI();
GuiRenderer.End();
NativeEditorWindow.SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
}
ActiveScene.Stop();
}
void RenderGUI() {
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
// Show a menu bar
{
MainMenuBar menuBar= MainMenuBar();
menuBar.ApplicationMenu(CurrentProject);
menuBar.SceneMenu(CurrentProject, ActiveScene);
}
{
ProjectInfo projectInfo(*(CurrentProject.get()));
}
{
Viewport sceneview = Viewport(ActiveScene);
}
{
SceneExplorer explorer(Selected, ActiveScene);
}
2022-11-10 20:51:11 +00:00
{
Inspector inspector = Inspector();
if (ActiveScene.getReg().valid(Selected)) {
Entity SelectedEntity = Entity(Selected, &ActiveScene);
inspector.AddComponentDropDown(SelectedEntity);
inspector.ShowComponents(SelectedEntity);
2022-11-10 20:51:11 +00:00
}
}
{
Settings();
}
{
AssetFinder assetsView = AssetFinder();
}
{
Console console = Console();
console.Show();
}
ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow();
}
private:
std::unique_ptr<Project> CurrentProject;
Scene ActiveScene;
entt::entity Selected;
};
2022-11-12 15:57:34 +00:00
YoggieEngine::Application* CreateApplication() {
return new Editor();
}
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene ) {
project = std::make_unique<Project>();
std::string path = (std::filesystem::current_path()).string();
project.get()->setProjectDirectory(path);
AssetManager::Init();
AssetManager::setAssetPath(project.get()->GetProjectDirectory());
AssetManager::BuildAssetView();
// Create a level and load it as the current level
auto importer = ModelImporter();
// Create a cube
auto model = importer.Import("build/Debug/Models/Cube.obj");
auto cube = scene.AddEntity("cube");
auto& render3DComponent = cube.AddComponent<Render3DComponent>();
render3DComponent.mesh = *(model->renderable->mesh);
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
auto cube2 = scene.AddEntity("Cube1");
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
rendercube2.mesh = *(model->renderable->mesh);
2022-11-12 15:57:34 +00:00
// create an ambient light source
auto AmbientLight = scene.AddEntity("AmbientLight");
auto light = AmbientLight.AddComponent<LightComponent>();
light.Color = glm::vec3(1.0f);
light.Strength = 1.0f;
}