Example #1
0
   bool EntityManager::GetDerived(EntityId eid, ComponentType ctype, Component*& comp) const
   {

      std::pair<TypeHierarchyMap::const_iterator, TypeHierarchyMap::const_iterator> keyRange;
      keyRange = mTypeHierarchy.equal_range(ctype);

      TypeHierarchyMap::const_iterator it = keyRange.first;
      while(it != keyRange.second)
      {
         dtEntity::EntitySystem* es;
         bool success = this->GetEntitySystem(it->second, es);
         if(!success)
         {
            LOG_ERROR("Error in type hierarchy structure! Cannot find entity system " << GetStringFromSID(it->second));
            continue;
         }

         if(es->GetComponent(eid, comp))
         {
            return true;
         }

         if(GetDerived(eid, es->GetComponentType(), comp))
         {
            return true;
         }

         ++it;
      }
      return false;
   }
Example #2
0
 bool EntityManager::HasComponent(EntityId eid, ComponentType t, bool searchDerived) const
 {
    EntitySystem* es;
    if(GetEntitySystem(t, es) && es->HasComponent(eid))
    {
       return true;
    }
    if(searchDerived)
    {
       dtEntity::Component* c;
       return GetDerived(eid, t, c);
    }
    return false;
 }
Example #3
0
 bool EntityManager::GetComponent(EntityId eid, ComponentType t, Component*& component, bool searchDerived)
 {
    EntitySystem* es;
    
    if(GetEntitySystem(t, es) && es->GetComponent(eid, component))
    {
       return true;
    }
    if(searchDerived)
    {
       return GetDerived(eid, t, component);
    }
    return false;
 }
Example #4
0
// virtual
void Properties::PropertyListener::handleEvent(System::Event* evt)
{
#if WIN32
	if (evt->get_eventPhase() != System::CAPTURING_PHASE)
	{
		if (*evt->get_type() == L"contextmenu")
		{
			evt->stopPropagation();
			UI::MouseEvent* mouseEvt = static_cast<UI::MouseEvent*>(evt);

			UI::CLXUIMenuElement* menu = new UI::CLXUIMenuElement();
		//	menu->SetRParent(m_ctledit);
			menu->SetOwnerWindow(mouseEvt->GetOwnerWindow());

			menu->addEventListener(WSTR("command"), this, false);

			if (false)
			{
				menu->AddItem(new UI::TextString(WSTR("Display As Table")), 100);
			}
			else
			{
				Type* pType = m_pProperty->get_method->m_decl->m_pType->GetFunction()->m_pReturnType;

				if (pType->get_Kind() == type_pointer && pType->GetPointerTo()->get_Kind() == type_class)
				{
					vector<ClassType*> list;
					GetDerived(pType->GetPointerTo()->GetClass(), list);

					for (int i = 0; i < list.GetSize(); i++)
					{
						ClassType* pDerived = list[i];
						if (pDerived->m_derived.GetSize() == 0)
						{
							menu->AddItem(new UI::TextString(pDerived->get_Name()->ToStringW()), (long)pDerived);
						}
					}
				}
			}

			menu->GetMenuPopup()->Popup(menu, LDraw::PointI(mouseEvt->get_ScreenX(), mouseEvt->get_ScreenY()));
		}
		else if (*evt->get_type() == L"command")
		{
			if (false)
			{
				m_bDisplayAsTable = !m_bDisplayAsTable;
			}
			else
			{
				evt->stopPropagation();
				UI::CommandInvokeEvent* cmdEvt = dynamic_cast<UI::CommandInvokeEvent*>(evt);

				long param = cmdEvt->get_Command();
				ClassType* pDerivedType = (ClassType*)param;

				void* p = newobj(pDerivedType);
				if (p)
				{
					Type* pType = m_pProperty->set_method->m_decl->m_pType->GetFunction()->m_parameters.m_parameters[0].m_pType;
					pType = pType->GetStripped();
					void* value = DynamicCast(p, pDerivedType, pType->GetPointerTo()->GetClass());

					ASSERT(0);
					void *_this = NULL;//__RTDynamicCast(m_itemVisual, 0, (void*)&typeid(m_itemVisual), (void*)m_pProperty->set_method->GetTypeInfo(), 0);

				//	StringA str_type = pType->ToString();

					ULONG_PTR func;
					if (m_pProperty->set_method->m_decl->m_offset != -1)
					{
						void* vtable = *(void**)_this;
						func = *(ULONG_PTR*)((uint8*)vtable + m_pProperty->set_method->m_decl->m_offset);
					}
					else
					{
						func = m_pProperty->set_method->m_func;
					}

					__asm
					{
						push ecx
						mov ecx,_this
						push value
						call func
						pop ecx
					}
				}
			}
		}

#if 0
		void *_this = __RTDynamicCast(m_itemVisual, 0, (void*)&typeid(m_itemVisual), (void*)put_type_info(), 0);

		cpp::Type* pType = put_decl->m_pType->m_pFunction->m_parameters[0]->m_pType;
		StringA str_type = pType->toString();
		pType = pType->GetType();

		DWORD func;
		if (put_decl->m_offset != -1)
		{
			void* vtable = *(void**)_this;
			func = *(DWORD*)((uint8*)vtable + put_decl->m_offset);
		}
		else
		{
			func = put_func;
		}

		if (*evt->get_type() == L"contextmenu")
		{
			evt->stopPropagation();
			UI::MouseEvent* mouseEvt = dynamic_cast<MouseEvent*>(evt);

			if (pType->m_type == cpp::type_pointer && pType->m_pPointerTo->m_type == cpp::type_class)
			{
				CLXUIMenuElement* menu = new CLXUIMenuElement();
				menu->SetRParent(m_ctledit);
				menu->SetOwnerWindow(m_ctledit->get_OwnerWindow());
				
				std::map<StringA, cpp::Type*>::iterator it = pD->m_namedTypes.begin();
				while (it != pD->m_namedTypes.end())
				{
					cpp::Type* pType2 = (*it).second;
					ASSERT(pType2);
					it++;

					if (pType2->m_type == cpp::type_class)
					{
						if (pType2->m_pClass->IsOfType(pType->m_pPointerTo->m_pClass))
						{
						//	pType2->m_pClass->IsOfType(pType->m_pPointerTo->m_pClass);
							menu->AddItem(new TextString(ConvertA2S(pType2->m_pClass->m_name)), (long)pType2);
						}
					}
				}

				menu->GetMenuPopup()->Popup(menu, LDraw::PointI(mouseEvt->get_ScreenX(), mouseEvt->get_ScreenY()));
			}
		}
		else if (*evt->get_type() == L"command")
		{
			evt->stopPropagation();
			CommandInvokeEvent* cmdEvt = dynamic_cast<CommandInvokeEvent*>(evt);

			long param = cmdEvt->get_Command();

			if (pType->m_type == cpp::type_enum)
			{
				__asm
				{
					push ecx
					mov ecx,_this
					push param
					call func
					pop ecx
				}
			}
			else
			{
				cpp::Type* pType2 = (cpp::Type*)param;

				void* object = newobj(pType2->m_pClass);
				Type_Info* src = (Type_Info*)pD->LookupSymbol(DecorateName(pType2->m_pClass->m_name));
				Type_Info* dst = (Type_Info*)pD->LookupSymbol(DecorateName(pType->m_pPointerTo->m_pClass->m_name));

				void* param = __RTDynamicCast(object, 0, src, dst, 0);

				__asm
				{
					push ecx
					mov ecx,_this
					push param
					call func
					pop ecx
				}
			}
		}
		else if (*evt->get_type() == L"ValueChange")