Skip to content

Commit

Permalink
basic support of SL region windlight as it is now
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Weatherwax authored and Armin Weatherwax committed Jun 13, 2011
1 parent 30d68ea commit 2c28ae4
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 2 deletions.
2 changes: 2 additions & 0 deletions linden/indra/newview/CMakeLists.txt
Expand Up @@ -75,6 +75,7 @@ set(viewer_SOURCE_FILES
aoremotectrl.cpp
chatbar_as_cmdline.cpp
emeraldboobutils.cpp
environmentsettings.cpp
floaterao.cpp
floaterbusy.cpp
floatercommandline.cpp
Expand Down Expand Up @@ -532,6 +533,7 @@ set(viewer_HEADER_FILES
aoremotectrl.h
chatbar_as_cmdline.h
emeraldboobutils.h
environmentsettings.h
floaterao.h
floaterbusy.h
floatercommandline.h
Expand Down
115 changes: 115 additions & 0 deletions linden/indra/newview/environmentsettings.cpp
@@ -0,0 +1,115 @@
//Copyright (C)2011 Armin.Weatherwax at googlemail dot com
//License: gpl v2 +floss exception as in Imprudence or at your choice lgpl v2.1 as in Kokua

#include "llviewerprecompiledheaders.h"

#include "environmentsettings.h"
#include "llsdutil.h"
#include "llsdserialize.h"
#include "llhttpclient.h"
#include "llcallbacklist.h"
#include "llagent.h"
#include "llviewerregion.h"
#include "llwaterparammanager.h"
#include "llwlparammanager.h"
#include "llwldaycycle.h"

class EnvironmentSettingsResponder : public LLHTTPClient::Responder
{
public:

virtual void result(const LLSD& content)
{
/*
std::string filename = "gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS ,"windlight/region","regionwl.";
filename += gAgent.getRegion()->getName();
filename += ".xml";
llstat s;
if(LLFile::stat(filename, &s))//only save if not already there
{
llofstream out(filename);
if (!out.good())
{
llwarns << "Unable to open " << filename << " for output." << llendl;
return;
}
LLSDSerialize::toPrettyXML(content, out);
out.close();
}
*/
if( 4 != content.size() ) return;//accept 3 leave out water?
LLSD::array_const_iterator it = content.beginArray();
LLSD message = *it++;
LLSD day_cycle = *it++;
LLSD skys = *it++;
LLSD water = *it;
LLUUID region_id = message["regionID"];
LLViewerRegion* region = gAgent.getRegion();

if( region_id != region->getRegionID() )
{
llwarns << "wrong region" << llendl;
return;
}
llwarns << "set water" << llendl;
LLWaterParamManager* water_mgr = LLWaterParamManager::instance();
std::string water_name = "RegionWater_";
water_name.append(region->getName());
water_mgr->loadPresetFromRegion(water_name, water, true);

LLWLParamManager* wl_mgr = LLWLParamManager::instance();
LLSD::map_const_iterator sky_it = skys.beginMap();
LLSD::map_const_iterator sky_end = skys.endMap();
for(;sky_it != sky_end; sky_it++)
{
LL_DEBUGS("EnvironmentSettings") << "preset:" <<(sky_it->first) <<"\n"
<< ll_pretty_print_sd(sky_it->second) << llendl;
wl_mgr->loadPresetFromRegion(sky_it->first, sky_it->second, true);
}
wl_mgr->mDay.loadRegionDayCycle(day_cycle);
wl_mgr->resetAnimator(0.5, true);
wl_mgr->mAnimator.mUseLindenTime = true;
}

virtual void error(U32 status, const std::string& reason)
{
llwarns << "EnvironmentSettings::error("
<< status << ": " << reason << ")" << llendl;
}
};

IMPEnvironmentSettings::IMPEnvironmentSettings()
{
mRegionID.setNull();
}

void IMPEnvironmentSettings::init()
{
gIdleCallbacks.addFunction(idle, this);

This comment has been minimized.

Copy link
@ArminW

ArminW Apr 15, 2012

Owner

of course for saving cpu cycles it would be way better to implement a callback for region crossing, which would be 2 or 3 lines of code that very likely are of use also for other things (however it wasn't the scope of this patch).

}

void IMPEnvironmentSettings::idle(void* user_data)
{
IMPEnvironmentSettings* self = (IMPEnvironmentSettings*)user_data;

LLViewerRegion* region = gAgent.getRegion();
if(region && region->capabilitiesReceived())
{
LLUUID region_id = region->getRegionID();
if( region_id != self->mRegionID)
{
self->mRegionID = region_id;
self->getEnvironmentSettings();
}
}
}

void IMPEnvironmentSettings::getEnvironmentSettings()
{
std::string url = gAgent.getRegion()->getCapability("EnvironmentSettings");
if (!url.empty())
{
LLHTTPClient::get(url, new EnvironmentSettingsResponder);
}
}
24 changes: 24 additions & 0 deletions linden/indra/newview/environmentsettings.h
@@ -0,0 +1,24 @@
//Copyright (C)2011 Armin.Weatherwax at googlemail dot com
//License: gpl v2 +floss exception as in Imprudence or at your choice lgpl v2.1 as in Kokua

#ifndef IMP_ENVIRONMENTSETTINGS_H
#define IMP_ENVIRONMENTSETTINGS_H

#include "lluuid.h"
#include "llmemory.h" // LLSingleton<>


class IMPEnvironmentSettings : public LLSingleton<IMPEnvironmentSettings>
{
public:
IMPEnvironmentSettings();
void init();
void getEnvironmentSettings();

private:
static void idle(void *user_data);

LLUUID mRegionID;
};

#endif //IMP_ENVIRONMENTSETTINGS_H
7 changes: 7 additions & 0 deletions linden/indra/newview/llstartup.cpp
Expand Up @@ -217,6 +217,8 @@
#include "hippolimits.h"

#include "lggautocorrect.h"

#include "environmentsettings.h"
//
// exported globals
//
Expand Down Expand Up @@ -2170,6 +2172,11 @@ bool idle_startup()
init_stat_view();
}

if (gHippoGridManager->getConnectedGrid()->isSecondLife())
{
IMPEnvironmentSettings::getInstance()->init();
}

display_startup();
//
// Set up region and surface defaults
Expand Down
1 change: 1 addition & 0 deletions linden/indra/newview/llviewerregion.cpp
Expand Up @@ -1432,6 +1432,7 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
capabilityNames.append("DispatchOpenRegionSettings");
capabilityNames.append("DispatchRegionInfo");
capabilityNames.append("DispatchWindLightSettings");
capabilityNames.append("EnvironmentSettings");
capabilityNames.append("EstateChangeInfo");
capabilityNames.append("EventQueueGet");
capabilityNames.append("FetchInventory");
Expand Down
20 changes: 20 additions & 0 deletions linden/indra/newview/llwaterparammanager.cpp
Expand Up @@ -259,6 +259,26 @@ bool LLWaterParamManager::loadPresetXML(const std::string& name, std::istream& p
return true;
}

bool LLWaterParamManager::loadPresetFromRegion(const std::string& name, const LLSD& preset, bool propagate )
{
std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
if(mIt == mParamList.end())
{
addParamSet(name, preset);
}
else
{
setParamSet(name, preset);
}

if(propagate)
{
getParamSet(name, mCurParams);
propagateParameters();
}
return true;
}

void LLWaterParamManager::loadPresetNotecard(const std::string& name, const LLUUID& asset_id, const LLUUID& inv_id)
{
gAssetStorage->getInvItemAsset(LLHost::invalid,
Expand Down
4 changes: 3 additions & 1 deletion linden/indra/newview/llwaterparammanager.h
Expand Up @@ -239,7 +239,9 @@ class LLWaterParamManager
/// load an individual preset into the sky from an LLSD stream
/// Returns whether the stream was actually reasonable XML to load from.
bool loadPresetXML(const std::string& name, std::istream& preset_stream, bool propogate=false, bool check_if_real=false);


bool loadPresetFromRegion(const std::string& name, const LLSD& preset, bool propagate =false);

/// Load an individual preset from a notecard.
void loadPresetNotecard(const std::string& name, const LLUUID& asset_id, const LLUUID& inv_id);

Expand Down
32 changes: 32 additions & 0 deletions linden/indra/newview/llwldaycycle.cpp
Expand Up @@ -97,6 +97,38 @@ void LLWLDayCycle::loadDayCycle(const std::string & fileName)
}
}

void LLWLDayCycle::loadRegionDayCycle(const LLSD& day_data)
{
// clear the first few things
mTimeMap.clear();

// add each key
for(S32 i = 0; i < day_data.size(); ++i)
{
// make sure it's a two array
if(day_data[i].size() != 2)
{
continue;
}

// check each param name exists in param manager
bool success;
LLWLParamSet pset;
success = LLWLParamManager::instance()->getParamSet(day_data[i][1].asString(), pset);
if(!success)
{
// alert the user
LLSD args;
args["SKY"] = day_data[i][1].asString();
LLNotifications::instance().add("WLMissingSky", args);
continue;
}

// then add the key
addKey((F32)day_data[i][0].asReal(), day_data[i][1].asString());
}
}

void LLWLDayCycle::saveDayCycle(const std::string & fileName)
{
LLSD day_data(LLSD::emptyArray());
Expand Down
2 changes: 2 additions & 0 deletions linden/indra/newview/llwldaycycle.h
Expand Up @@ -64,6 +64,8 @@ class LLWLDayCycle
/// load a day cycle
void loadDayCycle(const std::string & fileName);

void loadRegionDayCycle(const LLSD& day_data);

/// load a day cycle
void saveDayCycle(const std::string & fileName);

Expand Down
21 changes: 21 additions & 0 deletions linden/indra/newview/llwlparammanager.cpp
Expand Up @@ -238,6 +238,27 @@ bool LLWLParamManager::loadPresetXML(const std::string& name, std::istream& pres
}
return true;
}

bool LLWLParamManager::loadPresetFromRegion(const std::string& name, const LLSD& preset, bool propagate )
{
std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name);
if(mIt == mParamList.end())
{
addParamSet(name, preset);
}
else
{
setParamSet(name, preset);
}

if(propagate)
{
getParamSet(name, mCurParams);
propagateParameters();
}
return true;
}

void LLWLParamManager::loadPresetNotecard(const std::string& name, const LLUUID& asset_id, const LLUUID& inv_id)
{
gAssetStorage->getInvItemAsset(LLHost::invalid,
Expand Down
4 changes: 3 additions & 1 deletion linden/indra/newview/llwlparammanager.h
Expand Up @@ -151,7 +151,9 @@ class LLWLParamManager
/// load an individual preset into the sky from an LLSD stream
/// Returns whether the stream was actually reasonable XML to load from.
bool loadPresetXML(const std::string& name, std::istream& preset_stream, bool propogate=false, bool check_if_real=false);


bool loadPresetFromRegion(const std::string& name, const LLSD& preset, bool propagate =false);

/// Load an individual preset from a notecard.
void loadPresetNotecard(const std::string& name, const LLUUID& asset_id, const LLUUID& inv_id);

Expand Down

0 comments on commit 2c28ae4

Please sign in to comment.