diff --git a/panda/src/express/config_express.cxx b/panda/src/express/config_express.cxx index b6997d4324..4d7290f32b 100644 --- a/panda/src/express/config_express.cxx +++ b/panda/src/express/config_express.cxx @@ -49,6 +49,21 @@ get_leak_memory() { //const bool track_memory_usage = config_express.GetBool("track-memory-usage", false); +// Set this to false to avoid using the high-precision clock, even if +// it is available. +bool +get_use_high_res_clock() { + static bool got_use_high_res_clock = false; + static bool use_high_res_clock; + + if (!got_use_high_res_clock) { + use_high_res_clock = config_express.GetBool("use-high-res-clock", true); + got_use_high_res_clock = true; + } + + return use_high_res_clock; +} + const int patchfile_window_size = config_express.GetInt("patchfile-window-size", 16); diff --git a/panda/src/express/config_express.h b/panda/src/express/config_express.h index a963c02f7c..f1686b3d88 100644 --- a/panda/src/express/config_express.h +++ b/panda/src/express/config_express.h @@ -21,6 +21,7 @@ NotifyCategoryDecl(express, EXPCL_PANDAEXPRESS, EXPTP_PANDAEXPRESS); //extern EXPCL_PANDAEXPRESS const bool track_memory_usage; bool get_leak_memory(); +bool get_use_high_res_clock(); extern const int patchfile_window_size; extern const int patchfile_increment_size; diff --git a/panda/src/express/trueClock.cxx b/panda/src/express/trueClock.cxx index c0adab9973..4e34f52bc5 100644 --- a/panda/src/express/trueClock.cxx +++ b/panda/src/express/trueClock.cxx @@ -37,14 +37,6 @@ get_real_time() const { LARGE_INTEGER count; QueryPerformanceCounter(&count); - if (_init_count > count.QuadPart) - _init_count = count.QuadPart; - - if (_frequency < 0) { - express_cat.error() - << "TrueClock::get_real_time() - frequency is negative!" << endl; - QueryPerformanceFrequency((LARGE_INTEGER *)&_frequency); - } return (double)(count.QuadPart - _init_count) / (double)_frequency; } else { @@ -57,12 +49,25 @@ get_real_time() const { TrueClock:: TrueClock() { - _has_high_res = QueryPerformanceFrequency((LARGE_INTEGER *)&_frequency); + _has_high_res = false; + if (get_use_high_res_clock()) { + _has_high_res = QueryPerformanceFrequency((LARGE_INTEGER *)&_frequency); + } if (_has_high_res) { - QueryPerformanceCounter((LARGE_INTEGER *)&_init_count); + LARGE_INTEGER count; + QueryPerformanceCounter(&count); + _init_count = count.QuadPart; - } else { + if (_frequency <= 0) { + express_cat.error() + << "TrueClock::get_real_time() - frequency is negative!" << endl; + _has_high_res = false; + } + + } + + if (!_has_high_res) { express_cat.warning() << "No high resolution clock available." << endl;