dmz::Boolean
dmz::NetModulePacketCodecBasic::register_object (
      const Handle ObjectHandle,
      const ObjectType &Type,
      Marshal &outData) {

   Boolean result (False);

   _objTable.remove (ObjectHandle);

   ObjectType current (Type);

   EncodeObjectStruct *eos (0);

   do {

      eos = _objTypeTable.lookup (current.get_handle ());
      current.become_parent ();

   } while (current && !eos);

   if (ObjectHandle && eos && _objTable.store (ObjectHandle, eos)) {

      result = _write_object (ObjectHandle, NetObjectActivate, outData);
   }

   return result;
}
Esempio n. 2
0
int CJSONValue::GetCount (void) const

//	GetCount
//
//	Returns the number of elements

	{
	switch (m_iType)
		{
		case typeNull:
			return 0;

		case typeArray:
			{
			ArrayType *pArray = (ArrayType *)m_pValue;
			return pArray->GetCount();
			}

		case typeObject:
			{
			ObjectType *pObj = (ObjectType *)m_pValue;
			return pObj->GetCount();
			}

		default:
			return 1;
		}
	}
Esempio n. 3
0
inline ObjectType* ObjectHeap< ObjectType >::AllocateFresh( void )
{
	ObjectType* object = Allocate();
	if( object )
		object->Reset();
	return object;
}
Esempio n. 4
0
bool CJSONValue::FindElement (const CString &sKey, CJSONValue *retValue) const

//	FindElement
//
//	Finds a field in a structure

	{
	switch (m_iType)
		{
		case typeObject:
			{
			ObjectType *pObj = (ObjectType *)m_pValue;

			CJSONValue *pValue = pObj->GetAt(sKey);
			if (pValue == NULL)
				return false;

			if (retValue)
				*retValue = *pValue;

			return true;
			}

		default:
			return false;
		}
	}
Esempio n. 5
0
dmz::Boolean
dmz::NetModuleLocalDRBasic::update_object (const Handle ObjectHandle) {

   Boolean result (False);

   if (_objMod) {

      const ObjectType Type (_objMod->lookup_object_type (ObjectHandle));

      if (Type) {

         ObjectUpdate *test (_typeTable.lookup (Type.get_handle ()));

         if (!test) { test = _create_test_from_type (Type); }

         Boolean limitRate (False);

         while (test && !result && !limitRate) {

            result = test->update_object (ObjectHandle, *_objMod, limitRate);
            test = test->next;
         }
      }
   }

   return result;
}
dmz::Boolean
dmz::QtPluginCanvasObjectBasic::_find_config_from_type (
      Config &local,
      ObjectType &objType) {

   const String Name (get_plugin_name ());

   Boolean found (objType.get_config ().lookup_all_config_merged (Name, local));

   if (!found) {

      ObjectType currentType (objType);
      currentType.become_parent ();

      while (currentType && !found) {

         if (currentType.get_config ().lookup_all_config_merged (Name, local)) {

            found = True;
            objType = currentType;
         }

         currentType.become_parent ();
      }
   }

   return found;
}
dmz::QtPluginCanvasObjectBasic::ModelStruct *
dmz::QtPluginCanvasObjectBasic::_get_model_struct (const ObjectType &ObjType) {

   ModelStruct *retVal (_masterModelTable.lookup (ObjType.get_handle ()));

   if (!retVal) {

      Config local;
      ObjectType currentType (ObjType);

      if (_find_config_from_type (local, currentType)) {

         ModelStruct *ms (_modelTable.lookup (currentType.get_handle ()));

         if (!ms) {

            ms = _config_to_model_struct (local, currentType);

            if (ms) {

               _modelTable.store (ms->ObjType.get_handle (), ms);
            }
         }

         retVal = ms;
      }
   }

   if (retVal) {

      _masterModelTable.store (ObjType.get_handle (), retVal);
   }

   return retVal;
}
Esempio n. 8
0
static Rect worldToScreenCoords(const Point3f &_position, const ObjectType &_type, const Point2f &fov_size, const Size &frame_size, float cameraElevation)
{
	// TODO : replace magic numbers with an object depth property
	// This constant is half a ball diameter (9.75-ish inches), converted to meters
	// For example, goals will have 0 depth since we're just shooting at
	// a plane. 3d objects will have depth, though, so we track the center of the
	// rather than the front.
	float r = sqrtf(_position.x * _position.x + _position.y * _position.y + _position.z * _position.z); // - (4.572 * 25.4)/1000.0;
	float azimuth = asinf(_position.x / sqrt(_position.x * _position.x + _position.y * _position.y));
	float inclination = asinf( _position.z / r ) + cameraElevation;

	//inverse of formula in screenToWorldCoords()
	Point2f dist_to_center(
			tan(azimuth) * (0.5 * frame_size.width / tan(fov_size.x / 2)),
			tan(inclination) * (0.5 * frame_size.height / tan(fov_size.y / 2)));
	
	cout << "Distance to center: " << dist_to_center << endl;
	Point2f rect_center(
			dist_to_center.x + (frame_size.width / 2.0),
			-dist_to_center.y + (frame_size.height / 2.0));

	Point2f angular_size( 2.0 * atan2f(_type.width(), (2.0*r)), 2.0 * atan2f(_type.height(), (2.0*r)));
	Point2f screen_size(
			angular_size.x * (frame_size.width / fov_size.x),
			angular_size.y * (frame_size.height / fov_size.y));

	Point topLeft(
			cvRound(rect_center.x - (screen_size.x / 2.0)),
			cvRound(rect_center.y - (screen_size.y / 2.0)));
			return Rect(topLeft.x, topLeft.y, cvRound(screen_size.x), cvRound(screen_size.y));
}
Esempio n. 9
0
const CJSONValue &CJSONValue::GetElement (int iIndex) const

//	GetElement
//
//	Returns the element by index

	{
	switch (m_iType)
		{
		case typeArray:
			{
			ArrayType *pArray = (ArrayType *)m_pValue;
			if (iIndex < 0 || iIndex >= pArray->GetCount())
				return g_NullValue;

			return pArray->GetAt(iIndex);
			}

		case typeObject:
			{
			ObjectType *pObj = (ObjectType *)m_pValue;
			if (iIndex < 0 || iIndex >= pObj->GetCount())
				return g_NullValue;

			return pObj->GetValue(iIndex);
			}

		default:
			return g_NullValue;
		}
	}
Esempio n. 10
0
void
ObjectType::setLayout(ObjectTypeLayout* l)
{
    if (!l) {
        cerr << "[WARNING] ObjectType::setLayout: Cannot set layout to 0." << endl;
        return;
    }

    if (layout()) {
        if (layout() != l) {
            cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring();
            cerr << "' on ObjectType '" << objectName().cstring() << "', which already has a layout." << endl;
        }
        return;
    }

    ObjectType* oldParent = l->parent();
    if (oldParent && oldParent != this) {
        if (oldParent->isLayoutType()) {
            cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring();
            cerr << "' on ObjectType '" << objectName().cstring() << "', when the ObjectTypeLayout already has a parent layout." << endl;
            return;
        } else {
            // Steal the layout from an ObjectType parent.
            oldParent->takeLayout();
        }
    }

    m_layout = l;
    if (oldParent != this) {
        l->setParent(this);
        l->reparentChildren(this);
    }
}
Esempio n. 11
0
void Module::setSpecification(const ObjectType& parent, const ObjectType& child)
{
    if (!parent.typeTemplate().isVirtual()) {
        Log::error("Cannot forward ",parent," to ",child," because ",parent.typeTemplate(), " is not virtual ");
    }
    const ObjectType* parentPtr = new ObjectType(parent);
    _automaticSpecifications.insert(std::make_pair(parentPtr, child));
}
Esempio n. 12
0
ObjectType*
ObjectType::createWithChild()
{
    ObjectType* parent = create();
    ObjectType* child = create();
    child->setObjectName("child");
    child->setParent(parent);
    return parent;
}
Esempio n. 13
0
void ObjectTypeManager::setupObject(IGObject::Ptr obj, uint32_t type){
  if(checkValid(type)){
    ObjectType* prototype = typeStore[type];
    obj->setType(type);
    prototype->setupObject(obj);
  }else{
    //TODO throw exception?
  }
}
Esempio n. 14
0
// QtPluginIconPalletTool Interface
void
dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) {

   const String IconResource = config_to_string (
      get_plugin_name () + ".resource",
      Type.get_config());

   const String IconName = _rc.find_file (IconResource);

   if (IconName) {

      const String Name = Type.get_name ();

      if (Name) {

         QImage back (
            (int)_iconExtent,
            (int)_iconExtent,
            QImage::Format_ARGB32_Premultiplied);
         QPainter painter (&back);
         painter.setCompositionMode (QPainter::CompositionMode_Source);
         painter.fillRect (back.rect (), Qt::transparent);
         painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
         QSvgRenderer qsr (QString (IconName.get_buffer ()));
         QRectF size = qsr.viewBoxF ();
         qreal width = size.width ();
         qreal height = size.height ();
         qreal scale = (width > height) ? width : height;
         if (scale <= 0.0f) { scale = 1.0f; }
         scale = _iconExtent / scale;
         width *= scale;
         height *= scale;
         size.setWidth (width);
         size.setHeight (height);
         if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); }
         if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); }
         qsr.render (&painter, size);
         painter.end ();
         QIcon icon;
         icon.addPixmap (QPixmap::fromImage (back));
         QStandardItem *item = new QStandardItem (icon, Name.get_buffer ());
         item->setEditable (false);
         _model.appendRow (item);
      }
   }
   else if (IconResource) {

      _log.error << "Unable to find icon resource: " << IconResource
          << " for object type: " << Type.get_name () << endl;
   }

   RuntimeIterator it;
   ObjectType next;

   while (Type.get_next_child (it, next)) { _add_type (next); }
}
Esempio n. 15
0
void
dmz::QtPluginCanvasObject::_init (Config &local, Config &global) {

   _canvasModuleName = config_to_string ("module.canvas.name", local);

   Config pluginList;

   if (local.lookup_all_config ("plugins.plugin", pluginList)) {

      RuntimeContext *context (get_plugin_runtime_context ());

      if (dmz::load_plugins (context, pluginList, local, global, _extensions, &_log)) {

         _extensions.discover_plugins ();
      }
   }

   _defaultAttributeHandle = activate_default_object_attribute (
      ObjectCreateMask |
      ObjectDestroyMask |
      ObjectPositionMask |
      ObjectOrientationMask);

   _linkAttributeHandle = activate_object_attribute (
      ObjectAttributeLayerLinkName,
      ObjectLinkMask | ObjectUnlinkMask);

#if 0
   Config preLoadList;

   if (local.lookup_all_config ("preload", preLoadList)) {

      Config data;
      ConfigIterator it;

      Boolean done (!preLoadList.get_first_config (it, data));

      while (!done) {

         ObjectType objType;
         Mask objState;

         if (_defs.lookup_object_type (config_to_string ("type", data), objType)) {

            _defs.lookup_state (config_to_string ("state", data), objState);

            _log.info << "Pre-Loading object of type: " << objType.get_name () << endl;
            _get_model_struct (objType, objState);
         }

         done = !preLoadList.get_next_config (it, data);
      }
   }
#endif
}
Esempio n. 16
0
//------------------------------------------------------------------------------
void ObjectTypeDatabase::unregisterType(const ObjectType & t)
{
    if (t.getID() < m_types.size())
    {
        m_types[t.getID()] = nullptr;
    }
    else
    {
        SN_ERROR("ObjectTypeDatabase::unregisterType: type not found (" << t.toString() << ")");
    }
}
Esempio n. 17
0
void Module::setExtension(const ObjectTypeTemplate &childTemplate, const ObjectType &parent, const std::map<int, int> &parameterMapping)
{
    setExtension(childTemplate, [parent, parameterMapping](const ObjectType& type)
    {
        ObjectType father = parent;
        for(const auto& binding : parameterMapping)
        {
            father.setParameter(binding.second, type.parameterValue(binding.first));
        }
        return father;
    });
}
Esempio n. 18
0
void digidoc::dsig::operator<< (DOMElement &e, const ObjectType &i)
{
    e << static_cast<const ObjectTypeBase&>(i);

    for(ObjectType::QualifyingPropertiesConstIterator b = i.qualifyingProperties().begin();
        b != i.qualifyingProperties().end(); ++b)
    {
        DOMElement &s(
            xsd::cxx::xml::dom::create_element("QualifyingProperties", "http://uri.etsi.org/01903/v1.3.2#", e));
        s << *b;
    }
}
Esempio n. 19
0
void CJSONValue::Insert (const CString &sKey, const CJSONValue &Source)

//	Insert
//
//	Appends to a key to a structure

	{
	ASSERT(m_iType == typeObject);
	ObjectType *pObj = (ObjectType *)m_pValue;

	pObj->Insert(sKey, Source);
	}
Esempio n. 20
0
bool Module::isExtension(const ObjectType& child, const ObjectType& parent) const
{
    if(child.extendsDirectly(parent))
        return true;

    ObjectType father = getFather(child);

    if(!father.isNull())
        return isExtension(father, parent);

    return false;
}
Esempio n. 21
0
ItemUI::ItemUI(uint16_t id) : ThingUI()
{
	m_id = id;
	ObjectType* obj = Objects::getInstance()->getItemType(id);

	if(id < 100 || !obj){
		DEBUGPRINT(DEBUGPRINT_ERROR, DEBUGPRINT_LEVEL_OBLIGATORY, "[ItemUI::ItemUI] Invalid item %d\n", id);
		return;
	}

    obj->loadGfx();
    obj->instancesOnMap++;
}
Esempio n. 22
0
int64_t StructTypeTemplate::fixedSize(const ObjectType &type) const
{
    int s = 0;
    for (int i = 1; i < type.numberOfParameters(); i += 2) {
        int t = type.parameterValue(i).toObjectType().fixedSize();
        if (t != -1) {
            s += t;
        } else {
            return -1;
        }
    }
    return s;
}
Esempio n. 23
0
void CJSONValue::InsertHandoff (const CString &sKey, CJSONValue &Source)

//	InsertHandoff
//
//	Appends to a key to a structure

	{
	ASSERT(m_iType == typeObject);
	ObjectType *pObj = (ObjectType *)m_pValue;

	CJSONValue *pNewValue = pObj->Insert(sKey);
	pNewValue->TakeHandoff(Source);
	}
Esempio n. 24
0
// RenderPluginEventOSG Interface
dmz::RenderPluginEventOSG::TypeStruct *
dmz::RenderPluginEventOSG::_get_type (
      const Handle EventHandle,
      const EventType &Type) {

   TypeStruct *result (0);

   EventModule *module = get_event_module ();

   TypeTable *table (0);

   EventType event (Type);

   while (event && !result) {

      TypeTable *table = _get_type_table (Type);

      if (table) {

         ObjectType current;

         if (module) {

            module->lookup_object_type (EventHandle, table->TypeAttr, current);
         }

         const ObjectType Start (current);

         while (current && !result) {

            result = table->map.lookup (current.get_handle ());

            if (!result) {

               result = _create_type (EventHandle, event, current, *table);
            }

            if (!result) { current.become_parent (); }
         }

         if (result && (current != Start)) {

            table->map.store (Start.get_handle (), result);
         }
      }

      if (!result) { event.become_parent (); }
   }

   return result;
}
Esempio n. 25
0
ObjectType Module::specify(const ObjectType &parent) const
{
    ObjectType child = specifyLocally(parent);

    if(child.isNull())
    {
        for(const Module* module : reverse(_importedModules))
        {
            child = module->specify(parent);
            if(!child.isNull())
                return child;
        }
    }
    return child;
}
Esempio n. 26
0
ItemUI::~ItemUI()
{
    if (!Objects::getInstance()->isLoaded()) {
        printf("Destroying item %d after dat was unloaded\n", m_id);
        return;
    }
    ObjectType* obj = Objects::getInstance()->getItemType(m_id);
    if (obj) {
		if(obj->instancesOnMap){
			obj->instancesOnMap--;
			if (!obj->instancesOnMap) obj->unloadGfx();
		} else {
		}
    }
}
Esempio n. 27
0
ObjectType Module::specifyLocally(const ObjectType& parent) const
{
    auto it = _specializers.find(const_cast<ObjectTypeTemplate*>(&parent.typeTemplate()));
    if (it == _specializers.end())
    {
        return ObjectType();
    }

    ObjectType type = it->second.specialize(parent);
    if (!type.isNull())
    {
        type.importParameters(parent);
    }

    return type;
}
Esempio n. 28
0
void Module::setSpecification(const ObjectType& parent, const ObjectType& child)
{
    if (!parent.typeTemplate().isVirtual()) {
        Log::error("Cannot forward ",parent," to ",child," because ",parent.typeTemplate().name(), " is not virtual ");
    }
    const ObjectType* parentPtr = new ObjectType(parent);
    _automaticSpecifications.insert(std::make_pair(parentPtr, child));

    auto it = _specializers.find(const_cast<ObjectTypeTemplate*>(&parent.typeTemplate()));
    if (it == _specializers.end()) {        
        _specializers.emplace(std::piecewise_construct, std::make_tuple(const_cast<ObjectTypeTemplate* >(&parent.typeTemplate())), std::make_tuple(parent, child));
    } else {
        it->second.forward(parent, child);
    }

}
Esempio n. 29
0
ObjectType Module::specifyLocally(const ObjectType& parent) const
{
    ObjectType type;
    ObjectType rangeBegin(parent.typeTemplate());
    for(SpecificationMap::const_iterator it = _automaticSpecifications.lower_bound(&rangeBegin);
        it != _automaticSpecifications.end() && it->first->typeTemplate() == parent.typeTemplate();
        ++it)
    {
        if(parent.extendsDirectly(*(it->first)))
        {
            type = it->second;
            type.importParameters(parent);
            break;
        }
    }
    return type;
}
Esempio n. 30
0
Variant StructTypeTemplate::attributeValue(const ObjectType &type, ObjectTypeTemplate::Attribute attribute) const
{
    if (attribute == ObjectTypeTemplate::Attribute::name) {
        return type.parameterValue(0);
    } else {
        return Variant();
    }
}