PageRenderTime 74ms CodeModel.GetById 20ms app.highlight 32ms RepoModel.GetById 19ms app.codeStats 0ms

/indra/newview/llregioninfomodel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 217 lines | 142 code | 30 blank | 45 comment | 6 complexity | 4b8b20352a76684fe4ff9b9343432674 MD5 | raw file
  1/** 
  2 * @file llregioninfomodel.cpp
  3 * @brief Region info model
  4 *
  5 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llregioninfomodel.h"
 30
 31// libs
 32#include "message.h"
 33#include "llregionflags.h"
 34
 35// viewer
 36#include "llagent.h"
 37#include "llviewerregion.h"
 38
 39void LLRegionInfoModel::reset()
 40{
 41	mSimAccess			= 0;
 42	mAgentLimit			= 0;
 43
 44	mRegionFlags		= 0;
 45	mEstateID			= 0;
 46	mParentEstateID		= 0;
 47
 48	mPricePerMeter		= 0;
 49	mRedirectGridX		= 0;
 50	mRedirectGridY		= 0;
 51
 52	mBillableFactor		= 0.0f;
 53	mObjectBonusFactor	= 0.0f;
 54	mWaterHeight		= 0.0f;
 55	mTerrainRaiseLimit	= 0.0f;
 56	mTerrainLowerLimit	= 0.0f;
 57	mSunHour			= 0.0f;
 58
 59	mUseEstateSun		= false;
 60
 61	mSimType.clear();
 62	mSimName.clear();
 63}
 64
 65LLRegionInfoModel::LLRegionInfoModel()
 66{
 67	reset();
 68}
 69
 70boost::signals2::connection LLRegionInfoModel::setUpdateCallback(const update_signal_t::slot_type& cb)
 71{
 72	return mUpdateSignal.connect(cb);
 73}
 74
 75void LLRegionInfoModel::sendRegionTerrain(const LLUUID& invoice) const
 76{
 77	std::string buffer;
 78	std::vector<std::string> strings;
 79
 80	// ==========================================
 81	// Assemble and send setregionterrain message
 82	// "setregionterrain"
 83	// strings[0] = float water height
 84	// strings[1] = float terrain raise
 85	// strings[2] = float terrain lower
 86	// strings[3] = 'Y' use estate time
 87	// strings[4] = 'Y' fixed sun
 88	// strings[5] = float sun_hour
 89	// strings[6] = from estate, 'Y' use global time
 90	// strings[7] = from estate, 'Y' fixed sun
 91	// strings[8] = from estate, float sun_hour
 92
 93	// *NOTE: this resets estate sun info.
 94	BOOL estate_global_time = true;
 95	BOOL estate_fixed_sun = false;
 96	F32 estate_sun_hour = 0.f;
 97
 98	buffer = llformat("%f", mWaterHeight);
 99	strings.push_back(buffer);
100	buffer = llformat("%f", mTerrainRaiseLimit);
101	strings.push_back(buffer);
102	buffer = llformat("%f", mTerrainLowerLimit);
103	strings.push_back(buffer);
104	buffer = llformat("%s", (mUseEstateSun ? "Y" : "N"));
105	strings.push_back(buffer);
106	buffer = llformat("%s", (getUseFixedSun() ? "Y" : "N"));
107	strings.push_back(buffer);
108	buffer = llformat("%f", mSunHour);
109	strings.push_back(buffer);
110	buffer = llformat("%s", (estate_global_time ? "Y" : "N") );
111	strings.push_back(buffer);
112	buffer = llformat("%s", (estate_fixed_sun ? "Y" : "N") );
113	strings.push_back(buffer);
114	buffer = llformat("%f", estate_sun_hour);
115	strings.push_back(buffer);
116
117	sendEstateOwnerMessage(gMessageSystem, "setregionterrain", invoice, strings);
118}
119
120bool LLRegionInfoModel::getUseFixedSun() const
121{
122	return mRegionFlags & REGION_FLAGS_SUN_FIXED;
123}
124
125void LLRegionInfoModel::setUseFixedSun(bool fixed)
126{
127	if (fixed)
128	{
129		mRegionFlags |= REGION_FLAGS_SUN_FIXED;
130	}
131	else
132	{
133		mRegionFlags &= ~REGION_FLAGS_SUN_FIXED;
134	}
135}
136
137void LLRegionInfoModel::update(LLMessageSystem* msg)
138{
139	reset();
140
141	msg->getStringFast(_PREHASH_RegionInfo, _PREHASH_SimName, mSimName);
142	msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_EstateID, mEstateID);
143	msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_ParentEstateID, mParentEstateID);
144	msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, mRegionFlags);
145	msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_SimAccess, mSimAccess);
146	msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_MaxAgents, mAgentLimit);
147	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_ObjectBonusFactor, mObjectBonusFactor);
148	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_BillableFactor, mBillableFactor);
149	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, mWaterHeight);
150	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, mTerrainRaiseLimit);
151	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, mTerrainLowerLimit);
152	msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_PricePerMeter, mPricePerMeter);
153	msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_RedirectGridX, mRedirectGridX);
154	msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_RedirectGridY, mRedirectGridY);
155
156	msg->getBOOL(_PREHASH_RegionInfo, _PREHASH_UseEstateSun, mUseEstateSun);
157
158	// actually the "last set" sun hour, not the current sun hour. JC
159	msg->getF32(_PREHASH_RegionInfo, _PREHASH_SunHour, mSunHour);
160	LL_DEBUGS("Windlight Sync") << "Got region sun hour: " << mSunHour << LL_ENDL;
161
162	// the only reasonable way to decide if we actually have any data is to
163	// check to see if any of these fields have nonzero sizes
164	if (msg->getSize(_PREHASH_RegionInfo2, _PREHASH_ProductSKU) > 0 ||
165		msg->getSize(_PREHASH_RegionInfo2, "ProductName") > 0)
166	{
167		msg->getString(_PREHASH_RegionInfo2, "ProductName", mSimType);
168	}
169
170	// Let interested parties know that region info has been updated.
171	mUpdateSignal();
172}
173
174// static
175void LLRegionInfoModel::sendEstateOwnerMessage(
176	LLMessageSystem* msg,
177	const std::string& request,
178	const LLUUID& invoice,
179	const std::vector<std::string>& strings)
180{
181	LLViewerRegion* cur_region = gAgent.getRegion();
182
183	if (!cur_region)
184	{
185		llwarns << "Agent region not set" << llendl;
186		return;
187	}
188
189	llinfos << "Sending estate request '" << request << "'" << llendl;
190	msg->newMessage("EstateOwnerMessage");
191	msg->nextBlockFast(_PREHASH_AgentData);
192	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
193	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
194	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
195	msg->nextBlock("MethodData");
196	msg->addString("Method", request);
197	msg->addUUID("Invoice", invoice);
198
199	if (strings.empty())
200	{
201		msg->nextBlock("ParamList");
202		msg->addString("Parameter", NULL);
203	}
204	else
205	{
206		std::vector<std::string>::const_iterator it = strings.begin();
207		std::vector<std::string>::const_iterator end = strings.end();
208		for (unsigned i = 0; it != end; ++it, ++i)
209		{
210			lldebugs << "- [" << i << "] " << (*it) << llendl;
211			msg->nextBlock("ParamList");
212			msg->addString("Parameter", *it);
213		}
214	}
215
216	msg->sendReliable(cur_region->getHost());
217}