本文整理汇总了C++中EntityManager::AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::AddComponent方法的具体用法?C++ EntityManager::AddComponent怎么用?C++ EntityManager::AddComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::AddComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
//.........这里部分代码省略.........