From 892e8b82d84266f8bdfbd5c2cdd388f71c208035 Mon Sep 17 00:00:00 2001 From: RevolutionSmythe Date: Fri, 18 Mar 2011 17:32:12 -0500 Subject: Merge in Var Sized Regions into the Imprudence Experimental. --- linden/indra/llcommon/indra_constants.h | 7 +- linden/indra/llinventory/llparcel.h | 3 +- linden/indra/llmessage/message_prehash.cpp | 4 +- linden/indra/llmessage/message_prehash.h | 4 +- linden/indra/llmessage/patch_code.cpp | 13 +- linden/indra/llmessage/patch_code.h | 2 +- linden/indra/llmessage/patch_dct.h | 2 +- linden/indra/llwindow/glh/glh_linear.h | 3242 ++++++++++++------------ linden/indra/newview/llcloud.cpp | 2 +- linden/indra/newview/llfloaterregioninfo.cpp | 8 +- linden/indra/newview/llglsandbox.cpp | 2 +- linden/indra/newview/llmapresponders.cpp | 4 + linden/indra/newview/llstartup.cpp | 14 +- linden/indra/newview/llsurface.cpp | 20 +- linden/indra/newview/llviewermessage.cpp | 27 +- linden/indra/newview/llviewerparcelmgr.cpp | 22 +- linden/indra/newview/llviewerparcelmgr.h | 2 + linden/indra/newview/llviewerparceloverlay.cpp | 4 +- linden/indra/newview/llviewerparceloverlay.h | 1 + linden/indra/newview/llviewerregion.cpp | 3 + linden/indra/newview/llvlmanager.cpp | 61 +- linden/indra/newview/llvowater.cpp | 2 +- linden/indra/newview/llwind.cpp | 4 +- linden/indra/newview/llworld.cpp | 27 +- linden/indra/newview/llworld.h | 6 +- linden/indra/newview/llworldmap.cpp | 29 +- linden/indra/newview/llworldmap.h | 2 + linden/indra/newview/llworldmapview.cpp | 14 +- 28 files changed, 1823 insertions(+), 1708 deletions(-) diff --git a/linden/indra/llcommon/indra_constants.h b/linden/indra/llcommon/indra_constants.h index 279d280..ae1e04a 100644 --- a/linden/indra/llcommon/indra_constants.h +++ b/linden/indra/llcommon/indra_constants.h @@ -151,7 +151,12 @@ const U32 PORT_DISCOVERY_RANGE_MAX = PORT_DISCOVERY_RANGE_MIN + 50; const char LAND_LAYER_CODE = 'L'; const char WATER_LAYER_CODE = 'W'; const char WIND_LAYER_CODE = '7'; -const char CLOUD_LAYER_CODE = '8'; +const char CLOUD_LAYER_CODE = '8'; + +// Extended land layer for Aurora Sim +const char AURORA_LAND_LAYER_CODE = 'M'; +const char AURORA_WIND_LAYER_CODE = '9'; +const char AURORA_CLOUD_LAYER_CODE = ':'; // keys // Bit masks for various keyboard modifier keys. diff --git a/linden/indra/llinventory/llparcel.h b/linden/indra/llinventory/llparcel.h index 8faa673..366f589 100644 --- a/linden/indra/llinventory/llparcel.h +++ b/linden/indra/llinventory/llparcel.h @@ -66,7 +66,8 @@ const S32 PARCEL_PASS_PRICE_DEFAULT = 10; const F32 PARCEL_PASS_HOURS_DEFAULT = 1.f; // Number of "chunks" in which parcel overlay data is sent -// Chunk 0 = southern rows, entire width +// Chunk 0 = southern rows, entire width +// NOTE: NOT USABLE FOR VAR SIZED REGIONS! const S32 PARCEL_OVERLAY_CHUNKS = 4; // Bottom three bits are a color index for the land overlay diff --git a/linden/indra/llmessage/message_prehash.cpp b/linden/indra/llmessage/message_prehash.cpp index ecb45bf..a8b021f 100644 --- a/linden/indra/llmessage/message_prehash.cpp +++ b/linden/indra/llmessage/message_prehash.cpp @@ -586,7 +586,9 @@ char* _PREHASH_NotecardItemID = LLMessageStringTable::getInstance()->getString(" char* _PREHASH_LastName = LLMessageStringTable::getInstance()->getString("LastName"); char* _PREHASH_From = LLMessageStringTable::getInstance()->getString("From"); char* _PREHASH_RoleChange = LLMessageStringTable::getInstance()->getString("RoleChange"); -char* _PREHASH_Port = LLMessageStringTable::getInstance()->getString("Port"); +char* _PREHASH_Port = LLMessageStringTable::getInstance()->getString("Port"); +char* _PREHASH_RegionSizeX = LLMessageStringTable::getInstance()->getString("RegionSizeX"); +char* _PREHASH_RegionSizeY = LLMessageStringTable::getInstance()->getString("RegionSizeY"); char* _PREHASH_MemberTitle = LLMessageStringTable::getInstance()->getString("MemberTitle"); char* _PREHASH_LogParcelChanges = LLMessageStringTable::getInstance()->getString("LogParcelChanges"); char* _PREHASH_AgentCachedTextureResponse = LLMessageStringTable::getInstance()->getString("AgentCachedTextureResponse"); diff --git a/linden/indra/llmessage/message_prehash.h b/linden/indra/llmessage/message_prehash.h index 8516483..adf27ee 100644 --- a/linden/indra/llmessage/message_prehash.h +++ b/linden/indra/llmessage/message_prehash.h @@ -586,7 +586,9 @@ extern char * _PREHASH_NotecardItemID; extern char * _PREHASH_LastName; extern char * _PREHASH_From; extern char * _PREHASH_RoleChange; -extern char * _PREHASH_Port; +extern char * _PREHASH_Port; +extern char * _PREHASH_RegionSizeX; +extern char * _PREHASH_RegionSizeY; extern char * _PREHASH_MemberTitle; extern char * _PREHASH_LogParcelChanges; extern char * _PREHASH_AgentCachedTextureResponse; diff --git a/linden/indra/llmessage/patch_code.cpp b/linden/indra/llmessage/patch_code.cpp index 90fb236..4b4313d 100644 --- a/linden/indra/llmessage/patch_code.cpp +++ b/linden/indra/llmessage/patch_code.cpp @@ -235,7 +235,7 @@ void decode_patch_group_header(LLBitPack &bitpack, LLGroupHeader *gopp) gPatchSize = gopp->patch_size; } -void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph) +void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph, BOOL b_large_patch) { U8 retvalu8; @@ -274,15 +274,18 @@ void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph) #endif ph->range = retvalu16; - retvalu16 = 0; + retvalu32 = 0; #ifdef LL_BIG_ENDIAN ret = (U8 *)&retvalu16; bitpack.bitUnpack(&(ret[1]), 8); bitpack.bitUnpack(&(ret[0]), 2); #else - bitpack.bitUnpack((U8 *)&retvalu16, 10); -#endif - ph->patchids = retvalu16; + if (b_large_patch) + bitpack.bitUnpack((U8 *)&retvalu32, 32); + else + bitpack.bitUnpack((U8 *)&retvalu32, 10); +#endif + ph->patchids = retvalu32; gWordBits = (ph->quant_wbits & 0xf) + 2; } diff --git a/linden/indra/llmessage/patch_code.h b/linden/indra/llmessage/patch_code.h index 82fa6bb..dbfdf70 100644 --- a/linden/indra/llmessage/patch_code.h +++ b/linden/indra/llmessage/patch_code.h @@ -46,7 +46,7 @@ void end_patch_coding(LLBitPack &bitpack); void init_patch_decoding(LLBitPack &bitpack); void decode_patch_group_header(LLBitPack &bitpack, LLGroupHeader *gopp); -void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph); +void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph, BOOL b_large_patch); void decode_patch(LLBitPack &bitpack, S32 *patches); #endif diff --git a/linden/indra/llmessage/patch_dct.h b/linden/indra/llmessage/patch_dct.h index 663e146..ba21be7 100644 --- a/linden/indra/llmessage/patch_dct.h +++ b/linden/indra/llmessage/patch_dct.h @@ -79,7 +79,7 @@ public: F32 dc_offset; // 4 bytes U16 range; // 2 = 7 ((S16) FP range (breaks if we need > 32K meters in 1 patch) U8 quant_wbits; // 1 = 8 (upper 4 bits is quant - 2, lower 4 bits is word bits - 2) - U16 patchids; // 2 = 10 (actually only uses 10 bits, 5 for each) + U32 patchids; // 2 = 10 (actually only uses 10 bits, 5 for each) }; // Compression routines diff --git a/linden/indra/llwindow/glh/glh_linear.h b/linden/indra/llwindow/glh/glh_linear.h index 04ae1bd..bb59d7e 100755 --- a/linden/indra/llwindow/glh/glh_linear.h +++ b/linden/indra/llwindow/glh/glh_linear.h @@ -1,1621 +1,1621 @@ -/* - glh - is a platform-indepenedent C++ OpenGL helper library - - - Copyright (c) 2000 Cass Everitt - Copyright (c) 2000 NVIDIA Corporation - All rights reserved. - - Redistribution and use in source and binary forms, with or - without modification, are permitted provided that the following - conditions are met: - - * Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - - * The names of contributors to this software may not be used - to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - - Cass Everitt - cass@r3.nu -*/ - -/* -glh_linear.h -*/ - -// Author: Cass W. Everitt - -#ifndef GLH_LINEAR_H -#define GLH_LINEAR_H - -#include -#include -#include - -// only supports float for now... -#define GLH_REAL_IS_FLOAT - -#ifdef GLH_REAL_IS_FLOAT -# define GLH_REAL float -# define GLH_REAL_NAMESPACE ns_float -#endif - -#define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 - -#define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) -#define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) -#define GLH_ZERO GLH_REAL(0.0) -#define GLH_ONE GLH_REAL(1.0) -#define GLH_TWO GLH_REAL(2.0) -#define GLH_EPSILON GLH_REAL(10e-6) -#define GLH_PI GLH_REAL(3.1415926535897932384626433832795) - -#define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) - -namespace glh -{ - - inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } - inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } - - // forward declarations for friend template functions. - template class vec; - - // forward declarations for friend template functions. - template - bool operator == ( const vec & v1, const vec & v2 ); - - // forward declarations for friend template functions. - template - bool operator != ( const vec & v1, const vec & v2 ); - - template - class vec - { - public: - int size() const { return N; } - - vec(const T & t = T()) - { for(int i = 0; i < N; i++) v[i] = t; } - vec(const T * tp) - { for(int i = 0; i < N; i++) v[i] = tp[i]; } - - const T * get_value() const - { return v; } - - - T dot( const vec & rhs ) const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; - return r; - } - - T length() const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*v[i]; - return T(sqrt(r)); - } - - T square_norm() const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*v[i]; - return r; - } - - void negate() - { for(int i = 0; i < N; i++) v[i] = -v[i]; } - - - T normalize() - { - T sum(0); - for(int i = 0; i < N; i++) - sum += v[i]*v[i]; - sum = T(sqrt(sum)); - if (sum > GLH_EPSILON) - for(int i = 0; i < N; i++) - v[i] /= sum; - return sum; - } - - - vec & set_value( const T * rhs ) - { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } - - T & operator [] ( int i ) - { return v[i]; } - - const T & operator [] ( int i ) const - { return v[i]; } - - vec & operator *= ( T d ) - { for(int i = 0; i < N; i++) v[i] *= d; return *this;} - - vec & operator *= ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} - - vec & operator /= ( T d ) - { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} - - vec & operator += ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} - - vec & operator -= ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} - - - vec operator - () const - { vec rv = v; rv.negate(); return rv; } - - vec operator + ( const vec &v) const - { vec rt(*this); return rt += v; } - - vec operator - ( const vec &v) const - { vec rt(*this); return rt -= v; } - - vec operator * ( T d) const - { vec rt(*this); return rt *= d; } - - friend bool operator == <> ( const vec &v1, const vec &v2 ); - friend bool operator != <> ( const vec &v1, const vec &v2 ); - - - //protected: - T v[N]; - }; - - - - // vector friend operators - - template inline - vec operator * ( const vec & b, T d ) - { - vec rt(b); - return rt *= d; - } - - template inline - vec operator * ( T d, const vec & b ) - { return b*d; } - - template inline - vec operator * ( const vec & b, const vec & d ) - { - vec rt(b); - return rt *= d; - } - - template inline - vec operator / ( const vec & b, T d ) - { vec rt(b); return rt /= d; } - - template inline - vec operator + ( const vec & v1, const vec & v2 ) - { vec rt(v1); return rt += v2; } - - template inline - vec operator - ( const vec & v1, const vec & v2 ) - { vec rt(v1); return rt -= v2; } - - - template inline - bool operator == ( const vec & v1, const vec & v2 ) - { - for(int i = 0; i < N; i++) - if(v1.v[i] != v2.v[i]) - return false; - return true; - } - - template inline - bool operator != ( const vec & v1, const vec & v2 ) - { return !(v1 == v2); } - - - typedef vec<3,unsigned char> vec3ub; - typedef vec<4,unsigned char> vec4ub; - - - - - - namespace GLH_REAL_NAMESPACE - { - typedef GLH_REAL real; - - class line; - class plane; - class matrix4; - class quaternion; - typedef quaternion rotation; - - class vec2 : public vec<2,real> - { - public: - vec2(const real & t = real()) : vec<2,real>(t) - {} - vec2(const vec<2,real> & t) : vec<2,real>(t) - {} - vec2(const real * tp) : vec<2,real>(tp) - {} - - vec2(real x, real y ) - { v[0] = x; v[1] = y; } - - void get_value(real & x, real & y) const - { x = v[0]; y = v[1]; } - - vec2 & set_value( const real & x, const real & y) - { v[0] = x; v[1] = y; return *this; } - - }; - - - class vec3 : public vec<3,real> - { - public: - vec3(const real & t = real()) : vec<3,real>(t) - {} - vec3(const vec<3,real> & t) : vec<3,real>(t) - {} - vec3(const real * tp) : vec<3,real>(tp) - {} - - vec3(real x, real y, real z) - { v[0] = x; v[1] = y; v[2] = z; } - - void get_value(real & x, real & y, real & z) const - { x = v[0]; y = v[1]; z = v[2]; } - - vec3 cross( const vec3 &rhs ) const - { - vec3 rt; - rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; - rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; - rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; - return rt; - } - - vec3 & set_value( const real & x, const real & y, const real & z) - { v[0] = x; v[1] = y; v[2] = z; return *this; } - - }; - - - class vec4 : public vec<4,real> - { - public: - vec4(const real & t = real()) : vec<4,real>(t) - {} - vec4(const vec<4,real> & t) : vec<4,real>(t) - {} - - vec4(const vec<3,real> & t, real fourth) - - { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } - vec4(const real * tp) : vec<4,real>(tp) - {} - vec4(real x, real y, real z, real w) - { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } - - void get_value(real & x, real & y, real & z, real & w) const - { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } - - vec4 & set_value( const real & x, const real & y, const real & z, const real & w) - { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } - }; - - inline - vec3 homogenize(const vec4 & v) - { - vec3 rt; - assert(v.v[3] != GLH_ZERO); - rt.v[0] = v.v[0]/v.v[3]; - rt.v[1] = v.v[1]/v.v[3]; - rt.v[2] = v.v[2]/v.v[3]; - return rt; - } - - - - class line - { - public: - - line() - { set_value(vec3(0,0,0),vec3(0,0,1)); } - - line( const vec3 & p0, const vec3 &p1) - { set_value(p0,p1); } - - void set_value( const vec3 &p0, const vec3 &p1) - { - position = p0; - direction = p1-p0; - direction.normalize(); - } - - bool get_closest_points(const line &line2, - vec3 &pointOnThis, - vec3 &pointOnThat) - { - - // quick check to see if parallel -- if so, quit. - if(fabs(direction.dot(line2.direction)) == 1.0) - return 0; - line l2 = line2; - - // Algorithm: Brian Jean - // - register real u; - register real v; - vec3 Vr = direction; - vec3 Vs = l2.direction; - register real Vr_Dot_Vs = Vr.dot(Vs); - register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); - vec3 C = l2.position - position; - register real C_Dot_Vr = C.dot(Vr); - register real C_Dot_Vs = C.dot(Vs); - - u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; - v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; - - pointOnThis = position; - pointOnThis += direction * u; - pointOnThat = l2.position; - pointOnThat += l2.direction * v; - - return 1; - } - - vec3 get_closest_point(const vec3 &point) - { - vec3 np = point - position; - vec3 rp = direction*direction.dot(np)+position; - return rp; - } - - const vec3 & get_position() const {return position;} - - const vec3 & get_direction() const {return direction;} - - //protected: - vec3 position; - vec3 direction; - }; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // matrix - - - class matrix4 - { - - public: - - matrix4() { make_identity(); } - - matrix4( real r ) - { set_value(r); } - - matrix4( real * m ) - { set_value(m); } - - matrix4( real a00, real a01, real a02, real a03, - real a10, real a11, real a12, real a13, - real a20, real a21, real a22, real a23, - real a30, real a31, real a32, real a33 ) - { - element(0,0) = a00; - element(0,1) = a01; - element(0,2) = a02; - element(0,3) = a03; - - element(1,0) = a10; - element(1,1) = a11; - element(1,2) = a12; - element(1,3) = a13; - - element(2,0) = a20; - element(2,1) = a21; - element(2,2) = a22; - element(2,3) = a23; - - element(3,0) = a30; - element(3,1) = a31; - element(3,2) = a32; - element(3,3) = a33; - } - - - void get_value( real * mp ) const - { - int c = 0; - for(int j=0; j < 4; j++) - for(int i=0; i < 4; i++) - mp[c++] = element(i,j); - } - - - const real * get_value() const - { return m; } - - void set_value( real * mp) - { - int c = 0; - for(int j=0; j < 4; j++) - for(int i=0; i < 4; i++) - element(i,j) = mp[c++]; - } - - void set_value( real r ) - { - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - element(i,j) = r; - } - - void make_identity() - { - element(0,0) = 1.0; - element(0,1) = 0.0; - element(0,2) = 0.0; - element(0,3) = 0.0; - - element(1,0) = 0.0; - element(1,1) = 1.0; - element(1,2) = 0.0; - element(1,3) = 0.0; - - element(2,0) = 0.0; - element(2,1) = 0.0; - element(2,2) = 1.0; - element(2,3) = 0.0; - - element(3,0) = 0.0; - element(3,1) = 0.0; - element(3,2) = 0.0; - element(3,3) = 1.0; - } - - - static matrix4 identity() - { - static matrix4 mident ( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 ); - return mident; - } - - - void set_scale( real s ) - { - element(0,0) = s; - element(1,1) = s; - element(2,2) = s; - } - - void set_scale( const vec3 & s ) - { - element(0,0) = s.v[0]; - element(1,1) = s.v[1]; - element(2,2) = s.v[2]; - } - - - void set_translate( const vec3 & t ) - { - element(0,3) = t.v[0]; - element(1,3) = t.v[1]; - element(2,3) = t.v[2]; - } - - void set_row(int r, const vec4 & t) - { - element(r,0) = t.v[0]; - element(r,1) = t.v[1]; - element(r,2) = t.v[2]; - element(r,3) = t.v[3]; - } - - void set_column(int c, const vec4 & t) - { - element(0,c) = t.v[0]; - element(1,c) = t.v[1]; - element(2,c) = t.v[2]; - element(3,c) = t.v[3]; - } - - - void get_row(int r, vec4 & t) const - { - t.v[0] = element(r,0); - t.v[1] = element(r,1); - t.v[2] = element(r,2); - t.v[3] = element(r,3); - } - - vec4 get_row(int r) const - { - vec4 v; get_row(r, v); - return v; - } - - void get_column(int c, vec4 & t) const - { - t.v[0] = element(0,c); - t.v[1] = element(1,c); - t.v[2] = element(2,c); - t.v[3] = element(3,c); - } - - vec4 get_column(int c) const - { - vec4 v; get_column(c, v); - return v; - } - - matrix4 inverse() const - { - matrix4 minv; - - real r1[8], r2[8], r3[8], r4[8]; - real *s[4], *tmprow; - - s[0] = &r1[0]; - s[1] = &r2[0]; - s[2] = &r3[0]; - s[3] = &r4[0]; - - register int i,j,p,jj; - for(i=0;i<4;i++) - { - for(j=0;j<4;j++) - { - s[i][j] = element(i,j); - if(i==j) s[i][j+4] = 1.0; - else s[i][j+4] = 0.0; - } - } - real scp[4]; - for(i=0;i<4;i++) - { - scp[i] = real(fabs(s[i][0])); - for(j=1;j<4;j++) - if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); - if(scp[i] == 0.0) return minv; // singular matrix! - } - - int pivot_to; - real scp_max; - for(i=0;i<4;i++) - { - // select pivot row - pivot_to = i; - scp_max = real(fabs(s[i][i]/scp[i])); - // find out which row should be on top - for(p=i+1;p<4;p++) - if(real(fabs(s[p][i]/scp[p])) > scp_max) - { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } - // Pivot if necessary - if(pivot_to != i) - { - tmprow = s[i]; - s[i] = s[pivot_to]; - s[pivot_to] = tmprow; - real tmpscp; - tmpscp = scp[i]; - scp[i] = scp[pivot_to]; - scp[pivot_to] = tmpscp; - } - - real mji; - // perform gaussian elimination - for(j=i+1;j<4;j++) - { - mji = s[j][i]/s[i][i]; - s[j][i] = 0.0; - for(jj=i+1;jj<8;jj++) - s[j][jj] -= mji*s[i][jj]; - } - } - if(s[3][3] == 0.0) return minv; // singular matrix! - - // - // Now we have an upper triangular matrix. - // - // x x x x | y y y y - // 0 x x x | y y y y - // 0 0 x x | y y y y - // 0 0 0 x | y y y y - // - // we'll back substitute to get the inverse - // - // 1 0 0 0 | z z z z - // 0 1 0 0 | z z z z - // 0 0 1 0 | z z z z - // 0 0 0 1 | z z z z - // - - real mij; - for(i=3;i>0;i--) - { - for(j=i-1;j > -1; j--) - { - mij = s[j][i]/s[i][i]; - for(jj=j+1;jj<8;jj++) - s[j][jj] -= mij*s[i][jj]; - } - } - - for(i=0;i<4;i++) - for(j=0;j<4;j++) - minv(i,j) = s[i][j+4] / s[i][i]; - - return minv; - } - - - matrix4 transpose() const - { - matrix4 mtrans; - - for(int i=0;i<4;i++) - for(int j=0;j<4;j++) - mtrans(i,j) = element(j,i); - return mtrans; - } - - matrix4 & mult_right( const matrix4 & b ) - { - matrix4 mt(*this); - set_value(real(0)); - - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - for(int c=0; c < 4; c++) - element(i,j) += mt(i,c) * b(c,j); - return *this; - } - - matrix4 & mult_left( const matrix4 & b ) - { - matrix4 mt(*this); - set_value(real(0)); - - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - for(int c=0; c < 4; c++) - element(i,j) += b(i,c) * mt(c,j); - return *this; - } - - // dst = M * src - void mult_matrix_vec( const vec3 &src, vec3 &dst ) const - { - real w = ( - src.v[0] * element(3,0) + - src.v[1] * element(3,1) + - src.v[2] * element(3,2) + - element(3,3) ); - - assert(w != GLH_ZERO); - - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) + - element(0,3) ) / w; - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) + - element(1,3) ) / w; - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) + - element(2,3) ) / w; - } - - void mult_matrix_vec( vec3 & src_and_dst) const - { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_vec_matrix( const vec3 &src, vec3 &dst ) const - { - real w = ( - src.v[0] * element(0,3) + - src.v[1] * element(1,3) + - src.v[2] * element(2,3) + - element(3,3) ); - - assert(w != GLH_ZERO); - - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) + - element(3,0) ) / w; - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) + - element(3,1) ) / w; - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) + - element(3,2) ) / w; - } - - - void mult_vec_matrix( vec3 & src_and_dst) const - { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } - - // dst = M * src - void mult_matrix_vec( const vec4 &src, vec4 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) + - src.v[3] * element(0,3)); - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) + - src.v[3] * element(1,3)); - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) + - src.v[3] * element(2,3)); - dst.v[3] = ( - src.v[0] * element(3,0) + - src.v[1] * element(3,1) + - src.v[2] * element(3,2) + - src.v[3] * element(3,3)); - } - - void mult_matrix_vec( vec4 & src_and_dst) const - { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_vec_matrix( const vec4 &src, vec4 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) + - src.v[3] * element(3,0)); - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) + - src.v[3] * element(3,1)); - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) + - src.v[3] * element(3,2)); - dst.v[3] = ( - src.v[0] * element(0,3) + - src.v[1] * element(1,3) + - src.v[2] * element(2,3) + - src.v[3] * element(3,3)); - } - - - void mult_vec_matrix( vec4 & src_and_dst) const - { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } - - - // dst = M * src - void mult_matrix_dir( const vec3 &src, vec3 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) ) ; - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) ) ; - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) ) ; - } - - - void mult_matrix_dir( vec3 & src_and_dst) const - { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_dir_matrix( const vec3 &src, vec3 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) ) ; - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) ) ; - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) ) ; - } - - - void mult_dir_matrix( vec3 & src_and_dst) const - { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } - - - real & operator () (int row, int col) - { return element(row,col); } - - const real & operator () (int row, int col) const - { return element(row,col); } - - real & element (int row, int col) - { return m[row | (col<<2)]; } - - const real & element (int row, int col) const - { return m[row | (col<<2)]; } - - matrix4 & operator *= ( const matrix4 & mat ) - { - mult_right( mat ); - return *this; - } - - matrix4 & operator *= ( const real & r ) - { - for (int i = 0; i < 4; ++i) - { - element(0,i) *= r; - element(1,i) *= r; - element(2,i) *= r; - element(3,i) *= r; - } - return *this; - } - - matrix4 & operator += ( const matrix4 & mat ) - { - for (int i = 0; i < 4; ++i) - { - element(0,i) += mat.element(0,i); - element(1,i) += mat.element(1,i); - element(2,i) += mat.element(2,i); - element(3,i) += mat.element(3,i); - } - return *this; - } - - friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); - friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); - friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); - - //protected: - real m[16]; - }; - - inline - matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) - { - matrix4 product; - - product = m1; - product.mult_right(m2); - - return product; - } - - inline - bool operator ==( const matrix4 &m1, const matrix4 &m2 ) - { - return ( - m1(0,0) == m2(0,0) && - m1(0,1) == m2(0,1) && - m1(0,2) == m2(0,2) && - m1(0,3) == m2(0,3) && - m1(1,0) == m2(1,0) && - m1(1,1) == m2(1,1) && - m1(1,2) == m2(1,2) && - m1(1,3) == m2(1,3) && - m1(2,0) == m2(2,0) && - m1(2,1) == m2(2,1) && - m1(2,2) == m2(2,2) && - m1(2,3) == m2(2,3) && - m1(3,0) == m2(3,0) && - m1(3,1) == m2(3,1) && - m1(3,2) == m2(3,2) && - m1(3,3) == m2(3,3) ); - } - - inline - bool operator != ( const matrix4 & m1, const matrix4 & m2 ) - { return !( m1 == m2 ); } - - - - - - - - - - - - - - class quaternion - { - public: - - quaternion() - { - *this = identity(); - } - - quaternion( const real v[4] ) - { - set_value( v ); - } - - - quaternion( real q0, real q1, real q2, real q3 ) - { - set_value( q0, q1, q2, q3 ); - } - - - quaternion( const matrix4 & m ) - { - set_value( m ); - } - - - quaternion( const vec3 &axis, real radians ) - { - set_value( axis, radians ); - } - - - quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) - { - set_value( rotateFrom, rotateTo ); - } - - quaternion( const vec3 & from_look, const vec3 & from_up, - const vec3 & to_look, const vec3& to_up) - { - set_value(from_look, from_up, to_look, to_up); - } - - const real * get_value() const - { - return &q[0]; - } - - void get_value( real &q0, real &q1, real &q2, real &q3 ) const - { - q0 = q[0]; - q1 = q[1]; - q2 = q[2]; - q3 = q[3]; - } - - quaternion & set_value( real q0, real q1, real q2, real q3 ) - { - q[0] = q0; - q[1] = q1; - q[2] = q2; - q[3] = q3; - counter = 0; - return *this; - } - - void get_value( vec3 &axis, real &radians ) const - { - radians = real(acos( q[3] ) * GLH_TWO); - if ( radians == GLH_ZERO ) - axis = vec3( 0.0, 0.0, 1.0 ); - else - { - axis.v[0] = q[0]; - axis.v[1] = q[1]; - axis.v[2] = q[2]; - axis.normalize(); - } - } - - void get_value( matrix4 & m ) const - { - real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; - - real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; - - s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); - - xs = q[0] * s; - ys = q[1] * s; - zs = q[2] * s; - - wx = q[3] * xs; - wy = q[3] * ys; - wz = q[3] * zs; - - xx = q[0] * xs; - xy = q[0] * ys; - xz = q[0] * zs; - - yy = q[1] * ys; - yz = q[1] * zs; - zz = q[2] * zs; - - m(0,0) = real( GLH_ONE - ( yy + zz )); - m(1,0) = real ( xy + wz ); - m(2,0) = real ( xz - wy ); - - m(0,1) = real ( xy - wz ); - m(1,1) = real ( GLH_ONE - ( xx + zz )); - m(2,1) = real ( yz + wx ); - - m(0,2) = real ( xz + wy ); - m(1,2) = real ( yz - wx ); - m(2,2) = real ( GLH_ONE - ( xx + yy )); - - m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; - m(3,3) = GLH_ONE; - } - - quaternion & set_value( const real * qp ) - { - memcpy(q,qp,sizeof(real) * 4); - - counter = 0; - return *this; - } - - quaternion & set_value( const matrix4 & m ) - { - real tr, s; - int i, j, k; - const int nxt[3] = { 1, 2, 0 }; - - tr = m(0,0) + m(1,1) + m(2,2); - - if ( tr > GLH_ZERO ) - { - s = real(sqrt( tr + m(3,3) )); - q[3] = real ( s * 0.5 ); - s = real(0.5) / s; - - q[0] = real ( ( m(1,2) - m(2,1) ) * s ); - q[1] = real ( ( m(2,0) - m(0,2) ) * s ); - q[2] = real ( ( m(0,1) - m(1,0) ) * s ); - } - else - { - i = 0; - if ( m(1,1) > m(0,0) ) - i = 1; - - if ( m(2,2) > m(i,i) ) - i = 2; - - j = nxt[i]; - k = nxt[j]; - - s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); - - q[i] = real ( s * 0.5 ); - s = real(0.5 / s); - - q[3] = real ( ( m(j,k) - m(k,j) ) * s ); - q[j] = real ( ( m(i,j) + m(j,i) ) * s ); - q[k] = real ( ( m(i,k) + m(k,i) ) * s ); - } - - counter = 0; - return *this; - } - - quaternion & set_value( const vec3 &axis, real theta ) - { - real sqnorm = axis.square_norm(); - - if (sqnorm <= GLH_EPSILON) - { - // axis too small. - x = y = z = 0.0; - w = 1.0; - } - else - { - theta *= real(0.5); - real sin_theta = real(sin(theta)); - - if (!equivalent(sqnorm,GLH_ONE)) - sin_theta /= real(sqrt(sqnorm)); - x = sin_theta * axis.v[0]; - y = sin_theta * axis.v[1]; - z = sin_theta * axis.v[2]; - w = real(cos(theta)); - } - return *this; - } - - quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) - { - vec3 p1, p2; - real alpha; - - p1 = rotateFrom; - p1.normalize(); - p2 = rotateTo; - p2.normalize(); - - alpha = p1.dot(p2); - - if(equivalent(alpha,GLH_ONE)) - { - *this = identity(); - return *this; - } - - // ensures that the anti-parallel case leads to a positive dot - if(equivalent(alpha,-GLH_ONE)) - { - vec3 v; - - if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) - v = vec3(p1.v[1], p1.v[2], p1.v[0]); - else - v = vec3(-p1.v[0], p1.v[1], p1.v[2]); - - v -= p1 * p1.dot(v); - v.normalize(); - - set_value(v, GLH_PI); - return *this; - } - - p1 = p1.cross(p2); - p1.normalize(); - set_value(p1,real(acos(alpha))); - - counter = 0; - return *this; - } - - quaternion & set_value( const vec3 & from_look, const vec3 & from_up, - const vec3 & to_look, const vec3 & to_up) - { - quaternion r_look = quaternion(from_look, to_look); - - vec3 rotated_from_up(from_up); - r_look.mult_vec(rotated_from_up); - - quaternion r_twist = quaternion(rotated_from_up, to_up); - - *this = r_twist; - *this *= r_look; - return *this; - } - - quaternion & operator *= ( const quaternion & qr ) - { - quaternion ql(*this); - - w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; - x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; - y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; - z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; - - counter += qr.counter; - counter++; - counter_normalize(); - return *this; - } - - void normalize() - { - real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); - if (equivalent(rnorm, GLH_ZERO)) - return; - x *= rnorm; - y *= rnorm; - z *= rnorm; - w *= rnorm; - counter = 0; - } - - friend bool operator == ( const quaternion & q1, const quaternion & q2 ); - - friend bool operator != ( const quaternion & q1, const quaternion & q2 ); - - friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); - - bool equals( const quaternion & r, real tolerance ) const - { - real t; - - t = ( - (q[0]-r.q[0])*(q[0]-r.q[0]) + - (q[1]-r.q[1])*(q[1]-r.q[1]) + - (q[2]-r.q[2])*(q[2]-r.q[2]) + - (q[3]-r.q[3])*(q[3]-r.q[3]) ); - if(t > GLH_EPSILON) - return false; - return 1; - } - - quaternion & conjugate() - { - q[0] *= -GLH_ONE; - q[1] *= -GLH_ONE; - q[2] *= -GLH_ONE; - return *this; - } - - quaternion & invert() - { - return conjugate(); - } - - quaternion inverse() const - { - quaternion r = *this; - return r.invert(); - } - - // - // Quaternion multiplication with cartesian vector - // v' = q*v*q(star) - // - void mult_vec( const vec3 &src, vec3 &dst ) const - { - real v_coef = w * w - x * x - y * y - z * z; - real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); - real c_coef = GLH_TWO * w; - - dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); - dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); - dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); - } - - void mult_vec( vec3 & src_and_dst) const - { - mult_vec(vec3(src_and_dst), src_and_dst); - } - - void scale_angle( real scaleFactor ) - { - vec3 axis; - real radians; - - get_value(axis, radians); - radians *= scaleFactor; - set_value(axis, radians); - } - - static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) - { - quaternion r; - - real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; - // if B is on opposite hemisphere from A, use -B instead - - int bflip; - if ( ( bflip = (cos_omega < GLH_ZERO)) ) - cos_omega = -cos_omega; - - // complementary interpolation parameter - real beta = GLH_ONE - alpha; - - if(cos_omega <= GLH_ONE - GLH_EPSILON) - return p; - - real omega = real(acos(cos_omega)); - real one_over_sin_omega = GLH_ONE / real(sin(omega)); - - beta = real(sin(omega*beta) * one_over_sin_omega); - alpha = real(sin(omega*alpha) * one_over_sin_omega); - - if (bflip) - alpha = -alpha; - - r.x = beta * p.q[0]+ alpha * q.q[0]; - r.y = beta * p.q[1]+ alpha * q.q[1]; - r.z = beta * p.q[2]+ alpha * q.q[2]; - r.w = beta * p.q[3]+ alpha * q.q[3]; - return r; - } - - static quaternion identity() - { - static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); - return ident; - } - - real & operator []( int i ) - { - assert(i < 4); - return q[i]; - } - - const real & operator []( int i ) const - { - assert(i < 4); - return q[i]; - } - - protected: - - void counter_normalize() - { - if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) - normalize(); - } - - union - { - struct - { - real q[4]; - }; - struct - { - real x; - real y; - real z; - real w; - }; - }; - - // renormalization counter - unsigned char counter; - }; - - inline - bool operator == ( const quaternion & q1, const quaternion & q2 ) - { - return (equivalent(q1.x, q2.x) && - equivalent(q1.y, q2.y) && - equivalent(q1.z, q2.z) && - equivalent(q1.w, q2.w) ); - } - - inline - bool operator != ( const quaternion & q1, const quaternion & q2 ) - { - return ! ( q1 == q2 ); - } - - inline - quaternion operator * ( const quaternion & q1, const quaternion & q2 ) - { - quaternion r(q1); - r *= q2; - return r; - } - - - - - - - - - - - class plane - { - public: - - plane() - { - planedistance = 0.0; - planenormal.set_value( 0.0, 0.0, 1.0 ); - } - - - plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) - { - vec3 v0 = p1 - p0; - vec3 v1 = p2 - p0; - planenormal = v0.cross(v1); - planenormal.normalize(); - planedistance = p0.dot(planenormal); - } - - plane( const vec3 &normal, real distance ) - { - planedistance = distance; - planenormal = normal; - planenormal.normalize(); - } - - plane( const vec3 &normal, const vec3 &point ) - { - planenormal = normal; - planenormal.normalize(); - planedistance = point.dot(planenormal); - } - - void offset( real d ) - { - planedistance += d; - } - - bool intersect( const line &l, vec3 &intersection ) const - { - vec3 pos, dir; - vec3 pn = planenormal; - real pd = planedistance; - - pos = l.get_position(); - dir = l.get_direction(); - - if(dir.dot(pn) == 0.0) return 0; - pos -= pn*pd; - // now we're talking about a plane passing through the origin - if(pos.dot(pn) < 0.0) pn.negate(); - if(dir.dot(pn) > 0.0) dir.negate(); - vec3 ppos = pn * pos.dot(pn); - pos = (ppos.length()/dir.dot(-pn))*dir; - intersection = l.get_position(); - intersection += pos; - return 1; - } - void transform( const matrix4 &matrix ) - { - matrix4 invtr = matrix.inverse(); - invtr = invtr.transpose(); - - vec3 pntOnplane = planenormal * planedistance; - vec3 newPntOnplane; - vec3 newnormal; - - invtr.mult_dir_matrix(planenormal, newnormal); - matrix.mult_vec_matrix(pntOnplane, newPntOnplane); - - newnormal.normalize(); - planenormal = newnormal; - planedistance = newPntOnplane.dot(planenormal); - } - - bool is_in_half_space( const vec3 &point ) const - { - - if(( point.dot(planenormal) - planedistance) < 0.0) - return 0; - return 1; - } - - - real distance( const vec3 & point ) const - { - return planenormal.dot(point - planenormal*planedistance); - } - - const vec3 &get_normal() const - { - return planenormal; - } - - - real get_distance_from_origin() const - { - return planedistance; - } - - - friend bool operator == ( const plane & p1, const plane & p2 ); - - - friend bool operator != ( const plane & p1, const plane & p2 ); - - //protected: - vec3 planenormal; - real planedistance; - }; - - inline - bool operator == (const plane & p1, const plane & p2 ) - { - return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); - } - - inline - bool operator != ( const plane & p1, const plane & p2 ) - { return ! (p1 == p2); } - - - - } // "ns_##GLH_REAL" - - // make common typedefs... -#ifdef GLH_REAL_IS_FLOAT - typedef GLH_REAL_NAMESPACE::vec2 vec2f; - typedef GLH_REAL_NAMESPACE::vec3 vec3f; - typedef GLH_REAL_NAMESPACE::vec4 vec4f; - typedef GLH_REAL_NAMESPACE::quaternion quaternionf; - typedef GLH_REAL_NAMESPACE::quaternion rotationf; - typedef GLH_REAL_NAMESPACE::line linef; - typedef GLH_REAL_NAMESPACE::plane planef; - typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; -#endif - - - - -} // namespace glh - - - -#endif - +/* + glh - is a platform-indepenedent C++ OpenGL helper library + + + Copyright (c) 2000 Cass Everitt + Copyright (c) 2000 NVIDIA Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + + * The names of contributors to this software may not be used + to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + Cass Everitt - cass@r3.nu +*/ + +/* +glh_linear.h +*/ + +// Author: Cass W. Everitt + +#ifndef GLH_LINEAR_H +#define GLH_LINEAR_H + +#include +#include +#include + +// only supports float for now... +#define GLH_REAL_IS_FLOAT + +#ifdef GLH_REAL_IS_FLOAT +# define GLH_REAL float +# define GLH_REAL_NAMESPACE ns_float +#endif + +#define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 + +#define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) +#define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) +#define GLH_ZERO GLH_REAL(0.0) +#define GLH_ONE GLH_REAL(1.0) +#define GLH_TWO GLH_REAL(2.0) +#define GLH_EPSILON GLH_REAL(10e-6) +#define GLH_PI GLH_REAL(3.1415926535897932384626433832795) + +#define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) + +namespace glh +{ + + inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } + inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } + + // forward declarations for friend template functions. + template class vec; + + // forward declarations for friend template functions. + template + bool operator == ( const vec & v1, const vec & v2 ); + + // forward declarations for friend template functions. + template + bool operator != ( const vec & v1, const vec & v2 ); + + template + class vec + { + public: + int size() const { return N; } + + vec(const T & t = T()) + { for(int i = 0; i < N; i++) v[i] = t; } + vec(const T * tp) + { for(int i = 0; i < N; i++) v[i] = tp[i]; } + + const T * get_value() const + { return v; } + + + T dot( const vec & rhs ) const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; + return r; + } + + T length() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return T(sqrt(r)); + } + + T square_norm() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return r; + } + + void negate() + { for(int i = 0; i < N; i++) v[i] = -v[i]; } + + + T normalize() + { + T sum(0); + for(int i = 0; i < N; i++) + sum += v[i]*v[i]; + sum = T(sqrt(sum)); + if (sum > GLH_EPSILON) + for(int i = 0; i < N; i++) + v[i] /= sum; + return sum; + } + + + vec & set_value( const T * rhs ) + { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } + + T & operator [] ( int i ) + { return v[i]; } + + const T & operator [] ( int i ) const + { return v[i]; } + + vec & operator *= ( T d ) + { for(int i = 0; i < N; i++) v[i] *= d; return *this;} + + vec & operator *= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} + + vec & operator /= ( T d ) + { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} + + vec & operator += ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} + + vec & operator -= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} + + + vec operator - () const + { vec rv = v; rv.negate(); return rv; } + + vec operator + ( const vec &v) const + { vec rt(*this); return rt += v; } + + vec operator - ( const vec &v) const + { vec rt(*this); return rt -= v; } + + vec operator * ( T d) const + { vec rt(*this); return rt *= d; } + + friend bool operator == <> ( const vec &v1, const vec &v2 ); + friend bool operator != <> ( const vec &v1, const vec &v2 ); + + + //protected: + T v[N]; + }; + + + + // vector friend operators + + template inline + vec operator * ( const vec & b, T d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator * ( T d, const vec & b ) + { return b*d; } + + template inline + vec operator * ( const vec & b, const vec & d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator / ( const vec & b, T d ) + { vec rt(b); return rt /= d; } + + template inline + vec operator + ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt += v2; } + + template inline + vec operator - ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt -= v2; } + + + template inline + bool operator == ( const vec & v1, const vec & v2 ) + { + for(int i = 0; i < N; i++) + if(v1.v[i] != v2.v[i]) + return false; + return true; + } + + template inline + bool operator != ( const vec & v1, const vec & v2 ) + { return !(v1 == v2); } + + + typedef vec<3,unsigned char> vec3ub; + typedef vec<4,unsigned char> vec4ub; + + + + + + namespace GLH_REAL_NAMESPACE + { + typedef GLH_REAL real; + + class line; + class plane; + class matrix4; + class quaternion; + typedef quaternion rotation; + + class vec2 : public vec<2,real> + { + public: + vec2(const real & t = real()) : vec<2,real>(t) + {} + vec2(const vec<2,real> & t) : vec<2,real>(t) + {} + vec2(const real * tp) : vec<2,real>(tp) + {} + + vec2(real x, real y ) + { v[0] = x; v[1] = y; } + + void get_value(real & x, real & y) const + { x = v[0]; y = v[1]; } + + vec2 & set_value( const real & x, const real & y) + { v[0] = x; v[1] = y; return *this; } + + }; + + + class vec3 : public vec<3,real> + { + public: + vec3(const real & t = real()) : vec<3,real>(t) + {} + vec3(const vec<3,real> & t) : vec<3,real>(t) + {} + vec3(const real * tp) : vec<3,real>(tp) + {} + + vec3(real x, real y, real z) + { v[0] = x; v[1] = y; v[2] = z; } + + void get_value(real & x, real & y, real & z) const + { x = v[0]; y = v[1]; z = v[2]; } + + vec3 cross( const vec3 &rhs ) const + { + vec3 rt; + rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; + rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; + rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; + return rt; + } + + vec3 & set_value( const real & x, const real & y, const real & z) + { v[0] = x; v[1] = y; v[2] = z; return *this; } + + }; + + + class vec4 : public vec<4,real> + { + public: + vec4(const real & t = real()) : vec<4,real>(t) + {} + vec4(const vec<4,real> & t) : vec<4,real>(t) + {} + + vec4(const vec<3,real> & t, real fourth) + + { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } + vec4(const real * tp) : vec<4,real>(tp) + {} + vec4(real x, real y, real z, real w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } + + void get_value(real & x, real & y, real & z, real & w) const + { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } + + vec4 & set_value( const real & x, const real & y, const real & z, const real & w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } + }; + + inline + vec3 homogenize(const vec4 & v) + { + vec3 rt; + assert(v.v[3] != GLH_ZERO); + rt.v[0] = v.v[0]/v.v[3]; + rt.v[1] = v.v[1]/v.v[3]; + rt.v[2] = v.v[2]/v.v[3]; + return rt; + } + + + + class line + { + public: + + line() + { set_value(vec3(0,0,0),vec3(0,0,1)); } + + line( const vec3 & p0, const vec3 &p1) + { set_value(p0,p1); } + + void set_value( const vec3 &p0, const vec3 &p1) + { + position = p0; + direction = p1-p0; + direction.normalize(); + } + + bool get_closest_points(const line &line2, + vec3 &pointOnThis, + vec3 &pointOnThat) + { + + // quick check to see if parallel -- if so, quit. + if(fabs(direction.dot(line2.direction)) == 1.0) + return 0; + line l2 = line2; + + // Algorithm: Brian Jean + // + register real u; + register real v; + vec3 Vr = direction; + vec3 Vs = l2.direction; + register real Vr_Dot_Vs = Vr.dot(Vs); + register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); + vec3 C = l2.position - position; + register real C_Dot_Vr = C.dot(Vr); + register real C_Dot_Vs = C.dot(Vs); + + u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; + v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; + + pointOnThis = position; + pointOnThis += direction * u; + pointOnThat = l2.position; + pointOnThat += l2.direction * v; + + return 1; + } + + vec3 get_closest_point(const vec3 &point) + { + vec3 np = point - position; + vec3 rp = direction*direction.dot(np)+position; + return rp; + } + + const vec3 & get_position() const {return position;} + + const vec3 & get_direction() const {return direction;} + + //protected: + vec3 position; + vec3 direction; + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // matrix + + + class matrix4 + { + + public: + + matrix4() { make_identity(); } + + matrix4( real r ) + { set_value(r); } + + matrix4( real * m ) + { set_value(m); } + + matrix4( real a00, real a01, real a02, real a03, + real a10, real a11, real a12, real a13, + real a20, real a21, real a22, real a23, + real a30, real a31, real a32, real a33 ) + { + element(0,0) = a00; + element(0,1) = a01; + element(0,2) = a02; + element(0,3) = a03; + + element(1,0) = a10; + element(1,1) = a11; + element(1,2) = a12; + element(1,3) = a13; + + element(2,0) = a20; + element(2,1) = a21; + element(2,2) = a22; + element(2,3) = a23; + + element(3,0) = a30; + element(3,1) = a31; + element(3,2) = a32; + element(3,3) = a33; + } + + + void get_value( real * mp ) const + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + mp[c++] = element(i,j); + } + + + const real * get_value() const + { return m; } + + void set_value( real * mp) + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + element(i,j) = mp[c++]; + } + + void set_value( real r ) + { + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + element(i,j) = r; + } + + void make_identity() + { + element(0,0) = 1.0; + element(0,1) = 0.0; + element(0,2) = 0.0; + element(0,3) = 0.0; + + element(1,0) = 0.0; + element(1,1) = 1.0; + element(1,2) = 0.0; + element(1,3) = 0.0; + + element(2,0) = 0.0; + element(2,1) = 0.0; + element(2,2) = 1.0; + element(2,3) = 0.0; + + element(3,0) = 0.0; + element(3,1) = 0.0; + element(3,2) = 0.0; + element(3,3) = 1.0; + } + + + static matrix4 identity() + { + static matrix4 mident ( + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 ); + return mident; + } + + + void set_scale( real s ) + { + element(0,0) = s; + element(1,1) = s; + element(2,2) = s; + } + + void set_scale( const vec3 & s ) + { + element(0,0) = s.v[0]; + element(1,1) = s.v[1]; + element(2,2) = s.v[2]; + } + + + void set_translate( const vec3 & t ) + { + element(0,3) = t.v[0]; + element(1,3) = t.v[1]; + element(2,3) = t.v[2]; + } + + void set_row(int r, const vec4 & t) + { + element(r,0) = t.v[0]; + element(r,1) = t.v[1]; + element(r,2) = t.v[2]; + element(r,3) = t.v[3]; + } + + void set_column(int c, const vec4 & t) + { + element(0,c) = t.v[0]; + element(1,c) = t.v[1]; + element(2,c) = t.v[2]; + element(3,c) = t.v[3]; + } + + + void get_row(int r, vec4 & t) const + { + t.v[0] = element(r,0); + t.v[1] = element(r,1); + t.v[2] = element(r,2); + t.v[3] = element(r,3); + } + + vec4 get_row(int r) const + { + vec4 v; get_row(r, v); + return v; + } + + void get_column(int c, vec4 & t) const + { + t.v[0] = element(0,c); + t.v[1] = element(1,c); + t.v[2] = element(2,c); + t.v[3] = element(3,c); + } + + vec4 get_column(int c) const + { + vec4 v; get_column(c, v); + return v; + } + + matrix4 inverse() const + { + matrix4 minv; + + real r1[8], r2[8], r3[8], r4[8]; + real *s[4], *tmprow; + + s[0] = &r1[0]; + s[1] = &r2[0]; + s[2] = &r3[0]; + s[3] = &r4[0]; + + register int i,j,p,jj; + for(i=0;i<4;i++) + { + for(j=0;j<4;j++) + { + s[i][j] = element(i,j); + if(i==j) s[i][j+4] = 1.0; + else s[i][j+4] = 0.0; + } + } + real scp[4]; + for(i=0;i<4;i++) + { + scp[i] = real(fabs(s[i][0])); + for(j=1;j<4;j++) + if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); + if(scp[i] == 0.0) return minv; // singular matrix! + } + + int pivot_to; + real scp_max; + for(i=0;i<4;i++) + { + // select pivot row + pivot_to = i; + scp_max = real(fabs(s[i][i]/scp[i])); + // find out which row should be on top + for(p=i+1;p<4;p++) + if(real(fabs(s[p][i]/scp[p])) > scp_max) + { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } + // Pivot if necessary + if(pivot_to != i) + { + tmprow = s[i]; + s[i] = s[pivot_to]; + s[pivot_to] = tmprow; + real tmpscp; + tmpscp = scp[i]; + scp[i] = scp[pivot_to]; + scp[pivot_to] = tmpscp; + } + + real mji; + // perform gaussian elimination + for(j=i+1;j<4;j++) + { + mji = s[j][i]/s[i][i]; + s[j][i] = 0.0; + for(jj=i+1;jj<8;jj++) + s[j][jj] -= mji*s[i][jj]; + } + } + if(s[3][3] == 0.0) return minv; // singular matrix! + + // + // Now we have an upper triangular matrix. + // + // x x x x | y y y y + // 0 x x x | y y y y + // 0 0 x x | y y y y + // 0 0 0 x | y y y y + // + // we'll back substitute to get the inverse + // + // 1 0 0 0 | z z z z + // 0 1 0 0 | z z z z + // 0 0 1 0 | z z z z + // 0 0 0 1 | z z z z + // + + real mij; + for(i=3;i>0;i--) + { + for(j=i-1;j > -1; j--) + { + mij = s[j][i]/s[i][i]; + for(jj=j+1;jj<8;jj++) + s[j][jj] -= mij*s[i][jj]; + } + } + + for(i=0;i<4;i++) + for(j=0;j<4;j++) + minv(i,j) = s[i][j+4] / s[i][i]; + + return minv; + } + + + matrix4 transpose() const + { + matrix4 mtrans; + + for(int i=0;i<4;i++) + for(int j=0;j<4;j++) + mtrans(i,j) = element(j,i); + return mtrans; + } + + matrix4 & mult_right( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += mt(i,c) * b(c,j); + return *this; + } + + matrix4 & mult_left( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += b(i,c) * mt(c,j); + return *this; + } + + // dst = M * src + void mult_matrix_vec( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + element(0,3) ) / w; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + element(1,3) ) / w; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + element(2,3) ) / w; + } + + void mult_matrix_vec( vec3 & src_and_dst) const + { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + element(3,0) ) / w; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + element(3,1) ) / w; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + element(3,2) ) / w; + } + + + void mult_vec_matrix( vec3 & src_and_dst) const + { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } + + // dst = M * src + void mult_matrix_vec( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + src.v[3] * element(0,3)); + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + src.v[3] * element(1,3)); + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + src.v[3] * element(2,3)); + dst.v[3] = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + src.v[3] * element(3,3)); + } + + void mult_matrix_vec( vec4 & src_and_dst) const + { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + src.v[3] * element(3,0)); + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + src.v[3] * element(3,1)); + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + src.v[3] * element(3,2)); + dst.v[3] = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + src.v[3] * element(3,3)); + } + + + void mult_vec_matrix( vec4 & src_and_dst) const + { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } + + + // dst = M * src + void mult_matrix_dir( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) ) ; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) ) ; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) ) ; + } + + + void mult_matrix_dir( vec3 & src_and_dst) const + { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_dir_matrix( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) ) ; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) ) ; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) ) ; + } + + + void mult_dir_matrix( vec3 & src_and_dst) const + { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } + + + real & operator () (int row, int col) + { return element(row,col); } + + const real & operator () (int row, int col) const + { return element(row,col); } + + real & element (int row, int col) + { return m[row | (col<<2)]; } + + const real & element (int row, int col) const + { return m[row | (col<<2)]; } + + matrix4 & operator *= ( const matrix4 & mat ) + { + mult_right( mat ); + return *this; + } + + matrix4 & operator *= ( const real & r ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) *= r; + element(1,i) *= r; + element(2,i) *= r; + element(3,i) *= r; + } + return *this; + } + + matrix4 & operator += ( const matrix4 & mat ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) += mat.element(0,i); + element(1,i) += mat.element(1,i); + element(2,i) += mat.element(2,i); + element(3,i) += mat.element(3,i); + } + return *this; + } + + friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); + + //protected: + real m[16]; + }; + + inline + matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) + { + matrix4 product; + + product = m1; + product.mult_right(m2); + + return product; + } + + inline + bool operator ==( const matrix4 &m1, const matrix4 &m2 ) + { + return ( + m1(0,0) == m2(0,0) && + m1(0,1) == m2(0,1) && + m1(0,2) == m2(0,2) && + m1(0,3) == m2(0,3) && + m1(1,0) == m2(1,0) && + m1(1,1) == m2(1,1) && + m1(1,2) == m2(1,2) && + m1(1,3) == m2(1,3) && + m1(2,0) == m2(2,0) && + m1(2,1) == m2(2,1) && + m1(2,2) == m2(2,2) && + m1(2,3) == m2(2,3) && + m1(3,0) == m2(3,0) && + m1(3,1) == m2(3,1) && + m1(3,2) == m2(3,2) && + m1(3,3) == m2(3,3) ); + } + + inline + bool operator != ( const matrix4 & m1, const matrix4 & m2 ) + { return !( m1 == m2 ); } + + + + + + + + + + + + + + class quaternion + { + public: + + quaternion() + { + *this = identity(); + } + + quaternion( const real v[4] ) + { + set_value( v ); + } + + + quaternion( real q0, real q1, real q2, real q3 ) + { + set_value( q0, q1, q2, q3 ); + } + + + quaternion( const matrix4 & m ) + { + set_value( m ); + } + + + quaternion( const vec3 &axis, real radians ) + { + set_value( axis, radians ); + } + + + quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) + { + set_value( rotateFrom, rotateTo ); + } + + quaternion( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3& to_up) + { + set_value(from_look, from_up, to_look, to_up); + } + + const real * get_value() const + { + return &q[0]; + } + + void get_value( real &q0, real &q1, real &q2, real &q3 ) const + { + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + } + + quaternion & set_value( real q0, real q1, real q2, real q3 ) + { + q[0] = q0; + q[1] = q1; + q[2] = q2; + q[3] = q3; + counter = 0; + return *this; + } + + void get_value( vec3 &axis, real &radians ) const + { + radians = real(acos( q[3] ) * GLH_TWO); + if ( radians == GLH_ZERO ) + axis = vec3( 0.0, 0.0, 1.0 ); + else + { + axis.v[0] = q[0]; + axis.v[1] = q[1]; + axis.v[2] = q[2]; + axis.normalize(); + } + } + + void get_value( matrix4 & m ) const + { + real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; + + real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; + + s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); + + xs = q[0] * s; + ys = q[1] * s; + zs = q[2] * s; + + wx = q[3] * xs; + wy = q[3] * ys; + wz = q[3] * zs; + + xx = q[0] * xs; + xy = q[0] * ys; + xz = q[0] * zs; + + yy = q[1] * ys; + yz = q[1] * zs; + zz = q[2] * zs; + + m(0,0) = real( GLH_ONE - ( yy + zz )); + m(1,0) = real ( xy + wz ); + m(2,0) = real ( xz - wy ); + + m(0,1) = real ( xy - wz ); + m(1,1) = real ( GLH_ONE - ( xx + zz )); + m(2,1) = real ( yz + wx ); + + m(0,2) = real ( xz + wy ); + m(1,2) = real ( yz - wx ); + m(2,2) = real ( GLH_ONE - ( xx + yy )); + + m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; + m(3,3) = GLH_ONE; + } + + quaternion & set_value( const real * qp ) + { + memcpy(q,qp,sizeof(real) * 4); + + counter = 0; + return *this; + } + + quaternion & set_value( const matrix4 & m ) + { + real tr, s; + int i, j, k; + const int nxt[3] = { 1, 2, 0 }; + + tr = m(0,0) + m(1,1) + m(2,2); + + if ( tr > GLH_ZERO ) + { + s = real(sqrt( tr + m(3,3) )); + q[3] = real ( s * 0.5 ); + s = real(0.5) / s; + + q[0] = real ( ( m(1,2) - m(2,1) ) * s ); + q[1] = real ( ( m(2,0) - m(0,2) ) * s ); + q[2] = real ( ( m(0,1) - m(1,0) ) * s ); + } + else + { + i = 0; + if ( m(1,1) > m(0,0) ) + i = 1; + + if ( m(2,2) > m(i,i) ) + i = 2; + + j = nxt[i]; + k = nxt[j]; + + s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); + + q[i] = real ( s * 0.5 ); + s = real(0.5 / s); + + q[3] = real ( ( m(j,k) - m(k,j) ) * s ); + q[j] = real ( ( m(i,j) + m(j,i) ) * s ); + q[k] = real ( ( m(i,k) + m(k,i) ) * s ); + } + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 &axis, real theta ) + { + real sqnorm = axis.square_norm(); + + if (sqnorm <= GLH_EPSILON) + { + // axis too small. + x = y = z = 0.0; + w = 1.0; + } + else + { + theta *= real(0.5); + real sin_theta = real(sin(theta)); + + if (!equivalent(sqnorm,GLH_ONE)) + sin_theta /= real(sqrt(sqnorm)); + x = sin_theta * axis.v[0]; + y = sin_theta * axis.v[1]; + z = sin_theta * axis.v[2]; + w = real(cos(theta)); + } + return *this; + } + + quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) + { + vec3 p1, p2; + real alpha; + + p1 = rotateFrom; + p1.normalize(); + p2 = rotateTo; + p2.normalize(); + + alpha = p1.dot(p2); + + if(equivalent(alpha,GLH_ONE)) + { + *this = identity(); + return *this; + } + + // ensures that the anti-parallel case leads to a positive dot + if(equivalent(alpha,-GLH_ONE)) + { + vec3 v; + + if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) + v = vec3(p1.v[1], p1.v[2], p1.v[0]); + else + v = vec3(-p1.v[0], p1.v[1], p1.v[2]); + + v -= p1 * p1.dot(v); + v.normalize(); + + set_value(v, GLH_PI); + return *this; + } + + p1 = p1.cross(p2); + p1.normalize(); + set_value(p1,real(acos(alpha))); + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3 & to_up) + { + quaternion r_look = quaternion(from_look, to_look); + + vec3 rotated_from_up(from_up); + r_look.mult_vec(rotated_from_up); + + quaternion r_twist = quaternion(rotated_from_up, to_up); + + *this = r_twist; + *this *= r_look; + return *this; + } + + quaternion & operator *= ( const quaternion & qr ) + { + quaternion ql(*this); + + w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; + x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; + y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; + z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; + + counter += qr.counter; + counter++; + counter_normalize(); + return *this; + } + + void normalize() + { + real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); + if (equivalent(rnorm, GLH_ZERO)) + return; + x *= rnorm; + y *= rnorm; + z *= rnorm; + w *= rnorm; + counter = 0; + } + + friend bool operator == ( const quaternion & q1, const quaternion & q2 ); + + friend bool operator != ( const quaternion & q1, const quaternion & q2 ); + + friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); + + bool equals( const quaternion & r, real tolerance ) const + { + real t; + + t = ( + (q[0]-r.q[0])*(q[0]-r.q[0]) + + (q[1]-r.q[1])*(q[1]-r.q[1]) + + (q[2]-r.q[2])*(q[2]-r.q[2]) + + (q[3]-r.q[3])*(q[3]-r.q[3]) ); + if(t > GLH_EPSILON) + return false; + return 1; + } + + quaternion & conjugate() + { + q[0] *= -GLH_ONE; + q[1] *= -GLH_ONE; + q[2] *= -GLH_ONE; + return *this; + } + + quaternion & invert() + { + return conjugate(); + } + + quaternion inverse() const + { + quaternion r = *this; + return r.invert(); + } + + // + // Quaternion multiplication with cartesian vector + // v' = q*v*q(star) + // + void mult_vec( const vec3 &src, vec3 &dst ) const + { + real v_coef = w * w - x * x - y * y - z * z; + real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); + real c_coef = GLH_TWO * w; + + dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); + dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); + dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); + } + + void mult_vec( vec3 & src_and_dst) const + { + mult_vec(vec3(src_and_dst), src_and_dst); + } + + void scale_angle( real scaleFactor ) + { + vec3 axis; + real radians; + + get_value(axis, radians); + radians *= scaleFactor; + set_value(axis, radians); + } + + static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) + { + quaternion r; + + real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; + // if B is on opposite hemisphere from A, use -B instead + + int bflip; + if ( ( bflip = (cos_omega < GLH_ZERO)) ) + cos_omega = -cos_omega; + + // complementary interpolation parameter + real beta = GLH_ONE - alpha; + + if(cos_omega <= GLH_ONE - GLH_EPSILON) + return p; + + real omega = real(acos(cos_omega)); + real one_over_sin_omega = GLH_ONE / real(sin(omega)); + + beta = real(sin(omega*beta) * one_over_sin_omega); + alpha = real(sin(omega*alpha) * one_over_sin_omega); + + if (bflip) + alpha = -alpha; + + r.x = beta * p.q[0]+ alpha * q.q[0]; + r.y = beta * p.q[1]+ alpha * q.q[1]; + r.z = beta * p.q[2]+ alpha * q.q[2]; + r.w = beta * p.q[3]+ alpha * q.q[3]; + return r; + } + + static quaternion identity() + { + static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); + return ident; + } + + real & operator []( int i ) + { + assert(i < 4); + return q[i]; + } + + const real & operator []( int i ) const + { + assert(i < 4); + return q[i]; + } + + protected: + + void counter_normalize() + { + if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) + normalize(); + } + + union + { + struct + { + real q[4]; + }; + struct + { + real x; + real y; + real z; + real w; + }; + }; + + // renormalization counter + unsigned char counter; + }; + + inline + bool operator == ( const quaternion & q1, const quaternion & q2 ) + { + return (equivalent(q1.x, q2.x) && + equivalent(q1.y, q2.y) && + equivalent(q1.z, q2.z) && + equivalent(q1.w, q2.w) ); + } + + inline + bool operator != ( const quaternion & q1, const quaternion & q2 ) + { + return ! ( q1 == q2 ); + } + + inline + quaternion operator * ( const quaternion & q1, const quaternion & q2 ) + { + quaternion r(q1); + r *= q2; + return r; + } + + + + + + + + + + + class plane + { + public: + + plane() + { + planedistance = 0.0; + planenormal.set_value( 0.0, 0.0, 1.0 ); + } + + + plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) + { + vec3 v0 = p1 - p0; + vec3 v1 = p2 - p0; + planenormal = v0.cross(v1); + planenormal.normalize(); + planedistance = p0.dot(planenormal); + } + + plane( const vec3 &normal, real distance ) + { + planedistance = distance; + planenormal = normal; + planenormal.normalize(); + } + + plane( const vec3 &normal, const vec3 &point ) + { + planenormal = normal; + planenormal.normalize(); + planedistance = point.dot(planenormal); + } + + void offset( real d ) + { + planedistance += d; + } + + bool intersect( const line &l, vec3 &intersection ) const + { + vec3 pos, dir; + vec3 pn = planenormal; + real pd = planedistance; + + pos = l.get_position(); + dir = l.get_direction(); + + if(dir.dot(pn) == 0.0) return 0; + pos -= pn*pd; + // now we're talking about a plane passing through the origin + if(pos.dot(pn) < 0.0) pn.negate(); + if(dir.dot(pn) > 0.0) dir.negate(); + vec3 ppos = pn * pos.dot(pn); + pos = (ppos.length()/dir.dot(-pn))*dir; + intersection = l.get_position(); + intersection += pos; + return 1; + } + void transform( const matrix4 &matrix ) + { + matrix4 invtr = matrix.inverse(); + invtr = invtr.transpose(); + + vec3 pntOnplane = planenormal * planedistance; + vec3 newPntOnplane; + vec3 newnormal; + + invtr.mult_dir_matrix(planenormal, newnormal); + matrix.mult_vec_matrix(pntOnplane, newPntOnplane); + + newnormal.normalize(); + planenormal = newnormal; + planedistance = newPntOnplane.dot(planenormal); + } + + bool is_in_half_space( const vec3 &point ) const + { + + if(( point.dot(planenormal) - planedistance) < 0.0) + return 0; + return 1; + } + + + real distance( const vec3 & point ) const + { + return planenormal.dot(point - planenormal*planedistance); + } + + const vec3 &get_normal() const + { + return planenormal; + } + + + real get_distance_from_origin() const + { + return planedistance; + } + + + friend bool operator == ( const plane & p1, const plane & p2 ); + + + friend bool operator != ( const plane & p1, const plane & p2 ); + + //protected: + vec3 planenormal; + real planedistance; + }; + + inline + bool operator == (const plane & p1, const plane & p2 ) + { + return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); + } + + inline + bool operator != ( const plane & p1, const plane & p2 ) + { return ! (p1 == p2); } + + + + } // "ns_##GLH_REAL" + + // make common typedefs... +#ifdef GLH_REAL_IS_FLOAT + typedef GLH_REAL_NAMESPACE::vec2 vec2f; + typedef GLH_REAL_NAMESPACE::vec3 vec3f; + typedef GLH_REAL_NAMESPACE::vec4 vec4f; + typedef GLH_REAL_NAMESPACE::quaternion quaternionf; + typedef GLH_REAL_NAMESPACE::quaternion rotationf; + typedef GLH_REAL_NAMESPACE::line linef; + typedef GLH_REAL_NAMESPACE::plane planef; + typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; +#endif + + + + +} // namespace glh + + + +#endif + diff --git a/linden/indra/newview/llcloud.cpp b/linden/indra/newview/llcloud.cpp index 3e9b86a..b325265 100644 --- a/linden/indra/newview/llcloud.cpp +++ b/linden/indra/newview/llcloud.cpp @@ -427,7 +427,7 @@ void LLCloudLayer::decompress(LLBitPack &bitpack, LLGroupHeader *group_headerp) group_headerp->stride = group_headerp->patch_size; // offset required to step up one row set_group_of_patch_header(group_headerp); - decode_patch_header(bitpack, &patch_header); + decode_patch_header(bitpack, &patch_header, FALSE); decode_patch(bitpack, gBuffer); decompress_patch(mDensityp, gBuffer, &patch_header); } diff --git a/linden/indra/newview/llfloaterregioninfo.cpp b/linden/indra/newview/llfloaterregioninfo.cpp index d4ffe22..4880308 100644 --- a/linden/indra/newview/llfloaterregioninfo.cpp +++ b/linden/indra/newview/llfloaterregioninfo.cpp @@ -1244,10 +1244,10 @@ BOOL LLPanelRegionTextureInfo::sendUpdate() llinfos << "LLPanelRegionTextureInfo::sendUpdate()" << llendl; // Make sure user hasn't chosen wacky textures. - if (!validateTextureSizes()) - { - return FALSE; - } + //if (!validateTextureSizes()) + //{ + // return FALSE; + //} LLTextureCtrl* texture_ctrl; std::string buffer; diff --git a/linden/indra/newview/llglsandbox.cpp b/linden/indra/newview/llglsandbox.cpp index 98c4d06..96fd39b 100644 --- a/linden/indra/newview/llglsandbox.cpp +++ b/linden/indra/newview/llglsandbox.cpp @@ -710,7 +710,7 @@ void LLViewerParcelMgr::renderOneSegment(F32 x1, F32 y1, F32 x2, F32 y2, F32 hei { // HACK: At edge of last region of world, we need to make sure the region // resolves correctly so we can get a height value. - const F32 BORDER = REGION_WIDTH_METERS - 0.1f; + const F32 BORDER = regionp->getWidth() - 0.1f; F32 clamped_x1 = x1; F32 clamped_y1 = y1; diff --git a/linden/indra/newview/llmapresponders.cpp b/linden/indra/newview/llmapresponders.cpp index 9d974f2..b6b5c8a 100644 --- a/linden/indra/newview/llmapresponders.cpp +++ b/linden/indra/newview/llmapresponders.cpp @@ -120,6 +120,8 @@ void LLMapLayerResponder::result(const LLSD& result) S32 x_regions = map_block["X"]; S32 y_regions = map_block["Y"]; + S32 size_x_regions = map_block["SizeX"]; + S32 size_y_regions = map_block["SizeY"]; std::string name = map_block["Name"]; S32 access = map_block["Access"]; S32 region_flags = map_block["RegionFlags"]; @@ -168,6 +170,8 @@ void LLMapLayerResponder::result(const LLSD& result) LLWorldMap::getInstance()->mSimInfoMap[handle] = siminfo; siminfo->mHandle = handle; + siminfo->msizeX = size_x_regions; + siminfo->msizeY = size_y_regions; siminfo->mName.assign( name ); siminfo->mAccess = access; /*Flawfinder: ignore*/ siminfo->mRegionFlags = region_flags; diff --git a/linden/indra/newview/llstartup.cpp b/linden/indra/newview/llstartup.cpp index 5a3a8ee..0b6d75f 100644 --- a/linden/indra/newview/llstartup.cpp +++ b/linden/indra/newview/llstartup.cpp @@ -368,6 +368,8 @@ bool idle_startup() static U64 first_sim_handle = 0; static LLHost first_sim; static std::string first_sim_seed_cap; + static U32 first_sim_size_x = 256; + static U32 first_sim_size_y = 256; static LLVector3 initial_sun_direction(1.f, 0.f, 0.f); static LLVector3 agent_start_position_region(10.f, 10.f, 10.f); // default for when no space server @@ -1620,6 +1622,16 @@ bool idle_startup() first_sim_handle = to_region_handle(region_x, region_y); } + text = LLUserAuth::getInstance()->getResponse("region_size_x"); + if(!text.empty()) { + first_sim_size_x = strtoul(text.c_str(), NULL, 10); + LLViewerParcelMgr::getInstance()->init(first_sim_size_x); + } + + //region Y size is currently unused, major refactoring required. - Patrick Sapinski (2/10/2011) + text = LLUserAuth::getInstance()->getResponse("region_size_y"); + if(!text.empty()) first_sim_size_y = strtoul(text.c_str(), NULL, 10); + const std::string look_at_str = LLUserAuth::getInstance()->getResponse("look_at"); if (!look_at_str.empty()) { @@ -1915,7 +1927,7 @@ bool idle_startup() gAgent.initOriginGlobal(from_region_handle(first_sim_handle)); - LLWorld::getInstance()->addRegion(first_sim_handle, first_sim); + LLWorld::getInstance()->addRegion(first_sim_handle, first_sim, first_sim_size_x, first_sim_size_y); LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle(first_sim_handle); LL_INFOS("AppInit") << "Adding initial simulator " << regionp->getOriginGlobal() << LL_ENDL; diff --git a/linden/indra/newview/llsurface.cpp b/linden/indra/newview/llsurface.cpp index aaafe0d..66f8076 100644 --- a/linden/indra/newview/llsurface.cpp +++ b/linden/indra/newview/llsurface.cpp @@ -303,7 +303,7 @@ void LLSurface::initTextures() mWaterObjp = (LLVOWater *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_WATER, mRegionp); gPipeline.createObject(mWaterObjp); LLVector3d water_pos_global = from_region_handle(mRegionp->getHandle()); - water_pos_global += LLVector3d(128.0, 128.0, DEFAULT_WATER_HEIGHT); + water_pos_global += LLVector3d(mRegionp->getWidth()/2, mRegionp->getWidth()/2, DEFAULT_WATER_HEIGHT); mWaterObjp->setPositionGlobal(water_pos_global); } } @@ -356,8 +356,8 @@ void LLSurface::setOriginGlobal(const LLVector3d &origin_global) // Hack! if (mWaterObjp.notNull() && mWaterObjp->mDrawable.notNull()) { - const F64 x = origin_global.mdV[VX] + 128.0; - const F64 y = origin_global.mdV[VY] + 128.0; + const F64 x = origin_global.mdV[VX] + (F64)mRegionp->getWidth()/2; + const F64 y = origin_global.mdV[VY] + (F64)mRegionp->getWidth()/2; const F64 z = mWaterObjp->getPositionGlobal().mdV[VZ]; LLVector3d water_origin_global(x, y, z); @@ -707,14 +707,22 @@ void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL while (1) { - decode_patch_header(bitpack, &ph); + decode_patch_header(bitpack, &ph, b_large_patch); if (ph.quant_wbits == END_OF_PATCHES) { break; } - i = ph.patchids >> 5; - j = ph.patchids & 0x1F; + if (b_large_patch) + { + i = ph.patchids >> 16; //x + j = ph.patchids & 0xFFFF; //y + } + else + { + i = ph.patchids >> 5; //x + j = ph.patchids & 0x1F; //y + } if ((i >= mPatchesPerEdge) || (j >= mPatchesPerEdge)) { diff --git a/linden/indra/newview/llviewermessage.cpp b/linden/indra/newview/llviewermessage.cpp index 9ebfd04..4de4768 100755 --- a/linden/indra/newview/llviewermessage.cpp +++ b/linden/indra/newview/llviewermessage.cpp @@ -3531,6 +3531,17 @@ void process_teleport_finish(LLMessageSystem* msg, void**) U32 teleport_flags; msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags); + U32 region_size_x = 256; + msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y); + + //and a little hack for Second Life compatibility + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; + } std::string seedCap; msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seedCap); @@ -3550,7 +3561,7 @@ void process_teleport_finish(LLMessageSystem* msg, void**) // Viewer trusts the simulator. gMessageSystem->enableCircuit(sim_host, TRUE); - LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host); + LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host, region_size_x, region_size_y); /* // send camera update to new region @@ -3866,9 +3877,21 @@ void process_crossed_region(LLMessageSystem* msg, void**) std::string seedCap; msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap); + U32 region_size_x = 256; + msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeY, region_size_y); + + //and a little hack for Second Life compatibility + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; + } + send_complete_agent_movement(sim_host); - LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host); + LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host, region_size_x, region_size_y); regionp->setSeedCapability(seedCap); // Tell the LightShare handler that we have changed regions. diff --git a/linden/indra/newview/llviewerparcelmgr.cpp b/linden/indra/newview/llviewerparcelmgr.cpp index 630da54..abe0e9f 100644 --- a/linden/indra/newview/llviewerparcelmgr.cpp +++ b/linden/indra/newview/llviewerparcelmgr.cpp @@ -137,6 +137,18 @@ LLViewerParcelMgr::LLViewerParcelMgr() mHoverParcel = new LLParcel(); mCollisionParcel = new LLParcel(); + mBlockedImage = gImageList.getImageFromFile("noentrylines.j2c"); + mPassImage = gImageList.getImageFromFile("noentrypasslines.j2c"); + + init(256); +} + +//moved this stuff out of the constructor and into a function that we can call again after we get the region size. +//LLViewerParcelMgr needs to be changed so we either get an instance per region, or it handles various region sizes +//on a single grid properly - Patrick Sapinski (2/10/2011) +void LLViewerParcelMgr::init(F32 region_size) +{ + mParcelsPerEdge = S32( REGION_WIDTH_METERS / PARCEL_GRID_STEP_METERS ); mHighlightSegments = new U8[(mParcelsPerEdge+1)*(mParcelsPerEdge+1)]; resetSegments(mHighlightSegments); @@ -144,10 +156,9 @@ LLViewerParcelMgr::LLViewerParcelMgr() mCollisionSegments = new U8[(mParcelsPerEdge+1)*(mParcelsPerEdge+1)]; resetSegments(mCollisionSegments); - mBlockedImage = gImageList.getImageFromFile("noentrylines.j2c"); - mPassImage = gImageList.getImageFromFile("noentrypasslines.j2c"); - - S32 overlay_size = mParcelsPerEdge * mParcelsPerEdge / PARCEL_OVERLAY_CHUNKS; + S32 mParcelOverLayChunks = region_size * region_size / (128 * 128); + + S32 overlay_size = mParcelsPerEdge * mParcelsPerEdge / mParcelOverLayChunks; sPackedOverlay = new U8[overlay_size]; mAgentParcelOverlay = new U8[mParcelsPerEdge * mParcelsPerEdge]; @@ -1351,8 +1362,7 @@ void LLViewerParcelMgr::processParcelOverlay(LLMessageSystem *msg, void **user) return; } - S32 parcels_per_edge = LLViewerParcelMgr::getInstance()->mParcelsPerEdge; - S32 expected_size = parcels_per_edge * parcels_per_edge / PARCEL_OVERLAY_CHUNKS; + S32 expected_size = 1024; //parcels_per_edge * parcels_per_edge / PARCEL_OVERLAY_CHUNKS; if (packed_overlay_size != expected_size) { llwarns << "Got parcel overlay size " << packed_overlay_size diff --git a/linden/indra/newview/llviewerparcelmgr.h b/linden/indra/newview/llviewerparcelmgr.h index 9bf6096..dcdea3c 100644 --- a/linden/indra/newview/llviewerparcelmgr.h +++ b/linden/indra/newview/llviewerparcelmgr.h @@ -82,6 +82,8 @@ public: LLViewerParcelMgr(); ~LLViewerParcelMgr(); + void init(F32 region_size); + static void cleanupGlobals(); BOOL selectionEmpty() const; diff --git a/linden/indra/newview/llviewerparceloverlay.cpp b/linden/indra/newview/llviewerparceloverlay.cpp index 0bcd8f3..a31f153 100644 --- a/linden/indra/newview/llviewerparceloverlay.cpp +++ b/linden/indra/newview/llviewerparceloverlay.cpp @@ -58,6 +58,7 @@ const U8 OVERLAY_IMG_COMPONENTS = 4; LLViewerParcelOverlay::LLViewerParcelOverlay(LLViewerRegion* region, F32 region_width_meters) : mRegion( region ), mParcelGridsPerEdge( S32( region_width_meters / PARCEL_GRID_STEP_METERS ) ), + mRegionSize(S32(region_width_meters)), mDirty( FALSE ), mTimeSinceLastUpdate(), mOverlayTextureIdx(-1), @@ -299,7 +300,8 @@ void LLViewerParcelOverlay::uncompressLandOverlay(S32 chunk, U8 *packed_overlay) { // Unpack the message data into the ownership array S32 size = mParcelGridsPerEdge * mParcelGridsPerEdge; - S32 chunk_size = size / PARCEL_OVERLAY_CHUNKS; + S32 mParcelOverLayChunks = mRegionSize * mRegionSize / (128 * 128); + S32 chunk_size = size / mParcelOverLayChunks; memcpy(mOwnership + chunk*chunk_size, packed_overlay, chunk_size); /*Flawfinder: ignore*/ diff --git a/linden/indra/newview/llviewerparceloverlay.h b/linden/indra/newview/llviewerparceloverlay.h index 9bed1dd..d3b5980 100644 --- a/linden/indra/newview/llviewerparceloverlay.h +++ b/linden/indra/newview/llviewerparceloverlay.h @@ -98,6 +98,7 @@ private: LLViewerRegion* mRegion; S32 mParcelGridsPerEdge; + S32 mRegionSize; LLPointer mTexture; LLPointer mImageRaw; diff --git a/linden/indra/newview/llviewerregion.cpp b/linden/indra/newview/llviewerregion.cpp index a8047b8..4186362 100644 --- a/linden/indra/newview/llviewerregion.cpp +++ b/linden/indra/newview/llviewerregion.cpp @@ -65,6 +65,7 @@ #include "llvoclouds.h" #include "llworld.h" #include "llspatialpartition.h" +#include "llviewerparcelmgr.h" // Viewer object cache version, change if object update // format changes. JC @@ -199,6 +200,8 @@ LLViewerRegion::LLViewerRegion(const U64 &handle, if (!gNoRender) { mParcelOverlay = new LLViewerParcelOverlay(this, region_width_meters); + //Re-init the parcel mgr for this sim + LLViewerParcelMgr::getInstance()->init(region_width_meters); } else { diff --git a/linden/indra/newview/llvlmanager.cpp b/linden/indra/newview/llvlmanager.cpp index 177093c..68b4d7b 100644 --- a/linden/indra/newview/llvlmanager.cpp +++ b/linden/indra/newview/llvlmanager.cpp @@ -57,21 +57,23 @@ LLVLManager::~LLVLManager() void LLVLManager::addLayerData(LLVLData *vl_datap, const S32 mesg_size) { - if (LAND_LAYER_CODE == vl_datap->mType) - { - mLandBits += mesg_size * 8; - } - else if (WIND_LAYER_CODE == vl_datap->mType) - { - mWindBits += mesg_size * 8; - } - else if (CLOUD_LAYER_CODE == vl_datap->mType) - { - mCloudBits += mesg_size * 8; - } - else - { - llerrs << "Unknown layer type!" << (S32)vl_datap->mType << llendl; + if (LAND_LAYER_CODE == vl_datap->mType || + AURORA_LAND_LAYER_CODE == vl_datap->mType) + { + mLandBits += mesg_size * 8; + } + else if (WIND_LAYER_CODE == vl_datap->mType || + AURORA_WIND_LAYER_CODE == vl_datap->mType) + { + mWindBits += mesg_size * 8; + } + else if (CLOUD_LAYER_CODE == vl_datap->mType) + { + mCloudBits += mesg_size * 8; + } + else + { + llerrs << "Unknown layer type!" << (S32)vl_datap->mType << llendl; } mPacketData.put(vl_datap); @@ -90,18 +92,23 @@ void LLVLManager::unpackData(const S32 num_packets) LLGroupHeader goph; decode_patch_group_header(bit_pack, &goph); - if (LAND_LAYER_CODE == datap->mType) - { - datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, FALSE); - } - else if (WIND_LAYER_CODE == datap->mType) - { - datap->mRegionp->mWind.decompress(bit_pack, &goph); - - } - else if (CLOUD_LAYER_CODE == datap->mType) - { - datap->mRegionp->mCloudLayer.decompress(bit_pack, &goph); + if (LAND_LAYER_CODE == datap->mType) + { + datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, FALSE); + } + else if (AURORA_LAND_LAYER_CODE == datap->mType) + { + datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, TRUE); + } + else if (WIND_LAYER_CODE == datap->mType || + AURORA_WIND_LAYER_CODE == datap->mType) + { + datap->mRegionp->mWind.decompress(bit_pack, &goph); + } + else if (CLOUD_LAYER_CODE == datap->mType || + AURORA_CLOUD_LAYER_CODE == datap->mType) + { + datap->mRegionp->mCloudLayer.decompress(bit_pack, &goph); } } diff --git a/linden/indra/newview/llvowater.cpp b/linden/indra/newview/llvowater.cpp index c66295a..8af9e4a 100644 --- a/linden/indra/newview/llvowater.cpp +++ b/linden/indra/newview/llvowater.cpp @@ -74,7 +74,7 @@ LLVOWater::LLVOWater(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regi { // Terrain must draw during selection passes so it can block objects behind it. mbCanSelect = FALSE; - setScale(LLVector3(256.f, 256.f, 0.f)); // Hack for setting scale for bounding boxes/visibility. + setScale(LLVector3(mRegionp->getWidth(), mRegionp->getWidth(), 0.f)); // Hack for setting scale for bounding boxes/visibility. mUseTexture = TRUE; mIsEdgePatch = FALSE; diff --git a/linden/indra/newview/llwind.cpp b/linden/indra/newview/llwind.cpp index ae98bea..3dcbdf6 100644 --- a/linden/indra/newview/llwind.cpp +++ b/linden/indra/newview/llwind.cpp @@ -120,12 +120,12 @@ void LLWind::decompress(LLBitPack &bitpack, LLGroupHeader *group_headerp) set_group_of_patch_header(group_headerp); // X component - decode_patch_header(bitpack, &patch_header); + decode_patch_header(bitpack, &patch_header, FALSE); decode_patch(bitpack, buffer); decompress_patch(mVelX, buffer, &patch_header); // Y component - decode_patch_header(bitpack, &patch_header); + decode_patch_header(bitpack, &patch_header, FALSE); decode_patch(bitpack, buffer); decompress_patch(mVelY, buffer, &patch_header); diff --git a/linden/indra/newview/llworld.cpp b/linden/indra/newview/llworld.cpp index 7866bf8..525195d 100644 --- a/linden/indra/newview/llworld.cpp +++ b/linden/indra/newview/llworld.cpp @@ -80,12 +80,12 @@ const S32 WORLD_PATCH_SIZE = 16; extern LLColor4U MAX_WATER_COLOR; -const U32 LLWorld::mWidth = 256; +U32 LLWorld::mWidth = 256; // meters/point, therefore mWidth * mScale = meters per edge const F32 LLWorld::mScale = 1.f; -const F32 LLWorld::mWidthInMeters = mWidth * mScale; +F32 LLWorld::mWidthInMeters = mWidth * mScale; // // Functions @@ -140,7 +140,7 @@ F32 LLWorld::getRegionMaxHeight() const return gHippoLimits->getMaxHeight(); } -LLViewerRegion* LLWorld::addRegion(const U64 ®ion_handle, const LLHost &host) +LLViewerRegion* LLWorld::addRegion(const U64 ®ion_handle, const LLHost &host, const U32 ®ion_size_x, const U32 ®ion_size_y) { LLMemType mt(LLMemType::MTYPE_REGIONS); @@ -172,9 +172,11 @@ LLViewerRegion* LLWorld::addRegion(const U64 ®ion_handle, const LLHost &host) U32 iindex = 0; U32 jindex = 0; + mWidth = region_size_x; + mWidthInMeters = mWidth * mScale; from_region_handle(region_handle, &iindex, &jindex); - S32 x = (S32)(iindex/mWidth); - S32 y = (S32)(jindex/mWidth); + S32 x = (S32)(iindex/256); + S32 y = (S32)(jindex/256); llinfos << "Adding new region (" << x << ":" << y << ")" << llendl; llinfos << "Host: " << host << llendl; @@ -902,7 +904,7 @@ void LLWorld::updateWaterObjects() } // Region width in meters. - S32 const rwidth = (S32)REGION_WIDTH_U32; + S32 const rwidth = (S32)getRegionWidthInMeters(); // The distance we might see into the void // when standing on the edge of a region, in meters. @@ -1256,9 +1258,20 @@ void process_enable_simulator(LLMessageSystem *msg, void **user_data) // which simulator should we modify? LLHost sim(ip_u32, port); + U32 region_size_x = 256; + msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeY, region_size_y); + + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; + } + // Viewer trusts the simulator. msg->enableCircuit(sim, TRUE); - LLWorld::getInstance()->addRegion(handle, sim); + LLWorld::getInstance()->addRegion(handle, sim, region_size_x, region_size_y); // give the simulator a message it can use to get ip and port llinfos << "simulator_enable() Enabling " << sim << " with code " << msg->getOurCircuitCode() << llendl; diff --git a/linden/indra/newview/llworld.h b/linden/indra/newview/llworld.h index 964729d..5dbef6d 100644 --- a/linden/indra/newview/llworld.h +++ b/linden/indra/newview/llworld.h @@ -71,7 +71,7 @@ public: LLWorld(); void destroyClass(); - LLViewerRegion* addRegion(const U64 ®ion_handle, const LLHost &host); + LLViewerRegion* addRegion(const U64 ®ion_handle, const LLHost &host, const U32 ®ion_size_x, const U32 ®ion_size_y); // safe to call if already present, does the "right thing" if // hosts are same, or if hosts are different, etc... void removeRegion(const LLHost &host); @@ -171,12 +171,12 @@ private: region_list_t mCulledRegionList; // Number of points on edge - static const U32 mWidth; + static U32 mWidth; // meters/point, therefore mWidth * mScale = meters per edge static const F32 mScale; - static const F32 mWidthInMeters; + static F32 mWidthInMeters; F32 mLandFarClip; // Far clip distance for land. LLPatchVertexArray mLandPatch; diff --git a/linden/indra/newview/llworldmap.cpp b/linden/indra/newview/llworldmap.cpp index 3ada36f..ead72fa 100644 --- a/linden/indra/newview/llworldmap.cpp +++ b/linden/indra/newview/llworldmap.cpp @@ -237,16 +237,27 @@ LLSimInfo* LLWorldMap::simInfoFromPosGlobal(const LLVector3d& pos_global) return simInfoFromHandle(handle); } -LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 handle) +LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 findhandle) { - sim_info_map_t::iterator it = mSimInfoMap.find(handle); - if (it != mSimInfoMap.end()) - { - LLSimInfo* sim_info = (*it).second; - if (sim_info) - { - return sim_info; - } + std::map::const_iterator it; + for (it = LLWorldMap::getInstance()->mSimInfoMap.begin(); it != LLWorldMap::getInstance()->mSimInfoMap.end(); ++it) + { + const U64 handle = (*it).first; + LLSimInfo* info = (*it).second; + if(handle == findhandle) + { + return info; + } + U32 x = 0, y = 0; + from_region_handle(findhandle, &x, &y); + U32 checkRegionX, checkRegionY; + from_region_handle(handle, &checkRegionX, &checkRegionY); + + if(x > checkRegionX && x < (checkRegionX + info->msizeX) && + y > checkRegionY && y < (checkRegionY + info->msizeY)) + { + return info; + } } return NULL; } diff --git a/linden/indra/newview/llworldmap.h b/linden/indra/newview/llworldmap.h index b7089f3..6725f91 100644 --- a/linden/indra/newview/llworldmap.h +++ b/linden/indra/newview/llworldmap.h @@ -81,6 +81,8 @@ public: public: U64 mHandle; + S32 msizeX; + S32 msizeY; std::string mName; F64 mAgentsUpdateTime; diff --git a/linden/indra/newview/llworldmapview.cpp b/linden/indra/newview/llworldmapview.cpp index 443ee74..51de598 100644 --- a/linden/indra/newview/llworldmapview.cpp +++ b/linden/indra/newview/llworldmapview.cpp @@ -471,8 +471,8 @@ void LLWorldMapView::draw() // When the view isn't panned, 0,0 = center of rectangle F32 bottom = sPanY + half_height + relative_y; F32 left = sPanX + half_width + relative_x; - F32 top = bottom + sMapScale ; - F32 right = left + sMapScale ; + F32 top = bottom+ (sMapScale * info->msizeY / REGION_WIDTH_METERS); + F32 right = left + (sMapScale * info->msizeY / REGION_WIDTH_METERS); // Switch to world map texture (if available for this region) if either: // 1. Tiles are zoomed out small enough, or @@ -567,17 +567,21 @@ void LLWorldMapView::draw() center_global.mdV[VX] += 128.0; center_global.mdV[VY] += 128.0; - S32 draw_size = llround(sMapScale); + S32 x_draw_size = llround(sMapScale); + S32 y_draw_size = llround(sMapScale); + x_draw_size *= info->msizeX / REGION_WIDTH_METERS; + y_draw_size *= info->msizeY / REGION_WIDTH_METERS; + if (simimage != NULL) { simimage->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP); - simimage->setKnownDrawSize(llround(draw_size * LLUI::sGLScaleFactor.mV[VX]), llround(draw_size * LLUI::sGLScaleFactor.mV[VY])); + simimage->setKnownDrawSize(llround(x_draw_size * LLUI::sGLScaleFactor.mV[VX]), llround(y_draw_size * LLUI::sGLScaleFactor.mV[VY])); } if (overlayimage != NULL) { overlayimage->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP); - overlayimage->setKnownDrawSize(llround(draw_size * LLUI::sGLScaleFactor.mV[VX]), llround(draw_size * LLUI::sGLScaleFactor.mV[VY])); + overlayimage->setKnownDrawSize(llround(x_draw_size * LLUI::sGLScaleFactor.mV[VX]), llround(y_draw_size * LLUI::sGLScaleFactor.mV[VY])); } // LLTextureView::addDebugImage(simimage); -- cgit v1.1 From 44aecbf4eca7c2d94ed88f11dedd237e93b01010 Mon Sep 17 00:00:00 2001 From: RevolutionSmythe Date: Fri, 18 Mar 2011 19:26:19 -0500 Subject: Fix setting the viewer offset time from OpenRegionSettings, and also have it show what UTC offset it is representing in the time bar. --- linden/indra/llcommon/lltimer.cpp | 6 +++--- linden/indra/newview/kowopenregionsettings.cpp | 6 +++++- linden/indra/newview/viewertime.cpp | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/linden/indra/llcommon/lltimer.cpp b/linden/indra/llcommon/lltimer.cpp index 2d283ec..b825c1e 100644 --- a/linden/indra/llcommon/lltimer.cpp +++ b/linden/indra/llcommon/lltimer.cpp @@ -529,14 +529,14 @@ struct tm* utc_to_offset_time(time_t utc_time, S32 offset, BOOL DST) { if (DST) { - //Subtract one then - offset--; + //Add one then + offset++; } // We subtract off the PST/PDT offset _before_ getting // "UTC" time, because this will handle wrapping around // for 5 AM UTC -> 10 PM PDT of the previous day. - utc_time -= offset * MIN_PER_HOUR * SEC_PER_MIN; + utc_time -= (-1 * offset) * MIN_PER_HOUR * SEC_PER_MIN; // Internal buffer to PST/PDT (see above) struct tm* internal_time = gmtime(&utc_time); diff --git a/linden/indra/newview/kowopenregionsettings.cpp b/linden/indra/newview/kowopenregionsettings.cpp index ef14d2a..0c4bb38 100644 --- a/linden/indra/newview/kowopenregionsettings.cpp +++ b/linden/indra/newview/kowopenregionsettings.cpp @@ -37,6 +37,7 @@ #include "llfloaterregioninfo.h" #include "llfloaterworldmap.h" #include "llvoiceclient.h" +#include "viewertime.h" //DEBUG includes //#include "llsdserialize.h" //LLSDNotationStreamer - for dumping LLSD to string @@ -150,12 +151,15 @@ class OpenRegionInfoUpdate : public LLHTTPNode } if ( body.has("OffsetOfUTC") ) { - gSavedSettings.setS32("TimeOffset", body["OffsetOfUTC"].asReal()); + gSavedSettings.setS32("TimeOffset", body["OffsetOfUTC"].asInteger()); gSavedSettings.setBOOL("UseTimeOffset", true); + ViewerTime::sUseTimeOffset = true; + ViewerTime::sTimeOffset = gSavedSettings.getS32("TimeOffset"); } if ( body.has("OffsetOfUTCDST") ) { gSavedSettings.setBOOL("TimeOffsetDST", body["OffsetOfUTCDST"].asInteger() == 1 ? TRUE : FALSE); + ViewerTime::sTimeOffsetDST = gSavedSettings.getBOOL("TimeOffsetDST"); } if ( body.has("RenderWater") ) { diff --git a/linden/indra/newview/viewertime.cpp b/linden/indra/newview/viewertime.cpp index 06436b6..8a65a23 100644 --- a/linden/indra/newview/viewertime.cpp +++ b/linden/indra/newview/viewertime.cpp @@ -27,7 +27,8 @@ * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ - + +#include #include "llviewerprecompiledheaders.h" #include "llappviewer.h" // for gPacificDaylightTime @@ -129,10 +130,19 @@ void ViewerTime::refresh() if (hour == 0) hour = 12; } - mTZ = "PST"; - if (gPacificDaylightTime) + if (sUseTimeOffset) + { + std::stringstream myString; + myString << "UTC " << sTimeOffset; + mTZ = myString.str(); + } + else { - mTZ = "PDT"; + mTZ = "PST"; + if (gPacificDaylightTime) + { + mTZ = "PDT"; + } } } else // just UTC -- cgit v1.1 From 7df2707d9a70028b85eef57ae09bc2062db51f77 Mon Sep 17 00:00:00 2001 From: RevolutionSmythe Date: Fri, 18 Mar 2011 20:41:22 -0500 Subject: Fix a bug that only occurs when not running in a debugger. --- linden/indra/newview/llviewerparcelmgr.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linden/indra/newview/llviewerparcelmgr.cpp b/linden/indra/newview/llviewerparcelmgr.cpp index abe0e9f..7373c3f 100644 --- a/linden/indra/newview/llviewerparcelmgr.cpp +++ b/linden/indra/newview/llviewerparcelmgr.cpp @@ -148,8 +148,7 @@ LLViewerParcelMgr::LLViewerParcelMgr() //on a single grid properly - Patrick Sapinski (2/10/2011) void LLViewerParcelMgr::init(F32 region_size) { - - mParcelsPerEdge = S32( REGION_WIDTH_METERS / PARCEL_GRID_STEP_METERS ); + mParcelsPerEdge = S32( region_size / PARCEL_GRID_STEP_METERS ); mHighlightSegments = new U8[(mParcelsPerEdge+1)*(mParcelsPerEdge+1)]; resetSegments(mHighlightSegments); -- cgit v1.1 From e67e3f216fdb0868d05c35f105dd83c5358dd3b0 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 18 Mar 2011 21:05:23 -0500 Subject: Fixed bad line endings (CRLF) in many files. Windows users, please set "autocrlf = input" or "autocrlf = true" in your .git/config [core] section to avoid this in the future. --- linden/indra/llcommon/indra_constants.h | 10 +- linden/indra/llinventory/llparcel.h | 2 +- linden/indra/llmessage/message_prehash.cpp | 4 +- linden/indra/llmessage/message_prehash.h | 4 +- linden/indra/llmessage/patch_code.cpp | 10 +- linden/indra/llwindow/glh/glh_linear.h | 3242 +++++------ linden/indra/newview/llfloaterregioninfo.cpp | 6892 ++++++++++++------------ linden/indra/newview/llfloatertos.cpp | 610 +-- linden/indra/newview/llmaniptranslate.cpp | 2 +- linden/indra/newview/llmapresponders.cpp | 8 +- linden/indra/newview/llstartup.cpp | 22 +- linden/indra/newview/llsurface.cpp | 18 +- linden/indra/newview/llviewermessage.cpp | 40 +- linden/indra/newview/llviewerparcelmgr.cpp | 26 +- linden/indra/newview/llviewerparcelmgr.h | 4 +- linden/indra/newview/llviewerparceloverlay.cpp | 6 +- linden/indra/newview/llviewerparceloverlay.h | 2 +- linden/indra/newview/llviewerregion.cpp | 2 +- linden/indra/newview/llvlmanager.cpp | 68 +- linden/indra/newview/llvowater.cpp | 2 +- linden/indra/newview/llworld.cpp | 26 +- linden/indra/newview/llworldmap.cpp | 38 +- linden/indra/newview/llworldmap.h | 4 +- linden/indra/newview/llworldmapview.cpp | 14 +- linden/indra/newview/viewertime.cpp | 2 +- 25 files changed, 5529 insertions(+), 5529 deletions(-) diff --git a/linden/indra/llcommon/indra_constants.h b/linden/indra/llcommon/indra_constants.h index ae1e04a..b765d4d 100644 --- a/linden/indra/llcommon/indra_constants.h +++ b/linden/indra/llcommon/indra_constants.h @@ -151,11 +151,11 @@ const U32 PORT_DISCOVERY_RANGE_MAX = PORT_DISCOVERY_RANGE_MIN + 50; const char LAND_LAYER_CODE = 'L'; const char WATER_LAYER_CODE = 'W'; const char WIND_LAYER_CODE = '7'; -const char CLOUD_LAYER_CODE = '8'; - -// Extended land layer for Aurora Sim -const char AURORA_LAND_LAYER_CODE = 'M'; -const char AURORA_WIND_LAYER_CODE = '9'; +const char CLOUD_LAYER_CODE = '8'; + +// Extended land layer for Aurora Sim +const char AURORA_LAND_LAYER_CODE = 'M'; +const char AURORA_WIND_LAYER_CODE = '9'; const char AURORA_CLOUD_LAYER_CODE = ':'; // keys diff --git a/linden/indra/llinventory/llparcel.h b/linden/indra/llinventory/llparcel.h index 366f589..f102ec4 100644 --- a/linden/indra/llinventory/llparcel.h +++ b/linden/indra/llinventory/llparcel.h @@ -66,7 +66,7 @@ const S32 PARCEL_PASS_PRICE_DEFAULT = 10; const F32 PARCEL_PASS_HOURS_DEFAULT = 1.f; // Number of "chunks" in which parcel overlay data is sent -// Chunk 0 = southern rows, entire width +// Chunk 0 = southern rows, entire width // NOTE: NOT USABLE FOR VAR SIZED REGIONS! const S32 PARCEL_OVERLAY_CHUNKS = 4; diff --git a/linden/indra/llmessage/message_prehash.cpp b/linden/indra/llmessage/message_prehash.cpp index a8b021f..78b9d07 100644 --- a/linden/indra/llmessage/message_prehash.cpp +++ b/linden/indra/llmessage/message_prehash.cpp @@ -586,8 +586,8 @@ char* _PREHASH_NotecardItemID = LLMessageStringTable::getInstance()->getString(" char* _PREHASH_LastName = LLMessageStringTable::getInstance()->getString("LastName"); char* _PREHASH_From = LLMessageStringTable::getInstance()->getString("From"); char* _PREHASH_RoleChange = LLMessageStringTable::getInstance()->getString("RoleChange"); -char* _PREHASH_Port = LLMessageStringTable::getInstance()->getString("Port"); -char* _PREHASH_RegionSizeX = LLMessageStringTable::getInstance()->getString("RegionSizeX"); +char* _PREHASH_Port = LLMessageStringTable::getInstance()->getString("Port"); +char* _PREHASH_RegionSizeX = LLMessageStringTable::getInstance()->getString("RegionSizeX"); char* _PREHASH_RegionSizeY = LLMessageStringTable::getInstance()->getString("RegionSizeY"); char* _PREHASH_MemberTitle = LLMessageStringTable::getInstance()->getString("MemberTitle"); char* _PREHASH_LogParcelChanges = LLMessageStringTable::getInstance()->getString("LogParcelChanges"); diff --git a/linden/indra/llmessage/message_prehash.h b/linden/indra/llmessage/message_prehash.h index adf27ee..64544dd 100644 --- a/linden/indra/llmessage/message_prehash.h +++ b/linden/indra/llmessage/message_prehash.h @@ -586,8 +586,8 @@ extern char * _PREHASH_NotecardItemID; extern char * _PREHASH_LastName; extern char * _PREHASH_From; extern char * _PREHASH_RoleChange; -extern char * _PREHASH_Port; -extern char * _PREHASH_RegionSizeX; +extern char * _PREHASH_Port; +extern char * _PREHASH_RegionSizeX; extern char * _PREHASH_RegionSizeY; extern char * _PREHASH_MemberTitle; extern char * _PREHASH_LogParcelChanges; diff --git a/linden/indra/llmessage/patch_code.cpp b/linden/indra/llmessage/patch_code.cpp index 4b4313d..0cf8d2e 100644 --- a/linden/indra/llmessage/patch_code.cpp +++ b/linden/indra/llmessage/patch_code.cpp @@ -280,11 +280,11 @@ void decode_patch_header(LLBitPack &bitpack, LLPatchHeader *ph, BOOL b_large_pat bitpack.bitUnpack(&(ret[1]), 8); bitpack.bitUnpack(&(ret[0]), 2); #else - if (b_large_patch) - bitpack.bitUnpack((U8 *)&retvalu32, 32); - else - bitpack.bitUnpack((U8 *)&retvalu32, 10); -#endif + if (b_large_patch) + bitpack.bitUnpack((U8 *)&retvalu32, 32); + else + bitpack.bitUnpack((U8 *)&retvalu32, 10); +#endif ph->patchids = retvalu32; gWordBits = (ph->quant_wbits & 0xf) + 2; diff --git a/linden/indra/llwindow/glh/glh_linear.h b/linden/indra/llwindow/glh/glh_linear.h index bb59d7e..04ae1bd 100755 --- a/linden/indra/llwindow/glh/glh_linear.h +++ b/linden/indra/llwindow/glh/glh_linear.h @@ -1,1621 +1,1621 @@ -/* - glh - is a platform-indepenedent C++ OpenGL helper library - - - Copyright (c) 2000 Cass Everitt - Copyright (c) 2000 NVIDIA Corporation - All rights reserved. - - Redistribution and use in source and binary forms, with or - without modification, are permitted provided that the following - conditions are met: - - * Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - - * The names of contributors to this software may not be used - to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - - Cass Everitt - cass@r3.nu -*/ - -/* -glh_linear.h -*/ - -// Author: Cass W. Everitt - -#ifndef GLH_LINEAR_H -#define GLH_LINEAR_H - -#include -#include -#include - -// only supports float for now... -#define GLH_REAL_IS_FLOAT - -#ifdef GLH_REAL_IS_FLOAT -# define GLH_REAL float -# define GLH_REAL_NAMESPACE ns_float -#endif - -#define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 - -#define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) -#define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) -#define GLH_ZERO GLH_REAL(0.0) -#define GLH_ONE GLH_REAL(1.0) -#define GLH_TWO GLH_REAL(2.0) -#define GLH_EPSILON GLH_REAL(10e-6) -#define GLH_PI GLH_REAL(3.1415926535897932384626433832795) - -#define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) - -namespace glh -{ - - inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } - inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } - - // forward declarations for friend template functions. - template class vec; - - // forward declarations for friend template functions. - template - bool operator == ( const vec & v1, const vec & v2 ); - - // forward declarations for friend template functions. - template - bool operator != ( const vec & v1, const vec & v2 ); - - template - class vec - { - public: - int size() const { return N; } - - vec(const T & t = T()) - { for(int i = 0; i < N; i++) v[i] = t; } - vec(const T * tp) - { for(int i = 0; i < N; i++) v[i] = tp[i]; } - - const T * get_value() const - { return v; } - - - T dot( const vec & rhs ) const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; - return r; - } - - T length() const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*v[i]; - return T(sqrt(r)); - } - - T square_norm() const - { - T r = 0; - for(int i = 0; i < N; i++) r += v[i]*v[i]; - return r; - } - - void negate() - { for(int i = 0; i < N; i++) v[i] = -v[i]; } - - - T normalize() - { - T sum(0); - for(int i = 0; i < N; i++) - sum += v[i]*v[i]; - sum = T(sqrt(sum)); - if (sum > GLH_EPSILON) - for(int i = 0; i < N; i++) - v[i] /= sum; - return sum; - } - - - vec & set_value( const T * rhs ) - { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } - - T & operator [] ( int i ) - { return v[i]; } - - const T & operator [] ( int i ) const - { return v[i]; } - - vec & operator *= ( T d ) - { for(int i = 0; i < N; i++) v[i] *= d; return *this;} - - vec & operator *= ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} - - vec & operator /= ( T d ) - { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} - - vec & operator += ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} - - vec & operator -= ( const vec & u ) - { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} - - - vec operator - () const - { vec rv = v; rv.negate(); return rv; } - - vec operator + ( const vec &v) const - { vec rt(*this); return rt += v; } - - vec operator - ( const vec &v) const - { vec rt(*this); return rt -= v; } - - vec operator * ( T d) const - { vec rt(*this); return rt *= d; } - - friend bool operator == <> ( const vec &v1, const vec &v2 ); - friend bool operator != <> ( const vec &v1, const vec &v2 ); - - - //protected: - T v[N]; - }; - - - - // vector friend operators - - template inline - vec operator * ( const vec & b, T d ) - { - vec rt(b); - return rt *= d; - } - - template inline - vec operator * ( T d, const vec & b ) - { return b*d; } - - template inline - vec operator * ( const vec & b, const vec & d ) - { - vec rt(b); - return rt *= d; - } - - template inline - vec operator / ( const vec & b, T d ) - { vec rt(b); return rt /= d; } - - template inline - vec operator + ( const vec & v1, const vec & v2 ) - { vec rt(v1); return rt += v2; } - - template inline - vec operator - ( const vec & v1, const vec & v2 ) - { vec rt(v1); return rt -= v2; } - - - template inline - bool operator == ( const vec & v1, const vec & v2 ) - { - for(int i = 0; i < N; i++) - if(v1.v[i] != v2.v[i]) - return false; - return true; - } - - template inline - bool operator != ( const vec & v1, const vec & v2 ) - { return !(v1 == v2); } - - - typedef vec<3,unsigned char> vec3ub; - typedef vec<4,unsigned char> vec4ub; - - - - - - namespace GLH_REAL_NAMESPACE - { - typedef GLH_REAL real; - - class line; - class plane; - class matrix4; - class quaternion; - typedef quaternion rotation; - - class vec2 : public vec<2,real> - { - public: - vec2(const real & t = real()) : vec<2,real>(t) - {} - vec2(const vec<2,real> & t) : vec<2,real>(t) - {} - vec2(const real * tp) : vec<2,real>(tp) - {} - - vec2(real x, real y ) - { v[0] = x; v[1] = y; } - - void get_value(real & x, real & y) const - { x = v[0]; y = v[1]; } - - vec2 & set_value( const real & x, const real & y) - { v[0] = x; v[1] = y; return *this; } - - }; - - - class vec3 : public vec<3,real> - { - public: - vec3(const real & t = real()) : vec<3,real>(t) - {} - vec3(const vec<3,real> & t) : vec<3,real>(t) - {} - vec3(const real * tp) : vec<3,real>(tp) - {} - - vec3(real x, real y, real z) - { v[0] = x; v[1] = y; v[2] = z; } - - void get_value(real & x, real & y, real & z) const - { x = v[0]; y = v[1]; z = v[2]; } - - vec3 cross( const vec3 &rhs ) const - { - vec3 rt; - rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; - rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; - rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; - return rt; - } - - vec3 & set_value( const real & x, const real & y, const real & z) - { v[0] = x; v[1] = y; v[2] = z; return *this; } - - }; - - - class vec4 : public vec<4,real> - { - public: - vec4(const real & t = real()) : vec<4,real>(t) - {} - vec4(const vec<4,real> & t) : vec<4,real>(t) - {} - - vec4(const vec<3,real> & t, real fourth) - - { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } - vec4(const real * tp) : vec<4,real>(tp) - {} - vec4(real x, real y, real z, real w) - { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } - - void get_value(real & x, real & y, real & z, real & w) const - { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } - - vec4 & set_value( const real & x, const real & y, const real & z, const real & w) - { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } - }; - - inline - vec3 homogenize(const vec4 & v) - { - vec3 rt; - assert(v.v[3] != GLH_ZERO); - rt.v[0] = v.v[0]/v.v[3]; - rt.v[1] = v.v[1]/v.v[3]; - rt.v[2] = v.v[2]/v.v[3]; - return rt; - } - - - - class line - { - public: - - line() - { set_value(vec3(0,0,0),vec3(0,0,1)); } - - line( const vec3 & p0, const vec3 &p1) - { set_value(p0,p1); } - - void set_value( const vec3 &p0, const vec3 &p1) - { - position = p0; - direction = p1-p0; - direction.normalize(); - } - - bool get_closest_points(const line &line2, - vec3 &pointOnThis, - vec3 &pointOnThat) - { - - // quick check to see if parallel -- if so, quit. - if(fabs(direction.dot(line2.direction)) == 1.0) - return 0; - line l2 = line2; - - // Algorithm: Brian Jean - // - register real u; - register real v; - vec3 Vr = direction; - vec3 Vs = l2.direction; - register real Vr_Dot_Vs = Vr.dot(Vs); - register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); - vec3 C = l2.position - position; - register real C_Dot_Vr = C.dot(Vr); - register real C_Dot_Vs = C.dot(Vs); - - u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; - v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; - - pointOnThis = position; - pointOnThis += direction * u; - pointOnThat = l2.position; - pointOnThat += l2.direction * v; - - return 1; - } - - vec3 get_closest_point(const vec3 &point) - { - vec3 np = point - position; - vec3 rp = direction*direction.dot(np)+position; - return rp; - } - - const vec3 & get_position() const {return position;} - - const vec3 & get_direction() const {return direction;} - - //protected: - vec3 position; - vec3 direction; - }; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // matrix - - - class matrix4 - { - - public: - - matrix4() { make_identity(); } - - matrix4( real r ) - { set_value(r); } - - matrix4( real * m ) - { set_value(m); } - - matrix4( real a00, real a01, real a02, real a03, - real a10, real a11, real a12, real a13, - real a20, real a21, real a22, real a23, - real a30, real a31, real a32, real a33 ) - { - element(0,0) = a00; - element(0,1) = a01; - element(0,2) = a02; - element(0,3) = a03; - - element(1,0) = a10; - element(1,1) = a11; - element(1,2) = a12; - element(1,3) = a13; - - element(2,0) = a20; - element(2,1) = a21; - element(2,2) = a22; - element(2,3) = a23; - - element(3,0) = a30; - element(3,1) = a31; - element(3,2) = a32; - element(3,3) = a33; - } - - - void get_value( real * mp ) const - { - int c = 0; - for(int j=0; j < 4; j++) - for(int i=0; i < 4; i++) - mp[c++] = element(i,j); - } - - - const real * get_value() const - { return m; } - - void set_value( real * mp) - { - int c = 0; - for(int j=0; j < 4; j++) - for(int i=0; i < 4; i++) - element(i,j) = mp[c++]; - } - - void set_value( real r ) - { - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - element(i,j) = r; - } - - void make_identity() - { - element(0,0) = 1.0; - element(0,1) = 0.0; - element(0,2) = 0.0; - element(0,3) = 0.0; - - element(1,0) = 0.0; - element(1,1) = 1.0; - element(1,2) = 0.0; - element(1,3) = 0.0; - - element(2,0) = 0.0; - element(2,1) = 0.0; - element(2,2) = 1.0; - element(2,3) = 0.0; - - element(3,0) = 0.0; - element(3,1) = 0.0; - element(3,2) = 0.0; - element(3,3) = 1.0; - } - - - static matrix4 identity() - { - static matrix4 mident ( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 ); - return mident; - } - - - void set_scale( real s ) - { - element(0,0) = s; - element(1,1) = s; - element(2,2) = s; - } - - void set_scale( const vec3 & s ) - { - element(0,0) = s.v[0]; - element(1,1) = s.v[1]; - element(2,2) = s.v[2]; - } - - - void set_translate( const vec3 & t ) - { - element(0,3) = t.v[0]; - element(1,3) = t.v[1]; - element(2,3) = t.v[2]; - } - - void set_row(int r, const vec4 & t) - { - element(r,0) = t.v[0]; - element(r,1) = t.v[1]; - element(r,2) = t.v[2]; - element(r,3) = t.v[3]; - } - - void set_column(int c, const vec4 & t) - { - element(0,c) = t.v[0]; - element(1,c) = t.v[1]; - element(2,c) = t.v[2]; - element(3,c) = t.v[3]; - } - - - void get_row(int r, vec4 & t) const - { - t.v[0] = element(r,0); - t.v[1] = element(r,1); - t.v[2] = element(r,2); - t.v[3] = element(r,3); - } - - vec4 get_row(int r) const - { - vec4 v; get_row(r, v); - return v; - } - - void get_column(int c, vec4 & t) const - { - t.v[0] = element(0,c); - t.v[1] = element(1,c); - t.v[2] = element(2,c); - t.v[3] = element(3,c); - } - - vec4 get_column(int c) const - { - vec4 v; get_column(c, v); - return v; - } - - matrix4 inverse() const - { - matrix4 minv; - - real r1[8], r2[8], r3[8], r4[8]; - real *s[4], *tmprow; - - s[0] = &r1[0]; - s[1] = &r2[0]; - s[2] = &r3[0]; - s[3] = &r4[0]; - - register int i,j,p,jj; - for(i=0;i<4;i++) - { - for(j=0;j<4;j++) - { - s[i][j] = element(i,j); - if(i==j) s[i][j+4] = 1.0; - else s[i][j+4] = 0.0; - } - } - real scp[4]; - for(i=0;i<4;i++) - { - scp[i] = real(fabs(s[i][0])); - for(j=1;j<4;j++) - if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); - if(scp[i] == 0.0) return minv; // singular matrix! - } - - int pivot_to; - real scp_max; - for(i=0;i<4;i++) - { - // select pivot row - pivot_to = i; - scp_max = real(fabs(s[i][i]/scp[i])); - // find out which row should be on top - for(p=i+1;p<4;p++) - if(real(fabs(s[p][i]/scp[p])) > scp_max) - { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } - // Pivot if necessary - if(pivot_to != i) - { - tmprow = s[i]; - s[i] = s[pivot_to]; - s[pivot_to] = tmprow; - real tmpscp; - tmpscp = scp[i]; - scp[i] = scp[pivot_to]; - scp[pivot_to] = tmpscp; - } - - real mji; - // perform gaussian elimination - for(j=i+1;j<4;j++) - { - mji = s[j][i]/s[i][i]; - s[j][i] = 0.0; - for(jj=i+1;jj<8;jj++) - s[j][jj] -= mji*s[i][jj]; - } - } - if(s[3][3] == 0.0) return minv; // singular matrix! - - // - // Now we have an upper triangular matrix. - // - // x x x x | y y y y - // 0 x x x | y y y y - // 0 0 x x | y y y y - // 0 0 0 x | y y y y - // - // we'll back substitute to get the inverse - // - // 1 0 0 0 | z z z z - // 0 1 0 0 | z z z z - // 0 0 1 0 | z z z z - // 0 0 0 1 | z z z z - // - - real mij; - for(i=3;i>0;i--) - { - for(j=i-1;j > -1; j--) - { - mij = s[j][i]/s[i][i]; - for(jj=j+1;jj<8;jj++) - s[j][jj] -= mij*s[i][jj]; - } - } - - for(i=0;i<4;i++) - for(j=0;j<4;j++) - minv(i,j) = s[i][j+4] / s[i][i]; - - return minv; - } - - - matrix4 transpose() const - { - matrix4 mtrans; - - for(int i=0;i<4;i++) - for(int j=0;j<4;j++) - mtrans(i,j) = element(j,i); - return mtrans; - } - - matrix4 & mult_right( const matrix4 & b ) - { - matrix4 mt(*this); - set_value(real(0)); - - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - for(int c=0; c < 4; c++) - element(i,j) += mt(i,c) * b(c,j); - return *this; - } - - matrix4 & mult_left( const matrix4 & b ) - { - matrix4 mt(*this); - set_value(real(0)); - - for(int i=0; i < 4; i++) - for(int j=0; j < 4; j++) - for(int c=0; c < 4; c++) - element(i,j) += b(i,c) * mt(c,j); - return *this; - } - - // dst = M * src - void mult_matrix_vec( const vec3 &src, vec3 &dst ) const - { - real w = ( - src.v[0] * element(3,0) + - src.v[1] * element(3,1) + - src.v[2] * element(3,2) + - element(3,3) ); - - assert(w != GLH_ZERO); - - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) + - element(0,3) ) / w; - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) + - element(1,3) ) / w; - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) + - element(2,3) ) / w; - } - - void mult_matrix_vec( vec3 & src_and_dst) const - { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_vec_matrix( const vec3 &src, vec3 &dst ) const - { - real w = ( - src.v[0] * element(0,3) + - src.v[1] * element(1,3) + - src.v[2] * element(2,3) + - element(3,3) ); - - assert(w != GLH_ZERO); - - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) + - element(3,0) ) / w; - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) + - element(3,1) ) / w; - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) + - element(3,2) ) / w; - } - - - void mult_vec_matrix( vec3 & src_and_dst) const - { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } - - // dst = M * src - void mult_matrix_vec( const vec4 &src, vec4 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) + - src.v[3] * element(0,3)); - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) + - src.v[3] * element(1,3)); - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) + - src.v[3] * element(2,3)); - dst.v[3] = ( - src.v[0] * element(3,0) + - src.v[1] * element(3,1) + - src.v[2] * element(3,2) + - src.v[3] * element(3,3)); - } - - void mult_matrix_vec( vec4 & src_and_dst) const - { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_vec_matrix( const vec4 &src, vec4 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) + - src.v[3] * element(3,0)); - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) + - src.v[3] * element(3,1)); - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) + - src.v[3] * element(3,2)); - dst.v[3] = ( - src.v[0] * element(0,3) + - src.v[1] * element(1,3) + - src.v[2] * element(2,3) + - src.v[3] * element(3,3)); - } - - - void mult_vec_matrix( vec4 & src_and_dst) const - { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } - - - // dst = M * src - void mult_matrix_dir( const vec3 &src, vec3 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(0,1) + - src.v[2] * element(0,2) ) ; - dst.v[1] = ( - src.v[0] * element(1,0) + - src.v[1] * element(1,1) + - src.v[2] * element(1,2) ) ; - dst.v[2] = ( - src.v[0] * element(2,0) + - src.v[1] * element(2,1) + - src.v[2] * element(2,2) ) ; - } - - - void mult_matrix_dir( vec3 & src_and_dst) const - { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } - - - // dst = src * M - void mult_dir_matrix( const vec3 &src, vec3 &dst ) const - { - dst.v[0] = ( - src.v[0] * element(0,0) + - src.v[1] * element(1,0) + - src.v[2] * element(2,0) ) ; - dst.v[1] = ( - src.v[0] * element(0,1) + - src.v[1] * element(1,1) + - src.v[2] * element(2,1) ) ; - dst.v[2] = ( - src.v[0] * element(0,2) + - src.v[1] * element(1,2) + - src.v[2] * element(2,2) ) ; - } - - - void mult_dir_matrix( vec3 & src_and_dst) const - { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } - - - real & operator () (int row, int col) - { return element(row,col); } - - const real & operator () (int row, int col) const - { return element(row,col); } - - real & element (int row, int col) - { return m[row | (col<<2)]; } - - const real & element (int row, int col) const - { return m[row | (col<<2)]; } - - matrix4 & operator *= ( const matrix4 & mat ) - { - mult_right( mat ); - return *this; - } - - matrix4 & operator *= ( const real & r ) - { - for (int i = 0; i < 4; ++i) - { - element(0,i) *= r; - element(1,i) *= r; - element(2,i) *= r; - element(3,i) *= r; - } - return *this; - } - - matrix4 & operator += ( const matrix4 & mat ) - { - for (int i = 0; i < 4; ++i) - { - element(0,i) += mat.element(0,i); - element(1,i) += mat.element(1,i); - element(2,i) += mat.element(2,i); - element(3,i) += mat.element(3,i); - } - return *this; - } - - friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); - friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); - friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); - - //protected: - real m[16]; - }; - - inline - matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) - { - matrix4 product; - - product = m1; - product.mult_right(m2); - - return product; - } - - inline - bool operator ==( const matrix4 &m1, const matrix4 &m2 ) - { - return ( - m1(0,0) == m2(0,0) && - m1(0,1) == m2(0,1) && - m1(0,2) == m2(0,2) && - m1(0,3) == m2(0,3) && - m1(1,0) == m2(1,0) && - m1(1,1) == m2(1,1) && - m1(1,2) == m2(1,2) && - m1(1,3) == m2(1,3) && - m1(2,0) == m2(2,0) && - m1(2,1) == m2(2,1) && - m1(2,2) == m2(2,2) && - m1(2,3) == m2(2,3) && - m1(3,0) == m2(3,0) && - m1(3,1) == m2(3,1) && - m1(3,2) == m2(3,2) && - m1(3,3) == m2(3,3) ); - } - - inline - bool operator != ( const matrix4 & m1, const matrix4 & m2 ) - { return !( m1 == m2 ); } - - - - - - - - - - - - - - class quaternion - { - public: - - quaternion() - { - *this = identity(); - } - - quaternion( const real v[4] ) - { - set_value( v ); - } - - - quaternion( real q0, real q1, real q2, real q3 ) - { - set_value( q0, q1, q2, q3 ); - } - - - quaternion( const matrix4 & m ) - { - set_value( m ); - } - - - quaternion( const vec3 &axis, real radians ) - { - set_value( axis, radians ); - } - - - quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) - { - set_value( rotateFrom, rotateTo ); - } - - quaternion( const vec3 & from_look, const vec3 & from_up, - const vec3 & to_look, const vec3& to_up) - { - set_value(from_look, from_up, to_look, to_up); - } - - const real * get_value() const - { - return &q[0]; - } - - void get_value( real &q0, real &q1, real &q2, real &q3 ) const - { - q0 = q[0]; - q1 = q[1]; - q2 = q[2]; - q3 = q[3]; - } - - quaternion & set_value( real q0, real q1, real q2, real q3 ) - { - q[0] = q0; - q[1] = q1; - q[2] = q2; - q[3] = q3; - counter = 0; - return *this; - } - - void get_value( vec3 &axis, real &radians ) const - { - radians = real(acos( q[3] ) * GLH_TWO); - if ( radians == GLH_ZERO ) - axis = vec3( 0.0, 0.0, 1.0 ); - else - { - axis.v[0] = q[0]; - axis.v[1] = q[1]; - axis.v[2] = q[2]; - axis.normalize(); - } - } - - void get_value( matrix4 & m ) const - { - real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; - - real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; - - s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); - - xs = q[0] * s; - ys = q[1] * s; - zs = q[2] * s; - - wx = q[3] * xs; - wy = q[3] * ys; - wz = q[3] * zs; - - xx = q[0] * xs; - xy = q[0] * ys; - xz = q[0] * zs; - - yy = q[1] * ys; - yz = q[1] * zs; - zz = q[2] * zs; - - m(0,0) = real( GLH_ONE - ( yy + zz )); - m(1,0) = real ( xy + wz ); - m(2,0) = real ( xz - wy ); - - m(0,1) = real ( xy - wz ); - m(1,1) = real ( GLH_ONE - ( xx + zz )); - m(2,1) = real ( yz + wx ); - - m(0,2) = real ( xz + wy ); - m(1,2) = real ( yz - wx ); - m(2,2) = real ( GLH_ONE - ( xx + yy )); - - m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; - m(3,3) = GLH_ONE; - } - - quaternion & set_value( const real * qp ) - { - memcpy(q,qp,sizeof(real) * 4); - - counter = 0; - return *this; - } - - quaternion & set_value( const matrix4 & m ) - { - real tr, s; - int i, j, k; - const int nxt[3] = { 1, 2, 0 }; - - tr = m(0,0) + m(1,1) + m(2,2); - - if ( tr > GLH_ZERO ) - { - s = real(sqrt( tr + m(3,3) )); - q[3] = real ( s * 0.5 ); - s = real(0.5) / s; - - q[0] = real ( ( m(1,2) - m(2,1) ) * s ); - q[1] = real ( ( m(2,0) - m(0,2) ) * s ); - q[2] = real ( ( m(0,1) - m(1,0) ) * s ); - } - else - { - i = 0; - if ( m(1,1) > m(0,0) ) - i = 1; - - if ( m(2,2) > m(i,i) ) - i = 2; - - j = nxt[i]; - k = nxt[j]; - - s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); - - q[i] = real ( s * 0.5 ); - s = real(0.5 / s); - - q[3] = real ( ( m(j,k) - m(k,j) ) * s ); - q[j] = real ( ( m(i,j) + m(j,i) ) * s ); - q[k] = real ( ( m(i,k) + m(k,i) ) * s ); - } - - counter = 0; - return *this; - } - - quaternion & set_value( const vec3 &axis, real theta ) - { - real sqnorm = axis.square_norm(); - - if (sqnorm <= GLH_EPSILON) - { - // axis too small. - x = y = z = 0.0; - w = 1.0; - } - else - { - theta *= real(0.5); - real sin_theta = real(sin(theta)); - - if (!equivalent(sqnorm,GLH_ONE)) - sin_theta /= real(sqrt(sqnorm)); - x = sin_theta * axis.v[0]; - y = sin_theta * axis.v[1]; - z = sin_theta * axis.v[2]; - w = real(cos(theta)); - } - return *this; - } - - quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) - { - vec3 p1, p2; - real alpha; - - p1 = rotateFrom; - p1.normalize(); - p2 = rotateTo; - p2.normalize(); - - alpha = p1.dot(p2); - - if(equivalent(alpha,GLH_ONE)) - { - *this = identity(); - return *this; - } - - // ensures that the anti-parallel case leads to a positive dot - if(equivalent(alpha,-GLH_ONE)) - { - vec3 v; - - if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) - v = vec3(p1.v[1], p1.v[2], p1.v[0]); - else - v = vec3(-p1.v[0], p1.v[1], p1.v[2]); - - v -= p1 * p1.dot(v); - v.normalize(); - - set_value(v, GLH_PI); - return *this; - } - - p1 = p1.cross(p2); - p1.normalize(); - set_value(p1,real(acos(alpha))); - - counter = 0; - return *this; - } - - quaternion & set_value( const vec3 & from_look, const vec3 & from_up, - const vec3 & to_look, const vec3 & to_up) - { - quaternion r_look = quaternion(from_look, to_look); - - vec3 rotated_from_up(from_up); - r_look.mult_vec(rotated_from_up); - - quaternion r_twist = quaternion(rotated_from_up, to_up); - - *this = r_twist; - *this *= r_look; - return *this; - } - - quaternion & operator *= ( const quaternion & qr ) - { - quaternion ql(*this); - - w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; - x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; - y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; - z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; - - counter += qr.counter; - counter++; - counter_normalize(); - return *this; - } - - void normalize() - { - real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); - if (equivalent(rnorm, GLH_ZERO)) - return; - x *= rnorm; - y *= rnorm; - z *= rnorm; - w *= rnorm; - counter = 0; - } - - friend bool operator == ( const quaternion & q1, const quaternion & q2 ); - - friend bool operator != ( const quaternion & q1, const quaternion & q2 ); - - friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); - - bool equals( const quaternion & r, real tolerance ) const - { - real t; - - t = ( - (q[0]-r.q[0])*(q[0]-r.q[0]) + - (q[1]-r.q[1])*(q[1]-r.q[1]) + - (q[2]-r.q[2])*(q[2]-r.q[2]) + - (q[3]-r.q[3])*(q[3]-r.q[3]) ); - if(t > GLH_EPSILON) - return false; - return 1; - } - - quaternion & conjugate() - { - q[0] *= -GLH_ONE; - q[1] *= -GLH_ONE; - q[2] *= -GLH_ONE; - return *this; - } - - quaternion & invert() - { - return conjugate(); - } - - quaternion inverse() const - { - quaternion r = *this; - return r.invert(); - } - - // - // Quaternion multiplication with cartesian vector - // v' = q*v*q(star) - // - void mult_vec( const vec3 &src, vec3 &dst ) const - { - real v_coef = w * w - x * x - y * y - z * z; - real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); - real c_coef = GLH_TWO * w; - - dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); - dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); - dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); - } - - void mult_vec( vec3 & src_and_dst) const - { - mult_vec(vec3(src_and_dst), src_and_dst); - } - - void scale_angle( real scaleFactor ) - { - vec3 axis; - real radians; - - get_value(axis, radians); - radians *= scaleFactor; - set_value(axis, radians); - } - - static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) - { - quaternion r; - - real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; - // if B is on opposite hemisphere from A, use -B instead - - int bflip; - if ( ( bflip = (cos_omega < GLH_ZERO)) ) - cos_omega = -cos_omega; - - // complementary interpolation parameter - real beta = GLH_ONE - alpha; - - if(cos_omega <= GLH_ONE - GLH_EPSILON) - return p; - - real omega = real(acos(cos_omega)); - real one_over_sin_omega = GLH_ONE / real(sin(omega)); - - beta = real(sin(omega*beta) * one_over_sin_omega); - alpha = real(sin(omega*alpha) * one_over_sin_omega); - - if (bflip) - alpha = -alpha; - - r.x = beta * p.q[0]+ alpha * q.q[0]; - r.y = beta * p.q[1]+ alpha * q.q[1]; - r.z = beta * p.q[2]+ alpha * q.q[2]; - r.w = beta * p.q[3]+ alpha * q.q[3]; - return r; - } - - static quaternion identity() - { - static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); - return ident; - } - - real & operator []( int i ) - { - assert(i < 4); - return q[i]; - } - - const real & operator []( int i ) const - { - assert(i < 4); - return q[i]; - } - - protected: - - void counter_normalize() - { - if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) - normalize(); - } - - union - { - struct - { - real q[4]; - }; - struct - { - real x; - real y; - real z; - real w; - }; - }; - - // renormalization counter - unsigned char counter; - }; - - inline - bool operator == ( const quaternion & q1, const quaternion & q2 ) - { - return (equivalent(q1.x, q2.x) && - equivalent(q1.y, q2.y) && - equivalent(q1.z, q2.z) && - equivalent(q1.w, q2.w) ); - } - - inline - bool operator != ( const quaternion & q1, const quaternion & q2 ) - { - return ! ( q1 == q2 ); - } - - inline - quaternion operator * ( const quaternion & q1, const quaternion & q2 ) - { - quaternion r(q1); - r *= q2; - return r; - } - - - - - - - - - - - class plane - { - public: - - plane() - { - planedistance = 0.0; - planenormal.set_value( 0.0, 0.0, 1.0 ); - } - - - plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) - { - vec3 v0 = p1 - p0; - vec3 v1 = p2 - p0; - planenormal = v0.cross(v1); - planenormal.normalize(); - planedistance = p0.dot(planenormal); - } - - plane( const vec3 &normal, real distance ) - { - planedistance = distance; - planenormal = normal; - planenormal.normalize(); - } - - plane( const vec3 &normal, const vec3 &point ) - { - planenormal = normal; - planenormal.normalize(); - planedistance = point.dot(planenormal); - } - - void offset( real d ) - { - planedistance += d; - } - - bool intersect( const line &l, vec3 &intersection ) const - { - vec3 pos, dir; - vec3 pn = planenormal; - real pd = planedistance; - - pos = l.get_position(); - dir = l.get_direction(); - - if(dir.dot(pn) == 0.0) return 0; - pos -= pn*pd; - // now we're talking about a plane passing through the origin - if(pos.dot(pn) < 0.0) pn.negate(); - if(dir.dot(pn) > 0.0) dir.negate(); - vec3 ppos = pn * pos.dot(pn); - pos = (ppos.length()/dir.dot(-pn))*dir; - intersection = l.get_position(); - intersection += pos; - return 1; - } - void transform( const matrix4 &matrix ) - { - matrix4 invtr = matrix.inverse(); - invtr = invtr.transpose(); - - vec3 pntOnplane = planenormal * planedistance; - vec3 newPntOnplane; - vec3 newnormal; - - invtr.mult_dir_matrix(planenormal, newnormal); - matrix.mult_vec_matrix(pntOnplane, newPntOnplane); - - newnormal.normalize(); - planenormal = newnormal; - planedistance = newPntOnplane.dot(planenormal); - } - - bool is_in_half_space( const vec3 &point ) const - { - - if(( point.dot(planenormal) - planedistance) < 0.0) - return 0; - return 1; - } - - - real distance( const vec3 & point ) const - { - return planenormal.dot(point - planenormal*planedistance); - } - - const vec3 &get_normal() const - { - return planenormal; - } - - - real get_distance_from_origin() const - { - return planedistance; - } - - - friend bool operator == ( const plane & p1, const plane & p2 ); - - - friend bool operator != ( const plane & p1, const plane & p2 ); - - //protected: - vec3 planenormal; - real planedistance; - }; - - inline - bool operator == (const plane & p1, const plane & p2 ) - { - return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); - } - - inline - bool operator != ( const plane & p1, const plane & p2 ) - { return ! (p1 == p2); } - - - - } // "ns_##GLH_REAL" - - // make common typedefs... -#ifdef GLH_REAL_IS_FLOAT - typedef GLH_REAL_NAMESPACE::vec2 vec2f; - typedef GLH_REAL_NAMESPACE::vec3 vec3f; - typedef GLH_REAL_NAMESPACE::vec4 vec4f; - typedef GLH_REAL_NAMESPACE::quaternion quaternionf; - typedef GLH_REAL_NAMESPACE::quaternion rotationf; - typedef GLH_REAL_NAMESPACE::line linef; - typedef GLH_REAL_NAMESPACE::plane planef; - typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; -#endif - - - - -} // namespace glh - - - -#endif - +/* + glh - is a platform-indepenedent C++ OpenGL helper library + + + Copyright (c) 2000 Cass Everitt + Copyright (c) 2000 NVIDIA Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + + * The names of contributors to this software may not be used + to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + + Cass Everitt - cass@r3.nu +*/ + +/* +glh_linear.h +*/ + +// Author: Cass W. Everitt + +#ifndef GLH_LINEAR_H +#define GLH_LINEAR_H + +#include +#include +#include + +// only supports float for now... +#define GLH_REAL_IS_FLOAT + +#ifdef GLH_REAL_IS_FLOAT +# define GLH_REAL float +# define GLH_REAL_NAMESPACE ns_float +#endif + +#define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 + +#define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) +#define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) +#define GLH_ZERO GLH_REAL(0.0) +#define GLH_ONE GLH_REAL(1.0) +#define GLH_TWO GLH_REAL(2.0) +#define GLH_EPSILON GLH_REAL(10e-6) +#define GLH_PI GLH_REAL(3.1415926535897932384626433832795) + +#define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) + +namespace glh +{ + + inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } + inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } + + // forward declarations for friend template functions. + template class vec; + + // forward declarations for friend template functions. + template + bool operator == ( const vec & v1, const vec & v2 ); + + // forward declarations for friend template functions. + template + bool operator != ( const vec & v1, const vec & v2 ); + + template + class vec + { + public: + int size() const { return N; } + + vec(const T & t = T()) + { for(int i = 0; i < N; i++) v[i] = t; } + vec(const T * tp) + { for(int i = 0; i < N; i++) v[i] = tp[i]; } + + const T * get_value() const + { return v; } + + + T dot( const vec & rhs ) const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; + return r; + } + + T length() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return T(sqrt(r)); + } + + T square_norm() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return r; + } + + void negate() + { for(int i = 0; i < N; i++) v[i] = -v[i]; } + + + T normalize() + { + T sum(0); + for(int i = 0; i < N; i++) + sum += v[i]*v[i]; + sum = T(sqrt(sum)); + if (sum > GLH_EPSILON) + for(int i = 0; i < N; i++) + v[i] /= sum; + return sum; + } + + + vec & set_value( const T * rhs ) + { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } + + T & operator [] ( int i ) + { return v[i]; } + + const T & operator [] ( int i ) const + { return v[i]; } + + vec & operator *= ( T d ) + { for(int i = 0; i < N; i++) v[i] *= d; return *this;} + + vec & operator *= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} + + vec & operator /= ( T d ) + { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} + + vec & operator += ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} + + vec & operator -= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} + + + vec operator - () const + { vec rv = v; rv.negate(); return rv; } + + vec operator + ( const vec &v) const + { vec rt(*this); return rt += v; } + + vec operator - ( const vec &v) const + { vec rt(*this); return rt -= v; } + + vec operator * ( T d) const + { vec rt(*this); return rt *= d; } + + friend bool operator == <> ( const vec &v1, const vec &v2 ); + friend bool operator != <> ( const vec &v1, const vec &v2 ); + + + //protected: + T v[N]; + }; + + + + // vector friend operators + + template inline + vec operator * ( const vec & b, T d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator * ( T d, const vec & b ) + { return b*d; } + + template inline + vec operator * ( const vec & b, const vec & d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator / ( const vec & b, T d ) + { vec rt(b); return rt /= d; } + + template inline + vec operator + ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt += v2; } + + template inline + vec operator - ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt -= v2; } + + + template inline + bool operator == ( const vec & v1, const vec & v2 ) + { + for(int i = 0; i < N; i++) + if(v1.v[i] != v2.v[i]) + return false; + return true; + } + + template inline + bool operator != ( const vec & v1, const vec & v2 ) + { return !(v1 == v2); } + + + typedef vec<3,unsigned char> vec3ub; + typedef vec<4,unsigned char> vec4ub; + + + + + + namespace GLH_REAL_NAMESPACE + { + typedef GLH_REAL real; + + class line; + class plane; + class matrix4; + class quaternion; + typedef quaternion rotation; + + class vec2 : public vec<2,real> + { + public: + vec2(const real & t = real()) : vec<2,real>(t) + {} + vec2(const vec<2,real> & t) : vec<2,real>(t) + {} + vec2(const real * tp) : vec<2,real>(tp) + {} + + vec2(real x, real y ) + { v[0] = x; v[1] = y; } + + void get_value(real & x, real & y) const + { x = v[0]; y = v[1]; } + + vec2 & set_value( const real & x, const real & y) + { v[0] = x; v[1] = y; return *this; } + + }; + + + class vec3 : public vec<3,real> + { + public: + vec3(const real & t = real()) : vec<3,real>(t) + {} + vec3(const vec<3,real> & t) : vec<3,real>(t) + {} + vec3(const real * tp) : vec<3,real>(tp) + {} + + vec3(real x, real y, real z) + { v[0] = x; v[1] = y; v[2] = z; } + + void get_value(real & x, real & y, real & z) const + { x = v[0]; y = v[1]; z = v[2]; } + + vec3 cross( const vec3 &rhs ) const + { + vec3 rt; + rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; + rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; + rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; + return rt; + } + + vec3 & set_value( const real & x, const real & y, const real & z) + { v[0] = x; v[1] = y; v[2] = z; return *this; } + + }; + + + class vec4 : public vec<4,real> + { + public: + vec4(const real & t = real()) : vec<4,real>(t) + {} + vec4(const vec<4,real> & t) : vec<4,real>(t) + {} + + vec4(const vec<3,real> & t, real fourth) + + { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } + vec4(const real * tp) : vec<4,real>(tp) + {} + vec4(real x, real y, real z, real w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } + + void get_value(real & x, real & y, real & z, real & w) const + { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } + + vec4 & set_value( const real & x, const real & y, const real & z, const real & w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } + }; + + inline + vec3 homogenize(const vec4 & v) + { + vec3 rt; + assert(v.v[3] != GLH_ZERO); + rt.v[0] = v.v[0]/v.v[3]; + rt.v[1] = v.v[1]/v.v[3]; + rt.v[2] = v.v[2]/v.v[3]; + return rt; + } + + + + class line + { + public: + + line() + { set_value(vec3(0,0,0),vec3(0,0,1)); } + + line( const vec3 & p0, const vec3 &p1) + { set_value(p0,p1); } + + void set_value( const vec3 &p0, const vec3 &p1) + { + position = p0; + direction = p1-p0; + direction.normalize(); + } + + bool get_closest_points(const line &line2, + vec3 &pointOnThis, + vec3 &pointOnThat) + { + + // quick check to see if parallel -- if so, quit. + if(fabs(direction.dot(line2.direction)) == 1.0) + return 0; + line l2 = line2; + + // Algorithm: Brian Jean + // + register real u; + register real v; + vec3 Vr = direction; + vec3 Vs = l2.direction; + register real Vr_Dot_Vs = Vr.dot(Vs); + register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); + vec3 C = l2.position - position; + register real C_Dot_Vr = C.dot(Vr); + register real C_Dot_Vs = C.dot(Vs); + + u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; + v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; + + pointOnThis = position; + pointOnThis += direction * u; + pointOnThat = l2.position; + pointOnThat += l2.direction * v; + + return 1; + } + + vec3 get_closest_point(const vec3 &point) + { + vec3 np = point - position; + vec3 rp = direction*direction.dot(np)+position; + return rp; + } + + const vec3 & get_position() const {return position;} + + const vec3 & get_direction() const {return direction;} + + //protected: + vec3 position; + vec3 direction; + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // matrix + + + class matrix4 + { + + public: + + matrix4() { make_identity(); } + + matrix4( real r ) + { set_value(r); } + + matrix4( real * m ) + { set_value(m); } + + matrix4( real a00, real a01, real a02, real a03, + real a10, real a11, real a12, real a13, + real a20, real a21, real a22, real a23, + real a30, real a31, real a32, real a33 ) + { + element(0,0) = a00; + element(0,1) = a01; + element(0,2) = a02; + element(0,3) = a03; + + element(1,0) = a10; + element(1,1) = a11; + element(1,2) = a12; + element(1,3) = a13; + + element(2,0) = a20; + element(2,1) = a21; + element(2,2) = a22; + element(2,3) = a23; + + element(3,0) = a30; + element(3,1) = a31; + element(3,2) = a32; + element(3,3) = a33; + } + + + void get_value( real * mp ) const + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + mp[c++] = element(i,j); + } + + + const real * get_value() const + { return m; } + + void set_value( real * mp) + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + element(i,j) = mp[c++]; + } + + void set_value( real r ) + { + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + element(i,j) = r; + } + + void make_identity() + { + element(0,0) = 1.0; + element(0,1) = 0.0; + element(0,2) = 0.0; + element(0,3) = 0.0; + + element(1,0) = 0.0; + element(1,1) = 1.0; + element(1,2) = 0.0; + element(1,3) = 0.0; + + element(2,0) = 0.0; + element(2,1) = 0.0; + element(2,2) = 1.0; + element(2,3) = 0.0; + + element(3,0) = 0.0; + element(3,1) = 0.0; + element(3,2) = 0.0; + element(3,3) = 1.0; + } + + + static matrix4 identity() + { + static matrix4 mident ( + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 ); + return mident; + } + + + void set_scale( real s ) + { + element(0,0) = s; + element(1,1) = s; + element(2,2) = s; + } + + void set_scale( const vec3 & s ) + { + element(0,0) = s.v[0]; + element(1,1) = s.v[1]; + element(2,2) = s.v[2]; + } + + + void set_translate( const vec3 & t ) + { + element(0,3) = t.v[0]; + element(1,3) = t.v[1]; + element(2,3) = t.v[2]; + } + + void set_row(int r, const vec4 & t) + { + element(r,0) = t.v[0]; + element(r,1) = t.v[1]; + element(r,2) = t.v[2]; + element(r,3) = t.v[3]; + } + + void set_column(int c, const vec4 & t) + { + element(0,c) = t.v[0]; + element(1,c) = t.v[1]; + element(2,c) = t.v[2]; + element(3,c) = t.v[3]; + } + + + void get_row(int r, vec4 & t) const + { + t.v[0] = element(r,0); + t.v[1] = element(r,1); + t.v[2] = element(r,2); + t.v[3] = element(r,3); + } + + vec4 get_row(int r) const + { + vec4 v; get_row(r, v); + return v; + } + + void get_column(int c, vec4 & t) const + { + t.v[0] = element(0,c); + t.v[1] = element(1,c); + t.v[2] = element(2,c); + t.v[3] = element(3,c); + } + + vec4 get_column(int c) const + { + vec4 v; get_column(c, v); + return v; + } + + matrix4 inverse() const + { + matrix4 minv; + + real r1[8], r2[8], r3[8], r4[8]; + real *s[4], *tmprow; + + s[0] = &r1[0]; + s[1] = &r2[0]; + s[2] = &r3[0]; + s[3] = &r4[0]; + + register int i,j,p,jj; + for(i=0;i<4;i++) + { + for(j=0;j<4;j++) + { + s[i][j] = element(i,j); + if(i==j) s[i][j+4] = 1.0; + else s[i][j+4] = 0.0; + } + } + real scp[4]; + for(i=0;i<4;i++) + { + scp[i] = real(fabs(s[i][0])); + for(j=1;j<4;j++) + if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); + if(scp[i] == 0.0) return minv; // singular matrix! + } + + int pivot_to; + real scp_max; + for(i=0;i<4;i++) + { + // select pivot row + pivot_to = i; + scp_max = real(fabs(s[i][i]/scp[i])); + // find out which row should be on top + for(p=i+1;p<4;p++) + if(real(fabs(s[p][i]/scp[p])) > scp_max) + { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } + // Pivot if necessary + if(pivot_to != i) + { + tmprow = s[i]; + s[i] = s[pivot_to]; + s[pivot_to] = tmprow; + real tmpscp; + tmpscp = scp[i]; + scp[i] = scp[pivot_to]; + scp[pivot_to] = tmpscp; + } + + real mji; + // perform gaussian elimination + for(j=i+1;j<4;j++) + { + mji = s[j][i]/s[i][i]; + s[j][i] = 0.0; + for(jj=i+1;jj<8;jj++) + s[j][jj] -= mji*s[i][jj]; + } + } + if(s[3][3] == 0.0) return minv; // singular matrix! + + // + // Now we have an upper triangular matrix. + // + // x x x x | y y y y + // 0 x x x | y y y y + // 0 0 x x | y y y y + // 0 0 0 x | y y y y + // + // we'll back substitute to get the inverse + // + // 1 0 0 0 | z z z z + // 0 1 0 0 | z z z z + // 0 0 1 0 | z z z z + // 0 0 0 1 | z z z z + // + + real mij; + for(i=3;i>0;i--) + { + for(j=i-1;j > -1; j--) + { + mij = s[j][i]/s[i][i]; + for(jj=j+1;jj<8;jj++) + s[j][jj] -= mij*s[i][jj]; + } + } + + for(i=0;i<4;i++) + for(j=0;j<4;j++) + minv(i,j) = s[i][j+4] / s[i][i]; + + return minv; + } + + + matrix4 transpose() const + { + matrix4 mtrans; + + for(int i=0;i<4;i++) + for(int j=0;j<4;j++) + mtrans(i,j) = element(j,i); + return mtrans; + } + + matrix4 & mult_right( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += mt(i,c) * b(c,j); + return *this; + } + + matrix4 & mult_left( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += b(i,c) * mt(c,j); + return *this; + } + + // dst = M * src + void mult_matrix_vec( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + element(0,3) ) / w; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + element(1,3) ) / w; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + element(2,3) ) / w; + } + + void mult_matrix_vec( vec3 & src_and_dst) const + { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + element(3,0) ) / w; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + element(3,1) ) / w; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + element(3,2) ) / w; + } + + + void mult_vec_matrix( vec3 & src_and_dst) const + { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } + + // dst = M * src + void mult_matrix_vec( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + src.v[3] * element(0,3)); + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + src.v[3] * element(1,3)); + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + src.v[3] * element(2,3)); + dst.v[3] = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + src.v[3] * element(3,3)); + } + + void mult_matrix_vec( vec4 & src_and_dst) const + { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + src.v[3] * element(3,0)); + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + src.v[3] * element(3,1)); + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + src.v[3] * element(3,2)); + dst.v[3] = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + src.v[3] * element(3,3)); + } + + + void mult_vec_matrix( vec4 & src_and_dst) const + { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } + + + // dst = M * src + void mult_matrix_dir( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) ) ; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) ) ; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) ) ; + } + + + void mult_matrix_dir( vec3 & src_and_dst) const + { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_dir_matrix( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) ) ; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) ) ; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) ) ; + } + + + void mult_dir_matrix( vec3 & src_and_dst) const + { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } + + + real & operator () (int row, int col) + { return element(row,col); } + + const real & operator () (int row, int col) const + { return element(row,col); } + + real & element (int row, int col) + { return m[row | (col<<2)]; } + + const real & element (int row, int col) const + { return m[row | (col<<2)]; } + + matrix4 & operator *= ( const matrix4 & mat ) + { + mult_right( mat ); + return *this; + } + + matrix4 & operator *= ( const real & r ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) *= r; + element(1,i) *= r; + element(2,i) *= r; + element(3,i) *= r; + } + return *this; + } + + matrix4 & operator += ( const matrix4 & mat ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) += mat.element(0,i); + element(1,i) += mat.element(1,i); + element(2,i) += mat.element(2,i); + element(3,i) += mat.element(3,i); + } + return *this; + } + + friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); + + //protected: + real m[16]; + }; + + inline + matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) + { + matrix4 product; + + product = m1; + product.mult_right(m2); + + return product; + } + + inline + bool operator ==( const matrix4 &m1, const matrix4 &m2 ) + { + return ( + m1(0,0) == m2(0,0) && + m1(0,1) == m2(0,1) && + m1(0,2) == m2(0,2) && + m1(0,3) == m2(0,3) && + m1(1,0) == m2(1,0) && + m1(1,1) == m2(1,1) && + m1(1,2) == m2(1,2) && + m1(1,3) == m2(1,3) && + m1(2,0) == m2(2,0) && + m1(2,1) == m2(2,1) && + m1(2,2) == m2(2,2) && + m1(2,3) == m2(2,3) && + m1(3,0) == m2(3,0) && + m1(3,1) == m2(3,1) && + m1(3,2) == m2(3,2) && + m1(3,3) == m2(3,3) ); + } + + inline + bool operator != ( const matrix4 & m1, const matrix4 & m2 ) + { return !( m1 == m2 ); } + + + + + + + + + + + + + + class quaternion + { + public: + + quaternion() + { + *this = identity(); + } + + quaternion( const real v[4] ) + { + set_value( v ); + } + + + quaternion( real q0, real q1, real q2, real q3 ) + { + set_value( q0, q1, q2, q3 ); + } + + + quaternion( const matrix4 & m ) + { + set_value( m ); + } + + + quaternion( const vec3 &axis, real radians ) + { + set_value( axis, radians ); + } + + + quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) + { + set_value( rotateFrom, rotateTo ); + } + + quaternion( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3& to_up) + { + set_value(from_look, from_up, to_look, to_up); + } + + const real * get_value() const + { + return &q[0]; + } + + void get_value( real &q0, real &q1, real &q2, real &q3 ) const + { + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + } + + quaternion & set_value( real q0, real q1, real q2, real q3 ) + { + q[0] = q0; + q[1] = q1; + q[2] = q2; + q[3] = q3; + counter = 0; + return *this; + } + + void get_value( vec3 &axis, real &radians ) const + { + radians = real(acos( q[3] ) * GLH_TWO); + if ( radians == GLH_ZERO ) + axis = vec3( 0.0, 0.0, 1.0 ); + else + { + axis.v[0] = q[0]; + axis.v[1] = q[1]; + axis.v[2] = q[2]; + axis.normalize(); + } + } + + void get_value( matrix4 & m ) const + { + real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; + + real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; + + s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); + + xs = q[0] * s; + ys = q[1] * s; + zs = q[2] * s; + + wx = q[3] * xs; + wy = q[3] * ys; + wz = q[3] * zs; + + xx = q[0] * xs; + xy = q[0] * ys; + xz = q[0] * zs; + + yy = q[1] * ys; + yz = q[1] * zs; + zz = q[2] * zs; + + m(0,0) = real( GLH_ONE - ( yy + zz )); + m(1,0) = real ( xy + wz ); + m(2,0) = real ( xz - wy ); + + m(0,1) = real ( xy - wz ); + m(1,1) = real ( GLH_ONE - ( xx + zz )); + m(2,1) = real ( yz + wx ); + + m(0,2) = real ( xz + wy ); + m(1,2) = real ( yz - wx ); + m(2,2) = real ( GLH_ONE - ( xx + yy )); + + m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; + m(3,3) = GLH_ONE; + } + + quaternion & set_value( const real * qp ) + { + memcpy(q,qp,sizeof(real) * 4); + + counter = 0; + return *this; + } + + quaternion & set_value( const matrix4 & m ) + { + real tr, s; + int i, j, k; + const int nxt[3] = { 1, 2, 0 }; + + tr = m(0,0) + m(1,1) + m(2,2); + + if ( tr > GLH_ZERO ) + { + s = real(sqrt( tr + m(3,3) )); + q[3] = real ( s * 0.5 ); + s = real(0.5) / s; + + q[0] = real ( ( m(1,2) - m(2,1) ) * s ); + q[1] = real ( ( m(2,0) - m(0,2) ) * s ); + q[2] = real ( ( m(0,1) - m(1,0) ) * s ); + } + else + { + i = 0; + if ( m(1,1) > m(0,0) ) + i = 1; + + if ( m(2,2) > m(i,i) ) + i = 2; + + j = nxt[i]; + k = nxt[j]; + + s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); + + q[i] = real ( s * 0.5 ); + s = real(0.5 / s); + + q[3] = real ( ( m(j,k) - m(k,j) ) * s ); + q[j] = real ( ( m(i,j) + m(j,i) ) * s ); + q[k] = real ( ( m(i,k) + m(k,i) ) * s ); + } + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 &axis, real theta ) + { + real sqnorm = axis.square_norm(); + + if (sqnorm <= GLH_EPSILON) + { + // axis too small. + x = y = z = 0.0; + w = 1.0; + } + else + { + theta *= real(0.5); + real sin_theta = real(sin(theta)); + + if (!equivalent(sqnorm,GLH_ONE)) + sin_theta /= real(sqrt(sqnorm)); + x = sin_theta * axis.v[0]; + y = sin_theta * axis.v[1]; + z = sin_theta * axis.v[2]; + w = real(cos(theta)); + } + return *this; + } + + quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) + { + vec3 p1, p2; + real alpha; + + p1 = rotateFrom; + p1.normalize(); + p2 = rotateTo; + p2.normalize(); + + alpha = p1.dot(p2); + + if(equivalent(alpha,GLH_ONE)) + { + *this = identity(); + return *this; + } + + // ensures that the anti-parallel case leads to a positive dot + if(equivalent(alpha,-GLH_ONE)) + { + vec3 v; + + if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) + v = vec3(p1.v[1], p1.v[2], p1.v[0]); + else + v = vec3(-p1.v[0], p1.v[1], p1.v[2]); + + v -= p1 * p1.dot(v); + v.normalize(); + + set_value(v, GLH_PI); + return *this; + } + + p1 = p1.cross(p2); + p1.normalize(); + set_value(p1,real(acos(alpha))); + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3 & to_up) + { + quaternion r_look = quaternion(from_look, to_look); + + vec3 rotated_from_up(from_up); + r_look.mult_vec(rotated_from_up); + + quaternion r_twist = quaternion(rotated_from_up, to_up); + + *this = r_twist; + *this *= r_look; + return *this; + } + + quaternion & operator *= ( const quaternion & qr ) + { + quaternion ql(*this); + + w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; + x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; + y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; + z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; + + counter += qr.counter; + counter++; + counter_normalize(); + return *this; + } + + void normalize() + { + real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); + if (equivalent(rnorm, GLH_ZERO)) + return; + x *= rnorm; + y *= rnorm; + z *= rnorm; + w *= rnorm; + counter = 0; + } + + friend bool operator == ( const quaternion & q1, const quaternion & q2 ); + + friend bool operator != ( const quaternion & q1, const quaternion & q2 ); + + friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); + + bool equals( const quaternion & r, real tolerance ) const + { + real t; + + t = ( + (q[0]-r.q[0])*(q[0]-r.q[0]) + + (q[1]-r.q[1])*(q[1]-r.q[1]) + + (q[2]-r.q[2])*(q[2]-r.q[2]) + + (q[3]-r.q[3])*(q[3]-r.q[3]) ); + if(t > GLH_EPSILON) + return false; + return 1; + } + + quaternion & conjugate() + { + q[0] *= -GLH_ONE; + q[1] *= -GLH_ONE; + q[2] *= -GLH_ONE; + return *this; + } + + quaternion & invert() + { + return conjugate(); + } + + quaternion inverse() const + { + quaternion r = *this; + return r.invert(); + } + + // + // Quaternion multiplication with cartesian vector + // v' = q*v*q(star) + // + void mult_vec( const vec3 &src, vec3 &dst ) const + { + real v_coef = w * w - x * x - y * y - z * z; + real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); + real c_coef = GLH_TWO * w; + + dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); + dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); + dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); + } + + void mult_vec( vec3 & src_and_dst) const + { + mult_vec(vec3(src_and_dst), src_and_dst); + } + + void scale_angle( real scaleFactor ) + { + vec3 axis; + real radians; + + get_value(axis, radians); + radians *= scaleFactor; + set_value(axis, radians); + } + + static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) + { + quaternion r; + + real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; + // if B is on opposite hemisphere from A, use -B instead + + int bflip; + if ( ( bflip = (cos_omega < GLH_ZERO)) ) + cos_omega = -cos_omega; + + // complementary interpolation parameter + real beta = GLH_ONE - alpha; + + if(cos_omega <= GLH_ONE - GLH_EPSILON) + return p; + + real omega = real(acos(cos_omega)); + real one_over_sin_omega = GLH_ONE / real(sin(omega)); + + beta = real(sin(omega*beta) * one_over_sin_omega); + alpha = real(sin(omega*alpha) * one_over_sin_omega); + + if (bflip) + alpha = -alpha; + + r.x = beta * p.q[0]+ alpha * q.q[0]; + r.y = beta * p.q[1]+ alpha * q.q[1]; + r.z = beta * p.q[2]+ alpha * q.q[2]; + r.w = beta * p.q[3]+ alpha * q.q[3]; + return r; + } + + static quaternion identity() + { + static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); + return ident; + } + + real & operator []( int i ) + { + assert(i < 4); + return q[i]; + } + + const real & operator []( int i ) const + { + assert(i < 4); + return q[i]; + } + + protected: + + void counter_normalize() + { + if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) + normalize(); + } + + union + { + struct + { + real q[4]; + }; + struct + { + real x; + real y; + real z; + real w; + }; + }; + + // renormalization counter + unsigned char counter; + }; + + inline + bool operator == ( const quaternion & q1, const quaternion & q2 ) + { + return (equivalent(q1.x, q2.x) && + equivalent(q1.y, q2.y) && + equivalent(q1.z, q2.z) && + equivalent(q1.w, q2.w) ); + } + + inline + bool operator != ( const quaternion & q1, const quaternion & q2 ) + { + return ! ( q1 == q2 ); + } + + inline + quaternion operator * ( const quaternion & q1, const quaternion & q2 ) + { + quaternion r(q1); + r *= q2; + return r; + } + + + + + + + + + + + class plane + { + public: + + plane() + { + planedistance = 0.0; + planenormal.set_value( 0.0, 0.0, 1.0 ); + } + + + plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) + { + vec3 v0 = p1 - p0; + vec3 v1 = p2 - p0; + planenormal = v0.cross(v1); + planenormal.normalize(); + planedistance = p0.dot(planenormal); + } + + plane( const vec3 &normal, real distance ) + { + planedistance = distance; + planenormal = normal; + planenormal.normalize(); + } + + plane( const vec3 &normal, const vec3 &point ) + { + planenormal = normal; + planenormal.normalize(); + planedistance = point.dot(planenormal); + } + + void offset( real d ) + { + planedistance += d; + } + + bool intersect( const line &l, vec3 &intersection ) const + { + vec3 pos, dir; + vec3 pn = planenormal; + real pd = planedistance; + + pos = l.get_position(); + dir = l.get_direction(); + + if(dir.dot(pn) == 0.0) return 0; + pos -= pn*pd; + // now we're talking about a plane passing through the origin + if(pos.dot(pn) < 0.0) pn.negate(); + if(dir.dot(pn) > 0.0) dir.negate(); + vec3 ppos = pn * pos.dot(pn); + pos = (ppos.length()/dir.dot(-pn))*dir; + intersection = l.get_position(); + intersection += pos; + return 1; + } + void transform( const matrix4 &matrix ) + { + matrix4 invtr = matrix.inverse(); + invtr = invtr.transpose(); + + vec3 pntOnplane = planenormal * planedistance; + vec3 newPntOnplane; + vec3 newnormal; + + invtr.mult_dir_matrix(planenormal, newnormal); + matrix.mult_vec_matrix(pntOnplane, newPntOnplane); + + newnormal.normalize(); + planenormal = newnormal; + planedistance = newPntOnplane.dot(planenormal); + } + + bool is_in_half_space( const vec3 &point ) const + { + + if(( point.dot(planenormal) - planedistance) < 0.0) + return 0; + return 1; + } + + + real distance( const vec3 & point ) const + { + return planenormal.dot(point - planenormal*planedistance); + } + + const vec3 &get_normal() const + { + return planenormal; + } + + + real get_distance_from_origin() const + { + return planedistance; + } + + + friend bool operator == ( const plane & p1, const plane & p2 ); + + + friend bool operator != ( const plane & p1, const plane & p2 ); + + //protected: + vec3 planenormal; + real planedistance; + }; + + inline + bool operator == (const plane & p1, const plane & p2 ) + { + return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); + } + + inline + bool operator != ( const plane & p1, const plane & p2 ) + { return ! (p1 == p2); } + + + + } // "ns_##GLH_REAL" + + // make common typedefs... +#ifdef GLH_REAL_IS_FLOAT + typedef GLH_REAL_NAMESPACE::vec2 vec2f; + typedef GLH_REAL_NAMESPACE::vec3 vec3f; + typedef GLH_REAL_NAMESPACE::vec4 vec4f; + typedef GLH_REAL_NAMESPACE::quaternion quaternionf; + typedef GLH_REAL_NAMESPACE::quaternion rotationf; + typedef GLH_REAL_NAMESPACE::line linef; + typedef GLH_REAL_NAMESPACE::plane planef; + typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; +#endif + + + + +} // namespace glh + + + +#endif + diff --git a/linden/indra/newview/llfloaterregioninfo.cpp b/linden/indra/newview/llfloaterregioninfo.cpp index 4880308..3c3625b 100644 --- a/linden/indra/newview/llfloaterregioninfo.cpp +++ b/linden/indra/newview/llfloaterregioninfo.cpp @@ -1,3446 +1,3446 @@ -/** - * @file llfloaterregioninfo.cpp - * @author Aaron Brashears - * @brief Implementation of the region info and controls floater and panels. - * - * $LicenseInfo:firstyear=2004&license=viewergpl$ - * - * Copyright (c) 2004-2009, Linden Research, Inc. - * - * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception - * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. - * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. - * $/LicenseInfo$ - */ - -#include "llviewerprecompiledheaders.h" -#include "llfloaterregioninfo.h" - -#include -#include - -#include "llcachename.h" -#include "lldir.h" -#include "lldispatcher.h" -#include "llglheaders.h" -#include "llregionflags.h" -#include "llstl.h" -#include "indra_constants.h" -#include "message.h" - -#include "llagent.h" -#include "llalertdialog.h" -#include "llappviewer.h" -#include "llfloateravatarpicker.h" -#include "llbutton.h" -#include "llcheckboxctrl.h" -#include "llcombobox.h" -#include "llfilepicker.h" -#include "llfloaterdaycycle.h" -#include "llfloatergodtools.h" // for send_sim_wide_deletes() -#include "llfloatertopobjects.h" // added to fix SL-32336 -#include "llfloatergroups.h" -#include "llfloatertelehub.h" -#include "llfloaterwindlight.h" -#include "llinventorymodel.h" -#include "lllineeditor.h" -#include "llalertdialog.h" -#include "llnamelistctrl.h" -#include "llsliderctrl.h" -#include "llspinctrl.h" -#include "lltabcontainer.h" -#include "lltextbox.h" -#include "llinventory.h" -#include "lltexturectrl.h" -#include "lltrans.h" -#include "llviewercontrol.h" -#include "lluictrlfactory.h" -#include "llviewerimage.h" -#include "llviewerimagelist.h" -#include "llviewerregion.h" -#include "llviewerstats.h" -#include "llviewertexteditor.h" -#include "llviewerwindow.h" -#include "llvlcomposition.h" -#include "hippolimits.h" - -// [RLVa:KB] -#include "rlvhandler.h" -// [/RLVa:KB] - -#define ELAR_ENABLED 0 // Enable when server support is implemented - -const S32 TERRAIN_TEXTURE_COUNT = 4; -const S32 CORNER_COUNT = 4; - -///---------------------------------------------------------------------------- -/// Local class declaration -///---------------------------------------------------------------------------- - -class LLDispatchEstateUpdateInfo : public LLDispatchHandler -{ -public: - LLDispatchEstateUpdateInfo() {} - virtual ~LLDispatchEstateUpdateInfo() {} - virtual bool operator()( - const LLDispatcher* dispatcher, - const std::string& key, - const LLUUID& invoice, - const sparam_t& strings); -}; - -class LLDispatchSetEstateAccess : public LLDispatchHandler -{ -public: - LLDispatchSetEstateAccess() {} - virtual ~LLDispatchSetEstateAccess() {} - virtual bool operator()( - const LLDispatcher* dispatcher, - const std::string& key, - const LLUUID& invoice, - const sparam_t& strings); -}; - - -/* -void unpack_request_params( - LLMessageSystem* msg, - LLDispatcher::sparam_t& strings, - LLDispatcher::iparam_t& integers) -{ - char str_buf[MAX_STRING]; - S32 str_count = msg->getNumberOfBlocksFast(_PREHASH_StringData); - S32 i; - for (i = 0; i < str_count; ++i) - { - // we treat the SParam as binary data (since it might be an - // LLUUID in compressed form which may have embedded \0's,) - str_buf[0] = '\0'; - S32 data_size = msg->getSizeFast(_PREHASH_StringData, i, _PREHASH_SParam); - if (data_size >= 0) - { - msg->getBinaryDataFast(_PREHASH_StringData, _PREHASH_SParam, - str_buf, data_size, i, MAX_STRING - 1); - strings.push_back(std::string(str_buf, data_size)); - } - } - - U32 int_buf; - S32 int_count = msg->getNumberOfBlocksFast(_PREHASH_IntegerData); - for (i = 0; i < int_count; ++i) - { - msg->getU32("IntegerData", "IParam", int_buf, i); - integers.push_back(int_buf); - } -} -*/ - - - -bool estate_dispatch_initialized = false; - - -///---------------------------------------------------------------------------- -/// LLFloaterRegionInfo -///---------------------------------------------------------------------------- - -//S32 LLFloaterRegionInfo::sRequestSerial = 0; -LLUUID LLFloaterRegionInfo::sRequestInvoice; - -LLFloaterRegionInfo::LLFloaterRegionInfo(const LLSD& seed) -{ - LLUICtrlFactory::getInstance()->buildFloater(this, "floater_region_info.xml", NULL, FALSE); -} - -BOOL LLFloaterRegionInfo::postBuild() -{ - mTab = getChild("region_panels"); - - // contruct the panels - LLPanelRegionInfo* panel; - - panel = new LLPanelRegionGeneralInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_general.xml"); - mTab->addTabPanel(panel, panel->getLabel(), TRUE); - - // We only use this panel on Aurora-based sims -- MC - std::string url = gAgent.getRegion()->getCapability("DispatchOpenRegionSettings"); - if (!url.empty()) - { - panel = new LLPanelRegionOpenSettingsInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_open_region_settings.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - } - - panel = new LLPanelRegionDebugInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_debug.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - - panel = new LLPanelRegionTextureInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_texture.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - - panel = new LLPanelRegionTerrainInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_terrain.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - - panel = new LLPanelEstateInfo; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_estate.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - - panel = new LLPanelEstateCovenant; - mInfoPanels.push_back(panel); - LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_covenant.xml"); - mTab->addTabPanel(panel, panel->getLabel(), FALSE); - - gMessageSystem->setHandlerFunc( - "EstateOwnerMessage", - &processEstateOwnerRequest); - - return TRUE; -} - -LLFloaterRegionInfo::~LLFloaterRegionInfo() -{ -} - -void LLFloaterRegionInfo::onOpen() -{ - LLRect rect = gSavedSettings.getRect("FloaterRegionInfo"); - S32 left, top; - gFloaterView->getNewFloaterPosition(&left, &top); - rect.translate(left,top); - - refreshFromRegion(gAgent.getRegion()); - requestRegionInfo(); - LLFloater::onOpen(); -} - -// static -void LLFloaterRegionInfo::requestRegionInfo() -{ - LLTabContainer* tab = findInstance()->getChild("region_panels"); - - tab->getChild("General")->setCtrlsEnabled(FALSE); - tab->getChild("Debug")->setCtrlsEnabled(FALSE); - tab->getChild("Terrain")->setCtrlsEnabled(FALSE); - tab->getChild("Estate")->setCtrlsEnabled(FALSE); - tab->getChild("RegionSettings")->setCtrlsEnabled(FALSE); - - // Must allow anyone to request the RegionInfo data - // so non-owners/non-gods can see the values. - // Therefore can't use an EstateOwnerMessage JC - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("RequestRegionInfo"); - msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); - msg->addUUID("SessionID", gAgent.getSessionID()); - gAgent.sendReliableMessage(); -} - -// static -void LLFloaterRegionInfo::processEstateOwnerRequest(LLMessageSystem* msg,void**) -{ - static LLDispatcher dispatch; - if(!findInstance()) - { - return; - } - - if (!estate_dispatch_initialized) - { - LLPanelEstateInfo::initDispatch(dispatch); - } - - LLTabContainer* tab = findInstance()->getChild("region_panels"); - LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); - - // unpack the message - std::string request; - LLUUID invoice; - LLDispatcher::sparam_t strings; - LLDispatcher::unpackMessage(msg, request, invoice, strings); - if(invoice != getLastInvoice()) - { - llwarns << "Mismatched Estate message: " << request << llendl; - return; - } - - //dispatch the message - dispatch.dispatch(request, invoice, strings); - - LLViewerRegion* region = gAgent.getRegion(); - panel->updateControls(region); -} - - -// static -void LLFloaterRegionInfo::processRegionInfo(LLMessageSystem* msg) -{ - LLPanel* panel; - - llinfos << "LLFloaterRegionInfo::processRegionInfo" << llendl; - if(!findInstance()) - { - return; - } - - LLTabContainer* tab = findInstance()->getChild("region_panels"); - - LLViewerRegion* region = gAgent.getRegion(); - BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); - - // extract message - std::string sim_name; - std::string sim_type = LLTrans::getString("land_type_unknown"); - U32 region_flags; - U8 agent_limit; - F32 object_bonus_factor; - U8 sim_access; - F32 water_height; - F32 terrain_raise_limit; - F32 terrain_lower_limit; - BOOL use_estate_sun; - F32 sun_hour; - msg->getString("RegionInfo", "SimName", sim_name); - msg->getU32("RegionInfo", "RegionFlags", region_flags); - msg->getU8("RegionInfo", "MaxAgents", agent_limit); - msg->getF32("RegionInfo", "ObjectBonusFactor", object_bonus_factor); - msg->getU8("RegionInfo", "SimAccess", sim_access); - msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height); - msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, terrain_raise_limit); - msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, terrain_lower_limit); - msg->getBOOL("RegionInfo", "UseEstateSun", use_estate_sun); - // actually the "last set" sun hour, not the current sun hour. JC - msg->getF32("RegionInfo", "SunHour", sun_hour); - // the only reasonable way to decide if we actually have any data is to - // check to see if any of these fields have nonzero sizes - if (msg->getSize("RegionInfo2", "ProductSKU") > 0 || - msg->getSize("RegionInfo2", "ProductName") > 0) - { - msg->getString("RegionInfo2", "ProductName", sim_type); - } - - // GENERAL PANEL - panel = tab->getChild("General"); - panel->childSetValue("region_text", LLSD(sim_name)); - panel->childSetValue("region_type", LLSD(sim_type)); - panel->childSetValue("version_channel_text", gLastVersionChannel); - - panel->childSetValue("block_terraform_check", (region_flags & REGION_FLAGS_BLOCK_TERRAFORM) ? TRUE : FALSE ); - panel->childSetValue("block_fly_check", (region_flags & REGION_FLAGS_BLOCK_FLY) ? TRUE : FALSE ); - panel->childSetValue("allow_damage_check", (region_flags & REGION_FLAGS_ALLOW_DAMAGE) ? TRUE : FALSE ); - panel->childSetValue("restrict_pushobject", (region_flags & REGION_FLAGS_RESTRICT_PUSHOBJECT) ? TRUE : FALSE ); - panel->childSetValue("allow_land_resell_check", (region_flags & REGION_FLAGS_BLOCK_LAND_RESELL) ? FALSE : TRUE ); - panel->childSetValue("allow_parcel_changes_check", (region_flags & REGION_FLAGS_ALLOW_PARCEL_CHANGES) ? TRUE : FALSE ); - panel->childSetValue("block_parcel_search_check", (region_flags & REGION_FLAGS_BLOCK_PARCEL_SEARCH) ? TRUE : FALSE ); - panel->childSetValue("agent_limit_spin", LLSD((F32)agent_limit) ); - panel->childSetValue("object_bonus_spin", LLSD(object_bonus_factor) ); - panel->childSetValue("access_combo", LLSD(sim_access) ); - - - // detect teen grid for maturity - - U32 parent_estate_id; - msg->getU32("RegionInfo", "ParentEstateID", parent_estate_id); - BOOL teen_grid = (parent_estate_id == 5); // *TODO add field to estate table and test that - panel->childSetEnabled("access_combo", gAgent.isGodlike() || (region && region->canManageEstate() && !teen_grid)); - panel->setCtrlsEnabled(allow_modify); - - // RegionSettings PANEL - panel = tab->getChild("RegionSettings"); - panel->setCtrlsEnabled(allow_modify); - - // DEBUG PANEL - panel = tab->getChild("Debug"); - - panel->childSetValue("region_text", LLSD(sim_name) ); - panel->childSetValue("disable_scripts_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_SCRIPTS)) ); - panel->childSetValue("disable_collisions_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_COLLISIONS)) ); - panel->childSetValue("disable_physics_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_PHYSICS)) ); - panel->setCtrlsEnabled(allow_modify); - - // TERRAIN PANEL - panel = tab->getChild("Terrain"); - - panel->childSetValue("region_text", LLSD(sim_name)); - panel->childSetValue("water_height_spin", LLSD(water_height)); - panel->childSetValue("terrain_raise_spin", LLSD(terrain_raise_limit)); - panel->childSetValue("terrain_lower_spin", LLSD(terrain_lower_limit)); - panel->childSetValue("use_estate_sun_check", LLSD(use_estate_sun)); - - panel->childSetValue("fixed_sun_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SUN_FIXED))); - panel->childSetEnabled("fixed_sun_check", allow_modify && !use_estate_sun); - panel->childSetValue("sun_hour_slider", LLSD(sun_hour)); - panel->childSetEnabled("sun_hour_slider", allow_modify && !use_estate_sun); - panel->setCtrlsEnabled(allow_modify); - - getInstance()->refreshFromRegion( gAgent.getRegion() ); -} - -// static -LLPanelEstateInfo* LLFloaterRegionInfo::getPanelEstate() -{ - LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); - if (!floater) return NULL; - LLTabContainer* tab = floater->getChild("region_panels"); - LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); - return panel; -} - -// static -LLPanelEstateCovenant* LLFloaterRegionInfo::getPanelCovenant() -{ - LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); - if (!floater) return NULL; - LLTabContainer* tab = floater->getChild("region_panels"); - LLPanelEstateCovenant* panel = (LLPanelEstateCovenant*)tab->getChild("Covenant"); - return panel; -} - -// static -LLPanelRegionOpenSettingsInfo* LLFloaterRegionInfo::getPanelOpenSettings() -{ - LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); - if (floater) - { - LLTabContainer* tab = floater->getChild("region_panels"); - LLPanelRegionOpenSettingsInfo* panel = (LLPanelRegionOpenSettingsInfo*)tab->getChild("RegionSettings", FALSE, FALSE); - if (panel) - { - return panel; - } - } - return NULL; -} - -void LLFloaterRegionInfo::refreshFromRegion(LLViewerRegion* region) -{ - // call refresh from region on all panels - std::for_each( - mInfoPanels.begin(), - mInfoPanels.end(), - llbind2nd( -#if LL_WINDOWS - std::mem_fun1(&LLPanelRegionInfo::refreshFromRegion), -#else - std::mem_fun(&LLPanelRegionInfo::refreshFromRegion), -#endif - region)); -} - -// public -void LLFloaterRegionInfo::refresh() -{ - for(info_panels_t::iterator iter = mInfoPanels.begin(); - iter != mInfoPanels.end(); ++iter) - { - (*iter)->refresh(); - } -} - - -///---------------------------------------------------------------------------- -/// Local class implementation -///---------------------------------------------------------------------------- - -// -// LLPanelRegionInfo -// - -// static -void LLPanelRegionInfo::onBtnSet(void* user_data) -{ - LLPanelRegionInfo* panel = (LLPanelRegionInfo*)user_data; - if(!panel) return; - if (panel->sendUpdate()) - { - panel->disableButton("apply_btn"); - } -} - -//static -void LLPanelRegionInfo::onChangeChildCtrl(LLUICtrl* ctrl, void* user_data) -{ - if (ctrl) - { - LLPanelRegionInfo* panel = (LLPanelRegionInfo*) ctrl->getParent(); - panel->updateChild(ctrl); - } -} - -// static -// Enables the "set" button if it is not already enabled -void LLPanelRegionInfo::onChangeAnything(LLUICtrl* ctrl, void* user_data) -{ - LLPanelRegionInfo* panel = (LLPanelRegionInfo*)user_data; - if(panel) - { - panel->enableButton("apply_btn"); - panel->refresh(); - } -} - -// static -// Enables set button on change to line editor -void LLPanelRegionInfo::onChangeText(LLLineEditor* caller, void* user_data) -{ - // reuse the previous method - onChangeAnything(0, user_data); -} - - -// virtual -BOOL LLPanelRegionInfo::postBuild() -{ - childSetAction("apply_btn", onBtnSet, this); - childDisable("apply_btn"); - refresh(); - return TRUE; -} - -// virtual -void LLPanelRegionInfo::updateChild(LLUICtrl* child_ctr) -{ -} - -// virtual -bool LLPanelRegionInfo::refreshFromRegion(LLViewerRegion* region) -{ - if (region) mHost = region->getHost(); - return true; -} - -void LLPanelRegionInfo::sendEstateOwnerMessage( - LLMessageSystem* msg, - const std::string& request, - const LLUUID& invoice, - const strings_t& strings) -{ - llinfos << "Sending estate request '" << request << "'" << llendl; - msg->newMessage("EstateOwnerMessage"); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used - msg->nextBlock("MethodData"); - msg->addString("Method", request); - msg->addUUID("Invoice", invoice); - if(strings.empty()) - { - msg->nextBlock("ParamList"); - msg->addString("Parameter", NULL); - } - else - { - strings_t::const_iterator it = strings.begin(); - strings_t::const_iterator end = strings.end(); - for(; it != end; ++it) - { - msg->nextBlock("ParamList"); - msg->addString("Parameter", *it); - } - } - msg->sendReliable(mHost); -} - -void LLPanelRegionInfo::enableButton(const std::string& btn_name, BOOL enable) -{ - childSetEnabled(btn_name, enable); -} - -void LLPanelRegionInfo::disableButton(const std::string& btn_name) -{ - childDisable(btn_name); -} - -void LLPanelRegionInfo::initCtrl(const std::string& name) -{ - childSetCommitCallback(name, onChangeAnything, this); -} - -void LLPanelRegionInfo::initHelpBtn(const std::string& name, const std::string& xml_alert) -{ - childSetAction(name, onClickHelp, new std::string(xml_alert)); -} - -// static -void LLPanelRegionInfo::onClickHelp(void* data) -{ - std::string* xml_alert = (std::string*)data; - LLNotifications::instance().add(*xml_alert); -} - -///////////////////////////////////////////////////////////////////////////// -// LLPanelRegionGeneralInfo -// -bool LLPanelRegionGeneralInfo::refreshFromRegion(LLViewerRegion* region) -{ - BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); - setCtrlsEnabled(allow_modify); - childDisable("apply_btn"); - childSetEnabled("access_text", allow_modify); - // childSetEnabled("access_combo", allow_modify); - // now set in processRegionInfo for teen grid detection - childSetEnabled("kick_btn", allow_modify); - childSetEnabled("kick_all_btn", allow_modify); - childSetEnabled("im_btn", allow_modify); - childSetEnabled("manage_telehub_btn", allow_modify); - - // Data gets filled in by processRegionInfo - - return LLPanelRegionInfo::refreshFromRegion(region); -} - -BOOL LLPanelRegionGeneralInfo::postBuild() -{ - // Enable the "Apply" button if something is changed. JC - initCtrl("block_terraform_check"); - initCtrl("block_fly_check"); - initCtrl("allow_damage_check"); - initCtrl("allow_land_resell_check"); - initCtrl("allow_parcel_changes_check"); - initCtrl("agent_limit_spin"); - initCtrl("object_bonus_spin"); - initCtrl("access_combo"); - initCtrl("restrict_pushobject"); - initCtrl("block_parcel_search_check"); - initCtrl("minimum_agent_age"); - - initHelpBtn("terraform_help", "HelpRegionBlockTerraform"); - initHelpBtn("fly_help", "HelpRegionBlockFly"); - initHelpBtn("damage_help", "HelpRegionAllowDamage"); - initHelpBtn("agent_limit_help", "HelpRegionAgentLimit"); - initHelpBtn("object_bonus_help", "HelpRegionObjectBonus"); - initHelpBtn("access_help", "HelpRegionMaturity"); - initHelpBtn("restrict_pushobject_help", "HelpRegionRestrictPushObject"); - initHelpBtn("land_resell_help", "HelpRegionLandResell"); - initHelpBtn("parcel_changes_help", "HelpParcelChanges"); - initHelpBtn("parcel_search_help", "HelpRegionSearch"); - - childSetAction("kick_btn", onClickKick, this); - childSetAction("kick_all_btn", onClickKickAll, this); - childSetAction("im_btn", onClickMessage, this); - childSetAction("manage_telehub_btn", onClickManageTelehub, this); - - return LLPanelRegionInfo::postBuild(); -} - -// static -void LLPanelRegionGeneralInfo::onClickKick(void* userdata) -{ - llinfos << "LLPanelRegionGeneralInfo::onClickKick" << llendl; - LLPanelRegionGeneralInfo* panelp = (LLPanelRegionGeneralInfo*)userdata; - - // this depends on the grandparent view being a floater - // in order to set up floater dependency - LLFloater* parent_floater = gFloaterView->getParentFloater(panelp); - LLFloater* child_floater = LLFloaterAvatarPicker::show(onKickCommit, userdata, FALSE, TRUE); - parent_floater->addDependentFloater(child_floater); -} - -// static -void LLPanelRegionGeneralInfo::onKickCommit(const std::vector& names, const std::vector& ids, void* userdata) -{ - if (names.empty() || ids.empty()) return; - if(ids[0].notNull()) - { - LLPanelRegionGeneralInfo* self = (LLPanelRegionGeneralInfo*)userdata; - if(!self) return; - strings_t strings; - // [0] = our agent id - // [1] = target agent id - std::string buffer; - gAgent.getID().toString(buffer); - strings.push_back(buffer); - - ids[0].toString(buffer); - strings.push_back(strings_t::value_type(buffer)); - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - self->sendEstateOwnerMessage(gMessageSystem, "teleporthomeuser", invoice, strings); - } -} - -// static -void LLPanelRegionGeneralInfo::onClickKickAll(void* userdata) -{ - llinfos << "LLPanelRegionGeneralInfo::onClickKickAll" << llendl; - LLNotifications::instance().add("KickUsersFromRegion", - LLSD(), - LLSD(), - boost::bind(&LLPanelRegionGeneralInfo::onKickAllCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2)); -} - -bool LLPanelRegionGeneralInfo::onKickAllCommit(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option == 0) - { - strings_t strings; - // [0] = our agent id - std::string buffer; - gAgent.getID().toString(buffer); - strings.push_back(buffer); - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - // historical message name - sendEstateOwnerMessage(gMessageSystem, "teleporthomeallusers", invoice, strings); - } - return false; -} - -// static -void LLPanelRegionGeneralInfo::onClickMessage(void* userdata) -{ - llinfos << "LLPanelRegionGeneralInfo::onClickMessage" << llendl; - LLNotifications::instance().add("MessageRegion", - LLSD(), - LLSD(), - boost::bind(&LLPanelRegionGeneralInfo::onMessageCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2)); -} - -// static -bool LLPanelRegionGeneralInfo::onMessageCommit(const LLSD& notification, const LLSD& response) -{ - if(LLNotification::getSelectedOption(notification, response) != 0) return false; - - std::string text = response["message"].asString(); - if (text.empty()) return false; - - llinfos << "Message to everyone: " << text << llendl; - strings_t strings; - // [0] grid_x, unused here - // [1] grid_y, unused here - // [2] agent_id of sender - // [3] sender name - // [4] message - strings.push_back("-1"); - strings.push_back("-1"); - std::string buffer; - gAgent.getID().toString(buffer); - strings.push_back(buffer); - std::string name; - gAgent.buildFullname(name); - strings.push_back(strings_t::value_type(name)); - strings.push_back(strings_t::value_type(text)); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "simulatormessage", invoice, strings); - return false; -} - -// static -void LLPanelRegionGeneralInfo::onClickManageTelehub(void* data) -{ - LLFloaterRegionInfo::getInstance()->close(); - - LLFloaterTelehub::show(); -} - -// setregioninfo -// strings[0] = 'Y' - block terraform, 'N' - not -// strings[1] = 'Y' - block fly, 'N' - not -// strings[2] = 'Y' - allow damage, 'N' - not -// strings[3] = 'Y' - allow land sale, 'N' - not -// strings[4] = agent limit -// strings[5] = object bonus -// strings[6] = sim access (0 = unknown, 13 = PG, 21 = Mature, 42 = Adult) -// strings[7] = restrict pushobject -// strings[8] = 'Y' - allow parcel subdivide, 'N' - not -// strings[9] = 'Y' - block parcel search, 'N' - allow -BOOL LLPanelRegionGeneralInfo::sendUpdate() -{ - llinfos << "LLPanelRegionGeneralInfo::sendUpdate()" << llendl; - - // First try using a Cap. If that fails use the old method. - LLSD body; - std::string url = gAgent.getRegion()->getCapability("DispatchRegionInfo"); - if (!url.empty()) - { - body["block_terraform"] = childGetValue("block_terraform_check"); - body["block_fly"] = childGetValue("block_fly_check"); - body["allow_damage"] = childGetValue("allow_damage_check"); - body["allow_land_resell"] = childGetValue("allow_land_resell_check"); - body["agent_limit"] = childGetValue("agent_limit_spin"); - body["prim_bonus"] = childGetValue("object_bonus_spin"); - body["sim_access"] = childGetValue("access_combo"); - body["restrict_pushobject"] = childGetValue("restrict_pushobject"); - body["allow_parcel_changes"] = childGetValue("allow_parcel_changes_check"); - body["block_parcel_search"] = childGetValue("block_parcel_search_check"); - body["minimum_agent_age"] = childGetValue("minimum_agent_age"); - - LLHTTPClient::post(url, body, new LLHTTPClient::Responder()); - } - else - { - strings_t strings; - std::string buffer; - - buffer = llformat("%s", (childGetValue("block_terraform_check").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%s", (childGetValue("block_fly_check").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%s", (childGetValue("allow_damage_check").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%s", (childGetValue("allow_land_resell_check").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - F32 value = (F32)childGetValue("agent_limit_spin").asReal(); - buffer = llformat("%f", value); - strings.push_back(strings_t::value_type(buffer)); - - value = (F32)childGetValue("object_bonus_spin").asReal(); - buffer = llformat("%f", value); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%d", childGetValue("access_combo").asInteger()); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%s", (childGetValue("restrict_pushobject").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - buffer = llformat("%s", (childGetValue("allow_parcel_changes_check").asBoolean() ? "Y" : "N")); - strings.push_back(strings_t::value_type(buffer)); - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "setregioninfo", invoice, strings); - } - - // if we changed access levels, tell user about it - LLViewerRegion* region = gAgent.getRegion(); - if (region && (childGetValue("access_combo").asInteger() != region->getSimAccess()) ) - { - LLNotifications::instance().add("RegionMaturityChange"); - } - - return TRUE; -} - -///////////////////////////////////////////////////////////////////////////// -// LLPanelRegionOpenSettingsInfo -// -bool LLPanelRegionOpenSettingsInfo::refreshFromRegion(LLViewerRegion* region) -{ - // Data gets filled in by hippo manager - BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); - - childSetValue("draw_distance", gAgent.mDrawDistance); - childSetValue("force_draw_distance", gAgent.mLockedDrawDistance); - childSetValue("allow_minimap", LLSD(gHippoLimits->mAllowMinimap)); - childSetValue("allow_physical_prims", (gHippoLimits->mAllowPhysicalPrims == 1 ? TRUE : FALSE)); - childSetValue("max_drag_distance", LLSD(gHippoLimits->mMaxDragDistance)); - childSetValue("min_hole_size", LLSD(gHippoLimits->mMinHoleSize)); - childSetValue("max_hollow_size", LLSD(gHippoLimits->mMaxHollow)); - childSetValue("max_inventory_items_transfer", LLSD(gHippoLimits->mMaxInventoryItemsTransfer)); - childSetValue("max_link_count", LLSD(gHippoLimits->mMaxLinkedPrims)); - childSetValue("max_link_count_phys", LLSD(gHippoLimits->mMaxPhysLinkedPrims)); - childSetValue("max_phys_prim_scale", LLSD(gHippoLimits->mMaxPrimScale));//Todo:Fix - childSetValue("max_prim_scale", LLSD(gHippoLimits->mMaxPrimScale)); - childSetValue("min_prim_scale", LLSD(gHippoLimits->mMinPrimScale)); - childSetValue("render_water", LLSD(gHippoLimits->mRenderWater)); - childSetValue("show_tags", LLSD(gHippoLimits->mRenderName)); - childSetValue("max_groups", LLSD(gHippoLimits->mMaxAgentGroups)); - childSetValue("allow_parcel_windlight", LLSD(gHippoLimits->mAllowParcelWindLight)); - childSetValue("enable_teen_mode", LLSD(gHippoLimits->mEnableTeenMode)); - childSetValue("enforce_max_build", LLSD(gHippoLimits->mEnforceMaxBuild)); - - setCtrlsEnabled(allow_modify); - - return LLPanelRegionInfo::refreshFromRegion(region); -} - -BOOL LLPanelRegionOpenSettingsInfo::postBuild() -{ - // Enable the "Apply" button if something is changed. JC - initCtrl("draw_distance"); - initCtrl("force_draw_distance"); - initCtrl("max_drag_distance"); - initCtrl("max_prim_scale"); - initCtrl("min_prim_scale"); - initCtrl("max_phys_prim_scale"); - initCtrl("max_hollow_size"); - initCtrl("min_hole_size"); - initCtrl("max_link_count"); - initCtrl("max_link_count_phys"); - initCtrl("max_inventory_items_transfer"); - initCtrl("max_groups"); - initCtrl("render_water"); - initCtrl("allow_minimap"); - initCtrl("allow_physical_prims"); - initCtrl("enable_teen_mode"); - initCtrl("show_tags"); - initCtrl("allow_parcel_windlight"); - - initHelpBtn("force_draw_distance_help", "HelpForceDrawDistance"); - initHelpBtn("max_inventory_items_transfer_help", "HelpMaxInventoryItemsTransfer"); - initHelpBtn("max_groups_help", "HelpMaxGroups"); - initHelpBtn("render_water_help", "HelpRenderWater"); - initHelpBtn("allow_minimap_help", "HelpAllowMinimap"); - initHelpBtn("allow_physical_prims_help", "HelpAllowPhysicalPrims"); - initHelpBtn("enable_teen_mode_help", "HelpEnableTeenMode"); - initHelpBtn("show_tags_help", "HelpShowTags"); - initHelpBtn("allow_parcel_windlight_help", "HelpAllowParcelWindLight"); - - childSetAction("apply_ors_btn", onClickOrs, this); - - refreshFromRegion(gAgent.getRegion()); - - return LLPanelRegionInfo::postBuild(); -} - -// setregioninfo -// strings[0] = 'Y' - block terraform, 'N' - not -// strings[1] = 'Y' - block fly, 'N' - not -// strings[2] = 'Y' - allow damage, 'N' - not -// strings[3] = 'Y' - allow land sale, 'N' - not -// strings[4] = agent limit -// strings[5] = object bonus -// strings[6] = sim access (0 = unknown, 13 = PG, 21 = Mature, 42 = Adult) -// strings[7] = restrict pushobject -// strings[8] = 'Y' - allow parcel subdivide, 'N' - not -// strings[9] = 'Y' - block parcel search, 'N' - allow -void LLPanelRegionOpenSettingsInfo::onClickOrs(void* userdata) -{ - LLPanelRegionOpenSettingsInfo* self; - self = (LLPanelRegionOpenSettingsInfo*)userdata; - - llinfos << "LLPanelRegionOpenSettingsInfo::onClickOrs()" << llendl; - - LLSD body; - std::string url = gAgent.getRegion()->getCapability("DispatchOpenRegionSettings"); - if (!url.empty()) - { - body["draw_distance"] = self->childGetValue("draw_distance"); - body["force_draw_distance"] = self->childGetValue("force_draw_distance"); - body["allow_minimap"] = self->childGetValue("allow_minimap"); - body["allow_physical_prims"] = self->childGetValue("allow_physical_prims"); - body["max_drag_distance"] = self->childGetValue("max_drag_distance"); - body["min_hole_size"] = self->childGetValue("min_hole_size"); - body["max_hollow_size"] = self->childGetValue("max_hollow_size"); - body["max_inventory_items_transfer"] = self->childGetValue("max_inventory_items_transfer"); - body["max_link_count"] = self->childGetValue("max_link_count"); - body["max_link_count_phys"] = self->childGetValue("max_link_count_phys"); - body["max_phys_prim_scale"] = self->childGetValue("max_phys_prim_scale"); - body["max_prim_scale"] = self->childGetValue("max_prim_scale"); - body["min_prim_scale"] = self->childGetValue("min_prim_scale"); - body["render_water"] = self->childGetValue("render_water"); - body["show_tags"] = self->childGetValue("show_tags"); - body["max_groups"] = self->childGetValue("max_groups"); - body["allow_parcel_windlight"] = self->childGetValue("allow_parcel_windlight"); - body["enable_teen_mode"] = self->childGetValue("enable_teen_mode"); - body["enforce_max_build"] = self->childGetValue("enforce_max_build"); - - LLHTTPClient::post(url, body, new LLHTTPClient::Responder()); - } -} - -///////////////////////////////////////////////////////////////////////////// -// LLPanelRegionDebugInfo -///////////////////////////////////////////////////////////////////////////// -BOOL LLPanelRegionDebugInfo::postBuild() -{ - LLPanelRegionInfo::postBuild(); - initCtrl("disable_scripts_check"); - initCtrl("disable_collisions_check"); - initCtrl("disable_physics_check"); - - initHelpBtn("disable_scripts_help", "HelpRegionDisableScripts"); - initHelpBtn("disable_collisions_help", "HelpRegionDisableCollisions"); - initHelpBtn("disable_physics_help", "HelpRegionDisablePhysics"); - initHelpBtn("top_colliders_help", "HelpRegionTopColliders"); - initHelpBtn("top_scripts_help", "HelpRegionTopScripts"); - initHelpBtn("restart_help", "HelpRegionRestart"); - initHelpBtn("minimum_agent_age_help", "HelpRegionMinimumAge"); - - - childSetAction("choose_avatar_btn", onClickChooseAvatar, this); - childSetAction("return_btn", onClickReturn, this); - childSetAction("top_colliders_btn", onClickTopColliders, this); - childSetAction("top_scripts_btn", onClickTopScripts, this); - childSetAction("restart_btn", onClickRestart, this); - childSetAction("cancel_restart_btn", onClickCancelRestart, this); - - return TRUE; -} - -// virtual -bool LLPanelRegionDebugInfo::refreshFromRegion(LLViewerRegion* region) -{ - BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); - setCtrlsEnabled(allow_modify); - childDisable("apply_btn"); - childDisable("target_avatar_name"); - - childSetEnabled("choose_avatar_btn", allow_modify); - childSetEnabled("return_scripts", allow_modify && !mTargetAvatar.isNull()); - childSetEnabled("return_other_land", allow_modify && !mTargetAvatar.isNull()); - childSetEnabled("return_estate_wide", allow_modify && !mTargetAvatar.isNull()); - childSetEnabled("return_btn", allow_modify && !mTargetAvatar.isNull()); - childSetEnabled("top_colliders_btn", allow_modify); - childSetEnabled("top_scripts_btn", allow_modify); - childSetEnabled("restart_btn", allow_modify); - childSetEnabled("cancel_restart_btn", allow_modify); - - return LLPanelRegionInfo::refreshFromRegion(region); -} - -// virtual -BOOL LLPanelRegionDebugInfo::sendUpdate() -{ - llinfos << "LLPanelRegionDebugInfo::sendUpdate" << llendl; - strings_t strings; - std::string buffer; - - buffer = llformat("%s", (childGetValue("disable_scripts_check").asBoolean() ? "Y" : "N")); - strings.push_back(buffer); - - buffer = llformat("%s", (childGetValue("disable_collisions_check").asBoolean() ? "Y" : "N")); - strings.push_back(buffer); - - buffer = llformat("%s", (childGetValue("disable_physics_check").asBoolean() ? "Y" : "N")); - strings.push_back(buffer); - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "setregiondebug", invoice, strings); - return TRUE; -} - -void LLPanelRegionDebugInfo::onClickChooseAvatar(void* data) -{ - LLFloaterAvatarPicker::show(callbackAvatarID, data, FALSE, TRUE); -} - -// static -void LLPanelRegionDebugInfo::callbackAvatarID(const std::vector& names, const std::vector& ids, void* data) -{ - LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*) data; - if (ids.empty() || names.empty()) return; - self->mTargetAvatar = ids[0]; - self->childSetValue("target_avatar_name", LLSD(names[0])); - self->refreshFromRegion( gAgent.getRegion() ); -} - -// static -void LLPanelRegionDebugInfo::onClickReturn(void* data) -{ - LLPanelRegionDebugInfo* panelp = (LLPanelRegionDebugInfo*) data; - if (panelp->mTargetAvatar.isNull()) return; - - LLSD args; - args["USER_NAME"] = panelp->childGetValue("target_avatar_name").asString(); - LLSD payload; - payload["avatar_id"] = panelp->mTargetAvatar; - - U32 flags = SWD_ALWAYS_RETURN_OBJECTS; - - if (panelp->childGetValue("return_scripts").asBoolean()) - { - flags |= SWD_SCRIPTED_ONLY; - } - - if (panelp->childGetValue("return_other_land").asBoolean()) - { - flags |= SWD_OTHERS_LAND_ONLY; - } - payload["flags"] = int(flags); - payload["return_estate_wide"] = panelp->childGetValue("return_estate_wide").asBoolean(); - LLNotifications::instance().add("EstateObjectReturn", args, payload, - boost::bind(&LLPanelRegionDebugInfo::callbackReturn, panelp, _1, _2)); -} - -bool LLPanelRegionDebugInfo::callbackReturn(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) return false; - - LLUUID target_avatar = notification["payload"]["avatar_id"].asUUID(); - if (!target_avatar.isNull()) - { - U32 flags = notification["payload"]["flags"].asInteger(); - bool return_estate_wide = notification["payload"]["return_estate_wide"]; - if (return_estate_wide) - { - // send as estate message - routed by spaceserver to all regions in estate - strings_t strings; - strings.push_back(llformat("%d", flags)); - strings.push_back(target_avatar.asString()); - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - - sendEstateOwnerMessage(gMessageSystem, "estateobjectreturn", invoice, strings); - } - else - { - // send to this simulator only - send_sim_wide_deletes(target_avatar, flags); - } - } - return false; -} - - -// static -void LLPanelRegionDebugInfo::onClickTopColliders(void* data) -{ - LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; - strings_t strings; - strings.push_back("1"); // one physics step - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - LLFloaterTopObjects::show(); - LLFloaterTopObjects::clearList(); - self->sendEstateOwnerMessage(gMessageSystem, "colliders", invoice, strings); -} - -// static -void LLPanelRegionDebugInfo::onClickTopScripts(void* data) -{ - LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; - strings_t strings; - strings.push_back("6"); // top 5 scripts - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - LLFloaterTopObjects::show(); - LLFloaterTopObjects::clearList(); - self->sendEstateOwnerMessage(gMessageSystem, "scripts", invoice, strings); -} - -// static -void LLPanelRegionDebugInfo::onClickRestart(void* data) -{ - LLNotifications::instance().add("ConfirmRestart", LLSD(), LLSD(), - boost::bind(&LLPanelRegionDebugInfo::callbackRestart, (LLPanelRegionDebugInfo*)data, _1, _2)); -} - -bool LLPanelRegionDebugInfo::callbackRestart(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) return false; - - strings_t strings; - strings.push_back("120"); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings); - return false; -} - -// static -void LLPanelRegionDebugInfo::onClickCancelRestart(void* data) -{ - LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; - strings_t strings; - strings.push_back("-1"); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - self->sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings); -} - - -///////////////////////////////////////////////////////////////////////////// -// LLPanelRegionTextureInfo -// -LLPanelRegionTextureInfo::LLPanelRegionTextureInfo() : LLPanelRegionInfo() -{ - // nothing. -} - -bool LLPanelRegionTextureInfo::refreshFromRegion(LLViewerRegion* region) -{ - BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); - setCtrlsEnabled(allow_modify); - childDisable("apply_btn"); - - if (region) - { - childSetValue("region_text", LLSD(region->getName())); - } - else - { - childSetValue("region_text", LLSD("")); - } - - if (!region) return LLPanelRegionInfo::refreshFromRegion(region); - - LLVLComposition* compp = region->getComposition(); - LLTextureCtrl* texture_ctrl; - std::string buffer; - for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) - { - buffer = llformat("texture_detail_%d", i); - texture_ctrl = getChild(buffer); - if(texture_ctrl) - { - lldebugs << "Detail Texture " << i << ": " - << compp->getDetailTextureID(i) << llendl; - LLUUID tmp_id(compp->getDetailTextureID(i)); - texture_ctrl->setImageAssetID(tmp_id); - } - } - - for(S32 i = 0; i < CORNER_COUNT; ++i) - { - buffer = llformat("height_start_spin_%d", i); - childSetValue(buffer, LLSD(compp->getStartHeight(i))); - buffer = llformat("height_range_spin_%d", i); - childSetValue(buffer, LLSD(compp->getHeightRange(i))); - } - - // Call the parent for common book-keeping - return LLPanelRegionInfo::refreshFromRegion(region); -} - - -BOOL LLPanelRegionTextureInfo::postBuild() -{ - LLPanelRegionInfo::postBuild(); - std::string buffer; - for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) - { - buffer = llformat("texture_detail_%d", i); - initCtrl(buffer); - } - - for(S32 i = 0; i < CORNER_COUNT; ++i) - { - buffer = llformat("height_start_spin_%d", i); - initCtrl(buffer); - buffer = llformat("height_range_spin_%d", i); - initCtrl(buffer); - } - -// LLButton* btn = new LLButton("dump", LLRect(0, 20, 100, 0), "", onClickDump, this); -// btn->setFollows(FOLLOWS_TOP|FOLLOWS_LEFT); -// addChild(btn); - - return LLPanelRegionInfo::postBuild(); -} - -BOOL LLPanelRegionTextureInfo::sendUpdate() -{ - llinfos << "LLPanelRegionTextureInfo::sendUpdate()" << llendl; - - // Make sure user hasn't chosen wacky textures. - //if (!validateTextureSizes()) - //{ - // return FALSE; - //} - - LLTextureCtrl* texture_ctrl; - std::string buffer; - std::string id_str; - LLMessageSystem* msg = gMessageSystem; - strings_t strings; - - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - - for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) - { - buffer = llformat("texture_detail_%d", i); - texture_ctrl = getChild(buffer); - if(texture_ctrl) - { - LLUUID tmp_id(texture_ctrl->getImageAssetID()); - tmp_id.toString(id_str); - buffer = llformat("%d %s", i, id_str.c_str()); - strings.push_back(buffer); - } - } - sendEstateOwnerMessage(msg, "texturedetail", invoice, strings); - strings.clear(); - for(S32 i = 0; i < CORNER_COUNT; ++i) - { - buffer = llformat("height_start_spin_%d", i); - std::string buffer2 = llformat("height_range_spin_%d", i); - std::string buffer3 = llformat("%d %f %f", i, (F32)childGetValue(buffer).asReal(), (F32)childGetValue(buffer2).asReal()); - strings.push_back(buffer3); - } - sendEstateOwnerMessage(msg, "textureheights", invoice, strings); - strings.clear(); - sendEstateOwnerMessage(msg, "texturecommit", invoice, strings); - return TRUE; -} - -BOOL LLPanelRegionTextureInfo::validateTextureSizes() -{ - for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) - { - std::string buffer; - buffer = llformat("texture_detail_%d", i); - LLTextureCtrl* texture_ctrl = getChild(buffer); - if (!texture_ctrl) continue; - - LLUUID image_asset_id = texture_ctrl->getImageAssetID(); - LLViewerImage* img = gImageList.getImage(image_asset_id); - S32 components = img->getComponents(); - // Must ask for highest resolution version's width. JC - S32 width = img->getWidth(0); - S32 height = img->getHeight(0); - - //llinfos << "texture detail " << i << " is " << width << "x" << height << "x" << components << llendl; - - if (components != 3) - { - LLSD args; - args["TEXTURE_NUM"] = i+1; - args["TEXTURE_BIT_DEPTH"] = llformat("%d",components * 8); - LLNotifications::instance().add("InvalidTerrainBitDepth", args); - return FALSE; - } - - if (width > 512 || height > 512) - { - - LLSD args; - args["TEXTURE_NUM"] = i+1; - args["TEXTURE_SIZE_X"] = width; - args["TEXTURE_SIZE_Y"] = height; - LLNotifications::instance().add("InvalidTerrainSize", args); - return FALSE; - - } - } - - return TRUE; -} - - -// static -void LLPanelRegionTextureInfo::onClickDump(void* data) -{ - llinfos << "LLPanelRegionTextureInfo::onClickDump()" << llendl; -} - - -///////////////////////////////////////////////////////////////////////////// -// LLPanelRegionTerrainInfo -///////////////////////////////////////////////////////////////////////////// -BOOL LLPanelRegionTerrainInfo::postBuild() -{ - LLPanelRegionInfo::postBuild(); - - initHelpBtn("water_height_help", "HelpRegionWaterHeight"); - initHelpBtn("terrain_raise_help", "HelpRegionTerrainRaise"); - initHelpBtn("terrain_lower_help", "HelpRegionTerrainLower"); - initHelpBtn("upload_raw_help", "HelpRegionUploadRaw"); - initHelpBtn("download_raw_help", "HelpRegionDownloadRaw"); - initHelpBtn("use_estate_sun_help", "HelpRegionUseEstateSun"); - initHelpBtn("fixed_sun_help", "HelpRegionFixedSun"); - initHelpBtn("bake_terrain_help", "HelpRegionBakeTerrain"); - - initCtrl("water_height_spin"); - initCtrl("terrain_raise_spin"); - initCtrl("terrain_lower_spin"); - - initCtrl("fixed_sun_check"); - childSetCommitCallback("fixed_sun_check", onChangeFixedSun, this); - childSetCommitCallback("use_estate_sun_check", onChangeUseEstateTime, this); - childSetCommitCallback("sun_hour_slider", onChangeSunHour, this); - - childSetAction("download_raw_btn", onClickDownloadRaw, this); - childSetAction("upload_raw_btn", onClickUploadRaw, this); - childSetAction("bake_terrain_btn", onClickBakeTerrain, this); - - return TRUE; -} - -// virtual -bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region) -{ - llinfos << "LLPanelRegionTerrainInfo::refreshFromRegion" << llendl; - - BOOL owner_or_god = gAgent.isGodlike() - || (region && (region->getOwner() == gAgent.getID())); - BOOL owner_or_god_or_manager = owner_or_god - || (region && region->isEstateManager()); - setCtrlsEnabled(owner_or_god_or_manager); - childDisable("apply_btn"); - - childSetEnabled("download_raw_btn", owner_or_god); - childSetEnabled("upload_raw_btn", owner_or_god); - childSetEnabled("bake_terrain_btn", owner_or_god); - - return LLPanelRegionInfo::refreshFromRegion(region); -} - -// virtual -BOOL LLPanelRegionTerrainInfo::sendUpdate() -{ - llinfos << "LLPanelRegionTerrainInfo::sendUpdate" << llendl; - std::string buffer; - strings_t strings; - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - - buffer = llformat("%f", (F32)childGetValue("water_height_spin").asReal()); - strings.push_back(buffer); - buffer = llformat("%f", (F32)childGetValue("terrain_raise_spin").asReal()); - strings.push_back(buffer); - buffer = llformat("%f", (F32)childGetValue("terrain_lower_spin").asReal()); - strings.push_back(buffer); - buffer = llformat("%s", (childGetValue("use_estate_sun_check").asBoolean() ? "Y" : "N")); - strings.push_back(buffer); - buffer = llformat("%s", (childGetValue("fixed_sun_check").asBoolean() ? "Y" : "N")); - strings.push_back(buffer); - buffer = llformat("%f", (F32)childGetValue("sun_hour_slider").asReal() ); - strings.push_back(buffer); - - // Grab estate information in case the user decided to set the - // region back to estate time. JC - LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); - if (!floater) return true; - - LLTabContainer* tab = floater->getChild("region_panels"); - if (!tab) return true; - - LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); - if (!panel) return true; - - BOOL estate_global_time = panel->getGlobalTime(); - BOOL estate_fixed_sun = panel->getFixedSun(); - F32 estate_sun_hour; - if (estate_global_time) - { - estate_sun_hour = 0.f; - } - else - { - estate_sun_hour = panel->getSunHour(); - } - - buffer = llformat("%s", (estate_global_time ? "Y" : "N") ); - strings.push_back(buffer); - buffer = llformat("%s", (estate_fixed_sun ? "Y" : "N") ); - strings.push_back(buffer); - buffer = llformat("%f", estate_sun_hour); - strings.push_back(buffer); - - sendEstateOwnerMessage(gMessageSystem, "setregionterrain", invoice, strings); - return TRUE; -} - -// static -void LLPanelRegionTerrainInfo::onChangeUseEstateTime(LLUICtrl* ctrl, void* user_data) -{ - LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) user_data; - if (!panel) return; - BOOL use_estate_sun = panel->childGetValue("use_estate_sun_check").asBoolean(); - panel->childSetEnabled("fixed_sun_check", !use_estate_sun); - panel->childSetEnabled("sun_hour_slider", !use_estate_sun); - if (use_estate_sun) - { - panel->childSetValue("fixed_sun_check", LLSD(FALSE)); - panel->childSetValue("sun_hour_slider", LLSD(0.f)); - } - panel->childEnable("apply_btn"); -} - -// static -void LLPanelRegionTerrainInfo::onChangeFixedSun(LLUICtrl* ctrl, void* user_data) -{ - LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) user_data; - if (!panel) return; - // Just enable the apply button. We let the sun-hour slider be enabled - // for both fixed-sun and non-fixed-sun. JC - panel->childEnable("apply_btn"); -} - -// static -void LLPanelRegionTerrainInfo::onChangeSunHour(LLUICtrl* ctrl, void*) -{ - // can't use userdata to get panel, slider uses it internally - LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) ctrl->getParent(); - if (!panel) return; - panel->childEnable("apply_btn"); -} - -// static -void LLPanelRegionTerrainInfo::onClickDownloadRaw(void* data) -{ - LLFilePicker& picker = LLFilePicker::instance(); - if (!picker.getSaveFile(LLFilePicker::FFSAVE_RAW, "terrain.raw")) - { - llwarns << "No file" << llendl; - return; - } - std::string filepath = picker.getFirstFile(); - gXferManager->expectFileForRequest(filepath); - - LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data; - strings_t strings; - strings.push_back("download filename"); - strings.push_back(filepath); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); -} - -// static -void LLPanelRegionTerrainInfo::onClickUploadRaw(void* data) -{ - LLFilePicker& picker = LLFilePicker::instance(); - if (!picker.getOpenFile(LLFilePicker::FFLOAD_RAW)) - { - llwarns << "No file" << llendl; - return; - } - std::string filepath = picker.getFirstFile(); - gXferManager->expectFileForTransfer(filepath); - - LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data; - strings_t strings; - strings.push_back("upload filename"); - strings.push_back(filepath); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); - - LLNotifications::instance().add("RawUploadStarted"); -} - -// static -void LLPanelRegionTerrainInfo::onClickBakeTerrain(void* data) -{ - LLNotifications::instance().add( - LLNotification::Params("ConfirmBakeTerrain") - .functor(boost::bind(&LLPanelRegionTerrainInfo::callbackBakeTerrain, (LLPanelRegionTerrainInfo*)data, _1, _2))); -} - -bool LLPanelRegionTerrainInfo::callbackBakeTerrain(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) return false; - - strings_t strings; - strings.push_back("bake"); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); - return false; -} - -///////////////////////////////////////////////////////////////////////////// -// LLPanelEstateInfo -// - -LLPanelEstateInfo::LLPanelEstateInfo() -: LLPanelRegionInfo(), - mEstateID(0) // invalid -{ -} - -// static -void LLPanelEstateInfo::initDispatch(LLDispatcher& dispatch) -{ - std::string name; - -// name.assign("setowner"); -// static LLDispatchSetEstateOwner set_owner; -// dispatch.addHandler(name, &set_owner); - - name.assign("estateupdateinfo"); - static LLDispatchEstateUpdateInfo estate_update_info; - dispatch.addHandler(name, &estate_update_info); - - name.assign("setaccess"); - static LLDispatchSetEstateAccess set_access; - dispatch.addHandler(name, &set_access); - - estate_dispatch_initialized = true; -} - -// static -// Disables the sun-hour slider and the use fixed time check if the use global time is check -void LLPanelEstateInfo::onChangeUseGlobalTime(LLUICtrl* ctrl, void* user_data) -{ - LLPanelEstateInfo* panel = (LLPanelEstateInfo*) user_data; - if (panel) - { - bool enabled = !panel->childGetValue("use_global_time_check").asBoolean(); - panel->childSetEnabled("sun_hour_slider", enabled); - panel->childSetEnabled("fixed_sun_check", enabled); - panel->childSetValue("fixed_sun_check", LLSD(FALSE)); - panel->enableButton("apply_btn"); - } -} - -// Enables the sun-hour slider if the fixed-sun checkbox is set -void LLPanelEstateInfo::onChangeFixedSun(LLUICtrl* ctrl, void* user_data) -{ - LLPanelEstateInfo* panel = (LLPanelEstateInfo*) user_data; - if (panel) - { - bool enabled = !panel->childGetValue("fixed_sun_check").asBoolean(); - panel->childSetEnabled("use_global_time_check", enabled); - panel->childSetValue("use_global_time_check", LLSD(FALSE)); - panel->enableButton("apply_btn"); - } -} - - - - -//--------------------------------------------------------------------------- -// Add/Remove estate access button callbacks -//--------------------------------------------------------------------------- -void LLPanelEstateInfo::onClickEditSky(void* user_data) -{ - LLFloaterWindLight::show(); -} - -void LLPanelEstateInfo::onClickEditDayCycle(void* user_data) -{ - LLFloaterDayCycle::show(); -} - -// static -void LLPanelEstateInfo::onClickAddAllowedAgent(void* user_data) -{ - LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; - LLCtrlListInterface *list = self->childGetListInterface("allowed_avatar_name_list"); - if (!list) return; - if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) - { - //args - - LLSD args; - args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); - LLNotifications::instance().add("MaxAllowedAgentOnRegion", args); - return; - } - accessAddCore(ESTATE_ACCESS_ALLOWED_AGENT_ADD, "EstateAllowedAgentAdd"); -} - -// static -void LLPanelEstateInfo::onClickRemoveAllowedAgent(void* user_data) -{ - accessRemoveCore(ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, "EstateAllowedAgentRemove", "allowed_avatar_name_list"); -} - -// static -void LLPanelEstateInfo::onClickAddAllowedGroup(void* user_data) -{ - LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; - LLCtrlListInterface *list = self->childGetListInterface("allowed_group_name_list"); - if (!list) return; - if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) - { - LLSD args; - args["MAX_GROUPS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); - LLNotifications::instance().add("MaxAllowedGroupsOnRegion", args); - return; - } - - LLNotification::Params params("ChangeLindenAccess"); - params.functor(boost::bind(&LLPanelEstateInfo::addAllowedGroup, self, _1, _2)); - if (isLindenEstate()) - { - LLNotifications::instance().add(params); - } - else - { - LLNotifications::instance().forceResponse(params, 0); - } -} - -bool LLPanelEstateInfo::addAllowedGroup(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) return false; - - LLFloater* parent_floater = gFloaterView->getParentFloater(this); - - LLFloaterGroupPicker* widget; - widget = LLFloaterGroupPicker::showInstance(LLSD(gAgent.getID())); - if (widget) - { - widget->setSelectCallback(addAllowedGroup2, NULL); - if (parent_floater) - { - LLRect new_rect = gFloaterView->findNeighboringPosition(parent_floater, widget); - widget->setOrigin(new_rect.mLeft, new_rect.mBottom); - parent_floater->addDependentFloater(widget); - } - } - - return false; -} - -// static -void LLPanelEstateInfo::onClickRemoveAllowedGroup(void* user_data) -{ - accessRemoveCore(ESTATE_ACCESS_ALLOWED_GROUP_REMOVE, "EstateAllowedGroupRemove", "allowed_group_name_list"); -} - -// static -void LLPanelEstateInfo::onClickAddBannedAgent(void* user_data) -{ - LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; - LLCtrlListInterface *list = self->childGetListInterface("banned_avatar_name_list"); - if (!list) return; - if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) - { - LLSD args; - args["MAX_BANNED"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); - LLNotifications::instance().add("MaxBannedAgentsOnRegion", args); - return; - } - accessAddCore(ESTATE_ACCESS_BANNED_AGENT_ADD, "EstateBannedAgentAdd"); -} - -// static -void LLPanelEstateInfo::onClickRemoveBannedAgent(void* user_data) -{ - accessRemoveCore(ESTATE_ACCESS_BANNED_AGENT_REMOVE, "EstateBannedAgentRemove", "banned_avatar_name_list"); -} - -// static -void LLPanelEstateInfo::onClickAddEstateManager(void* user_data) -{ - LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; - LLCtrlListInterface *list = self->childGetListInterface("estate_manager_name_list"); - if (!list) return; - if (list->getItemCount() >= ESTATE_MAX_MANAGERS) - { // Tell user they can't add more managers - LLSD args; - args["MAX_MANAGER"] = llformat("%d",ESTATE_MAX_MANAGERS); - LLNotifications::instance().add("MaxManagersOnRegion", args); - } - else - { // Go pick managers to add - accessAddCore(ESTATE_ACCESS_MANAGER_ADD, "EstateManagerAdd"); - } -} - -// static -void LLPanelEstateInfo::onClickRemoveEstateManager(void* user_data) -{ - accessRemoveCore(ESTATE_ACCESS_MANAGER_REMOVE, "EstateManagerRemove", "estate_manager_name_list"); -} - -//--------------------------------------------------------------------------- -// Kick from estate methods -//--------------------------------------------------------------------------- -struct LLKickFromEstateInfo -{ - LLPanelEstateInfo *mEstatePanelp; - LLUUID mAgentID; -}; - -void LLPanelEstateInfo::onClickKickUser(void *user_data) -{ - LLPanelEstateInfo* panelp = (LLPanelEstateInfo*)user_data; - - // this depends on the grandparent view being a floater - // in order to set up floater dependency - LLFloater* parent_floater = gFloaterView->getParentFloater(panelp); - LLFloater* child_floater = LLFloaterAvatarPicker::show(LLPanelEstateInfo::onKickUserCommit, user_data, FALSE, TRUE); - parent_floater->addDependentFloater(child_floater); -} - -void LLPanelEstateInfo::onKickUserCommit(const std::vector& names, const std::vector& ids, void* userdata) -{ - if (names.empty() || ids.empty()) return; - - //check to make sure there is one valid user and id - if( (ids[0].isNull()) || - (names[0].length() == 0) ) - { - return; - } - - LLPanelEstateInfo* self = (LLPanelEstateInfo*)userdata; - if(!self) return; - - //keep track of what user they want to kick and other misc info - LLKickFromEstateInfo *kick_info = new LLKickFromEstateInfo(); - kick_info->mEstatePanelp = self; - kick_info->mAgentID = ids[0]; - - //Bring up a confirmation dialog - LLSD args; - args["EVIL_USER"] = names[0]; - LLSD payload; - payload["agent_id"] = ids[0]; - LLNotifications::instance().add("EstateKickUser", args, payload, boost::bind(&LLPanelEstateInfo::kickUserConfirm, self, _1, _2)); - -} - -bool LLPanelEstateInfo::kickUserConfirm(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - switch(option) - { - case 0: - { - //Kick User - strings_t strings; - strings.push_back(notification["payload"]["agent_id"].asString()); - - sendEstateOwnerMessage(gMessageSystem, "kickestate", LLFloaterRegionInfo::getLastInvoice(), strings); - break; - } - default: - break; - } - return false; -} - -//--------------------------------------------------------------------------- -// Core Add/Remove estate access methods -// TODO: INTERNATIONAL: don't build message text here; -// instead, create multiple translatable messages and choose -// one based on the status. -//--------------------------------------------------------------------------- -std::string all_estates_text() -{ - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return "(error)"; - - std::string owner = panel->getOwnerName(); - - LLViewerRegion* region = gAgent.getRegion(); - if (gAgent.isGodlike()) - { - return llformat("all estates\nowned by %s", owner.c_str()); - } - else if (region && region->getOwner() == gAgent.getID()) - { - return "all estates you own"; - } - else if (region && region->isEstateManager()) - { - return llformat("all estates that\nyou manage for %s", owner.c_str()); - } - else - { - return "(error)"; - } -} - -// static -bool LLPanelEstateInfo::isLindenEstate() -{ - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return false; - - U32 estate_id = panel->getEstateID(); - return (estate_id <= ESTATE_LAST_LINDEN); -} - -typedef std::vector AgentOrGroupIDsVector; -struct LLEstateAccessChangeInfo -{ - LLEstateAccessChangeInfo(const LLSD& sd) - { - mDialogName = sd["dialog_name"].asString(); - mOperationFlag = (U32)sd["operation"].asInteger(); - LLSD::array_const_iterator end_it = sd["allowed_ids"].endArray(); - for (LLSD::array_const_iterator id_it = sd["allowed_ids"].beginArray(); - id_it != end_it; - ++id_it) - { - mAgentOrGroupIDs.push_back(id_it->asUUID()); - } - } - - const LLSD asLLSD() const - { - LLSD sd; - sd["name"] = mDialogName; - sd["operation"] = (S32)mOperationFlag; - for (AgentOrGroupIDsVector::const_iterator it = mAgentOrGroupIDs.begin(); - it != mAgentOrGroupIDs.end(); - ++it) - { - sd["allowed_ids"].append(*it); - } - return sd; - } - - U32 mOperationFlag; // ESTATE_ACCESS_BANNED_AGENT_ADD, _REMOVE, etc. - std::string mDialogName; - AgentOrGroupIDsVector mAgentOrGroupIDs; // List of agent IDs to apply to this change -}; - -// Special case callback for groups, since it has different callback format than names -// static -void LLPanelEstateInfo::addAllowedGroup2(LLUUID id, void* user_data) -{ - LLSD payload; - payload["operation"] = (S32)ESTATE_ACCESS_ALLOWED_GROUP_ADD; - payload["dialog_name"] = "EstateAllowedGroupAdd"; - payload["allowed_ids"].append(id); - - LLSD args; - args["ALL_ESTATES"] = all_estates_text(); - - LLNotification::Params params("EstateAllowedGroupAdd"); - params.payload(payload) - .substitutions(args) - .functor(accessCoreConfirm); - if (isLindenEstate()) - { - LLNotifications::instance().forceResponse(params, 0); - } - else - { - LLNotifications::instance().add(params); - } -} - -// static -void LLPanelEstateInfo::accessAddCore(U32 operation_flag, const std::string& dialog_name) -{ - LLSD payload; - payload["operation"] = (S32)operation_flag; - payload["dialog_name"] = dialog_name; - // agent id filled in after avatar picker - - LLNotification::Params params("ChangeLindenAccess"); - params.payload(payload) - .functor(accessAddCore2); - - if (isLindenEstate()) - { - LLNotifications::instance().add(params); - } - else - { - // same as clicking "OK" - LLNotifications::instance().forceResponse(params, 0); - } -} - -// static -bool LLPanelEstateInfo::accessAddCore2(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) - { - // abort change - return false; - } - - LLEstateAccessChangeInfo* change_info = new LLEstateAccessChangeInfo(notification["payload"]); - // avatar picker yes multi-select, yes close-on-select - LLFloaterAvatarPicker::show(accessAddCore3, (void*)change_info, TRUE, TRUE); - return false; -} - -// static -void LLPanelEstateInfo::accessAddCore3(const std::vector& names, const std::vector& ids, void* data) -{ - LLEstateAccessChangeInfo* change_info = (LLEstateAccessChangeInfo*)data; - if (!change_info) return; - if (ids.empty()) - { - // User didn't select a name. - delete change_info; - change_info = NULL; - return; - } - // User did select a name. - change_info->mAgentOrGroupIDs = ids; - // Can't put estate owner on ban list - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return; - LLViewerRegion* region = gAgent.getRegion(); - if (!region) return; - - if (change_info->mOperationFlag & ESTATE_ACCESS_ALLOWED_AGENT_ADD) - { - LLCtrlListInterface *list = panel->childGetListInterface("allowed_avatar_name_list"); - int currentCount = (list ? list->getItemCount() : 0); - if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS) - { - LLSD args; - args["NUM_ADDED"] = llformat("%d",ids.size()); - args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); - args["LIST_TYPE"] = "Allowed Residents"; - args["NUM_EXCESS"] = llformat("%d",(ids.size()+currentCount)-ESTATE_MAX_ACCESS_IDS); - LLNotifications::instance().add("MaxAgentOnRegionBatch", args); - delete change_info; - return; - } - } - if (change_info->mOperationFlag & ESTATE_ACCESS_BANNED_AGENT_ADD) - { - LLCtrlListInterface *list = panel->childGetListInterface("banned_avatar_name_list"); - int currentCount = (list ? list->getItemCount() : 0); - if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS) - { - LLSD args; - args["NUM_ADDED"] = llformat("%d",ids.size()); - args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); - args["LIST_TYPE"] = "Banned Residents"; - args["NUM_EXCESS"] = llformat("%d",(ids.size()+currentCount)-ESTATE_MAX_ACCESS_IDS); - LLNotifications::instance().add("MaxAgentOnRegionBatch", args); - delete change_info; - return; - } - } - - LLSD args; - args["ALL_ESTATES"] = all_estates_text(); - - LLNotification::Params params(change_info->mDialogName); - params.substitutions(args) - .payload(change_info->asLLSD()) - .functor(accessCoreConfirm); - - if (isLindenEstate()) - { - // just apply to this estate - LLNotifications::instance().forceResponse(params, 0); - } - else - { - // ask if this estate or all estates with this owner - LLNotifications::instance().add(params); - } -} - -// static -void LLPanelEstateInfo::accessRemoveCore(U32 operation_flag, const std::string& dialog_name, const std::string& list_ctrl_name) -{ - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return; - LLNameListCtrl* name_list = panel->getChild(list_ctrl_name); - if (!name_list) return; - - std::vector list_vector = name_list->getAllSelected(); - if (list_vector.size() == 0) - return; - - LLSD payload; - payload["operation"] = (S32)operation_flag; - payload["dialog_name"] = dialog_name; - - for (std::vector::const_iterator iter = list_vector.begin(); - iter != list_vector.end(); - iter++) - { - LLScrollListItem *item = (*iter); - payload["allowed_ids"].append(item->getUUID()); - } - - LLNotification::Params params("ChangeLindenAccess"); - params.payload(payload) - .functor(accessRemoveCore2); - - if (isLindenEstate()) - { - // warn on change linden estate - LLNotifications::instance().add(params); - } - else - { - // just proceed, as if clicking OK - LLNotifications::instance().forceResponse(params, 0); - } -} - -// static -bool LLPanelEstateInfo::accessRemoveCore2(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - if (option != 0) - { - // abort - return false; - } - - // If Linden estate, can only apply to "this" estate, not all estates - // owned by NULL. - if (isLindenEstate()) - { - accessCoreConfirm(notification, response); - } - else - { - LLSD args; - args["ALL_ESTATES"] = all_estates_text(); - LLNotifications::instance().add(notification["payload"]["dialog_name"], - args, - notification["payload"], - accessCoreConfirm); - } - return false; -} - -// Used for both access add and remove operations, depending on the mOperationFlag -// passed in (ESTATE_ACCESS_BANNED_AGENT_ADD, ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, etc.) -// static -bool LLPanelEstateInfo::accessCoreConfirm(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger(); - - LLViewerRegion* region = gAgent.getRegion(); - - LLSD::array_const_iterator end_it = notification["payload"]["allowed_ids"].endArray(); - - for (LLSD::array_const_iterator iter = notification["payload"]["allowed_ids"].beginArray(); - iter != end_it; - iter++) - { - U32 flags = originalFlags; - if (iter + 1 != end_it) - flags |= ESTATE_ACCESS_NO_REPLY; - - const LLUUID id = iter->asUUID(); - if (((U32)notification["payload"]["operation"].asInteger() & ESTATE_ACCESS_BANNED_AGENT_ADD) - && region && (region->getOwner() == id)) - { - LLNotifications::instance().add("OwnerCanNotBeDenied"); - break; - } - switch(option) - { - case 0: - // This estate - sendEstateAccessDelta(flags, id); - break; - case 1: - { - // All estates, either than I own or manage for this owner. - // This will be verified on simulator. JC - if (!region) break; - if (region->getOwner() == gAgent.getID() - || gAgent.isGodlike()) - { - flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES; - sendEstateAccessDelta(flags, id); - } - else if (region->isEstateManager()) - { - flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES; - sendEstateAccessDelta(flags, id); - } - break; - } - case 2: - default: - break; - } - } - return false; -} - -// key = "estateaccessdelta" -// str(estate_id) will be added to front of list by forward_EstateOwnerRequest_to_dataserver -// str[0] = str(agent_id) requesting the change -// str[1] = str(flags) (ESTATE_ACCESS_DELTA_*) -// str[2] = str(agent_id) to add or remove -// static -void LLPanelEstateInfo::sendEstateAccessDelta(U32 flags, const LLUUID& agent_or_group_id) -{ - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("EstateOwnerMessage"); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used - - msg->nextBlock("MethodData"); - msg->addString("Method", "estateaccessdelta"); - msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); - - std::string buf; - gAgent.getID().toString(buf); - msg->nextBlock("ParamList"); - msg->addString("Parameter", buf); - - buf = llformat("%u", flags); - msg->nextBlock("ParamList"); - msg->addString("Parameter", buf); - - agent_or_group_id.toString(buf); - msg->nextBlock("ParamList"); - msg->addString("Parameter", buf); - - - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - - if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_ALLOWED_AGENT_REMOVE | - ESTATE_ACCESS_BANNED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_REMOVE)) - { - - panel->clearAccessLists(); - } - - gAgent.sendReliableMessage(); -} - -void LLPanelEstateInfo::updateControls(LLViewerRegion* region) -{ - BOOL god = gAgent.isGodlike(); - BOOL owner = (region && (region->getOwner() == gAgent.getID())); - BOOL manager = (region && region->isEstateManager()); - setCtrlsEnabled(god || owner || manager); - - childDisable("apply_btn"); - childSetEnabled("add_allowed_avatar_btn", god || owner || manager); - childSetEnabled("remove_allowed_avatar_btn", god || owner || manager); - childSetEnabled("add_allowed_group_btn", god || owner || manager); - childSetEnabled("remove_allowed_group_btn", god || owner || manager); - childSetEnabled("add_banned_avatar_btn", god || owner || manager); - childSetEnabled("remove_banned_avatar_btn", god || owner || manager); - childSetEnabled("message_estate_btn", god || owner || manager); - childSetEnabled("kick_user_from_estate_btn", god || owner || manager); - childSetEnabled("abuse_email_address", god || owner || manager); - - // estate managers can't add estate managers - childSetEnabled("add_estate_manager_btn", god || owner); - childSetEnabled("remove_estate_manager_btn", god || owner); - childSetEnabled("estate_manager_name_list", god || owner); -} - -bool LLPanelEstateInfo::refreshFromRegion(LLViewerRegion* region) -{ - updateControls(region); - - // let the parent class handle the general data collection. - bool rv = LLPanelRegionInfo::refreshFromRegion(region); - - // We want estate info. To make sure it works across region - // boundaries and multiple packets, we add a serial number to the - // integers and track against that on update. - strings_t strings; - //integers_t integers; - //LLFloaterRegionInfo::incrementSerial(); - LLFloaterRegionInfo::nextInvoice(); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - //integers.push_back(LLFloaterRegionInfo::());::getPanelEstate(); - - - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - panel->clearAccessLists(); - - - sendEstateOwnerMessage(gMessageSystem, "getinfo", invoice, strings); - - refresh(); - - return rv; -} - -void LLPanelEstateInfo::updateChild(LLUICtrl* child_ctrl) -{ - if (checkRemovalButton(child_ctrl->getName())) - { - // do nothing - } - else if (checkSunHourSlider(child_ctrl)) - { - // do nothing - } -} - -bool LLPanelEstateInfo::estateUpdate(LLMessageSystem* msg) -{ - llinfos << "LLPanelEstateInfo::estateUpdate()" << llendl; - return false; -} - - -BOOL LLPanelEstateInfo::postBuild() -{ - // set up the callbacks for the generic controls - initCtrl("externally_visible_check"); - initCtrl("use_global_time_check"); - initCtrl("fixed_sun_check"); - initCtrl("allow_direct_teleport"); - initCtrl("limit_payment"); - initCtrl("limit_age_verified"); - initCtrl("voice_chat_check"); - childSetCommitCallback("abuse_email_address", onChangeAnything, this); - childSetKeystrokeCallback("abuse_email_address", onChangeText, this); - - initHelpBtn("estate_manager_help", "HelpEstateEstateManager"); - initHelpBtn("use_global_time_help", "HelpEstateUseGlobalTime"); - initHelpBtn("fixed_sun_help", "HelpEstateFixedSun"); - initHelpBtn("WLEditSkyHelp", "HelpEditSky"); - initHelpBtn("WLEditDayCycleHelp", "HelpEditDayCycle"); - - initHelpBtn("externally_visible_help", "HelpEstateExternallyVisible"); - initHelpBtn("allow_direct_teleport_help", "HelpEstateAllowDirectTeleport"); - initHelpBtn("allow_resident_help", "HelpEstateAllowResident"); - initHelpBtn("allow_group_help", "HelpEstateAllowGroup"); - initHelpBtn("ban_resident_help", "HelpEstateBanResident"); - initHelpBtn("abuse_email_address_help", "HelpEstateAbuseEmailAddress"); - initHelpBtn("voice_chat_help", "HelpEstateVoiceChat"); - - // set up the use global time checkbox - childSetCommitCallback("use_global_time_check", onChangeUseGlobalTime, this); - childSetCommitCallback("fixed_sun_check", onChangeFixedSun, this); - childSetCommitCallback("sun_hour_slider", onChangeChildCtrl, this); - - childSetCommitCallback("allowed_avatar_name_list", onChangeChildCtrl, this); - LLNameListCtrl *avatar_name_list = getChild("allowed_avatar_name_list"); - if (avatar_name_list) - { - avatar_name_list->setCommitOnSelectionChange(TRUE); - avatar_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); - } - - childSetAction("add_allowed_avatar_btn", onClickAddAllowedAgent, this); - childSetAction("remove_allowed_avatar_btn", onClickRemoveAllowedAgent, this); - - childSetCommitCallback("allowed_group_name_list", onChangeChildCtrl, this); - LLNameListCtrl* group_name_list = getChild("allowed_group_name_list"); - if (group_name_list) - { - group_name_list->setCommitOnSelectionChange(TRUE); - group_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); - } - - childSetAction("add_allowed_group_btn", onClickAddAllowedGroup, this); - childSetAction("remove_allowed_group_btn", onClickRemoveAllowedGroup, this); - - childSetCommitCallback("banned_avatar_name_list", onChangeChildCtrl, this); - LLNameListCtrl* banned_name_list = getChild("banned_avatar_name_list"); - if (banned_name_list) - { - banned_name_list->setCommitOnSelectionChange(TRUE); - banned_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); - } - - childSetAction("add_banned_avatar_btn", onClickAddBannedAgent, this); - childSetAction("remove_banned_avatar_btn", onClickRemoveBannedAgent, this); - - childSetCommitCallback("estate_manager_name_list", onChangeChildCtrl, this); - LLNameListCtrl* manager_name_list = getChild("estate_manager_name_list"); - if (manager_name_list) - { - manager_name_list->setCommitOnSelectionChange(TRUE); - manager_name_list->setMaxItemCount(ESTATE_MAX_MANAGERS * 4); // Allow extras for dupe issue - } - - childSetAction("add_estate_manager_btn", onClickAddEstateManager, this); - childSetAction("remove_estate_manager_btn", onClickRemoveEstateManager, this); - childSetAction("message_estate_btn", onClickMessageEstate, this); - childSetAction("kick_user_from_estate_btn", onClickKickUser, this); - - childSetAction("WLEditSky", onClickEditSky, this); - childSetAction("WLEditDayCycle", onClickEditDayCycle, this); - - return LLPanelRegionInfo::postBuild(); -} - -void LLPanelEstateInfo::refresh() -{ - bool public_access = childGetValue("externally_visible_check").asBoolean(); - childSetEnabled("Only Allow", public_access); - childSetEnabled("limit_payment", public_access); - childSetEnabled("limit_age_verified", public_access); - // if this is set to false, then the limit fields are meaningless and should be turned off - if (public_access == false) - { - childSetValue("limit_payment", false); - childSetValue("limit_age_verified", false); - } -} - -BOOL LLPanelEstateInfo::sendUpdate() -{ - llinfos << "LLPanelEsateInfo::sendUpdate()" << llendl; - - LLNotification::Params params("ChangeLindenEstate"); - params.functor(boost::bind(&LLPanelEstateInfo::callbackChangeLindenEstate, this, _1, _2)); - - if (getEstateID() <= ESTATE_LAST_LINDEN) - { - // trying to change reserved estate, warn - LLNotifications::instance().add(params); - } - else - { - // for normal estates, just make the change - LLNotifications::instance().forceResponse(params, 0); - } - return TRUE; -} - -bool LLPanelEstateInfo::callbackChangeLindenEstate(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - switch(option) - { - case 0: - // send the update - if (!commitEstateInfoCaps()) - { - // the caps method failed, try the old way - LLFloaterRegionInfo::nextInvoice(); - commitEstateInfoDataserver(); - } - // we don't want to do this because we'll get it automatically from the sim - // after the spaceserver processes it -// else -// { -// // caps method does not automatically send this info -// LLFloaterRegionInfo::requestRegionInfo(); -// } - break; - case 1: - default: - // do nothing - break; - } - return false; -} - - -/* -// Request = "getowner" -// SParam[0] = "" (empty string) -// IParam[0] = serial -void LLPanelEstateInfo::getEstateOwner() -{ - // TODO -- disable the panel - // and call this function whenever we cross a region boundary - // re-enable when owner matches, and get new estate info - LLMessageSystem* msg = gMessageSystem; - msg->newMessageFast(_PREHASH_EstateOwnerRequest); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - - msg->nextBlockFast(_PREHASH_RequestData); - msg->addStringFast(_PREHASH_Request, "getowner"); - - // we send an empty string so that the variable block is not empty - msg->nextBlockFast(_PREHASH_StringData); - msg->addStringFast(_PREHASH_SParam, ""); - - msg->nextBlockFast(_PREHASH_IntegerData); - msg->addS32Fast(_PREHASH_IParam, LLFloaterRegionInfo::getSerial()); - - gAgent.sendMessage(); -} -*/ - -class LLEstateChangeInfoResponder : public LLHTTPClient::Responder -{ -public: - LLEstateChangeInfoResponder(void* userdata) : mpPanel((LLPanelEstateInfo*)userdata) {}; - - // if we get a normal response, handle it here - virtual void result(const LLSD& content) - { - // refresh the panel from the database - mpPanel->refresh(); - } - - // if we get an error response - virtual void error(U32 status, const std::string& reason) - { - llinfos << "LLEstateChangeInfoResponder::error " - << status << ": " << reason << llendl; - } -private: - LLPanelEstateInfo* mpPanel; -}; - -// tries to send estate info using a cap; returns true if it succeeded -bool LLPanelEstateInfo::commitEstateInfoCaps() -{ - std::string url = gAgent.getRegion()->getCapability("EstateChangeInfo"); - - if (url.empty()) - { - // whoops, couldn't find the cap, so bail out - return false; - } - - LLSD body; - body["estate_name"] = getEstateName(); - - body["is_externally_visible"] = childGetValue("externally_visible_check").asBoolean(); - body["allow_direct_teleport"] = childGetValue("allow_direct_teleport").asBoolean(); - body["is_sun_fixed" ] = childGetValue("fixed_sun_check").asBoolean(); - body["deny_anonymous" ] = childGetValue("limit_payment").asBoolean(); - body["deny_age_unverified" ] = childGetValue("limit_age_verified").asBoolean(); - body["allow_voice_chat" ] = childGetValue("voice_chat_check").asBoolean(); - body["invoice" ] = LLFloaterRegionInfo::getLastInvoice(); - - // block fly is in estate database but not in estate UI, so we're not supporting it - //body["block_fly" ] = childGetValue("").asBoolean(); - - F32 sun_hour = getSunHour(); - if (childGetValue("use_global_time_check").asBoolean()) - { - sun_hour = 0.f; // 0 = global time - } - body["sun_hour"] = sun_hour; - - body["owner_abuse_email"] = childGetValue("abuse_email_address").asString(); - - // we use a responder so that we can re-get the data after committing to the database - LLHTTPClient::post(url, body, new LLEstateChangeInfoResponder((void*)this)); - return true; -} - -/* This is the old way of doing things, is deprecated, and should be - deleted when the dataserver model can be removed */ -// key = "estatechangeinfo" -// strings[0] = str(estate_id) (added by simulator before relay - not here) -// strings[1] = estate_name -// strings[2] = str(estate_flags) -// strings[3] = str((S32)(sun_hour * 1024.f)) -void LLPanelEstateInfo::commitEstateInfoDataserver() -{ - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("EstateOwnerMessage"); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used - - msg->nextBlock("MethodData"); - msg->addString("Method", "estatechangeinfo"); - msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); - - msg->nextBlock("ParamList"); - msg->addString("Parameter", getEstateName()); - - std::string buffer; - buffer = llformat("%u", computeEstateFlags()); - msg->nextBlock("ParamList"); - msg->addString("Parameter", buffer); - - F32 sun_hour = getSunHour(); - if (childGetValue("use_global_time_check").asBoolean()) - { - sun_hour = 0.f; // 0 = global time - } - - buffer = llformat("%d", (S32)(sun_hour*1024.0f)); - msg->nextBlock("ParamList"); - msg->addString("Parameter", buffer); - - gAgent.sendMessage(); -} - -void LLPanelEstateInfo::setEstateFlags(U32 flags) -{ - childSetValue("externally_visible_check", LLSD(flags & REGION_FLAGS_EXTERNALLY_VISIBLE ? TRUE : FALSE) ); - childSetValue("fixed_sun_check", LLSD(flags & REGION_FLAGS_SUN_FIXED ? TRUE : FALSE) ); - childSetValue( - "voice_chat_check", - LLSD(flags & REGION_FLAGS_ALLOW_VOICE ? TRUE : FALSE)); - childSetValue("allow_direct_teleport", LLSD(flags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT ? TRUE : FALSE) ); - childSetValue("limit_payment", LLSD(flags & REGION_FLAGS_DENY_ANONYMOUS ? TRUE : FALSE) ); - childSetValue("limit_age_verified", LLSD(flags & REGION_FLAGS_DENY_AGEUNVERIFIED ? TRUE : FALSE) ); - - refresh(); -} - -U32 LLPanelEstateInfo::computeEstateFlags() -{ - U32 flags = 0; - - if (childGetValue("externally_visible_check").asBoolean()) - { - flags |= REGION_FLAGS_EXTERNALLY_VISIBLE; - } - - if ( childGetValue("voice_chat_check").asBoolean() ) - { - flags |= REGION_FLAGS_ALLOW_VOICE; - } - - if (childGetValue("allow_direct_teleport").asBoolean()) - { - flags |= REGION_FLAGS_ALLOW_DIRECT_TELEPORT; - } - - if (childGetValue("fixed_sun_check").asBoolean()) - { - flags |= REGION_FLAGS_SUN_FIXED; - } - - if (childGetValue("limit_payment").asBoolean()) - { - flags |= REGION_FLAGS_DENY_ANONYMOUS; - } - - if (childGetValue("limit_age_verified").asBoolean()) - { - flags |= REGION_FLAGS_DENY_AGEUNVERIFIED; - } - - - return flags; -} - -BOOL LLPanelEstateInfo::getGlobalTime() -{ - return childGetValue("use_global_time_check").asBoolean(); -} - -void LLPanelEstateInfo::setGlobalTime(bool b) -{ - childSetValue("use_global_time_check", LLSD(b)); - childSetEnabled("fixed_sun_check", LLSD(!b)); - childSetEnabled("sun_hour_slider", LLSD(!b)); - if (b) - { - childSetValue("sun_hour_slider", LLSD(0.f)); - } -} - - -BOOL LLPanelEstateInfo::getFixedSun() -{ - return childGetValue("fixed_sun_check").asBoolean(); -} - -void LLPanelEstateInfo::setSunHour(F32 sun_hour) -{ - if(sun_hour < 6.0f) - { - sun_hour = 24.0f + sun_hour; - } - childSetValue("sun_hour_slider", LLSD(sun_hour)); -} - -F32 LLPanelEstateInfo::getSunHour() -{ - if (childIsEnabled("sun_hour_slider")) - { - return (F32)childGetValue("sun_hour_slider").asReal(); - } - return 0.f; -} - -const std::string LLPanelEstateInfo::getEstateName() const -{ - return childGetValue("estate_name").asString(); -} - -void LLPanelEstateInfo::setEstateName(const std::string& name) -{ - childSetValue("estate_name", LLSD(name)); -} - -const std::string LLPanelEstateInfo::getOwnerName() const -{ - return childGetValue("estate_owner").asString(); -} - -void LLPanelEstateInfo::setOwnerName(const std::string& name) -{ - childSetValue("estate_owner", LLSD(name)); -} - -const std::string LLPanelEstateInfo::getAbuseEmailAddress() const -{ - return childGetValue("abuse_email_address").asString(); -} - -void LLPanelEstateInfo::setAbuseEmailAddress(const std::string& address) -{ - childSetValue("abuse_email_address", LLSD(address)); -} - -void LLPanelEstateInfo::setAccessAllowedEnabled(bool enable_agent, - bool enable_group, - bool enable_ban) -{ - childSetEnabled("allow_resident_label", enable_agent); - childSetEnabled("allowed_avatar_name_list", enable_agent); - childSetVisible("allowed_avatar_name_list", enable_agent); - childSetEnabled("add_allowed_avatar_btn", enable_agent); - childSetEnabled("remove_allowed_avatar_btn", enable_agent); - - // Groups - childSetEnabled("allow_group_label", enable_group); - childSetEnabled("allowed_group_name_list", enable_group); - childSetVisible("allowed_group_name_list", enable_group); - childSetEnabled("add_allowed_group_btn", enable_group); - childSetEnabled("remove_allowed_group_btn", enable_group); - - // Ban - childSetEnabled("ban_resident_label", enable_ban); - childSetEnabled("banned_avatar_name_list", enable_ban); - childSetVisible("banned_avatar_name_list", enable_ban); - childSetEnabled("add_banned_avatar_btn", enable_ban); - childSetEnabled("remove_banned_avatar_btn", enable_ban); - - // Update removal buttons if needed - if (enable_agent) - { - checkRemovalButton("allowed_avatar_name_list"); - } - - if (enable_group) - { - checkRemovalButton("allowed_group_name_list"); - } - - if (enable_ban) - { - checkRemovalButton("banned_avatar_name_list"); - } -} - -// static -void LLPanelEstateInfo::callbackCacheName( - const LLUUID& id, - const std::string& first, - const std::string& last, - BOOL is_group, - void*) -{ - LLPanelEstateInfo* self = LLFloaterRegionInfo::getPanelEstate(); - if (!self) return; - - std::string name; - - if (id.isNull()) - { - name = "(none)"; - } - else - { - name = first + " " + last; - } - - self->setOwnerName(name); -} - -void LLPanelEstateInfo::clearAccessLists() -{ - LLNameListCtrl* name_list = getChild("allowed_avatar_name_list"); - if (name_list) - { - name_list->deleteAllItems(); - } - - name_list = getChild("banned_avatar_name_list"); - if (name_list) - { - name_list->deleteAllItems(); - } -} - -// enables/disables the "remove" button for the various allow/ban lists -BOOL LLPanelEstateInfo::checkRemovalButton(std::string name) -{ - std::string btn_name = ""; - if (name == "allowed_avatar_name_list") - { - btn_name = "remove_allowed_avatar_btn"; - } - else if (name == "allowed_group_name_list") - { - btn_name = "remove_allowed_group_btn"; - } - else if (name == "banned_avatar_name_list") - { - btn_name = "remove_banned_avatar_btn"; - } - else if (name == "estate_manager_name_list") - { - //ONLY OWNER CAN ADD /DELET ESTATE MANAGER - LLViewerRegion* region = gAgent.getRegion(); - if (region && (region->getOwner() == gAgent.getID())) - { - btn_name = "remove_estate_manager_btn"; - } - } - - // enable the remove button if something is selected - LLNameListCtrl* name_list = getChild(name); - childSetEnabled(btn_name, name_list && name_list->getFirstSelected() ? TRUE : FALSE); - - return (btn_name != ""); -} - -BOOL LLPanelEstateInfo::checkSunHourSlider(LLUICtrl* child_ctrl) -{ - BOOL found_child_ctrl = FALSE; - if (child_ctrl->getName() == "sun_hour_slider") - { - enableButton("apply_btn"); - found_child_ctrl = TRUE; - } - return found_child_ctrl; -} - -// static -void LLPanelEstateInfo::onClickMessageEstate(void* userdata) -{ - llinfos << "LLPanelEstateInfo::onClickMessageEstate" << llendl; - LLNotifications::instance().add("MessageEstate", LLSD(), LLSD(), boost::bind(&LLPanelEstateInfo::onMessageCommit, (LLPanelEstateInfo*)userdata, _1, _2)); -} - -bool LLPanelEstateInfo::onMessageCommit(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - std::string text = response["message"].asString(); - if(option != 0) return false; - if(text.empty()) return false; - llinfos << "Message to everyone: " << text << llendl; - strings_t strings; - //integers_t integers; - std::string name; - gAgent.buildFullname(name); - strings.push_back(strings_t::value_type(name)); - strings.push_back(strings_t::value_type(text)); - LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); - sendEstateOwnerMessage(gMessageSystem, "instantmessage", invoice, strings); - return false; -} - -LLPanelEstateCovenant::LLPanelEstateCovenant() -: mCovenantID(LLUUID::null) -{ -} - -// virtual -bool LLPanelEstateCovenant::refreshFromRegion(LLViewerRegion* region) -{ - LLTextBox* region_name = getChild("region_name_text"); - if (region_name) - { - region_name->setText(region->getName()); - } - - LLTextBox* resellable_clause = getChild("resellable_clause"); - if (resellable_clause) - { - if (region->getRegionFlags() & REGION_FLAGS_BLOCK_LAND_RESELL) - { - resellable_clause->setText(getString("can_not_resell")); - } - else - { - resellable_clause->setText(getString("can_resell")); - } - } - - LLTextBox* changeable_clause = getChild("changeable_clause"); - if (changeable_clause) - { - if (region->getRegionFlags() & REGION_FLAGS_ALLOW_PARCEL_CHANGES) - { - changeable_clause->setText(getString("can_change")); - } - else - { - changeable_clause->setText(getString("can_not_change")); - } - } - - LLTextBox* region_maturity = getChild("region_maturity_text"); - if (region_maturity) - { - region_maturity->setText(region->getSimAccessString()); - } - - LLTextBox* region_landtype = getChild("region_landtype_text"); - if (region_landtype) - { - region_landtype->setText(region->getSimProductName()); - } - - - // let the parent class handle the general data collection. - bool rv = LLPanelRegionInfo::refreshFromRegion(region); - LLMessageSystem *msg = gMessageSystem; - msg->newMessage("EstateCovenantRequest"); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID()); - msg->sendReliable(region->getHost()); - return rv; -} - -// virtual -bool LLPanelEstateCovenant::estateUpdate(LLMessageSystem* msg) -{ - llinfos << "LLPanelEstateCovenant::estateUpdate()" << llendl; - return true; -} - -// virtual -BOOL LLPanelEstateCovenant::postBuild() -{ - initHelpBtn("covenant_help", "HelpEstateCovenant"); - mEstateNameText = getChild("estate_name_text"); - mEstateOwnerText = getChild("estate_owner_text"); - mLastModifiedText = getChild("covenant_timestamp_text"); - mEditor = getChild("covenant_editor"); - if (mEditor) mEditor->setHandleEditKeysDirectly(TRUE); - LLButton* reset_button = getChild("reset_covenant"); - reset_button->setEnabled(gAgent.canManageEstate()); - reset_button->setClickedCallback(LLPanelEstateCovenant::resetCovenantID, NULL); - - return LLPanelRegionInfo::postBuild(); -} - -// virtual -void LLPanelEstateCovenant::updateChild(LLUICtrl* child_ctrl) -{ -} - -// virtual -BOOL LLPanelEstateCovenant::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, - EDragAndDropType cargo_type, - void* cargo_data, - EAcceptance* accept, - std::string& tooltip_msg) -{ - LLInventoryItem* item = (LLInventoryItem*)cargo_data; - - if (!gAgent.canManageEstate()) - { - *accept = ACCEPT_NO; - return TRUE; - } - - switch(cargo_type) - { - case DAD_NOTECARD: - *accept = ACCEPT_YES_COPY_SINGLE; - if (item && drop) - { - LLSD payload; - payload["item_id"] = item->getUUID(); - LLNotifications::instance().add("EstateChangeCovenant", LLSD(), payload, - LLPanelEstateCovenant::confirmChangeCovenantCallback); - } - break; - default: - *accept = ACCEPT_NO; - break; - } - - return TRUE; -} - -// static -bool LLPanelEstateCovenant::confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response) -{ - S32 option = LLNotification::getSelectedOption(notification, response); - LLInventoryItem* item = gInventory.getItem(notification["payload"]["item_id"].asUUID()); - LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant(); - - if (!item || !self) return false; - - switch(option) - { - case 0: - self->loadInvItem(item); - break; - default: - break; - } - return false; -} - -// static -void LLPanelEstateCovenant::resetCovenantID(void* userdata) -{ - LLNotifications::instance().add("EstateChangeCovenant", LLSD(), LLSD(), confirmResetCovenantCallback); -} - -// static -bool LLPanelEstateCovenant::confirmResetCovenantCallback(const LLSD& notification, const LLSD& response) -{ - LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant(); - if (!self) return false; - - S32 option = LLNotification::getSelectedOption(notification, response); - switch(option) - { - case 0: - self->loadInvItem(NULL); - break; - default: - break; - } - return false; -} - -void LLPanelEstateCovenant::loadInvItem(LLInventoryItem *itemp) -{ - const BOOL high_priority = TRUE; - if (itemp) - { - gAssetStorage->getInvItemAsset(gAgent.getRegionHost(), - gAgent.getID(), - gAgent.getSessionID(), - itemp->getPermissions().getOwner(), - LLUUID::null, - itemp->getUUID(), - itemp->getAssetUUID(), - itemp->getType(), - onLoadComplete, - (void*)this, - high_priority); - mAssetStatus = ASSET_LOADING; - } - else - { - mAssetStatus = ASSET_LOADED; - setCovenantTextEditor("There is no Covenant provided for this Estate."); - sendChangeCovenantID(LLUUID::null); - } -} - -// static -void LLPanelEstateCovenant::onLoadComplete(LLVFS *vfs, - const LLUUID& asset_uuid, - LLAssetType::EType type, - void* user_data, S32 status, LLExtStat ext_status) -{ - llinfos << "LLPanelEstateCovenant::onLoadComplete()" << llendl; - LLPanelEstateCovenant* panelp = (LLPanelEstateCovenant*)user_data; - if( panelp ) - { - if(0 == status) - { - LLVFile file(vfs, asset_uuid, type, LLVFile::READ); - - S32 file_length = file.getSize(); - - char* buffer = new char[file_length+1]; - if (buffer == NULL) - { - llerrs << "Memory Allocation Failed" << llendl; - return; - } - - file.read((U8*)buffer, file_length); /* Flawfinder: ignore */ - // put a EOS at the end - buffer[file_length] = 0; - - if( (file_length > 19) && !strncmp( buffer, "Linden text version", 19 ) ) - { - if( !panelp->mEditor->importBuffer( buffer, file_length+1 ) ) - { - llwarns << "Problem importing estate covenant." << llendl; - LLNotifications::instance().add("ProblemImportingEstateCovenant"); - } - else - { - panelp->sendChangeCovenantID(asset_uuid); - } - } - else - { - // Version 0 (just text, doesn't include version number) - panelp->sendChangeCovenantID(asset_uuid); - } - delete[] buffer; - } - else - { - LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED ); - - if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status || - LL_ERR_FILE_EMPTY == status) - { - LLNotifications::instance().add("MissingNotecardAssetID"); - } - else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status) - { - LLNotifications::instance().add("NotAllowedToViewNotecard"); - } - else - { - LLNotifications::instance().add("UnableToLoadNotecardAsset"); - } - - llwarns << "Problem loading notecard: " << status << llendl; - } - panelp->mAssetStatus = ASSET_LOADED; - panelp->setCovenantID(asset_uuid); - } -} - -// key = "estatechangecovenantid" -// strings[0] = str(estate_id) (added by simulator before relay - not here) -// strings[1] = str(covenant_id) -void LLPanelEstateCovenant::sendChangeCovenantID(const LLUUID &asset_id) -{ - if (asset_id != getCovenantID()) - { - setCovenantID(asset_id); - - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("EstateOwnerMessage"); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used - - msg->nextBlock("MethodData"); - msg->addString("Method", "estatechangecovenantid"); - msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); - - msg->nextBlock("ParamList"); - msg->addString("Parameter", getCovenantID().asString()); - gAgent.sendReliableMessage(); - } -} - -// virtual -BOOL LLPanelEstateCovenant::sendUpdate() -{ - return TRUE; -} - -const std::string& LLPanelEstateCovenant::getEstateName() const -{ - return mEstateNameText->getText(); -} - -void LLPanelEstateCovenant::setEstateName(const std::string& name) -{ - mEstateNameText->setText(name); -} - -// static -void LLPanelEstateCovenant::updateCovenantText(const std::string& string, const LLUUID& asset_id) -{ - LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); - if( panelp ) - { - panelp->mEditor->setText(string); - panelp->setCovenantID(asset_id); - } -} - -// static -void LLPanelEstateCovenant::updateEstateName(const std::string& name) -{ - LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); - if( panelp ) - { - panelp->mEstateNameText->setText(name); - } -} - -// static -void LLPanelEstateCovenant::updateLastModified(const std::string& text) -{ - LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); - if( panelp ) - { - panelp->mLastModifiedText->setText(text); - } -} - -// static -void LLPanelEstateCovenant::updateEstateOwnerName(const std::string& name) -{ - LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); - if( panelp ) - { - panelp->mEstateOwnerText->setText(name); - } -} - -const std::string& LLPanelEstateCovenant::getOwnerName() const -{ - return mEstateOwnerText->getText(); -} - -void LLPanelEstateCovenant::setOwnerName(const std::string& name) -{ - mEstateOwnerText->setText(name); -} - -void LLPanelEstateCovenant::setCovenantTextEditor(const std::string& text) -{ - mEditor->setText(text); -} - -// key = "estateupdateinfo" -// strings[0] = estate name -// strings[1] = str(owner_id) -// strings[2] = str(estate_id) -// strings[3] = str(estate_flags) -// strings[4] = str((S32)(sun_hour * 1024)) -// strings[5] = str(parent_estate_id) -// strings[6] = str(covenant_id) -// strings[7] = str(covenant_timestamp) -// strings[8] = str(send_to_agent_only) -// strings[9] = str(abuse_email_addr) -bool LLDispatchEstateUpdateInfo::operator()( - const LLDispatcher* dispatcher, - const std::string& key, - const LLUUID& invoice, - const sparam_t& strings) -{ - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return true; - - // NOTE: LLDispatcher extracts strings with an extra \0 at the - // end. If we pass the std::string direct to the UI/renderer - // it draws with a weird character at the end of the string. - std::string estate_name = strings[0].c_str(); // preserve c_str() call! - panel->setEstateName(estate_name); - - if (strings.size() > 3) - { - std::string abuse_email = strings[9].c_str(); // preserve c_str() call! - panel->setAbuseEmailAddress(abuse_email); - } - else - { - panel->setAbuseEmailAddress(panel->getString("email_unsupported")); - } - - LLViewerRegion* regionp = gAgent.getRegion(); - - LLUUID owner_id(strings[1]); - regionp->setOwner(owner_id); - // Update estate owner name in UI - const BOOL is_group = FALSE; - gCacheName->get(owner_id, is_group, LLPanelEstateInfo::callbackCacheName); - - U32 estate_id = strtoul(strings[2].c_str(), NULL, 10); - panel->setEstateID(estate_id); - - U32 flags = strtoul(strings[3].c_str(), NULL, 10); - panel->setEstateFlags(flags); - - F32 sun_hour = ((F32)(strtod(strings[4].c_str(), NULL)))/1024.0f; - if(sun_hour == 0 && (flags & REGION_FLAGS_SUN_FIXED ? FALSE : TRUE)) - { - panel->setGlobalTime(TRUE); - } - else - { - panel->setGlobalTime(FALSE); - panel->setSunHour(sun_hour); - } - - bool visible_from_mainland = (bool)(flags & REGION_FLAGS_EXTERNALLY_VISIBLE); - bool god = gAgent.isGodlike(); - bool linden_estate = (estate_id <= ESTATE_LAST_LINDEN); - - // If visible from mainland, disable the access allowed - // UI, as anyone can teleport there. - // However, gods need to be able to edit the access list for - // linden estates, regardless of visibility, to allow object - // and L$ transfers. - bool enable_agent = (!visible_from_mainland || (god && linden_estate)); - bool enable_group = enable_agent; - bool enable_ban = !linden_estate; - panel->setAccessAllowedEnabled(enable_agent, enable_group, enable_ban); - - return true; -} - - -// key = "setaccess" -// strings[0] = str(estate_id) -// strings[1] = str(packed_access_lists) -// strings[2] = str(num allowed agent ids) -// strings[3] = str(num allowed group ids) -// strings[4] = str(num banned agent ids) -// strings[5] = str(num estate manager agent ids) -// strings[6] = bin(uuid) -// strings[7] = bin(uuid) -// strings[8] = bin(uuid) -// ... -bool LLDispatchSetEstateAccess::operator()( - const LLDispatcher* dispatcher, - const std::string& key, - const LLUUID& invoice, - const sparam_t& strings) -{ - LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); - if (!panel) return true; - - S32 index = 1; // skip estate_id - U32 access_flags = strtoul(strings[index++].c_str(), NULL,10); - S32 num_allowed_agents = strtol(strings[index++].c_str(), NULL, 10); - S32 num_allowed_groups = strtol(strings[index++].c_str(), NULL, 10); - S32 num_banned_agents = strtol(strings[index++].c_str(), NULL, 10); - S32 num_estate_managers = strtol(strings[index++].c_str(), NULL, 10); - - // sanity ckecks - if (num_allowed_agents > 0 - && !(access_flags & ESTATE_ACCESS_ALLOWED_AGENTS)) - { - llwarns << "non-zero count for allowed agents, but no corresponding flag" << llendl; - } - if (num_allowed_groups > 0 - && !(access_flags & ESTATE_ACCESS_ALLOWED_GROUPS)) - { - llwarns << "non-zero count for allowed groups, but no corresponding flag" << llendl; - } - if (num_banned_agents > 0 - && !(access_flags & ESTATE_ACCESS_BANNED_AGENTS)) - { - llwarns << "non-zero count for banned agents, but no corresponding flag" << llendl; - } - if (num_estate_managers > 0 - && !(access_flags & ESTATE_ACCESS_MANAGERS)) - { - llwarns << "non-zero count for managers, but no corresponding flag" << llendl; - } - - // grab the UUID's out of the string fields - if (access_flags & ESTATE_ACCESS_ALLOWED_AGENTS) - { - LLNameListCtrl* allowed_agent_name_list; - allowed_agent_name_list = panel->getChild("allowed_avatar_name_list"); - - int totalAllowedAgents = num_allowed_agents; - - if (allowed_agent_name_list) - { - totalAllowedAgents += allowed_agent_name_list->getItemCount(); - } - - std::string msg = llformat("Allowed residents: (%d, max %d)", - totalAllowedAgents, - ESTATE_MAX_ACCESS_IDS); - panel->childSetValue("allow_resident_label", LLSD(msg)); - - if (allowed_agent_name_list) - { - //allowed_agent_name_list->deleteAllItems(); - for (S32 i = 0; i < num_allowed_agents && i < ESTATE_MAX_ACCESS_IDS; i++) - { - LLUUID id; - memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ - allowed_agent_name_list->addNameItem(id); - } - panel->childSetEnabled("remove_allowed_avatar_btn", allowed_agent_name_list->getFirstSelected() ? TRUE : FALSE); - allowed_agent_name_list->sortByColumnIndex(0, TRUE); - } - } - - if (access_flags & ESTATE_ACCESS_ALLOWED_GROUPS) - { - LLNameListCtrl* allowed_group_name_list; - allowed_group_name_list = panel->getChild("allowed_group_name_list"); - - std::string msg = llformat("Allowed groups: (%d, max %d)", - num_allowed_groups, - (S32) ESTATE_MAX_GROUP_IDS); - panel->childSetValue("allow_group_label", LLSD(msg)); - - if (allowed_group_name_list) - { - allowed_group_name_list->deleteAllItems(); - for (S32 i = 0; i < num_allowed_groups && i < ESTATE_MAX_GROUP_IDS; i++) - { - LLUUID id; - memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ - allowed_group_name_list->addGroupNameItem(id); - } - panel->childSetEnabled("remove_allowed_group_btn", allowed_group_name_list->getFirstSelected() ? TRUE : FALSE); - allowed_group_name_list->sortByColumnIndex(0, TRUE); - } - } - - if (access_flags & ESTATE_ACCESS_BANNED_AGENTS) - { - LLNameListCtrl* banned_agent_name_list; - banned_agent_name_list = panel->getChild("banned_avatar_name_list"); - - int totalBannedAgents = num_banned_agents; - - if (banned_agent_name_list) - { - totalBannedAgents += banned_agent_name_list->getItemCount(); - } - - - std::string msg = llformat("Banned residents: (%d, max %d)", - totalBannedAgents, - ESTATE_MAX_ACCESS_IDS); - panel->childSetValue("ban_resident_label", LLSD(msg)); - - if (banned_agent_name_list) - { - //banned_agent_name_list->deleteAllItems(); - for (S32 i = 0; i < num_banned_agents && i < ESTATE_MAX_ACCESS_IDS; i++) - { - LLUUID id; - memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ - banned_agent_name_list->addNameItem(id); - } - panel->childSetEnabled("remove_banned_avatar_btn", banned_agent_name_list->getFirstSelected() ? TRUE : FALSE); - banned_agent_name_list->sortByColumnIndex(0, TRUE); - } - } - - if (access_flags & ESTATE_ACCESS_MANAGERS) - { - std::string msg = llformat("Estate Managers: (%d, max %d)", - num_estate_managers, - ESTATE_MAX_MANAGERS); - panel->childSetValue("estate_manager_label", LLSD(msg)); - - LLNameListCtrl* estate_manager_name_list = - panel->getChild("estate_manager_name_list"); - if (estate_manager_name_list) - { - estate_manager_name_list->deleteAllItems(); // Clear existing entries - - // There should be only ESTATE_MAX_MANAGERS people in the list, but if the database gets more (SL-46107) don't - // truncate the list unless it's really big. Go ahead and show the extras so the user doesn't get confused, - // and they can still remove them. - for (S32 i = 0; i < num_estate_managers && i < (ESTATE_MAX_MANAGERS * 4); i++) - { - LLUUID id; - memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ - estate_manager_name_list->addNameItem(id); - } - panel->childSetEnabled("remove_estate_manager_btn", estate_manager_name_list->getFirstSelected() ? TRUE : FALSE); - estate_manager_name_list->sortByColumnIndex(0, TRUE); - } - } - - return true; -} - -// [RLVa:KB] - Checked: 2009-07-04 (RLVa-1.0.0a) -void LLFloaterRegionInfo::open() -{ - // We'll allow access to the estate tools for estate managers (and for the sim owner) - if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) - { - LLViewerRegion* pRegion = gAgent.getRegion(); - if (!pRegion) - return; - - // Should be able to call LLRegion::canManageEstate() but then we can fake god like - if ( (!pRegion->isEstateManager()) && (pRegion->getOwner() != gAgent.getID()) ) - return; - } - - LLFloater::open(); -} -// [/RLVa:KB] +/** + * @file llfloaterregioninfo.cpp + * @author Aaron Brashears + * @brief Implementation of the region info and controls floater and panels. + * + * $LicenseInfo:firstyear=2004&license=viewergpl$ + * + * Copyright (c) 2004-2009, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" +#include "llfloaterregioninfo.h" + +#include +#include + +#include "llcachename.h" +#include "lldir.h" +#include "lldispatcher.h" +#include "llglheaders.h" +#include "llregionflags.h" +#include "llstl.h" +#include "indra_constants.h" +#include "message.h" + +#include "llagent.h" +#include "llalertdialog.h" +#include "llappviewer.h" +#include "llfloateravatarpicker.h" +#include "llbutton.h" +#include "llcheckboxctrl.h" +#include "llcombobox.h" +#include "llfilepicker.h" +#include "llfloaterdaycycle.h" +#include "llfloatergodtools.h" // for send_sim_wide_deletes() +#include "llfloatertopobjects.h" // added to fix SL-32336 +#include "llfloatergroups.h" +#include "llfloatertelehub.h" +#include "llfloaterwindlight.h" +#include "llinventorymodel.h" +#include "lllineeditor.h" +#include "llalertdialog.h" +#include "llnamelistctrl.h" +#include "llsliderctrl.h" +#include "llspinctrl.h" +#include "lltabcontainer.h" +#include "lltextbox.h" +#include "llinventory.h" +#include "lltexturectrl.h" +#include "lltrans.h" +#include "llviewercontrol.h" +#include "lluictrlfactory.h" +#include "llviewerimage.h" +#include "llviewerimagelist.h" +#include "llviewerregion.h" +#include "llviewerstats.h" +#include "llviewertexteditor.h" +#include "llviewerwindow.h" +#include "llvlcomposition.h" +#include "hippolimits.h" + +// [RLVa:KB] +#include "rlvhandler.h" +// [/RLVa:KB] + +#define ELAR_ENABLED 0 // Enable when server support is implemented + +const S32 TERRAIN_TEXTURE_COUNT = 4; +const S32 CORNER_COUNT = 4; + +///---------------------------------------------------------------------------- +/// Local class declaration +///---------------------------------------------------------------------------- + +class LLDispatchEstateUpdateInfo : public LLDispatchHandler +{ +public: + LLDispatchEstateUpdateInfo() {} + virtual ~LLDispatchEstateUpdateInfo() {} + virtual bool operator()( + const LLDispatcher* dispatcher, + const std::string& key, + const LLUUID& invoice, + const sparam_t& strings); +}; + +class LLDispatchSetEstateAccess : public LLDispatchHandler +{ +public: + LLDispatchSetEstateAccess() {} + virtual ~LLDispatchSetEstateAccess() {} + virtual bool operator()( + const LLDispatcher* dispatcher, + const std::string& key, + const LLUUID& invoice, + const sparam_t& strings); +}; + + +/* +void unpack_request_params( + LLMessageSystem* msg, + LLDispatcher::sparam_t& strings, + LLDispatcher::iparam_t& integers) +{ + char str_buf[MAX_STRING]; + S32 str_count = msg->getNumberOfBlocksFast(_PREHASH_StringData); + S32 i; + for (i = 0; i < str_count; ++i) + { + // we treat the SParam as binary data (since it might be an + // LLUUID in compressed form which may have embedded \0's,) + str_buf[0] = '\0'; + S32 data_size = msg->getSizeFast(_PREHASH_StringData, i, _PREHASH_SParam); + if (data_size >= 0) + { + msg->getBinaryDataFast(_PREHASH_StringData, _PREHASH_SParam, + str_buf, data_size, i, MAX_STRING - 1); + strings.push_back(std::string(str_buf, data_size)); + } + } + + U32 int_buf; + S32 int_count = msg->getNumberOfBlocksFast(_PREHASH_IntegerData); + for (i = 0; i < int_count; ++i) + { + msg->getU32("IntegerData", "IParam", int_buf, i); + integers.push_back(int_buf); + } +} +*/ + + + +bool estate_dispatch_initialized = false; + + +///---------------------------------------------------------------------------- +/// LLFloaterRegionInfo +///---------------------------------------------------------------------------- + +//S32 LLFloaterRegionInfo::sRequestSerial = 0; +LLUUID LLFloaterRegionInfo::sRequestInvoice; + +LLFloaterRegionInfo::LLFloaterRegionInfo(const LLSD& seed) +{ + LLUICtrlFactory::getInstance()->buildFloater(this, "floater_region_info.xml", NULL, FALSE); +} + +BOOL LLFloaterRegionInfo::postBuild() +{ + mTab = getChild("region_panels"); + + // contruct the panels + LLPanelRegionInfo* panel; + + panel = new LLPanelRegionGeneralInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_general.xml"); + mTab->addTabPanel(panel, panel->getLabel(), TRUE); + + // We only use this panel on Aurora-based sims -- MC + std::string url = gAgent.getRegion()->getCapability("DispatchOpenRegionSettings"); + if (!url.empty()) + { + panel = new LLPanelRegionOpenSettingsInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_open_region_settings.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + } + + panel = new LLPanelRegionDebugInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_debug.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + + panel = new LLPanelRegionTextureInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_texture.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + + panel = new LLPanelRegionTerrainInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_terrain.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + + panel = new LLPanelEstateInfo; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_estate.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + + panel = new LLPanelEstateCovenant; + mInfoPanels.push_back(panel); + LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_region_covenant.xml"); + mTab->addTabPanel(panel, panel->getLabel(), FALSE); + + gMessageSystem->setHandlerFunc( + "EstateOwnerMessage", + &processEstateOwnerRequest); + + return TRUE; +} + +LLFloaterRegionInfo::~LLFloaterRegionInfo() +{ +} + +void LLFloaterRegionInfo::onOpen() +{ + LLRect rect = gSavedSettings.getRect("FloaterRegionInfo"); + S32 left, top; + gFloaterView->getNewFloaterPosition(&left, &top); + rect.translate(left,top); + + refreshFromRegion(gAgent.getRegion()); + requestRegionInfo(); + LLFloater::onOpen(); +} + +// static +void LLFloaterRegionInfo::requestRegionInfo() +{ + LLTabContainer* tab = findInstance()->getChild("region_panels"); + + tab->getChild("General")->setCtrlsEnabled(FALSE); + tab->getChild("Debug")->setCtrlsEnabled(FALSE); + tab->getChild("Terrain")->setCtrlsEnabled(FALSE); + tab->getChild("Estate")->setCtrlsEnabled(FALSE); + tab->getChild("RegionSettings")->setCtrlsEnabled(FALSE); + + // Must allow anyone to request the RegionInfo data + // so non-owners/non-gods can see the values. + // Therefore can't use an EstateOwnerMessage JC + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("RequestRegionInfo"); + msg->nextBlock("AgentData"); + msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("SessionID", gAgent.getSessionID()); + gAgent.sendReliableMessage(); +} + +// static +void LLFloaterRegionInfo::processEstateOwnerRequest(LLMessageSystem* msg,void**) +{ + static LLDispatcher dispatch; + if(!findInstance()) + { + return; + } + + if (!estate_dispatch_initialized) + { + LLPanelEstateInfo::initDispatch(dispatch); + } + + LLTabContainer* tab = findInstance()->getChild("region_panels"); + LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); + + // unpack the message + std::string request; + LLUUID invoice; + LLDispatcher::sparam_t strings; + LLDispatcher::unpackMessage(msg, request, invoice, strings); + if(invoice != getLastInvoice()) + { + llwarns << "Mismatched Estate message: " << request << llendl; + return; + } + + //dispatch the message + dispatch.dispatch(request, invoice, strings); + + LLViewerRegion* region = gAgent.getRegion(); + panel->updateControls(region); +} + + +// static +void LLFloaterRegionInfo::processRegionInfo(LLMessageSystem* msg) +{ + LLPanel* panel; + + llinfos << "LLFloaterRegionInfo::processRegionInfo" << llendl; + if(!findInstance()) + { + return; + } + + LLTabContainer* tab = findInstance()->getChild("region_panels"); + + LLViewerRegion* region = gAgent.getRegion(); + BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); + + // extract message + std::string sim_name; + std::string sim_type = LLTrans::getString("land_type_unknown"); + U32 region_flags; + U8 agent_limit; + F32 object_bonus_factor; + U8 sim_access; + F32 water_height; + F32 terrain_raise_limit; + F32 terrain_lower_limit; + BOOL use_estate_sun; + F32 sun_hour; + msg->getString("RegionInfo", "SimName", sim_name); + msg->getU32("RegionInfo", "RegionFlags", region_flags); + msg->getU8("RegionInfo", "MaxAgents", agent_limit); + msg->getF32("RegionInfo", "ObjectBonusFactor", object_bonus_factor); + msg->getU8("RegionInfo", "SimAccess", sim_access); + msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height); + msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, terrain_raise_limit); + msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, terrain_lower_limit); + msg->getBOOL("RegionInfo", "UseEstateSun", use_estate_sun); + // actually the "last set" sun hour, not the current sun hour. JC + msg->getF32("RegionInfo", "SunHour", sun_hour); + // the only reasonable way to decide if we actually have any data is to + // check to see if any of these fields have nonzero sizes + if (msg->getSize("RegionInfo2", "ProductSKU") > 0 || + msg->getSize("RegionInfo2", "ProductName") > 0) + { + msg->getString("RegionInfo2", "ProductName", sim_type); + } + + // GENERAL PANEL + panel = tab->getChild("General"); + panel->childSetValue("region_text", LLSD(sim_name)); + panel->childSetValue("region_type", LLSD(sim_type)); + panel->childSetValue("version_channel_text", gLastVersionChannel); + + panel->childSetValue("block_terraform_check", (region_flags & REGION_FLAGS_BLOCK_TERRAFORM) ? TRUE : FALSE ); + panel->childSetValue("block_fly_check", (region_flags & REGION_FLAGS_BLOCK_FLY) ? TRUE : FALSE ); + panel->childSetValue("allow_damage_check", (region_flags & REGION_FLAGS_ALLOW_DAMAGE) ? TRUE : FALSE ); + panel->childSetValue("restrict_pushobject", (region_flags & REGION_FLAGS_RESTRICT_PUSHOBJECT) ? TRUE : FALSE ); + panel->childSetValue("allow_land_resell_check", (region_flags & REGION_FLAGS_BLOCK_LAND_RESELL) ? FALSE : TRUE ); + panel->childSetValue("allow_parcel_changes_check", (region_flags & REGION_FLAGS_ALLOW_PARCEL_CHANGES) ? TRUE : FALSE ); + panel->childSetValue("block_parcel_search_check", (region_flags & REGION_FLAGS_BLOCK_PARCEL_SEARCH) ? TRUE : FALSE ); + panel->childSetValue("agent_limit_spin", LLSD((F32)agent_limit) ); + panel->childSetValue("object_bonus_spin", LLSD(object_bonus_factor) ); + panel->childSetValue("access_combo", LLSD(sim_access) ); + + + // detect teen grid for maturity + + U32 parent_estate_id; + msg->getU32("RegionInfo", "ParentEstateID", parent_estate_id); + BOOL teen_grid = (parent_estate_id == 5); // *TODO add field to estate table and test that + panel->childSetEnabled("access_combo", gAgent.isGodlike() || (region && region->canManageEstate() && !teen_grid)); + panel->setCtrlsEnabled(allow_modify); + + // RegionSettings PANEL + panel = tab->getChild("RegionSettings"); + panel->setCtrlsEnabled(allow_modify); + + // DEBUG PANEL + panel = tab->getChild("Debug"); + + panel->childSetValue("region_text", LLSD(sim_name) ); + panel->childSetValue("disable_scripts_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_SCRIPTS)) ); + panel->childSetValue("disable_collisions_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_COLLISIONS)) ); + panel->childSetValue("disable_physics_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SKIP_PHYSICS)) ); + panel->setCtrlsEnabled(allow_modify); + + // TERRAIN PANEL + panel = tab->getChild("Terrain"); + + panel->childSetValue("region_text", LLSD(sim_name)); + panel->childSetValue("water_height_spin", LLSD(water_height)); + panel->childSetValue("terrain_raise_spin", LLSD(terrain_raise_limit)); + panel->childSetValue("terrain_lower_spin", LLSD(terrain_lower_limit)); + panel->childSetValue("use_estate_sun_check", LLSD(use_estate_sun)); + + panel->childSetValue("fixed_sun_check", LLSD((BOOL)(region_flags & REGION_FLAGS_SUN_FIXED))); + panel->childSetEnabled("fixed_sun_check", allow_modify && !use_estate_sun); + panel->childSetValue("sun_hour_slider", LLSD(sun_hour)); + panel->childSetEnabled("sun_hour_slider", allow_modify && !use_estate_sun); + panel->setCtrlsEnabled(allow_modify); + + getInstance()->refreshFromRegion( gAgent.getRegion() ); +} + +// static +LLPanelEstateInfo* LLFloaterRegionInfo::getPanelEstate() +{ + LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); + if (!floater) return NULL; + LLTabContainer* tab = floater->getChild("region_panels"); + LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); + return panel; +} + +// static +LLPanelEstateCovenant* LLFloaterRegionInfo::getPanelCovenant() +{ + LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); + if (!floater) return NULL; + LLTabContainer* tab = floater->getChild("region_panels"); + LLPanelEstateCovenant* panel = (LLPanelEstateCovenant*)tab->getChild("Covenant"); + return panel; +} + +// static +LLPanelRegionOpenSettingsInfo* LLFloaterRegionInfo::getPanelOpenSettings() +{ + LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); + if (floater) + { + LLTabContainer* tab = floater->getChild("region_panels"); + LLPanelRegionOpenSettingsInfo* panel = (LLPanelRegionOpenSettingsInfo*)tab->getChild("RegionSettings", FALSE, FALSE); + if (panel) + { + return panel; + } + } + return NULL; +} + +void LLFloaterRegionInfo::refreshFromRegion(LLViewerRegion* region) +{ + // call refresh from region on all panels + std::for_each( + mInfoPanels.begin(), + mInfoPanels.end(), + llbind2nd( +#if LL_WINDOWS + std::mem_fun1(&LLPanelRegionInfo::refreshFromRegion), +#else + std::mem_fun(&LLPanelRegionInfo::refreshFromRegion), +#endif + region)); +} + +// public +void LLFloaterRegionInfo::refresh() +{ + for(info_panels_t::iterator iter = mInfoPanels.begin(); + iter != mInfoPanels.end(); ++iter) + { + (*iter)->refresh(); + } +} + + +///---------------------------------------------------------------------------- +/// Local class implementation +///---------------------------------------------------------------------------- + +// +// LLPanelRegionInfo +// + +// static +void LLPanelRegionInfo::onBtnSet(void* user_data) +{ + LLPanelRegionInfo* panel = (LLPanelRegionInfo*)user_data; + if(!panel) return; + if (panel->sendUpdate()) + { + panel->disableButton("apply_btn"); + } +} + +//static +void LLPanelRegionInfo::onChangeChildCtrl(LLUICtrl* ctrl, void* user_data) +{ + if (ctrl) + { + LLPanelRegionInfo* panel = (LLPanelRegionInfo*) ctrl->getParent(); + panel->updateChild(ctrl); + } +} + +// static +// Enables the "set" button if it is not already enabled +void LLPanelRegionInfo::onChangeAnything(LLUICtrl* ctrl, void* user_data) +{ + LLPanelRegionInfo* panel = (LLPanelRegionInfo*)user_data; + if(panel) + { + panel->enableButton("apply_btn"); + panel->refresh(); + } +} + +// static +// Enables set button on change to line editor +void LLPanelRegionInfo::onChangeText(LLLineEditor* caller, void* user_data) +{ + // reuse the previous method + onChangeAnything(0, user_data); +} + + +// virtual +BOOL LLPanelRegionInfo::postBuild() +{ + childSetAction("apply_btn", onBtnSet, this); + childDisable("apply_btn"); + refresh(); + return TRUE; +} + +// virtual +void LLPanelRegionInfo::updateChild(LLUICtrl* child_ctr) +{ +} + +// virtual +bool LLPanelRegionInfo::refreshFromRegion(LLViewerRegion* region) +{ + if (region) mHost = region->getHost(); + return true; +} + +void LLPanelRegionInfo::sendEstateOwnerMessage( + LLMessageSystem* msg, + const std::string& request, + const LLUUID& invoice, + const strings_t& strings) +{ + llinfos << "Sending estate request '" << request << "'" << llendl; + msg->newMessage("EstateOwnerMessage"); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); + msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used + msg->nextBlock("MethodData"); + msg->addString("Method", request); + msg->addUUID("Invoice", invoice); + if(strings.empty()) + { + msg->nextBlock("ParamList"); + msg->addString("Parameter", NULL); + } + else + { + strings_t::const_iterator it = strings.begin(); + strings_t::const_iterator end = strings.end(); + for(; it != end; ++it) + { + msg->nextBlock("ParamList"); + msg->addString("Parameter", *it); + } + } + msg->sendReliable(mHost); +} + +void LLPanelRegionInfo::enableButton(const std::string& btn_name, BOOL enable) +{ + childSetEnabled(btn_name, enable); +} + +void LLPanelRegionInfo::disableButton(const std::string& btn_name) +{ + childDisable(btn_name); +} + +void LLPanelRegionInfo::initCtrl(const std::string& name) +{ + childSetCommitCallback(name, onChangeAnything, this); +} + +void LLPanelRegionInfo::initHelpBtn(const std::string& name, const std::string& xml_alert) +{ + childSetAction(name, onClickHelp, new std::string(xml_alert)); +} + +// static +void LLPanelRegionInfo::onClickHelp(void* data) +{ + std::string* xml_alert = (std::string*)data; + LLNotifications::instance().add(*xml_alert); +} + +///////////////////////////////////////////////////////////////////////////// +// LLPanelRegionGeneralInfo +// +bool LLPanelRegionGeneralInfo::refreshFromRegion(LLViewerRegion* region) +{ + BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); + setCtrlsEnabled(allow_modify); + childDisable("apply_btn"); + childSetEnabled("access_text", allow_modify); + // childSetEnabled("access_combo", allow_modify); + // now set in processRegionInfo for teen grid detection + childSetEnabled("kick_btn", allow_modify); + childSetEnabled("kick_all_btn", allow_modify); + childSetEnabled("im_btn", allow_modify); + childSetEnabled("manage_telehub_btn", allow_modify); + + // Data gets filled in by processRegionInfo + + return LLPanelRegionInfo::refreshFromRegion(region); +} + +BOOL LLPanelRegionGeneralInfo::postBuild() +{ + // Enable the "Apply" button if something is changed. JC + initCtrl("block_terraform_check"); + initCtrl("block_fly_check"); + initCtrl("allow_damage_check"); + initCtrl("allow_land_resell_check"); + initCtrl("allow_parcel_changes_check"); + initCtrl("agent_limit_spin"); + initCtrl("object_bonus_spin"); + initCtrl("access_combo"); + initCtrl("restrict_pushobject"); + initCtrl("block_parcel_search_check"); + initCtrl("minimum_agent_age"); + + initHelpBtn("terraform_help", "HelpRegionBlockTerraform"); + initHelpBtn("fly_help", "HelpRegionBlockFly"); + initHelpBtn("damage_help", "HelpRegionAllowDamage"); + initHelpBtn("agent_limit_help", "HelpRegionAgentLimit"); + initHelpBtn("object_bonus_help", "HelpRegionObjectBonus"); + initHelpBtn("access_help", "HelpRegionMaturity"); + initHelpBtn("restrict_pushobject_help", "HelpRegionRestrictPushObject"); + initHelpBtn("land_resell_help", "HelpRegionLandResell"); + initHelpBtn("parcel_changes_help", "HelpParcelChanges"); + initHelpBtn("parcel_search_help", "HelpRegionSearch"); + + childSetAction("kick_btn", onClickKick, this); + childSetAction("kick_all_btn", onClickKickAll, this); + childSetAction("im_btn", onClickMessage, this); + childSetAction("manage_telehub_btn", onClickManageTelehub, this); + + return LLPanelRegionInfo::postBuild(); +} + +// static +void LLPanelRegionGeneralInfo::onClickKick(void* userdata) +{ + llinfos << "LLPanelRegionGeneralInfo::onClickKick" << llendl; + LLPanelRegionGeneralInfo* panelp = (LLPanelRegionGeneralInfo*)userdata; + + // this depends on the grandparent view being a floater + // in order to set up floater dependency + LLFloater* parent_floater = gFloaterView->getParentFloater(panelp); + LLFloater* child_floater = LLFloaterAvatarPicker::show(onKickCommit, userdata, FALSE, TRUE); + parent_floater->addDependentFloater(child_floater); +} + +// static +void LLPanelRegionGeneralInfo::onKickCommit(const std::vector& names, const std::vector& ids, void* userdata) +{ + if (names.empty() || ids.empty()) return; + if(ids[0].notNull()) + { + LLPanelRegionGeneralInfo* self = (LLPanelRegionGeneralInfo*)userdata; + if(!self) return; + strings_t strings; + // [0] = our agent id + // [1] = target agent id + std::string buffer; + gAgent.getID().toString(buffer); + strings.push_back(buffer); + + ids[0].toString(buffer); + strings.push_back(strings_t::value_type(buffer)); + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + self->sendEstateOwnerMessage(gMessageSystem, "teleporthomeuser", invoice, strings); + } +} + +// static +void LLPanelRegionGeneralInfo::onClickKickAll(void* userdata) +{ + llinfos << "LLPanelRegionGeneralInfo::onClickKickAll" << llendl; + LLNotifications::instance().add("KickUsersFromRegion", + LLSD(), + LLSD(), + boost::bind(&LLPanelRegionGeneralInfo::onKickAllCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2)); +} + +bool LLPanelRegionGeneralInfo::onKickAllCommit(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option == 0) + { + strings_t strings; + // [0] = our agent id + std::string buffer; + gAgent.getID().toString(buffer); + strings.push_back(buffer); + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + // historical message name + sendEstateOwnerMessage(gMessageSystem, "teleporthomeallusers", invoice, strings); + } + return false; +} + +// static +void LLPanelRegionGeneralInfo::onClickMessage(void* userdata) +{ + llinfos << "LLPanelRegionGeneralInfo::onClickMessage" << llendl; + LLNotifications::instance().add("MessageRegion", + LLSD(), + LLSD(), + boost::bind(&LLPanelRegionGeneralInfo::onMessageCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2)); +} + +// static +bool LLPanelRegionGeneralInfo::onMessageCommit(const LLSD& notification, const LLSD& response) +{ + if(LLNotification::getSelectedOption(notification, response) != 0) return false; + + std::string text = response["message"].asString(); + if (text.empty()) return false; + + llinfos << "Message to everyone: " << text << llendl; + strings_t strings; + // [0] grid_x, unused here + // [1] grid_y, unused here + // [2] agent_id of sender + // [3] sender name + // [4] message + strings.push_back("-1"); + strings.push_back("-1"); + std::string buffer; + gAgent.getID().toString(buffer); + strings.push_back(buffer); + std::string name; + gAgent.buildFullname(name); + strings.push_back(strings_t::value_type(name)); + strings.push_back(strings_t::value_type(text)); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "simulatormessage", invoice, strings); + return false; +} + +// static +void LLPanelRegionGeneralInfo::onClickManageTelehub(void* data) +{ + LLFloaterRegionInfo::getInstance()->close(); + + LLFloaterTelehub::show(); +} + +// setregioninfo +// strings[0] = 'Y' - block terraform, 'N' - not +// strings[1] = 'Y' - block fly, 'N' - not +// strings[2] = 'Y' - allow damage, 'N' - not +// strings[3] = 'Y' - allow land sale, 'N' - not +// strings[4] = agent limit +// strings[5] = object bonus +// strings[6] = sim access (0 = unknown, 13 = PG, 21 = Mature, 42 = Adult) +// strings[7] = restrict pushobject +// strings[8] = 'Y' - allow parcel subdivide, 'N' - not +// strings[9] = 'Y' - block parcel search, 'N' - allow +BOOL LLPanelRegionGeneralInfo::sendUpdate() +{ + llinfos << "LLPanelRegionGeneralInfo::sendUpdate()" << llendl; + + // First try using a Cap. If that fails use the old method. + LLSD body; + std::string url = gAgent.getRegion()->getCapability("DispatchRegionInfo"); + if (!url.empty()) + { + body["block_terraform"] = childGetValue("block_terraform_check"); + body["block_fly"] = childGetValue("block_fly_check"); + body["allow_damage"] = childGetValue("allow_damage_check"); + body["allow_land_resell"] = childGetValue("allow_land_resell_check"); + body["agent_limit"] = childGetValue("agent_limit_spin"); + body["prim_bonus"] = childGetValue("object_bonus_spin"); + body["sim_access"] = childGetValue("access_combo"); + body["restrict_pushobject"] = childGetValue("restrict_pushobject"); + body["allow_parcel_changes"] = childGetValue("allow_parcel_changes_check"); + body["block_parcel_search"] = childGetValue("block_parcel_search_check"); + body["minimum_agent_age"] = childGetValue("minimum_agent_age"); + + LLHTTPClient::post(url, body, new LLHTTPClient::Responder()); + } + else + { + strings_t strings; + std::string buffer; + + buffer = llformat("%s", (childGetValue("block_terraform_check").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%s", (childGetValue("block_fly_check").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%s", (childGetValue("allow_damage_check").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%s", (childGetValue("allow_land_resell_check").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + F32 value = (F32)childGetValue("agent_limit_spin").asReal(); + buffer = llformat("%f", value); + strings.push_back(strings_t::value_type(buffer)); + + value = (F32)childGetValue("object_bonus_spin").asReal(); + buffer = llformat("%f", value); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%d", childGetValue("access_combo").asInteger()); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%s", (childGetValue("restrict_pushobject").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + buffer = llformat("%s", (childGetValue("allow_parcel_changes_check").asBoolean() ? "Y" : "N")); + strings.push_back(strings_t::value_type(buffer)); + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "setregioninfo", invoice, strings); + } + + // if we changed access levels, tell user about it + LLViewerRegion* region = gAgent.getRegion(); + if (region && (childGetValue("access_combo").asInteger() != region->getSimAccess()) ) + { + LLNotifications::instance().add("RegionMaturityChange"); + } + + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////// +// LLPanelRegionOpenSettingsInfo +// +bool LLPanelRegionOpenSettingsInfo::refreshFromRegion(LLViewerRegion* region) +{ + // Data gets filled in by hippo manager + BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); + + childSetValue("draw_distance", gAgent.mDrawDistance); + childSetValue("force_draw_distance", gAgent.mLockedDrawDistance); + childSetValue("allow_minimap", LLSD(gHippoLimits->mAllowMinimap)); + childSetValue("allow_physical_prims", (gHippoLimits->mAllowPhysicalPrims == 1 ? TRUE : FALSE)); + childSetValue("max_drag_distance", LLSD(gHippoLimits->mMaxDragDistance)); + childSetValue("min_hole_size", LLSD(gHippoLimits->mMinHoleSize)); + childSetValue("max_hollow_size", LLSD(gHippoLimits->mMaxHollow)); + childSetValue("max_inventory_items_transfer", LLSD(gHippoLimits->mMaxInventoryItemsTransfer)); + childSetValue("max_link_count", LLSD(gHippoLimits->mMaxLinkedPrims)); + childSetValue("max_link_count_phys", LLSD(gHippoLimits->mMaxPhysLinkedPrims)); + childSetValue("max_phys_prim_scale", LLSD(gHippoLimits->mMaxPrimScale));//Todo:Fix + childSetValue("max_prim_scale", LLSD(gHippoLimits->mMaxPrimScale)); + childSetValue("min_prim_scale", LLSD(gHippoLimits->mMinPrimScale)); + childSetValue("render_water", LLSD(gHippoLimits->mRenderWater)); + childSetValue("show_tags", LLSD(gHippoLimits->mRenderName)); + childSetValue("max_groups", LLSD(gHippoLimits->mMaxAgentGroups)); + childSetValue("allow_parcel_windlight", LLSD(gHippoLimits->mAllowParcelWindLight)); + childSetValue("enable_teen_mode", LLSD(gHippoLimits->mEnableTeenMode)); + childSetValue("enforce_max_build", LLSD(gHippoLimits->mEnforceMaxBuild)); + + setCtrlsEnabled(allow_modify); + + return LLPanelRegionInfo::refreshFromRegion(region); +} + +BOOL LLPanelRegionOpenSettingsInfo::postBuild() +{ + // Enable the "Apply" button if something is changed. JC + initCtrl("draw_distance"); + initCtrl("force_draw_distance"); + initCtrl("max_drag_distance"); + initCtrl("max_prim_scale"); + initCtrl("min_prim_scale"); + initCtrl("max_phys_prim_scale"); + initCtrl("max_hollow_size"); + initCtrl("min_hole_size"); + initCtrl("max_link_count"); + initCtrl("max_link_count_phys"); + initCtrl("max_inventory_items_transfer"); + initCtrl("max_groups"); + initCtrl("render_water"); + initCtrl("allow_minimap"); + initCtrl("allow_physical_prims"); + initCtrl("enable_teen_mode"); + initCtrl("show_tags"); + initCtrl("allow_parcel_windlight"); + + initHelpBtn("force_draw_distance_help", "HelpForceDrawDistance"); + initHelpBtn("max_inventory_items_transfer_help", "HelpMaxInventoryItemsTransfer"); + initHelpBtn("max_groups_help", "HelpMaxGroups"); + initHelpBtn("render_water_help", "HelpRenderWater"); + initHelpBtn("allow_minimap_help", "HelpAllowMinimap"); + initHelpBtn("allow_physical_prims_help", "HelpAllowPhysicalPrims"); + initHelpBtn("enable_teen_mode_help", "HelpEnableTeenMode"); + initHelpBtn("show_tags_help", "HelpShowTags"); + initHelpBtn("allow_parcel_windlight_help", "HelpAllowParcelWindLight"); + + childSetAction("apply_ors_btn", onClickOrs, this); + + refreshFromRegion(gAgent.getRegion()); + + return LLPanelRegionInfo::postBuild(); +} + +// setregioninfo +// strings[0] = 'Y' - block terraform, 'N' - not +// strings[1] = 'Y' - block fly, 'N' - not +// strings[2] = 'Y' - allow damage, 'N' - not +// strings[3] = 'Y' - allow land sale, 'N' - not +// strings[4] = agent limit +// strings[5] = object bonus +// strings[6] = sim access (0 = unknown, 13 = PG, 21 = Mature, 42 = Adult) +// strings[7] = restrict pushobject +// strings[8] = 'Y' - allow parcel subdivide, 'N' - not +// strings[9] = 'Y' - block parcel search, 'N' - allow +void LLPanelRegionOpenSettingsInfo::onClickOrs(void* userdata) +{ + LLPanelRegionOpenSettingsInfo* self; + self = (LLPanelRegionOpenSettingsInfo*)userdata; + + llinfos << "LLPanelRegionOpenSettingsInfo::onClickOrs()" << llendl; + + LLSD body; + std::string url = gAgent.getRegion()->getCapability("DispatchOpenRegionSettings"); + if (!url.empty()) + { + body["draw_distance"] = self->childGetValue("draw_distance"); + body["force_draw_distance"] = self->childGetValue("force_draw_distance"); + body["allow_minimap"] = self->childGetValue("allow_minimap"); + body["allow_physical_prims"] = self->childGetValue("allow_physical_prims"); + body["max_drag_distance"] = self->childGetValue("max_drag_distance"); + body["min_hole_size"] = self->childGetValue("min_hole_size"); + body["max_hollow_size"] = self->childGetValue("max_hollow_size"); + body["max_inventory_items_transfer"] = self->childGetValue("max_inventory_items_transfer"); + body["max_link_count"] = self->childGetValue("max_link_count"); + body["max_link_count_phys"] = self->childGetValue("max_link_count_phys"); + body["max_phys_prim_scale"] = self->childGetValue("max_phys_prim_scale"); + body["max_prim_scale"] = self->childGetValue("max_prim_scale"); + body["min_prim_scale"] = self->childGetValue("min_prim_scale"); + body["render_water"] = self->childGetValue("render_water"); + body["show_tags"] = self->childGetValue("show_tags"); + body["max_groups"] = self->childGetValue("max_groups"); + body["allow_parcel_windlight"] = self->childGetValue("allow_parcel_windlight"); + body["enable_teen_mode"] = self->childGetValue("enable_teen_mode"); + body["enforce_max_build"] = self->childGetValue("enforce_max_build"); + + LLHTTPClient::post(url, body, new LLHTTPClient::Responder()); + } +} + +///////////////////////////////////////////////////////////////////////////// +// LLPanelRegionDebugInfo +///////////////////////////////////////////////////////////////////////////// +BOOL LLPanelRegionDebugInfo::postBuild() +{ + LLPanelRegionInfo::postBuild(); + initCtrl("disable_scripts_check"); + initCtrl("disable_collisions_check"); + initCtrl("disable_physics_check"); + + initHelpBtn("disable_scripts_help", "HelpRegionDisableScripts"); + initHelpBtn("disable_collisions_help", "HelpRegionDisableCollisions"); + initHelpBtn("disable_physics_help", "HelpRegionDisablePhysics"); + initHelpBtn("top_colliders_help", "HelpRegionTopColliders"); + initHelpBtn("top_scripts_help", "HelpRegionTopScripts"); + initHelpBtn("restart_help", "HelpRegionRestart"); + initHelpBtn("minimum_agent_age_help", "HelpRegionMinimumAge"); + + + childSetAction("choose_avatar_btn", onClickChooseAvatar, this); + childSetAction("return_btn", onClickReturn, this); + childSetAction("top_colliders_btn", onClickTopColliders, this); + childSetAction("top_scripts_btn", onClickTopScripts, this); + childSetAction("restart_btn", onClickRestart, this); + childSetAction("cancel_restart_btn", onClickCancelRestart, this); + + return TRUE; +} + +// virtual +bool LLPanelRegionDebugInfo::refreshFromRegion(LLViewerRegion* region) +{ + BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); + setCtrlsEnabled(allow_modify); + childDisable("apply_btn"); + childDisable("target_avatar_name"); + + childSetEnabled("choose_avatar_btn", allow_modify); + childSetEnabled("return_scripts", allow_modify && !mTargetAvatar.isNull()); + childSetEnabled("return_other_land", allow_modify && !mTargetAvatar.isNull()); + childSetEnabled("return_estate_wide", allow_modify && !mTargetAvatar.isNull()); + childSetEnabled("return_btn", allow_modify && !mTargetAvatar.isNull()); + childSetEnabled("top_colliders_btn", allow_modify); + childSetEnabled("top_scripts_btn", allow_modify); + childSetEnabled("restart_btn", allow_modify); + childSetEnabled("cancel_restart_btn", allow_modify); + + return LLPanelRegionInfo::refreshFromRegion(region); +} + +// virtual +BOOL LLPanelRegionDebugInfo::sendUpdate() +{ + llinfos << "LLPanelRegionDebugInfo::sendUpdate" << llendl; + strings_t strings; + std::string buffer; + + buffer = llformat("%s", (childGetValue("disable_scripts_check").asBoolean() ? "Y" : "N")); + strings.push_back(buffer); + + buffer = llformat("%s", (childGetValue("disable_collisions_check").asBoolean() ? "Y" : "N")); + strings.push_back(buffer); + + buffer = llformat("%s", (childGetValue("disable_physics_check").asBoolean() ? "Y" : "N")); + strings.push_back(buffer); + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "setregiondebug", invoice, strings); + return TRUE; +} + +void LLPanelRegionDebugInfo::onClickChooseAvatar(void* data) +{ + LLFloaterAvatarPicker::show(callbackAvatarID, data, FALSE, TRUE); +} + +// static +void LLPanelRegionDebugInfo::callbackAvatarID(const std::vector& names, const std::vector& ids, void* data) +{ + LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*) data; + if (ids.empty() || names.empty()) return; + self->mTargetAvatar = ids[0]; + self->childSetValue("target_avatar_name", LLSD(names[0])); + self->refreshFromRegion( gAgent.getRegion() ); +} + +// static +void LLPanelRegionDebugInfo::onClickReturn(void* data) +{ + LLPanelRegionDebugInfo* panelp = (LLPanelRegionDebugInfo*) data; + if (panelp->mTargetAvatar.isNull()) return; + + LLSD args; + args["USER_NAME"] = panelp->childGetValue("target_avatar_name").asString(); + LLSD payload; + payload["avatar_id"] = panelp->mTargetAvatar; + + U32 flags = SWD_ALWAYS_RETURN_OBJECTS; + + if (panelp->childGetValue("return_scripts").asBoolean()) + { + flags |= SWD_SCRIPTED_ONLY; + } + + if (panelp->childGetValue("return_other_land").asBoolean()) + { + flags |= SWD_OTHERS_LAND_ONLY; + } + payload["flags"] = int(flags); + payload["return_estate_wide"] = panelp->childGetValue("return_estate_wide").asBoolean(); + LLNotifications::instance().add("EstateObjectReturn", args, payload, + boost::bind(&LLPanelRegionDebugInfo::callbackReturn, panelp, _1, _2)); +} + +bool LLPanelRegionDebugInfo::callbackReturn(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) return false; + + LLUUID target_avatar = notification["payload"]["avatar_id"].asUUID(); + if (!target_avatar.isNull()) + { + U32 flags = notification["payload"]["flags"].asInteger(); + bool return_estate_wide = notification["payload"]["return_estate_wide"]; + if (return_estate_wide) + { + // send as estate message - routed by spaceserver to all regions in estate + strings_t strings; + strings.push_back(llformat("%d", flags)); + strings.push_back(target_avatar.asString()); + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + + sendEstateOwnerMessage(gMessageSystem, "estateobjectreturn", invoice, strings); + } + else + { + // send to this simulator only + send_sim_wide_deletes(target_avatar, flags); + } + } + return false; +} + + +// static +void LLPanelRegionDebugInfo::onClickTopColliders(void* data) +{ + LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; + strings_t strings; + strings.push_back("1"); // one physics step + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + LLFloaterTopObjects::show(); + LLFloaterTopObjects::clearList(); + self->sendEstateOwnerMessage(gMessageSystem, "colliders", invoice, strings); +} + +// static +void LLPanelRegionDebugInfo::onClickTopScripts(void* data) +{ + LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; + strings_t strings; + strings.push_back("6"); // top 5 scripts + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + LLFloaterTopObjects::show(); + LLFloaterTopObjects::clearList(); + self->sendEstateOwnerMessage(gMessageSystem, "scripts", invoice, strings); +} + +// static +void LLPanelRegionDebugInfo::onClickRestart(void* data) +{ + LLNotifications::instance().add("ConfirmRestart", LLSD(), LLSD(), + boost::bind(&LLPanelRegionDebugInfo::callbackRestart, (LLPanelRegionDebugInfo*)data, _1, _2)); +} + +bool LLPanelRegionDebugInfo::callbackRestart(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) return false; + + strings_t strings; + strings.push_back("120"); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings); + return false; +} + +// static +void LLPanelRegionDebugInfo::onClickCancelRestart(void* data) +{ + LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data; + strings_t strings; + strings.push_back("-1"); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + self->sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings); +} + + +///////////////////////////////////////////////////////////////////////////// +// LLPanelRegionTextureInfo +// +LLPanelRegionTextureInfo::LLPanelRegionTextureInfo() : LLPanelRegionInfo() +{ + // nothing. +} + +bool LLPanelRegionTextureInfo::refreshFromRegion(LLViewerRegion* region) +{ + BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate()); + setCtrlsEnabled(allow_modify); + childDisable("apply_btn"); + + if (region) + { + childSetValue("region_text", LLSD(region->getName())); + } + else + { + childSetValue("region_text", LLSD("")); + } + + if (!region) return LLPanelRegionInfo::refreshFromRegion(region); + + LLVLComposition* compp = region->getComposition(); + LLTextureCtrl* texture_ctrl; + std::string buffer; + for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) + { + buffer = llformat("texture_detail_%d", i); + texture_ctrl = getChild(buffer); + if(texture_ctrl) + { + lldebugs << "Detail Texture " << i << ": " + << compp->getDetailTextureID(i) << llendl; + LLUUID tmp_id(compp->getDetailTextureID(i)); + texture_ctrl->setImageAssetID(tmp_id); + } + } + + for(S32 i = 0; i < CORNER_COUNT; ++i) + { + buffer = llformat("height_start_spin_%d", i); + childSetValue(buffer, LLSD(compp->getStartHeight(i))); + buffer = llformat("height_range_spin_%d", i); + childSetValue(buffer, LLSD(compp->getHeightRange(i))); + } + + // Call the parent for common book-keeping + return LLPanelRegionInfo::refreshFromRegion(region); +} + + +BOOL LLPanelRegionTextureInfo::postBuild() +{ + LLPanelRegionInfo::postBuild(); + std::string buffer; + for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) + { + buffer = llformat("texture_detail_%d", i); + initCtrl(buffer); + } + + for(S32 i = 0; i < CORNER_COUNT; ++i) + { + buffer = llformat("height_start_spin_%d", i); + initCtrl(buffer); + buffer = llformat("height_range_spin_%d", i); + initCtrl(buffer); + } + +// LLButton* btn = new LLButton("dump", LLRect(0, 20, 100, 0), "", onClickDump, this); +// btn->setFollows(FOLLOWS_TOP|FOLLOWS_LEFT); +// addChild(btn); + + return LLPanelRegionInfo::postBuild(); +} + +BOOL LLPanelRegionTextureInfo::sendUpdate() +{ + llinfos << "LLPanelRegionTextureInfo::sendUpdate()" << llendl; + + // Make sure user hasn't chosen wacky textures. + //if (!validateTextureSizes()) + //{ + // return FALSE; + //} + + LLTextureCtrl* texture_ctrl; + std::string buffer; + std::string id_str; + LLMessageSystem* msg = gMessageSystem; + strings_t strings; + + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + + for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) + { + buffer = llformat("texture_detail_%d", i); + texture_ctrl = getChild(buffer); + if(texture_ctrl) + { + LLUUID tmp_id(texture_ctrl->getImageAssetID()); + tmp_id.toString(id_str); + buffer = llformat("%d %s", i, id_str.c_str()); + strings.push_back(buffer); + } + } + sendEstateOwnerMessage(msg, "texturedetail", invoice, strings); + strings.clear(); + for(S32 i = 0; i < CORNER_COUNT; ++i) + { + buffer = llformat("height_start_spin_%d", i); + std::string buffer2 = llformat("height_range_spin_%d", i); + std::string buffer3 = llformat("%d %f %f", i, (F32)childGetValue(buffer).asReal(), (F32)childGetValue(buffer2).asReal()); + strings.push_back(buffer3); + } + sendEstateOwnerMessage(msg, "textureheights", invoice, strings); + strings.clear(); + sendEstateOwnerMessage(msg, "texturecommit", invoice, strings); + return TRUE; +} + +BOOL LLPanelRegionTextureInfo::validateTextureSizes() +{ + for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i) + { + std::string buffer; + buffer = llformat("texture_detail_%d", i); + LLTextureCtrl* texture_ctrl = getChild(buffer); + if (!texture_ctrl) continue; + + LLUUID image_asset_id = texture_ctrl->getImageAssetID(); + LLViewerImage* img = gImageList.getImage(image_asset_id); + S32 components = img->getComponents(); + // Must ask for highest resolution version's width. JC + S32 width = img->getWidth(0); + S32 height = img->getHeight(0); + + //llinfos << "texture detail " << i << " is " << width << "x" << height << "x" << components << llendl; + + if (components != 3) + { + LLSD args; + args["TEXTURE_NUM"] = i+1; + args["TEXTURE_BIT_DEPTH"] = llformat("%d",components * 8); + LLNotifications::instance().add("InvalidTerrainBitDepth", args); + return FALSE; + } + + if (width > 512 || height > 512) + { + + LLSD args; + args["TEXTURE_NUM"] = i+1; + args["TEXTURE_SIZE_X"] = width; + args["TEXTURE_SIZE_Y"] = height; + LLNotifications::instance().add("InvalidTerrainSize", args); + return FALSE; + + } + } + + return TRUE; +} + + +// static +void LLPanelRegionTextureInfo::onClickDump(void* data) +{ + llinfos << "LLPanelRegionTextureInfo::onClickDump()" << llendl; +} + + +///////////////////////////////////////////////////////////////////////////// +// LLPanelRegionTerrainInfo +///////////////////////////////////////////////////////////////////////////// +BOOL LLPanelRegionTerrainInfo::postBuild() +{ + LLPanelRegionInfo::postBuild(); + + initHelpBtn("water_height_help", "HelpRegionWaterHeight"); + initHelpBtn("terrain_raise_help", "HelpRegionTerrainRaise"); + initHelpBtn("terrain_lower_help", "HelpRegionTerrainLower"); + initHelpBtn("upload_raw_help", "HelpRegionUploadRaw"); + initHelpBtn("download_raw_help", "HelpRegionDownloadRaw"); + initHelpBtn("use_estate_sun_help", "HelpRegionUseEstateSun"); + initHelpBtn("fixed_sun_help", "HelpRegionFixedSun"); + initHelpBtn("bake_terrain_help", "HelpRegionBakeTerrain"); + + initCtrl("water_height_spin"); + initCtrl("terrain_raise_spin"); + initCtrl("terrain_lower_spin"); + + initCtrl("fixed_sun_check"); + childSetCommitCallback("fixed_sun_check", onChangeFixedSun, this); + childSetCommitCallback("use_estate_sun_check", onChangeUseEstateTime, this); + childSetCommitCallback("sun_hour_slider", onChangeSunHour, this); + + childSetAction("download_raw_btn", onClickDownloadRaw, this); + childSetAction("upload_raw_btn", onClickUploadRaw, this); + childSetAction("bake_terrain_btn", onClickBakeTerrain, this); + + return TRUE; +} + +// virtual +bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region) +{ + llinfos << "LLPanelRegionTerrainInfo::refreshFromRegion" << llendl; + + BOOL owner_or_god = gAgent.isGodlike() + || (region && (region->getOwner() == gAgent.getID())); + BOOL owner_or_god_or_manager = owner_or_god + || (region && region->isEstateManager()); + setCtrlsEnabled(owner_or_god_or_manager); + childDisable("apply_btn"); + + childSetEnabled("download_raw_btn", owner_or_god); + childSetEnabled("upload_raw_btn", owner_or_god); + childSetEnabled("bake_terrain_btn", owner_or_god); + + return LLPanelRegionInfo::refreshFromRegion(region); +} + +// virtual +BOOL LLPanelRegionTerrainInfo::sendUpdate() +{ + llinfos << "LLPanelRegionTerrainInfo::sendUpdate" << llendl; + std::string buffer; + strings_t strings; + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + + buffer = llformat("%f", (F32)childGetValue("water_height_spin").asReal()); + strings.push_back(buffer); + buffer = llformat("%f", (F32)childGetValue("terrain_raise_spin").asReal()); + strings.push_back(buffer); + buffer = llformat("%f", (F32)childGetValue("terrain_lower_spin").asReal()); + strings.push_back(buffer); + buffer = llformat("%s", (childGetValue("use_estate_sun_check").asBoolean() ? "Y" : "N")); + strings.push_back(buffer); + buffer = llformat("%s", (childGetValue("fixed_sun_check").asBoolean() ? "Y" : "N")); + strings.push_back(buffer); + buffer = llformat("%f", (F32)childGetValue("sun_hour_slider").asReal() ); + strings.push_back(buffer); + + // Grab estate information in case the user decided to set the + // region back to estate time. JC + LLFloaterRegionInfo* floater = LLFloaterRegionInfo::getInstance(); + if (!floater) return true; + + LLTabContainer* tab = floater->getChild("region_panels"); + if (!tab) return true; + + LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild("Estate"); + if (!panel) return true; + + BOOL estate_global_time = panel->getGlobalTime(); + BOOL estate_fixed_sun = panel->getFixedSun(); + F32 estate_sun_hour; + if (estate_global_time) + { + estate_sun_hour = 0.f; + } + else + { + estate_sun_hour = panel->getSunHour(); + } + + buffer = llformat("%s", (estate_global_time ? "Y" : "N") ); + strings.push_back(buffer); + buffer = llformat("%s", (estate_fixed_sun ? "Y" : "N") ); + strings.push_back(buffer); + buffer = llformat("%f", estate_sun_hour); + strings.push_back(buffer); + + sendEstateOwnerMessage(gMessageSystem, "setregionterrain", invoice, strings); + return TRUE; +} + +// static +void LLPanelRegionTerrainInfo::onChangeUseEstateTime(LLUICtrl* ctrl, void* user_data) +{ + LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) user_data; + if (!panel) return; + BOOL use_estate_sun = panel->childGetValue("use_estate_sun_check").asBoolean(); + panel->childSetEnabled("fixed_sun_check", !use_estate_sun); + panel->childSetEnabled("sun_hour_slider", !use_estate_sun); + if (use_estate_sun) + { + panel->childSetValue("fixed_sun_check", LLSD(FALSE)); + panel->childSetValue("sun_hour_slider", LLSD(0.f)); + } + panel->childEnable("apply_btn"); +} + +// static +void LLPanelRegionTerrainInfo::onChangeFixedSun(LLUICtrl* ctrl, void* user_data) +{ + LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) user_data; + if (!panel) return; + // Just enable the apply button. We let the sun-hour slider be enabled + // for both fixed-sun and non-fixed-sun. JC + panel->childEnable("apply_btn"); +} + +// static +void LLPanelRegionTerrainInfo::onChangeSunHour(LLUICtrl* ctrl, void*) +{ + // can't use userdata to get panel, slider uses it internally + LLPanelRegionTerrainInfo* panel = (LLPanelRegionTerrainInfo*) ctrl->getParent(); + if (!panel) return; + panel->childEnable("apply_btn"); +} + +// static +void LLPanelRegionTerrainInfo::onClickDownloadRaw(void* data) +{ + LLFilePicker& picker = LLFilePicker::instance(); + if (!picker.getSaveFile(LLFilePicker::FFSAVE_RAW, "terrain.raw")) + { + llwarns << "No file" << llendl; + return; + } + std::string filepath = picker.getFirstFile(); + gXferManager->expectFileForRequest(filepath); + + LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data; + strings_t strings; + strings.push_back("download filename"); + strings.push_back(filepath); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); +} + +// static +void LLPanelRegionTerrainInfo::onClickUploadRaw(void* data) +{ + LLFilePicker& picker = LLFilePicker::instance(); + if (!picker.getOpenFile(LLFilePicker::FFLOAD_RAW)) + { + llwarns << "No file" << llendl; + return; + } + std::string filepath = picker.getFirstFile(); + gXferManager->expectFileForTransfer(filepath); + + LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data; + strings_t strings; + strings.push_back("upload filename"); + strings.push_back(filepath); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); + + LLNotifications::instance().add("RawUploadStarted"); +} + +// static +void LLPanelRegionTerrainInfo::onClickBakeTerrain(void* data) +{ + LLNotifications::instance().add( + LLNotification::Params("ConfirmBakeTerrain") + .functor(boost::bind(&LLPanelRegionTerrainInfo::callbackBakeTerrain, (LLPanelRegionTerrainInfo*)data, _1, _2))); +} + +bool LLPanelRegionTerrainInfo::callbackBakeTerrain(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) return false; + + strings_t strings; + strings.push_back("bake"); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings); + return false; +} + +///////////////////////////////////////////////////////////////////////////// +// LLPanelEstateInfo +// + +LLPanelEstateInfo::LLPanelEstateInfo() +: LLPanelRegionInfo(), + mEstateID(0) // invalid +{ +} + +// static +void LLPanelEstateInfo::initDispatch(LLDispatcher& dispatch) +{ + std::string name; + +// name.assign("setowner"); +// static LLDispatchSetEstateOwner set_owner; +// dispatch.addHandler(name, &set_owner); + + name.assign("estateupdateinfo"); + static LLDispatchEstateUpdateInfo estate_update_info; + dispatch.addHandler(name, &estate_update_info); + + name.assign("setaccess"); + static LLDispatchSetEstateAccess set_access; + dispatch.addHandler(name, &set_access); + + estate_dispatch_initialized = true; +} + +// static +// Disables the sun-hour slider and the use fixed time check if the use global time is check +void LLPanelEstateInfo::onChangeUseGlobalTime(LLUICtrl* ctrl, void* user_data) +{ + LLPanelEstateInfo* panel = (LLPanelEstateInfo*) user_data; + if (panel) + { + bool enabled = !panel->childGetValue("use_global_time_check").asBoolean(); + panel->childSetEnabled("sun_hour_slider", enabled); + panel->childSetEnabled("fixed_sun_check", enabled); + panel->childSetValue("fixed_sun_check", LLSD(FALSE)); + panel->enableButton("apply_btn"); + } +} + +// Enables the sun-hour slider if the fixed-sun checkbox is set +void LLPanelEstateInfo::onChangeFixedSun(LLUICtrl* ctrl, void* user_data) +{ + LLPanelEstateInfo* panel = (LLPanelEstateInfo*) user_data; + if (panel) + { + bool enabled = !panel->childGetValue("fixed_sun_check").asBoolean(); + panel->childSetEnabled("use_global_time_check", enabled); + panel->childSetValue("use_global_time_check", LLSD(FALSE)); + panel->enableButton("apply_btn"); + } +} + + + + +//--------------------------------------------------------------------------- +// Add/Remove estate access button callbacks +//--------------------------------------------------------------------------- +void LLPanelEstateInfo::onClickEditSky(void* user_data) +{ + LLFloaterWindLight::show(); +} + +void LLPanelEstateInfo::onClickEditDayCycle(void* user_data) +{ + LLFloaterDayCycle::show(); +} + +// static +void LLPanelEstateInfo::onClickAddAllowedAgent(void* user_data) +{ + LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; + LLCtrlListInterface *list = self->childGetListInterface("allowed_avatar_name_list"); + if (!list) return; + if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) + { + //args + + LLSD args; + args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); + LLNotifications::instance().add("MaxAllowedAgentOnRegion", args); + return; + } + accessAddCore(ESTATE_ACCESS_ALLOWED_AGENT_ADD, "EstateAllowedAgentAdd"); +} + +// static +void LLPanelEstateInfo::onClickRemoveAllowedAgent(void* user_data) +{ + accessRemoveCore(ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, "EstateAllowedAgentRemove", "allowed_avatar_name_list"); +} + +// static +void LLPanelEstateInfo::onClickAddAllowedGroup(void* user_data) +{ + LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; + LLCtrlListInterface *list = self->childGetListInterface("allowed_group_name_list"); + if (!list) return; + if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) + { + LLSD args; + args["MAX_GROUPS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); + LLNotifications::instance().add("MaxAllowedGroupsOnRegion", args); + return; + } + + LLNotification::Params params("ChangeLindenAccess"); + params.functor(boost::bind(&LLPanelEstateInfo::addAllowedGroup, self, _1, _2)); + if (isLindenEstate()) + { + LLNotifications::instance().add(params); + } + else + { + LLNotifications::instance().forceResponse(params, 0); + } +} + +bool LLPanelEstateInfo::addAllowedGroup(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) return false; + + LLFloater* parent_floater = gFloaterView->getParentFloater(this); + + LLFloaterGroupPicker* widget; + widget = LLFloaterGroupPicker::showInstance(LLSD(gAgent.getID())); + if (widget) + { + widget->setSelectCallback(addAllowedGroup2, NULL); + if (parent_floater) + { + LLRect new_rect = gFloaterView->findNeighboringPosition(parent_floater, widget); + widget->setOrigin(new_rect.mLeft, new_rect.mBottom); + parent_floater->addDependentFloater(widget); + } + } + + return false; +} + +// static +void LLPanelEstateInfo::onClickRemoveAllowedGroup(void* user_data) +{ + accessRemoveCore(ESTATE_ACCESS_ALLOWED_GROUP_REMOVE, "EstateAllowedGroupRemove", "allowed_group_name_list"); +} + +// static +void LLPanelEstateInfo::onClickAddBannedAgent(void* user_data) +{ + LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; + LLCtrlListInterface *list = self->childGetListInterface("banned_avatar_name_list"); + if (!list) return; + if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS) + { + LLSD args; + args["MAX_BANNED"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); + LLNotifications::instance().add("MaxBannedAgentsOnRegion", args); + return; + } + accessAddCore(ESTATE_ACCESS_BANNED_AGENT_ADD, "EstateBannedAgentAdd"); +} + +// static +void LLPanelEstateInfo::onClickRemoveBannedAgent(void* user_data) +{ + accessRemoveCore(ESTATE_ACCESS_BANNED_AGENT_REMOVE, "EstateBannedAgentRemove", "banned_avatar_name_list"); +} + +// static +void LLPanelEstateInfo::onClickAddEstateManager(void* user_data) +{ + LLPanelEstateInfo* self = (LLPanelEstateInfo*)user_data; + LLCtrlListInterface *list = self->childGetListInterface("estate_manager_name_list"); + if (!list) return; + if (list->getItemCount() >= ESTATE_MAX_MANAGERS) + { // Tell user they can't add more managers + LLSD args; + args["MAX_MANAGER"] = llformat("%d",ESTATE_MAX_MANAGERS); + LLNotifications::instance().add("MaxManagersOnRegion", args); + } + else + { // Go pick managers to add + accessAddCore(ESTATE_ACCESS_MANAGER_ADD, "EstateManagerAdd"); + } +} + +// static +void LLPanelEstateInfo::onClickRemoveEstateManager(void* user_data) +{ + accessRemoveCore(ESTATE_ACCESS_MANAGER_REMOVE, "EstateManagerRemove", "estate_manager_name_list"); +} + +//--------------------------------------------------------------------------- +// Kick from estate methods +//--------------------------------------------------------------------------- +struct LLKickFromEstateInfo +{ + LLPanelEstateInfo *mEstatePanelp; + LLUUID mAgentID; +}; + +void LLPanelEstateInfo::onClickKickUser(void *user_data) +{ + LLPanelEstateInfo* panelp = (LLPanelEstateInfo*)user_data; + + // this depends on the grandparent view being a floater + // in order to set up floater dependency + LLFloater* parent_floater = gFloaterView->getParentFloater(panelp); + LLFloater* child_floater = LLFloaterAvatarPicker::show(LLPanelEstateInfo::onKickUserCommit, user_data, FALSE, TRUE); + parent_floater->addDependentFloater(child_floater); +} + +void LLPanelEstateInfo::onKickUserCommit(const std::vector& names, const std::vector& ids, void* userdata) +{ + if (names.empty() || ids.empty()) return; + + //check to make sure there is one valid user and id + if( (ids[0].isNull()) || + (names[0].length() == 0) ) + { + return; + } + + LLPanelEstateInfo* self = (LLPanelEstateInfo*)userdata; + if(!self) return; + + //keep track of what user they want to kick and other misc info + LLKickFromEstateInfo *kick_info = new LLKickFromEstateInfo(); + kick_info->mEstatePanelp = self; + kick_info->mAgentID = ids[0]; + + //Bring up a confirmation dialog + LLSD args; + args["EVIL_USER"] = names[0]; + LLSD payload; + payload["agent_id"] = ids[0]; + LLNotifications::instance().add("EstateKickUser", args, payload, boost::bind(&LLPanelEstateInfo::kickUserConfirm, self, _1, _2)); + +} + +bool LLPanelEstateInfo::kickUserConfirm(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + switch(option) + { + case 0: + { + //Kick User + strings_t strings; + strings.push_back(notification["payload"]["agent_id"].asString()); + + sendEstateOwnerMessage(gMessageSystem, "kickestate", LLFloaterRegionInfo::getLastInvoice(), strings); + break; + } + default: + break; + } + return false; +} + +//--------------------------------------------------------------------------- +// Core Add/Remove estate access methods +// TODO: INTERNATIONAL: don't build message text here; +// instead, create multiple translatable messages and choose +// one based on the status. +//--------------------------------------------------------------------------- +std::string all_estates_text() +{ + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return "(error)"; + + std::string owner = panel->getOwnerName(); + + LLViewerRegion* region = gAgent.getRegion(); + if (gAgent.isGodlike()) + { + return llformat("all estates\nowned by %s", owner.c_str()); + } + else if (region && region->getOwner() == gAgent.getID()) + { + return "all estates you own"; + } + else if (region && region->isEstateManager()) + { + return llformat("all estates that\nyou manage for %s", owner.c_str()); + } + else + { + return "(error)"; + } +} + +// static +bool LLPanelEstateInfo::isLindenEstate() +{ + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return false; + + U32 estate_id = panel->getEstateID(); + return (estate_id <= ESTATE_LAST_LINDEN); +} + +typedef std::vector AgentOrGroupIDsVector; +struct LLEstateAccessChangeInfo +{ + LLEstateAccessChangeInfo(const LLSD& sd) + { + mDialogName = sd["dialog_name"].asString(); + mOperationFlag = (U32)sd["operation"].asInteger(); + LLSD::array_const_iterator end_it = sd["allowed_ids"].endArray(); + for (LLSD::array_const_iterator id_it = sd["allowed_ids"].beginArray(); + id_it != end_it; + ++id_it) + { + mAgentOrGroupIDs.push_back(id_it->asUUID()); + } + } + + const LLSD asLLSD() const + { + LLSD sd; + sd["name"] = mDialogName; + sd["operation"] = (S32)mOperationFlag; + for (AgentOrGroupIDsVector::const_iterator it = mAgentOrGroupIDs.begin(); + it != mAgentOrGroupIDs.end(); + ++it) + { + sd["allowed_ids"].append(*it); + } + return sd; + } + + U32 mOperationFlag; // ESTATE_ACCESS_BANNED_AGENT_ADD, _REMOVE, etc. + std::string mDialogName; + AgentOrGroupIDsVector mAgentOrGroupIDs; // List of agent IDs to apply to this change +}; + +// Special case callback for groups, since it has different callback format than names +// static +void LLPanelEstateInfo::addAllowedGroup2(LLUUID id, void* user_data) +{ + LLSD payload; + payload["operation"] = (S32)ESTATE_ACCESS_ALLOWED_GROUP_ADD; + payload["dialog_name"] = "EstateAllowedGroupAdd"; + payload["allowed_ids"].append(id); + + LLSD args; + args["ALL_ESTATES"] = all_estates_text(); + + LLNotification::Params params("EstateAllowedGroupAdd"); + params.payload(payload) + .substitutions(args) + .functor(accessCoreConfirm); + if (isLindenEstate()) + { + LLNotifications::instance().forceResponse(params, 0); + } + else + { + LLNotifications::instance().add(params); + } +} + +// static +void LLPanelEstateInfo::accessAddCore(U32 operation_flag, const std::string& dialog_name) +{ + LLSD payload; + payload["operation"] = (S32)operation_flag; + payload["dialog_name"] = dialog_name; + // agent id filled in after avatar picker + + LLNotification::Params params("ChangeLindenAccess"); + params.payload(payload) + .functor(accessAddCore2); + + if (isLindenEstate()) + { + LLNotifications::instance().add(params); + } + else + { + // same as clicking "OK" + LLNotifications::instance().forceResponse(params, 0); + } +} + +// static +bool LLPanelEstateInfo::accessAddCore2(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) + { + // abort change + return false; + } + + LLEstateAccessChangeInfo* change_info = new LLEstateAccessChangeInfo(notification["payload"]); + // avatar picker yes multi-select, yes close-on-select + LLFloaterAvatarPicker::show(accessAddCore3, (void*)change_info, TRUE, TRUE); + return false; +} + +// static +void LLPanelEstateInfo::accessAddCore3(const std::vector& names, const std::vector& ids, void* data) +{ + LLEstateAccessChangeInfo* change_info = (LLEstateAccessChangeInfo*)data; + if (!change_info) return; + if (ids.empty()) + { + // User didn't select a name. + delete change_info; + change_info = NULL; + return; + } + // User did select a name. + change_info->mAgentOrGroupIDs = ids; + // Can't put estate owner on ban list + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return; + LLViewerRegion* region = gAgent.getRegion(); + if (!region) return; + + if (change_info->mOperationFlag & ESTATE_ACCESS_ALLOWED_AGENT_ADD) + { + LLCtrlListInterface *list = panel->childGetListInterface("allowed_avatar_name_list"); + int currentCount = (list ? list->getItemCount() : 0); + if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS) + { + LLSD args; + args["NUM_ADDED"] = llformat("%d",ids.size()); + args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); + args["LIST_TYPE"] = "Allowed Residents"; + args["NUM_EXCESS"] = llformat("%d",(ids.size()+currentCount)-ESTATE_MAX_ACCESS_IDS); + LLNotifications::instance().add("MaxAgentOnRegionBatch", args); + delete change_info; + return; + } + } + if (change_info->mOperationFlag & ESTATE_ACCESS_BANNED_AGENT_ADD) + { + LLCtrlListInterface *list = panel->childGetListInterface("banned_avatar_name_list"); + int currentCount = (list ? list->getItemCount() : 0); + if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS) + { + LLSD args; + args["NUM_ADDED"] = llformat("%d",ids.size()); + args["MAX_AGENTS"] = llformat("%d",ESTATE_MAX_ACCESS_IDS); + args["LIST_TYPE"] = "Banned Residents"; + args["NUM_EXCESS"] = llformat("%d",(ids.size()+currentCount)-ESTATE_MAX_ACCESS_IDS); + LLNotifications::instance().add("MaxAgentOnRegionBatch", args); + delete change_info; + return; + } + } + + LLSD args; + args["ALL_ESTATES"] = all_estates_text(); + + LLNotification::Params params(change_info->mDialogName); + params.substitutions(args) + .payload(change_info->asLLSD()) + .functor(accessCoreConfirm); + + if (isLindenEstate()) + { + // just apply to this estate + LLNotifications::instance().forceResponse(params, 0); + } + else + { + // ask if this estate or all estates with this owner + LLNotifications::instance().add(params); + } +} + +// static +void LLPanelEstateInfo::accessRemoveCore(U32 operation_flag, const std::string& dialog_name, const std::string& list_ctrl_name) +{ + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return; + LLNameListCtrl* name_list = panel->getChild(list_ctrl_name); + if (!name_list) return; + + std::vector list_vector = name_list->getAllSelected(); + if (list_vector.size() == 0) + return; + + LLSD payload; + payload["operation"] = (S32)operation_flag; + payload["dialog_name"] = dialog_name; + + for (std::vector::const_iterator iter = list_vector.begin(); + iter != list_vector.end(); + iter++) + { + LLScrollListItem *item = (*iter); + payload["allowed_ids"].append(item->getUUID()); + } + + LLNotification::Params params("ChangeLindenAccess"); + params.payload(payload) + .functor(accessRemoveCore2); + + if (isLindenEstate()) + { + // warn on change linden estate + LLNotifications::instance().add(params); + } + else + { + // just proceed, as if clicking OK + LLNotifications::instance().forceResponse(params, 0); + } +} + +// static +bool LLPanelEstateInfo::accessRemoveCore2(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + if (option != 0) + { + // abort + return false; + } + + // If Linden estate, can only apply to "this" estate, not all estates + // owned by NULL. + if (isLindenEstate()) + { + accessCoreConfirm(notification, response); + } + else + { + LLSD args; + args["ALL_ESTATES"] = all_estates_text(); + LLNotifications::instance().add(notification["payload"]["dialog_name"], + args, + notification["payload"], + accessCoreConfirm); + } + return false; +} + +// Used for both access add and remove operations, depending on the mOperationFlag +// passed in (ESTATE_ACCESS_BANNED_AGENT_ADD, ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, etc.) +// static +bool LLPanelEstateInfo::accessCoreConfirm(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger(); + + LLViewerRegion* region = gAgent.getRegion(); + + LLSD::array_const_iterator end_it = notification["payload"]["allowed_ids"].endArray(); + + for (LLSD::array_const_iterator iter = notification["payload"]["allowed_ids"].beginArray(); + iter != end_it; + iter++) + { + U32 flags = originalFlags; + if (iter + 1 != end_it) + flags |= ESTATE_ACCESS_NO_REPLY; + + const LLUUID id = iter->asUUID(); + if (((U32)notification["payload"]["operation"].asInteger() & ESTATE_ACCESS_BANNED_AGENT_ADD) + && region && (region->getOwner() == id)) + { + LLNotifications::instance().add("OwnerCanNotBeDenied"); + break; + } + switch(option) + { + case 0: + // This estate + sendEstateAccessDelta(flags, id); + break; + case 1: + { + // All estates, either than I own or manage for this owner. + // This will be verified on simulator. JC + if (!region) break; + if (region->getOwner() == gAgent.getID() + || gAgent.isGodlike()) + { + flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES; + sendEstateAccessDelta(flags, id); + } + else if (region->isEstateManager()) + { + flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES; + sendEstateAccessDelta(flags, id); + } + break; + } + case 2: + default: + break; + } + } + return false; +} + +// key = "estateaccessdelta" +// str(estate_id) will be added to front of list by forward_EstateOwnerRequest_to_dataserver +// str[0] = str(agent_id) requesting the change +// str[1] = str(flags) (ESTATE_ACCESS_DELTA_*) +// str[2] = str(agent_id) to add or remove +// static +void LLPanelEstateInfo::sendEstateAccessDelta(U32 flags, const LLUUID& agent_or_group_id) +{ + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("EstateOwnerMessage"); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); + msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used + + msg->nextBlock("MethodData"); + msg->addString("Method", "estateaccessdelta"); + msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); + + std::string buf; + gAgent.getID().toString(buf); + msg->nextBlock("ParamList"); + msg->addString("Parameter", buf); + + buf = llformat("%u", flags); + msg->nextBlock("ParamList"); + msg->addString("Parameter", buf); + + agent_or_group_id.toString(buf); + msg->nextBlock("ParamList"); + msg->addString("Parameter", buf); + + + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + + if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_ALLOWED_AGENT_REMOVE | + ESTATE_ACCESS_BANNED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_REMOVE)) + { + + panel->clearAccessLists(); + } + + gAgent.sendReliableMessage(); +} + +void LLPanelEstateInfo::updateControls(LLViewerRegion* region) +{ + BOOL god = gAgent.isGodlike(); + BOOL owner = (region && (region->getOwner() == gAgent.getID())); + BOOL manager = (region && region->isEstateManager()); + setCtrlsEnabled(god || owner || manager); + + childDisable("apply_btn"); + childSetEnabled("add_allowed_avatar_btn", god || owner || manager); + childSetEnabled("remove_allowed_avatar_btn", god || owner || manager); + childSetEnabled("add_allowed_group_btn", god || owner || manager); + childSetEnabled("remove_allowed_group_btn", god || owner || manager); + childSetEnabled("add_banned_avatar_btn", god || owner || manager); + childSetEnabled("remove_banned_avatar_btn", god || owner || manager); + childSetEnabled("message_estate_btn", god || owner || manager); + childSetEnabled("kick_user_from_estate_btn", god || owner || manager); + childSetEnabled("abuse_email_address", god || owner || manager); + + // estate managers can't add estate managers + childSetEnabled("add_estate_manager_btn", god || owner); + childSetEnabled("remove_estate_manager_btn", god || owner); + childSetEnabled("estate_manager_name_list", god || owner); +} + +bool LLPanelEstateInfo::refreshFromRegion(LLViewerRegion* region) +{ + updateControls(region); + + // let the parent class handle the general data collection. + bool rv = LLPanelRegionInfo::refreshFromRegion(region); + + // We want estate info. To make sure it works across region + // boundaries and multiple packets, we add a serial number to the + // integers and track against that on update. + strings_t strings; + //integers_t integers; + //LLFloaterRegionInfo::incrementSerial(); + LLFloaterRegionInfo::nextInvoice(); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + //integers.push_back(LLFloaterRegionInfo::());::getPanelEstate(); + + + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + panel->clearAccessLists(); + + + sendEstateOwnerMessage(gMessageSystem, "getinfo", invoice, strings); + + refresh(); + + return rv; +} + +void LLPanelEstateInfo::updateChild(LLUICtrl* child_ctrl) +{ + if (checkRemovalButton(child_ctrl->getName())) + { + // do nothing + } + else if (checkSunHourSlider(child_ctrl)) + { + // do nothing + } +} + +bool LLPanelEstateInfo::estateUpdate(LLMessageSystem* msg) +{ + llinfos << "LLPanelEstateInfo::estateUpdate()" << llendl; + return false; +} + + +BOOL LLPanelEstateInfo::postBuild() +{ + // set up the callbacks for the generic controls + initCtrl("externally_visible_check"); + initCtrl("use_global_time_check"); + initCtrl("fixed_sun_check"); + initCtrl("allow_direct_teleport"); + initCtrl("limit_payment"); + initCtrl("limit_age_verified"); + initCtrl("voice_chat_check"); + childSetCommitCallback("abuse_email_address", onChangeAnything, this); + childSetKeystrokeCallback("abuse_email_address", onChangeText, this); + + initHelpBtn("estate_manager_help", "HelpEstateEstateManager"); + initHelpBtn("use_global_time_help", "HelpEstateUseGlobalTime"); + initHelpBtn("fixed_sun_help", "HelpEstateFixedSun"); + initHelpBtn("WLEditSkyHelp", "HelpEditSky"); + initHelpBtn("WLEditDayCycleHelp", "HelpEditDayCycle"); + + initHelpBtn("externally_visible_help", "HelpEstateExternallyVisible"); + initHelpBtn("allow_direct_teleport_help", "HelpEstateAllowDirectTeleport"); + initHelpBtn("allow_resident_help", "HelpEstateAllowResident"); + initHelpBtn("allow_group_help", "HelpEstateAllowGroup"); + initHelpBtn("ban_resident_help", "HelpEstateBanResident"); + initHelpBtn("abuse_email_address_help", "HelpEstateAbuseEmailAddress"); + initHelpBtn("voice_chat_help", "HelpEstateVoiceChat"); + + // set up the use global time checkbox + childSetCommitCallback("use_global_time_check", onChangeUseGlobalTime, this); + childSetCommitCallback("fixed_sun_check", onChangeFixedSun, this); + childSetCommitCallback("sun_hour_slider", onChangeChildCtrl, this); + + childSetCommitCallback("allowed_avatar_name_list", onChangeChildCtrl, this); + LLNameListCtrl *avatar_name_list = getChild("allowed_avatar_name_list"); + if (avatar_name_list) + { + avatar_name_list->setCommitOnSelectionChange(TRUE); + avatar_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); + } + + childSetAction("add_allowed_avatar_btn", onClickAddAllowedAgent, this); + childSetAction("remove_allowed_avatar_btn", onClickRemoveAllowedAgent, this); + + childSetCommitCallback("allowed_group_name_list", onChangeChildCtrl, this); + LLNameListCtrl* group_name_list = getChild("allowed_group_name_list"); + if (group_name_list) + { + group_name_list->setCommitOnSelectionChange(TRUE); + group_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); + } + + childSetAction("add_allowed_group_btn", onClickAddAllowedGroup, this); + childSetAction("remove_allowed_group_btn", onClickRemoveAllowedGroup, this); + + childSetCommitCallback("banned_avatar_name_list", onChangeChildCtrl, this); + LLNameListCtrl* banned_name_list = getChild("banned_avatar_name_list"); + if (banned_name_list) + { + banned_name_list->setCommitOnSelectionChange(TRUE); + banned_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS); + } + + childSetAction("add_banned_avatar_btn", onClickAddBannedAgent, this); + childSetAction("remove_banned_avatar_btn", onClickRemoveBannedAgent, this); + + childSetCommitCallback("estate_manager_name_list", onChangeChildCtrl, this); + LLNameListCtrl* manager_name_list = getChild("estate_manager_name_list"); + if (manager_name_list) + { + manager_name_list->setCommitOnSelectionChange(TRUE); + manager_name_list->setMaxItemCount(ESTATE_MAX_MANAGERS * 4); // Allow extras for dupe issue + } + + childSetAction("add_estate_manager_btn", onClickAddEstateManager, this); + childSetAction("remove_estate_manager_btn", onClickRemoveEstateManager, this); + childSetAction("message_estate_btn", onClickMessageEstate, this); + childSetAction("kick_user_from_estate_btn", onClickKickUser, this); + + childSetAction("WLEditSky", onClickEditSky, this); + childSetAction("WLEditDayCycle", onClickEditDayCycle, this); + + return LLPanelRegionInfo::postBuild(); +} + +void LLPanelEstateInfo::refresh() +{ + bool public_access = childGetValue("externally_visible_check").asBoolean(); + childSetEnabled("Only Allow", public_access); + childSetEnabled("limit_payment", public_access); + childSetEnabled("limit_age_verified", public_access); + // if this is set to false, then the limit fields are meaningless and should be turned off + if (public_access == false) + { + childSetValue("limit_payment", false); + childSetValue("limit_age_verified", false); + } +} + +BOOL LLPanelEstateInfo::sendUpdate() +{ + llinfos << "LLPanelEsateInfo::sendUpdate()" << llendl; + + LLNotification::Params params("ChangeLindenEstate"); + params.functor(boost::bind(&LLPanelEstateInfo::callbackChangeLindenEstate, this, _1, _2)); + + if (getEstateID() <= ESTATE_LAST_LINDEN) + { + // trying to change reserved estate, warn + LLNotifications::instance().add(params); + } + else + { + // for normal estates, just make the change + LLNotifications::instance().forceResponse(params, 0); + } + return TRUE; +} + +bool LLPanelEstateInfo::callbackChangeLindenEstate(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + switch(option) + { + case 0: + // send the update + if (!commitEstateInfoCaps()) + { + // the caps method failed, try the old way + LLFloaterRegionInfo::nextInvoice(); + commitEstateInfoDataserver(); + } + // we don't want to do this because we'll get it automatically from the sim + // after the spaceserver processes it +// else +// { +// // caps method does not automatically send this info +// LLFloaterRegionInfo::requestRegionInfo(); +// } + break; + case 1: + default: + // do nothing + break; + } + return false; +} + + +/* +// Request = "getowner" +// SParam[0] = "" (empty string) +// IParam[0] = serial +void LLPanelEstateInfo::getEstateOwner() +{ + // TODO -- disable the panel + // and call this function whenever we cross a region boundary + // re-enable when owner matches, and get new estate info + LLMessageSystem* msg = gMessageSystem; + msg->newMessageFast(_PREHASH_EstateOwnerRequest); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + + msg->nextBlockFast(_PREHASH_RequestData); + msg->addStringFast(_PREHASH_Request, "getowner"); + + // we send an empty string so that the variable block is not empty + msg->nextBlockFast(_PREHASH_StringData); + msg->addStringFast(_PREHASH_SParam, ""); + + msg->nextBlockFast(_PREHASH_IntegerData); + msg->addS32Fast(_PREHASH_IParam, LLFloaterRegionInfo::getSerial()); + + gAgent.sendMessage(); +} +*/ + +class LLEstateChangeInfoResponder : public LLHTTPClient::Responder +{ +public: + LLEstateChangeInfoResponder(void* userdata) : mpPanel((LLPanelEstateInfo*)userdata) {}; + + // if we get a normal response, handle it here + virtual void result(const LLSD& content) + { + // refresh the panel from the database + mpPanel->refresh(); + } + + // if we get an error response + virtual void error(U32 status, const std::string& reason) + { + llinfos << "LLEstateChangeInfoResponder::error " + << status << ": " << reason << llendl; + } +private: + LLPanelEstateInfo* mpPanel; +}; + +// tries to send estate info using a cap; returns true if it succeeded +bool LLPanelEstateInfo::commitEstateInfoCaps() +{ + std::string url = gAgent.getRegion()->getCapability("EstateChangeInfo"); + + if (url.empty()) + { + // whoops, couldn't find the cap, so bail out + return false; + } + + LLSD body; + body["estate_name"] = getEstateName(); + + body["is_externally_visible"] = childGetValue("externally_visible_check").asBoolean(); + body["allow_direct_teleport"] = childGetValue("allow_direct_teleport").asBoolean(); + body["is_sun_fixed" ] = childGetValue("fixed_sun_check").asBoolean(); + body["deny_anonymous" ] = childGetValue("limit_payment").asBoolean(); + body["deny_age_unverified" ] = childGetValue("limit_age_verified").asBoolean(); + body["allow_voice_chat" ] = childGetValue("voice_chat_check").asBoolean(); + body["invoice" ] = LLFloaterRegionInfo::getLastInvoice(); + + // block fly is in estate database but not in estate UI, so we're not supporting it + //body["block_fly" ] = childGetValue("").asBoolean(); + + F32 sun_hour = getSunHour(); + if (childGetValue("use_global_time_check").asBoolean()) + { + sun_hour = 0.f; // 0 = global time + } + body["sun_hour"] = sun_hour; + + body["owner_abuse_email"] = childGetValue("abuse_email_address").asString(); + + // we use a responder so that we can re-get the data after committing to the database + LLHTTPClient::post(url, body, new LLEstateChangeInfoResponder((void*)this)); + return true; +} + +/* This is the old way of doing things, is deprecated, and should be + deleted when the dataserver model can be removed */ +// key = "estatechangeinfo" +// strings[0] = str(estate_id) (added by simulator before relay - not here) +// strings[1] = estate_name +// strings[2] = str(estate_flags) +// strings[3] = str((S32)(sun_hour * 1024.f)) +void LLPanelEstateInfo::commitEstateInfoDataserver() +{ + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("EstateOwnerMessage"); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); + msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used + + msg->nextBlock("MethodData"); + msg->addString("Method", "estatechangeinfo"); + msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); + + msg->nextBlock("ParamList"); + msg->addString("Parameter", getEstateName()); + + std::string buffer; + buffer = llformat("%u", computeEstateFlags()); + msg->nextBlock("ParamList"); + msg->addString("Parameter", buffer); + + F32 sun_hour = getSunHour(); + if (childGetValue("use_global_time_check").asBoolean()) + { + sun_hour = 0.f; // 0 = global time + } + + buffer = llformat("%d", (S32)(sun_hour*1024.0f)); + msg->nextBlock("ParamList"); + msg->addString("Parameter", buffer); + + gAgent.sendMessage(); +} + +void LLPanelEstateInfo::setEstateFlags(U32 flags) +{ + childSetValue("externally_visible_check", LLSD(flags & REGION_FLAGS_EXTERNALLY_VISIBLE ? TRUE : FALSE) ); + childSetValue("fixed_sun_check", LLSD(flags & REGION_FLAGS_SUN_FIXED ? TRUE : FALSE) ); + childSetValue( + "voice_chat_check", + LLSD(flags & REGION_FLAGS_ALLOW_VOICE ? TRUE : FALSE)); + childSetValue("allow_direct_teleport", LLSD(flags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT ? TRUE : FALSE) ); + childSetValue("limit_payment", LLSD(flags & REGION_FLAGS_DENY_ANONYMOUS ? TRUE : FALSE) ); + childSetValue("limit_age_verified", LLSD(flags & REGION_FLAGS_DENY_AGEUNVERIFIED ? TRUE : FALSE) ); + + refresh(); +} + +U32 LLPanelEstateInfo::computeEstateFlags() +{ + U32 flags = 0; + + if (childGetValue("externally_visible_check").asBoolean()) + { + flags |= REGION_FLAGS_EXTERNALLY_VISIBLE; + } + + if ( childGetValue("voice_chat_check").asBoolean() ) + { + flags |= REGION_FLAGS_ALLOW_VOICE; + } + + if (childGetValue("allow_direct_teleport").asBoolean()) + { + flags |= REGION_FLAGS_ALLOW_DIRECT_TELEPORT; + } + + if (childGetValue("fixed_sun_check").asBoolean()) + { + flags |= REGION_FLAGS_SUN_FIXED; + } + + if (childGetValue("limit_payment").asBoolean()) + { + flags |= REGION_FLAGS_DENY_ANONYMOUS; + } + + if (childGetValue("limit_age_verified").asBoolean()) + { + flags |= REGION_FLAGS_DENY_AGEUNVERIFIED; + } + + + return flags; +} + +BOOL LLPanelEstateInfo::getGlobalTime() +{ + return childGetValue("use_global_time_check").asBoolean(); +} + +void LLPanelEstateInfo::setGlobalTime(bool b) +{ + childSetValue("use_global_time_check", LLSD(b)); + childSetEnabled("fixed_sun_check", LLSD(!b)); + childSetEnabled("sun_hour_slider", LLSD(!b)); + if (b) + { + childSetValue("sun_hour_slider", LLSD(0.f)); + } +} + + +BOOL LLPanelEstateInfo::getFixedSun() +{ + return childGetValue("fixed_sun_check").asBoolean(); +} + +void LLPanelEstateInfo::setSunHour(F32 sun_hour) +{ + if(sun_hour < 6.0f) + { + sun_hour = 24.0f + sun_hour; + } + childSetValue("sun_hour_slider", LLSD(sun_hour)); +} + +F32 LLPanelEstateInfo::getSunHour() +{ + if (childIsEnabled("sun_hour_slider")) + { + return (F32)childGetValue("sun_hour_slider").asReal(); + } + return 0.f; +} + +const std::string LLPanelEstateInfo::getEstateName() const +{ + return childGetValue("estate_name").asString(); +} + +void LLPanelEstateInfo::setEstateName(const std::string& name) +{ + childSetValue("estate_name", LLSD(name)); +} + +const std::string LLPanelEstateInfo::getOwnerName() const +{ + return childGetValue("estate_owner").asString(); +} + +void LLPanelEstateInfo::setOwnerName(const std::string& name) +{ + childSetValue("estate_owner", LLSD(name)); +} + +const std::string LLPanelEstateInfo::getAbuseEmailAddress() const +{ + return childGetValue("abuse_email_address").asString(); +} + +void LLPanelEstateInfo::setAbuseEmailAddress(const std::string& address) +{ + childSetValue("abuse_email_address", LLSD(address)); +} + +void LLPanelEstateInfo::setAccessAllowedEnabled(bool enable_agent, + bool enable_group, + bool enable_ban) +{ + childSetEnabled("allow_resident_label", enable_agent); + childSetEnabled("allowed_avatar_name_list", enable_agent); + childSetVisible("allowed_avatar_name_list", enable_agent); + childSetEnabled("add_allowed_avatar_btn", enable_agent); + childSetEnabled("remove_allowed_avatar_btn", enable_agent); + + // Groups + childSetEnabled("allow_group_label", enable_group); + childSetEnabled("allowed_group_name_list", enable_group); + childSetVisible("allowed_group_name_list", enable_group); + childSetEnabled("add_allowed_group_btn", enable_group); + childSetEnabled("remove_allowed_group_btn", enable_group); + + // Ban + childSetEnabled("ban_resident_label", enable_ban); + childSetEnabled("banned_avatar_name_list", enable_ban); + childSetVisible("banned_avatar_name_list", enable_ban); + childSetEnabled("add_banned_avatar_btn", enable_ban); + childSetEnabled("remove_banned_avatar_btn", enable_ban); + + // Update removal buttons if needed + if (enable_agent) + { + checkRemovalButton("allowed_avatar_name_list"); + } + + if (enable_group) + { + checkRemovalButton("allowed_group_name_list"); + } + + if (enable_ban) + { + checkRemovalButton("banned_avatar_name_list"); + } +} + +// static +void LLPanelEstateInfo::callbackCacheName( + const LLUUID& id, + const std::string& first, + const std::string& last, + BOOL is_group, + void*) +{ + LLPanelEstateInfo* self = LLFloaterRegionInfo::getPanelEstate(); + if (!self) return; + + std::string name; + + if (id.isNull()) + { + name = "(none)"; + } + else + { + name = first + " " + last; + } + + self->setOwnerName(name); +} + +void LLPanelEstateInfo::clearAccessLists() +{ + LLNameListCtrl* name_list = getChild("allowed_avatar_name_list"); + if (name_list) + { + name_list->deleteAllItems(); + } + + name_list = getChild("banned_avatar_name_list"); + if (name_list) + { + name_list->deleteAllItems(); + } +} + +// enables/disables the "remove" button for the various allow/ban lists +BOOL LLPanelEstateInfo::checkRemovalButton(std::string name) +{ + std::string btn_name = ""; + if (name == "allowed_avatar_name_list") + { + btn_name = "remove_allowed_avatar_btn"; + } + else if (name == "allowed_group_name_list") + { + btn_name = "remove_allowed_group_btn"; + } + else if (name == "banned_avatar_name_list") + { + btn_name = "remove_banned_avatar_btn"; + } + else if (name == "estate_manager_name_list") + { + //ONLY OWNER CAN ADD /DELET ESTATE MANAGER + LLViewerRegion* region = gAgent.getRegion(); + if (region && (region->getOwner() == gAgent.getID())) + { + btn_name = "remove_estate_manager_btn"; + } + } + + // enable the remove button if something is selected + LLNameListCtrl* name_list = getChild(name); + childSetEnabled(btn_name, name_list && name_list->getFirstSelected() ? TRUE : FALSE); + + return (btn_name != ""); +} + +BOOL LLPanelEstateInfo::checkSunHourSlider(LLUICtrl* child_ctrl) +{ + BOOL found_child_ctrl = FALSE; + if (child_ctrl->getName() == "sun_hour_slider") + { + enableButton("apply_btn"); + found_child_ctrl = TRUE; + } + return found_child_ctrl; +} + +// static +void LLPanelEstateInfo::onClickMessageEstate(void* userdata) +{ + llinfos << "LLPanelEstateInfo::onClickMessageEstate" << llendl; + LLNotifications::instance().add("MessageEstate", LLSD(), LLSD(), boost::bind(&LLPanelEstateInfo::onMessageCommit, (LLPanelEstateInfo*)userdata, _1, _2)); +} + +bool LLPanelEstateInfo::onMessageCommit(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + std::string text = response["message"].asString(); + if(option != 0) return false; + if(text.empty()) return false; + llinfos << "Message to everyone: " << text << llendl; + strings_t strings; + //integers_t integers; + std::string name; + gAgent.buildFullname(name); + strings.push_back(strings_t::value_type(name)); + strings.push_back(strings_t::value_type(text)); + LLUUID invoice(LLFloaterRegionInfo::getLastInvoice()); + sendEstateOwnerMessage(gMessageSystem, "instantmessage", invoice, strings); + return false; +} + +LLPanelEstateCovenant::LLPanelEstateCovenant() +: mCovenantID(LLUUID::null) +{ +} + +// virtual +bool LLPanelEstateCovenant::refreshFromRegion(LLViewerRegion* region) +{ + LLTextBox* region_name = getChild("region_name_text"); + if (region_name) + { + region_name->setText(region->getName()); + } + + LLTextBox* resellable_clause = getChild("resellable_clause"); + if (resellable_clause) + { + if (region->getRegionFlags() & REGION_FLAGS_BLOCK_LAND_RESELL) + { + resellable_clause->setText(getString("can_not_resell")); + } + else + { + resellable_clause->setText(getString("can_resell")); + } + } + + LLTextBox* changeable_clause = getChild("changeable_clause"); + if (changeable_clause) + { + if (region->getRegionFlags() & REGION_FLAGS_ALLOW_PARCEL_CHANGES) + { + changeable_clause->setText(getString("can_change")); + } + else + { + changeable_clause->setText(getString("can_not_change")); + } + } + + LLTextBox* region_maturity = getChild("region_maturity_text"); + if (region_maturity) + { + region_maturity->setText(region->getSimAccessString()); + } + + LLTextBox* region_landtype = getChild("region_landtype_text"); + if (region_landtype) + { + region_landtype->setText(region->getSimProductName()); + } + + + // let the parent class handle the general data collection. + bool rv = LLPanelRegionInfo::refreshFromRegion(region); + LLMessageSystem *msg = gMessageSystem; + msg->newMessage("EstateCovenantRequest"); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID()); + msg->sendReliable(region->getHost()); + return rv; +} + +// virtual +bool LLPanelEstateCovenant::estateUpdate(LLMessageSystem* msg) +{ + llinfos << "LLPanelEstateCovenant::estateUpdate()" << llendl; + return true; +} + +// virtual +BOOL LLPanelEstateCovenant::postBuild() +{ + initHelpBtn("covenant_help", "HelpEstateCovenant"); + mEstateNameText = getChild("estate_name_text"); + mEstateOwnerText = getChild("estate_owner_text"); + mLastModifiedText = getChild("covenant_timestamp_text"); + mEditor = getChild("covenant_editor"); + if (mEditor) mEditor->setHandleEditKeysDirectly(TRUE); + LLButton* reset_button = getChild("reset_covenant"); + reset_button->setEnabled(gAgent.canManageEstate()); + reset_button->setClickedCallback(LLPanelEstateCovenant::resetCovenantID, NULL); + + return LLPanelRegionInfo::postBuild(); +} + +// virtual +void LLPanelEstateCovenant::updateChild(LLUICtrl* child_ctrl) +{ +} + +// virtual +BOOL LLPanelEstateCovenant::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, + EDragAndDropType cargo_type, + void* cargo_data, + EAcceptance* accept, + std::string& tooltip_msg) +{ + LLInventoryItem* item = (LLInventoryItem*)cargo_data; + + if (!gAgent.canManageEstate()) + { + *accept = ACCEPT_NO; + return TRUE; + } + + switch(cargo_type) + { + case DAD_NOTECARD: + *accept = ACCEPT_YES_COPY_SINGLE; + if (item && drop) + { + LLSD payload; + payload["item_id"] = item->getUUID(); + LLNotifications::instance().add("EstateChangeCovenant", LLSD(), payload, + LLPanelEstateCovenant::confirmChangeCovenantCallback); + } + break; + default: + *accept = ACCEPT_NO; + break; + } + + return TRUE; +} + +// static +bool LLPanelEstateCovenant::confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotification::getSelectedOption(notification, response); + LLInventoryItem* item = gInventory.getItem(notification["payload"]["item_id"].asUUID()); + LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant(); + + if (!item || !self) return false; + + switch(option) + { + case 0: + self->loadInvItem(item); + break; + default: + break; + } + return false; +} + +// static +void LLPanelEstateCovenant::resetCovenantID(void* userdata) +{ + LLNotifications::instance().add("EstateChangeCovenant", LLSD(), LLSD(), confirmResetCovenantCallback); +} + +// static +bool LLPanelEstateCovenant::confirmResetCovenantCallback(const LLSD& notification, const LLSD& response) +{ + LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant(); + if (!self) return false; + + S32 option = LLNotification::getSelectedOption(notification, response); + switch(option) + { + case 0: + self->loadInvItem(NULL); + break; + default: + break; + } + return false; +} + +void LLPanelEstateCovenant::loadInvItem(LLInventoryItem *itemp) +{ + const BOOL high_priority = TRUE; + if (itemp) + { + gAssetStorage->getInvItemAsset(gAgent.getRegionHost(), + gAgent.getID(), + gAgent.getSessionID(), + itemp->getPermissions().getOwner(), + LLUUID::null, + itemp->getUUID(), + itemp->getAssetUUID(), + itemp->getType(), + onLoadComplete, + (void*)this, + high_priority); + mAssetStatus = ASSET_LOADING; + } + else + { + mAssetStatus = ASSET_LOADED; + setCovenantTextEditor("There is no Covenant provided for this Estate."); + sendChangeCovenantID(LLUUID::null); + } +} + +// static +void LLPanelEstateCovenant::onLoadComplete(LLVFS *vfs, + const LLUUID& asset_uuid, + LLAssetType::EType type, + void* user_data, S32 status, LLExtStat ext_status) +{ + llinfos << "LLPanelEstateCovenant::onLoadComplete()" << llendl; + LLPanelEstateCovenant* panelp = (LLPanelEstateCovenant*)user_data; + if( panelp ) + { + if(0 == status) + { + LLVFile file(vfs, asset_uuid, type, LLVFile::READ); + + S32 file_length = file.getSize(); + + char* buffer = new char[file_length+1]; + if (buffer == NULL) + { + llerrs << "Memory Allocation Failed" << llendl; + return; + } + + file.read((U8*)buffer, file_length); /* Flawfinder: ignore */ + // put a EOS at the end + buffer[file_length] = 0; + + if( (file_length > 19) && !strncmp( buffer, "Linden text version", 19 ) ) + { + if( !panelp->mEditor->importBuffer( buffer, file_length+1 ) ) + { + llwarns << "Problem importing estate covenant." << llendl; + LLNotifications::instance().add("ProblemImportingEstateCovenant"); + } + else + { + panelp->sendChangeCovenantID(asset_uuid); + } + } + else + { + // Version 0 (just text, doesn't include version number) + panelp->sendChangeCovenantID(asset_uuid); + } + delete[] buffer; + } + else + { + LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED ); + + if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status || + LL_ERR_FILE_EMPTY == status) + { + LLNotifications::instance().add("MissingNotecardAssetID"); + } + else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status) + { + LLNotifications::instance().add("NotAllowedToViewNotecard"); + } + else + { + LLNotifications::instance().add("UnableToLoadNotecardAsset"); + } + + llwarns << "Problem loading notecard: " << status << llendl; + } + panelp->mAssetStatus = ASSET_LOADED; + panelp->setCovenantID(asset_uuid); + } +} + +// key = "estatechangecovenantid" +// strings[0] = str(estate_id) (added by simulator before relay - not here) +// strings[1] = str(covenant_id) +void LLPanelEstateCovenant::sendChangeCovenantID(const LLUUID &asset_id) +{ + if (asset_id != getCovenantID()) + { + setCovenantID(asset_id); + + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("EstateOwnerMessage"); + msg->nextBlockFast(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); + msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used + + msg->nextBlock("MethodData"); + msg->addString("Method", "estatechangecovenantid"); + msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice()); + + msg->nextBlock("ParamList"); + msg->addString("Parameter", getCovenantID().asString()); + gAgent.sendReliableMessage(); + } +} + +// virtual +BOOL LLPanelEstateCovenant::sendUpdate() +{ + return TRUE; +} + +const std::string& LLPanelEstateCovenant::getEstateName() const +{ + return mEstateNameText->getText(); +} + +void LLPanelEstateCovenant::setEstateName(const std::string& name) +{ + mEstateNameText->setText(name); +} + +// static +void LLPanelEstateCovenant::updateCovenantText(const std::string& string, const LLUUID& asset_id) +{ + LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); + if( panelp ) + { + panelp->mEditor->setText(string); + panelp->setCovenantID(asset_id); + } +} + +// static +void LLPanelEstateCovenant::updateEstateName(const std::string& name) +{ + LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); + if( panelp ) + { + panelp->mEstateNameText->setText(name); + } +} + +// static +void LLPanelEstateCovenant::updateLastModified(const std::string& text) +{ + LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); + if( panelp ) + { + panelp->mLastModifiedText->setText(text); + } +} + +// static +void LLPanelEstateCovenant::updateEstateOwnerName(const std::string& name) +{ + LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant(); + if( panelp ) + { + panelp->mEstateOwnerText->setText(name); + } +} + +const std::string& LLPanelEstateCovenant::getOwnerName() const +{ + return mEstateOwnerText->getText(); +} + +void LLPanelEstateCovenant::setOwnerName(const std::string& name) +{ + mEstateOwnerText->setText(name); +} + +void LLPanelEstateCovenant::setCovenantTextEditor(const std::string& text) +{ + mEditor->setText(text); +} + +// key = "estateupdateinfo" +// strings[0] = estate name +// strings[1] = str(owner_id) +// strings[2] = str(estate_id) +// strings[3] = str(estate_flags) +// strings[4] = str((S32)(sun_hour * 1024)) +// strings[5] = str(parent_estate_id) +// strings[6] = str(covenant_id) +// strings[7] = str(covenant_timestamp) +// strings[8] = str(send_to_agent_only) +// strings[9] = str(abuse_email_addr) +bool LLDispatchEstateUpdateInfo::operator()( + const LLDispatcher* dispatcher, + const std::string& key, + const LLUUID& invoice, + const sparam_t& strings) +{ + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return true; + + // NOTE: LLDispatcher extracts strings with an extra \0 at the + // end. If we pass the std::string direct to the UI/renderer + // it draws with a weird character at the end of the string. + std::string estate_name = strings[0].c_str(); // preserve c_str() call! + panel->setEstateName(estate_name); + + if (strings.size() > 3) + { + std::string abuse_email = strings[9].c_str(); // preserve c_str() call! + panel->setAbuseEmailAddress(abuse_email); + } + else + { + panel->setAbuseEmailAddress(panel->getString("email_unsupported")); + } + + LLViewerRegion* regionp = gAgent.getRegion(); + + LLUUID owner_id(strings[1]); + regionp->setOwner(owner_id); + // Update estate owner name in UI + const BOOL is_group = FALSE; + gCacheName->get(owner_id, is_group, LLPanelEstateInfo::callbackCacheName); + + U32 estate_id = strtoul(strings[2].c_str(), NULL, 10); + panel->setEstateID(estate_id); + + U32 flags = strtoul(strings[3].c_str(), NULL, 10); + panel->setEstateFlags(flags); + + F32 sun_hour = ((F32)(strtod(strings[4].c_str(), NULL)))/1024.0f; + if(sun_hour == 0 && (flags & REGION_FLAGS_SUN_FIXED ? FALSE : TRUE)) + { + panel->setGlobalTime(TRUE); + } + else + { + panel->setGlobalTime(FALSE); + panel->setSunHour(sun_hour); + } + + bool visible_from_mainland = (bool)(flags & REGION_FLAGS_EXTERNALLY_VISIBLE); + bool god = gAgent.isGodlike(); + bool linden_estate = (estate_id <= ESTATE_LAST_LINDEN); + + // If visible from mainland, disable the access allowed + // UI, as anyone can teleport there. + // However, gods need to be able to edit the access list for + // linden estates, regardless of visibility, to allow object + // and L$ transfers. + bool enable_agent = (!visible_from_mainland || (god && linden_estate)); + bool enable_group = enable_agent; + bool enable_ban = !linden_estate; + panel->setAccessAllowedEnabled(enable_agent, enable_group, enable_ban); + + return true; +} + + +// key = "setaccess" +// strings[0] = str(estate_id) +// strings[1] = str(packed_access_lists) +// strings[2] = str(num allowed agent ids) +// strings[3] = str(num allowed group ids) +// strings[4] = str(num banned agent ids) +// strings[5] = str(num estate manager agent ids) +// strings[6] = bin(uuid) +// strings[7] = bin(uuid) +// strings[8] = bin(uuid) +// ... +bool LLDispatchSetEstateAccess::operator()( + const LLDispatcher* dispatcher, + const std::string& key, + const LLUUID& invoice, + const sparam_t& strings) +{ + LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate(); + if (!panel) return true; + + S32 index = 1; // skip estate_id + U32 access_flags = strtoul(strings[index++].c_str(), NULL,10); + S32 num_allowed_agents = strtol(strings[index++].c_str(), NULL, 10); + S32 num_allowed_groups = strtol(strings[index++].c_str(), NULL, 10); + S32 num_banned_agents = strtol(strings[index++].c_str(), NULL, 10); + S32 num_estate_managers = strtol(strings[index++].c_str(), NULL, 10); + + // sanity ckecks + if (num_allowed_agents > 0 + && !(access_flags & ESTATE_ACCESS_ALLOWED_AGENTS)) + { + llwarns << "non-zero count for allowed agents, but no corresponding flag" << llendl; + } + if (num_allowed_groups > 0 + && !(access_flags & ESTATE_ACCESS_ALLOWED_GROUPS)) + { + llwarns << "non-zero count for allowed groups, but no corresponding flag" << llendl; + } + if (num_banned_agents > 0 + && !(access_flags & ESTATE_ACCESS_BANNED_AGENTS)) + { + llwarns << "non-zero count for banned agents, but no corresponding flag" << llendl; + } + if (num_estate_managers > 0 + && !(access_flags & ESTATE_ACCESS_MANAGERS)) + { + llwarns << "non-zero count for managers, but no corresponding flag" << llendl; + } + + // grab the UUID's out of the string fields + if (access_flags & ESTATE_ACCESS_ALLOWED_AGENTS) + { + LLNameListCtrl* allowed_agent_name_list; + allowed_agent_name_list = panel->getChild("allowed_avatar_name_list"); + + int totalAllowedAgents = num_allowed_agents; + + if (allowed_agent_name_list) + { + totalAllowedAgents += allowed_agent_name_list->getItemCount(); + } + + std::string msg = llformat("Allowed residents: (%d, max %d)", + totalAllowedAgents, + ESTATE_MAX_ACCESS_IDS); + panel->childSetValue("allow_resident_label", LLSD(msg)); + + if (allowed_agent_name_list) + { + //allowed_agent_name_list->deleteAllItems(); + for (S32 i = 0; i < num_allowed_agents && i < ESTATE_MAX_ACCESS_IDS; i++) + { + LLUUID id; + memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ + allowed_agent_name_list->addNameItem(id); + } + panel->childSetEnabled("remove_allowed_avatar_btn", allowed_agent_name_list->getFirstSelected() ? TRUE : FALSE); + allowed_agent_name_list->sortByColumnIndex(0, TRUE); + } + } + + if (access_flags & ESTATE_ACCESS_ALLOWED_GROUPS) + { + LLNameListCtrl* allowed_group_name_list; + allowed_group_name_list = panel->getChild("allowed_group_name_list"); + + std::string msg = llformat("Allowed groups: (%d, max %d)", + num_allowed_groups, + (S32) ESTATE_MAX_GROUP_IDS); + panel->childSetValue("allow_group_label", LLSD(msg)); + + if (allowed_group_name_list) + { + allowed_group_name_list->deleteAllItems(); + for (S32 i = 0; i < num_allowed_groups && i < ESTATE_MAX_GROUP_IDS; i++) + { + LLUUID id; + memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ + allowed_group_name_list->addGroupNameItem(id); + } + panel->childSetEnabled("remove_allowed_group_btn", allowed_group_name_list->getFirstSelected() ? TRUE : FALSE); + allowed_group_name_list->sortByColumnIndex(0, TRUE); + } + } + + if (access_flags & ESTATE_ACCESS_BANNED_AGENTS) + { + LLNameListCtrl* banned_agent_name_list; + banned_agent_name_list = panel->getChild("banned_avatar_name_list"); + + int totalBannedAgents = num_banned_agents; + + if (banned_agent_name_list) + { + totalBannedAgents += banned_agent_name_list->getItemCount(); + } + + + std::string msg = llformat("Banned residents: (%d, max %d)", + totalBannedAgents, + ESTATE_MAX_ACCESS_IDS); + panel->childSetValue("ban_resident_label", LLSD(msg)); + + if (banned_agent_name_list) + { + //banned_agent_name_list->deleteAllItems(); + for (S32 i = 0; i < num_banned_agents && i < ESTATE_MAX_ACCESS_IDS; i++) + { + LLUUID id; + memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ + banned_agent_name_list->addNameItem(id); + } + panel->childSetEnabled("remove_banned_avatar_btn", banned_agent_name_list->getFirstSelected() ? TRUE : FALSE); + banned_agent_name_list->sortByColumnIndex(0, TRUE); + } + } + + if (access_flags & ESTATE_ACCESS_MANAGERS) + { + std::string msg = llformat("Estate Managers: (%d, max %d)", + num_estate_managers, + ESTATE_MAX_MANAGERS); + panel->childSetValue("estate_manager_label", LLSD(msg)); + + LLNameListCtrl* estate_manager_name_list = + panel->getChild("estate_manager_name_list"); + if (estate_manager_name_list) + { + estate_manager_name_list->deleteAllItems(); // Clear existing entries + + // There should be only ESTATE_MAX_MANAGERS people in the list, but if the database gets more (SL-46107) don't + // truncate the list unless it's really big. Go ahead and show the extras so the user doesn't get confused, + // and they can still remove them. + for (S32 i = 0; i < num_estate_managers && i < (ESTATE_MAX_MANAGERS * 4); i++) + { + LLUUID id; + memcpy(id.mData, strings[index++].data(), UUID_BYTES); /* Flawfinder: ignore */ + estate_manager_name_list->addNameItem(id); + } + panel->childSetEnabled("remove_estate_manager_btn", estate_manager_name_list->getFirstSelected() ? TRUE : FALSE); + estate_manager_name_list->sortByColumnIndex(0, TRUE); + } + } + + return true; +} + +// [RLVa:KB] - Checked: 2009-07-04 (RLVa-1.0.0a) +void LLFloaterRegionInfo::open() +{ + // We'll allow access to the estate tools for estate managers (and for the sim owner) + if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) + { + LLViewerRegion* pRegion = gAgent.getRegion(); + if (!pRegion) + return; + + // Should be able to call LLRegion::canManageEstate() but then we can fake god like + if ( (!pRegion->isEstateManager()) && (pRegion->getOwner() != gAgent.getID()) ) + return; + } + + LLFloater::open(); +} +// [/RLVa:KB] diff --git a/linden/indra/newview/llfloatertos.cpp b/linden/indra/newview/llfloatertos.cpp index ac4a06b..efc8bd6 100644 --- a/linden/indra/newview/llfloatertos.cpp +++ b/linden/indra/newview/llfloatertos.cpp @@ -1,305 +1,305 @@ -/** - * @file llfloatertos.cpp - * @brief Terms of Service Agreement dialog - * - * $LicenseInfo:firstyear=2003&license=viewergpl$ - * - * Copyright (c) 2003-2009, Linden Research, Inc. - * - * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception - * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. - * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. - * $/LicenseInfo$ - */ - -#include "llviewerprecompiledheaders.h" - -#include "llfloatertos.h" - -// viewer includes -#include "llagent.h" -#include "llappviewer.h" -#include "llstartup.h" -#include "llviewerstats.h" -#include "llviewertexteditor.h" -#include "llviewerwindow.h" - -// linden library includes -#include "llbutton.h" -#include "llhttpclient.h" -#include "llhttpstatuscodes.h" // for HTTP_FOUND -#include "llradiogroup.h" -#include "lltextbox.h" -#include "llui.h" -#include "lluictrlfactory.h" -#include "llvfile.h" -#include "message.h" -#include "hippogridmanager.h" - - -// static -LLFloaterTOS* LLFloaterTOS::sInstance = NULL; - -// static -LLFloaterTOS* LLFloaterTOS::show(ETOSType type, const std::string & message) -{ - if( !LLFloaterTOS::sInstance ) - { - LLFloaterTOS::sInstance = new LLFloaterTOS(type, message); - } - - if (type == TOS_TOS) - { - LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_tos.xml"); - } - else - { - LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_critical.xml"); - } - - return LLFloaterTOS::sInstance; -} - - -LLFloaterTOS::LLFloaterTOS(ETOSType type, const std::string & message) -: LLModalDialog( std::string(" "), 100, 100 ), - mType(type), - mMessage(message), - mWebBrowserWindowId( 0 ), - mLoadCompleteCount( 0 ) -{ -} - -// helper class that trys to download a URL from a web site and calls a method -// on parent class indicating if the web server is working or not -class LLIamHereTOS : public LLHTTPClient::Responder -{ - private: - LLIamHereTOS( LLFloaterTOS* parent ) : - mParent( parent ) - {} - - LLFloaterTOS* mParent; - - public: - - static boost::intrusive_ptr< LLIamHereTOS > build( LLFloaterTOS* parent ) - { - return boost::intrusive_ptr< LLIamHereTOS >( new LLIamHereTOS( parent ) ); - }; - - virtual void setParent( LLFloaterTOS* parentIn ) - { - mParent = parentIn; - }; - - virtual void result( const LLSD& content ) - { - if ( mParent ) - mParent->setSiteIsAlive( true ); - }; - - virtual void error( U32 status, const std::string& reason ) - { - if ( mParent ) - { - // *HACK: For purposes of this alive check, 302 Found - // (aka Moved Temporarily) is considered alive. The web site - // redirects this link to a "cache busting" temporary URL. JC - bool alive = (status == HTTP_FOUND); - mParent->setSiteIsAlive( alive ); - } - }; -}; - -// this is global and not a class member to keep crud out of the header file -namespace { - boost::intrusive_ptr< LLIamHereTOS > gResponsePtr = 0; -}; - -BOOL LLFloaterTOS::postBuild() -{ - childSetAction("Continue", onContinue, this); - childSetAction("Cancel", onCancel, this); - childSetCommitCallback("agree_chk", updateAgree, this); - - LLCheckBoxCtrl* tos_agreement = getChild("agree_chk"); - tos_agreement->setEnabled( true ); - - //Always set this so that the TOS is displayed whether the web browser pops up or not. - LLTextEditor *editor = getChild("tos_text"); - editor->setHandleEditKeysDirectly( TRUE ); - editor->setEnabled( FALSE ); - editor->setWordWrap(TRUE); - editor->setFocus(TRUE); - editor->setValue(LLSD(mMessage)); - LLMediaCtrl* web_browser = getChild("tos_html"); - if (web_browser) - { - //Disable for critical messages and text messages, it is reenabled later - web_browser->setVisible( FALSE ); - } - - if ( mType != TOS_TOS ) - { - // this displays the critical message only - return TRUE; - } - bool use_web_browser = false; - - //Check to see if the message is a link to display - std::string token = "http://"; - std::string::size_type iIndex = mMessage.rfind(token); - //IF it has http:// in it, we use the web browser - if(iIndex != std::string::npos && mMessage.length() >= 2) - { - // it exists - use_web_browser = true; - } - else if (gHippoGridManager->getConnectedGrid()->isSecondLife()) - { - //Its SL, use the browser for it as thats what it should do - use_web_browser = true; - } - - if ( web_browser && use_web_browser) - { - // hide the SL text widget if we're displaying TOS with using a browser widget. - LLTextEditor *editor = getChild("tos_text"); - editor->setVisible( FALSE ); - - // disable Agree to TOS radio button until the page has fully loaded - tos_agreement->setEnabled( false ); - - // Reenable the web browser - web_browser->setVisible( TRUE ); - - web_browser->addObserver(this); - gResponsePtr = LLIamHereTOS::build( this ); - LLHTTPClient::head( getString( "real_url" ), gResponsePtr ); - } - - return TRUE; -} - -void LLFloaterTOS::setSiteIsAlive( bool alive ) -{ - // only do this for TOS pages - if ( mType == TOS_TOS ) - { - LLMediaCtrl* web_browser = getChild("tos_html"); - // if the contents of the site was retrieved - if ( alive ) - { - if ( web_browser ) - { - // navigate to the "real" page - web_browser->navigateTo( getString( "real_url" ) ); - }; - } - else - { - // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads) - // but if the page is unavailable, we need to do this now - LLCheckBoxCtrl* tos_agreement = getChild("agree_chk"); - tos_agreement->setEnabled( true ); - }; - }; -} - -LLFloaterTOS::~LLFloaterTOS() -{ - - // tell the responder we're not here anymore - if ( gResponsePtr ) - gResponsePtr->setParent( 0 ); - - LLFloaterTOS::sInstance = NULL; -} - -// virtual -void LLFloaterTOS::draw() -{ - // draw children - LLModalDialog::draw(); -} - -// static -void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata ) -{ - LLFloaterTOS* self = (LLFloaterTOS*) userdata; - bool agree = self->childGetValue("agree_chk").asBoolean(); - self->childSetEnabled("Continue", agree); -} - -// static -void LLFloaterTOS::onContinue( void* userdata ) -{ - LLFloaterTOS* self = (LLFloaterTOS*) userdata; - llinfos << "User agrees with TOS." << llendl; - if (self->mType == TOS_TOS) - { - gAcceptTOS = TRUE; - } - else - { - gAcceptCriticalMessage = TRUE; - } - - // Testing TOS dialog - #if ! LL_RELEASE_FOR_DOWNLOAD - if ( LLStartUp::getStartupState() == STATE_LOGIN_WAIT ) - { - LLStartUp::setStartupState( STATE_LOGIN_SHOW ); - } - else - #endif - - LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT ); // Go back and finish authentication - self->close(); // destroys this object -} - -// static -void LLFloaterTOS::onCancel( void* userdata ) -{ - LLFloaterTOS* self = (LLFloaterTOS*) userdata; - llinfos << "User disagrees with TOS." << llendl; - LLNotifications::instance().add("MustAgreeToLogIn", LLSD(), LLSD(), login_alert_done); - LLStartUp::setStartupState( STATE_LOGIN_SHOW ); - self->mLoadCompleteCount = 0; // reset counter for next time we come to TOS - self->close(); // destroys this object -} - -//virtual -void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent event) -{ - if(event == MEDIA_EVENT_NAVIGATE_COMPLETE) - { - // skip past the loading screen navigate complete - if ( ++mLoadCompleteCount == 2 ) - { - llinfos << "NAVIGATE COMPLETE" << llendl; - // enable Agree to TOS radio button now that page has loaded - LLCheckBoxCtrl * tos_agreement = getChild("agree_chk"); - tos_agreement->setEnabled( true ); - } - } -} +/** + * @file llfloatertos.cpp + * @brief Terms of Service Agreement dialog + * + * $LicenseInfo:firstyear=2003&license=viewergpl$ + * + * Copyright (c) 2003-2009, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llfloatertos.h" + +// viewer includes +#include "llagent.h" +#include "llappviewer.h" +#include "llstartup.h" +#include "llviewerstats.h" +#include "llviewertexteditor.h" +#include "llviewerwindow.h" + +// linden library includes +#include "llbutton.h" +#include "llhttpclient.h" +#include "llhttpstatuscodes.h" // for HTTP_FOUND +#include "llradiogroup.h" +#include "lltextbox.h" +#include "llui.h" +#include "lluictrlfactory.h" +#include "llvfile.h" +#include "message.h" +#include "hippogridmanager.h" + + +// static +LLFloaterTOS* LLFloaterTOS::sInstance = NULL; + +// static +LLFloaterTOS* LLFloaterTOS::show(ETOSType type, const std::string & message) +{ + if( !LLFloaterTOS::sInstance ) + { + LLFloaterTOS::sInstance = new LLFloaterTOS(type, message); + } + + if (type == TOS_TOS) + { + LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_tos.xml"); + } + else + { + LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_critical.xml"); + } + + return LLFloaterTOS::sInstance; +} + + +LLFloaterTOS::LLFloaterTOS(ETOSType type, const std::string & message) +: LLModalDialog( std::string(" "), 100, 100 ), + mType(type), + mMessage(message), + mWebBrowserWindowId( 0 ), + mLoadCompleteCount( 0 ) +{ +} + +// helper class that trys to download a URL from a web site and calls a method +// on parent class indicating if the web server is working or not +class LLIamHereTOS : public LLHTTPClient::Responder +{ + private: + LLIamHereTOS( LLFloaterTOS* parent ) : + mParent( parent ) + {} + + LLFloaterTOS* mParent; + + public: + + static boost::intrusive_ptr< LLIamHereTOS > build( LLFloaterTOS* parent ) + { + return boost::intrusive_ptr< LLIamHereTOS >( new LLIamHereTOS( parent ) ); + }; + + virtual void setParent( LLFloaterTOS* parentIn ) + { + mParent = parentIn; + }; + + virtual void result( const LLSD& content ) + { + if ( mParent ) + mParent->setSiteIsAlive( true ); + }; + + virtual void error( U32 status, const std::string& reason ) + { + if ( mParent ) + { + // *HACK: For purposes of this alive check, 302 Found + // (aka Moved Temporarily) is considered alive. The web site + // redirects this link to a "cache busting" temporary URL. JC + bool alive = (status == HTTP_FOUND); + mParent->setSiteIsAlive( alive ); + } + }; +}; + +// this is global and not a class member to keep crud out of the header file +namespace { + boost::intrusive_ptr< LLIamHereTOS > gResponsePtr = 0; +}; + +BOOL LLFloaterTOS::postBuild() +{ + childSetAction("Continue", onContinue, this); + childSetAction("Cancel", onCancel, this); + childSetCommitCallback("agree_chk", updateAgree, this); + + LLCheckBoxCtrl* tos_agreement = getChild("agree_chk"); + tos_agreement->setEnabled( true ); + + //Always set this so that the TOS is displayed whether the web browser pops up or not. + LLTextEditor *editor = getChild("tos_text"); + editor->setHandleEditKeysDirectly( TRUE ); + editor->setEnabled( FALSE ); + editor->setWordWrap(TRUE); + editor->setFocus(TRUE); + editor->setValue(LLSD(mMessage)); + LLMediaCtrl* web_browser = getChild("tos_html"); + if (web_browser) + { + //Disable for critical messages and text messages, it is reenabled later + web_browser->setVisible( FALSE ); + } + + if ( mType != TOS_TOS ) + { + // this displays the critical message only + return TRUE; + } + bool use_web_browser = false; + + //Check to see if the message is a link to display + std::string token = "http://"; + std::string::size_type iIndex = mMessage.rfind(token); + //IF it has http:// in it, we use the web browser + if(iIndex != std::string::npos && mMessage.length() >= 2) + { + // it exists + use_web_browser = true; + } + else if (gHippoGridManager->getConnectedGrid()->isSecondLife()) + { + //Its SL, use the browser for it as thats what it should do + use_web_browser = true; + } + + if ( web_browser && use_web_browser) + { + // hide the SL text widget if we're displaying TOS with using a browser widget. + LLTextEditor *editor = getChild("tos_text"); + editor->setVisible( FALSE ); + + // disable Agree to TOS radio button until the page has fully loaded + tos_agreement->setEnabled( false ); + + // Reenable the web browser + web_browser->setVisible( TRUE ); + + web_browser->addObserver(this); + gResponsePtr = LLIamHereTOS::build( this ); + LLHTTPClient::head( getString( "real_url" ), gResponsePtr ); + } + + return TRUE; +} + +void LLFloaterTOS::setSiteIsAlive( bool alive ) +{ + // only do this for TOS pages + if ( mType == TOS_TOS ) + { + LLMediaCtrl* web_browser = getChild("tos_html"); + // if the contents of the site was retrieved + if ( alive ) + { + if ( web_browser ) + { + // navigate to the "real" page + web_browser->navigateTo( getString( "real_url" ) ); + }; + } + else + { + // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads) + // but if the page is unavailable, we need to do this now + LLCheckBoxCtrl* tos_agreement = getChild("agree_chk"); + tos_agreement->setEnabled( true ); + }; + }; +} + +LLFloaterTOS::~LLFloaterTOS() +{ + + // tell the responder we're not here anymore + if ( gResponsePtr ) + gResponsePtr->setParent( 0 ); + + LLFloaterTOS::sInstance = NULL; +} + +// virtual +void LLFloaterTOS::draw() +{ + // draw children + LLModalDialog::draw(); +} + +// static +void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata ) +{ + LLFloaterTOS* self = (LLFloaterTOS*) userdata; + bool agree = self->childGetValue("agree_chk").asBoolean(); + self->childSetEnabled("Continue", agree); +} + +// static +void LLFloaterTOS::onContinue( void* userdata ) +{ + LLFloaterTOS* self = (LLFloaterTOS*) userdata; + llinfos << "User agrees with TOS." << llendl; + if (self->mType == TOS_TOS) + { + gAcceptTOS = TRUE; + } + else + { + gAcceptCriticalMessage = TRUE; + } + + // Testing TOS dialog + #if ! LL_RELEASE_FOR_DOWNLOAD + if ( LLStartUp::getStartupState() == STATE_LOGIN_WAIT ) + { + LLStartUp::setStartupState( STATE_LOGIN_SHOW ); + } + else + #endif + + LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT ); // Go back and finish authentication + self->close(); // destroys this object +} + +// static +void LLFloaterTOS::onCancel( void* userdata ) +{ + LLFloaterTOS* self = (LLFloaterTOS*) userdata; + llinfos << "User disagrees with TOS." << llendl; + LLNotifications::instance().add("MustAgreeToLogIn", LLSD(), LLSD(), login_alert_done); + LLStartUp::setStartupState( STATE_LOGIN_SHOW ); + self->mLoadCompleteCount = 0; // reset counter for next time we come to TOS + self->close(); // destroys this object +} + +//virtual +void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent event) +{ + if(event == MEDIA_EVENT_NAVIGATE_COMPLETE) + { + // skip past the loading screen navigate complete + if ( ++mLoadCompleteCount == 2 ) + { + llinfos << "NAVIGATE COMPLETE" << llendl; + // enable Agree to TOS radio button now that page has loaded + LLCheckBoxCtrl * tos_agreement = getChild("agree_chk"); + tos_agreement->setEnabled( true ); + } + } +} diff --git a/linden/indra/newview/llmaniptranslate.cpp b/linden/indra/newview/llmaniptranslate.cpp index 8484c4e..3b78553 100644 --- a/linden/indra/newview/llmaniptranslate.cpp +++ b/linden/indra/newview/llmaniptranslate.cpp @@ -531,7 +531,7 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) // You can't move more than some distance from your original mousedown point. F32 max_drag_distance = gHippoLimits->getMaxDragDistance(); - if (max_drag_distance != FLT_MAX && relative_move.magVecSquared() > max_drag_distance * max_drag_distance) + if (max_drag_distance != FLT_MAX && relative_move.magVecSquared() > max_drag_distance * max_drag_distance) { lldebugst(LLERR_USER_INPUT) << "hover handled by LLManipTranslate (too far)" << llendl; gViewerWindow->setCursor(UI_CURSOR_NOLOCKED); diff --git a/linden/indra/newview/llmapresponders.cpp b/linden/indra/newview/llmapresponders.cpp index b6b5c8a..31c04a3 100644 --- a/linden/indra/newview/llmapresponders.cpp +++ b/linden/indra/newview/llmapresponders.cpp @@ -120,8 +120,8 @@ void LLMapLayerResponder::result(const LLSD& result) S32 x_regions = map_block["X"]; S32 y_regions = map_block["Y"]; - S32 size_x_regions = map_block["SizeX"]; - S32 size_y_regions = map_block["SizeY"]; + S32 size_x_regions = map_block["SizeX"]; + S32 size_y_regions = map_block["SizeY"]; std::string name = map_block["Name"]; S32 access = map_block["Access"]; S32 region_flags = map_block["RegionFlags"]; @@ -170,8 +170,8 @@ void LLMapLayerResponder::result(const LLSD& result) LLWorldMap::getInstance()->mSimInfoMap[handle] = siminfo; siminfo->mHandle = handle; - siminfo->msizeX = size_x_regions; - siminfo->msizeY = size_y_regions; + siminfo->msizeX = size_x_regions; + siminfo->msizeY = size_y_regions; siminfo->mName.assign( name ); siminfo->mAccess = access; /*Flawfinder: ignore*/ siminfo->mRegionFlags = region_flags; diff --git a/linden/indra/newview/llstartup.cpp b/linden/indra/newview/llstartup.cpp index 0b6d75f..164e038 100644 --- a/linden/indra/newview/llstartup.cpp +++ b/linden/indra/newview/llstartup.cpp @@ -368,7 +368,7 @@ bool idle_startup() static U64 first_sim_handle = 0; static LLHost first_sim; static std::string first_sim_seed_cap; - static U32 first_sim_size_x = 256; + static U32 first_sim_size_x = 256; static U32 first_sim_size_y = 256; static LLVector3 initial_sun_direction(1.f, 0.f, 0.f); @@ -1622,16 +1622,16 @@ bool idle_startup() first_sim_handle = to_region_handle(region_x, region_y); } - text = LLUserAuth::getInstance()->getResponse("region_size_x"); - if(!text.empty()) { - first_sim_size_x = strtoul(text.c_str(), NULL, 10); - LLViewerParcelMgr::getInstance()->init(first_sim_size_x); - } - - //region Y size is currently unused, major refactoring required. - Patrick Sapinski (2/10/2011) - text = LLUserAuth::getInstance()->getResponse("region_size_y"); - if(!text.empty()) first_sim_size_y = strtoul(text.c_str(), NULL, 10); - + text = LLUserAuth::getInstance()->getResponse("region_size_x"); + if(!text.empty()) { + first_sim_size_x = strtoul(text.c_str(), NULL, 10); + LLViewerParcelMgr::getInstance()->init(first_sim_size_x); + } + + //region Y size is currently unused, major refactoring required. - Patrick Sapinski (2/10/2011) + text = LLUserAuth::getInstance()->getResponse("region_size_y"); + if(!text.empty()) first_sim_size_y = strtoul(text.c_str(), NULL, 10); + const std::string look_at_str = LLUserAuth::getInstance()->getResponse("look_at"); if (!look_at_str.empty()) { diff --git a/linden/indra/newview/llsurface.cpp b/linden/indra/newview/llsurface.cpp index 66f8076..5a99e66 100644 --- a/linden/indra/newview/llsurface.cpp +++ b/linden/indra/newview/llsurface.cpp @@ -713,15 +713,15 @@ void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL break; } - if (b_large_patch) - { - i = ph.patchids >> 16; //x - j = ph.patchids & 0xFFFF; //y - } - else - { - i = ph.patchids >> 5; //x - j = ph.patchids & 0x1F; //y + if (b_large_patch) + { + i = ph.patchids >> 16; //x + j = ph.patchids & 0xFFFF; //y + } + else + { + i = ph.patchids >> 5; //x + j = ph.patchids & 0x1F; //y } if ((i >= mPatchesPerEdge) || (j >= mPatchesPerEdge)) diff --git a/linden/indra/newview/llviewermessage.cpp b/linden/indra/newview/llviewermessage.cpp index 4de4768..f67f0dc 100755 --- a/linden/indra/newview/llviewermessage.cpp +++ b/linden/indra/newview/llviewermessage.cpp @@ -3531,16 +3531,16 @@ void process_teleport_finish(LLMessageSystem* msg, void**) U32 teleport_flags; msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags); - U32 region_size_x = 256; - msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x); - U32 region_size_y = 256; - msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y); - - //and a little hack for Second Life compatibility - if (region_size_y == 0 || region_size_x == 0) - { - region_size_x = 256; - region_size_y = 256; + U32 region_size_x = 256; + msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y); + + //and a little hack for Second Life compatibility + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; } std::string seedCap; @@ -3877,16 +3877,16 @@ void process_crossed_region(LLMessageSystem* msg, void**) std::string seedCap; msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap); - U32 region_size_x = 256; - msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeX, region_size_x); - U32 region_size_y = 256; - msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeY, region_size_y); - - //and a little hack for Second Life compatibility - if (region_size_y == 0 || region_size_x == 0) - { - region_size_x = 256; - region_size_y = 256; + U32 region_size_x = 256; + msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeY, region_size_y); + + //and a little hack for Second Life compatibility + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; } send_complete_agent_movement(sim_host); diff --git a/linden/indra/newview/llviewerparcelmgr.cpp b/linden/indra/newview/llviewerparcelmgr.cpp index 7373c3f..b99b0c0 100644 --- a/linden/indra/newview/llviewerparcelmgr.cpp +++ b/linden/indra/newview/llviewerparcelmgr.cpp @@ -140,24 +140,24 @@ LLViewerParcelMgr::LLViewerParcelMgr() mBlockedImage = gImageList.getImageFromFile("noentrylines.j2c"); mPassImage = gImageList.getImageFromFile("noentrypasslines.j2c"); - init(256); -} - -//moved this stuff out of the constructor and into a function that we can call again after we get the region size. -//LLViewerParcelMgr needs to be changed so we either get an instance per region, or it handles various region sizes -//on a single grid properly - Patrick Sapinski (2/10/2011) -void LLViewerParcelMgr::init(F32 region_size) -{ - mParcelsPerEdge = S32( region_size / PARCEL_GRID_STEP_METERS ); + init(256); +} + +//moved this stuff out of the constructor and into a function that we can call again after we get the region size. +//LLViewerParcelMgr needs to be changed so we either get an instance per region, or it handles various region sizes +//on a single grid properly - Patrick Sapinski (2/10/2011) +void LLViewerParcelMgr::init(F32 region_size) +{ + mParcelsPerEdge = S32( region_size / PARCEL_GRID_STEP_METERS ); mHighlightSegments = new U8[(mParcelsPerEdge+1)*(mParcelsPerEdge+1)]; resetSegments(mHighlightSegments); mCollisionSegments = new U8[(mParcelsPerEdge+1)*(mParcelsPerEdge+1)]; resetSegments(mCollisionSegments); - S32 mParcelOverLayChunks = region_size * region_size / (128 * 128); - - S32 overlay_size = mParcelsPerEdge * mParcelsPerEdge / mParcelOverLayChunks; + S32 mParcelOverLayChunks = region_size * region_size / (128 * 128); + + S32 overlay_size = mParcelsPerEdge * mParcelsPerEdge / mParcelOverLayChunks; sPackedOverlay = new U8[overlay_size]; mAgentParcelOverlay = new U8[mParcelsPerEdge * mParcelsPerEdge]; @@ -1361,7 +1361,7 @@ void LLViewerParcelMgr::processParcelOverlay(LLMessageSystem *msg, void **user) return; } - S32 expected_size = 1024; //parcels_per_edge * parcels_per_edge / PARCEL_OVERLAY_CHUNKS; + S32 expected_size = 1024; //parcels_per_edge * parcels_per_edge / PARCEL_OVERLAY_CHUNKS; if (packed_overlay_size != expected_size) { llwarns << "Got parcel overlay size " << packed_overlay_size diff --git a/linden/indra/newview/llviewerparcelmgr.h b/linden/indra/newview/llviewerparcelmgr.h index dcdea3c..59e6186 100644 --- a/linden/indra/newview/llviewerparcelmgr.h +++ b/linden/indra/newview/llviewerparcelmgr.h @@ -82,8 +82,8 @@ public: LLViewerParcelMgr(); ~LLViewerParcelMgr(); - void init(F32 region_size); - + void init(F32 region_size); + static void cleanupGlobals(); BOOL selectionEmpty() const; diff --git a/linden/indra/newview/llviewerparceloverlay.cpp b/linden/indra/newview/llviewerparceloverlay.cpp index a31f153..4ae3253 100644 --- a/linden/indra/newview/llviewerparceloverlay.cpp +++ b/linden/indra/newview/llviewerparceloverlay.cpp @@ -58,7 +58,7 @@ const U8 OVERLAY_IMG_COMPONENTS = 4; LLViewerParcelOverlay::LLViewerParcelOverlay(LLViewerRegion* region, F32 region_width_meters) : mRegion( region ), mParcelGridsPerEdge( S32( region_width_meters / PARCEL_GRID_STEP_METERS ) ), - mRegionSize(S32(region_width_meters)), + mRegionSize(S32(region_width_meters)), mDirty( FALSE ), mTimeSinceLastUpdate(), mOverlayTextureIdx(-1), @@ -300,8 +300,8 @@ void LLViewerParcelOverlay::uncompressLandOverlay(S32 chunk, U8 *packed_overlay) { // Unpack the message data into the ownership array S32 size = mParcelGridsPerEdge * mParcelGridsPerEdge; - S32 mParcelOverLayChunks = mRegionSize * mRegionSize / (128 * 128); - S32 chunk_size = size / mParcelOverLayChunks; + S32 mParcelOverLayChunks = mRegionSize * mRegionSize / (128 * 128); + S32 chunk_size = size / mParcelOverLayChunks; memcpy(mOwnership + chunk*chunk_size, packed_overlay, chunk_size); /*Flawfinder: ignore*/ diff --git a/linden/indra/newview/llviewerparceloverlay.h b/linden/indra/newview/llviewerparceloverlay.h index d3b5980..fc0db0a 100644 --- a/linden/indra/newview/llviewerparceloverlay.h +++ b/linden/indra/newview/llviewerparceloverlay.h @@ -98,7 +98,7 @@ private: LLViewerRegion* mRegion; S32 mParcelGridsPerEdge; - S32 mRegionSize; + S32 mRegionSize; LLPointer mTexture; LLPointer mImageRaw; diff --git a/linden/indra/newview/llviewerregion.cpp b/linden/indra/newview/llviewerregion.cpp index 4186362..eba0db7 100644 --- a/linden/indra/newview/llviewerregion.cpp +++ b/linden/indra/newview/llviewerregion.cpp @@ -200,7 +200,7 @@ LLViewerRegion::LLViewerRegion(const U64 &handle, if (!gNoRender) { mParcelOverlay = new LLViewerParcelOverlay(this, region_width_meters); - //Re-init the parcel mgr for this sim + //Re-init the parcel mgr for this sim LLViewerParcelMgr::getInstance()->init(region_width_meters); } else diff --git a/linden/indra/newview/llvlmanager.cpp b/linden/indra/newview/llvlmanager.cpp index 68b4d7b..7f483ca 100644 --- a/linden/indra/newview/llvlmanager.cpp +++ b/linden/indra/newview/llvlmanager.cpp @@ -57,23 +57,23 @@ LLVLManager::~LLVLManager() void LLVLManager::addLayerData(LLVLData *vl_datap, const S32 mesg_size) { - if (LAND_LAYER_CODE == vl_datap->mType || - AURORA_LAND_LAYER_CODE == vl_datap->mType) - { - mLandBits += mesg_size * 8; - } - else if (WIND_LAYER_CODE == vl_datap->mType || - AURORA_WIND_LAYER_CODE == vl_datap->mType) - { - mWindBits += mesg_size * 8; - } - else if (CLOUD_LAYER_CODE == vl_datap->mType) - { - mCloudBits += mesg_size * 8; - } - else - { - llerrs << "Unknown layer type!" << (S32)vl_datap->mType << llendl; + if (LAND_LAYER_CODE == vl_datap->mType || + AURORA_LAND_LAYER_CODE == vl_datap->mType) + { + mLandBits += mesg_size * 8; + } + else if (WIND_LAYER_CODE == vl_datap->mType || + AURORA_WIND_LAYER_CODE == vl_datap->mType) + { + mWindBits += mesg_size * 8; + } + else if (CLOUD_LAYER_CODE == vl_datap->mType) + { + mCloudBits += mesg_size * 8; + } + else + { + llerrs << "Unknown layer type!" << (S32)vl_datap->mType << llendl; } mPacketData.put(vl_datap); @@ -92,23 +92,23 @@ void LLVLManager::unpackData(const S32 num_packets) LLGroupHeader goph; decode_patch_group_header(bit_pack, &goph); - if (LAND_LAYER_CODE == datap->mType) - { - datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, FALSE); - } - else if (AURORA_LAND_LAYER_CODE == datap->mType) - { - datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, TRUE); - } - else if (WIND_LAYER_CODE == datap->mType || - AURORA_WIND_LAYER_CODE == datap->mType) - { - datap->mRegionp->mWind.decompress(bit_pack, &goph); - } - else if (CLOUD_LAYER_CODE == datap->mType || - AURORA_CLOUD_LAYER_CODE == datap->mType) - { - datap->mRegionp->mCloudLayer.decompress(bit_pack, &goph); + if (LAND_LAYER_CODE == datap->mType) + { + datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, FALSE); + } + else if (AURORA_LAND_LAYER_CODE == datap->mType) + { + datap->mRegionp->getLand().decompressDCTPatch(bit_pack, &goph, TRUE); + } + else if (WIND_LAYER_CODE == datap->mType || + AURORA_WIND_LAYER_CODE == datap->mType) + { + datap->mRegionp->mWind.decompress(bit_pack, &goph); + } + else if (CLOUD_LAYER_CODE == datap->mType || + AURORA_CLOUD_LAYER_CODE == datap->mType) + { + datap->mRegionp->mCloudLayer.decompress(bit_pack, &goph); } } diff --git a/linden/indra/newview/llvowater.cpp b/linden/indra/newview/llvowater.cpp index 8af9e4a..eb74520 100644 --- a/linden/indra/newview/llvowater.cpp +++ b/linden/indra/newview/llvowater.cpp @@ -74,7 +74,7 @@ LLVOWater::LLVOWater(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regi { // Terrain must draw during selection passes so it can block objects behind it. mbCanSelect = FALSE; - setScale(LLVector3(mRegionp->getWidth(), mRegionp->getWidth(), 0.f)); // Hack for setting scale for bounding boxes/visibility. + setScale(LLVector3(mRegionp->getWidth(), mRegionp->getWidth(), 0.f)); // Hack for setting scale for bounding boxes/visibility. mUseTexture = TRUE; mIsEdgePatch = FALSE; diff --git a/linden/indra/newview/llworld.cpp b/linden/indra/newview/llworld.cpp index 525195d..13fc91c 100644 --- a/linden/indra/newview/llworld.cpp +++ b/linden/indra/newview/llworld.cpp @@ -172,11 +172,11 @@ LLViewerRegion* LLWorld::addRegion(const U64 ®ion_handle, const LLHost &host, U32 iindex = 0; U32 jindex = 0; - mWidth = region_size_x; - mWidthInMeters = mWidth * mScale; + mWidth = region_size_x; + mWidthInMeters = mWidth * mScale; from_region_handle(region_handle, &iindex, &jindex); - S32 x = (S32)(iindex/256); - S32 y = (S32)(jindex/256); + S32 x = (S32)(iindex/256); + S32 y = (S32)(jindex/256); llinfos << "Adding new region (" << x << ":" << y << ")" << llendl; llinfos << "Host: " << host << llendl; @@ -1258,15 +1258,15 @@ void process_enable_simulator(LLMessageSystem *msg, void **user_data) // which simulator should we modify? LLHost sim(ip_u32, port); - U32 region_size_x = 256; - msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeX, region_size_x); - U32 region_size_y = 256; - msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeY, region_size_y); - - if (region_size_y == 0 || region_size_x == 0) - { - region_size_x = 256; - region_size_y = 256; + U32 region_size_x = 256; + msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeX, region_size_x); + U32 region_size_y = 256; + msg->getU32Fast(_PREHASH_SimulatorInfo, _PREHASH_RegionSizeY, region_size_y); + + if (region_size_y == 0 || region_size_x == 0) + { + region_size_x = 256; + region_size_y = 256; } // Viewer trusts the simulator. diff --git a/linden/indra/newview/llworldmap.cpp b/linden/indra/newview/llworldmap.cpp index ead72fa..bd3996d 100644 --- a/linden/indra/newview/llworldmap.cpp +++ b/linden/indra/newview/llworldmap.cpp @@ -239,25 +239,25 @@ LLSimInfo* LLWorldMap::simInfoFromPosGlobal(const LLVector3d& pos_global) LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 findhandle) { - std::map::const_iterator it; - for (it = LLWorldMap::getInstance()->mSimInfoMap.begin(); it != LLWorldMap::getInstance()->mSimInfoMap.end(); ++it) - { - const U64 handle = (*it).first; - LLSimInfo* info = (*it).second; - if(handle == findhandle) - { - return info; - } - U32 x = 0, y = 0; - from_region_handle(findhandle, &x, &y); - U32 checkRegionX, checkRegionY; - from_region_handle(handle, &checkRegionX, &checkRegionY); - - if(x > checkRegionX && x < (checkRegionX + info->msizeX) && - y > checkRegionY && y < (checkRegionY + info->msizeY)) - { - return info; - } + std::map::const_iterator it; + for (it = LLWorldMap::getInstance()->mSimInfoMap.begin(); it != LLWorldMap::getInstance()->mSimInfoMap.end(); ++it) + { + const U64 handle = (*it).first; + LLSimInfo* info = (*it).second; + if(handle == findhandle) + { + return info; + } + U32 x = 0, y = 0; + from_region_handle(findhandle, &x, &y); + U32 checkRegionX, checkRegionY; + from_region_handle(handle, &checkRegionX, &checkRegionY); + + if(x > checkRegionX && x < (checkRegionX + info->msizeX) && + y > checkRegionY && y < (checkRegionY + info->msizeY)) + { + return info; + } } return NULL; } diff --git a/linden/indra/newview/llworldmap.h b/linden/indra/newview/llworldmap.h index 6725f91..56b32a2 100644 --- a/linden/indra/newview/llworldmap.h +++ b/linden/indra/newview/llworldmap.h @@ -81,8 +81,8 @@ public: public: U64 mHandle; - S32 msizeX; - S32 msizeY; + S32 msizeX; + S32 msizeY; std::string mName; F64 mAgentsUpdateTime; diff --git a/linden/indra/newview/llworldmapview.cpp b/linden/indra/newview/llworldmapview.cpp index 51de598..8d9ed1b 100644 --- a/linden/indra/newview/llworldmapview.cpp +++ b/linden/indra/newview/llworldmapview.cpp @@ -471,8 +471,8 @@ void LLWorldMapView::draw() // When the view isn't panned, 0,0 = center of rectangle F32 bottom = sPanY + half_height + relative_y; F32 left = sPanX + half_width + relative_x; - F32 top = bottom+ (sMapScale * info->msizeY / REGION_WIDTH_METERS); - F32 right = left + (sMapScale * info->msizeY / REGION_WIDTH_METERS); + F32 top = bottom+ (sMapScale * info->msizeY / REGION_WIDTH_METERS); + F32 right = left + (sMapScale * info->msizeY / REGION_WIDTH_METERS); // Switch to world map texture (if available for this region) if either: // 1. Tiles are zoomed out small enough, or @@ -567,11 +567,11 @@ void LLWorldMapView::draw() center_global.mdV[VX] += 128.0; center_global.mdV[VY] += 128.0; - S32 x_draw_size = llround(sMapScale); - S32 y_draw_size = llround(sMapScale); - x_draw_size *= info->msizeX / REGION_WIDTH_METERS; - y_draw_size *= info->msizeY / REGION_WIDTH_METERS; - + S32 x_draw_size = llround(sMapScale); + S32 y_draw_size = llround(sMapScale); + x_draw_size *= info->msizeX / REGION_WIDTH_METERS; + y_draw_size *= info->msizeY / REGION_WIDTH_METERS; + if (simimage != NULL) { simimage->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP); diff --git a/linden/indra/newview/viewertime.cpp b/linden/indra/newview/viewertime.cpp index 8a65a23..5ed9465 100644 --- a/linden/indra/newview/viewertime.cpp +++ b/linden/indra/newview/viewertime.cpp @@ -27,7 +27,7 @@ * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ - + #include #include "llviewerprecompiledheaders.h" -- cgit v1.1 From 74d6849a9730941839f00c1ec2b640958fd61cc9 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sat, 19 Mar 2011 13:38:38 -0500 Subject: Package both libz.so.1 and libz.so (symlink) on Linux32. (IMP-790) The viewer binary links against libz.so, but libvivoxsdk.so and some other libraries link against libz.so.1. --- linden/indra/newview/viewer_manifest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linden/indra/newview/viewer_manifest.py b/linden/indra/newview/viewer_manifest.py index 8225b4c..86acaea 100755 --- a/linden/indra/newview/viewer_manifest.py +++ b/linden/indra/newview/viewer_manifest.py @@ -1018,7 +1018,8 @@ class Linux_i686Manifest(LinuxManifest): self.path("libELFIO.so") self.path("libopenjpeg.so.2") self.path("libxml2.so.2") - self.path("libz.so.1","libz.so") + self.path("libz.so") + self.path("libz.so.1") # OpenAL self.path("libopenal.so.1.12.854", "libopenal.so.1") -- cgit v1.1