示例#1
0
task main()
{
	startTask(gyro_loop);
	startTask(sonar_loop);
	while(gyro_loop_state!=READING) sleep(5);
	faceObject();
	sleep(1000);
	turn();

}
bool DroidObjectImplementation::sendConversationStartTo(SceneObject* player) {
	if (!player->isPlayerCreature() || isDead())
		return false;

	if (player != getLinkedCreature().get())
		return false;

	BaseDroidModuleComponent* m = getModule("personality_chip");
	if (m == NULL) {
		return false;
	}

	DroidPersonalityModuleDataComponent* personality = dynamic_cast<DroidPersonalityModuleDataComponent*>(m);
	if (personality == NULL) {
		return false;
	}

	if (personality->getPersonalityConversationTemplate() == 0) {
		return false;
	}

	//Face player.
	faceObject(player);

	PatrolPoint current(coordinates.getPosition(), getParent().get());

	broadcastNextPositionUpdate(&current);

	CreatureObject* playerCreature = cast<CreatureObject*>( player);
	StartNpcConversation* conv = new StartNpcConversation(playerCreature, getObjectID(), "");
	player->sendMessage(conv);

	SortedVector<ManagedReference<Observer*> > observers = getObservers(ObserverEventType::STARTCONVERSATION);

	for (int i = 0;  i < observers.size(); ++i) {
		if (dynamic_cast<ConversationObserver*>(observers.get(i).get()) != NULL) {
			return true;
		}
	}
	//Create conversation observer.
	ConversationObserver* conversationObserver = ConversationManager::instance()->getConversationObserver(personality->getPersonalityConversationTemplate());

	if (conversationObserver != NULL) {
		//Register observers.
		registerObserver(ObserverEventType::CONVERSE, conversationObserver);
		registerObserver(ObserverEventType::STARTCONVERSATION, conversationObserver);
		registerObserver(ObserverEventType::SELECTCONVERSATION, conversationObserver);
		registerObserver(ObserverEventType::STOPCONVERSATION, conversationObserver);
	} else {
		error("Could not create conversation observer.");
		return false;
	}

	return true;
}
示例#3
0
void BuddyPlayer::act( vector< Object * > * others, World * world, vector< Object * > * add ){
    Character::act(others, world, add);

    if (show_life > getHealth()){
        show_life--;
    }

    if (show_life < getHealth()){
        show_life++;
    }

    vector<Object *> enemies;

    if (getStatus() != Status_Ground && getStatus() != Status_Jumping){
        return;
    }

    filterEnemies(enemies, others);

    if (animation_current->Act()){
        animation_current->reset();
        // nextTicket();
        // animation_current = movements[ "idle" ];
        animation_current = getMovement("idle");
        animation_current->reset();
    }

    if (animation_current == getMovement("idle") ||
        animation_current == getMovement("walk") ){
        if (enemies.empty() && want_x == -1 && want_z == -1 && Util::rnd(15) == 0){
            // want_x = Util::rnd( 100 ) - 50 + furthestFriend( others, getAlliance(), this );
            want_x = Util::rnd(100) - 50 + (int) leader->getX();
            want_z = Util::rnd(world->getMinimumZ(), world->getMaximumZ());
        } else if (! enemies.empty()){
            const Object * main_enemy = findClosest(enemies);
            if ( main_enemy->getX() > getX() ){
                want_x = (int)(main_enemy->getX() - 20 - Util::rnd(20));
            } else {
                want_x = (int)(main_enemy->getX() + 20 + Util::rnd(20));
            }
            if (want_x < 1){
                want_x = Util::rnd(100) - 50 + (int) leader->getX();
            }
            want_z = (int)(Util::rnd(3) - 1 + main_enemy->getZ());
            faceObject(main_enemy);

            if (Util::rnd(35) == 0){
                vector<Util::ReferenceCount<Animation> > attacks;
                for (map<string, Util::ReferenceCount<Animation> >::const_iterator it = getMovements().begin(); it != getMovements().end(); it++){
                    Util::ReferenceCount<Animation> maybe = (*it).second;
                    if (maybe->isAttack() && maybe->getStatus() == Status_Ground && maybe->getName() != "special"){
                        attacks.push_back(maybe);
                    }
                }

                double attack_range = fabs( getX() - main_enemy->getX() );
                double zdistance = ZDistance( main_enemy );
                for (vector<Util::ReferenceCount<Animation> >::iterator it = attacks.begin(); it != attacks.end(); /**/){
                    Util::ReferenceCount<Animation> maybe = *it;
                    if (attack_range > maybe->getRange() || zdistance > maybe->getMinZDistance()){
                        it = attacks.erase(it);
                    } else {
                        it++;
                    }
                }

                if (!attacks.empty()){
                    animation_current = attacks[Util::rnd(attacks.size())];
                    world->addMessage(animationMessage());
                    nextTicket();
                    animation_current->reset();
                    return;
                } else {
                }
            }
        }

        if (want_x != -1 && want_z != -1){
            bool walk = false;
            if (want_x < 1){
                want_x = 1;
            }
            if (want_z < world->getMinimumZ()){
                want_z = world->getMinimumZ() + 1;
            }
            if (want_z >= world->getMaximumZ()){
                want_z = world->getMaximumZ() - 1;
            }
            if (getX() - want_x < -2){
                moveX(getSpeed());
                setFacing(FACING_RIGHT);
                walk = true;
            } else if (getX() - want_x > 2){
                setFacing(FACING_LEFT);
                moveX(getSpeed());
                walk = true;
            }

            if (getZ() < want_z){
                moveZ(getSpeed());
                walk = true;
            } else if (getZ() > want_z){
                moveZ(-getSpeed());
                walk = true;
            }

            if (walk){
                animation_current = getMovement("walk");
            }

            if (fabs(getX() - want_x) <= 2 &&
                fabs(getZ() - want_z) <= 2){
                want_x = -1;
                want_z = -1;
                animation_current = getMovement("idle");
            }
        }
    }
}
示例#4
0
int GenericCLIInterface(int argc, char** argv,
                        boost::shared_ptr<ElVis::Scene> scene,
                        boost::shared_ptr<ElVis::Model> model,
                        boost::shared_ptr<ElVis::ColorMap> colorMap,
                        unsigned int width, unsigned int height, const std::string& outFilePath, const ElVis::Camera& c)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(100, 100);
    glutCreateWindow("fake");

    std::cout << "Generic CLI Interface." << std::endl;
    const char* isovaluesLabel = "Isovalues";
    const char* isosurfaceModuleEnabledLabel = "IsosurfaceModuleEnabled";
    const char* volumeRenderingModuleEnabledLabel = "VolumeRenderingModuleEnabled";
    const char* contourModuleEnabledLabel = "ContourModuleEnabled";
    const char* meshModuleEnabledLabel = "MeshModuleEnabled";
    const char* boundarySurfacesLabel = "BoundarySurfaces";

    // Volume Rendering labels
    const char* integrationTypeLabel = "IntegrationType";
    const char* breakpointLabel = "Breakpoints";
    const char* colorsLabel = "Colors";
    const char* hLabel = "h";
    const char* epsilonLabel = "Epsilon";
    const char* traceLabel = "EnableTrace";
    const char* traceXLabel = "TraceX";
    const char* traceYLabel = "TraceY";
    const char* trackNumSamplesLabel = "TrackNumSamples";
    const char* renderIntegrationTypeLabel = "RenderIntegrationType";
    const char* emptySpaceSkippingLabel = "EnableEmptySpaceSkipping";

    const char* cutPlaneNormalLabel = "CutPlaneNormal";
    const char* cutPlanePointLabel= "CutPlanePoint";
    const char* fieldLabel="Field";

    const char* numTestsLabel = "NumTests";

    std::vector<double> cutPlaneNormal;
    std::vector<double> cutPlanePoint;
    std::vector<double> breakpoints;
    std::vector<double> colors;
    std::vector<int> boundarySurfaces;
    std::vector<double> isovalues;
    bool isosurfaceModuleEnabled = false;
    bool volumeRenderingModuleEnabled = false;
    bool contourModuleEnabled = false;
    bool meshModuleEnabled = false;
    unsigned int numTests = 1;
    std::string configFile;
    int fieldIndex = 0;

    boost::program_options::options_description desc("GenericCLIOptions");
    desc.add_options()
        (isovaluesLabel, boost::program_options::value<std::vector<double> >(&isovalues)->multitoken(), "Isovalues")
        (boundarySurfacesLabel, boost::program_options::value<std::vector<int> >(&boundarySurfaces)->multitoken(), "Boundary Surfaces")
        (isosurfaceModuleEnabledLabel, boost::program_options::value<bool>(&isosurfaceModuleEnabled), "Isosurface Module Enabled")
        (volumeRenderingModuleEnabledLabel, boost::program_options::value<bool>(&volumeRenderingModuleEnabled), "Volume Rendering Module Enabled")
        (contourModuleEnabledLabel, boost::program_options::value<bool>(&contourModuleEnabled), "Contour Module Enabled")
        (meshModuleEnabledLabel, boost::program_options::value<bool>(&meshModuleEnabled), "Mesh Module Enabled")
        (integrationTypeLabel, boost::program_options::value<int>(), "Integration Type")
        (breakpointLabel, boost::program_options::value<std::vector<double> >(&breakpoints)->multitoken(), "Breakpoints")
        (colorsLabel, boost::program_options::value<std::vector<double> >(&colors)->multitoken(), "Colors")
        (hLabel, boost::program_options::value<double>(), "h")
        (epsilonLabel, boost::program_options::value<double>(), "Epsilon")
        (traceLabel, boost::program_options::value<int>(), "Enable Trace")
        (traceXLabel, boost::program_options::value<int>(), "Trace X")
        (traceYLabel, boost::program_options::value<int>(), "Trace Y")
        (trackNumSamplesLabel, boost::program_options::value<int>(), "Track Num Samples")
        (renderIntegrationTypeLabel, boost::program_options::value<int>(), "RenderIntegrationType")
        (emptySpaceSkippingLabel, boost::program_options::value<int>(), "EnableEmptySpaceSkipping")
        (numTestsLabel, boost::program_options::value<unsigned int>(&numTests), "Number of Tests")
        (cutPlaneNormalLabel, boost::program_options::value<std::vector<double> >(&cutPlaneNormal)->multitoken(), "Cut Plane Normal")
        (cutPlanePointLabel, boost::program_options::value<std::vector<double> >(&cutPlanePoint)->multitoken(), "Cut Plane Point")
        (fieldLabel, boost::program_options::value<int>(&fieldIndex), "Field Index")
        ;

    const char* configFileNameLabel = "ConfigFile";

    boost::program_options::options_description configFileOptions("ConfigFileOptions");
    configFileOptions.add_options()
            (configFileNameLabel, boost::program_options::value<std::string>(&configFile), "Config File")
            ;

    boost::program_options::options_description commandLineOptions("CommandLineOptions");
    commandLineOptions.add(desc).add(configFileOptions);


    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(commandLineOptions).style(boost::program_options::command_line_style::allow_long |
                                                                                                              boost::program_options::command_line_style::long_allow_adjacent).allow_unregistered().run(), vm);
    boost::program_options::notify(vm);

    if( !configFile.empty() )
    {
        std::ifstream inFile(configFile.c_str());
        if( inFile )
        {
            boost::program_options::store(boost::program_options::parse_config_file(inFile, desc, true), vm);
            boost::program_options::notify(vm);
        }
        inFile.close();
    }

    #ifdef __GNUC__
    system("nvidia-smi");
    #endif

    ElVis::PointLight* l = new ElVis::PointLight();
    ElVis::Color lightColor;
    lightColor.SetRed(.5);
    lightColor.SetGreen(.5);
    lightColor.SetBlue(.5);

    ElVis::WorldPoint lightPos(10.0, 0.0, 0.0);
    l->SetColor(lightColor);
    l->SetPosition(lightPos);
    scene->AddLight(l);

    ElVis::Color ambientColor;
    ambientColor.SetRed(.5);
    ambientColor.SetGreen(.5);
    ambientColor.SetBlue(.5);
    scene->SetAmbientLightColor(ambientColor);

    boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView());
    view->SetCamera(c);


    view->SetScalarFieldIndex(fieldIndex);

    boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule());
    view->AddRenderModule(primaryRayModule);

    if( cutPlaneNormal.size() == 3 &&
        cutPlanePoint.size() == 3 )
    {
        ElVis::WorldPoint normal(cutPlaneNormal[0], cutPlaneNormal[1], cutPlaneNormal[2]);
        ElVis::WorldPoint p(cutPlanePoint[0], cutPlanePoint[1], cutPlanePoint[2]);
        
        boost::shared_ptr<ElVis::Plane> cutPlane(new ElVis::Plane(normal, p));
        boost::shared_ptr<ElVis::SampleVolumeSamplerObject> sampler(new ElVis::SampleVolumeSamplerObject(cutPlane));
        primaryRayModule->AddObject(sampler);
    }

    if( contourModuleEnabled )
    {
        std::cout << "Contour Module enabled.  Number of isovalues = " << isovalues.size() << std::endl;
        boost::shared_ptr<ElVis::CutSurfaceContourModule> contourModule(new ElVis::CutSurfaceContourModule());
        view->AddRenderModule(contourModule);

        for(unsigned int i = 0; i < isovalues.size(); ++i)
        {
            contourModule->AddIsovalue(isovalues[i]);
        }
    }

    if( meshModuleEnabled )
    {
        boost::shared_ptr<ElVis::CutSurfaceMeshModule> meshModule(new ElVis::CutSurfaceMeshModule());
        view->AddRenderModule(meshModule);
    }

    if( isosurfaceModuleEnabled )
    {
        boost::shared_ptr<ElVis::IsosurfaceModule> isosurfaceModule(new ElVis::IsosurfaceModule());
        view->AddRenderModule(isosurfaceModule);

        for(unsigned int i = 0; i < isovalues.size(); ++i)
        {
            isosurfaceModule->AddIsovalue(isovalues[i]);
        }
    }

    boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule());
    view->AddRenderModule(colorMapperModule);
    colorMapperModule->SetColorMap(colorMap);

    if( boundarySurfaces.size() > 0)
    {
        boost::shared_ptr<ElVis::FaceObject> faceObject(new ElVis::FaceObject(scene));
        boost::shared_ptr<ElVis::SampleFaceObject> obj(new ElVis::SampleFaceObject(faceObject));
        primaryRayModule->AddObject(obj);
        for(int i = 0; i < boundarySurfaces.size(); ++i)
        {
            std::vector<int> faceIds;
            std::string boundaryName;
            model->GetBoundarySurface(boundarySurfaces[i], boundaryName, faceIds);

            if( faceIds.empty() ) continue;

            for(unsigned int j = 0; j < faceIds.size(); ++j)
            {
                obj->EnableFace(faceIds[j]);
            }
        }
    }

    if( volumeRenderingModuleEnabled )
    {
        if( vm.count(integrationTypeLabel) == 0 )
        {
            return 1;
        }

        if( breakpoints.size()*4 != colors.size() )
        {
            std::cerr << "Invalid transfer specification." << std::endl;
            std::cerr << "Breakpoint size " << breakpoints.size() << std::endl;
            std::cerr << "Color size " << colors.size() << std::endl;
            return 1;
        }

        ElVis::VolumeRenderingIntegrationType integrationType = static_cast<ElVis::VolumeRenderingIntegrationType>(vm[integrationTypeLabel].as<int>());

        double h = .1;
        if( vm.count(hLabel) == 1 )
        {
            h = vm[hLabel].as<double>();
        }

        double epsilon = .001;
        if( vm.count(epsilonLabel) == 1 )
        {
            epsilon = vm[epsilonLabel].as<double>();
        }

        bool trackNumSamples = false;
        if( vm.count(trackNumSamplesLabel) == 1 )
        {
            trackNumSamples = (vm[trackNumSamplesLabel].as<int>() == 1);
        }

        bool renderIntegrationType = false;
        if( vm.count(renderIntegrationTypeLabel) == 1 )
        {
            renderIntegrationType = (vm[renderIntegrationTypeLabel].as<int>() == 1);
        }

        bool enableEmptySpaceSkipping = true;
        if( vm.count(emptySpaceSkippingLabel) == 1 )
        {
            enableEmptySpaceSkipping = (vm[emptySpaceSkippingLabel].as<int>() == 1);
        }

        boost::shared_ptr<ElVis::VolumeRenderingModule> m_volumeRenderingModule(new ElVis::VolumeRenderingModule());
        m_volumeRenderingModule->SetIntegrationType(integrationType);
        m_volumeRenderingModule->SetCompositingStepSize(h);
        m_volumeRenderingModule->SetEpsilon(epsilon);

        m_volumeRenderingModule->SetRenderIntegrationType(renderIntegrationType);
        m_volumeRenderingModule->SetEnableEmptySpaceSkipping(enableEmptySpaceSkipping);

        m_volumeRenderingModule->SetTrackNumberOfSamples(trackNumSamples);

        // Setup the transfer function.
        boost::shared_ptr<ElVis::HostTransferFunction> transferFunction = m_volumeRenderingModule->GetTransferFunction();
        for(unsigned int i = 0; i < breakpoints.size(); ++ i)
        {
            ElVis::Color c(colors[i*4], colors[i*4+1], colors[i*4+2], colors[i*4+3]);
            transferFunction->SetBreakpoint(breakpoints[i], c);
        }

        view->AddRenderModule(m_volumeRenderingModule);
    }

    boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule());
    view->AddRenderModule(lighting);


    view->SetScene(scene);
    view->Resize(width, height);


    // Don't time to take care of initialization artifacts.
    view->Draw();


    double* times = new double[numTests-1];
    for(unsigned int testNum = 1; testNum < numTests; ++testNum)
    {
        // Repeated redraws will do nothing if we don't signal that the view has changed in some way.
        view->OnSceneViewChanged(*view);
        ElVis::Timer t = view->Draw();
        times[testNum-1] = t.TimePerTest(1);
    }

    view->WriteColorBufferToFile(outFilePath.c_str());

    if( numTests > 1 )
    {
        ElVis::Stat runtimeStats(times, std::numeric_limits<ElVisFloat>::max(), numTests-1, .95);
        std::cout << "Average Time Per Run: " << runtimeStats.Mean << std::endl;
        #ifdef __GNUC__
        system("nvidia-smi");
        #endif

    }


    return 0;
}