I am currently developing an SFML application which stores a certain value in my model, which the view is displaying.
As SFML operates on a kind of render loop, which refreshes the interface constantly, I need to fetch this value which has to be displayed from the model where it is stored in every iteration to keep it up to date. It is not possible to effectively pass this value from the controller, due to the following:
My SFML loop looks like this:
while (renderWindow->isOpen())
{
sf::Event event;
while (renderWindow->pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
renderWindow->close();
break;
case sf::Event::MouseButtonPressed:
HandleLeftClick(event);
break;
case sf::Event::MouseButtonReleased:
HandleLeftClickRelease(event);
break;
}
}
m_mainWindowView->DrawWindow();
}
As you can see, I do the event handling in my controller, but I pass the whole interface redrawing to my view. I could technically pass the value I want to display with this call, but if I need more values from my controller, this might lead to a lot of parameters later on.
As far as I know, the view should not have a reference to the model. Therefore, my current solution looks like this:
When the view redraws the window, it calls a function in the controller to fetch the value to be displayed from the model. The controller then redirects this request to the model, and therefore returns the data from the model to the view over the controller.
I feel like this approach is not correct, but I can't quite figure out what other options I have with the MVC pattern. I'm not even sure if the SFML event loop allows for a pure MVC approach or if I can't get around adapting it somewhat.
I could theoretically store a pointer to the desired value in the view, but that would kind of create a dependency from the view to the model as well.
Any advice on how to do this in proper fashion?