Not theft, but a loan

I was having a lot of difficulty reconciling a core object that does this:

Graphics2D g = screen.getGraphicsContext();

The core object gets the graphics context from another object and draws on it; does that make it a View? I thought it was the Controller. To me, it felt like GameCore was a thief and he was exploiting ScreenManager’s graphics context.

But actually there’s this line in gameLoop() method:


So GameCore is just borrowing the reference, drawing stuff on it, and disposing it; ScreenManager then updates with its buffering strategy. At that moment, the user sees something. That puts ScreenManager as the View. GameCore as a cooperating object “consults the controller” in a “view context” – acting as a View, GameCore-as-View – with the ScreenManager-as-Controller, employing draw() as a populating method and the graphics context as the “controller’s data fetched from a model.”

In AutoIt, it would be View.au3 iterating over a global array in Controller.au3 to populate an invisible ListView. In a sense, the graphics context is ScreenManager’s “global array.” The graphics context is the “global array” of ScreenManager-Controller with a (graphics device abstraction) model.

\#include <Model.au3>

Dim $gArrayInController = GetDataFromModel()

Func GetDataFromModel()
  Local $arr[1] = [ 0 ]
  DAOGetData($arr)  ; model function
  Return $arr

\#include <Controller.au3>
For $i = 1 To $gArrayInController[0]
  Dim $aSplit = StringSplit($gArrayInController[$i], ",")

  ; AutoIt idiom for ListView: populate first field of row,
  ; then the rest of the row
  PopulateFirstCol($listView, $i, $aSplit[1])  ; convenience function
  PopulateRestOfRow($listView, $i, $aSplit)    ; index 2..$aSplit[0]

| View ^
messages | Controller | data
v Model |
GameCore says to ScreenManager, “I know you’re the one who will display the screen; may I borrow your graphics context so that I can act as a View?”

Of especial relevance to this post is Dijkstra:

Brackeen is a godsend to game programming. A lot of folks would be thankful to him if they checked out his book.

Don’t worry – I don’t know what I wrote here, either.