当前位置: 首页>>代码示例>>C++>>正文


C++ EntityManager::visitEntitiesWithTypeMask方法代码示例

本文整理汇总了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;
         }
     });
 }
开发者ID:joekarl,项目名称:Space-Shooter,代码行数:28,代码来源:EnemyAISystem.hpp

示例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();
         }
     });
 }
开发者ID:joekarl,项目名称:Space-Shooter,代码行数:29,代码来源:DiesWhenOffscreenSystem.hpp

示例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;
     });
 }
开发者ID:joekarl,项目名称:Space-Shooter,代码行数:9,代码来源:AutoMovementSystem.hpp

示例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());
     });
 }
开发者ID:joekarl,项目名称:Space-Shooter,代码行数:18,代码来源:DebugCollisionRenderSystem.hpp


注:本文中的EntityManager::visitEntitiesWithTypeMask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。