Commits

ecsv committed 776d24e

Speed up texture loading by reducing status updates
The status updates are limited by the amount of frames which can be rendered.
Showing a status update for each hires texture limits also the loading of them.
This gets even more problematic when vsync is enabled.

Now only every 0.25 seconds a status update is made. This is enough to keep the
user a feeling what is happening and still utilize the CPU and the I/O enough.

Comments (0)

Files changed (1)

src/GlideHQ/TxHiResCache.cpp

 /* 2007 Gonetz <gonetz(at)ngs.ru>
  * Added callback to display hires texture info. */
 
+#include <time.h>
+
 #ifdef __MSC__
 #pragma warning(disable: 4786)
 #endif
 boolean
 TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean replace)
 {
+  struct timespec last, now, diff;
   DBG_INFO(80, L"-----\n");
   DBG_INFO(80, L"path: %ls\n", dir_path.string().c_str());
+  clock_gettime(CLOCK_MONOTONIC, &last);
 
   /* find it on disk */
   if (!boost::filesystem::exists(dir_path)) {
 
       /* add to cache */
       if (TxCache::add(chksum64, &tmpInfo)) {
+        unsigned int msec;
+
+        clock_gettime(CLOCK_MONOTONIC, &now);
+        diff.tv_sec = now.tv_sec - last.tv_sec;
+        if (now.tv_nsec < last.tv_nsec) {
+          diff.tv_sec--;
+          diff.tv_nsec = now.tv_nsec - last.tv_nsec + 1000000000UL;
+        } else {
+          diff.tv_nsec = now.tv_nsec - last.tv_nsec;
+        }
+        msec = diff.tv_sec * 1000 + diff.tv_nsec / 1000000UL;
+
         /* Callback to display hires texture info.
          * Gonetz <gonetz(at)ngs.ru> */
-        if (_callback) {
+        if (_callback && msec > 250) {
           wchar_t tmpbuf[MAX_PATH];
           mbstowcs(tmpbuf, fname, MAX_PATH);
           (*_callback)(L"[%d] total mem:%.2fmb - %ls\n", _cache.size(), (float)_totalSize/1000000, tmpbuf);
+          last = now;
         }
         DBG_INFO(80, L"texture loaded!\n");
       }