diff --git a/README.md b/README.md index 74e2b56..612808d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ProtoT - Fun 3D programming prototyping environment Copyright (c) 2016 - Martin Felis name = name; @@ -87,7 +76,7 @@ void RuntimeModuleManager::Update(float dt) { } // We need to sleep to make sure we load the new files - usleep(150000); + usleep(350000); } for (int i = 0; i < mModules.size(); i++) { diff --git a/src/RuntimeModuleManager.h b/src/RuntimeModuleManager.h index 1859f9a..dccee2b 100644 --- a/src/RuntimeModuleManager.h +++ b/src/RuntimeModuleManager.h @@ -3,8 +3,21 @@ #include #include +#include "RuntimeModule.h" + struct RuntimeModule; +struct RuntimeModule { + std::string name = ""; + void *handle = nullptr; + ino_t id = 0; + void *data = nullptr; + int mtime = 0; + + struct module_api api; + struct module_state *state = nullptr; +}; + struct RuntimeModuleManager { std::vector mModules; diff --git a/src/main.cc b/src/main.cc index 16dc1e5..509be1c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -19,6 +19,7 @@ #include "Globals.h" Renderer* gRenderer = nullptr; GLFWwindow* gWindow = nullptr; +RuntimeModuleManager* gModuleManager = nullptr; using namespace std; @@ -93,6 +94,9 @@ int main(void) module_manager.RegisterModule("src/modules/libRenderModule.so"); module_manager.RegisterModule("src/modules/libTestModule.so"); + // Setup global variables + gModuleManager = &module_manager; + glfwSetKeyCallback(gWindow, key_callback); int64_t time_offset = bx::getHPCounter(); diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index c360f8c..dee0b5b 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -1032,7 +1032,10 @@ void Renderer::paintGL() { // Use debug font to print information about this example. bgfx::dbgTextClear(); - bgfx::dbgTextPrintf(0, 0, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); + + // debug font is 8 pixels wide + int num_chars = width / 8; + bgfx::dbgTextPrintf(num_chars - 18, 0, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); // submit the imgui widgets imguiEndFrame(); diff --git a/src/modules/TestModule.cc b/src/modules/TestModule.cc index 051629b..718fb7a 100644 --- a/src/modules/TestModule.cc +++ b/src/modules/TestModule.cc @@ -9,6 +9,8 @@ #include "SimpleMath/SimpleMathMap.h" #include "SimpleMath/SimpleMathGL.h" +#include "RuntimeModuleManager.h" + #include #include @@ -31,6 +33,10 @@ struct module_state { bool fps_camera; float camera_theta; float camera_phi; + bool modules_window_visible = false; + bool imgui_demo_window_visible = false; + + int modules_window_selected_index = -1; }; void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { @@ -124,7 +130,7 @@ void handle_keyboard (struct module_state *state) { direction += Vector3f (0.f, 1.f, 0.f); } - if (glfwGetKey(gWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) { + if (glfwGetKey(gWindow, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) { direction += Vector3f (0.f, -1.f, 0.f); } @@ -165,39 +171,89 @@ static void module_unload(struct module_state *state) { glfwSetScrollCallback (gWindow, nullptr); } +void ShowModulesWindow(struct module_state *state) { + ImGui::SetNextWindowSize (ImVec2(400.f, 300.0f), ImGuiSetCond_Once); + ImGui::SetNextWindowPos (ImVec2(400.f, 16.0f), ImGuiSetCond_Once); + ImGui::Begin("Modules"); + +// ImGui::Columns(2); + int selected = state->modules_window_selected_index; + for (int i = 0; i < gModuleManager->mModules.size(); i++) { + ImGuiTreeNodeFlags node_flags = + ImGuiTreeNodeFlags_Leaf + | ((i == selected) ? ImGuiTreeNodeFlags_Selected : 0) + ; + + bool node_open = ImGui::TreeNodeEx( + gModuleManager->mModules[i]->name.c_str(), + node_flags); + + if (ImGui::IsItemClicked()) { + selected = i; + } + + if (node_open) { + ImGui::TreePop(); + } + } + state->modules_window_selected_index = selected; + + +// ImGui::NextColumn(); + + ImGui::Separator(); + + RuntimeModule* selected_module = nullptr; + if (selected != -1) { + selected_module = gModuleManager->mModules[selected]; + } + + if (selected_module) { + static char time_buf[32]; + memset (time_buf, 0, 32); + + ImGui::LabelText("File", "%s", selected_module->name.c_str()); + ImGui::LabelText("Handle", "0x%p", selected_module->handle); + ImGui::LabelText("id", "%ld", selected_module->id); + + ctime_r((time_t*)&selected_module->mtime, time_buf); + ImGui::LabelText("mtime", "%s", time_buf); + + if (ImGui::Button ("Force Reload")) { + selected_module->mtime = 0; + selected_module->id = 0; + } + } + + ImGui::End(); +} + static bool module_step(struct module_state *state) { if (gRenderer == nullptr) return false; bool enabled = true; - ImGui::Begin("TestModule"); - if (ImGui::Checkbox("FPS Camera", &state->fps_camera)) { + static bool imgui_demo_window_visible = false; + + ImGui::BeginMainMenuBar(); + + if (ImGui::BeginMenu("Dialogs")) + { + ImGui::Checkbox("Modules", &state->modules_window_visible); + ImGui::Checkbox("ImGui Demo", &state->imgui_demo_window_visible); + + ImGui::EndMenu(); } - ImGui::SliderFloat("Theta", &state->camera_theta, -3.141592f, 3.141592f); - ImGui::SliderFloat("Phi", &state->camera_phi, -3.141592f, 3.141592f); + ImGui::EndMainMenuBar(); - if (gRenderer) { - Camera *active_camera = &gRenderer->cameras[gRenderer->activeCameraIndex]; - if (active_camera) { - ImGui::SliderFloat3("Eye", active_camera->eye, -30.0f, 30.0f); - ImGui::SliderFloat3("Poi", active_camera->poi, -30.0f, 30.0f); - } - assert (active_camera != nullptr); + if (state->modules_window_visible) { + ShowModulesWindow(state); } - if (ImGui::Button("Hallo Katrina Whaddup?")) { - if (gRenderer->drawDebug) { - gRenderer->drawDebug = false; - } else { - gRenderer->drawDebug = true; - } - std::cout << "Clicked on Baem!" << std::endl; + if (state->imgui_demo_window_visible) { + ImGui::ShowTestWindow(); } - ImGui::End(); - - static bool imgui_test_window = true; -// ImGui::ShowTestWindow(); float deltaTime = 0.3; std::ostringstream s;