本文整理汇总了C++中kernel::Object类的典型用法代码示例。如果您正苦于以下问题:C++ Object类的具体用法?C++ Object怎么用?C++ Object使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testComputerDestruction
void TestDetector::testComputerDestruction()
{
InternalMessage("Model","Model::TestDetector::testComputerDestruction entering") ;
/*!
We create a ship with a detector and a second object to detect.
*/
std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestDetector::testComputerDestruction")) ;
model->init() ;
Kernel::Object* system = model->createObject() ;
Kernel::Object* ship = system->createObject() ;
ship->addTrait(new Positioned()) ;
ship->addTrait(new Oriented()) ;
ship->addTrait(new Mobile()) ;
ship->addTrait(new Solid(Mesh("test_ship.mesh"))) ;
ship->addTrait(new Massive(Mass::Kilogram(1000))) ;
ship->addTrait(new Computer()) ;
ship->addTrait(new Detector()) ;
Detector::connect(ship,ship) ;
Kernel::Object* ship2 = system->createObject() ;
ship2->addTrait(new Positioned(Position::Meter(0,0,500))) ;
ship2->addTrait(new Massive(Mass::Kilogram(1000))) ;
ship2->addTrait(new Oriented()) ;
ship2->addTrait(new Mobile()) ;
ship2->addTrait(new Solid(Mesh("test_ship.mesh"))) ;
InternalMessage("Model","Model::TestDetector::testComputerDestruction destroying computer") ;
ship->destroyTrait(ship->getTrait<Computer>()) ;
model->update(0.1) ;
InternalMessage("Model","Model::TestDetector::testComputerDestruction leaving") ;
}
示例2: steeringFullBackShouldTurn
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) ;
}
示例3: beamEnergy
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) ;
}
示例4: isTargetedByTarget
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()) ;
}
示例5: fire
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") ;
}
示例6: detectOneObject
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") ;
}
示例7: createObserver
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 ;
}
示例8: load
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") ;
}
示例9: SendSyncRequest
/// 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;
}
示例10: testFullMenu
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") ;
}
示例11: testKeyboardAutoRepeat
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") ;
}
示例12: SendSyncRequest
/// 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;
}
示例13: testJoystickAutoRepeat
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") ;
}
示例14: basicTest
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") ;
}
示例15: WaitSynchronizationN
/// 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;
}