void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) {
    if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) {
        exit();
    } else if (getState() == "Render Dialog") {
        if (event->key() == Qt::Key_Escape) {
            render_process->stopRender();
        }
    } else {
        if (event->key() == Qt::Key_F5) {
            // Start render in a thread
            if ((event->modifiers() & Qt::ControlModifier) and (event->modifiers() & Qt::ShiftModifier)) {
                render_process->startFinalRender();
            } else if (event->modifiers() & Qt::ControlModifier) {
                render_process->startMediumRender();
            } else {
                render_process->startQuickRender();
            }
        } else if (event->key() == Qt::Key_F6) {
            render_process->showPreviousRender();
        } else if (event->key() == Qt::Key_F12) {
            Logs::warning("UI") << "Current scenery dump:" << endl
                                << scenery->toString() << endl;
        } else if (event->key() == Qt::Key_N) {
            if (event->modifiers() & Qt::ControlModifier) {
                newFile();
            }
        } else if (event->key() == Qt::Key_S) {
            if (event->modifiers() & Qt::ControlModifier) {
                saveFile();
            }
        } else if (event->key() == Qt::Key_L or event->key() == Qt::Key_O) {
            if (event->modifiers() & Qt::ControlModifier) {
                loadFile();
            }
        } else if (event->key() == Qt::Key_Z) {
            if (event->modifiers() & Qt::ControlModifier) {
                if (event->modifiers() & Qt::ShiftModifier) {
                    getScenery()->redo();
                } else {
                    getScenery()->undo();
                }
            }
        } else if (event->key() == Qt::Key_Y) {
            if (event->modifiers() & Qt::ControlModifier) {
                getScenery()->redo();
            }
        }
    }
}
Example #2
0
void SoftwareRenderer::prepare() {
    scenery->validate();
    scenery->getCamera()->copy(render_camera);

    // Prepare sub renderers
    // TODO Don't recreate the renderer each time, only when it changes
    lighting->unregisterSource(atmosphere_renderer);
    delete atmosphere_renderer;
    if (getScenery()->getAtmosphere()->model == AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON) {
        atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this);
    } else {
        atmosphere_renderer = new BaseAtmosphereRenderer(this);
    }
    lighting->registerSource(atmosphere_renderer);

    clouds_renderer->update();
    terrain_renderer->update();
    water_renderer->update();

    nightsky_renderer->update();

    // Prepare global tools
    godrays->prepare(this);
    fluid_medium->clearMedia();
    // fluid_medium->registerMedium(water_renderer);
}
bool VegetationPresenceDefinition::collectInstances(vector<VegetationInstance> *result,
                                                    const VegetationModelDefinition &model, double xmin, double zmin,
                                                    double xmax, double zmax, bool outcomers) const {
    if (outcomers) {
        // Expand the area to include outcoming instances
        double max_radius = getMaxHeight();
        xmin -= max_radius;
        zmin -= max_radius;
        xmax += max_radius;
        zmax += max_radius;
    }

    int added = 0;

    auto generator = noise->getGenerator();
    double interval_value = interval->getValue();

    double xstart = xmin - fmod(xmin, interval_value);
    double zstart = zmin - fmod(zmin, interval_value);
    for (double x = xstart; x < xmax; x += interval_value) {
        for (double z = zstart; z < zmax; z += interval_value) {
            double detail = interval_value * 0.1;
            double noise_presence = generator->get2d(detail, x * 0.1, z * 0.1);
            if (noise_presence > 0.0) {
                double size =
                    0.1 + 0.2 * fabs(generator->get2d(detail, z * 10.0, x * 10.0)) * (noise_presence * 0.5 + 0.5);
                double angle = 3.0 * generator->get2d(detail, -x * 20.0, z * 20.0); // TODO balanced distribution
                double xo = x + fabs(generator->get2d(detail, x * 12.0, -z * 12.0));
                double zo = z + fabs(generator->get2d(detail, -x * 27.0, -z * 27.0));
                if (xo >= xmin and xo < xmax and zo >= zmin and zo < zmax) {
                    double y = getScenery()->getTerrain()->getInterpolatedHeight(xo, zo, true, true);
                    result->push_back(VegetationInstance(model, Vector3(xo, y, zo), size, angle));
                    added++;
                }
            }
        }
    }

    return added > 0;
}
Example #4
0
void SDRender::UpdateSky(double currentTime, double accelTime)
{
    // Detect first call (in order to initialize "last times").
    static bool bInitialized = false;
    static double lastTimeHighSpeed = 0;
    static int lastTimeLowSpeed = 0;

    // Nothing to do if static sky dome, or race not started.
    //if (!grDynamicSkyDome)	//TODO(kilo): find some meaning for this variable
    /*if (!SDSkyDomeDistance || SDTrack->skyversion < 1)
        return;*/

    if (currentTime < 0)
    {
        bInitialized = false;
        return;
    }

    if (!bInitialized)
    {
        if ( SDSkyDomeDistance )
        {
            // Ensure the sun and moon positions are reset
            const int timeOfDay = (int)SDTrack->local.timeofday;
            GLfloat sunAscension = SDTrack->local.sunascension;
            SDSunDeclination = (float)(15 * (double)timeOfDay / 3600 - 90.0);

            const float moonAscension = SDTrack->local.sunascension;
            //SDMoonDeclination = grUpdateMoonPos(timeOfDay);

            thesky->setSD( DEG2RAD(SDSunDeclination));
            thesky->setSRA( sunAscension );

            thesky->setMD( DEG2RAD(SDMoonDeclination) );
            thesky->setMRA( DEG2RAD(moonAscension) );
        }

        lastTimeHighSpeed = currentTime;
        lastTimeLowSpeed = 60 * (int)floor(accelTime / 60.0);

        bInitialized = true;
        return;
    }

    // At each call, update possibly high speed objects of the sky dome : the clouds.
    scenery = (SDScenery *)getScenery();
    double r_WrldX = scenery->getWorldX();
    double r_WrldY = scenery->getWorldY();

    osg::Vec3 viewPos(r_WrldX / 2, r_WrldY/ 2, 0.0 );
    thesky->reposition(viewPos, 0, currentTime - lastTimeHighSpeed);

    // Now, we are done for high speed objects.
    lastTimeHighSpeed = currentTime;

    // Check if time to update low speed objects : sun and moon (once every minute).
    int nextTimeLowSpeed = 60 * (int)floor((accelTime + 60.0) / 60.0);

    const float deltaTimeLowSpeed = (float)(nextTimeLowSpeed - lastTimeLowSpeed);

    // Update sun and moon, and thus global lighting / coloring parameters of the scene.
    if (nextTimeLowSpeed != lastTimeLowSpeed)
    {
        // 1) Update sun position
        const float deltaDecl = deltaTimeLowSpeed * 360.0f / (24.0f * 60.0f * 60.0f);
        SDSunDeclination += deltaDecl;
        if (SDSunDeclination >= 360.0f)
            SDSunDeclination -= 360.0f;

        thesky->setSD( DEG2RAD(SDSunDeclination) );

        // 2) Update moon position
        SDMoonDeclination += deltaDecl;
        if (SDMoonDeclination >= 360.0f)
            SDMoonDeclination -= 360.0f;

        thesky->setMD( DEG2RAD(SDMoonDeclination) );
        lastTimeLowSpeed = nextTimeLowSpeed;
    }

    // 3) Update scene color and light
    UpdateLight();

    sunLight->getLight()->setAmbient(SceneAmbiant);
    sunLight->getLight()->setDiffuse(SceneDiffuse);
    sunLight->getLight()->setSpecular(SceneSpecular);
    sunLight->setStateSetModes(*stateSet,osg::StateAttribute::ON);

    float emis = 0.5f * sky_brightness;
    float ambian = 0.8f * sky_brightness;

    Scene_ambiant = osg::Vec4f(ambian, ambian, ambian, 1.0f);
    osg::ref_ptr<osg::Material> material = new osg::Material;

    material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
    material->setAmbient(osg::Material::FRONT_AND_BACK, Scene_ambiant);
    stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
    stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

    osg::Vec3f sun_position = thesky->sunposition();
    osg::Vec3f sun_direction = -sun_position;
    osg::Vec4f position(sun_position, 1.0f);
    sunLight->getLight()->setPosition(position);
    sunLight->getLight()->setDirection(sun_direction);

}//grUpdateSky
Example #5
0
/**
 * SDRender
 * Initialises a scene (ie a new view).
 *
 * @return 0 if OK, -1 if something failed
 */
void SDRender::Init(tTrack *track)
{
    SDTrack = track;

    std::string datapath = GetDataDir();
    //datapath +="/";
    thesky = new SDSky;
    GfOut("SDSky class\n");

    // Sky dome / background.
    SDSkyDomeDistance = 20000;
    if (SDSkyDomeDistance > 0 && SDSkyDomeDistance < SDSkyDomeDistThresh)
        SDSkyDomeDistance = SDSkyDomeDistThresh; // If user enabled it (>0), must be at least the threshold.

    SDDynamicSkyDome = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_DYNAMICSKYDOME, GR_ATT_DYNAMICSKYDOME_DISABLED), GR_ATT_DYNAMICSKYDOME_ENABLED) == 0;

    GfLogInfo("Graphic options : Sky dome : distance = %u m, dynamic = %s\n",
              SDSkyDomeDistance, SDDynamicSkyDome ? "true" : "false");

    // Dynamic weather.
    //grDynamicWeather = GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_grDynamicWeather, (char*)NULL, grDynamicWeather);

    // Cloud layers.
    SDNbCloudLayers =
            (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_CLOUDLAYER, 0, 0) + 0.5);

    GfLogInfo("Graphic options : Number of cloud layers : %u\n", SDNbCloudLayers);

    SDMax_Visibility =
            (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_VISIBILITY, 0, 0));

    ShadowIndex = 0; // Default value index, in case file value not found in list.
    const char* pszShadow =
            GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_SHADOW_TYPE, GR_ATT_SHADOW_NONE);

    for (int i = 0; i < NbShadowValues; i++)
    {
        if (!strcmp(pszShadow, ShadowValues[i]))
        {
            ShadowIndex = i;
            break;
        }
    }

    TexSizeIndex = 0; // Default value index, in case file value not found in list.
    const char* pszTexSize =
            GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_SHADOW_SIZE, GR_ATT_SHADOW_1024);

    for (int i = 0; i < NbTexSizeValues; i++)
    {
        if (!strcmp(pszTexSize, TexSizeValues[i]))
        {
            TexSizeIndex = i;
            break;
        }
    }

    switch (TexSizeIndex)
    {
    case 0:
        ShadowTexSize = 512;
        break;

    case 1:
        ShadowTexSize = 1024;
        break;

    case 2:
        ShadowTexSize = 2048;
        break;

    case 3:
        ShadowTexSize = 4096;
        break;

    case 4:
        ShadowTexSize = 8192;
        break;

    default:
        ShadowTexSize = 1024;
        break;
    }

    QualityIndex = 0; // Default value index, in case file value not found in list.
    const char* pszQuality =
            GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_AGR_QUALITY, GR_ATT_AGR_LITTLE);

    for (int i = 0; i < NbQualityValues; i++)
    {
        if (!strcmp(pszQuality, QualityValues[i]))
        {
            QualityIndex = i;
            break;
        }
    }

    carsShader = 0; // Default value index, in case file value not found in list.
    const char* pszShaders =
            GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_SHADERS, GR_ATT_AGR_NULL);

    for (int i = 0; i < NbShadersValues; i++)
    {
        if (!strcmp(pszShaders, ShadersValues[i]))
        {
            carsShader = i;
            break;
        }
    }

    GfLogInfo("Graphic options : Shadow Type : %u\n", ShadowIndex);
    GfLogInfo("Graphic options : Shadow Texture Size : %u\n", ShadowTexSize);
    GfLogInfo("Graphic options : Shadow Quality : %u\n", QualityIndex);

    NStars = NMaxStars;
    if (AStarsData)
        delete [] AStarsData;

    AStarsData = new osg::Vec3d[NStars];

    for(int i= 0; i < NStars; i++)
    {
        AStarsData[i][0] = SDRandom() * PI;
        AStarsData[i][1] = SDRandom() * PI;
        AStarsData[i][2] = SDRandom() * 7.0;
    }

    GfLogInfo("  Stars (random) : %d\n", NStars);

    NPlanets = 0;
    APlanetsData = NULL;

    GfLogInfo("  Planets : %d\n", NPlanets);

    const int timeOfDay = (int)SDTrack->local.timeofday;
    const double domeSizeRatio = SDSkyDomeDistance / 80000.0;

    GfLogInfo("  domeSizeRation : %d\n", domeSizeRatio);

    thesky->build(datapath, SDSkyDomeDistance, SDSkyDomeDistance, 800,
                  40000, 800, 30000, NPlanets,
                  APlanetsData, NStars, AStarsData );
    GfOut("Build SKY\n");
    GLfloat sunAscension = SDTrack->local.sunascension;
    SDSunDeclination = (float)(15 * (double)timeOfDay / 3600 - 90.0);

    thesky->setSD( DEG2RAD(SDSunDeclination));
    thesky->setSRA( sunAscension );

    GfLogInfo("  Sun : time of day = %02d:%02d:%02d (declination = %.1f deg), "
              "ascension = %.1f deg\n", timeOfDay / 3600, (timeOfDay % 3600) / 60, timeOfDay % 60,
              SDSunDeclination, RAD2DEG(sunAscension));

    if ( SDSunDeclination > 180 )
        SDMoonDeclination = 3.0 + (rand() % 40);
    else
        SDMoonDeclination = (rand() % 270);

    //SDMoonDeclination = grUpdateMoonPos(timeOfDay);
    //SDMoonDeclination = 22.0; /*(rand() % 270);*/

    const float moonAscension = SDTrack->local.sunascension;

    thesky->setMD( DEG2RAD(SDMoonDeclination) );
    thesky->setMRA( DEG2RAD(moonAscension) );

    GfLogInfo("  Moon : declination = %.1f deg, ascension = %.1f deg\n",
              SDMoonDeclination, moonAscension);

    /*

    SDCloudLayer *layer = new SDCloudLayer(datapath);
    layer->setCoverage(layer->SD_CLOUD_CIRRUS);
    layer->setSpeed(30);
    layer->setDirection(20);
    layer->setElevation_m(3000);
    layer->setThickness_m(400  / domeSizeRatio);
    layer->setTransition_m(400  / domeSizeRatio);
    layer->setSpan_m(SDSkyDomeDistance / 2);
    thesky->add_cloud_layer(layer);

    SDCloudLayer *layer2 = new SDCloudLayer(datapath);
    layer2->setCoverage(layer2->SD_CLOUD_CIRRUS2);
    layer2->setSpeed(60);
    layer2->setDirection(20);
    layer2->setElevation_m(1500);
    layer2->setThickness_m(400  / domeSizeRatio);
    layer2->setTransition_m(400  / domeSizeRatio);
    layer2->setSpan_m(SDSkyDomeDistance / 2);
    thesky->add_cloud_layer(layer2);*/

    // Initialize the whole sky dome.
    SDScenery * scenery = (SDScenery *)getScenery();
    double r_WrldX = scenery->getWorldX();
    double r_WrldY = scenery->getWorldY();
    //double r_WrldZ = SDScenery::getWorldZ();
    osg::Vec3 viewPos(r_WrldX / 2, r_WrldY/ 2, 0.0 );

    weather();
    thesky->set_visibility( SDVisibility ); // Visibility in meters

    thesky->reposition( viewPos, 0, 0);
    sol_angle = (float)thesky->getSA();
    moon_angle = (float)thesky->getMA();
    thesky->repaint(SkyColor, FogColor, CloudsColor, sol_angle, moon_angle, NPlanets,
                    APlanetsData, NStars, AStarsData);
    UpdateLight();

    osg::ref_ptr<osg::Group> sceneGroup = new osg::Group;
    osg::ref_ptr<osg::Group> mRoot = new osg::Group;
    osg::ref_ptr<osgShadow::ShadowMap> vdsm = new osgShadow::ShadowMap;
    m_scene = new osg::Group;
    m_CarRoot = new osg::Group;
    m_RealRoot = new osg::Group;
    shadowRoot = new osgShadow::ShadowedScene;

    osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect = new osgParticle::PrecipitationEffect;

    if (SDVisibility < 2000)
    {
        sceneGroup->addChild(precipitationEffect.get());
    }

    osg::ref_ptr<osg::Group> scene = new osg::Group;
    osg::ref_ptr<osg::Group> background = new osg::Group;
    osg::ref_ptr<osg::Group> cargroup = new osg::Group;

    scene->addChild(scenery->getScene());
    cargroup->addChild(m_CarRoot.get());
    background->addChild(scenery->getBackground());

	if(ShadowIndex > 0)
	{
		switch (QualityIndex+1)
		{
		case 0:
			break;
		case 1:
			scene->setNodeMask( rcvShadowMask );
			background->setNodeMask(~(rcvShadowMask | castShadowMask));
			cargroup->setNodeMask(castShadowMask);
			break;
		case 2:
			scene->setNodeMask( rcvShadowMask );
			background->setNodeMask(~(rcvShadowMask | castShadowMask));
			cargroup->setNodeMask(rcvShadowMask | castShadowMask);
			break;
		case 3:
			scene->setNodeMask( rcvShadowMask | castShadowMask);
			background->setNodeMask(~(rcvShadowMask | castShadowMask));
			cargroup->setNodeMask(rcvShadowMask | castShadowMask);
			break;
		default:
			break;
		}
	}

    m_scene->addChild(scene.get());
    m_scene->addChild(cargroup.get());
    m_scene->addChild(background.get());

    sceneGroup->addChild(m_scene.get());

    stateSet = new osg::StateSet;
    stateSet = m_scene->getOrCreateStateSet();
    stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
    if (SDVisibility < 2000)
        stateSet->setAttributeAndModes(precipitationEffect->getFog());

    float emis = 0.5f * sky_brightness;
    float ambian = 0.8f * sky_brightness;
    osg::ref_ptr<osg::Material> material = new osg::Material;
    material->setColorMode(osg::Material::OFF); // switch glColor usage off
    Scene_ambiant = osg::Vec4f( ambian, ambian, ambian, 1.0f);            ;
    material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
    material->setAmbient(osg::Material::FRONT_AND_BACK, Scene_ambiant);
    stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
    stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);

    lightSource = new osg::LightSource;
    lightSource->getLight()->setDataVariance(osg::Object::DYNAMIC);
    lightSource->getLight()->setLightNum(0);
    // relative because of CameraView being just a clever transform node
    lightSource->setReferenceFrame(osg::LightSource::RELATIVE_RF);
    lightSource->setLocalStateSetModes(osg::StateAttribute::ON);
    lightSource->getLight()->setAmbient(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f));
    lightSource->getLight()->setDiffuse(osg::Vec4( 0.2f, 0.2f, 0.2f, 1.0f));
    lightSource->getLight()->setSpecular(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f));
    sceneGroup->addChild(lightSource);

    // we need a white diffuse light for the phase of the moon
    sunLight = new osg::LightSource;
    sunLight->getLight()->setDataVariance(osg::Object::DYNAMIC);
    sunLight->getLight()->setLightNum(1);
    sunLight->setReferenceFrame(osg::LightSource::RELATIVE_RF);
    sunLight->setLocalStateSetModes(osg::StateAttribute::ON);
    sunLight->getLight()->setAmbient(SceneAmbiant);
    sunLight->getLight()->setDiffuse(SceneDiffuse);
    sunLight->getLight()->setSpecular(SceneSpecular);
    sunLight->setStateSetModes(*stateSet,osg::StateAttribute::ON);

    osg::Vec3f sun_position = thesky->sunposition();
    osg::Vec3f sun_direction = -sun_position;
    osg::Vec4f position(sun_position, 1.0f);
    sunLight->getLight()->setPosition(position);
    sunLight->getLight()->setDirection(sun_direction);

    skyGroup = new osg::Group;
    skyGroup->setName("skyCloudsGroup");
    skyGroup->setNodeMask(thesky->BACKGROUND_BIT);
    skyGroup->addChild(thesky->getPreRoot());
    skyGroup->addChild((thesky->getCloudRoot()));

    skySS = new osg::StateSet;
    skySS = skyGroup->getOrCreateStateSet();
    skySS->setMode(GL_LIGHT0, osg::StateAttribute::OFF);
    skySS->setAttributeAndModes( new osg::ColorMask( true, true, true, false ), osg::StateAttribute::ON );

    skyGroup->setNodeMask(~(rcvShadowMask | castShadowMask));
    sunLight->addChild(skyGroup.get());

    mRoot->addChild(sceneGroup.get());
    mRoot->setStateSet(setFogState().get());
    mRoot->addChild(sunLight.get());

    // Clouds are added to the scene graph later
    osg::ref_ptr<osg::StateSet> stateSet2 = new osg::StateSet;
    stateSet2 = mRoot->getOrCreateStateSet();
    stateSet2->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
    stateSet2->setMode(GL_LIGHTING, osg::StateAttribute::ON);
    stateSet2->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);

    m_RealRoot->addChild(mRoot.get());

    GfOut("LE POINTEUR %d\n", mRoot.get());
}//SDRender::Init
void MainModelerWindow::newFile() {
    getScenery()->autoPreset();
    renderer->reset();
}
void MainModelerWindow::saveFile() {
    getScenery()->saveGlobal("saved.p3d");
}
Example #8
0
void Scene::updateActivity(float dt)
{
    if( !_isLoaded )
    {
        load();
        _isLoaded = true;
        return;
    }

    // tune scene reverberation
#ifdef GAMEPLAY_DEVELOPER_EDITION
    if( _reverberation )
    {
        bool _isChanged = false;
        // F4 = decrease inGain
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x3E] & 0x80 )
        {
            _reverberation->inGain -= 0.01f;
            _isChanged = true;
        }
        // F5 = increate inGain
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x3F] & 0x80 )
        {
            _reverberation->inGain += 0.01f;
            _isChanged = true;
        }
        // F6 = decrease reverbMixDB
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x40] & 0x80 )
        {
            _reverberation->reverbMixDB -= 0.001f;
            _isChanged = true;
        }
        // F7 = increate reverbMixDB
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x41] & 0x80 )
        {
            _reverberation->reverbMixDB += 0.001f;
            _isChanged = true;
        }
        // F8 = decrease reverbTime
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x42] & 0x80 )
        {
            _reverberation->reverbTime -= 0.01f;
            _isChanged = true;
        }
        // F9 = increase reverbTime
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x43] & 0x80 )
        {
            _reverberation->reverbTime += 0.01f;
            _isChanged = true;
        }
        // F10 = decrease hfTimeRatio
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x44] & 0x80 )
        {
            _reverberation->hfTimeRatio -= 0.001f;
            _isChanged = true;
        }
        // F11 = increase hfTimeRatio
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x57] & 0x80 )
        {
            _reverberation->hfTimeRatio += 0.001f;
            _isChanged = true;
        }
        if( _isChanged )
        {
            getScenery()->happen( getScenery(), EVENT_SCENE_REVERBERATION_IS_CHANGED, NULL );
            if( _modes.size() ) getTopMode()->happen( getTopMode(), EVENT_SCENE_REVERBERATION_IS_CHANGED, NULL );
            getCore()->logMessage(
                "Reverb = { %3.3f, %3.3f, %3.3f, %3.3f }",
                _reverberation->inGain,
                _reverberation->reverbMixDB,
                _reverberation->reverbTime,
                _reverberation->hfTimeRatio
            );
        }
    }
#endif

    // switch HUD
    _switchHUDTimeout -= dt;
    if( Gameplay::iGameplay->getActionChannel( ::iaSwitchHUDMode )->getTrigger() &&
            _switchHUDTimeout < 0 )
    {
        _isHUDEnabled = !_isHUDEnabled;
        _switchHUDTimeout = 0.25f;
    }

    // update playing time
    getCareer()->getVirtues()->statistics.playingTime += dt;

    // time speed effect
    dt *= _timeSpeed * _timeSpeedMultiplier;

    // wind time
    _windTime += dt * getCore()->getRandToolkit()->getUniform( 0.0f, 0.25f ) *
                 getCore()->getRandToolkit()->getUniform( 0.0f, 0.25f );

    // update scenery
    _scenery->updateActivity( dt );

    // remove complete modes
    if( _modes.size() )
    {
        if( _modes.top()->endOfMode() )
        {
            _modes.top()->onSuspend();
            delete _modes.top();
            _modes.pop();
            if( _modes.size() ) _modes.top()->onResume();
        }
    }
    // add mode queries
    if( _modeQuery )
    {
        if( _modes.size() ) _modes.top()->onSuspend();
        _modes.push( _modeQuery );
        _modes.top()->onResume();
        _modeQuery = NULL;
    }

    // update current mode
    //network->stopSending();
    if( _modes.size() )
    {
        _modes.top()->updateActivity( dt );
    }
    //if (!network->arePacketsLocked() && !network->arePacketsSendingLocked()) {
    //	network->beginSending();
    //}

    // update rain
    if( _rain )
    {
        Matrix4f cameraPose = _camera->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        _rain->setProperty( "Center", cameraPos );
        Vector3f vel = Vector3f( 0,-1000,0 ) - wrap( getWindAtPoint( PxVec3( 0,0,0 ) ) );
        _rain->setProperty( "Velocity", vel );
        _rain->setProperty( "NBias", 3.0f );
        _rain->setProperty( "TimeSpeed", _timeSpeed * _timeSpeedMultiplier );
    }

    // update camera
    if( _camera )
    {
        _camera->updateActivity( dt );

        Matrix4f cameraPose = _camera->getPose();
        Vector3f cameraOffset = Vector3f( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] ) -
                                Vector3f( _lastCameraPose[3][0], _lastCameraPose[3][1], _lastCameraPose[3][2] );
        Vector3f cameraVel = cameraOffset;
        float velMagnitude = cameraVel.length();
        velMagnitude = velMagnitude / ( dt > 0 ? dt : 0.001f );
        if( velMagnitude > 5000.0f ) velMagnitude = 5000.0f;
        cameraVel.normalize();
        cameraVel *= velMagnitude;
        Gameplay::iAudio->setListener( cameraPose, cameraVel );
        _lastCameraPose = cameraPose;
    }

    // check player health
    if( _career->getVirtues()->evolution.health < 0.75f && !Gameplay::iGameplay->_freeModeIsEnabled )
    {
#ifdef GAMEPLAY_DEMOVERSION
        // check top mode is not mission and not interrupt mode
        if( dynamic_cast<Mission*>( _modes.top() ) == NULL &&
                dynamic_cast<Interrupt*>( _modes.top() ) == NULL )
        {
            if( _career->getVirtues()->evolution.health > 0 )
            {
                _career->getVirtues()->evolution.health = 1.0f;
            }
            else
            {
                _endOfActivity = true;
            }
        }
#else
        // check top mode is not mission and not interrupt mode
        if( dynamic_cast<Mission*>( _modes.top() ) == NULL &&
                dynamic_cast<Interrupt*>( _modes.top() ) == NULL )
        {
            // force exit to career course
            _endOfActivity = true;
        }
#endif
    }
}
Example #9
0
void Scene::load(void)
{
    //#ifdef GAMEPLAY_EDITION_ND
    // cache default desktop texture
    engine::ITexture* desktopTexture = Gameplay::iGui->getDesktop()->getTexture();
    gui::Rect desktopTextureRect = Gameplay::iGui->getDesktop()->getTextureRect();
    // enumerate slides
    std::vector<std::string> slides;
    WIN32_FIND_DATA findData;
    HANDLE findHandle = FindFirstFile( "./res/slides/*.dds", &findData );
    if( findHandle != INVALID_HANDLE_VALUE )
    {
        slides.push_back( findData.cFileName );
        while( FindNextFile( findHandle, &findData ) ) slides.push_back( findData.cFileName );
        FindClose( findHandle );
    }
    // select slide texture
    engine::ITexture* slideTexture = NULL;
    if( slides.size() )
    {
        unsigned int slideId = getCore()->getRandToolkit()->getUniformInt() % slides.size();
        std::string resourceName = "./res/slides/" + slides[slideId];
        slideTexture = Gameplay::iEngine->createTexture( resourceName.c_str() );
        assert( slideTexture );
    }
    // replace desktop texture
    if( slideTexture )
    {
        Gameplay::iGui->getDesktop()->setTexture( slideTexture );
        Gameplay::iGui->getDesktop()->setTextureRect(
            gui::Rect( 0,0, slideTexture->getWidth(), slideTexture->getHeight() )
        );
    }
    //#endif

    callback::BSPL   bsps;
    callback::ClumpL clumps;
    callback::ClumpI clumpI;
    callback::AtomicL atomicL;
    callback::AtomicI atomicI;

    // insert loading window in Gui
    Gameplay::iGui->getDesktop()->insertPanel( _loadingWindow->getPanel() );
    _loadingWindow->align( gui::atBottom, 4, gui::atCenter, 0 );

    // database record for scene location
    database::LocationInfo* locationInfo = database::LocationInfo::getRecord( _location->getDatabaseId() );

    // load local textures
    if( locationInfo->localTextures )
    {
        const char** resourceName = locationInfo->localTextures;
        while( *resourceName != NULL )
        {
            engine::ITexture* texture = Gameplay::iEngine->createTexture( *resourceName );
            assert( texture );
            texture->addReference();
            texture->setMagFilter( engine::ftLinear );
            texture->setMinFilter( engine::ftLinear );
            texture->setMipFilter( engine::ftLinear );
            _localTextures.push_back( texture );
            resourceName++;
        }
    }


    // retrieve weather options
    database::LocationInfo::Weather* weatherOption = NULL;
    if( locationInfo->weathers )
    {
        database::LocationInfo::Weather* currentOption = locationInfo->weathers;
        while( currentOption->weather != ::wtDatabaseEnding )
        {
            if( currentOption->weather == _location->getWeather() )
            {
                weatherOption = currentOption;
                break;
            }
            currentOption++;
        }
    }

    // retrieve weather option
    if( _locationWeather )
    {
        // load panorama
        _panoramaNearClip = _locationWeather->panorama.zNear;
        _panoramaFarClip  = _locationWeather->panorama.zFar;
        _panoramaAsset    = Gameplay::iEngine->createAsset( engine::atBinary, _locationWeather->panorama.resource );
        assert( _panoramaAsset );
        _panoramaAsset->forAllBSPs( callback::enumerateBSPs, &bsps );
        assert( bsps.size() );
        _panoramaAsset->forAllClumps( callback::enumerateClumps, &clumps );
        _panorama = *( bsps.begin() );

        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
            _panorama->add( *( clumpI ) );
        }
        bsps.clear();
        clumps.clear();
    }

    //_panorama->forAllClumps( adjustSunLightCCB, &sunMute );
    //_panorama->forAllClumps( adjustAmbientLightCCB, &ambientMute );

    // load stage
    _stageNearClip = locationInfo->stage.zNear;
    _stageFarClip = locationInfo->stage.zFar;
    _stageAsset = Gameplay::iEngine->createAsset( engine::atBinary, locationInfo->stage.resource );
    assert( _stageAsset );
    //_stageAsset = Gameplay::iEngine->createAsset( engine::atBinary, "./res/dropzone/burjdubai.ba" ); assert( _stageAsset );

    _stageAsset->forAllBSPs( callback::enumerateBSPs, &bsps );
    assert( bsps.size() );
    _stageAsset->forAllClumps( callback::enumerateClumps, &clumps );
    _stage = *( bsps.begin() );
    for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
    {
        _stage->add( *( clumpI ) );
    }
    bsps.clear();
    clumps.clear();

    // modify rendering options
    if( weatherOption )
    {
        assert( weatherOption->fogType != engine::fogLinear );
        _stage->setFogType( weatherOption->fogType );
        _stage->setFogDensity( weatherOption->fogDensity );
        _stage->setFogColor( weatherOption->fogColor );
        _stage->forAllClumps( adjustSunLightCCB, &weatherOption->sunMute );
        _stage->forAllClumps( adjustAmbientLightCCB, &weatherOption->ambientMute );
    }

    // load extras
    _extrasAsset = Gameplay::iEngine->createAsset( engine::atBinary, locationInfo->extras.resource );
    assert( _extrasAsset );

    // load local assets
    database::LocationInfo::AssetInfo* assetInfo = locationInfo->localAssets;
    while( assetInfo->name != NULL )
    {
        // load asset
        engine::IAsset* asset = Gameplay::iEngine->createAsset( engine::atXFile, assetInfo->resource );
        assert( asset );
        // rename clumps
        asset->forAllClumps( callback::enumerateClumps, &clumps );
        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
            (*( clumpI ))->setName( assetInfo->name );
        }
        // preprocess asset
        xpp::preprocessXAsset( asset );
        // insert asset in scene storage
        _localAssets.push_back( asset );
        clumps.clear();
        assetInfo++;
    }

    // initialize afterfx
    _brightPass = locationInfo->afterFx.brightPass;
    _bloom = locationInfo->afterFx.bloom;

    // initialize grass
    TiXmlElement* details = Gameplay::iGameplay->getConfigElement( "details" );
    int grass = 0;
    details->Attribute( "grass", &grass );
    if( grass != 0 )
    {
        _grassTexture = NULL;
        if( locationInfo->grass.scheme != NULL )
        {
            // load grass texture
            _grassTexture = Gameplay::iEngine->getTexture( locationInfo->grass.textureName );
            if( !_grassTexture )
            {
                _grassTexture = Gameplay::iEngine->createTexture( locationInfo->grass.textureResource );
                assert( _grassTexture );
            }
            _grassTexture->addReference();
            _grassTexture->setMagFilter( engine::ftLinear );
            _grassTexture->setMinFilter( engine::ftLinear );
            _grassTexture->setMipFilter( engine::ftLinear );
            _grassTexture->setMipmapLODBias( -2 );

            // locate template atomic
            callback::Locator locator;
            engine::IClump* templateClump = locator.locate( _extrasAsset, locationInfo->grass.templ );
            assert( templateClump );
            templateClump->getFrame()->translate( Vector3f(0,0,0) );
            templateClump->getFrame()->getLTM();
            templateClump->forAllAtomics( callback::enumerateAtomics, &atomicL );
            assert( atomicL.size() == 1 );

            // generate (load) grass
            _grass = Gameplay::iEngine->createGrass(
                         locationInfo->grass.cache,
                         *atomicL.begin(),
                         _grassTexture,
                         locationInfo->grass.scheme,
                         locationInfo->grass.fadeStart,
                         locationInfo->grass.fadeEnd
                     );
            assert( _grass );
            _stage->add( _grass );
        }
    }

    // generate rain settings
    unsigned int numParticles = 0;
    switch( _location->getWeather() )
    {
    case ::wtLightRain:
        numParticles = 1024;
        break;
    case ::wtHardRain:
        numParticles = 2048;
        break;
    case ::wtThunder:
        numParticles = 3072;
        break;
    }

    // initialize rain
    if( numParticles )
    {
        // load rain texture
        _rainTexture = Gameplay::iEngine->createTexture( "./res/particles/rain.dds" );
        assert( _rainTexture );
        _rainTexture->addReference();
        _rainTexture->setMagFilter( engine::ftLinear );
        _rainTexture->setMinFilter( engine::ftLinear );
        _rainTexture->setMipFilter( engine::ftLinear );
        _rainTexture->setMipmapLODBias( -2 );

        // create rain
        _rain = Gameplay::iEngine->createRain( numParticles, 1250.0f, _rainTexture, Vector4f( 1,1,1,1 ) );
        assert( _rain );
        _stage->add( _rain );
    }

    // initialize exit points
    clumps.clear();
    _extrasAsset->forAllClumps( callback::enumerateClumps, &clumps );
    database::LocationInfo::ExitPoint* exitPoint = locationInfo->exitPoints;
    while( exitPoint->nameId != 0 )
    {
        // search for enclosure clump
        bool creationFlag = false;
        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
//			getCore()->logMessage((*clumpI)->getName());
            if( strcmp( (*clumpI)->getName(), exitPoint->extras ) == 0 )
            {
                _enclosures.insert( EnclosureT( exitPoint, new Enclosure( *clumpI, exitPoint->delay ) ) );
                creationFlag = true;
                break;
            }
        }
        assert( creationFlag );
        // next exit point
        exitPoint++;
    }

    // initialize physics
    initializePhysics();

    // casting
    if( locationInfo->castingCallback ) locationInfo->castingCallback( getScenery() );

    // remove loading window from Gui
    Gameplay::iGui->getDesktop()->removePanel( _loadingWindow->getPanel() );

#ifdef GAMEPLAY_EDITION_ND
    // remove slide
    if( slideTexture )
    {
        Gameplay::iGui->getDesktop()->setTexture( desktopTexture );
        Gameplay::iGui->getDesktop()->setTextureRect( desktopTextureRect );
        slideTexture->release();
    }
#endif


    // CLEAN VERSION
    //updateDaytime();
}