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


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

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


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

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	EntityManager* pManager = new EntityManager;

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


	return 0;
}
开发者ID:lythm,项目名称:orb3d,代码行数:9,代码来源:EL_Test.cpp

示例2: main

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();

//.........这里部分代码省略.........
开发者ID:Razoric480,项目名称:EntitySystem-Pong,代码行数:101,代码来源:main.cpp


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