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::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 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::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 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 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") ;
      }
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") ;
    }
Exemple #9
0
/// Synchronize to an OS service
static Result SendSyncRequest(Handle handle) {
    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);

    _assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");
    DEBUG_LOG(SVC, "called handle=0x%08X(%s)", handle, object->GetTypeName().c_str());

    bool wait = false;
    Result res = object->SyncRequest(&wait);
    if (wait) {
        Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
    }

    return res;
}
      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 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") ;
        
      }
Exemple #12
0
/// Synchronize to an OS service
static Result SendSyncRequest(Handle handle) {
    // TODO(yuriks): ObjectPool::Get tries to check the Object type, which fails since this is a generic base Object,
    // so we are forced to use GetFast and manually verify the handle.
    if (!Kernel::g_object_pool.IsValid(handle)) {
        return InvalidHandle(ErrorModule::Kernel).raw;
    }
    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);

    _assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");
    DEBUG_LOG(SVC, "called handle=0x%08X(%s)", handle, object->GetTypeName().c_str());

    ResultVal<bool> wait = object->SyncRequest();
    if (wait.Succeeded() && *wait) {
        Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
    }

    return wait.Code().raw;
}
      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 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") ;
      }
Exemple #15
0
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all,
    s64 nano_seconds) {
    // TODO(bunnei): Do something with nano_seconds, currently ignoring this
    bool unlock_all = true;
    bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated

    DEBUG_LOG(SVC, "called handle_count=%d, wait_all=%s, nanoseconds=%lld",
        handle_count, (wait_all ? "true" : "false"), nano_seconds);

    // Iterate through each handle, synchronize kernel object
    for (s32 i = 0; i < handle_count; i++) {
        if (!Kernel::g_object_pool.IsValid(handles[i])) {
            return InvalidHandle(ErrorModule::Kernel).raw;
        }
        Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handles[i]);

        DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(),
            object->GetName().c_str());

        // TODO(yuriks): Verify how the real function behaves when an error happens here
        ResultVal<bool> wait_result = object->WaitSynchronization();
        bool wait = wait_result.Succeeded() && *wait_result;

        if (!wait && !wait_all) {
            *out = i;
            return RESULT_SUCCESS.raw;
        } else {
            unlock_all = false;
        }
    }

    if (wait_all && unlock_all) {
        *out = handle_count;
        return RESULT_SUCCESS.raw;
    }

    // Check for next thread to schedule
    HLE::Reschedule(__func__);

    return RESULT_SUCCESS.raw;
}
Exemple #16
0
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all,
    s64 nano_seconds) {
    // TODO(bunnei): Do something with nano_seconds, currently ignoring this
    bool unlock_all = true;
    bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated

    DEBUG_LOG(SVC, "called handle_count=%d, wait_all=%s, nanoseconds=%lld",
        handle_count, (wait_all ? "true" : "false"), nano_seconds);

    // Iterate through each handle, synchronize kernel object
    for (s32 i = 0; i < handle_count; i++) {
        bool wait = false;
        Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handles[i]);

        _assert_msg_(KERNEL, (object != nullptr), "called handle=0x%08X, but kernel object "
            "is nullptr!", handles[i]);

        DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(),
            object->GetName().c_str());

        Result res = object->WaitSynchronization(&wait);

        if (!wait && !wait_all) {
            *out = i;
            return 0;
        } else {
            unlock_all = false;
        }
    }

    if (wait_all && unlock_all) {
        *out = handle_count;
        return 0;
    }

    // Check for next thread to schedule
    HLE::Reschedule(__func__);

    return 0;
}
      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") ;
      }
Exemple #18
0
/// Wait for a handle to synchronize, timeout after the specified nanoseconds
static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
    // TODO(bunnei): Do something with nano_seconds, currently ignoring this
    bool wait = false;
    bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated

    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);

    DEBUG_LOG(SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(),
            object->GetName().c_str(), nano_seconds);

    _assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");

    Result res = object->WaitSynchronization(&wait);

    // Check for next thread to schedule
    if (wait) {
        HLE::Reschedule(__func__);
        return 0;
    }

    return res;
}
Exemple #19
0
/// Wait for a handle to synchronize, timeout after the specified nanoseconds
static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
    // TODO(bunnei): Do something with nano_seconds, currently ignoring this
    bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated

    if (!Kernel::g_object_pool.IsValid(handle)) {
        return InvalidHandle(ErrorModule::Kernel).raw;
    }
    Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);
    _dbg_assert_(KERNEL, object != nullptr);

    DEBUG_LOG(SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(),
            object->GetName().c_str(), nano_seconds);

    ResultVal<bool> wait = object->WaitSynchronization();

    // Check for next thread to schedule
    if (wait.Succeeded() && *wait) {
        HLE::Reschedule(__func__);
    }

    return wait.Code().raw;
}
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 ;
}
        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 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 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") ;
      }
      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") ;
      }
      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 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() ;
        collision->addTrait(new Model::Collision(elm1, elm2)) ;
        collision->addTrait(new Model::Positionned()) ;
        
        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 TestSoundEnvironnement::basicTest()
      {
        std::cerr << "TestSoundEnvironnement::basicTest"  ;
        std::cerr.flush() ;
        
        /*!
         - build a SoundEnvironnement
         - build an Engine in this environnement
         - build a listener in the same environnement   
         - change a parent and listen the sound continue with just a little artefact between the close and init
         */

        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestSoundEnvironnement::basicTest"));
        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(Model::Orientation(Ogre::Quaternion(1.0, 0.0, 10.0, 0.0)))) ;
        listener->addTrait(new Model::Mobile());

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

        ship->getChild<Model::Throttle>()->set(100) ;

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

        std::cerr << " normal... " ;
        std::cerr.flush() ;

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

        Kernel::Object* env = system->createObject() ;
        Model::SoundEnvironnement* soundEnv = new Model::SoundEnvironnement();
        //        soundEnv->setDensity(0.5) ;
        //        soundEnv->setDiffusion(1.0) ;
        //        soundEnv->setGain(0.5) ;
        //        soundEnv->setGainHF(1.0) ;
        //        soundEnv->setDecayTime(2.0) ;
        //        soundEnv->setDecayHFRatio(1.1) ;
        //        soundEnv->setReflexionsGain(1.0) ;
        //        soundEnv->setReflexionsDelay(2.0) ;
        //        soundEnv->setLateReverbGain(1.0) ;
        //        soundEnv->setLateReverbDelay(2.5) ;
        env->addTrait(soundEnv) ;
        ship->changeParent(env) ;

        std::cerr << " switching environement... " << std::endl ;
        std::cerr.flush() ;

        while (global_timer.getSecond() <= 6)
        {
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
      }
      void TestMovingObject::basicTest()
      {
        std::cerr << "TestMovingObject::basicTest" << std::endl ;
        std::cerr.flush() ;
        /*!
          - build a engine
          - build a listener
          - move the engine position
          - 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("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* 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,-50));
        engine->addTrait(enginePos);
        engine->addTrait(new Model::Oriented()) ;
        engine->addTrait(new Model::Mobile());
        
        Kernel::ViewPoint* viewpoint = model->getViewPoint<Implementation::OpenAL::RealWorldViewPoint>() ;
        
        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) ;
        
        /// moving on Z axis
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+ Model::Position::Meter(0,0,0.005));
          expected_position_z += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on X axis
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(-50,0,0));
        
        expected_position_x = -50 ;
        expected_position_y = 0 ;
        expected_position_z = 0 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+Model::Position::Meter(0.005,0,0));
          expected_position_x += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on Y axis
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(0,-50,0));
        
        expected_position_x = 0 ;
        expected_position_y = -50 ;
        expected_position_z = 0 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+Model::Position::Meter(0,0.005,0));
          expected_position_y += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on X axis listener and source
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(0,0,-100));
        
        expected_position_x = 0 ;
        expected_position_y = 0 ;
        expected_position_z = -100 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        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 ;
        
        while (global_timer.getSecond() <= 1)
        {
          listenerPos->setPosition(listenerPos->getPosition()+ Model::Position::Meter(0,0,-0.005));
          expected_listener_position_z -= 0.005 ;
          
          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) ;
          
          enginePos->setPosition(enginePos->getPosition()+ Model::Position::Meter(0,0,0.005));
          expected_position_z += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        InternalMessage("Sound","after sound close") ;
      }
      void TestMovingObject::moveParentAndSourceHasPosition()
      {
        std::cerr << "TestMovingObject::moveParentAndSourceHasPosition" << std::endl ;
        std::cerr.flush() ;

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMovingObject::moveParentAndSourceHasPosition")) ;
        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))) ;
        engine->addTrait(new Model::Positionned()) ;
        
        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,-1));
        
        expected_position_z -= 1 ;

        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
      }