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


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

本文整理汇总了C++中EntityManager::addComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::addComponent方法的具体用法?C++ EntityManager::addComponent怎么用?C++ EntityManager::addComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntityManager的用法示例。


在下文中一共展示了EntityManager::addComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST(EntityFilter, Optional) {
    EntityManager entityManager;
    using TestFilter = EntityFilter<
                       TestComponent<0>,
                       Optional<TestComponent<1>>
                       >;
    // Set up filter
    TestFilter filter;
    filter.setEntityManager(&entityManager);
    TestFilter::EntityMap filteredEntities = filter.entities();
    // Add first component
    EntityId entityId = entityManager.generateNewId();
    entityManager.addComponent(
        entityId,
        make_unique<TestComponent<0>>()
    );
    // Check filter
    filteredEntities = filter.entities();
    EXPECT_EQ(1, filteredEntities.count(entityId));
    EXPECT_EQ(1, filteredEntities.size());
    // Check group
    TestFilter::ComponentGroup group = filteredEntities[entityId];
    EXPECT_TRUE(std::get<0>(group) != nullptr);
    EXPECT_TRUE(std::get<1>(group) == nullptr);
    // Add second component
    entityManager.addComponent(
        entityId,
        make_unique<TestComponent<1>>()
    );
    // Check filter
    filteredEntities = filter.entities();
    EXPECT_EQ(1, filteredEntities.count(entityId));
    EXPECT_EQ(1, filteredEntities.size());
    // Check group
    group = filteredEntities[entityId];
    EXPECT_TRUE(std::get<0>(group) != nullptr);
    EXPECT_TRUE(std::get<1>(group) != nullptr);
    // Remove component
    entityManager.removeComponent(
        entityId,
        TestComponent<1>::TYPE_ID
    );
    entityManager.processRemovals();
    // Check filter
    filteredEntities = filter.entities();
    EXPECT_EQ(1, filteredEntities.count(entityId));
    EXPECT_EQ(1, filteredEntities.size());
    // Check group
    group = filteredEntities[entityId];
    EXPECT_TRUE(std::get<0>(group) != nullptr);
}
开发者ID:RodGame,项目名称:Thrive,代码行数:51,代码来源:entity_filter.cpp

示例2: filter

TEST(EntityFilter, Record) {
    EntityManager entityManager;
    using TestFilter = EntityFilter<
                       TestComponent<0>
                       >;
    // Set up filter
    TestFilter filter(true);
    filter.setEntityManager(&entityManager);
    TestFilter::EntityMap filteredEntities = filter.entities();
    // Add first component
    EntityId entityId = entityManager.generateNewId();
    entityManager.addComponent(
        entityId,
        make_unique<TestComponent<0>>()
    );
    // Check added entities
    EXPECT_EQ(1, filter.addedEntities().count(entityId));
    // Remove component
    entityManager.removeComponent(
        entityId,
        TestComponent<0>::TYPE_ID
    );
    entityManager.processRemovals();
    // Check removed entities
    EXPECT_EQ(1, filter.removedEntities().count(entityId));
}
开发者ID:RodGame,项目名称:Thrive,代码行数:26,代码来源:entity_filter.cpp

示例3: createEntity

int createEntity(EntityManager& entityManager) {
	int id = entityManager.createEntity();
	std::cout << "Entity ID: " << id << std::endl;
	// std::unique_ptr<PositionComponent> position{new PositionComponent{sf::Vector2f{0, 0}}};
	// entityManager.addComponent(id, std::move(position));
	entityManager.addComponent(id, new PositionComponent{sf::Vector2f{(float) id, 4432}});
	return id;
}
开发者ID:dr01d3k4,项目名称:Platformer,代码行数:8,代码来源:main.cpp

示例4: setup

//--------------------------------------------------------------
void testApp::setup() {

    world = new World();

    EntityManager * em = world->getEntityManager();
    
    world->getSystemManager()->addSystem(new ecs::MotionSystem(world));
    world->getSystemManager()->addSystem(new ecs::RenderSystem(world));

    for (int i = 0; i < 100; i++) {
        
        Entity * e = em->createEntity();
        
        em->addComponent(e->id, new TransformComponent(rand() % 1024, rand() % 768));
        em->addComponent(e->id, new MotionComponent(randPlusMinus(100), randPlusMinus(100)));
        em->addComponent(e->id, new RenderComponent(new CircleRenderer(rand() % 5, rand() % 255, rand() % 255, rand() % 255)));

    }
    
    
    ofBackground(0, 0, 0);
}
开发者ID:jimmytheleaf,项目名称:OpenFrameworksSandbox,代码行数:23,代码来源:testApp.cpp

示例5:

void
EntityManager::transferEntity(
    EntityId oldEntityId,
    EntityId newEntityId,
    EntityManager& newEntityManager,
    const ComponentFactory& componentFactory
){
    for (const auto& pair : m_impl->m_collections) {
        Component* component = pair.second->get(oldEntityId);
        if (component != nullptr){
            if (not component->isVolatile() and not
                (m_impl->m_volatileEntities.count(oldEntityId) > 0)
            ) {
                auto newComponent = componentFactory.load(componentFactory.getTypeName(pair.first), component->storage());
                newComponent->setOwner(newEntityId);

                newEntityManager.addComponent(newEntityId, std::move(newComponent));
            }
        }
        m_impl->m_entitiesToRemove.push_back(oldEntityId);
    }
}
开发者ID:Anth0rx,项目名称:Thrive,代码行数:22,代码来源:entity_manager.cpp


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