2024-12-25 21:44:33 +00:00
|
|
|
// src/Engine.cpp
|
|
|
|
|
2024-12-25 23:01:05 +00:00
|
|
|
// Settings
|
|
|
|
|
2024-12-27 23:04:03 +00:00
|
|
|
#define VSync 0
|
2024-12-25 23:01:05 +00:00
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
#include "Engine.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <chrono>
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <GLFW/glfw3.h>
|
2024-12-27 01:34:34 +00:00
|
|
|
#include <string>
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
// Dear ImGui
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_impl_glfw.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
|
|
|
|
|
|
|
#include "Windows/RenderWindow.h"
|
|
|
|
#include "Windows/PerformanceWindow.h"
|
|
|
|
#include "Windows/LoggerWindow.h"
|
2024-12-25 23:35:38 +00:00
|
|
|
#include "Windows/InspectorWindow.h"
|
2024-12-26 03:06:17 +00:00
|
|
|
#include "Windows/SceneWindow.h"
|
2025-01-01 04:31:58 +00:00
|
|
|
#include "Windows/Icons.h"
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
#include "Windows/ProfilerWindow.h"
|
|
|
|
|
2024-12-28 03:43:17 +00:00
|
|
|
// Create an instance
|
|
|
|
|
|
|
|
// In your rendering loop
|
|
|
|
|
2024-12-26 04:00:13 +00:00
|
|
|
#include "Engine/ThemeManager.h"
|
2024-12-27 04:08:50 +00:00
|
|
|
#include "Engine/SceneManager.h"
|
2024-12-27 21:27:05 +00:00
|
|
|
#include "Engine/LuaAPI.h"
|
2024-12-29 02:50:39 +00:00
|
|
|
#include "Engine/Utilitys.h"
|
2025-01-01 07:36:53 +00:00
|
|
|
#include "Engine/InputManager.h"
|
2024-12-29 02:50:39 +00:00
|
|
|
#include "Engine/ScopedTimer.h"
|
|
|
|
#include "Engine/Profiler.h"
|
2025-01-04 00:32:39 +00:00
|
|
|
#include "Engine/Settings.h"
|
2024-12-26 04:00:13 +00:00
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
// #define YAML_CPP_STATIC_DEFINE
|
2024-12-26 03:06:17 +00:00
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
#include "TestModel.h"
|
|
|
|
|
2024-12-25 23:01:05 +00:00
|
|
|
AssetManager g_AssetManager;
|
|
|
|
|
2024-12-25 23:35:38 +00:00
|
|
|
LoggerWindow *g_LoggerWindow;
|
|
|
|
|
2024-12-27 04:20:16 +00:00
|
|
|
SceneManager g_SceneManager;
|
|
|
|
|
2025-01-01 07:36:53 +00:00
|
|
|
InputManager g_InputManager;
|
|
|
|
|
2025-01-04 00:32:39 +00:00
|
|
|
Settings g_SettingsManager;
|
2025-01-01 07:36:53 +00:00
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
std::vector<std::shared_ptr<GameObject>> g_GameObjects;
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
std::shared_ptr<CameraComponent> g_RuntimeCameraObject;
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
int g_GPU_Triangles_drawn_to_screen = 0;
|
2025-01-03 23:14:25 +00:00
|
|
|
int g_GPU_Draw_Calls = 0;
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2025-01-04 00:32:39 +00:00
|
|
|
bool DrawBBBO;
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
GameObject *g_SelectedObject; // Pointer to the currently selected object
|
2024-12-26 00:15:18 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
int m_GameRunning = 0;
|
2024-12-28 18:07:06 +00:00
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
bool MyEngine::Init(int width, int height, const std::string &title)
|
2024-12-25 21:44:33 +00:00
|
|
|
{
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[START] Engine Init");
|
2025-01-04 00:32:39 +00:00
|
|
|
|
|
|
|
g_SettingsManager.S_LineColor = glm::vec4(1.0f, 0.27058823529f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
// 1) Initialize GLFW
|
|
|
|
// ------------------------------------------
|
|
|
|
if (!glfwInit())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "[Engine] Failed to initialize GLFW\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup hints for OpenGL 3.3 Core
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
|
|
// Create window
|
|
|
|
m_Window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
|
|
|
if (!m_Window)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "[Engine] Failed to create GLFW window\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(m_Window);
|
2024-12-25 23:01:05 +00:00
|
|
|
glfwSwapInterval(VSync); // vsync
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
// ------------------------------------------
|
|
|
|
// 2) Initialize GLEW
|
|
|
|
// ------------------------------------------
|
|
|
|
if (glewInit() != GLEW_OK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "[Engine] Failed to initialize GLEW\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------
|
|
|
|
// 3) Initialize ImGui
|
|
|
|
// ------------------------------------------
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
2024-12-27 01:34:34 +00:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2024-12-25 21:44:33 +00:00
|
|
|
(void)io;
|
|
|
|
// Enable docking
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
2025-01-01 04:31:58 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2024-12-31 08:40:23 +00:00
|
|
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
|
2025-01-01 04:31:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Path to your font files
|
|
|
|
const char *regularFontPath = "assets/fonts/Roboto-Medium.ttf"; // Replace with your font file path
|
|
|
|
const char *fontAwesomePath = "assets/fonts/fa-solid-900.ttf"; // Replace with Font Awesome font path
|
|
|
|
|
|
|
|
float fontSize = 16.0f; // Font size for both regular font and icons
|
|
|
|
|
|
|
|
// Load the regular font
|
|
|
|
ImFont *regularFont = io.Fonts->AddFontFromFileTTF(regularFontPath, fontSize);
|
|
|
|
if (!regularFont)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to load regular font: %s\n", regularFontPath);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure Font Awesome
|
|
|
|
ImFontConfig fontAwesomeConfig;
|
|
|
|
fontAwesomeConfig.MergeMode = true; // Merge into the main font
|
|
|
|
fontAwesomeConfig.PixelSnapH = true; // Snap pixels for better alignment
|
|
|
|
fontAwesomeConfig.GlyphOffset.y = 2.0f; // Adjust vertical alignment (tweak this value if needed)
|
|
|
|
|
|
|
|
// Define the glyph range for Font Awesome
|
|
|
|
static const ImWchar fontAwesomeRanges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
|
|
|
|
|
|
|
// Load Font Awesome and merge it into the regular font
|
|
|
|
ImFont *fontAwesomeFont = io.Fonts->AddFontFromFileTTF(fontAwesomePath, fontSize, &fontAwesomeConfig, fontAwesomeRanges);
|
|
|
|
if (!fontAwesomeFont)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to load Font Awesome font: %s\n", fontAwesomePath);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the fonts
|
|
|
|
io.Fonts->Build();
|
2024-12-31 08:40:23 +00:00
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
// (Optional) Multi-viewport
|
|
|
|
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
|
|
|
|
|
|
// Style
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
|
|
|
// Platform/Renderer bindings
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
|
|
|
|
ImGui_ImplOpenGL3_Init("#version 330");
|
|
|
|
|
|
|
|
// Initialize windows
|
2024-12-27 01:34:34 +00:00
|
|
|
m_RenderWindow = std::make_unique<RenderWindow>();
|
2024-12-25 21:44:33 +00:00
|
|
|
m_PerformanceWindow = std::make_unique<PerformanceWindow>();
|
2024-12-27 01:34:34 +00:00
|
|
|
m_LoggerWindow = std::make_unique<LoggerWindow>();
|
|
|
|
m_InspectorWindow = std::make_unique<InspectorWindow>();
|
|
|
|
m_SceneWindow = std::make_unique<SceneWindow>();
|
2024-12-28 03:43:17 +00:00
|
|
|
m_luaEditor = std::make_unique<LuaEditorWindow>();
|
2024-12-29 02:50:39 +00:00
|
|
|
m_profilerWindow = std::make_unique<ProfilerWindow>();
|
2024-12-25 21:44:33 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
m_GameRunning = false;
|
|
|
|
m_FirstTickGameRunning = true;
|
2025-01-01 04:47:05 +00:00
|
|
|
m_showProfiler = true;
|
2024-12-27 21:27:05 +00:00
|
|
|
|
2025-01-04 00:32:39 +00:00
|
|
|
DrawBBBO = false;
|
|
|
|
|
2024-12-28 03:43:17 +00:00
|
|
|
g_LoggerWindow = m_LoggerWindow.get();
|
2024-12-27 21:27:05 +00:00
|
|
|
|
|
|
|
// Optionally, call 'onInit' Lua function
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
// Some initial logs
|
|
|
|
m_LoggerWindow->AddLog("Engine initialized.");
|
|
|
|
m_LoggerWindow->AddLog("Welcome to Tesseract Engine!");
|
|
|
|
|
|
|
|
m_Running = true;
|
|
|
|
m_LastTime = glfwGetTime();
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[OK] Engine Init ");
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyEngine::Run()
|
|
|
|
{
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[START] Engine Run ");
|
2024-12-26 00:15:18 +00:00
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
DEBUG_PRINT("Transition to Editor");
|
|
|
|
// printf("%p\n", &g_GameObjects);
|
|
|
|
|
|
|
|
// Possibly create more GameObjects with different positions or textures
|
2024-12-26 04:00:13 +00:00
|
|
|
|
2025-01-01 06:56:47 +00:00
|
|
|
ThemeManager_ChangeTheme(3);
|
2024-12-27 01:34:34 +00:00
|
|
|
DEBUG_PRINT("Changed Theme to default");
|
2024-12-26 04:00:13 +00:00
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
while (!glfwWindowShouldClose(m_Window) && m_Running)
|
|
|
|
{
|
2024-12-29 02:50:39 +00:00
|
|
|
|
2024-12-27 21:27:05 +00:00
|
|
|
// Poll events
|
2024-12-29 02:50:39 +00:00
|
|
|
{
|
|
|
|
ScopedTimer timer("glfwPollEvents");
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
2024-12-25 21:44:33 +00:00
|
|
|
|
2025-01-01 07:36:53 +00:00
|
|
|
{
|
|
|
|
SCOPE_TIMER("InputManagerUpdate");
|
|
|
|
g_InputManager.Update(m_Window);
|
|
|
|
}
|
|
|
|
|
2024-12-27 21:27:05 +00:00
|
|
|
// Calculate current time
|
2024-12-25 21:44:33 +00:00
|
|
|
double current_time = glfwGetTime();
|
2024-12-27 21:27:05 +00:00
|
|
|
|
|
|
|
// Calculate per-frame delta time
|
|
|
|
double frame_delta = current_time - m_LastFrameTime;
|
|
|
|
m_LastFrameTime = current_time;
|
|
|
|
|
|
|
|
// Accumulate time for FPS calculation
|
|
|
|
m_TimeAccumulator += frame_delta;
|
2024-12-25 21:44:33 +00:00
|
|
|
m_FrameCount++;
|
2024-12-27 21:27:05 +00:00
|
|
|
|
|
|
|
// Update FPS every 0.1 seconds
|
|
|
|
if (m_TimeAccumulator >= 0.1)
|
2024-12-25 21:44:33 +00:00
|
|
|
{
|
2024-12-27 21:27:05 +00:00
|
|
|
m_Fps = static_cast<float>(m_FrameCount / m_TimeAccumulator);
|
|
|
|
m_Ms = 100.0f / m_Fps; // Assuming m_Ms represents milliseconds per frame
|
|
|
|
|
|
|
|
// Reset counters
|
2024-12-25 21:44:33 +00:00
|
|
|
m_FrameCount = 0;
|
2024-12-27 21:27:05 +00:00
|
|
|
m_TimeAccumulator = 0.0;
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start new frame
|
|
|
|
BeginFrame();
|
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
if (m_FirstTickGameRunning && m_GameRunning)
|
|
|
|
{
|
2024-12-30 04:25:16 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
ScopedTimer timer("SaveScene");
|
|
|
|
m_FirstTickGameRunning = false;
|
|
|
|
|
2024-12-31 08:40:23 +00:00
|
|
|
std::string savePath = createTempFolder().string() + "/TesseractEngineTempScene.scene";
|
2024-12-29 02:50:39 +00:00
|
|
|
DEBUG_PRINT("Save path: %s", savePath.c_str());
|
|
|
|
g_SceneManager.SaveScene(g_GameObjects, savePath);
|
2024-12-30 04:25:16 +00:00
|
|
|
|
|
|
|
ScopedTimer LUA_INIT_timer("GameObjectsScriptInit");
|
|
|
|
for (auto &Gameobject : g_GameObjects)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Handle Components That Require Updates
|
|
|
|
std::shared_ptr<ScriptComponent> script = Gameobject->GetComponent<ScriptComponent>();
|
|
|
|
if (script)
|
2025-01-01 04:31:58 +00:00
|
|
|
{ // Null Checks
|
2024-12-30 04:25:16 +00:00
|
|
|
ScopedTimer Lua_timer("GameObjectLuaCall_INIT: " + Gameobject->name); // var has to be named that or it will be redecl
|
|
|
|
|
|
|
|
script->Init();
|
|
|
|
}
|
|
|
|
}
|
2024-12-29 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_FirstTickGameRunning && !m_GameRunning)
|
|
|
|
{
|
|
|
|
ScopedTimer timer("LoadScene");
|
|
|
|
m_FirstTickGameRunning = true;
|
|
|
|
|
2024-12-31 08:40:23 +00:00
|
|
|
std::string loadPath = createTempFolder().string() + "/TesseractEngineTempScene.scene";
|
2024-12-29 02:50:39 +00:00
|
|
|
|
|
|
|
DEBUG_PRINT("Load path: %s", loadPath.c_str());
|
|
|
|
|
|
|
|
g_SceneManager.LoadScene(g_GameObjects, loadPath);
|
|
|
|
}
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
// Show main DockSpace
|
|
|
|
ShowDockSpace();
|
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
if (m_GameRunning)
|
2024-12-28 03:43:17 +00:00
|
|
|
{
|
2024-12-29 02:50:39 +00:00
|
|
|
ScopedTimer timer("UpdateGameObjects");
|
2024-12-28 03:43:17 +00:00
|
|
|
for (auto &Gameobject : g_GameObjects)
|
|
|
|
{
|
2024-12-27 21:27:05 +00:00
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
Gameobject->Update(frame_delta);
|
2024-12-27 21:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
// Render and show various windows
|
|
|
|
{
|
|
|
|
ScopedTimer timer("RenderGame");
|
2024-12-27 01:34:34 +00:00
|
|
|
|
2024-12-29 03:20:11 +00:00
|
|
|
m_RenderWindow->Show(&m_GameRunning); // The spinning triangle as ImGui::Image
|
2024-12-29 02:50:39 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
ScopedTimer timer("ShowEditor");
|
2024-12-25 23:01:05 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
m_InspectorWindow->Show();
|
|
|
|
m_PerformanceWindow->Show(m_Fps, m_Ms); // FPS & ms
|
|
|
|
m_LoggerWindow->Show(); // Logs
|
|
|
|
m_SceneWindow->Show();
|
2025-01-01 04:31:58 +00:00
|
|
|
// m_luaEditor->Show();
|
2024-12-26 03:06:17 +00:00
|
|
|
|
2024-12-29 03:20:11 +00:00
|
|
|
if (m_showProfiler)
|
|
|
|
{
|
|
|
|
m_profilerWindow->Show();
|
|
|
|
}
|
2024-12-29 02:50:39 +00:00
|
|
|
}
|
2024-12-28 03:43:17 +00:00
|
|
|
|
2024-12-25 23:01:05 +00:00
|
|
|
// After rendering
|
2025-01-03 23:14:25 +00:00
|
|
|
m_PerformanceWindow->UpdatePerformanceStats(g_GPU_Draw_Calls, g_GPU_Triangles_drawn_to_screen);
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
// End frame
|
|
|
|
EndFrame();
|
2024-12-29 02:50:39 +00:00
|
|
|
|
|
|
|
// Mark the end of frame for profiling
|
|
|
|
Profiler::Get().EndFrame();
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|
2024-12-27 21:27:05 +00:00
|
|
|
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[OK] Engine Run ");
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyEngine::Cleanup()
|
|
|
|
{
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[START] Engine Cleanup ");
|
2024-12-27 01:34:34 +00:00
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
// ImGui cleanup
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
|
|
|
|
// GLFW cleanup
|
|
|
|
if (m_Window)
|
|
|
|
{
|
|
|
|
glfwDestroyWindow(m_Window);
|
|
|
|
m_Window = nullptr;
|
|
|
|
}
|
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
m_Running = false;
|
2024-12-25 23:01:05 +00:00
|
|
|
DEBUG_PRINT("[OK] Engine Cleanup ");
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyEngine::BeginFrame()
|
|
|
|
{
|
|
|
|
// ImGui new frame
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyEngine::EndFrame()
|
|
|
|
{
|
|
|
|
// Render ImGui
|
|
|
|
ImGui::Render();
|
|
|
|
|
|
|
|
// Clear the default framebuffer
|
|
|
|
int display_w, display_h;
|
|
|
|
glfwGetFramebufferSize(m_Window, &display_w, &display_h);
|
|
|
|
glViewport(0, 0, display_w, display_h);
|
|
|
|
glClearColor(0.05f, 0.05f, 0.06f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
// Draw the ImGui data
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
|
|
|
// (Optional) handle multi-viewport
|
2024-12-27 01:34:34 +00:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2024-12-25 21:44:33 +00:00
|
|
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
|
|
|
{
|
2024-12-27 01:34:34 +00:00
|
|
|
GLFWwindow *backup_current_context = glfwGetCurrentContext();
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGui::UpdatePlatformWindows();
|
|
|
|
ImGui::RenderPlatformWindowsDefault();
|
|
|
|
glfwMakeContextCurrent(backup_current_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap
|
|
|
|
glfwSwapBuffers(m_Window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyEngine::ShowDockSpace()
|
|
|
|
{
|
|
|
|
static bool dockspaceOpen = true;
|
|
|
|
static bool opt_fullscreen = true;
|
2024-12-27 01:34:34 +00:00
|
|
|
// Initialize dockspace_flags without ImGuiDockNodeFlags_DockSpace
|
|
|
|
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
|
|
|
|
if (opt_fullscreen)
|
|
|
|
{
|
2024-12-27 01:34:34 +00:00
|
|
|
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
|
|
|
ImGui::SetNextWindowSize(viewport->WorkSize);
|
|
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
2024-12-27 01:34:34 +00:00
|
|
|
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
|
|
|
|
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
// Style adjustments
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
|
|
|
|
|
|
ImGui::Begin("DockSpace", &dockspaceOpen, window_flags);
|
|
|
|
ImGui::PopStyleVar(2);
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
// Menu bar
|
2024-12-25 21:44:33 +00:00
|
|
|
if (ImGui::BeginMenuBar())
|
|
|
|
{
|
|
|
|
if (ImGui::BeginMenu("File"))
|
|
|
|
{
|
|
|
|
if (ImGui::MenuItem("Exit"))
|
2024-12-27 04:08:50 +00:00
|
|
|
{
|
2024-12-25 21:44:33 +00:00
|
|
|
m_Running = false; // Stop the engine
|
2024-12-27 04:08:50 +00:00
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Save"))
|
|
|
|
{
|
2024-12-27 04:27:47 +00:00
|
|
|
m_LoggerWindow->AddLog("Saveing Scene", ImVec4(0.3f, 1.0f, 0.3f, 1.0f));
|
2024-12-27 05:31:12 +00:00
|
|
|
g_SceneManager.SaveScene(g_GameObjects, "./scenes/Default.scene");
|
2024-12-27 04:08:50 +00:00
|
|
|
}
|
|
|
|
if (ImGui::MenuItem("Load"))
|
|
|
|
{
|
2024-12-27 04:27:47 +00:00
|
|
|
m_LoggerWindow->AddLog("Loading Scene", ImVec4(0.3f, 1.0f, 0.3f, 1.0f));
|
|
|
|
|
2024-12-27 05:31:12 +00:00
|
|
|
g_SceneManager.LoadScene(g_GameObjects, "./scenes/Default.scene");
|
2024-12-27 04:08:50 +00:00
|
|
|
}
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2024-12-29 03:20:11 +00:00
|
|
|
if (ImGui::BeginMenu("Tools"))
|
|
|
|
{
|
|
|
|
ImGui::Checkbox("Show Profiler", &m_showProfiler); // Add a checkbox to toggle the profiler
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2025-01-04 00:32:39 +00:00
|
|
|
if (ImGui::BeginMenu("Settings"))
|
|
|
|
{
|
|
|
|
// A checkbox to enable/disable bounding boxes
|
|
|
|
ImGui::Checkbox("Show Box's", &DrawBBBO);
|
|
|
|
|
|
|
|
// On the same line, we place a small color edit widget
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::ColorEdit4("Box Color",
|
|
|
|
reinterpret_cast<float *>(&g_SettingsManager.S_LineColor),
|
|
|
|
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
|
|
|
|
// Explanation of Flags:
|
|
|
|
// - ImGuiColorEditFlags_NoInputs hides numeric RGBA input fields
|
|
|
|
// - ImGuiColorEditFlags_NoLabel hides the default label, since we already have "Box Color"
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
if (ImGui::BeginMenu("Engine"))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ImGui::MenuItem(m_GameRunning ? "Stop" : "Start"))
|
|
|
|
{
|
|
|
|
m_GameRunning = !m_GameRunning; // Stop the engine
|
|
|
|
}
|
2024-12-29 03:20:11 +00:00
|
|
|
|
2024-12-29 02:50:39 +00:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGui::EndMenuBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
// DockSpace
|
2024-12-27 01:34:34 +00:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2024-12-25 21:44:33 +00:00
|
|
|
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
|
|
|
|
{
|
2024-12-27 01:34:34 +00:00
|
|
|
// Optional: Log the flags for debugging
|
|
|
|
// DEBUG_PRINT("DockSpace Flags: %d", dockspace_flags);
|
|
|
|
|
2024-12-25 21:44:33 +00:00
|
|
|
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
|
|
|
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImGui::Text("Docking is not enabled. Set io.ConfigFlags |= ImGuiConfigFlags_DockingEnable.");
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|