Added nanosecond info of last module modification

master
Martin Felis 2017-01-14 16:21:47 +01:00
parent 4deba61a09
commit c76f0959ff
4 changed files with 17 additions and 13 deletions

View File

@ -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);

View File

@ -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;

View File

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

View File

@ -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;