From c76f0959ff372a4af2f9da5109a9a351f5001e5f Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 14 Jan 2017 16:21:47 +0100 Subject: [PATCH] Added nanosecond info of last module modification --- src/RuntimeModuleManager.cc | 12 +----------- src/RuntimeModuleManager.h | 1 + src/main.cc | 11 +++++++++++ src/modules/TestModule.cc | 6 ++++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/RuntimeModuleManager.cc b/src/RuntimeModuleManager.cc index 6951f7b..1d4aeaa 100644 --- a/src/RuntimeModuleManager.cc +++ b/src/RuntimeModuleManager.cc @@ -57,6 +57,7 @@ void RuntimeModuleManager::LoadModule(RuntimeModule* module) { module->handle = handle; module->id = attr.st_ino; module->mtime = attr.st_mtime; + module->mtimensec = attr.st_mtim.tv_nsec; const struct module_api *api = (module_api*) dlsym(module->handle, "MODULE_API"); if (api != NULL) { module->api = *api; @@ -83,17 +84,6 @@ void RuntimeModuleManager::LoadModule(RuntimeModule* module) { } void RuntimeModuleManager::Update(float dt) { - if (CheckModulesChanged()) { - std::cout << "Detected module update. Unloading all modules." << std::endl; - - UnloadModules(); - - // We need to sleep to make sure we load the new files - usleep(300000); - - LoadModules(); - } - for (int i = mModules.size() - 1; i >= 0; i--) { if (mModules[i]->handle) { mModules[i]->api.step(mModules[i]->state, dt); diff --git a/src/RuntimeModuleManager.h b/src/RuntimeModuleManager.h index 65cb003..13e4f2c 100644 --- a/src/RuntimeModuleManager.h +++ b/src/RuntimeModuleManager.h @@ -13,6 +13,7 @@ struct RuntimeModule { ino_t id = 0; void *data = nullptr; int mtime = 0; + int mtimensec = 0; struct module_api api; struct module_state *state = nullptr; diff --git a/src/main.cc b/src/main.cc index 5842d85..520dd6b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -122,6 +122,17 @@ int main(void) float time = (float)( (now-time_offset)/double(bx::getHPFrequency() ) ); + if (module_manager.CheckModulesChanged()) { + std::cout << "Detected module update. Unloading all modules." << std::endl; + module_manager.UnloadModules(); + // We need to sleep to make sure we load the new files + usleep(300000); + module_manager.LoadModules(); + // We need to update our last timestamp to ignore the delay due + // to reloading of the modules. + last = bx::getHPCounter(); + } + module_manager.Update((float)(frameTime / freq)); glfwPollEvents(); diff --git a/src/modules/TestModule.cc b/src/modules/TestModule.cc index 1fef6f8..04d02e4 100644 --- a/src/modules/TestModule.cc +++ b/src/modules/TestModule.cc @@ -411,9 +411,11 @@ void ShowModulesWindow(struct module_state *state) { ImGui::LabelText("File", "%s", selected_module->name.c_str()); ImGui::LabelText("Handle", "0x%p", selected_module->handle); ImGui::LabelText("id", "%ld", selected_module->id); + ImGui::LabelText("mtime", "%ld", selected_module->mtime); + ImGui::LabelText("mtimensec", "%ld", selected_module->mtimensec); - ctime_r((time_t*)&selected_module->mtime, time_buf); - ImGui::LabelText("mtime", "%s", time_buf); +// ImGui::LabelText("mtime", "%s", ctime((time_t*)&selected_module->mtime)); +// cout << "time_buf = " << ctime((time_t*)&selected_module->mtime) << endl; if (ImGui::Button ("Force Reload")) { selected_module->mtime = 0;