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
#include "Deer/Memory.h"
#ifdef DEER_RENDER
#include "DeerRender/Events/ApplicationEvent.h"
#include "DeerRender/Events/Event.h"
#include "DeerRender/Window.h"
#endif
namespace Deer {
class ImGuiLayer;
namespace Core {
@ -25,62 +19,14 @@ namespace Deer {
float m_time;
};
namespace Application_tmp {
namespace Application {
using Function = void(*)();
using EventFunction = void(*)(Event&);
extern bool running;
void run();
void setTickCallback(Function);
#ifdef DEER_RENDER
void initWindow();
void shutdownWindow();
void setRenderCallback(Function);
void setEventCallback(EventFunction);
Window& getWindow();
#endif
void shutdown();
}
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

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();
}
}

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

@ -1,140 +1,70 @@
#include "Deer/Application.h"
#include "Deer/Log.h"
#include <functional>
#include <thread>
#ifdef DEER_RENDER
#include "DeerRender/Render/RenderCommand.h"
#include "DeerRender/Render/Render.h"
#include "DeerRender/Render/RenderUtils.h"
#include "DeerRender/Render/Render.h"
#include "DeerRender/ImGui/ImGuiLayer.h"
#include "imgui.h"
#include <functional>
#endif
namespace Deer {
namespace Core {
int argc;
char **argv;
}
namespace Application {
// Implemented in DeerRender/Application
void runRender(float deltaTime);
void resolveEvents();
Application* Application::s_application;
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;
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
auto previousTime = std::chrono::high_resolution_clock::now();
double accumulatedUpdateTime = 0.0;
double accumulatedRenderTime = 0.0;
int res = onPreInit();
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;
void setTickCallback(Function _tick) {
tickCallback = _tick;
}
while (m_running) {
// Time handling
auto currentTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> deltaTime = currentTime - previousTime;
previousTime = currentTime;
void run() {
running = true;
accumulatedUpdateTime += deltaTime.count();
accumulatedRenderTime += deltaTime.count();
auto previousTime = std::chrono::high_resolution_clock::now();
double accumulatedUpdateTime = 0.0;
double accumulatedRenderTime = 0.0;
// Fixed Update loop (60 FPS)
while (accumulatedUpdateTime >= targetUpdateTime) {
Timestep timestep = (float)targetUpdateTime;
onUpdate(timestep);
accumulatedUpdateTime -= targetUpdateTime;
}
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) {
RenderCommand::setClearColor({ 0.2f, 0.2f, 0.3f, 1.0f });
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;
m_window->onRender();
}
m_window->resolveEvents();
if (accumulatedRenderTime >= targetRenderTime) {
runRender((float)targetRenderTime);
accumulatedRenderTime -= targetRenderTime;
}
resolveEvents();
#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 Application::onEventCallback(Event& e) {
onEvent(e);
m_imGuiLayer->onEvent(e);
EventDispatcher dispatcher(e);
dispatcher.dispatch<WindowCloseEvent>(std::bind(&Application::onWindowClose, this, std::placeholders::_1));
void shutdown() {
running = false;
}
}
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/Application.h"
namespace Deer {
#ifdef DEER_RENDER
bool Input::isKeyPressed(unsigned int key) {
return Application::s_application->m_window->getKeyPressed(key);
return Application::getWindow().getKeyPressed(key);
}
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) {
return Application::s_application->m_window->getMousePos(x, y);
return Application::getWindow().getMousePos(x, y);
}
#else
bool Input::isKeyPressed(unsigned int key) {

View File

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

View File

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

View File

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

View File

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

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

@ -1,239 +1,127 @@
#include "DeerStudio.h"
#include <functional>
#include "Deer/DataStore.h"
#include "Deer/Scene.h"
#include "Deer/ScriptEngine.h"
#include "Deer/Voxel.h"
#include "Deer/Path.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/Fonts.h"
#include "DeerStudio/Editor/GamePanel.h"
#include "DeerStudio/Editor/Icons.h"
#include "DeerStudio/Editor/Terrain/TerrainEditor.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
int main(int, char**) {
Deer::DeerStudio::main();
}
namespace Deer {
int DeerStudioApplication::onPreInit() {
Path projectPath = Application::m_window->folderDialog(nullptr);
if (projectPath.empty()) return 1;
namespace DeerStudio {
void main() {
DataStore::rootPath = projectPath;
DataStore::loadVoxelsData();
DataStore::loadVoxelsAspect();
return 0;
}
Log::init();
Application::initWindow();
Path projectPath = Application::getWindow().folderDialog(nullptr);
if (projectPath.empty()) return;
DataStore::rootPath = projectPath;
int DeerStudioApplication::onInit() {
DataStore::generateTextureAtlas();
DataStore::loadVoxelsShaders();
EditorEngine::initialize();
DataStore::loadVoxelsData();
DataStore::loadVoxelsAspect();
DataStore::generateTextureAtlas();
DataStore::loadVoxelsShaders();
Icons::setupIcons();
EditorEngine::initialize();
// IMGUI STYLE
ImGuiIO& io = ImGui::GetIO();
Icons::setupIcons();
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();
SetupImGuiStyle();
initializeFonts();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
Application::setTickCallback(DeerStudio::onUpdate);
Application::setRenderCallback(DeerStudio::onRender);
Application::setEventCallback(DeerStudio::onEvent);
SetupImGuiStyle();
Application::run();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
auto m_gamePanel = Ref<GamePanel>(new GamePanel());
Panels.push_back(m_gamePanel);
EditorEngine::deinitialize();
return 0;
}
void DeerStudioApplication::onShutdown() {
if (Scene::getExecutingState())
Scene::endExecution();
Panels.clear();
EditorEngine::deinitialize();
}
void DeerStudioApplication::onRender(Timestep delta) {
for (auto Panel : Panels) {
Panel->onRender(delta);
Application::shutdownWindow();
Log::shutdown();
}
int windowWidth = Application::s_application->m_window->getWitdth();
int windowHeight = Application::s_application->m_window->getHeight();
}
void onUpdate() {
if (VoxelWorld::isInitialized())
VoxelWorld::bakeNextChunk();
}
void DeerStudioApplication::onUpdate(Timestep delta) {
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;
void DeerStudioApplication::onEvent(Event& e) {
for (auto& Panel : Panels) Panel->onEventCallback(e);
ImGuiWindowFlags window_flags =
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
viewport_onEvent(e);
}
{
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;
}
void DeerStudioApplication::onImGUI() {
static bool opt_fullscreen = true;
static bool opt_padding = false;
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
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);
ImGuiWindowFlags window_flags =
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
ImGuiID dockspace_id = ImGui::GetID("DockSpace Demo");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
{
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;
if (ImGui::BeginMenuBar()) {
// MENUBAR
ImGui::EndMenuBar();
}
TerrainEditor::onImGui();
viewport_onImGui();
EditorEngine::render();
Scene::gizmoRenderer.refresh();
ImGui::End();
}
void onEvent(Event& e) {
viewport_onEvent(e);
EventDispatcher ed(e);
ed.dispatch<WindowCloseEvent>(onWindowCloseEvent);
}
bool onWindowCloseEvent(WindowCloseEvent&) {
Application::shutdown();
return true;
}
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 DeerStudioApplication::drawMenuBar() {
if (ImGui::BeginMenu("Project")) {
if (ImGui::MenuItem("New project")) {
}
if (ImGui::MenuItem("Open project")) {
}
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")) {
if (ImGui::MenuItem("New scene")) {
// TODO
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

View File

@ -1,13 +1,17 @@
#pragma once
#include "DeerRender/Events/Event.h"
#include "DeerRender/Events/ApplicationEvent.h"
int main(int, char**);
namespace Deer {
namespace DeerStudio {
void onRender(Timestep delta);
void onUpdate(Timestep delta);
void onRender();
void onUpdate();
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 y = UI::getAvailableSizeY();
if (x < 10 || y < 10)
return;
frameBuffer.resize(x, y);
frameBuffer.clearRGBA(0, 0, 0, 255);