Refactor, removed Application singelton and working Deer Studio

This commit is contained in:
Chewico 2025-05-22 01:04:30 +02:00
parent bea9a56354
commit 7f452d7e25
15 changed files with 333 additions and 626 deletions

View File

@ -1,12 +1,6 @@
#pragma once #pragma once
#include "Deer/Memory.h" #include "Deer/Memory.h"
#ifdef DEER_RENDER
#include "DeerRender/Events/ApplicationEvent.h"
#include "DeerRender/Events/Event.h"
#include "DeerRender/Window.h"
#endif
namespace Deer { namespace Deer {
class ImGuiLayer; class ImGuiLayer;
namespace Core { namespace Core {
@ -25,62 +19,14 @@ namespace Deer {
float m_time; float m_time;
}; };
namespace Application_tmp { namespace Application {
using Function = void(*)(); using Function = void(*)();
using EventFunction = void(*)(Event&);
extern bool running; extern bool running;
void run(); void run();
void setTickCallback(Function); void setTickCallback(Function);
#ifdef DEER_RENDER void shutdown();
void initWindow();
void shutdownWindow();
void setRenderCallback(Function);
void setEventCallback(EventFunction);
Window& getWindow();
#endif
} }
class Application {
public:
Application();
~Application();
static Application* s_application;
int run();
virtual int onInit() { return 0; }
virtual int onPreInit() { return 0; }
virtual void onShutdown() {}
virtual void onUpdate(Timestep delta) {}
private:
bool m_running;
float m_lastFrameTime = 0.0f;
#ifdef DEER_RENDER
public:
Application(const WindowProps& props = WindowProps());
virtual void onRender(Timestep delta) {}
virtual void onImGUI() {}
virtual void onEvent(Event& event) {}
Scope<Window> m_window;
private:
Scope<ImGuiLayer> m_imGuiLayer;
const WindowProps m_windowProps;
virtual void onEventCallback(Event& e);
void initializeWindow();
bool onWindowClose(WindowCloseEvent& e);
#endif
};
} // namespace Deer } // namespace Deer

View File

@ -0,0 +1,21 @@
#include "Deer/Application.h"
#ifdef DEER_RENDER
#include "DeerRender/Events/ApplicationEvent.h"
#include "DeerRender/Events/Event.h"
#include "DeerRender/Window.h"
#endif
namespace Deer {
namespace Application {
using EventFunction = void(*)(Event&);
void initWindow();
void shutdownWindow();
void setRenderCallback(Function);
void setEventCallback(EventFunction);
Window& getWindow();
}
}

122
Deer/src/Deer/Core/Application.cpp Executable file → Normal file
View File

@ -1,78 +1,40 @@
#include "Deer/Application.h" #include "Deer/Application.h"
#include "Deer/Log.h" #include <functional>
#include <thread>
#ifdef DEER_RENDER #ifdef DEER_RENDER
#include "DeerRender/Render/RenderCommand.h" #include "DeerRender/Render/RenderCommand.h"
#include "DeerRender/Render/Render.h"
#include "DeerRender/Render/RenderUtils.h" #include "DeerRender/Render/RenderUtils.h"
#include "DeerRender/Render/Render.h"
#include "DeerRender/ImGui/ImGuiLayer.h" #include "DeerRender/ImGui/ImGuiLayer.h"
#include "imgui.h" #include "imgui.h"
#include <functional>
#endif #endif
namespace Deer { namespace Deer {
namespace Core { namespace Application {
int argc; // Implemented in DeerRender/Application
char **argv; void runRender(float deltaTime);
} void resolveEvents();
Application* Application::s_application; Function tickCallback;
bool running;
Application::Application() : m_running(false) {
#ifdef DEER_RENDER
m_window = Scope<Window>(Window::create(m_windowProps));
m_imGuiLayer = MakeScope<ImGuiLayer>();
#endif
}
Application::~Application() { }
#ifdef DEER_RENDER
Application::Application(const WindowProps& props)
: m_running(false), m_windowProps(props) {
m_window = Scope<Window>(Window::create(m_windowProps));
m_imGuiLayer = MakeScope<ImGuiLayer>();
}
void Application::initializeWindow() {
m_window->initWindow();
m_window->setEventCallback(std::bind(&Application::onEventCallback, this, std::placeholders::_1));
}
#endif
int Application::run() {
s_application = this;
m_running = true;
const double targetUpdateTime = 1.0 / 60.0; // Fixed 60 FPS update const double targetUpdateTime = 1.0 / 60.0; // Fixed 60 FPS update
double targetRenderTime = 1.0 / 160.0; // User-defined render FPS double targetRenderTime = 1.0 / 160.0; // User-defined render FPS
void setTickCallback(Function _tick) {
tickCallback = _tick;
}
void run() {
running = true;
auto previousTime = std::chrono::high_resolution_clock::now(); auto previousTime = std::chrono::high_resolution_clock::now();
double accumulatedUpdateTime = 0.0; double accumulatedUpdateTime = 0.0;
double accumulatedRenderTime = 0.0; double accumulatedRenderTime = 0.0;
int res = onPreInit(); while (running) {
if (res != 0)
return res;
#ifdef DEER_RENDER
initializeWindow();
m_imGuiLayer->onAttach();
RenderUtils::initializeRenderUtils();
RenderCommand::init();
#endif
res = onInit();
if (res != 0){
#ifdef DEER_RENDER
m_imGuiLayer->onDetach();
#endif
return res;
}
while (m_running) {
// Time handling // Time handling
auto currentTime = std::chrono::high_resolution_clock::now(); auto currentTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> deltaTime = currentTime - previousTime; std::chrono::duration<double> deltaTime = currentTime - previousTime;
@ -84,57 +46,25 @@ namespace Deer {
// Fixed Update loop (60 FPS) // Fixed Update loop (60 FPS)
while (accumulatedUpdateTime >= targetUpdateTime) { while (accumulatedUpdateTime >= targetUpdateTime) {
Timestep timestep = (float)targetUpdateTime; Timestep timestep = (float)targetUpdateTime;
onUpdate(timestep);
accumulatedUpdateTime -= targetUpdateTime; accumulatedUpdateTime -= targetUpdateTime;
}
if (tickCallback)
tickCallback();
}
#ifdef DEER_RENDER #ifdef DEER_RENDER
// Render loop (User-defined FPS)
if (accumulatedRenderTime >= targetRenderTime) { if (accumulatedRenderTime >= targetRenderTime) {
RenderCommand::setClearColor({ 0.2f, 0.2f, 0.3f, 1.0f }); runRender((float)targetRenderTime);
RenderCommand::clear();
Render::initExecution();
onRender(Timestep((float)targetRenderTime));
Render::endExecution();
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = (float)targetRenderTime;
m_imGuiLayer->begin();
onImGUI();
m_imGuiLayer->end();
accumulatedRenderTime -= targetRenderTime; accumulatedRenderTime -= targetRenderTime;
m_window->onRender();
} }
resolveEvents();
m_window->resolveEvents();
#endif #endif
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
#ifdef DEER_RENDER
m_imGuiLayer->onDetach();
#endif
onShutdown();
return 0;
} }
#ifdef DEER_RENDER void shutdown() {
void Application::onEventCallback(Event& e) { running = false;
onEvent(e);
m_imGuiLayer->onEvent(e);
EventDispatcher dispatcher(e);
dispatcher.dispatch<WindowCloseEvent>(std::bind(&Application::onWindowClose, this, std::placeholders::_1));
} }
bool Application::onWindowClose(WindowCloseEvent& e)
{
m_running = false;
return true;
} }
#endif
} }

View File

@ -1,118 +0,0 @@
#include "Deer/Application.h"
#include <functional>
#include <thread>
#ifdef DEER_RENDER
#include "DeerRender/Render/RenderCommand.h"
#include "DeerRender/Render/RenderUtils.h"
#include "DeerRender/Render/Render.h"
#include "DeerRender/ImGui/ImGuiLayer.h"
#include "imgui.h"
#endif
namespace Deer {
namespace Application_tmp {
Function tickCallback;
bool running;
const double targetUpdateTime = 1.0 / 60.0; // Fixed 60 FPS update
double targetRenderTime = 1.0 / 160.0; // User-defined render FPS
#ifdef DEER_RENDER
Function renderCallback;
EventFunction eventCallback;
Scope<Window> window;
Scope<ImGuiLayer> imGuiLayer;
#endif
void setTickCallback(Function _tick) {
tickCallback = _tick;
}
#ifdef DEER_RENDER
void setRenderCallback(Function _render) {
renderCallback = _render;
}
void setEventCallback(EventFunction _event) {
eventCallback = _event;
}
Window& getWindow() {
return *window;
}
void initWindow() {
window = Scope<Window>(Window::create());
imGuiLayer = MakeScope<ImGuiLayer>();
window->initWindow();
imGuiLayer->onAttach();
if (eventCallback)
window->setEventCallback(eventCallback);
RenderUtils::initializeRenderUtils();
RenderCommand::init();
}
void shutdownWindow() {
imGuiLayer->onDetach();
window.reset();
imGuiLayer.reset();
}
#endif
void run() {
running = true;
auto previousTime = std::chrono::high_resolution_clock::now();
double accumulatedUpdateTime = 0.0;
double accumulatedRenderTime = 0.0;
while (running) {
// Time handling
auto currentTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> deltaTime = currentTime - previousTime;
previousTime = currentTime;
accumulatedUpdateTime += deltaTime.count();
accumulatedRenderTime += deltaTime.count();
// Fixed Update loop (60 FPS)
while (accumulatedUpdateTime >= targetUpdateTime) {
Timestep timestep = (float)targetUpdateTime;
accumulatedUpdateTime -= targetUpdateTime;
if (tickCallback)
tickCallback();
}
#ifdef DEER_RENDER
// Render loop (User-defined FPS)
if (accumulatedRenderTime >= targetRenderTime && tickCallback) {
RenderCommand::setClearColor({ 0.2f, 0.2f, 0.3f, 1.0f });
RenderCommand::clear();
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = (float)targetRenderTime;
imGuiLayer->begin();
tickCallback();
imGuiLayer->end();
accumulatedRenderTime -= targetRenderTime;
}
window->resolveEvents();
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
}
}

View File

@ -0,0 +1,78 @@
#include "DeerRender/Application.h"
#include <functional>
#include <thread>
#include "DeerRender/Render/RenderCommand.h"
#include "DeerRender/Render/RenderUtils.h"
#include "DeerRender/Render/Render.h"
#include "Deer/Log.h"
#include "DeerRender/ImGui/ImGuiLayer.h"
#include "imgui.h"
namespace Deer {
namespace Application {
Function renderCallback;
EventFunction eventCallback;
Scope<Window> window;
Scope<ImGuiLayer> imGuiLayer;
void setRenderCallback(Function _render) {
renderCallback = _render;
}
void setEventCallback(EventFunction _event) {
eventCallback = _event;
window->setEventCallback(eventCallback);
}
Window& getWindow() {
return *window;
}
void initWindow() {
window = Scope<Window>(Window::create());
window->initWindow();
imGuiLayer = MakeScope<ImGuiLayer>();
imGuiLayer->onAttach();
if (eventCallback)
window->setEventCallback(eventCallback);
RenderUtils::initializeRenderUtils();
RenderCommand::init();
}
void resolveEvents() {
window->resolveEvents();
}
void shutdownWindow() {
imGuiLayer->onDetach();
imGuiLayer.reset();
window.reset();
}
void runRender(float deltaTime) {
if (!renderCallback)
return;
RenderCommand::setClearColor({ 0.2f, 0.2f, 0.3f, 1.0f });
RenderCommand::clear();
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = (float)deltaTime;
imGuiLayer->begin();
renderCallback();
imGuiLayer->end();
window->onRender();
}
}
}

View File

@ -1,17 +1,18 @@
#include "DeerRender/Input.h" #include "DeerRender/Input.h"
#include "DeerRender/Application.h"
namespace Deer { namespace Deer {
#ifdef DEER_RENDER #ifdef DEER_RENDER
bool Input::isKeyPressed(unsigned int key) { bool Input::isKeyPressed(unsigned int key) {
return Application::s_application->m_window->getKeyPressed(key); return Application::getWindow().getKeyPressed(key);
} }
bool Input::isMouseButtonPressed(int button) { bool Input::isMouseButtonPressed(int button) {
return Application::s_application->m_window->getMouseButton(button); return Application::getWindow().getMouseButton(button);
} }
void Input::getMousePos(float& x, float& y) { void Input::getMousePos(float& x, float& y) {
return Application::s_application->m_window->getMousePos(x, y); return Application::getWindow().getMousePos(x, y);
} }
#else #else
bool Input::isKeyPressed(unsigned int key) { bool Input::isKeyPressed(unsigned int key) {

View File

@ -1,6 +1,6 @@
#include "DeerRender/ImGui/ImGuiLayer.h" #include "DeerRender/ImGui/ImGuiLayer.h"
#include "Deer/Application.h" #include "DeerRender/Application.h"
#include "Deer/Log.h" #include "Deer/Log.h"
#include "DeerRender/Events/Event.h" #include "DeerRender/Events/Event.h"
#include "DeerRender/Input.h" #include "DeerRender/Input.h"
@ -30,10 +30,11 @@ namespace Deer {
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
ImGui_ImplOpenGL3_Init("#version 410"); ImGui_ImplOpenGL3_Init("#version 410");
Application::s_application->m_window->initImGUI(); Application::getWindow().initImGUI();
io.DisplaySize = io.DisplaySize =
ImVec2(Application::s_application->m_window->getWitdth(), ImVec2(Application::getWindow().getWitdth(),
Application::s_application->m_window->getHeight()); Application::getWindow().getHeight());
} }
void ImGuiLayer::onDetach() {} void ImGuiLayer::onDetach() {}

View File

@ -124,7 +124,7 @@ namespace Deer {
LinuxWindow::LinuxWindow(const WindowProps& props) LinuxWindow::LinuxWindow(const WindowProps& props)
: m_windowProps(props) { : m_windowProps(props) {
gtk_init(&Core::argc, &Core::argv); gtk_init(0, nullptr);
m_data.height = props.height; m_data.height = props.height;
m_data.width = props.width; m_data.width = props.width;

View File

@ -1,6 +1,6 @@
#include "OpenGLFrameBuffer.h" #include "OpenGLFrameBuffer.h"
#include "Deer/Log.h" #include "Deer/Log.h"
#include "Deer/Application.h" #include "DeerRender/Application.h"
#include "glad/glad.h" #include "glad/glad.h"
@ -30,8 +30,8 @@ namespace Deer {
} }
void OpenGLFrameBuffer::unbind() { void OpenGLFrameBuffer::unbind() {
unsigned int width = Application::s_application->m_window->getWitdth(); unsigned int width = Application::getWindow().getWitdth();
unsigned int height = Application::s_application->m_window->getHeight(); unsigned int height = Application::getWindow().getHeight();
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }

View File

@ -1,7 +1,7 @@
#include "OpenGLRenderAPI.h" #include "OpenGLRenderAPI.h"
#include "Plattform/OpenGL/OpenGLBuffer.h" #include "Plattform/OpenGL/OpenGLBuffer.h"
#include "DeerRender/Render/VertexArray.h" #include "DeerRender/Render/VertexArray.h"
#include "Deer/Application.h" #include "DeerRender/Application.h"
#include "glad/glad.h" #include "glad/glad.h"
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
@ -61,8 +61,8 @@ namespace Deer {
} }
void OpenGLRenderAPI::unbindFrameBuffer() { void OpenGLRenderAPI::unbindFrameBuffer() {
unsigned int width = Application::s_application->m_window->getWitdth(); unsigned int width = Application::getWindow().getWitdth();
unsigned int height = Application::s_application->m_window->getHeight(); unsigned int height = Application::getWindow().getHeight();
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }

61
DeerStudio/imgui.ini Normal file
View File

@ -0,0 +1,61 @@
[Window][DockSpace Demo]
Pos=0,0
Size=1280,720
Collapsed=0
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Terrain Editor]
Pos=947,24
Size=333,454
Collapsed=0
DockId=0x00000006,1
[Window][Viewport]
Pos=294,24
Size=651,454
Collapsed=0
DockId=0x00000005,1
[Window][ViewportPannel]
Pos=294,24
Size=651,454
Collapsed=0
DockId=0x00000005,0
[Window][ShaderExplorer]
Pos=0,480
Size=1280,240
Collapsed=0
DockId=0x00000004,1
[Window][TreePannel]
Pos=0,24
Size=292,454
Collapsed=0
DockId=0x00000001,0
[Window][MeshExplorer]
Pos=0,480
Size=1280,240
Collapsed=0
DockId=0x00000004,0
[Window][PropertiesPannel]
Pos=947,24
Size=333,454
Collapsed=0
DockId=0x00000006,0
[Docking][Data]
DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y Selected=0x34A4C10F
DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,454 Split=X
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=292,696 Selected=0xE45B9F93
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=986,696 Split=X Selected=0x34A4C10F
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=651,454 CentralNode=1 Selected=0x34A4C10F
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=333,454 Selected=0xA35A27E3
DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,240 Selected=0xD962995A

212
DeerStudio/src/DeerStudio/DeerStudio.cpp Executable file → Normal file
View File

@ -1,36 +1,42 @@
#include "DeerStudio.h" #include "DeerStudio.h"
#include <functional> #include "Deer/Path.h"
#include "Deer/DataStore.h"
#include "Deer/Scene.h"
#include "Deer/ScriptEngine.h"
#include "Deer/Voxel.h"
#include "Deer/VoxelWorld.h" #include "Deer/VoxelWorld.h"
#include "DeerRender/Mesh.h" #include "Deer/DataStore.h"
#include "Deer/Voxel.h"
#include "Deer/Scene.h"
#include "DeerRender/Application.h"
#include "DeerRender/GizmoRenderer.h"
#include "DeerStudio/EditorEngine.h" #include "DeerStudio/EditorEngine.h"
#include "DeerStudio/Fonts.h"
#include "DeerStudio/Editor/GamePanel.h"
#include "DeerStudio/Editor/Icons.h"
#include "DeerStudio/Editor/Terrain/TerrainEditor.h"
#include "DeerStudio/Editor/Viewport.h" #include "DeerStudio/Editor/Viewport.h"
#include "Style.h" #include "DeerStudio/Editor/Terrain/TerrainEditor.h"
void extract_angelScript(); // TMP
#include "DeerStudio/Editor/Icons.h"
#include "DeerStudio/Fonts.h"
#include "DeerStudio/Style.h"
// TMP
namespace Deer { int main(int, char**) {
int DeerStudioApplication::onPreInit() { Deer::DeerStudio::main();
Path projectPath = Application::m_window->folderDialog(nullptr);
if (projectPath.empty()) return 1;
DataStore::rootPath = projectPath;
DataStore::loadVoxelsData();
DataStore::loadVoxelsAspect();
return 0;
} }
int DeerStudioApplication::onInit() { namespace Deer {
namespace DeerStudio {
void main() {
Log::init();
Application::initWindow();
Path projectPath = Application::getWindow().folderDialog(nullptr);
if (projectPath.empty()) return;
DataStore::rootPath = projectPath;
DataStore::loadVoxelsData();
DataStore::loadVoxelsAspect();
DataStore::generateTextureAtlas(); DataStore::generateTextureAtlas();
DataStore::loadVoxelsShaders(); DataStore::loadVoxelsShaders();
@ -38,57 +44,29 @@ namespace Deer {
Icons::setupIcons(); Icons::setupIcons();
// IMGUI STYLE
ImGuiIO& io = ImGui::GetIO();
std::string fLoc = (DataStore::rootPath / "imgui.ini").generic_string();
char* filenameFLoc = new char[fLoc.size() + 1]();
strcpy(filenameFLoc, fLoc.c_str());
io.IniFilename = filenameFLoc;
initializeFonts(); initializeFonts();
SetupImGuiStyle(); SetupImGuiStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
auto m_gamePanel = Ref<GamePanel>(new GamePanel());
Panels.push_back(m_gamePanel);
return 0; Application::setTickCallback(DeerStudio::onUpdate);
} Application::setRenderCallback(DeerStudio::onRender);
Application::setEventCallback(DeerStudio::onEvent);
void DeerStudioApplication::onShutdown() { Application::run();
if (Scene::getExecutingState())
Scene::endExecution();
Panels.clear();
EditorEngine::deinitialize(); EditorEngine::deinitialize();
Application::shutdownWindow();
Log::shutdown();
} }
void DeerStudioApplication::onRender(Timestep delta) { void onUpdate() {
for (auto Panel : Panels) {
Panel->onRender(delta);
}
int windowWidth = Application::s_application->m_window->getWitdth();
int windowHeight = Application::s_application->m_window->getHeight();
}
void DeerStudioApplication::onUpdate(Timestep delta) {
if (Scene::getExecutingState())
Scene::tickExecution();
if (VoxelWorld::isInitialized()) if (VoxelWorld::isInitialized())
VoxelWorld::bakeNextChunk(); VoxelWorld::bakeNextChunk();
} }
void DeerStudioApplication::onEvent(Event& e) { void onRender() {
for (auto& Panel : Panels) Panel->onEventCallback(e);
viewport_onEvent(e);
}
void DeerStudioApplication::onImGUI() {
static bool opt_fullscreen = true; static bool opt_fullscreen = true;
static bool opt_padding = false; static bool opt_padding = false;
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
@ -121,119 +99,29 @@ namespace Deer {
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {
drawMenuBar(); // MENUBAR
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
for (auto Panel : Panels) {
Panel->onImGui();
}
// ---- PanelS -----
TerrainEditor::onImGui(); TerrainEditor::onImGui();
viewport_onImGui(); viewport_onImGui();
EditorEngine::render(); EditorEngine::render();
// ---- PanelS -----
Scene::gizmoRenderer.refresh(); Scene::gizmoRenderer.refresh();
ImGui::End(); ImGui::End();
} }
void DeerStudioApplication::drawMenuBar() { void onEvent(Event& e) {
if (ImGui::BeginMenu("Project")) { viewport_onEvent(e);
if (ImGui::MenuItem("New project")) {
} EventDispatcher ed(e);
if (ImGui::MenuItem("Open project")) {
} ed.dispatch<WindowCloseEvent>(onWindowCloseEvent);
if (ImGui::MenuItem("Save project")) {
}
if (ImGui::MenuItem("Save project as...")) {
}
ImGui::Separator();
if (ImGui::MenuItem("Create binaries")) {
}
if (ImGui::MenuItem("Export project")) {
}
if (ImGui::MenuItem("Project settings")) {
}
ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Scene")) { bool onWindowCloseEvent(WindowCloseEvent&) {
if (ImGui::MenuItem("New scene")) { Application::shutdown();
// TODO return true;
Scene::clear();
DataStore::exportScene("new_scene");
}
// if (Project::m_sceneSerializer->getCurrentScenePath() !=
// "_NO_INITIALIZED_" && ImGui::MenuItem("Save scene")) {
// Project::m_sceneSerializer->serialize(Project::m_sceneSerializer->getCurrentScenePath());
// }
if (ImGui::MenuItem("Save scene")) {
DataStore::exportScene("saved_scene");
}
if (ImGui::MenuItem("Save scene as...")) {
// TODO
}
if (ImGui::MenuItem("Load scene")) {
// Scene::swap(DataStore::loadScene("new_scene"));
// DataStore::exportScene(Project::m_scene,
// "new_scene");
}
if (ImGui::MenuItem("Scene settings")) {
// TODO
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Runtime")) {
if (ImGui::MenuItem("Start")) {
// TODO
}
if (ImGui::MenuItem("End")) {
// TODO
}
if (ImGui::MenuItem("Restart")) {
// TODO
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Voxel")) {
if (ImGui::MenuItem("Voxel Panel")) {
// TODO
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Interface")) {
if (ImGui::MenuItem("Reload interface")) {
EditorEngine::initialize();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Scripts")) {
if (ImGui::MenuItem("Reload scripts") &&
!Scene::getExecutingState()) {
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
if (ImGui::MenuItem("Documentation")) {
// TODO
}
if (ImGui::MenuItem("Report bug")) {
// TODO
}
if (ImGui::MenuItem("About")) {
// TODO
}
ImGui::EndMenu();
} }
} }
void DeerStudioApplication::onChangeScene() { ActiveEntity::clear(); }
} // namespace Deer } // namespace Deer

View File

@ -1,13 +1,17 @@
#pragma once #pragma once
#include "DeerRender/Events/Event.h" #include "DeerRender/Events/Event.h"
#include "DeerRender/Events/ApplicationEvent.h"
int main(int, char**); int main(int, char**);
namespace Deer { namespace Deer {
namespace DeerStudio { namespace DeerStudio {
void onRender(Timestep delta); void onRender();
void onUpdate(Timestep delta); void onUpdate();
void onEvent(Event& e); void onEvent(Event& e);
void main();
bool onWindowCloseEvent(WindowCloseEvent&);
} }
} }

View File

@ -1,109 +0,0 @@
#include "DeerStudio.h"
#include "DeerStudio/EditorEngine.h"
// TMP
#include "DeerStudio/Editor/Icons.h"
#include "DeerStudio/Fonts.h"
#include "DeerStudio/Style.h"
// TMP
#include "Deer/Application.h"
#include "Deer/Path.h"
#include "Deer/DataStore.h"
#include "Deer/Voxel.h"
int main(int, char**) {
Deer::Path projectPath = Deer::Application_tmp::getWindow().folderDialog(nullptr);
if (projectPath.empty()) return 0;
Deer::DataStore::rootPath = projectPath;
Deer::DataStore::loadVoxelsData();
Deer::DataStore::loadVoxelsAspect();
Deer::Application_tmp::initWindow();
Deer::DataStore::generateTextureAtlas();
Deer::DataStore::loadVoxelsShaders();
Deer::EditorEngine::initialize();
Deer::Icons::setupIcons();
Deer::initializeFonts();
SetupImGuiStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
Deer::Application_tmp::run();
Deer::EditorEngine::deinitialize();
}
namespace Deer {
namespace DeerStudio {
void onUpdate() {
if (Scene::getExecutingState())
Scene::tickExecution();
if (VoxelWorld::isInitialized())
VoxelWorld::bakeNextChunk();
}
void onRender() {
static bool opt_fullscreen = true;
static bool opt_padding = false;
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
ImGuiWindowFlags window_flags =
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->WorkPos);
ImGui::SetNextWindowSize(viewport->WorkSize);
ImGui::SetNextWindowViewport(viewport->ID);
window_flags |= ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoNavFocus;
window_flags |= ImGuiWindowFlags_NoBackground;
}
static bool p_open = true;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::Begin("DockSpace Demo", &p_open, window_flags);
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
ImGuiID dockspace_id = ImGui::GetID("DockSpace Demo");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
if (ImGui::BeginMenuBar()) {
drawMenuBar();
ImGui::EndMenuBar();
}
for (auto Panel : Panels) {
Panel->onImGui();
}
// ---- PanelS -----
TerrainEditor::onImGui();
viewport_onImGui();
EditorEngine::render();
// ---- PanelS -----
Scene::gizmoRenderer.refresh();
ImGui::End();
}
void onEvent(Event& e) {
viewport_onEvent(e);
}
}
} // namespace Deer

View File

@ -13,6 +13,10 @@ class ViewportPannel : DockPanel {
int x = UI::getAvailableSizeX(); int x = UI::getAvailableSizeX();
int y = UI::getAvailableSizeY(); int y = UI::getAvailableSizeY();
if (x < 10 || y < 10)
return;
frameBuffer.resize(x, y); frameBuffer.resize(x, y);
frameBuffer.clearRGBA(0, 0, 0, 255); frameBuffer.clearRGBA(0, 0, 0, 255);