Exemplo n.º 1
0
TEST(NAME, DispatchesDestroyEntityEventOnDestruction)
{
    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, onEntitiesReallocatedHelper(testing::_))
        .Times(testing::AtLeast(0));

    // interesting calls
    EXPECT_CALL(mock, onDestroyEntityHelper(testing::_))
        .Times(1);

    Entity& e = em->createEntity("entity");
    delete em;
}
Exemplo n.º 2
0
void 
CEntityBuilder::BuildEntity( TiXmlElement *pParent, EntityManager &em, Resources *pResources){
  // Create entity (new id)
  Entity *ent = em.createEntity();
  if ( !ent){
    LOG2ERR<<"Could not create entity\n";
    throw "Could not create entity";
  }
  TiXmlElement* pChilds = pParent->FirstChildElement( "tags");
  if ( pChilds ){
    // Add tags
    for(pChilds=pChilds->FirstChildElement( "tag" ); pChilds; pChilds = pChilds->NextSiblingElement() ){
      std::string name;
      if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "name", &name))
      {
        std::string unique;
        bool        isUnique(false);
        if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "unique", &unique) ){
          isUnique = ( unique=="true");
        }
        em.tagEntity( ent, name, isUnique);
      }
    }
  }
  
  // Add components
  pChilds = pParent->FirstChildElement( "components");
  if ( pChilds ){
    for( pChilds=pChilds->FirstChildElement( "component" ); pChilds; pChilds = pChilds->NextSiblingElement() ){
      std::string type; 
      if ( TIXML_SUCCESS == pChilds->QueryValueAttribute( "type", &type)){
        //LOG2 <<name<<"\n";
        buildComponents(pChilds, type, ent, pResources);
      }
      else {
        LOG2ERR<<"Attribute [type] not found\n";
      }
    }
  }
}
//--------------------------------------------------------------
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);
}
Exemplo n.º 4
0
TEST(NAME, DispatchesCreateAndDestroyEntityEvents)
{
    World w;
    MockEntityManagerListener mock;
    EntityManager* em = new EntityManager(&w);
    em->event.addListener(&mock, "mock");

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

    // interesting calls
    EXPECT_CALL(mock, onCreateEntityHelper(testing::_))
        .Times(1);
    EXPECT_CALL(mock, onDestroyEntityHelper(testing::_))
        .Times(1);

    Entity& e = em->createEntity("entity");
    ASSERT_EQ(1, em->getEntityList().size());
    em->destroyEntity(e);
    em->event.removeListener("mock");
    delete em;
}
using namespace std;
using namespace test;
using namespace tetra;
using namespace tetra::meta;
using namespace tetra::framework;

SCENARIO( "Using an EntityManager to manage a set of entities",
          "[EntityManager]" )
{
  GIVEN( "An empty EntityManager" )
  {
    EntityManager entityManager{};

    THEN( "We should be able to create a new Entity" )
    {
      auto id = entityManager.createEntity();

      Entity& entity = entityManager.getEntity( id );
    }

    THEN( "Attempting to access an entity which does not exist "
          "should throw an EntityDoesNotExistException" )
    {
      REQUIRE_THROWS_AS( entityManager.getEntity( 5 ),
                         EntityDoesNotExistException );
    }

    THEN( "We should be able to get a list of all existing entities "
          "and access them" )
    {
      auto id1 = entityManager.createEntity();