void TestDetector::detectOneObject()
      {
        InternalMessage("Model","Model::TestDetector::detectOneObject entering") ;
        /*!
          We create a ship with a detector and a second object to detect.
        */
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestDetector::detectOneObject")) ;
        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"))) ;

        std::set<Kernel::Object*> detected(ship->getTrait<Computer>()->getDetectedObjects()) ;

        CPPUNIT_ASSERT(!detected.empty()) ;
        CPPUNIT_ASSERT(detected.find(ship2) != detected.end()) ;

        InternalMessage("Model","Model::TestDetector::detectOneObject leaving") ;
      }
      void TestMenu::mouseCursor()
      {
        InternalMessage("Input","Input::TestMenu::mouseCursor entering") ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMenu::mouseCursor")) ;
        model->init() ;
        
        Kernel::Object* menu = model->createObject() ;
        menu->addTrait(new Model::Menu("Demo7Windows.layout")) ;
        Kernel::Object* observer = model->createObject() ;
        observer->addTrait(new Model::Observer()) ;
        observer->addTrait(new Model::Player()) ;
        observer->addTrait(new Model::Positionned()) ;
        
        Kernel::Timer timer ;
        Kernel::Timer global_timer ;
        
        while (global_timer.getSecond() < 20)
        {
          float seconds = timer.getSecond() ;
          if (seconds != 0)
          {
            timer.reset() ;
          }
          model->update(seconds) ;
        }        
        
        InternalMessage("Input","Input::TestMenu::mouseCursor leaving") ;
      }
      void TestLaser::beamEnergy()
      {
        InternalMessage("Model","Model::TestLaser::beamEnergy entering") ;
        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestLaser::testFire")) ;
        model->init() ;

        // should be a PhysicalWorld
        Kernel::Object* system = model->createObject() ;
        CPPUNIT_ASSERT(system->getTrait<PhysicalWorld>()) ;

        Kernel::Object* ship = system->createObject() ;
        ship->addTrait(new Positionned()) ;
        ship->addTrait(new Oriented()) ;
        ship->addTrait(new Mobile()) ;
        ship->addTrait(new Massive(Mass::Kilogram(1000))) ;
        ship->addTrait(new Laser(Position(),Orientation(),Energy::Joule(10))) ;
        CPPUNIT_ASSERT(ship->getTrait<PhysicalObject>()) ;
        CPPUNIT_ASSERT(ship->getTrait<PhysicalWorld>()) ;

        CPPUNIT_ASSERT(system->getChildren().size()==1) ;

        InternalMessage("Model","built ship") ;

        ship->call("fire") ;

        InternalMessage("Model","fire") ;
        CPPUNIT_ASSERT(system->getDescendants<LaserBeam>().size()==1) ;
        CPPUNIT_ASSERT(system->getDescendants<Shot>().size()==1) ;

        std::set<LaserBeam*> beams = system->getDescendants<LaserBeam>() ;
        LaserBeam* beam = *(beams.begin()) ;
        
        CPPUNIT_ASSERT(beam->getEnergy().Joule()==10) ;
      }
      void TestAgent::steeringFullBackShouldTurn()
      {
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestAgent::steeringFullBackShouldTurn")) ;
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::StellarSystem()) ;
        system->addTrait(new Model::Positioned()) ;

        Kernel::Object* ship = Model::createShip(system) ;
        Kernel::Object* agent = Model::createAI(ship) ;

        Implementation::Agent* agent_controler = getAgentController(agent) ;

        /*
          should perform a full turn :
          <--       -->
          ship      steering

          => x or y command should be not null.
        */
        //
        agent_controler->m_steering = Ogre::Vector3::UNIT_Z ;

        Ogre::Vector3 command(agent_controler->calculateSteeringCommands(0.1)) ;

        CPPUNIT_ASSERT_MESSAGE("ship should turn",command.x != 0 || command.y != 0) ;
      }
      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") ;
      }
      void TestAgent::isTargetedByTarget()
      {
        std::auto_ptr<Kernel::Model> model(new Kernel::Model()) ;
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::StellarSystem()) ;
        system->addTrait(new Model::Positioned()) ;

        Kernel::Object* ship1 = Model::createShip(system) ;
        Kernel::Object* agent = Model::createAI(ship1) ;
        Model::TargetingSystem* targeting_system1 = ship1->getChild<Model::TargetingSystem>() ;

        Kernel::Object* ship2 = Model::createShip(system) ;
        Model::TargetingSystem* targeting_system2 = ship2->getChild<Model::TargetingSystem>() ;

        Implementation::Agent* agent_controller = getAgentController(agent) ;

        targeting_system1->selectTarget(ship2) ;

        CPPUNIT_ASSERT(!agent_controller->isTargetedByTarget()) ;

        targeting_system2->selectTarget(ship1) ;

        CPPUNIT_ASSERT(agent_controller->isTargetedByTarget()) ;
      }
      void TestGuidanceControl::basicTest()
      {
        InternalMessage("Model","Model::TestGuidanceControl::basicTest entering") ;
        /// we construct a complete system on a ship
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestGuidanceControl::basicTest")) ;

        /// should be a PhysicalWorld
        Kernel::Object* system = model->createObject() ;
        CPPUNIT_ASSERT(system->getTrait<PhysicalWorld>()) ;

        Kernel::Object* ship = system->createObject() ;
        ship->addTrait(new Positionned()) ;
        ship->addTrait(new Oriented()) ;
        ship->addTrait(new Mobile()) ;
        ship->addTrait(new Massive(Mass::Kilogram(1000))) ;
        CPPUNIT_ASSERT(ship->getTrait<PhysicalObject>()) ;

        Kernel::Object* stick = ship->createObject() ;
        stick->addTrait(new Oriented()) ;

        Kernel::Object* guidance_system = ship->createObject() ;
        guidance_system->addTrait(new GuidanceSystem(1)) ;

        Kernel::Object* guidance_control = ship->createObject() ;
        guidance_control->addTrait(new GuidanceControler()) ;

        connectStickControler(stick,guidance_control) ;
        connectControlerGuidanceSystem(guidance_control,guidance_system) ;

        /// now we can test the control...
        {
          /// variables redefines to have direct access to interesting traits

          GuidanceSystem* guidance_system_trait = guidance_system->getTrait<GuidanceSystem>() ;
          CPPUNIT_ASSERT(guidance_system_trait) ;
          GuidanceControler* guidance_control_trait = guidance_control->getTrait<GuidanceControler>() ;
          CPPUNIT_ASSERT(guidance_control_trait) ;
          Oriented* stick_trait = stick->getTrait<Oriented>() ;
          CPPUNIT_ASSERT(stick_trait) ;

          /// basic init check
          CPPUNIT_ASSERT(guidance_system_trait->NewtonMeter() == Ogre::Vector3(0,0,0)) ;

          Ogre::Quaternion orientation(0,1,0,0) ;
          stick_trait->setOrientation(orientation) ;

          CPPUNIT_ASSERT(equal(guidance_system_trait->NewtonMeter().x,pi) &&
                         equal(guidance_system_trait->NewtonMeter().y,pi) &&
                         equal(guidance_system_trait->NewtonMeter().z,0)) ;

          /// reorient ship...
          ship->getTrait<Oriented>()->setOrientation(
            Ogre::Quaternion(sqrt(0.5),0,sqrt(0.5),0)) ;

          CPPUNIT_ASSERT(equal(guidance_system_trait->NewtonMeter().x,0) &&
                         equal(guidance_system_trait->NewtonMeter().y,pi) &&
                         equal(guidance_system_trait->NewtonMeter().z,-pi)) ;
        }
      }
      void TestMovingObject::moveParentSource()
      {
        std::cerr << "TestMovingObject::moveParentSource" << std::endl ;
        std::cerr.flush() ;

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMovingObject::basicTest")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        Model::Positionned* listenerPos = new Model::Positionned();
        listener->addTrait(listenerPos) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());
        
        Kernel::Object* ship = system->createObject() ;
        Model::Positionned* ship_positionned = new Model::Positionned(Model::Position::Meter(0,0,-50));
        ship->addTrait(ship_positionned);
        ship->addTrait(new Model::Oriented()) ;
        ship->addTrait(new Model::Mobile());
        
        Kernel::Object* engine = ship->createObject() ;
        engine->addTrait(new Model::Engine(Model::Force::Newton(10,10,10))) ;
        
        Kernel::ViewPoint* viewpoint = model->getViewPoint<Implementation::OpenAL::RealWorldViewPoint>() ;
        CPPUNIT_ASSERT(engine->getTrait<Implementation::Engine>()
                             ->getView<Implementation::OpenAL::Engine>(viewpoint)) ;
        
        ALuint engine_source = 
          engine->getTrait<Implementation::Engine>()
                ->getView<Implementation::OpenAL::Engine>(viewpoint)->m_source ;
        
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        
        float expected_position_x = 0 ;
        float expected_position_y = 0 ;
        float expected_position_z = -50 ;

        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;

        ship_positionned->setPosition(ship_positionned->getPosition()+Model::Position::Meter(0,0,-0.01));
        
        expected_position_z -= 0.01 ;

        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
      }
      void TestMovingObject::moveParentAndListenerHasPosition()
      {
        std::cerr << "TestMovingObject::moveParentAndListenerHasPosition" << std::endl ;
        std::cerr.flush() ;

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMovingObject::moveParentAndListenerHasPosition")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener_ship = system->createObject() ;
        Model::Positionned* listener_ship_positionned = new Model::Positionned();
        listener_ship->addTrait(listener_ship_positionned) ;
        
        Kernel::Object* listener = listener_ship->createObject() ;
        listener->addTrait(new Model::Positionned()) ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());
        
        Kernel::Object* ship = system->createObject() ;
        Model::Positionned* ship_positionned = new Model::Positionned(Model::Position::Meter(0,0,-50));
        ship->addTrait(ship_positionned);
        ship->addTrait(new Model::Oriented()) ;
        ship->addTrait(new Model::Mobile());
        
        Kernel::Object* engine = ship->createObject() ;
        engine->addTrait(new Model::Engine(Model::Force::Newton(10,10,10))) ;
        engine->addTrait(new Model::Positionned()) ;
        
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        
        float listener_position_x ;
        float listener_position_y ;
        float listener_position_z ;

        float expected_listener_position_x = 0 ;
        float expected_listener_position_y = 0 ;
        float expected_listener_position_z = 0 ;

        alGetListener3f(AL_POSITION,&listener_position_x,&listener_position_y,&listener_position_z) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_x,listener_position_x,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_y,listener_position_y,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_z,listener_position_z,delta) ;

        listener_ship_positionned->setPosition(listener_ship_positionned->getPosition()+Model::Position::Meter(0,0,-1));
        
        expected_listener_position_z -= 1 ;

        alGetListener3f(AL_POSITION,&listener_position_x,&listener_position_y,&listener_position_z) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_x,listener_position_x,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_y,listener_position_y,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_z,listener_position_z,delta) ;
      }
        void Collision::onInit()
        {
          InternalMessage("Model","Collision::onInit entering") ;
          m_beam = NULL ;
          m_destroyable = NULL ;
          /*
            if one object is a laser beam
            - destroy it 
            and if the other is destroyable
            - manage damage 
          */
          LaserBeam* beam1 = getTrait()->getObject1()->getTrait<LaserBeam>() ;
          LaserBeam* beam2 = getTrait()->getObject2()->getTrait<LaserBeam>() ;
          
          Destroyable* destroyable1 = getTrait()->getObject1()->getTrait<Destroyable>() ;
          Destroyable* destroyable2 = getTrait()->getObject2()->getTrait<Destroyable>() ;
          
          if (beam1)
          {
            m_beam = beam1 ;
            getTrait()->getObject1()->destroyObject() ;
          }

          if (beam2)
          {
            m_beam = beam2 ;
            getTrait()->getObject2()->destroyObject() ;
          }
          
          if (destroyable1)
          {
            m_destroyable = destroyable1 ;
          }

          if (destroyable2)
          {
            m_destroyable = destroyable2 ;
          }
          
          // handle beam/destroyable collision
          if (m_beam && m_destroyable)
          {
            InternalMessage("Model","Collision::onInit damaging " + Kernel::toString(m_beam->getEnergy().Joule())) ;
            m_destroyable->damage(m_beam->getEnergy()) ;
            Kernel::Object* hit = m_destroyable->getObject()->createObject() ;
            hit->addTrait(new Hit()) ;
            Position position(getRelativePosition(getObject(),m_destroyable->getObject())) ;

            InternalMessage("Model","Collision::onInit creating hit at " + ::Ogre::StringConverter::toString(position.Meter())) ;

            hit->addTrait(new Positioned(position)) ;
            hit->addTrait(new WithLifetime(Duration::Second(0))) ;
            hit->addTrait(new Sized(Distance(Distance::_Meter,60))) ;
            hit->addTrait(new Oriented(Orientation(position))) ;
          }          
          
          InternalMessage("Model","Collision::onInit leaving") ;
        }
      void TestDemonstration::oneShip()
      {
        InternalMessage("Sound","entering TestDemonstration::oneShip") ;
        std::cerr << "TestDemonstration::oneShip" << std::endl ;
        std::cerr.flush() ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model()) ;
        model->init() ;

        Kernel::Object* root = model->createObject() ;

        Kernel::Object* universe = root->createObject() ;
        universe->addTrait(new Model::Universe()) ;
        universe->addTrait(new Model::Positioned()) ;
        universe->setName("universe") ;

        Kernel::Object* system = universe->createObject() ;
        system->addTrait(new Model::StellarSystem()) ;
        system->addTrait(new Model::Positioned()) ;
        system->setName("system") ;

//        Kernel::Object* ship = Model::loadShip("test_ship",system) ;

        Kernel::Object* pilot = system->createObject() ;
        pilot->addTrait(new Model::Listener()) ;
        pilot->addTrait(new Model::Positioned()) ;
        pilot->addTrait(new Model::Oriented()) ;
        pilot->addTrait(new Model::Player()) ;
        pilot->addTrait(new Model::Observer()) ;
        pilot->addTrait(new Model::Active()) ;
        pilot->addTrait(new Model::Mobile()) ;

        Kernel::Object* ship2 = Model::loadShip("test_ship",system) ;

        Model::Positioned* ship2_positioned = ship2->getTrait<Model::Positioned>() ;
        ship2_positioned->setPosition(Model::Position::Meter(0,0,200)) ;
        ship2->getTrait<Model::Mobile>()->setSpeed(Model::Speed::MeterPerSecond(0,0,-50)) ;
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;

        std::set<Model::Throttle*> throttles = ship2->getChildren<Model::Throttle>() ;

        (*throttles.begin())->set(100) ;

        while (global_timer.getSecond() <= 4)
        {
          float seconds = timer.getSecond() ;
          if (seconds > 0)
          {
            timer.reset() ;
            ship2_positioned->setPosition(ship2_positioned->getPosition()+Model::Position::Meter(0,0,-50*seconds)) ;
            model->update(seconds) ;
          }
        }
        InternalMessage("Sound","leaving TestDemonstration::oneShip") ;
      }
      void TestBackgroundSound::basicTest()
      {
        /*!
          - build a background sound object wih a ogg
          - build an event colision with a wav (default sound.wav in OpenAL::colision.cpp code) 
          - build a listener
          - destroy the event  before the end of the sound
          - update the module for streaming during 10secondes
          -destroy all and clean sound module
        */

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestBackgroundSound::basicTest")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Positionned()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* emmiter = system->createObject() ;
        emmiter->addTrait(new Model::BackgroundSound("pu_comm_essai_1.ogg")) ;
        emmiter->addTrait(new Model::Positionned()) ;
        emmiter->addTrait(new Model::Oriented()) ;
        
        
        Kernel::Object* elm1 = system->createObject() ;
        Kernel::Object* elm2 = system->createObject() ;
        Kernel::Object* collision = system->createObject() ;
        const Model::Position& posRef = Model::Position();
        collision->addTrait(new Model::Collision(elm1, elm2, posRef)) ;
        InternalMessage("Sound","fin definition world") ;
        
        model->destroyObject(collision) ;
        
        InternalMessage("Sound","after destroy colision") ;
        
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        int i = 0 ;
        while(global_timer.getSecond() <= 10.0)
        {
          ++i ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }          
        
        InternalMessage("Sound","i=" + Kernel::toString(i)) ;
      }
      void TestMenu::customMission()
      {
        InternalMessage("GUI","GUI::TestMenu::customMission entering") ;
        try
        {
          std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMenu::customMission")) ;
          model->init() ;

          Kernel::Object* mission = model->createObject() ;
          mission->addTrait(new Model::CustomMission("test",NULL,NULL)) ;
          mission->addTrait(new Model::Edited()) ;

          Kernel::Object* team1 = mission->createObject() ;
          team1->addTrait(new Model::Team("team 1")) ;

          Kernel::Object* team2 = mission->createObject() ;
          team2->addTrait(new Model::Team("team 2")) ;

          Kernel::Object* team3 = mission->createObject() ;
          team3->addTrait(new Model::Team("team 3")) ;

          Kernel::Timer timer ;
          Kernel::Timer global_timer ;

          float test_duration = 0 ;

          try
          {
            test_duration = Kernel::Parameters::getValue<float>("GUI","Test.PlayerConfiguration.Duration") ;
          }
          catch(...)
          {
            test_duration = 5 ;
          }

          while (global_timer.getSecond() < test_duration)
          {
            float seconds = timer.getSecond() ;
            if (seconds != 0)
            {
              timer.reset() ;
            }
            model->update(seconds) ;
          }
        }
        catch( ::CEGUI::Exception& exception)
        {
          std::cout << exception.getMessage() << std::endl ;
          throw ;
        }

        InternalMessage("GUI","GUI::TestMenu::customMission leaving") ;
      }
Kernel::Object* DisplayTestFixture::createUniverseAndSystem(Kernel::Model* model) const
{
    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()) ;

    return system ;
}
Kernel::Object* DisplayTestFixture::createObserver(Kernel::Object* parent) const
{
    Kernel::Object* observer = parent->createObject() ;
    observer->addTrait(new Model::Observer()) ;
    observer->getTrait<Model::Observer>()->setFieldOfView(::Ogre::Degree(70)) ;
    observer->addTrait(new Model::Player()) ;
    observer->addTrait(new Model::Active()) ;
    observer->addTrait(new Model::Positioned()) ;
    observer->addTrait(new Model::Oriented()) ;

    return observer ;
}
    void CustomMission::load()
    {
      // setup the system 
      Kernel::Object* universe = getObject()->createObject() ;
      universe->addTrait(new Universe()) ;
      universe->addTrait(new Positioned()) ;
      universe->setName("universe") ;

      m_system = universe->createObject() ;
      m_system->addTrait(new StellarSystem()) ;
      m_system->addTrait(new Positioned()) ;
      m_system->setName("system") ;
    }
      void TestMenu::testFullMenu()
      {
        InternalMessage("GUI","GUI::TestMenu::testFullMenu entering") ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMenu::testFullMenu")) ;
        model->init() ;

        Kernel::Object* root = model->createObject() ;
        root->addTrait(new Model::State()) ;
        root->addTrait(new Model::Active()) ;

        Kernel::Object* main_menu = root->createObject() ;
        main_menu->setName("main_menu") ;
        main_menu->addTrait(new Model::Menu("main_menu.layout")) ;
        main_menu->addTrait(new Model::State()) ;
        main_menu->getTrait<Model::State>()->addCommandAlias("configure","push(player_configuration,Edited)") ;

        Kernel::Object* player_configuration = Model::createDefaultPlayerConfiguration(main_menu) ;
        player_configuration->setName("player_configuration") ;
        player_configuration->addTrait(new Model::State()) ;

        root->getTrait<Model::State>()->changeState(main_menu,new Model::Displayed()) ;

        Kernel::Timer timer ;
        Kernel::Timer global_timer ;

        float test_duration = 0 ;

        try
        {
          test_duration = Kernel::Parameters::getValue<float>("GUI","Test.PlayerConfiguration.Duration") ;
        }
        catch(...)
        {
          test_duration = 5 ;
        }

        while (global_timer.getSecond() < test_duration)
        {
          float seconds = timer.getSecond() ;
          if (seconds != 0)
          {
            timer.reset() ;
          }
          model->update(seconds) ;
        }

        InternalMessage("GUI","GUI::TestMenu::testFullMenu leaving") ;

      }
      void TestSoundEvent::smallCollision()
      {
        std::cerr << "TestSoundEvent::smallCollision" << std::endl;
        std::cerr.flush() ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestSoundEvent::collision"));
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positioned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Positioned()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* collision = system->createObject() ;
        collision->addTrait(new Model::Collision(system,listener,Model::Energy::Joule(100))) ;
        collision->addTrait(new Model::Positioned(Model::Position::Meter(10,10,10))) ;

        Implementation::OpenAL::Collision* sound = collision->getView<Implementation::OpenAL::Collision>(model->getViewPoint<Implementation::OpenAL::RealWorldViewPoint>()) ;
        CPPUNIT_ASSERT(sound) ;

        Kernel::Timer timer;
        Kernel::Timer global_timer;

        while (global_timer.getSecond() <= 1)
        {
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
      }
      void TestSoundEvent::farCollision()
      {
        std::cerr << "TestSoundEvent::farCollision" << std::endl;
        std::cerr.flush() ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestSoundEvent::farCollision"));
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positioned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Positioned()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* collision = system->createObject() ;
        collision->addTrait(new Model::Collision(system,listener,Model::Energy::Joule(200))) ;
        collision->addTrait(new Model::Positioned(Model::Position::Meter(0,0,100))) ;

        Kernel::Timer timer;
        Kernel::Timer global_timer;

        while (global_timer.getSecond() <= 1)
        {
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }

      }
      void TestConeProperty::basicTest()
      {
        /*!
          - build a engine
          - build a listener
          - move the listener in a circle around the engine
            to heard the variation with the angle.
          
        */
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestConeProperty::basicTest")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        Model::Positionned* listenerPos = new Model::Positionned(Model::Position::Meter(0,0,0));
        listener->addTrait(listenerPos) ;
        listener->addTrait(new Model::Oriented(Model::Orientation(Ogre::Quaternion(1.0, 0.0, 10.0, 0.0)))) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* engine = system->createObject() ;
        engine->addTrait(new Model::Engine(Model::Force::Newton(10,10,10))) ;
        Model::Positionned* enginePos = new Model::Positionned(Model::Position::Meter(0,0,0));
        engine->addTrait(enginePos);
        engine->addTrait(new Model::Oriented(Model::Orientation(Ogre::Quaternion(1.0, 0.0, -10.0, 0.0)))) ;
        engine->addTrait(new Model::Mobile());
        
        Kernel::Timer timer ;

        float angle = 0;
        int tour = 0;
        while (tour < 1)
        {
          //variation between 0 and 100% of 2PI
          angle += 0.00005;
          if (angle > 1)
          {
            angle = 0;
            tour++;
          }
          listenerPos->setPosition(Model::Position::Meter(0.0,5*std::cos(angle*2*PI),5*std::sin(angle*2*PI)));
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }      
      }
      void TestGuidanceControl::fullRigth()
      {
        InternalMessage("Model","Model::TestGuidanceControl::basicTest entering") ;
        /// we construct a complete system on a ship
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestGuidanceControl::basicTest")) ;

        /// should be a PhysicalWorld
        Kernel::Object* system = model->createObject() ;
        CPPUNIT_ASSERT(system->getTrait<PhysicalWorld>()) ;

        Kernel::Object* ship = system->createObject() ;
        ship->addTrait(new Positionned()) ;
        ship->addTrait(new Oriented()) ;
        ship->addTrait(new Mobile()) ;
        ship->addTrait(new Massive(Mass::Kilogram(1000))) ;
        CPPUNIT_ASSERT(ship->getTrait<PhysicalObject>()) ;

        Kernel::Object* stick = ship->createObject() ;
        stick->addTrait(new Stick()) ;

        Kernel::Object* guidance_system = ship->createObject() ;
        guidance_system->addTrait(new GuidanceSystem(1)) ;

        Kernel::Object* guidance_control = ship->createObject() ;
        guidance_control->addTrait(new GuidanceControler()) ;

        connectStickControler(stick,guidance_control) ;
        connectControlerGuidanceSystem(guidance_control,guidance_system) ;

        // 100 on yaw means go rigth
        stick->call("Yaw",100) ;
        stick->getTrait<Stick>()->updateOrientation() ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x == 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y < 0) ;

        stick->call("Yaw",0) ;
        stick->getTrait<Stick>()->updateOrientation() ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x == 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y == 0) ;

        // 100 on pitch measn go down
        stick->call("Pitch",100) ;
        stick->getTrait<Stick>()->updateOrientation() ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().x < 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().z == 0) ;
        CPPUNIT_ASSERT(guidance_system->getTrait<GuidanceSystem>()->NewtonMeter().y == 0) ;
      }
예제 #22
0
    void Laser::fire()
    {
      InternalMessage("Model","entering fire") ;

      // handle firing rate
      if (m_time_to_fire.Second() > 0)
        return ;

      Positioned* positioned = getObject()->getParent<Positioned>() ;
      Oriented* oriented = getObject()->getParent<Oriented>() ;
      PhysicalObject* object = getObject()->getParent<PhysicalObject>() ;
      PhysicalWorld* world = object ? object->getObject()->getAncestor<PhysicalWorld>() : NULL ;

      if (world && positioned && oriented)
      {
        InternalMessage("Model","firing") ;
        // create a laser beam object
        Kernel::Object* beam = world->getObject()->createObject() ;

        // should apply local rotation to have correct local position..
        Orientation orientation_of_laser = oriented->getOrientation(world->getObject()) ;

        Position position_of_the_beam =
          positioned->getPosition(world->getObject()) + m_out_position*orientation_of_laser ;

        beam->addTrait(new Positioned(position_of_the_beam)) ;

        Orientation orientation_of_the_beam =
          orientation_of_laser*m_out_orientation ;

        beam->addTrait(new Oriented(orientation_of_the_beam)) ;

        // orientation gives speed vector
        // basic_speed(full Z oriented) * orientation
        Speed speed = Speed::MeterPerSecond(0,0,-getLaserSpeedMeterPerSecond())*orientation_of_the_beam ;

        // maybe we should add the object speed ?? (i.e. the speed of the ship)

        beam->addTrait(new Mobile(speed)) ;
        beam->addTrait(new Massive(Mass(m_laser_beam_energy,speed))) ;

        beam->addTrait(new LaserBeam(object->getObject(),m_beam_length,m_beam_radius)) ;
        beam->addTrait(new WithLifetime(getLaserBeamLifeDuration())) ;

        // shot
        Kernel::Object* shot = world->getObject()->createObject() ;
        shot->addTrait(new Positioned(position_of_the_beam)) ;
        shot->addTrait(new Shot()) ;

        // re-init timer
        m_time_to_fire = m_time_between_shots ;
        // done

      }
      // else : not much sense thus do nothing
      InternalMessage("Model","leaving fire") ;
    }
      void TestMenu::basicTest()
      {
        InternalMessage("GUI","GUI::TestMenu::basicTest entering") ;

        try
        {
          std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMenu::basicTest")) ;
          model->init() ;

          std::string menu_name ;

          menu_name = Kernel::Parameters::getValue<std::string>("GUI","Test.BasicTest.Name","main_menu.layout") ;

          Kernel::Object* menu = model->createObject() ;
          menu->addTrait(new Model::Menu(menu_name)) ;
          menu->addTrait(new Model::Displayed()) ;

          Kernel::Timer timer ;
          Kernel::Timer global_timer ;

          float test_duration = 0 ;

          test_duration = Kernel::Parameters::getValue<float>("GUI","Test.BasicTest.Duration",5) ;

          while (global_timer.getSecond() < test_duration)
          {
            float seconds = timer.getSecond() ;
            if (seconds != 0)
            {
              timer.reset() ;
            }
            model->update(seconds) ;
          }
        }
        catch( ::CEGUI::Exception& exception)
        {
          std::cout << exception.getMessage() << std::endl ;
          throw ;
        }
        InternalMessage("GUI","GUI::TestMenu::mouseCursor leaving") ;
      }
      void TestAgent::obstacles()
      {
        std::auto_ptr<Kernel::Model> model(new Kernel::Model()) ;
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::StellarSystem()) ;
        system->addTrait(new Model::Positioned()) ;

        Kernel::Object* ship1 = Model::createShip(system) ;
        Kernel::Object* agent1 = Model::createAI(ship1) ;

        Kernel::Object* ship2 = Model::createShip(system) ;
        Kernel::Object* agent2 = Model::createAI(ship2) ;

        Implementation::Agent* agent_controller1 = getAgentController(agent1) ;

        std::set<Implementation::Vehicle*> obstacles(agent_controller1->getObstacles()) ;
        CPPUNIT_ASSERT_EQUAL((unsigned int)1,obstacles.size()) ;
        Implementation::Agent* agent_controller2 = getAgentController(agent2) ;
        CPPUNIT_ASSERT(agent_controller2->getVehicle()) ;
        CPPUNIT_ASSERT(obstacles.find(agent_controller2->getVehicle())!=obstacles.end()) ;
      }
      void TestAgent::applyOnlyToAI()
      {
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestModelControler::attackAllEnemies")) ;
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::StellarSystem()) ;
        system->addTrait(new Model::Positioned()) ;

        Kernel::ObjectReference ship1 ;
        {
          Kernel::Object* ship = Model::createShip(system) ;
          ship->getTrait<Model::Positioned>()->setPosition(Model::Position::Meter(0,0,0)) ;
          ship1 = ship ;
        }

        {
          Kernel::Object* ship = Model::createShip(system) ;
          ship->getTrait<Model::Positioned>()->setPosition(Model::Position::Meter(1000,0,0)) ;
        }

        ship1->call(Model::TargetingSystem::SelectNextTarget) ;
      }
      void TestInputSystem::testKeyboardAutoRepeat()
      {
        InternalMessage("Input","Input::TestInputSystem::testKeyboardAutoRepeat entering") ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestPlayerConfiguration::testKeyboardAutoRepeat")) ;
        model->init() ;
        Kernel::ControlerSet* controler_set = model->getControlerSet<Implementation::OIS::InputControlerSet>() ;
        controler_set->setTimeStep(0.01) ;

        Kernel::Object* root = model->createObject() ;
        root->addTrait(new Keyboard()) ;
        
        
        Implementation::OIS::Keyboard* keyboard = Implementation::OIS::getKeyboard() ;
        if (!keyboard)
        {
          std::cout << "warning : no keyboard found, skipping test" ;
          return ;
        }
        // send a key pressed
        ::OIS::KeyEvent keyboard_event(getOISKeyboard(),::OIS::KC_0,(unsigned int)'0') ;
        keyboard->keyPressed(keyboard_event) ;

        // count the actual interpreted key pressed events...
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        
        const float simulation_time = 2 ; 
        
        while (global_timer.getSecond() < simulation_time)
        {
          if (timer.getSecond() > 0.1)
          {
            model->update(timer.getSecond()) ;
            timer.reset() ;
          }
        }
        
        CPPUNIT_ASSERT_EQUAL((unsigned int)(simulation_time/
                             Kernel::Parameters::getValue<float>(
                                 "Input",
                                 "AutoRepeatDelay",
                                 Implementation::OIS::default_autorepeat_delay)),
                             KeyboardListener::m_count) ;
        
        InternalMessage("Input","Input::TestInputSystem::testKeyboardAutoRepeat leaving") ;
        
      }
      void TestBackgroundSound::wavSound()
      {
        std::cerr << "TestBackgroundSound::wavSound" << std::endl ;
        std::cerr.flush() ;
        InternalMessage("Sound","Enter TestBackgroundSound::wavSound") ;
        
        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestBackgroundSound::basicTest"));
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Positionned()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* emmiter = system->createObject() ;
        emmiter->addTrait(new Model::BackgroundSound("test.wav")) ;
        emmiter->addTrait(new Model::Positionned()) ;
        emmiter->addTrait(new Model::Oriented()) ;

        Kernel::Timer global_timer;
        Kernel::Timer timer;
        int i = 0;
        while (global_timer.getSecond() <= 2.0)
        {
          ++i;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        InternalMessage("Sound","Leave TestBackgroundSound::wavSound") ;

      }
      void TestInputSystem::testJoystickAutoRepeat()
      {
        InternalMessage("Input","Input::TestInputSystem::testJoystickAutoRepeat entering") ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestPlayerConfiguration::testJoystickAutoRepeat")) ;
        model->init() ;

        Kernel::Object* root = model->createObject() ;
        root->addTrait(new Joystick()) ;

        Implementation::OIS::Joystick* joystick = Implementation::OIS::getJoystick() ;
        if (!joystick)
        {
          std::cout << "warning : no joystick found, skipping test" ;
          return ;
        }
        // send a button pressed
        ::OIS::JoyStickEvent joystick_event(NULL,::OIS::JoyStickState()) ;
        joystick->buttonPressed(joystick_event,1) ;
        
        // count the actual interpreted key pressed events...
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        
        const float simulation_time = 2 ; 
        
        while (global_timer.getSecond() < simulation_time)
        {
          if (timer.getSecond() > 0.1)
          {
            model->update(timer.getSecond()) ;
            timer.reset() ;
          }
        }

        CPPUNIT_ASSERT_EQUAL((unsigned int)(simulation_time/
                             Kernel::Parameters::getValue<float>(
                                 "Input",                        
                                 "AutoRepeatDelay",
                                 Implementation::OIS::default_autorepeat_delay)),
                             JoystickListener::m_count) ;
        
        InternalMessage("Input","Input::TestInputSystem::testJoystickAutoRepeat leaving") ;
      }
      void TestSoundEvent::collision()
      {
        std::cerr << "TestSoundEvent::collision" << std::endl;
        std::cerr.flush() ;

        /*!
         - build an event object plays sound and destroy it
         - check that the sound is still playing
         */

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestSoundEvent::collision"));
        model->init() ;

        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positioned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Positioned()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* collision = system->createObject() ;
        collision->addTrait(new Model::Collision(system,listener,Model::Energy::Joule(200))) ;
        collision->addTrait(new Model::Positioned(Model::Position::Meter(10,10,10))) ;

        Kernel::Timer timer;
        Kernel::Timer global_timer;

        while (global_timer.getSecond() <= 1)
        {
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }

      }
      void TestMenu::playerConfiguration()
      {
        InternalMessage("GUI","GUI::TestMenu::playerConfiguration entering") ;

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMenu::playerConfiguration")) ;
        model->init() ;

        Kernel::Object* option = model->createObject() ;
        Kernel::Object* configuration = Model::createDefaultPlayerConfiguration(option) ;
        configuration->addTrait(new Model::Edited()) ;

        Kernel::Timer timer ;
        Kernel::Timer global_timer ;

        float test_duration = 0 ;

        try
        {
          test_duration = Kernel::Parameters::getValue<float>("GUI","Test.PlayerConfiguration.Duration") ;
        }
        catch(...)
        {
          test_duration = 5 ;
        }

        while (global_timer.getSecond() < test_duration)
        {
          float seconds = timer.getSecond() ;
          if (seconds != 0)
          {
            timer.reset() ;
          }
          model->update(seconds) ;
        }

        InternalMessage("GUI","GUI::TestMenu::playerConfiguration leaving") ;
      }