So, i want to have static bools like "key_left_wasPressed" in a class, update them in main and do the game stuff in another thread.
right now my code looks something like this:
RenderWindow window;
volatile bool willUpdateEvents = false;
void game(){
//in a loop:
willUpdateEvents = true;
while(willUpdateEvents){}
//(do game stuff)
//(draw stuff)
}
int main(){
//(setup window)
window.setActive(false);
Thread gameThread(game);
gameThread.launch();
while(Game::gameState != Game::Exit){
if(willUpdateEvents){
GameEvents::update(window);
willUpdateEvents = false;
}
}
gameThread.wait();
}
//Update function in GameEvents class:
void update(RenderWindow &window){
everything = false;
while(window.pollEvent(event)){
//(set the event bools)
}
}
The problem is, it's super slow, i can't close the window and it still freezes when i'm dragging it.
And i can't just do the game stuff that should happen at events in the event loop because i have like 8 rooms in the game so far and i don't want to have half of the logic in an event loop.