From b6478ed527c35a817a72f351fae2169ed7ba2827 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sat, 31 Jul 2010 01:11:11 -0500 Subject: Tidied up and documented lightshare.cpp and lightshare.h. --- linden/indra/newview/lightshare.cpp | 26 +++++++---------- linden/indra/newview/lightshare.h | 57 ++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/linden/indra/newview/lightshare.cpp b/linden/indra/newview/lightshare.cpp index b2bbb96..1d87ab1 100644 --- a/linden/indra/newview/lightshare.cpp +++ b/linden/indra/newview/lightshare.cpp @@ -2,7 +2,7 @@ * @file lightshare.cpp * @brief Handler for Meta7 Lightshare (region-side Windlight settings). * - * Copyright (c) 2010, Tom Meta / Meta7 + * Copyright (c) 2010, Tom Grimshaw (Tom Meta) * Copyright (c) 2010, Jacek Antonelli * * The source code in this file ("Source Code") is provided to you @@ -30,8 +30,6 @@ #include "lightshare.h" #include "linden_common.h" - -#include "lluuid.h" #include "llviewercontrol.h" #include "llwaterparammanager.h" #include "llwaterparamset.h" @@ -41,7 +39,6 @@ #include "meta7windlight.h" -// The names of the presets where the region settings are stored. const std::string WindlightMessage::sWaterPresetName = "(Region settings)"; const std::string WindlightMessage::sSkyPresetName = "(Region settings)"; @@ -82,7 +79,7 @@ WindlightMessage::WindlightMessage( LLMessageSystem* msg ) : mWater = new LLWaterParamSet(); mSky = new LLWLParamSet(); - mWaterNormal = LLUUID(); + mWaterNormal = new LLUUID(); process_packet(&buf[0]); process_water(); @@ -97,6 +94,7 @@ WindlightMessage::~WindlightMessage() { delete mWater; delete mSky; + delete mWaterNormal; } @@ -127,8 +125,8 @@ void WindlightMessage::processWindlight(LLMessageSystem* msg, void**) if( !ignoreTimerHasExpired() ) { // The user recently ignored a windlight message, so ignore - // this one too, and reset the timer. - resetIgnoreTimer(); + // this one too, and restart the timer. + restartIgnoreTimer(); delete wl; return; } @@ -145,10 +143,8 @@ void WindlightMessage::processWindlight(LLMessageSystem* msg, void**) // No most recent, so store this and create notification // asking the user whether to apply or not. sMostRecent = wl; - LLNotifications::instance() - .add("ConfirmLightShare", - LLSD(), LLSD(), - boost::bind(&applyCallback, _1, _2)); + LLNotifications::instance().add("ConfirmLightShare", LLSD(), LLSD(), + boost::bind(&applyCallback, _1, _2)); return; } else @@ -177,7 +173,7 @@ bool WindlightMessage::applyCallback(const LLSD& notification, } case 1:{ // "Not Now", ignore until the region stops spamming - resetIgnoreTimer(); + restartIgnoreTimer(); break; } case 2:{ @@ -202,7 +198,7 @@ void WindlightMessage::resetRegion() // static -void WindlightMessage::resetIgnoreTimer() +void WindlightMessage::restartIgnoreTimer() { F32 time = gSavedSettings.getF32("LightShareIgnoreTimer"); sIgnoreTimer->start(); @@ -226,7 +222,7 @@ bool WindlightMessage::apply() water_mgr->addParamSet( sWaterPresetName, *mWater ); water_mgr->savePreset( sWaterPresetName ); water_mgr->loadPreset( sWaterPresetName, true ); - water_mgr->setNormalMapID( mWaterNormal ); + water_mgr->setNormalMapID( *mWaterNormal ); mSky->mName = sSkyPresetName; sky_mgr->mAnimator.mIsRunning = false; @@ -306,7 +302,7 @@ void WindlightMessage::process_water() (U8)(mPacket->normalMapTexture[14]), (U8)(mPacket->normalMapTexture[15])); - mWaterNormal.set(uuid); + mWaterNormal->set(uuid); } diff --git a/linden/indra/newview/lightshare.h b/linden/indra/newview/lightshare.h index 0b2965e..f179458 100644 --- a/linden/indra/newview/lightshare.h +++ b/linden/indra/newview/lightshare.h @@ -1,6 +1,6 @@ /** * @file lightshare.h - * @brief Public interface for lightshare.cpp + * @brief WindlightMessage class definition. * * Copyright (c) 2010, Jacek Antonelli * @@ -29,38 +29,67 @@ #ifndef LIGHTSHARE_H #define LIGHTSHARE_H -#include "message.h" -#include "meta7windlight.h" -#include "lltimer.h" -#include "llwaterparamset.h" -#include "llwlparamset.h" +#include + +struct Meta7WindlightPacket; +class LLMessageSystem; +class LLSD; +class LLTimer; +class LLUUID; +class LLWaterParamSet; +class LLWLParamSet; // Encapsulates a "Windlight" (LightShare) message sent from the -// server, allowing the settings to be applied at a later time. +// region, allowing the settings to be applied at a later time. // class WindlightMessage { public: + // Constructs a new WindlightMessage instance from a GenericMessage + // with the "Windlight" method, such as those sent by a + // Lightshare-enabled OpenSim region. + WindlightMessage( LLMessageSystem* msg ); + + ~WindlightMessage(); + + // The name of the water preset where the region settings are stored. static const std::string sWaterPresetName; + + // The name of the sky preset where the region settings are stored. static const std::string sSkyPresetName; - WindlightMessage( LLMessageSystem* msg ); - ~WindlightMessage(); + // Message handler for GenericMessage with the "Windlight" method. + // Creates and applies a new WindlightMessage (or prompts user). static void processWindlight(LLMessageSystem* msg, void**); + + // Callback when the user interacts with the notification. static bool applyCallback(const LLSD& notification, const LLSD& response); + + // Called after the user has entered a new region, to reset the + // "ignore while in this region" state. static void resetRegion(); + // Applies/activates the Windlight settings from the message. bool apply(); + + // Returns true if the message contains valid Windlight settings. + // (But there's no real validation yet, so this is always true.) bool isValid(); + protected: - static void resetIgnoreTimer(); + // Restart the timer for temporarily ignoring settings. + static void restartIgnoreTimer(); + + // Returns true if the ignore timer has expired (i.e. new settings + // should not be ignored anymore). static bool ignoreTimerHasExpired(); + private: static WindlightMessage* sMostRecent; @@ -70,12 +99,18 @@ class WindlightMessage Meta7WindlightPacket* mPacket; LLWaterParamSet* mWater; LLWLParamSet* mSky; - LLUUID mWaterNormal; + LLUUID* mWaterNormal; bool mIsValid; + // Converts the message's raw bytes into a Meta7WindlightPacket. void process_packet( char* buf ); + + // Constructs a LLWaterParamSet from the Meta7WindlightPacket. void process_water(); + + // Constructs a LLWLParamSet from the Meta7WindlightPacket. void process_sky(); + }; #endif -- cgit v1.1