Exemplo n.º 1
0
dmz::Boolean
dmz::EventModuleBasic::release_event_observer (
      const EventType &Type,
      const Mask &CallbackMask,
      EventObserver &observer) {

   Boolean result (False);

   const Handle ObsHandle (observer.get_event_observer_handle ());
   SubscriptionStruct *sub (_subscriptionTable.lookup (ObsHandle));

   if (sub) {

      if (CallbackMask & CreateMask) {

         EventObserverStruct *eos (sub->createTable.remove (Type.get_handle ()));

         if (eos) { eos->remove (ObsHandle); }
      }

      if (CallbackMask & CloseMask) {

         EventObserverStruct *eos (sub->closeTable.remove (Type.get_handle ()));

         if (eos) { eos->remove (ObsHandle); }
      }

      result = True;
   }

   return result;
}
Exemplo n.º 2
0
// Event Observer Interface
void
dmz::AudioPluginEventSimple::close_event (
      const Handle EventHandle,
      const EventType &Type,
      const EventLocalityEnum Locality) {

   EventType current (Type);
   EventStruct *es (0);

   while (!es && current) {

      es = _eventTable.lookup (current.get_handle ());

      if (!es) { current.become_parent (); }
   }
  
   if (es && es->sound) {

      EventModule *eventMod (get_event_module ());

      if (_audioMod && eventMod) {

         Vector pos;

         if (eventMod->lookup_position (EventHandle, _defaultEventHandle, pos)) {

            SoundInit init;
            SoundAttributes attributes;
            attributes.set_position (pos);
            _audioMod->play_sound (es->sound, init, attributes);
         }
      }
   }
}
Exemplo n.º 3
0
// EventModule Interface
dmz::Boolean
dmz::EventModuleBasic::register_event_observer (
      const EventType &Type,
      const Mask &CallbackMask,
      EventObserver &observer) {

   Boolean result (False);

   const Handle ObsHandle (observer.get_event_observer_handle ());
   SubscriptionStruct *sub (_subscriptionTable.lookup (ObsHandle));

   if (!sub) {

      sub = new SubscriptionStruct (observer);

      if (!_subscriptionTable.store (ObsHandle, sub)) { delete sub; sub = 0; }
   }

   if (sub) {

      if (CallbackMask & CreateMask) {

         EventObserverStruct *eos (
            _create_event_observers (Type.get_handle (), _createTable));

         if (eos && eos->store (ObsHandle, &observer)) {

            sub->createTable.store (Type.get_handle (), eos);
         }
      }

      if (CallbackMask & CloseMask) {

         EventObserverStruct *eos (
            _create_event_observers (Type.get_handle (), _closeTable));

         if (eos && eos->store (ObsHandle, &observer)) {

            sub->closeTable.store (Type.get_handle (), eos);
         }
      }

      result = True;
   }

   return result;
}
Exemplo n.º 4
0
/*!

\brief Removes event type with the given unique handle.
\param[in] TypeHandle Unique handle of event type to remove from the set.
\param[in] context Pointer to runtime context.
\return Returns dmz::True if event type was successfully remove from the set.

*/
dmz::Boolean
dmz::EventTypeSet::remove_event_type (const Handle TypeHandle, RuntimeContext *context) {

   Boolean result (False);

   EventType tmp (TypeHandle, context);

   EventType *ptr (_state.table.remove (tmp.get_handle ()));

   if (ptr)  { delete ptr; ptr = 0; result = True; }

   return result;
}
Exemplo n.º 5
0
// Event Observer Interface
void
dmz::RenderPluginEventOSG::close_event (
      const Handle EventHandle,
      const EventType &Type,
      const EventLocalityEnum Locality) {

   const Handle TypeHandle = Type.get_handle ();

   if (!_ignore.contains (TypeHandle)) {

      TypeStruct *ts = _get_type (EventHandle, Type);

      if (ts) { _create_event (EventHandle, *ts); }
   }
}
Exemplo n.º 6
0
/*!

\brief Removes event type from set.
\param[in] Type EventType to remove from the set.
\return Returns dmz::True if the type was removed from the set.

*/
dmz::Boolean
dmz::EventTypeSet::remove_event_type (const EventType &Type) {

   Boolean result (False);

   EventType *ptr (_state.table.remove (Type.get_handle ()));

   if (ptr)  {

      delete ptr; ptr = 0;
      result = True;
   }

   return result;
}
Exemplo n.º 7
0
dmz::Boolean
dmz::NetModulePacketCodecBasic::encode_event (
      const EventType &Type,
      const Handle EventHandle,
      Marshal &outData) {

   Boolean result (False);

   EncodeEventStruct *ees (_eventTypeTable.lookup (Type.get_handle ()));

   if (!ees) {

      EventType current (Type); current.become_parent ();

      while (!ees && current) {

         ees = _eventTypeTable.lookup (current.get_handle ());
         current.become_parent ();
      }
   }

   if (ees && _headerCodec) {

      const Int32 Place (outData.get_place ());
      if (_headerCodec->write_header (ees->PacketID, outData)) {

         if (ees->codec.encode_event (EventHandle, outData)) {

            outData.set_place (Place);
            result = _headerCodec->write_header (ees->PacketID, outData);
         }
      }
   }

   return result;
}
Exemplo n.º 8
0
/*!

\brief Adds event type with specified unique handle to the set.
\param[in] TypeHandle Unique handle of the event type to add to the set.
\param[in] context Pointer to the runtime context.
\return Returns dmz::True if the event type was successfully added to the set.

*/
dmz::Boolean
dmz::EventTypeSet::add_event_type (const Handle TypeHandle, RuntimeContext *context) {

   Boolean result (False);

   EventType *ptr (new EventType (TypeHandle, context));

   if (ptr && *ptr) {

      result = _state.table.store (ptr->get_handle (), ptr);

      if (!result) { delete ptr; ptr = 0; }
   }

   return result;
}
Exemplo n.º 9
0
/*!

\brief Tests if event type is stored in set.
\param[in] Type EventType to use in test.
\return Returns dmz::True if the \a Type or one of its parents is contained in the set.

*/
dmz::Boolean
dmz::EventTypeSet::contains_type (const EventType &Type) const {

   Boolean result (False);

   EventType current (Type);

   Boolean done (current ? False : True);

   while (!done) {

      if (_state.table.lookup (current.get_handle ())) { result = done = True; }
      else { current.become_parent (); if (!current) { done = True; } }
   }

   return result;
}
Exemplo n.º 10
0
//! Gets root event type.
dmz::EventType
dmz::Definitions::get_root_event_type () const {

   EventType result;

   if (_state.context && _state.defs) {

      EventType *ptr (_state.defs->eventNameTable.lookup (LocalRootEventTypeName));

      if (!ptr) {

         TypeContext *rootTypeContext = new TypeContext (
            LocalRootEventTypeName,
            _state.context,
            0,
            0);

         if (rootTypeContext) {

            ptr = new EventType (rootTypeContext);

            if (ptr && _state.defs->eventNameTable.store (ptr->get_name (), ptr)) {

               _state.defs->eventHandleTable.store (ptr->get_handle (), ptr);
            }
            else if (ptr) { delete ptr; ptr = 0; }

            rootTypeContext->unref ();
         }
      }

      if (ptr) { result = *ptr; }
   }

   return result;
}
Exemplo n.º 11
0
void
dmz::EventModuleBasic::_close_event (EventStruct &event) {

   EventType current (event.type);

   while (current) {

      EventObserverStruct *eos (_createTable.lookup (current.get_handle ()));

      if (eos) {

         HashTableHandleIterator it;

         EventObserver *obs (eos->get_first (it));

         while (obs) {

            obs->create_event (event.handle, event.type, event.locality);
            obs = eos->get_next (it);
         }
      }

      current.become_parent ();
   }

   event.closed = True;
   event.closeTime = _time.get_frame_time ();

   current = event.type;

   while (current) {

      EventObserverStruct *eos (_closeTable.lookup (current.get_handle ()));

      if (eos) {

         HashTableHandleIterator it;

         EventObserver *obs (eos->get_first (it));

         while (obs) {

            obs->close_event (event.handle, event.type, event.locality);
            obs = eos->get_next (it);
         }
      }

      current.become_parent ();
   }

   // Move to end of the table.
   if (_eventTable.remove (event.handle)) {

      if (!_eventTable.store (event.handle, &event)) {

         _log.error << "Internal error: Failed to save event: " << event.handle
            << " of type: " << event.type.get_name () << endl;
         _eventCache = 0; delete &event;
      }
   }
}
Exemplo n.º 12
0
/*!

\brief Tests if exact event type is stored in set.
\param[in] Type EventType to use in test.
\return Returns dmz::True if the \a Type is contained in the set.

*/
dmz::Boolean
dmz::EventTypeSet::contains_exact_type (const EventType &Type) const {

  return _state.table.lookup (Type.get_handle ()) != 0;
}
Exemplo n.º 13
0
void
dmz::NetModulePacketCodecBasic::_discover_codec (const Plugin *PluginPtr) {

   const String Name (PluginPtr ? PluginPtr->get_plugin_name () : "");

   NetExtPacketCodecObject *objCodec (NetExtPacketCodecObject::cast (PluginPtr));
   NetExtPacketCodecEvent *eventCodec (NetExtPacketCodecEvent::cast (PluginPtr));

   if (Name && (objCodec || eventCodec)) {

      PacketStruct *hs (_packetTable.lookup (Name));

      if (hs) {

         DecodeStruct *ds (0);
         if (objCodec) { ds = new DecodeStruct (hs->PacketID, *objCodec); }
         else if (eventCodec) { ds = new DecodeStruct (hs->PacketID, *eventCodec); }

         if (ds && _decodeTable.store (hs->PacketID, ds)) {

            if (objCodec && hs->objects.get_count ()) {

               EncodeObjectStruct *eos (
                  new EncodeObjectStruct (hs->PacketID, *objCodec));

               if (eos && _objEncodeTable.store (hs->PacketID, eos)) {

                  ObjectTypeIterator it;

                  ObjectType type;

                  Boolean found (hs->objects.get_first (it, type));

                  while (found) {

                     _objTypeTable.store (type.get_handle (), eos);
                     found = hs->objects.get_next (it, type);
                  }
               }
               else if (eos) { delete eos; eos = 0; }
            }
            else if (eventCodec && hs->events.get_count ()) {

               EncodeEventStruct *ees (
                  new EncodeEventStruct (hs->PacketID, *eventCodec));

               if (ees && _eventEncodeTable.store (hs->PacketID, ees)) {

                  EventTypeIterator it;

                  EventType type;

                  Boolean found (hs->events.get_first (it, type));

                  while (found) {

                     _eventTypeTable.store (type.get_handle (), ees);
                     found = hs->events.get_next (it, type);
                  }
               }
               else if (ees) { delete ees; ees = 0; }
            }
         }
         else if (ds) {

            delete ds; ds = 0;
         }
      }
   }
}