mosra / magnum-bindings

Bindings of the Magnum C++11 graphics engine into other languages
https://magnum.graphics
Other
19 stars 13 forks source link

Rendering without having the main loop owned by magnum #6

Closed kekeblom closed 5 years ago

kekeblom commented 5 years ago

Is it possible to have the main loop owned by the python application?

What I would like to do is something like this:

app = Application()
while True: 
  app.mainLoopIteration()
  # do other stuff

Now this could be achieved by just exposing the mainLoopIteration method on Sdl2Application. However, then the python application would have to check for the exit flag and the flags are not exposed outside the application class.

Is there a way to do this that I'm overlooking or would this have to be implemented? If this would have to be implemented, what do you feel would be the appropriate way to change the api to support such a use case?

mosra commented 5 years ago

Hi!

One idea would be:

while app.exit_requested:
    app.main_loop_iteration()

    # other stuff

But the exit_requested would be absolutely useless in other use cases, not a fan. Then I thought I could turn exit() into a property, so you could do stuff like

while not app.exit:
    app.main_loop_iteration()

    ...

    if thing: app.exit = 0 # Exit with a success return code

... but that feels to me like not being very intuitive / looking weird, and not following the C++ API at all. Then, what about having main_loop_iteration return a bool, saying False if the app is meant to exit? That could work well and fix the same issue on the C++ side too I think:

while app.main_loop_iteration():
    # other stuff

Thoughts? :)

kekeblom commented 5 years ago

I feel the last one is probably the cleanest solution and this would support the use case nicely.

mosra commented 5 years ago

Yeah, that's my feeling too :) I'll do the changes and let you know once they hit master on both the main magnum repo and this one.

The mainLoopIteration() is currently only on Sdl2Application, not on GlfwApplication. Is that okay?

mosra commented 5 years ago

With mosra/magnum@82f53862e12a7318bb1e3c62e8307422290b36ab and 7068412b7c8d634b20471d6d312936a0ab32c5a0 this is now in master :)

kekeblom commented 5 years ago

Wow that was fast. Was actually planning to take a stab at this myself today.

Thanks a lot for the help!