本文整理汇总了C++中Entity::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::Attach方法的具体用法?C++ Entity::Attach怎么用?C++ Entity::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::Attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnMouseDown
void OnMouseDown(UINT button, int x, int y)
{
XOrientation camOrient;
cameraEntity->GetOrientation(&camOrient);
if (button == 0)
cameraControl = true;
//shoot a cube
else if (button == 1)
{
Entity* pCube = g_pScene->CreateEntity();
g_pSelectedEntity = pCube;
pCube->SetPosition(cameraEntity->GetPosition() + camOrient.z);
pCube->SetVelocity(0.1f * camOrient.z);
//pCube->SetMaxLifeTime(5.0f);
MeshComponent* pMesh = new MeshComponent(pCube);
pMesh->SetMeshResource("cube.nfm");
BodyComponent* pBody = new BodyComponent(pCube);
pBody->SetMass(10.0f);
pBody->EnablePhysics((CollisionShape*)EngineGetResource(ResourceType::COLLISION_SHAPE,
"shape_box"));
OmniLightDesc lightDesc;
lightDesc.radius = 4.0f;
lightDesc.shadowFadeStart = 20.0;
lightDesc.shadowFadeEnd = 30.0;
Entity* pLightEntity = g_pScene->CreateEntity();
pCube->Attach(pLightEntity);
//pLightEntity->SetLocalPosition(Vector(0.0f, 1.0f, 0.0f));
LightComponent* pLight = new LightComponent(pLightEntity);
pLight->SetOmniLight(&lightDesc);
pLight->SetColor(Float3(1.0f, 1.0f, 10.0f));
pLight->SetShadowMap(0);
}
else
{
Entity* pBarrel = g_pScene->CreateEntity();
g_pSelectedEntity = pBarrel;
pBarrel->SetPosition(cameraEntity->GetPosition() + camOrient.z);
pBarrel->SetVelocity(30.0f * camOrient.z);
MeshComponent* pMesh = new MeshComponent(pBarrel);
pMesh->SetMeshResource("barrel.nfm");
BodyComponent* pBody = new BodyComponent(pBarrel);
pBody->SetMass(20.0f);
pBody->EnablePhysics((CollisionShape*)EngineGetResource(ResourceType::COLLISION_SHAPE,
"shape_barrel"));
}
}
示例2: Update
//.........这里部分代码省略.........
JobContext::Spawner< 1 > entityUpdateSpawner;
JobContext* pContext = entityUpdateSpawner.Allocate();
HELIUM_ASSERT( pContext );
WorldManagerUpdate< EntityPostUpdate >* pJob = pContext->Create< WorldManagerUpdate< EntityPostUpdate > >();
HELIUM_ASSERT( pJob );
WorldManagerUpdate< EntityPostUpdate >::Parameters& rParameters = pJob->GetParameters();
rParameters.pspWorlds = m_worlds.GetData();
rParameters.worldCount = m_worlds.GetSize();
}
// Perform the entity synchronous update.
m_updatePhase = UPDATE_PHASE_SYNCHRONOUS;
size_t worldCount = m_worlds.GetSize();
for( size_t worldIndex = 0; worldIndex < worldCount; ++worldIndex )
{
World* pWorld = m_worlds[ worldIndex ];
HELIUM_ASSERT( pWorld );
size_t layerCount = pWorld->GetLayerCount();
for( size_t layerIndex = 0; layerIndex < layerCount; ++layerIndex )
{
Layer* pLayer = pWorld->GetLayer( layerIndex );
HELIUM_ASSERT( pLayer );
size_t entityCount = pLayer->GetEntityCount();
for( size_t entityIndex = 0; entityIndex < entityCount; ++entityIndex )
{
Entity* pEntity = pLayer->GetEntity( entityIndex );
HELIUM_ASSERT( pEntity );
bool bNeedsSynchronousUpdate = pEntity->NeedsSynchronousUpdate();
uint32_t deferredWorkFlags = pEntity->GetDeferredWorkFlags();
if( !bNeedsSynchronousUpdate && !deferredWorkFlags )
{
continue;
}
if( deferredWorkFlags & Entity::DEFERRED_WORK_FLAG_DESTROY )
{
pLayer->DestroyEntity( pEntity );
--entityIndex;
// Only the current entity should be destroyed; entity destruction should not trigger the
// immediate creation or destruction of other entities.
--entityCount;
HELIUM_ASSERT( pLayer->GetEntityCount() == entityCount );
continue;
}
// Entity::NeedsSynchronousUpdate() also checks the deferred work flags.
if( bNeedsSynchronousUpdate /*deferredWorkFlags & Entity::DEFERRED_WORK_FLAG_UPDATE*/ )
{
pEntity->SynchronousUpdate( m_frameDeltaSeconds );
// Update the entity count in case a new entity was created during the synchronous update.
entityCount = pLayer->GetEntityCount();
HELIUM_ASSERT( entityIndex < entityCount );
// Update the deferred work flags and reassess entity destruction after the synchronous update.
deferredWorkFlags = pEntity->GetDeferredWorkFlags();
if( deferredWorkFlags & Entity::DEFERRED_WORK_FLAG_DESTROY )
{
pLayer->DestroyEntity( pEntity );
--entityIndex;
// Only the current entity should be destroyed; entity destruction should not trigger the
// immediate creation or destruction of other entities.
--entityCount;
HELIUM_ASSERT( pLayer->GetEntityCount() == entityCount );
continue;
}
}
if( deferredWorkFlags & Entity::DEFERRED_WORK_FLAG_REATTACH )
{
pEntity->Detach();
pEntity->Attach();
// Entities should only be spawned during the synchronous update call, so the count should not
// have changed as a result of reattachment.
HELIUM_ASSERT( pLayer->GetEntityCount() == entityCount );
}
pEntity->ClearDeferredWorkFlags();
}
}
}
m_updatePhase = UPDATE_PHASE_INVALID;
// Update the graphics scene for each world.
for( size_t worldIndex = 0; worldIndex < worldCount; ++worldIndex )
{
World* pWorld = m_worlds[ worldIndex ];
HELIUM_ASSERT( pWorld );
pWorld->UpdateGraphicsScene();
}
}