Ejemplo n.º 1
0
int _tmain(int argc, _TCHAR* argv[])
{
	EntityManager* pManager = new EntityManager;

	Entity* pCharacter = pManager->CreateEntity(0);


	return 0;
}
Ejemplo n.º 2
0
int main() {

  ServiceLocator::Initialize();

  ComponentFactory factory;
  RegisterFactories(&factory);

  ConsoleHandler console(80, 50, "Pong", ConsoleProc );
  GameClock clock;

  EntityManager manager;
  ServiceLocator::ProvideEntityManager(&manager);

  //Deprecated code in favour of using XML to automate generation of entities.
  /*
  //one ball
  unsigned int ball = manager->CreateEntity();
  manager.AddComponent( ball, new Ball() );

  //two paddles
  unsigned int player = manager.CreateEntity();
  manager.AddComponent( player, new Paddle(true) );
  manager.AddComponent( player, new Score() );

  unsigned int ai = manager.CreateEntity();
  manager.AddComponent( ai, new Paddle(false) );
  manager.AddComponent( ai, new Score() );

  //4 borders
  //top
  Vector2 pos = { 50.0f, 99.0f };
  Border* border = new Border( pos, true, 2 );
  unsigned int border_ent = manager.CreateEntity();
  manager.AddComponent( border_ent, border );
  //bottom
  pos.y = 1.0f;
  border = new Border( pos, true, 1 );
  border_ent = manager.CreateEntity();
  manager.AddComponent( border_ent, border );
  //left
  pos.x = 1.0f;
  pos.y = 50.0f;
  border = new Border( pos, false, 2 );
  border_ent = manager.CreateEntity();
  manager.AddComponent( border_ent, border );
  //right
  pos.x = 99.0f;
  border = new Border( pos, false, 1 );
  border_ent = manager.CreateEntity();
  manager.AddComponent( border_ent, border );
  */

  {
    //get the document
    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file( string(LOCAL_DATA + "pong.xml").c_str() );

    if( !result) {
      cout << "XML loading error: " << result.description() << endl;
    }
    else {
      //get the <entities /> tag
      pugi::xml_node entities = doc.child("entities");

      //iterate through each child of the tag to find each <entity /> tag
      for( pugi::xml_node entity = entities.first_child(); entity; entity = entity.next_sibling() ) {
        //create a new entity for each child
        unsigned int entity_id = manager.CreateEntity();

        //iterate through each component of a given entity
        for( pugi::xml_node component = entity.first_child(); component; component = component.next_sibling() ) {
          
          //get the type
          string type = component.attribute("type").value();
          
          //throw it at our component factory
          IComponent* new_component = factory.Create( type );
          if( new_component ) {
            //deserialize any pertinent XML data
            new_component->Deserialize(component);
            //add it to our entity
            manager.AddComponent( entity_id, new_component );
          }
        }
      }
    }

    //document goes out of scope and is destroyed
  }

  //Get game systems
  AIPaddleDriver ai_paddle_driver;
  BallDriver ball_driver;
  Collision collision;
  PlayerPaddleDriver player_paddle_driver;

  while(g_app_running) {
    //start timing the frame
    clock.StartFrame();

    //take care of any events
    console.CheckEvents();

    //run all of our systems to update components, passing the delta_time value for timing
    ball_driver.Process(clock.delta_time());
    ai_paddle_driver.Process(clock.delta_time());
    player_paddle_driver.Process(clock.delta_time());
    collision.Process(clock.delta_time());

    //draw components
    Draw(&console);

    //swap buffers
    console.Present();

    //finish timing frame and update delta time
    clock.EndFrame();
  }

  return 0;
}