Tuesday 7 June 2016

Immediate-Mode as a Programming Paradigm?


So, I needed to implement some sort of GUI (graphical user interface) in the FireStorm (v2) engine framework, and my previous effort had been to cobble together a custom solution, which was basically a classic Retained-Mode Gui, where we create a bunch of 'widget objects' upfront, that might be visible, and might not be, and often holds lots of redundant state.

I was recently re-introduced to 'Dear ImGui', an immediate-mode gui library, which does things very differently - basically, under the immediate-mode paradigm, the items we work with never 'exist as objects', unless they are actually being referenced... conceptually, if we choose not to draw something, it does not exist, and contains no state either way.
Updating the logic for gui widgets under a retained-mode system is not the responsibility of each widget, since they don't exist, but the responsibility of the system framework... when we 'draw' each widget, we can update its logic at the same time, and depending on the result, choose to do (whatever), including actually displaying it. The gui code becomes highly 'lexically-scoped', and is a really good fit with most modern scripting languages.
In fact, I found myself able to edit my gui script with itself, within minutes of working with a well-designed immediate-mode GUI.

Which brings me to my point.

Classical GUI are typically hierarchical, tree-structured things, which got me thinking, if the immediate-mode works so well with GUI, and allows us to break the shackles of the traditional model of retained-mode object hierarchies, what ELSE can we use it for?



2 comments:

  1. As someone who once wrote an entire widget framework and wysiwyg editor to get away from immediate mode, you're off your rocker....or I was off my rocker....one of us is off their rocker.

    I get that IM has it's advantages, but developer productivity isn't one of them. After typing out the same 4 or 5 lines to get a stateful text box in a dozen different places in the same module, abstraction becomes a very desirable concept...that's where you write a 'helper' method and before you know it....bam! Widgets.

    Ahren M

    ReplyDelete
  2. Ahren, Thanks for your input! I've just managed to successfully (and quickly) implement AI Behavior Trees using the Immediate Mode programming paradigm, rather than retained-mode Node Objects, there are simply functions that simulate node hierarchies. I was more interested in the paradigm, though I did mentioned the gui example specifically, it was because that is where I got the idea to apply IM to something other than gui.

    ReplyDelete