本文整理汇总了C++中ComponentPtr::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ ComponentPtr::Get方法的具体用法?C++ ComponentPtr::Get怎么用?C++ ComponentPtr::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComponentPtr
的用法示例。
在下文中一共展示了ComponentPtr::Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 " + String(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(Max(id, idGenerator_.id));
}
component->SetNewId(id);
component->SetParentEntity(this);
components_[id] = component;
if (change != AttributeChange::Disconnected)
ComponentAdded.Emit(component.Get(), change == AttributeChange::Default ? component->UpdateMode() : change);
if (scene_)
scene_->EmitComponentAdded(this, component.Get(), change);
}
}