Browse Source

prefere user input evaluation before rendering

Kolja Strohm 1 year ago
parent
commit
f5bdf6fbcd
2 changed files with 27 additions and 0 deletions
  1. 24 0
      Bildschirm.cpp
  2. 3 0
      Bildschirm.h

+ 24 - 0
Bildschirm.cpp

@@ -510,27 +510,51 @@ void Bildschirm3D::tick(double tickval)
 
 void Bildschirm3D::doMausEreignis(MausEreignis& me) // sendet maus Ereignis
 {
+    std::unique_lock<std::mutex> lk(mutex);
+    waitingUserInput++;
+    lk.unlock();
     lock();
     __super::doMausEreignis(me);
     for (int i = kameras->getEintragAnzahl() - 1; i >= 0; i--)
         kameras->z(i)->doMausEreignis(me);
     unlock();
+    lk.lock();
+    waitingUserInput--;
+    if (waitingUserInput == 0)
+    {
+        lk.unlock();
+        waiting.notify_all();
+    }
 }
 
 void Bildschirm3D::doTastaturEreignis(
     TastaturEreignis& te) // sendet tastatur Ereignis
 {
+    std::unique_lock<std::mutex> lk(mutex);
+    waitingUserInput++;
+    lk.unlock();
     lock();
     __super::doTastaturEreignis(te);
     for (int i = kameras->getEintragAnzahl() - 1; i >= 0; i--)
         kameras->z(i)->doTastaturEreignis(te);
     unlock();
+    lk.lock();
+    waitingUserInput--;
+    if (waitingUserInput == 0)
+    {
+        lk.unlock();
+        waiting.notify_all();
+    }
 }
 
 void Bildschirm3D::render() // Zeichnet das Bild
 {
     if (!rend && !rend3D && testRend) return;
+    std::unique_lock<std::mutex> lk(mutex);
+    if (waitingUserInput > 0)
+        waiting.wait(lk);
     rendering = 1;
+    lk.unlock();
     lock();
     renderZeit->messungStart();
     // Clear the back buffer.

+ 3 - 0
Bildschirm.h

@@ -84,6 +84,9 @@ namespace Framework
         bool testRend;
         bool fill;
         bool rend;
+        std::mutex mutex;
+        int waitingUserInput;
+        std::condition_variable waiting;
 
     public:
         //! Konstruktor