C++ Game Logic UI synchronization with threads

  animation, c++, multithreading, resume, sleep

I am writing a game in C++ using EnTT (ECS framework)

My game is designed in simple concepts like Logic UI and Game which controls this two.

So I have struct like this

struct Game {
   // The logic
   Logic logic;

   // Ui
   Ui ui;
}

I am using delegates to fire events from one concept to another for example.

struct Logic {
   void doSomeCalculations(){
      ...
      elementSpawned(someElement);
      ...
   }
}

And in Game part I implement this

struct Game {
...

    void onElementSpawned(someElement){
    }
}

Now let’s say spawning element does some animation.

So I need to stop the logic for a while do the animation and then continue, because Logic can go too far with calculations while UI is animating.

So I need to implement something like this

void onElementSpawned(someElement) {

   logic.wait();
   ui.doAnimation(someElement);
   logic.resume();
}

How can I achieve this?

Source: Windows Questions C++

LEAVE A COMMENT