This is impressive!

Btw, we should take the Morphic discussion to squeak-dev. It's pretty much irrelevant to vm-dev.

On 06.02.2014, at 17:36, gettimothy <gettimothy@zoho.com> wrote:

Event forwarding

    1. What I call "primitive events" are much easier to use (for me) than un-wrapping morphic events.

They're not. All the pain you're going through (particularly in your point 5 below) is because you're trying to somehow preserve low-level events.

    2. I modified HandMorph by adding a primitiveEventListener framework that mimics the existing HandMorph >> addEventListener:/sendListenEvent:to:/handleListenEvent: framwork.
       
       See HandMorph >> addPrimitiveEventListener:/sendListenPrimitiveEvent:to:/handleListenPrimitiveEvent.
      
        For morphic events, listener notification happens in HandMorph >>  handleEvent. For the primitiveEvents, I had to use HandMorph >> processEvents.

Brave, yet completely unnecessary ;)

    3. If this is un-acceptable, then the task of 'decoding' the Morphic Events that HandMorph creates in HandMorph >> processEvents needs to be done.
        I prefer to not do it as it is ugly.

It will be much easier if you don't think of this as "decoding" to "get back the original events". Forget that your simulator is running on a Squeak VM. Forget that at some point there were low-level events. This is completely irrelevant and just distracting. Think of the morphic events that your Morph receives as the primary input source. *Generate* your own VM events from these morphic events. Much simpler and much more clear.

    4. Primitive events from HandMorph are passed to StackInterpreterSimulatorMorphicModel after being registered with HandMorph.
       1. The StackIterpreterSimulatorMorph >> displayView registers the model with the HandMorph for event notification.

    5. StackInterpreterSimulatorMorphicModel >> handleListenPrimitiveEvent: evtBuf is where event translation and filtering happens.
       1. This needs a deft hand. Preferrably by somebody who is familiar with Morhic bounds translations. I briefly looked at it and its a deep subject, so I ran away screaming.
       2. You can un-comment some code to see the raw events on the transcript. I found this handy.
       3. EventSensorConstants has a list of other events that you may want to forward.

The problem here is that you are trying to circumvent morphic event handling, rather than using it.

    6. Event's are queued in StackInterpreterSimulatorMorphicModel >> handleListenPrimitiveEvent: and dequeued in StackInterpreterSimulator >> ioGetNextEvent.

Maybe this helps: Your host VM may or may not run using the event primitives. It might use the polling primitives. Morphic runs fine on both. So in some cases it's not even *possible* to use the "original VM events". 

- Bert -