Example #1
0
// NetExtPacketCodecObject Interface
dmz::Boolean
dmz::NetExtPacketCodecObjectNative::decode (Unmarshal &data, Boolean &isLoopback) {

   Boolean result (False);

   UUID uuid;
   data.get_next_uuid (uuid);

   isLoopback = (uuid == _SysID);

   if (!isLoopback && _objMod) {

      UUID objectID;
      data.get_next_uuid (objectID);
      const Int32 TypeSize (Int32 (data.get_next_int8 ()));

      Handle objectHandle (_objMod->lookup_handle_from_uuid (objectID));

      if (!TypeSize) {

         if (objectHandle) { _objMod->destroy_object (objectHandle); }
      }
      else {

         ArrayUInt32 typeArray (TypeSize);

         for (Int32 ix = 0; ix < TypeSize; ix++) {

            typeArray.set (ix, UInt32 (data.get_next_uint8 ()));
         }

         Boolean activateObject (False);

         if (!objectHandle) {

            ObjectType type;
            _attrMod->to_internal_object_type (typeArray, type);

            objectHandle = _objMod->create_object (type, ObjectRemote);

            if (objectHandle) {

               _objMod->store_uuid (objectHandle, objectID);
               activateObject = True;
            }
         }

         if (objectHandle) {

            result = True;

            ObjectAttributeAdapter *current (_adapterList);

            while (current) {

               current->decode (objectHandle, data, *_objMod);
               current = current->next;
            }

            if (activateObject) { _objMod->activate_object (objectHandle); }

            _objMod->store_time_stamp (objectHandle, _lnvHandle, _time.get_frame_time ());
         }
      }
   }

   return result;
}
// NetExtPacketCodecObject Interface
dmz::Boolean
dmz::NetExtPacketCodecObjectBasic::decode (Unmarshal &data, Boolean &isLoopback) {

   Boolean result (False);

   isLoopback = False;

   if (_attrMod && _objMod) {

      UUID uuid;
      data.get_next_uuid (uuid);

      if (_SysID == uuid) {

         isLoopback = True;
      }
      else {

         data.get_next_uuid (uuid);

         Vector pos;
         Matrix ori;
         Vector vel;
         ArrayUInt32 typeArray;
         ArrayUInt32 stateArray;

         data.get_next_vector (pos);
         data.get_next_matrix (ori);
         data.get_next_vector (vel);
         typeArray.set (0, data.get_next_uint32 ());
         typeArray.set (1, data.get_next_uint32 ());
         typeArray.set (2, data.get_next_uint32 ());
         stateArray.set (0, data.get_next_uint32 ());

         ObjectType type;

         _attrMod->to_internal_object_type (typeArray, type);

         Handle handle (_objMod->lookup_handle_from_uuid (uuid));

         Boolean activateObject (False);

         if (type && !handle) {

            handle = _objMod->create_object (type, ObjectRemote);

            if (handle) {

               _objMod->store_uuid (handle, uuid);
               activateObject = True;
            }
         }

         if (handle) {

            Mask state;
            _objMod->lookup_state (handle, _defaultHandle, state);
            _attrMod->to_internal_object_mask (type, stateArray, state);

            if (_deactivateState && state.contains (_deactivateState)) {

               _objMod->destroy_object (handle);
            }
            else {

               _objMod->store_position (handle, _defaultHandle, pos);
               _objMod->store_position (handle, _lnvHandle, pos);
               _objMod->store_orientation (handle, _defaultHandle, ori);
               _objMod->store_velocity (handle, _defaultHandle, vel);
               _objMod->store_state (handle, _defaultHandle, state);
               _objMod->store_time_stamp (handle, _lnvHandle, _time.get_frame_time ());

               const Handle ScalarCount (data.get_next_uint32 ());

               if (ScalarCount) {

                  for (UInt32 ix = 0; ix < ScalarCount; ix++) {

                     const Handle NetHandle = data.get_next_uint32 ();
                     const Float64 Value = data.get_next_float64 ();

                     ScalarStruct *ss = _scalarTable.lookup (NetHandle);

                     if (ss && ss->AttrHandle) {

                        _objMod->store_scalar (handle, ss->AttrHandle, Value);
                     }
                  }
               }

               if (activateObject) { _objMod->activate_object (handle); }
            }

            result = True;
         }
      }
   }

   return result;
}