Added RuntimeModule debug window
parent
a8e06dc63b
commit
34ade062a4
|
@ -1,6 +1,8 @@
|
||||||
ProtoT - Fun 3D programming prototyping environment
|
ProtoT - Fun 3D programming prototyping environment
|
||||||
Copyright (c) 2016 - Martin Felis <martin@fysx.org
|
Copyright (c) 2016 - Martin Felis <martin@fysx.org
|
||||||
|
|
||||||
|
Needs inotifywait to work (in ubuntu provided by inotify-tools)
|
||||||
|
|
||||||
mkdir build/
|
mkdir build/
|
||||||
cd build/
|
cd build/
|
||||||
ln -s ../shaders
|
ln -s ../shaders
|
||||||
|
|
|
@ -5,3 +5,6 @@ extern Renderer* gRenderer;
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
extern GLFWwindow* gWindow;
|
extern GLFWwindow* gWindow;
|
||||||
|
|
||||||
|
struct RuntimeModuleManager;
|
||||||
|
extern RuntimeModuleManager* gModuleManager;
|
||||||
|
|
|
@ -13,17 +13,6 @@
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
void RuntimeModuleManager::RegisterModule(const char* name) {
|
void RuntimeModuleManager::RegisterModule(const char* name) {
|
||||||
RuntimeModule* module = new RuntimeModule();
|
RuntimeModule* module = new RuntimeModule();
|
||||||
module->name = name;
|
module->name = name;
|
||||||
|
@ -87,7 +76,7 @@ void RuntimeModuleManager::Update(float dt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to sleep to make sure we load the new files
|
// We need to sleep to make sure we load the new files
|
||||||
usleep(150000);
|
usleep(350000);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < mModules.size(); i++) {
|
for (int i = 0; i < mModules.size(); i++) {
|
||||||
|
|
|
@ -3,8 +3,21 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "RuntimeModule.h"
|
||||||
|
|
||||||
struct RuntimeModule;
|
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 {
|
struct RuntimeModuleManager {
|
||||||
std::vector<RuntimeModule*> mModules;
|
std::vector<RuntimeModule*> mModules;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
Renderer* gRenderer = nullptr;
|
Renderer* gRenderer = nullptr;
|
||||||
GLFWwindow* gWindow = nullptr;
|
GLFWwindow* gWindow = nullptr;
|
||||||
|
RuntimeModuleManager* gModuleManager = nullptr;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -93,6 +94,9 @@ int main(void)
|
||||||
module_manager.RegisterModule("src/modules/libRenderModule.so");
|
module_manager.RegisterModule("src/modules/libRenderModule.so");
|
||||||
module_manager.RegisterModule("src/modules/libTestModule.so");
|
module_manager.RegisterModule("src/modules/libTestModule.so");
|
||||||
|
|
||||||
|
// Setup global variables
|
||||||
|
gModuleManager = &module_manager;
|
||||||
|
|
||||||
glfwSetKeyCallback(gWindow, key_callback);
|
glfwSetKeyCallback(gWindow, key_callback);
|
||||||
int64_t time_offset = bx::getHPCounter();
|
int64_t time_offset = bx::getHPCounter();
|
||||||
|
|
||||||
|
|
|
@ -1032,7 +1032,10 @@ void Renderer::paintGL() {
|
||||||
|
|
||||||
// Use debug font to print information about this example.
|
// Use debug font to print information about this example.
|
||||||
bgfx::dbgTextClear();
|
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
|
// submit the imgui widgets
|
||||||
imguiEndFrame();
|
imguiEndFrame();
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "SimpleMath/SimpleMathMap.h"
|
#include "SimpleMath/SimpleMathMap.h"
|
||||||
#include "SimpleMath/SimpleMathGL.h"
|
#include "SimpleMath/SimpleMathGL.h"
|
||||||
|
|
||||||
|
#include "RuntimeModuleManager.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -31,6 +33,10 @@ struct module_state {
|
||||||
bool fps_camera;
|
bool fps_camera;
|
||||||
float camera_theta;
|
float camera_theta;
|
||||||
float camera_phi;
|
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) {
|
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);
|
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);
|
direction += Vector3f (0.f, -1.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,39 +171,89 @@ static void module_unload(struct module_state *state) {
|
||||||
glfwSetScrollCallback (gWindow, nullptr);
|
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) {
|
static bool module_step(struct module_state *state) {
|
||||||
if (gRenderer == nullptr)
|
if (gRenderer == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
ImGui::Begin("TestModule");
|
static bool imgui_demo_window_visible = false;
|
||||||
if (ImGui::Checkbox("FPS Camera", &state->fps_camera)) {
|
|
||||||
|
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::EndMainMenuBar();
|
||||||
ImGui::SliderFloat("Phi", &state->camera_phi, -3.141592f, 3.141592f);
|
|
||||||
|
|
||||||
if (gRenderer) {
|
if (state->modules_window_visible) {
|
||||||
Camera *active_camera = &gRenderer->cameras[gRenderer->activeCameraIndex];
|
ShowModulesWindow(state);
|
||||||
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 (ImGui::Button("Hallo Katrina Whaddup?")) {
|
if (state->imgui_demo_window_visible) {
|
||||||
if (gRenderer->drawDebug) {
|
ImGui::ShowTestWindow();
|
||||||
gRenderer->drawDebug = false;
|
|
||||||
} else {
|
|
||||||
gRenderer->drawDebug = true;
|
|
||||||
}
|
}
|
||||||
std::cout << "Clicked on Baem!" << std::endl;
|
|
||||||
}
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
static bool imgui_test_window = true;
|
|
||||||
// ImGui::ShowTestWindow();
|
|
||||||
|
|
||||||
float deltaTime = 0.3;
|
float deltaTime = 0.3;
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
|
Loading…
Reference in New Issue