Hello
i've encountered a strange problem and I'm not sure how to tackle it. At the moment my program consists of a renderwindow and a console(debug build). The problem is that when the render has "no events to capture" (i move mouse outside of the window region, minimize the window, or simply leave the cursor within the window but motionless) the class responsible for graphics (the one that has the renderwindow as its member) just holds execution. The messages it would print to the console won't appear until the moment i move the mouse within the render window. The messages generated by a separate class appear in the console normally. What can be the cause of this behavior? I would like my program to continue execution regardless if the window has focus or not/ if a user sits in front of the pc or not. The code that represents the program structure (and partially recreates the problem - partially because in here both classes stop "working" when the i don't move the mouse/move it outside of the window) is below
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class Window
{
public:
Window(): timer(2), window(sf::VideoMode(800, 600), "SFML window"){}
timeFunc()
{
sf::Time measure = clock.getElapsedTime();
if (measure.asSeconds() >= timer)
{
std::cout<< "window func" << std::endl;
clock.restart();
}
}
sf::RenderWindow window;
private:
int timer;
sf::Clock clock;
};
class Terminal
{
public:
Terminal(): timer(2){}
timeFunc()
{
sf::Time measure = clock.getElapsedTime();
if (measure.asSeconds() >= timer)
{
std::cout<< "terminal func" << std::endl;
clock.restart();
}
}
private:
int timer;
sf::Clock clock;
};
class base
{
public:
base(){running = true;}
Window window;
Terminal terminal;
bool running;
};
int main()
{
base a;
while(a.running)
{
sf::Event event;
while(a.window.window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
a.running = false;
a.window.timeFunc();
a.terminal.timeFunc();
a.window.window.clear();
a.window.window.display();
}
}
return 0;
}