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


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

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


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

示例1: EntityManager

TEST(NAME, DestroyingEntitiesDispatchesReallocationEvent)
{
    World w;
    MockEntityManagerListener mock;
    EntityManager* em = new EntityManager(&w);
    em->event.addListener(&mock, "mock");

    // uninteresting calls
    EXPECT_CALL(mock, onCreateEntityHelper(testing::_))
        .Times(testing::AtLeast(0));
    EXPECT_CALL(mock, onDestroyEntityHelper(testing::_))
        .Times(testing::AtLeast(0));

    EXPECT_CALL(mock, onEntitiesReallocatedHelper(testing::_)).Times(testing::AtLeast(0)); // ignore this call during entity creation - not important
    em->createEntity("entity1");             // will be destroyed via destroyEntities()
    em->createEntity("entity2");             // will be via destroyAllEntities

    // expect 4 calls, since 4 entities are being destroyed
    EXPECT_CALL(mock, onEntitiesReallocatedHelper(testing::_))
        .Times(4);  // 4 entities were created...

    em->destroyEntities("entity1");
    em->destroyAllEntities();
    Entity& e = em->createEntity("entity3");
    em->destroyEntity(e);
    em->createEntity("entity4"); // destroyed by destructor
    delete em;
}
开发者ID:TheComet93,项目名称:ontology,代码行数:28,代码来源:test_EntityManager.cpp

示例2: main

int main() {
    ResourceManager resourceManager = ResourceManager();
    resourceManager.addResourceDirectory("res/");
    sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "ECS Test");
    EntityManager entityManager = EntityManager(&window, 100);
    for (int i = 1; i < 10000; ++i) {
        int temp = entityManager.createEntity(sf::Vector2f(WINDOW_X * float(rand()) / RAND_MAX, WINDOW_Y * float(rand()) / RAND_MAX));
        entityManager.attachComponent(temp, RenderComponent(resourceManager.getTexture("player.png")));
        entityManager.attachComponent(temp, PhysicsComponent(sf::Vector2f(100 * (float(rand()) / RAND_MAX - 0.5), 100 * (float(rand()) / RAND_MAX - 0.5))));
    }
    // Remove some entities.
    for (int i = 1; i < 3; ++i) {
        entityManager.destroyEntity(i);
    }
    // Remove some components.
    for (int i = 3; i < 10; ++i) {
        entityManager.detachComponent(i, RENDER);
    }
    sf::Clock clock;
    while (window.isOpen()) {
        // Handle events.
        sf::Event event;
        while (window.pollEvent(event)) {
          if(event.type == sf::Event::Closed) {
              window.close();
          }
        }
        float frametime = clock.restart().asSeconds();
        std::cout << (1 / frametime) << std::endl;
        window.clear(sf::Color::White);
        entityManager.update(frametime);
        window.display();
    }
}
开发者ID:pmarathe25,项目名称:GameEngine2D,代码行数:34,代码来源:tester.cpp


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