Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR restructures the Lua resources to provide a deferred lua execution method, such that services and the CLI can queue lua commands which get executed at one single, foreseeable point in the main loop.
Summary of Changes
main()
, twice a frame the lua queue gets processed: beforeRenderNextFrame()
, and insideRenderNextFrame()
before rendering of entry points (after services possibly issued lua commands)main()
moved to use deferred luaReferences and Context
This refactoring streamlines the Lua execution logic in the program, getting rid of project file and CLI Lua inputs confusion. This allows, for example, to load a project file and directly alter parameters of instantiated modules via CLI. At the same time, when taking control over the main loop via a lua project file, we remain outside of
RenderNextFrame()
. For the GUI, this allows for a strictly data-driven GUI re-design, decoupling of GUI event handling (before rendering of the frame) from rendering of the GUI draw list.Challenges
To keep the Lua execution outside of a frame, we need to flush the Lua queue before
RenderNextFrame()
. However, because services can issue Lua commands too (incoming network messages, keyboard/mouse + GUI inputs, resulting graph changes), Lua also needs to be flushed after service resource updates/digestion and before rendering of the graph. Having two Lua flushes leads to problems, e.g. Lua scripts coming from network get executed inside a frame, which is problematic when they containmmRenderNextFrame()
. However, not executing Lua after service updates ignores latest rendering state inputs for one frame, which seems even worse.Test Instructions
CLI project files, param changes, lua execution, order of lua commands is respected:
./megamol.exe -p ../examples/testspheres.lua --param ::data::numSpheres=100 --param ::view::anim::play=true -e "print(\"\n\nHello MegaMol\n\n.\"); print(mmHelp())"
Load other project file after 500 frames:
./megamol.exe -p ../examples/testspheres.lua --param ::data::numSpheres=100 --param ::view::anim::play=true -e "for i = 1,500,1; do mmRenderNextFrame(); end; mmClearGraph()" -p ../examples/infovis-spheres.lua
2023-04-17-18-33-06_Trim.mp4