I have an OpenGL application with two main parts (viewers), with a main loop as follows:
int main(int argc, char* argv[])
{
gp::viewers::PatternViewer pViewer;
gp::viewers::MeshViewer mViewer;
while (!pViewer.shouldClose() && !mViewer.shouldClose())
{
pViewer.makeCurrent();
pViewer.mainLoop();
pViewer.swap();
mViewer.makeCurrent();
mViewer.mainLoop();
mViewer.swap();
glfwWaitEvents();
}
glfwTerminate();
return 0;
}
It happens that a user interaction with one viewer should propagate a change to the other viewer. My gut instinct says to update the loop as follows:
int main(int argc, char* argv[])
{
gp::viewers::PatternViewer pViewer;
gp::viewers::MeshViewer mViewer;
while (!pViewer.shouldClose() && !mViewer.shouldClose())
{
pViewer.makeCurrent();
pViewer.mainLoop();
pViewer.swap();
mViewer.makeCurrent();
mViewer.mainLoop();
mViewer.swap();
// UPDATE HERE
mViewer.update(pViewer);
pViewer.update(mViewer);
glfwWaitEvents();
}
glfwTerminate();
return 0;
}
But in that case, PatternViewer needs to know about MeshViewer, and MeshViewer needs to know about PatternViewer - a circular dependency. Moreover, it isn't clear if mViewer.update(pViewer) should update pViewer with whatever updates are available from mViewer, or vice versa. It seems to me that it should be the former - mViewer should know what updates to propagate, not pViewer.
It should be mentioned that PatternViewer and MeshViewer both inherit from abstract superclass Viewer.
Is there any way of resolving this circular dependency? Is there an accepted way/design pattern for handling this case?
Aucun commentaire:
Enregistrer un commentaire