Example #1
0
bool NetworkEventHandler::HandleOpenSimNetworkEvent(event_id_t event_id, Foundation::EventDataInterface* data)
{
    PROFILE(NetworkEventHandler_HandleOpenSimNetworkEvent);
    ProtocolUtilities::NetworkEventInboundData *netdata = checked_static_cast<ProtocolUtilities::NetworkEventInboundData *>(data);
    switch(event_id)
    {
    case RexNetMsgRegionHandshake:
        return HandleOSNE_RegionHandshake(netdata);

    case RexNetMsgAgentMovementComplete:
        return HandleOSNE_AgentMovementComplete(netdata);

    case RexNetMsgAvatarAnimation:
        return rexlogicmodule_->GetAvatarHandler()->HandleOSNE_AvatarAnimation(netdata);

    case RexNetMsgGenericMessage:
        return HandleOSNE_GenericMessage(netdata);

    case RexNetMsgLogoutReply:
        return HandleOSNE_LogoutReply(netdata);

    case RexNetMsgImprovedTerseObjectUpdate:
        return HandleOSNE_ImprovedTerseObjectUpdate(netdata);

    case RexNetMsgKillObject:
        return HandleOSNE_KillObject(netdata);

    case RexNetMsgObjectUpdate:
        return HandleOSNE_ObjectUpdate(netdata);

    case RexNetMsgObjectProperties:
        return rexlogicmodule_->GetPrimitiveHandler()->HandleOSNE_ObjectProperties(netdata);

    case RexNetMsgAttachedSound:
        return rexlogicmodule_->GetPrimitiveHandler()->HandleOSNE_AttachedSound(netdata);

    case RexNetMsgAttachedSoundGainChange:
        return rexlogicmodule_->GetPrimitiveHandler()->HandleOSNE_AttachedSoundGainChange(netdata);

    case RexNetMsgSoundTrigger:
        return HandleOSNE_SoundTrigger(netdata);

    case RexNetMsgPreloadSound:
        return HandleOSNE_PreloadSound(netdata);

    case RexNetMsgScriptDialog:
        return HandleOSNE_ScriptDialog(netdata);

    default:
        break;
    }

    return false;
}
Example #2
0
    bool EnvironmentModule::HandleNetworkEvent(event_id_t event_id, Foundation::EventDataInterface* data)
    {
        ProtocolUtilities::NetworkEventInboundData *netdata = checked_static_cast<ProtocolUtilities::NetworkEventInboundData *>(data);
        assert(netdata);

        switch(event_id)
        {
        case RexNetMsgLayerData:
        {
            if(terrain_.get())
            {
                static int count = 0;
                bool kill_event = terrain_->HandleOSNE_LayerData(netdata);
                if (environment_editor_)
                    environment_editor_->UpdateTerrain();
                return kill_event;
            }
        }
        case RexNetMsgGenericMessage:
        {
            ProtocolUtilities::NetInMessage &msg = *netdata->message;
            std::string methodname = ProtocolUtilities::ParseGenericMessageMethod(msg);

            if (methodname == "RexPostP")
            {
                OgreRenderer::Renderer *renderer = framework_->GetService<OgreRenderer::Renderer>();
                if (renderer)
                {
                    StringVector vec = ProtocolUtilities::ParseGenericMessageParameters(msg);
                    //Since postprocessing effect was enabled/disabled elsewhere, we have to notify the dialog about the event.
                    //Also, no need to put effect on from the CompositionHandler since the dialog will notify CompositionHandler when 
                    //button is checked
                    if (postprocess_dialog_)
                    {
                        QString effect_name = renderer->GetCompositionHandler()->MapNumberToEffectName(vec.at(0)).c_str();
                        bool enabled = true;
                        if (vec.at(1) == "False")
                            enabled = false;

                        postprocess_dialog_->EnableEffect(effect_name,enabled);
                    }
                }
            }
            else if(methodname == "RexSky" && sky_.get())
            {
                return GetSkyHandler()->HandleRexGM_RexSky(netdata);
            }
            else if (methodname == "RexWaterHeight")
            {
                msg.ResetReading();
                msg.SkipToFirstVariableByName("Parameter");

                // Variable block begins, should have currently (at least) 1 instances.
                size_t instance_count = msg.ReadCurrentBlockInstanceCount();
                if (instance_count < 1)
                    return false;

                if (water_.get() != 0)
                {
                    std::string message = msg.ReadString();
                    // Convert to float.
                    try
                    {
                        float height = boost::lexical_cast<float>(message);
                        water_->SetWaterHeight(height);
                    }
                    catch(boost::bad_lexical_cast&)
                    {
                    }
                }
            }
            else if (methodname == "RexDrawWater")
            {
                msg.ResetReading();
                msg.SkipToFirstVariableByName("Parameter");

                // Variable block begins, should have currently (at least) 1 instances.
                size_t instance_count = msg.ReadCurrentBlockInstanceCount();
                if (instance_count < 1 )
                    return false;

                std::string message = msg.ReadString();
                bool draw = ParseBool(message);
                if (draw)
                    if (water_.get())
                        water_->CreateWaterGeometry();
                    else
                        CreateWater();
                else
                    water_->RemoveWaterGeometry();
            }
            else if (methodname == "RexFog")
            {
                StringVector parameters = ProtocolUtilities::ParseGenericMessageParameters(msg); 
                if ( parameters.size() < 5)
                    return false;

                // may have , instead of . so replace
                ReplaceCharInplace(parameters[0], ',', '.');
                ReplaceCharInplace(parameters[1], ',', '.');
                ReplaceCharInplace(parameters[2], ',', '.');
                ReplaceCharInplace(parameters[3], ',', '.');
                ReplaceCharInplace(parameters[4], ',', '.');
                float fogStart = 0.0, fogEnd = 0.0, fogC_r = 0.0, fogC_g = 0.0, fogC_b = 0.0;

                try
                {
                    fogStart = boost::lexical_cast<float>(parameters[0]);
                    fogEnd = boost::lexical_cast<float>(parameters[1]);
                    fogC_r = boost::lexical_cast<float>(parameters[2]);
                    fogC_g = boost::lexical_cast<float>(parameters[3]);
                    fogC_b = boost::lexical_cast<float>(parameters[4]);
                }
                catch(boost::bad_lexical_cast&)
                {
                    return false;
                }
                if (environment_ != 0)
                {
                    // Adjust fog.
                    QVector<float> color;
                    color<<fogC_r<<fogC_g<<fogC_b;
                    environment_->SetWaterFog(fogStart, fogEnd, color); 
                }
            }
            else if (methodname == "RexAmbientL")
            {
                /**
                 * Deals RexAmbientLight message. 
                 **/
                
                StringVector parameters = ProtocolUtilities::ParseGenericMessageParameters(msg); 
                if ( parameters.size() < 3)
                    return false; 

                // may have , instead of . so replace
                ReplaceCharInplace(parameters[0], ',', '.');
                ReplaceCharInplace(parameters[1], ',', '.');
                ReplaceCharInplace(parameters[2], ',', '.');

                const QChar empty(' ');
                StringVector sun_light_direction = SplitString(parameters[0].c_str(), empty.toAscii() );
                StringVector sun_light_color = SplitString(parameters[1].c_str(), empty.toAscii());
                StringVector ambient_light_color = SplitString(parameters[2].c_str(), empty.toAscii());

                if ( environment_ != 0 )
                {
                      environment_->SetSunDirection(environment_->ConvertToQVector<float>(sun_light_direction));
                      environment_->SetSunColor(environment_->ConvertToQVector<float>(sun_light_color));
                      environment_->SetAmbientLight(environment_->ConvertToQVector<float>(ambient_light_color));
                 }
            }
        }
        case RexNetMsgSimulatorViewerTimeMessage:
        {
            if (environment_!= 0)
                return environment_->HandleSimulatorViewerTimeMessage(netdata);
            break;
        }
        case RexNetMsgRegionHandshake:
        {
            bool kill_event = HandleOSNE_RegionHandshake(netdata);
            if (environment_editor_)
                environment_editor_->UpdateTerrainTextureRanges();
            return kill_event;
        }
        case RexNetMsgRegionInfo:
        {
            if (waiting_for_regioninfomessage_)
            {
                currentWorldStream_->SendTextureCommitMessage();
                waiting_for_regioninfomessage_ = false;
            }
        }
        }

        return false;
    }