本文整理汇总了C++中kernel::Object::destroyTrait方法的典型用法代码示例。如果您正苦于以下问题:C++ Object::destroyTrait方法的具体用法?C++ Object::destroyTrait怎么用?C++ Object::destroyTrait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kernel::Object
的用法示例。
在下文中一共展示了Object::destroyTrait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testComputerDestruction
void TestDetector::testComputerDestruction()
{
InternalMessage("Model","Model::TestDetector::testComputerDestruction entering") ;
/*!
We create a ship with a detector and a second object to detect.
*/
std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestDetector::testComputerDestruction")) ;
model->init() ;
Kernel::Object* system = model->createObject() ;
Kernel::Object* ship = system->createObject() ;
ship->addTrait(new Positioned()) ;
ship->addTrait(new Oriented()) ;
ship->addTrait(new Mobile()) ;
ship->addTrait(new Solid(Mesh("test_ship.mesh"))) ;
ship->addTrait(new Massive(Mass::Kilogram(1000))) ;
ship->addTrait(new Computer()) ;
ship->addTrait(new Detector()) ;
Detector::connect(ship,ship) ;
Kernel::Object* ship2 = system->createObject() ;
ship2->addTrait(new Positioned(Position::Meter(0,0,500))) ;
ship2->addTrait(new Massive(Mass::Kilogram(1000))) ;
ship2->addTrait(new Oriented()) ;
ship2->addTrait(new Mobile()) ;
ship2->addTrait(new Solid(Mesh("test_ship.mesh"))) ;
InternalMessage("Model","Model::TestDetector::testComputerDestruction destroying computer") ;
ship->destroyTrait(ship->getTrait<Computer>()) ;
model->update(0.1) ;
InternalMessage("Model","Model::TestDetector::testComputerDestruction leaving") ;
}
示例2: basicDestroy
void TestModelControler::basicDestroy()
{
std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestModelControler::basicDestroy")) ;
model->init() ;
Kernel::Object* team1 = model->createObject() ;
team1->addTrait(new Model::Team("team1")) ;
Kernel::Object* team2 = model->createObject() ;
team2->addTrait(new Model::Team("team2")) ;
Kernel::Object* universe = model->createObject() ;
universe->addTrait(new Model::Universe()) ;
universe->addTrait(new Model::Positioned()) ;
Kernel::Object* system = universe->createObject() ;
system->addTrait(new Model::StellarSystem()) ;
system->addTrait(new Model::Positioned()) ;
Kernel::Object* observer = system->createObject() ;
observer->addTrait(new Model::Observer()) ;
observer->addTrait(new Model::Player()) ;
observer->addTrait(new Model::Active()) ;
observer->addTrait(new Model::Positioned(Model::Position::Meter(0,1000,0))) ;
observer->addTrait(new Model::Oriented(Model::Orientation(::Ogre::Quaternion(::Ogre::Degree(-90),::Ogre::Vector3::UNIT_X)))) ;
/*
Situation seen from top :
------------------------
| |
| <-- --> |
| ship1 ship2 |
| |
------------------------
Objective of the the system : they must stay in the box
(initial_distance+ship_size*4,ship_size*4,ship_size*4)
*/
Kernel::ObjectReference ship1 ;
{
Kernel::Object* ship = Model::createShip(system) ;
ship->getTrait<Model::Positioned>()->setPosition(Model::Position::Meter(-500,0,0)) ;
ship->getTrait<Model::Oriented>()->setOrientation(Model::Orientation(Ogre::Quaternion(Ogre::Degree(90),Ogre::Vector3::UNIT_Y))) ;
ship->addTrait(new Model::Transponder(team1)) ;
ship->destroyTrait(ship->getTrait<Model::Destroyable>()) ;
Kernel::Object* agent = Model::createAI(ship) ;
agent->getTrait<Model::WithObjectives>()->addObjective(Model::Objective::attackAllEnemies()) ;
ship1 = ship ;
}
Kernel::ObjectReference ship2 ;
{
Kernel::Object* ship = Model::createShip(system) ;
ship->getTrait<Model::Positioned>()->setPosition(Model::Position::Meter(1000,0,0)) ;
ship->getTrait<Model::Oriented>()->setOrientation(Model::Orientation(Ogre::Quaternion(Ogre::Degree(-90),Ogre::Vector3::UNIT_Y))) ;
Kernel::Object* agent = Model::createAI(ship) ;
agent->getTrait<Model::WithObjectives>()->addObjective(Model::Objective::attackAllEnemies()) ;
ship->addTrait(new Model::Transponder(team2)) ;
ship2 = ship ;
}
Kernel::Timer timer ;
Kernel::Timer global_timer ;
while (global_timer.getSecond() < 20)
{
float seconds = timer.getSecond() ;
if (seconds > 0)
{
timer.reset() ;
model->update(seconds) ;
}
}
CPPUNIT_ASSERT(!ship2) ;
}