本文整理汇总了C++中EntityManager::visitEntitiesWithTypeMask方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::visitEntitiesWithTypeMask方法的具体用法?C++ EntityManager::visitEntitiesWithTypeMask怎么用?C++ EntityManager::visitEntitiesWithTypeMask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::visitEntitiesWithTypeMask方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void update(double dt) {
entityManagerRef->visitEntitiesWithTypeMask(componentMask, [&](Entity<EntityManagerTypes...> &entity){
auto &aiComponent = entity.template getComponent<EnemyAIComponent>();
if (aiComponent.playerId == -1) {
int playerMask = 0;
playerMask |= 1 << getTypeId<PlayerDetailsComponent>();
playerMask |= 1 << getTypeId<TransformComponent>();
auto entities = entityManagerRef->getEntityIDsWithTypeMask(playerMask);
aiComponent.playerId = entities[0];
}
switch (aiComponent.aiType) {
case EnemyAIComponent::AIType::DUMB:
updateDumbAI(dt, entity);
break;
case EnemyAIComponent::AIType::FLEE:
updateDumbAI(dt, entity);
break;
case EnemyAIComponent::AIType::FOLLOW_FIRE:
updateDumbAI(dt, entity);
break;
default:
break;
}
});
}
示例2: checkOffscreenPositions
void checkOffscreenPositions() {
entityManagerRef->visitEntitiesWithTypeMask(componentMask, [](Entity<EntityManagerTypes...> &entity){
auto &transformComponent = entity.template getComponent<TransformComponent>();
auto &aabbComponent = entity.template getComponent<AABBComponent>();
auto &diesWhenOffscreenComponent = entity.template getComponent<DiesWhenOffscreenComponent>();
auto halfWidth = aabbComponent.width / 2.0;
auto halfHeight = aabbComponent.height / 2.0;
auto isOffscreen = (transformComponent.x - halfWidth > SCREEN_WIDTH ||
transformComponent.x + halfWidth < 0 ||
transformComponent.y - halfHeight > SCREEN_HEIGHT ||
transformComponent.y + halfHeight < 0);
if (isOffscreen && diesWhenOffscreenComponent.cameOnscreen) {
// only kill if we're offscreen and have been onscreen at some point
printf("Killing entity %zu because it went offscreen\n", entity.getId());
entity.kill();
} else if (!isOffscreen && !diesWhenOffscreenComponent.cameOnscreen) {
diesWhenOffscreenComponent.cameOnscreen = true;
} else if (transformComponent.x > 10000 ||
transformComponent.x < -1000 ||
transformComponent.y > 10000 ||
transformComponent.y < -1000) {
// just some failsafe stuff here
entity.kill();
}
});
}
示例3: moveEntities
void moveEntities(double dt) {
entityManagerRef->visitEntitiesWithTypeMask(componentMask, [&](Entity<EntityManagerTypes...> &entity){
auto &transformComponent = entity.template getComponent<TransformComponent>();
transformComponent.x += transformComponent.dx * dt;
transformComponent.y += transformComponent.dy * dt;
transformComponent.z += transformComponent.dz * dt;
});
}
示例4: renderSprites
void renderSprites() {
glUseProgram(spriteShaderProgramId);
entityManagerRef->visitEntitiesWithTypeMask(componentMask, [&](Entity<EntityManagerTypes...> &entity){
auto &aabbComponent = entity.template getComponent<AABBComponent>();
auto &transformComponent = entity.template getComponent<TransformComponent>();
Eigen::Translation<GLfloat, 3> translationMat((transformComponent.x - HALF_SCREEN_WIDTH) / HALF_SCREEN_WIDTH,
(transformComponent.y - HALF_SCREEN_HEIGHT) / HALF_SCREEN_HEIGHT,
0);
Eigen::DiagonalMatrix<GLfloat, 3> scaleMat(aabbComponent.width / SCREEN_WIDTH,
aabbComponent.height / SCREEN_HEIGHT,
1);
Eigen::Transform<GLfloat, 3, Eigen::Affine> transformMatrix = translationMat * scaleMat;
boundsSprite.render(transformMatrix.matrix());
});
}