Principles of Design -- Listeners and Events

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
paul424
Gnome
Posts: 314
Joined: Thu May 24, 2012 7:16 pm
x 13

Principles of Design -- Listeners and Events

Post by paul424 »

So far, when reading the code I see most of the time Frame and EvenSource are not universal classes, but the Listener class is added ad hoc inside existing one:

Code: Select all

   class _OgreExport MovableObject : public ShadowCaster, public AnimableObject, public MovableAlloc
    {
    public:
        /** Listener which gets called back on MovableObject events.
        */
        class _OgreExport Listener
        {
        public:
            Listener(void) {}
            virtual ~Listener() {}
            /** MovableObject is being destroyed */
            virtual void objectDestroyed(MovableObject*) {}
            /** MovableObject has been attached to a node */
            virtual void objectAttached(MovableObject*) {}
            /** MovableObject has been detached from a node */
            virtual void objectDetached(MovableObject*) {}
            /** MovableObject has been moved */
            virtual void objectMoved(MovableObject*) {}
            /** Called when the movable object of the camera to be used for rendering.
            @return
                true if allows queue for rendering, false otherwise.
            */
            virtual bool objectRendering(const MovableObject*, const Camera*) { return true; }
            /** Called when the movable object needs to query a light list.
Was there a specific reason not to create generic Listener and EventsGenerator classes?
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Principles of Design -- Listeners and Events

Post by spacegaier »

I guess having those listeners directly tied to the respectable classes/objects helps the performance, since less casting is involved as you already know what type of object/instance you are expecting and need to handle.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Post Reply