How to design a complete app in oF

The standard openFrameworks system is very good for 1 class applications. There is 1 testApp.cpp class and you can use it for your code. But we generally need to design a complete app with a flow like that:

–> SplashScreen.cpp
–> MainMenu.cpp
----> Explanations.cpp ----> Play.cpp ----> Scoreboard.cpp ----> Main Menu
----> Help.cpp
----> Scoreboard.cpp
----> About.cpp
----> Exit

What is the best way or your best practice to design a complete app with multiple classes in openFrameworks?

2 Likes

MVC works well. When I started messing with OF, TSPS was one of the first full blown OF apps that I found. It’s a few years old but still active.

Is it suitable for memory hungry apps like 3d games?

I don’t think MVC is suitable. I need god classes which can use all possible hardware resources.

I tried to run the second class by “ofRunApp(new secondclass());” from testApp, but it doesnt work.

You could write a scene manager class, that handles your different scenes (splashScreen/MainMenu/…) and knows which one to execute (i.e. call update/draw/enable mouse events/etc.).
You can decide to implement your state-machine in your main app, and drive the scene manager from there.
You could decide that each scene notifies the state-machine (e.g. using events) to go to another scene.
The main app would do the top-level things, like sceneManager.goToScene(SCOREBOARD), while in the goToScene method the sceneManager would take care of lower-level stuff, like notifying the current scene that it will disappear, and the new scene that it will appear.
The scene manager should stay as generic as possible and should handle objects inheriting from a scene class.
When the main app registers a scene to the scene manager, the latter could take care of initialization of the scene (like calling a setup() function).
This is just one way of doing, let me know if you want more details.

Hey @sachaventura thanks for the input. Yes I wrote a scene manager, it is working now.

I see there is not another way then something like a MV* design as @jvcleave has suggested, without hacking the oF core. So I designed a “Layered MVC”. It is a middle way between mvc and god classes.

There are 2 layers in this layered mvc design. The first layer is the scene manager as you suggest. It manages the info of the god class to connect. The second layer is the mvc layer as jvcleave suggests, where testApp.cpp (not main.cpp) connects only to the god class.

Thanks all.