本文整理汇总了C++中ComponentPtr::TypeName方法的典型用法代码示例。如果您正苦于以下问题:C++ ComponentPtr::TypeName方法的具体用法?C++ ComponentPtr::TypeName怎么用?C++ ComponentPtr::TypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComponentPtr
的用法示例。
在下文中一共展示了ComponentPtr::TypeName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CloneComponent
ComponentPtr ComponentManager::CloneComponent(const ComponentPtr &component)
{
ComponentFactoryMap::const_iterator iter = factories_.find(component->TypeName());
if (iter == factories_.end())
return ComponentPtr();
ComponentPtr newComponent = (*iter->second.get())(component);
return newComponent;
}
示例2: AddComponent
bool ComponentGroup::AddComponent(ComponentPtr comp)
{
PROFILE(ComponentGroup_AddComponent);
//Check if the component have already added to component group or it's name or type are different for the component group.
if(ContainsComponent(comp) || comp->Name() != name_ || comp->TypeName() != typeName_)
return false;
components_.push_back(ComponentWeakPtr(comp));
editor_->AddNewComponent(comp);
return true;
}
示例3: QTreeWidgetItem
ComponentItem::ComponentItem(const ComponentPtr &comp, EntityItem *parent) :
QTreeWidgetItem(parent),
parentItem(parent),
ptr(comp),
typeId(comp->TypeId()),
typeName(comp->TypeName()),
name(comp->Name())
{
SetText(comp.get());
}
示例4: AddComponent
void Entity::AddComponent(component_id_t id, const ComponentPtr &component, AttributeChange::Type change)
{
// Must exist and be free
if (component && component->ParentEntity() == 0)
{
if (!id)
{
bool authority = true;
if (scene_)
authority = scene_->IsAuthority();
// Loop until we find a free ID
for (;;)
{
if (authority)
id = component->IsReplicated() ? idGenerator_.AllocateReplicated() : idGenerator_.AllocateLocal();
else
id = component->IsReplicated() ? idGenerator_.AllocateUnacked() : idGenerator_.AllocateLocal();
if (components_.find(id) == components_.end())
break;
}
}
else
{
component->SetReplicated(id < UniqueIdGenerator::FIRST_LOCAL_ID);
// If component ID is specified manually, but it already exists, it is an error. Do not add the component in that case.
if (components_.find(id) != components_.end())
{
LogError("Can not add component: a component with id " + QString::number(id) + " already exists in entity " + ToString());
return;
}
// Whenever a manual replicated ID is assigned, reset the ID generator to the highest value to avoid unnecessary free ID probing in the future
if (id < UniqueIdGenerator::FIRST_LOCAL_ID)
idGenerator_.ResetReplicatedId(std::max(id, idGenerator_.id));
}
QString componentTypeName = component->TypeName();
componentTypeName.replace(0, 3, "");
componentTypeName = componentTypeName.toLower();
// We already have 'name' property in Entity, so ignore "EC_Name" ("name") here.
if (componentTypeName != "name" && !property(componentTypeName.toStdString().c_str()).isValid())
{
QVariant var = QVariant::fromValue<QObject*>(component.get());
setProperty(componentTypeName.toStdString().c_str(), var);
}
component->SetNewId(id);
component->SetParentEntity(this);
components_[id] = component;
if (change != AttributeChange::Disconnected)
emit ComponentAdded(component.get(), change == AttributeChange::Default ? component->UpdateMode() : change);
if (scene_)
scene_->EmitComponentAdded(this, component.get(), change);
}
}
示例5: assert
ComponentGroup::ComponentGroup(ComponentPtr component, ECComponentEditor *editor, bool isDynamic):
editor_(editor),
isDynamic_(isDynamic)
{
assert(component);
// No point to add component to editor cause it's already added in ECBrowser's AddNewComponentToGroup mehtod.
if(component)
{
components_.push_back(ComponentWeakPtr(component));
name_ = component->Name();
typeName_ = component->TypeName();
}
}
示例6: RemoveComponent
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
if (component)
{
ComponentVector::iterator iter = std::find(components_.begin(), components_.end(), component);
if (iter != components_.end())
{
QString componentTypeName = component->TypeName();
componentTypeName.replace(0, 3, "");
componentTypeName = componentTypeName.toLower();
if(property(componentTypeName.toStdString().c_str()).isValid())
{
QObject *obj = property(componentTypeName.toStdString().c_str()).value<QObject*>();
//Make sure that QObject is inherited by the IComponent.
if (obj && dynamic_cast<IComponent*>(obj))
{
//Make sure that name is matching incase there are many of same type of components in entity.
if (dynamic_cast<IComponent*>(obj)->Name() == component->Name())
setProperty(componentTypeName.toStdString().c_str(), QVariant());
}
}
if (change != AttributeChange::Disconnected)
emit ComponentRemoved((*iter).get(), change == AttributeChange::Default ? component->GetUpdateMode() : change);
if (scene_)
scene_->EmitComponentRemoved(this, (*iter).get(), change);
(*iter)->SetParentEntity(0);
components_.erase(iter);
}
else
{
LogWarning("Failed to remove component: " + component->TypeName() + " from entity: " + QString::number(GetId()));
}
}
}
示例7: RemoveComponent
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
if (component)
{
for(ComponentMap::Iterator it = components_.Begin(); it != components_.End(); ++it)
if (it->second_ == component)
{
RemoveComponent(it, change);
return;
}
LogWarning("Entity::RemoveComponent: Failed to find " + component->TypeName() + " \"" + component->Name() + "\" from " + ToString() + ".");
}
}
示例8: RemoveComponent
void Entity::RemoveComponent(const ComponentPtr &component, AttributeChange::Type change)
{
if (component)
{
ComponentMap::iterator iter = components_.find(component->Id());
if (iter != components_.end())
{
RemoveComponent(iter, change);
}
else
{
LogWarning("Failed to remove component: " + component->TypeName() + " from entity: " + QString::number(Id()));
}
}
}
示例9: AddComponent
void Entity::AddComponent(const ComponentPtr &component, AttributeChange::Type change)
{
// Must exist and be free
if (component && component->GetParentEntity() == 0)
{
QString componentTypeName = component->TypeName();
componentTypeName.replace(0, 3, "");
componentTypeName = componentTypeName.toLower();
if(!property(componentTypeName.toStdString().c_str()).isValid())
{
QVariant var = QVariant::fromValue<QObject*>(component.get());
setProperty(componentTypeName.toStdString().c_str(), var);
}
component->SetParentEntity(this);
components_.push_back(component);
if (change != AttributeChange::Disconnected)
emit ComponentAdded(component.get(), change == AttributeChange::Default ? component->GetUpdateMode() : change);
if (scene_)
scene_->EmitComponentAdded(this, component.get(), change);
}
}
示例10: IsSameComponent
/// @todo made some major changes to this function - ensure that everything is working right.
bool ComponentGroup::IsSameComponent(ComponentPtr component) const
{
assert(component);
if(!IsValid())
return false;
PROFILE(ComponentGroup_IsSameComponent);
if(component->TypeName() != typeName_ || component->Name() != name_)
return false;
// If component type is dynamic component we need to compere their attributes aswell. To ensure
// that they are holding exactly the same attributes.
if(isDynamic_)
{
EC_DynamicComponent *thisComponent = dynamic_cast<EC_DynamicComponent*>(components_[0].lock().get());
EC_DynamicComponent *compareComponent = dynamic_cast<EC_DynamicComponent*>(component.get());
if(!compareComponent || !thisComponent)
return false;
if(!thisComponent->ContainSameAttributes(*compareComponent))
return false;
}
return true;
}