Apertura del repositorio

This commit is contained in:
2025-05-24 18:09:39 -03:00
parent 76e6359dad
commit d883ddd0d0
35253 changed files with 2891973 additions and 2 deletions
+76
View File
@@ -0,0 +1,76 @@
# -*- cmake -*-
project(llinventory)
include(00-Common)
include(LLCommon)
include(LLCoreHttp)
set(llinventory_SOURCE_FILES
llcategory.cpp
lleconomy.cpp #<FS:Ansariel> OpenSim legacy economy
llfoldertype.cpp
llinventory.cpp
llinventorydefines.cpp
llinventorysettings.cpp
llinventorytype.cpp
lllandmark.cpp
llnotecard.cpp
llparcel.cpp
llpermissions.cpp
llsaleinfo.cpp
llsettingsbase.cpp
llsettingsdaycycle.cpp
llsettingssky.cpp
llsettingswater.cpp
lltransactionflags.cpp
lluserrelations.cpp
)
set(llinventory_HEADER_FILES
CMakeLists.txt
llcategory.h
lleconomy.h #<FS:Ansariel> OpenSim legacy economy
llfoldertype.h
llinventory.h
llinventorydefines.h
llinventorysettings.h
llinventorytype.h
llinvtranslationbrdg.h
lllandmark.h
llnotecard.h
llparcel.h
llparcelflags.h
llpermissions.h
llpermissionsflags.h
llsaleinfo.h
llsettingsbase.h
llsettingsdaycycle.h
llsettingssky.h
llsettingswater.h
lltransactionflags.h
lltransactiontypes.h
lluserrelations.h
)
list(APPEND llinventory_SOURCE_FILES ${llinventory_HEADER_FILES})
add_library (llinventory ${llinventory_SOURCE_FILES})
target_link_libraries( llinventory llcommon llmath llmessage llxml )
target_include_directories( llinventory INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
#add unit tests
if (LL_TESTS)
INCLUDE(LLAddBuildTest)
SET(llinventory_TEST_SOURCE_FILES
# no real unit tests yet!
)
LL_ADD_PROJECT_UNIT_TESTS(llinventory "${llinventory_TEST_SOURCE_FILES}")
#set(TEST_DEBUG on)
set(test_libs llinventory llmath llcorehttp llfilesystem )
LL_ADD_INTEGRATION_TEST(inventorymisc "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llparcel "" "${test_libs}")
endif (LL_TESTS)
+179
View File
@@ -0,0 +1,179 @@
/**
* @file llcategory.cpp
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llcategory.h"
#include "message.h"
const LLCategory LLCategory::none;
///----------------------------------------------------------------------------
/// Local function declarations, constants, enums, and typedefs
///----------------------------------------------------------------------------
// This is the storage of the category names. It's loosely based on a
// heap-like structure with indices into it for faster searching and
// so that we don't have to maintain a balanced heap. It's *VITALLY*
// important that the CATEGORY_INDEX and CATEGORY_NAME tables are kept
// in synch.
// CATEGORY_INDEX indexes into CATEGORY_NAME at the first occurance of
// a child. Thus, the first child of root is "Object" which is located
// in CATEGORY_NAME[1].
const S32 CATEGORY_INDEX[] =
{
1, // ROOT
6, // object
7, // clothing
7, // texture
7, // sound
7, // landmark
7, // object|component
7, // off the end (required for child count calculations)
};
// The heap of names
const char* CATEGORY_NAME[] =
{
"(none)",
"Object", // (none)
"Clothing",
"Texture",
"Sound",
"Landmark",
"Component", // object
NULL
};
///----------------------------------------------------------------------------
/// Class llcategory
///----------------------------------------------------------------------------
LLCategory::LLCategory()
{
// this is used as a simple compile time assertion. If this code
// fails to compile, the depth has been changed, and we need to
// clean up some of the code that relies on the depth, such as the
// default constructor. If CATEGORY_DEPTH != 4, this code will
// attempt to construct a zero length array - which the compiler
// should balk at.
// static const char CATEGORY_DEPTH_CHECK[(CATEGORY_DEPTH == 4)?1:0] = {' '}; // unused
// actually initialize the object.
mData[0] = 0;
mData[1] = 0;
mData[2] = 0;
mData[3] = 0;
}
void LLCategory::init(U32 value)
{
U8 v;
for(S32 i = 0; i < CATEGORY_DEPTH; i++)
{
v = (U8)((0x000000ff) & value);
mData[CATEGORY_DEPTH - 1 - i] = v;
value >>= 8;
}
}
U32 LLCategory::getU32() const
{
U32 rv = 0;
rv |= mData[0];
rv <<= 8;
rv |= mData[1];
rv <<= 8;
rv |= mData[2];
rv <<= 8;
rv |= mData[3];
return rv;
}
S32 LLCategory::getSubCategoryCount() const
{
S32 rv = CATEGORY_INDEX[mData[0] + 1] - CATEGORY_INDEX[mData[0]];
return rv;
}
// This method will return a category that is the nth subcategory. If
// you're already at the bottom of the hierarchy, then the method will
// return a copy of this.
LLCategory LLCategory::getSubCategory(U8 n) const
{
LLCategory rv(*this);
for(S32 i = 0; i < (CATEGORY_DEPTH - 1); i++)
{
if(rv.mData[i] == 0)
{
rv.mData[i] = n + 1;
break;
}
}
return rv;
}
// This method will return the name of the leaf category type
const char* LLCategory::lookupName() const
{
S32 i = 0;
S32 index = mData[i++];
while((i < CATEGORY_DEPTH) && (mData[i] != 0))
{
index = CATEGORY_INDEX[index];
++i;
}
return CATEGORY_NAME[index];
}
// message serialization
void LLCategory::packMessage(LLMessageSystem* msg) const
{
U32 data = getU32();
msg->addU32Fast(_PREHASH_Category, data);
}
// message serialization
void LLCategory::unpackMessage(LLMessageSystem* msg, const char* block)
{
U32 data;
msg->getU32Fast(block, _PREHASH_Category, data);
init(data);
}
// message serialization
void LLCategory::unpackMultiMessage(LLMessageSystem* msg, const char* block,
S32 block_num)
{
U32 data;
msg->getU32Fast(block, _PREHASH_Category, data, block_num);
init(data);
}
///----------------------------------------------------------------------------
/// Local function definitions
///----------------------------------------------------------------------------
+98
View File
@@ -0,0 +1,98 @@
/**
* @file llcategory.h
* @brief LLCategory class header file.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLCATEGORY_H
#define LL_LLCATEGORY_H
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLCategory
//
// An instance of the LLCategory class represents a particular
// category in a hierarchical classification system. For now, it is 4
// levels deep with 255 (minus 1) possible values at each level. If a
// non zero value is found at level 4, that is the leaf category,
// otherwise, it is the first level that has a 0 in the next depth
// level.
//
// To output the names of all top level categories, you could do the
// following:
//
// S32 count = LLCategory::none.getSubCategoryCount();
// for(S32 i = 0; i < count; i++)
// {
// LL_INFOS() << none.getSubCategory(i).lookupNmae() << LL_ENDL;
// }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLMessageSystem;
class LLCategory
{
public:
// Nice default static const.
static const LLCategory none;
// construction. Since this is really a POD type, destruction,
// copy, and assignment are handled by the compiler.
LLCategory();
explicit LLCategory(U32 value) { init(value); }
// methods
void init(U32 value);
U32 getU32() const;
S32 getSubCategoryCount() const;
// This method will return a category that is the nth
// subcategory. If you're already at the bottom of the hierarchy,
// then the method will return a copy of this.
LLCategory getSubCategory(U8 n) const;
// This method will return the name of the leaf category type
const char* lookupName() const;
// This method will return the full hierarchy name in an easily
// interpreted (TOP)|(SUB1)|(SUB2) format. *NOTE: not implemented
// because we don't have anything but top level categories at the
// moment.
//const char* lookupFullName() const;
// message serialization
void packMessage(LLMessageSystem* msg) const;
void unpackMessage(LLMessageSystem* msg, const char* block);
void unpackMultiMessage(LLMessageSystem* msg, const char* block,
S32 block_num);
protected:
enum
{
CATEGORY_TOP = 0,
CATEGORY_DEPTH = 4,
};
U8 mData[CATEGORY_DEPTH];
};
#endif // LL_LLCATEGORY_H
+287
View File
@@ -0,0 +1,287 @@
/**
* @file lleconomy.cpp
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lleconomy.h"
#include "llerror.h"
#include "message.h"
#include "v3math.h"
LLBaseEconomy::LLBaseEconomy()
: mObjectCount( -1 ),
mObjectCapacity( -1 ),
mPriceObjectClaim( -1 ),
mPricePublicObjectDecay( -1 ),
mPricePublicObjectDelete( -1 ),
mPriceEnergyUnit( -1 ),
mPriceUpload( -1 ),
mPriceRentLight( -1 ),
mTeleportMinPrice( -1 ),
mTeleportPriceExponent( -1 ),
mPriceGroupCreate( -1 )
{ }
LLBaseEconomy::~LLBaseEconomy()
{ }
void LLBaseEconomy::addObserver(LLEconomyObserver* observer)
{
mObservers.push_back(observer);
}
void LLBaseEconomy::removeObserver(LLEconomyObserver* observer)
{
std::list<LLEconomyObserver*>::iterator it =
std::find(mObservers.begin(), mObservers.end(), observer);
if (it != mObservers.end())
{
mObservers.erase(it);
}
}
void LLBaseEconomy::notifyObservers()
{
for (std::list<LLEconomyObserver*>::iterator it = mObservers.begin();
it != mObservers.end();
++it)
{
(*it)->onEconomyDataChange();
}
}
// static
void LLBaseEconomy::processEconomyData(LLMessageSystem *msg, LLBaseEconomy* econ_data)
{
S32 i;
F32 f;
msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
econ_data->setObjectCapacity(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
econ_data->setObjectCount(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
econ_data->setPriceEnergyUnit(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
econ_data->setPriceObjectClaim(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
econ_data->setPricePublicObjectDecay(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
econ_data->setPricePublicObjectDelete(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, i);
econ_data->setPriceUpload(i);
#if LL_LINUX
// We can optionally fake the received upload price for testing.
// Note that the server is within its rights to not obey our fake
// price. :)
const char* fakeprice_str = getenv("LL_FAKE_UPLOAD_PRICE");
if (fakeprice_str)
{
S32 fakeprice = (S32)atoi(fakeprice_str);
LL_WARNS() << "LL_FAKE_UPLOAD_PRICE: Faking upload price as L$" << fakeprice << LL_ENDL;
econ_data->setPriceUpload(fakeprice);
}
#endif
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
econ_data->setPriceRentLight(i);
msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
econ_data->setTeleportMinPrice(i);
msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
econ_data->setTeleportPriceExponent(f);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate, i);
econ_data->setPriceGroupCreate(i);
econ_data->notifyObservers();
}
S32 LLBaseEconomy::calculateTeleportCost(F32 distance) const
{
S32 min_cost = getTeleportMinPrice();
F32 exponent = getTeleportPriceExponent();
F32 divisor = 100.f * pow(3.f, exponent);
S32 cost = (U32)(distance * pow(log10(distance), exponent) / divisor);
if (cost < 0)
{
cost = 0;
}
else if (cost < min_cost)
{
cost = min_cost;
}
return cost;
}
S32 LLBaseEconomy::calculateLightRent(const LLVector3& object_size) const
{
F32 intensity_mod = llmax(object_size.magVec(), 1.f);
return (S32)(intensity_mod * getPriceRentLight());
}
void LLBaseEconomy::print()
{
LL_INFOS() << "Global Economy Settings: " << LL_ENDL;
LL_INFOS() << "Object Capacity: " << mObjectCapacity << LL_ENDL;
LL_INFOS() << "Object Count: " << mObjectCount << LL_ENDL;
LL_INFOS() << "Claim Price Per Object: " << mPriceObjectClaim << LL_ENDL;
LL_INFOS() << "Claim Price Per Public Object: " << mPricePublicObjectDecay << LL_ENDL;
LL_INFOS() << "Delete Price Per Public Object: " << mPricePublicObjectDelete << LL_ENDL;
LL_INFOS() << "Release Price Per Public Object: " << getPricePublicObjectRelease() << LL_ENDL;
LL_INFOS() << "Price Per Energy Unit: " << mPriceEnergyUnit << LL_ENDL;
LL_INFOS() << "Price Per Upload: " << mPriceUpload << LL_ENDL;
LL_INFOS() << "Light Base Price: " << mPriceRentLight << LL_ENDL;
LL_INFOS() << "Teleport Min Price: " << mTeleportMinPrice << LL_ENDL;
LL_INFOS() << "Teleport Price Exponent: " << mTeleportPriceExponent << LL_ENDL;
LL_INFOS() << "Price for group creation: " << mPriceGroupCreate << LL_ENDL;
}
LLRegionEconomy::LLRegionEconomy()
: mPriceObjectRent( -1.f ),
mPriceObjectScaleFactor( -1.f ),
mEnergyEfficiency( -1.f ),
mBasePriceParcelClaimDefault(-1),
mBasePriceParcelClaimActual(-1),
mPriceParcelClaimFactor(-1.f),
mBasePriceParcelRent(-1),
mAreaOwned(-1.f),
mAreaTotal(-1.f)
{ }
LLRegionEconomy::~LLRegionEconomy()
{ }
bool LLRegionEconomy::hasData() const
{
return (mBasePriceParcelRent != -1);
}
// static
void LLRegionEconomy::processEconomyData(LLMessageSystem *msg, void** user_data)
{
S32 i;
F32 f;
LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
LLBaseEconomy::processEconomyData(msg, this_ptr);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelClaim, i);
this_ptr->setBasePriceParcelClaimDefault(i);
msg->getF32(_PREHASH_Info, _PREHASH_PriceParcelClaimFactor, f);
this_ptr->setPriceParcelClaimFactor(f);
msg->getF32Fast(_PREHASH_Info, _PREHASH_EnergyEfficiency, f);
this_ptr->setEnergyEfficiency(f);
msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectRent, f);
this_ptr->setPriceObjectRent(f);
msg->getF32Fast(_PREHASH_Info, _PREHASH_PriceObjectScaleFactor, f);
this_ptr->setPriceObjectScaleFactor(f);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceParcelRent, i);
this_ptr->setBasePriceParcelRent(i);
}
// static
void LLRegionEconomy::processEconomyDataRequest(LLMessageSystem *msg, void **user_data)
{
LLRegionEconomy *this_ptr = (LLRegionEconomy*)user_data;
if (!this_ptr->hasData())
{
LL_WARNS() << "Dropping EconomyDataRequest, because EconomyData message "
<< "has not been processed" << LL_ENDL;
}
msg->newMessageFast(_PREHASH_EconomyData);
msg->nextBlockFast(_PREHASH_Info);
msg->addS32Fast(_PREHASH_ObjectCapacity, this_ptr->getObjectCapacity());
msg->addS32Fast(_PREHASH_ObjectCount, this_ptr->getObjectCount());
msg->addS32Fast(_PREHASH_PriceEnergyUnit, this_ptr->getPriceEnergyUnit());
msg->addS32Fast(_PREHASH_PriceObjectClaim, this_ptr->getPriceObjectClaim());
msg->addS32Fast(_PREHASH_PricePublicObjectDecay, this_ptr->getPricePublicObjectDecay());
msg->addS32Fast(_PREHASH_PricePublicObjectDelete, this_ptr->getPricePublicObjectDelete());
msg->addS32Fast(_PREHASH_PriceParcelClaim, this_ptr->mBasePriceParcelClaimActual);
msg->addF32Fast(_PREHASH_PriceParcelClaimFactor, this_ptr->mPriceParcelClaimFactor);
msg->addS32Fast(_PREHASH_PriceUpload, this_ptr->getPriceUpload());
msg->addS32Fast(_PREHASH_PriceRentLight, this_ptr->getPriceRentLight());
msg->addS32Fast(_PREHASH_TeleportMinPrice, this_ptr->getTeleportMinPrice());
msg->addF32Fast(_PREHASH_TeleportPriceExponent, this_ptr->getTeleportPriceExponent());
msg->addF32Fast(_PREHASH_EnergyEfficiency, this_ptr->getEnergyEfficiency());
msg->addF32Fast(_PREHASH_PriceObjectRent, this_ptr->getPriceObjectRent());
msg->addF32Fast(_PREHASH_PriceObjectScaleFactor, this_ptr->getPriceObjectScaleFactor());
msg->addS32Fast(_PREHASH_PriceParcelRent, this_ptr->getPriceParcelRent());
msg->addS32Fast(_PREHASH_PriceGroupCreate, this_ptr->getPriceGroupCreate());
msg->sendReliable(msg->getSender());
}
S32 LLRegionEconomy::getPriceParcelClaim() const
{
//return (S32)((F32)mBasePriceParcelClaim * (mAreaTotal / (mAreaTotal - mAreaOwned)));
return (S32)((F32)mBasePriceParcelClaimActual * mPriceParcelClaimFactor);
}
S32 LLRegionEconomy::getPriceParcelRent() const
{
return mBasePriceParcelRent;
}
void LLRegionEconomy::print()
{
this->LLBaseEconomy::print();
LL_INFOS() << "Region Economy Settings: " << LL_ENDL;
LL_INFOS() << "Land (square meters): " << mAreaTotal << LL_ENDL;
LL_INFOS() << "Owned Land (square meters): " << mAreaOwned << LL_ENDL;
LL_INFOS() << "Daily Object Rent: " << mPriceObjectRent << LL_ENDL;
LL_INFOS() << "Daily Land Rent (per meter): " << getPriceParcelRent() << LL_ENDL;
LL_INFOS() << "Energey Efficiency: " << mEnergyEfficiency << LL_ENDL;
}
void LLRegionEconomy::setBasePriceParcelClaimDefault(S32 val)
{
mBasePriceParcelClaimDefault = val;
if(mBasePriceParcelClaimActual == -1)
{
mBasePriceParcelClaimActual = val;
}
}
void LLRegionEconomy::setBasePriceParcelClaimActual(S32 val)
{
mBasePriceParcelClaimActual = val;
}
void LLRegionEconomy::setPriceParcelClaimFactor(F32 val)
{
mPriceParcelClaimFactor = val;
}
void LLRegionEconomy::setBasePriceParcelRent(S32 val)
{
mBasePriceParcelRent = val;
}
+157
View File
@@ -0,0 +1,157 @@
/**
* @file lleconomy.h
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLECONOMY_H
#define LL_LLECONOMY_H
#include "llsingleton.h"
#include <list>
class LLMessageSystem;
class LLVector3;
/**
* Register an observer to be notified of economy data updates coming from server.
*/
class LLEconomyObserver
{
public:
virtual ~LLEconomyObserver() {}
virtual void onEconomyDataChange() = 0;
};
class LLBaseEconomy
{
public:
LLBaseEconomy();
virtual ~LLBaseEconomy();
virtual void print();
void addObserver(LLEconomyObserver* observer);
void removeObserver(LLEconomyObserver* observer);
void notifyObservers();
static void processEconomyData(LLMessageSystem *msg, LLBaseEconomy* econ_data);
S32 calculateTeleportCost(F32 distance) const;
S32 calculateLightRent(const LLVector3& object_size) const;
S32 getObjectCount() const { return mObjectCount; }
S32 getObjectCapacity() const { return mObjectCapacity; }
S32 getPriceObjectClaim() const { return mPriceObjectClaim; }
S32 getPricePublicObjectDecay() const { return mPricePublicObjectDecay; }
S32 getPricePublicObjectDelete() const { return mPricePublicObjectDelete; }
S32 getPricePublicObjectRelease() const { return mPriceObjectClaim - mPricePublicObjectDelete; }
S32 getPriceEnergyUnit() const { return mPriceEnergyUnit; }
S32 getPriceUpload() const { return mPriceUpload; }
S32 getPriceRentLight() const { return mPriceRentLight; }
S32 getTeleportMinPrice() const { return mTeleportMinPrice; }
F32 getTeleportPriceExponent() const { return mTeleportPriceExponent; }
S32 getPriceGroupCreate() const { return mPriceGroupCreate; }
void setObjectCount(S32 val) { mObjectCount = val; }
void setObjectCapacity(S32 val) { mObjectCapacity = val; }
void setPriceObjectClaim(S32 val) { mPriceObjectClaim = val; }
void setPricePublicObjectDecay(S32 val) { mPricePublicObjectDecay = val; }
void setPricePublicObjectDelete(S32 val) { mPricePublicObjectDelete = val; }
void setPriceEnergyUnit(S32 val) { mPriceEnergyUnit = val; }
void setPriceUpload(S32 val) { mPriceUpload = val; }
void setPriceRentLight(S32 val) { mPriceRentLight = val; }
void setTeleportMinPrice(S32 val) { mTeleportMinPrice = val; }
void setTeleportPriceExponent(F32 val) { mTeleportPriceExponent = val; }
void setPriceGroupCreate(S32 val) { mPriceGroupCreate = val; }
private:
S32 mObjectCount;
S32 mObjectCapacity;
S32 mPriceObjectClaim; // per primitive
S32 mPricePublicObjectDecay; // per primitive
S32 mPricePublicObjectDelete; // per primitive
S32 mPriceEnergyUnit;
S32 mPriceUpload;
S32 mPriceRentLight;
S32 mTeleportMinPrice;
F32 mTeleportPriceExponent;
S32 mPriceGroupCreate;
std::list<LLEconomyObserver*> mObservers;
};
class LLGlobalEconomy: public LLSingleton<LLGlobalEconomy>, public LLBaseEconomy
{
LLSINGLETON_EMPTY_CTOR(LLGlobalEconomy);
};
class LLRegionEconomy : public LLBaseEconomy
{
public:
LLRegionEconomy();
~LLRegionEconomy();
static void processEconomyData(LLMessageSystem *msg, void **user_data);
static void processEconomyDataRequest(LLMessageSystem *msg, void **user_data);
void print();
bool hasData() const;
F32 getPriceObjectRent() const { return mPriceObjectRent; }
F32 getPriceObjectScaleFactor() const {return mPriceObjectScaleFactor;}
F32 getEnergyEfficiency() const { return mEnergyEfficiency; }
S32 getPriceParcelClaim() const;
S32 getPriceParcelRent() const;
F32 getAreaOwned() const { return mAreaOwned; }
F32 getAreaTotal() const { return mAreaTotal; }
S32 getBasePriceParcelClaimActual() const { return mBasePriceParcelClaimActual; }
void setPriceObjectRent(F32 val) { mPriceObjectRent = val; }
void setPriceObjectScaleFactor(F32 val) { mPriceObjectScaleFactor = val; }
void setEnergyEfficiency(F32 val) { mEnergyEfficiency = val; }
void setBasePriceParcelClaimDefault(S32 val);
void setBasePriceParcelClaimActual(S32 val);
void setPriceParcelClaimFactor(F32 val);
void setBasePriceParcelRent(S32 val);
void setAreaOwned(F32 val) { mAreaOwned = val; }
void setAreaTotal(F32 val) { mAreaTotal = val; }
private:
F32 mPriceObjectRent;
F32 mPriceObjectScaleFactor;
F32 mEnergyEfficiency;
S32 mBasePriceParcelClaimDefault;
S32 mBasePriceParcelClaimActual;
F32 mPriceParcelClaimFactor;
S32 mBasePriceParcelRent;
F32 mAreaOwned;
F32 mAreaTotal;
};
#endif
+224
View File
@@ -0,0 +1,224 @@
/**
* @file llfoldertype.cpp
* @brief Implementatino of LLFolderType functionality.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llfoldertype.h"
#include "lldictionary.h"
#include "llmemory.h"
#include "llsingleton.h"
///----------------------------------------------------------------------------
/// Class LLFolderType
///----------------------------------------------------------------------------
struct FolderEntry : public LLDictionaryEntry
{
FolderEntry(const std::string &type_name, // 8 character limit!
bool is_protected, // can the viewer change categories of this type?
bool is_automatic, // always made before first login?
bool is_singleton // should exist as a unique copy under root
)
:
LLDictionaryEntry(type_name),
mIsProtected(is_protected),
mIsAutomatic(is_automatic),
mIsSingleton(is_singleton)
{
llassert(type_name.length() <= 8);
}
const bool mIsProtected;
const bool mIsAutomatic;
const bool mIsSingleton;
};
class LLFolderDictionary : public LLSingleton<LLFolderDictionary>,
public LLDictionary<LLFolderType::EType, FolderEntry>
{
LLSINGLETON(LLFolderDictionary);
protected:
virtual LLFolderType::EType notFound() const override
{
return LLFolderType::FT_NONE;
}
};
// Folder types
//
// PROTECTED means that folders of this type can't be moved, deleted
// or otherwise modified by the viewer.
//
// SINGLETON means that there should always be exactly one folder of
// this type, and it should be the root or a child of the root. This
// is true for most types of folders.
//
// AUTOMATIC means that a copy of this folder should be created under
// the root before the user ever logs in, and should never be created
// from the viewer. A missing AUTOMATIC folder should be treated as a
// fatal error by the viewer, since it indicates either corrupted
// inventory or a failure in the inventory services.
//
LLFolderDictionary::LLFolderDictionary()
{
// TYPE NAME, PROTECTED, AUTOMATIC, SINGLETON
addEntry(LLFolderType::FT_TEXTURE, new FolderEntry("texture", true, true, true));
addEntry(LLFolderType::FT_SOUND, new FolderEntry("sound", true, true, true));
addEntry(LLFolderType::FT_CALLINGCARD, new FolderEntry("callcard", true, true, false));
addEntry(LLFolderType::FT_LANDMARK, new FolderEntry("landmark", true, false, false));
addEntry(LLFolderType::FT_CLOTHING, new FolderEntry("clothing", true, true, true));
addEntry(LLFolderType::FT_OBJECT, new FolderEntry("object", true, true, true));
addEntry(LLFolderType::FT_NOTECARD, new FolderEntry("notecard", true, true, true));
addEntry(LLFolderType::FT_ROOT_INVENTORY, new FolderEntry("root_inv", true, true, true));
addEntry(LLFolderType::FT_LSL_TEXT, new FolderEntry("lsltext", true, true, true));
addEntry(LLFolderType::FT_BODYPART, new FolderEntry("bodypart", true, true, true));
addEntry(LLFolderType::FT_TRASH, new FolderEntry("trash", true, false, true));
addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, new FolderEntry("snapshot", true, true, true));
addEntry(LLFolderType::FT_LOST_AND_FOUND, new FolderEntry("lstndfnd", true, true, true));
addEntry(LLFolderType::FT_ANIMATION, new FolderEntry("animatn", true, true, true));
addEntry(LLFolderType::FT_GESTURE, new FolderEntry("gesture", true, true, true));
addEntry(LLFolderType::FT_FAVORITE, new FolderEntry("favorite", true, false, true));
for (S32 ensemble_num = S32(LLFolderType::FT_ENSEMBLE_START); ensemble_num <= S32(LLFolderType::FT_ENSEMBLE_END); ensemble_num++)
{
addEntry(LLFolderType::EType(ensemble_num), new FolderEntry("ensemble", false, false, false)); // Not used
}
addEntry(LLFolderType::FT_CURRENT_OUTFIT, new FolderEntry("current", true, false, true));
addEntry(LLFolderType::FT_OUTFIT, new FolderEntry("outfit", false, false, false));
addEntry(LLFolderType::FT_MY_OUTFITS, new FolderEntry("my_otfts", true, false, true));
addEntry(LLFolderType::FT_MESH, new FolderEntry("mesh", true, false, false)); // Not used?
addEntry(LLFolderType::FT_INBOX, new FolderEntry("inbox", true, false, true));
addEntry(LLFolderType::FT_OUTBOX, new FolderEntry("outbox", false, false, false)); // <FS:Ansariel> Make obsolete Merchant Outbox folder deletable
addEntry(LLFolderType::FT_BASIC_ROOT, new FolderEntry("basic_rt", true, false, false));
addEntry(LLFolderType::FT_MARKETPLACE_LISTINGS, new FolderEntry("merchant", false, false, false));
addEntry(LLFolderType::FT_MARKETPLACE_STOCK, new FolderEntry("stock", false, false, false));
addEntry(LLFolderType::FT_MARKETPLACE_VERSION, new FolderEntry("version", false, false, false));
addEntry(LLFolderType::FT_SETTINGS, new FolderEntry("settings", true, false, true));
addEntry(LLFolderType::FT_MATERIAL, new FolderEntry("material", true, false, true));
addEntry(LLFolderType::FT_MY_SUITCASE, new FolderEntry("suitcase", true, false, true)); // <FS:Ansariel> OpenSim HG-support
addEntry(LLFolderType::FT_NONE, new FolderEntry("-1", false, false, false));
};
// static
LLFolderType::EType LLFolderType::lookup(const std::string& name)
{
return LLFolderDictionary::getInstance()->lookup(name);
}
// static
const std::string &LLFolderType::lookup(LLFolderType::EType folder_type)
{
const FolderEntry *entry = LLFolderDictionary::getInstance()->lookup(folder_type);
if (entry)
{
return entry->mName;
}
else
{
return badLookup();
}
}
// static
// Only plain folders and a few other types aren't protected. "Protected" means
// you can't move, deleted, or change certain properties such as their type.
bool LLFolderType::lookupIsProtectedType(EType folder_type)
{
const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
const FolderEntry *entry = dict->lookup(folder_type);
if (entry)
{
return entry->mIsProtected;
}
return true;
}
// static
// Is this folder type automatically created outside the viewer?
bool LLFolderType::lookupIsAutomaticType(EType folder_type)
{
const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
const FolderEntry *entry = dict->lookup(folder_type);
if (entry)
{
return entry->mIsAutomatic;
}
return true;
}
// static
// Should this folder always exist as a single copy under (or as) the root?
bool LLFolderType::lookupIsSingletonType(EType folder_type)
{
const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
const FolderEntry *entry = dict->lookup(folder_type);
if (entry)
{
return entry->mIsSingleton;
}
return true;
}
// static
bool LLFolderType::lookupIsEnsembleType(EType folder_type)
{
return (folder_type >= FT_ENSEMBLE_START &&
folder_type <= FT_ENSEMBLE_END);
}
// static
LLAssetType::EType LLFolderType::folderTypeToAssetType(LLFolderType::EType folder_type)
{
if (LLAssetType::lookup(LLAssetType::EType(folder_type)) == LLAssetType::BADLOOKUP)
{
LL_WARNS() << "Converting to unknown asset type " << folder_type << LL_ENDL;
}
return (LLAssetType::EType)folder_type;
}
// static
LLFolderType::EType LLFolderType::assetTypeToFolderType(LLAssetType::EType asset_type)
{
if (LLFolderType::lookup(LLFolderType::EType(asset_type)) == LLFolderType::badLookup())
{
LL_WARNS() << "Converting to unknown folder type " << asset_type << LL_ENDL;
}
return (LLFolderType::EType)asset_type;
}
// static
const std::string &LLFolderType::badLookup()
{
static const std::string sBadLookup = "llfoldertype_bad_lookup";
return sBadLookup;
}
+131
View File
@@ -0,0 +1,131 @@
/**
* @file llfoldertype.h
* @brief Declaration of LLFolderType.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLFOLDERTYPE_H
#define LL_LLFOLDERTYPE_H
#include <string>
#include "llassettype.h"
// This class handles folder types (similar to assettype, except for folders)
// and operations on those.
class LL_COMMON_API LLFolderType
{
public:
// ! BACKWARDS COMPATIBILITY ! Folder type enums must match asset type enums.
enum EType
{
FT_TEXTURE = 0,
FT_SOUND = 1,
FT_CALLINGCARD = 2,
FT_LANDMARK = 3,
FT_CLOTHING = 5,
FT_OBJECT = 6,
FT_NOTECARD = 7,
FT_ROOT_INVENTORY = 8,
// We'd really like to change this to 9 since AT_CATEGORY is 8,
// but "My Inventory" has been type 8 for a long time.
FT_LSL_TEXT = 10,
FT_BODYPART = 13,
FT_TRASH = 14,
FT_SNAPSHOT_CATEGORY = 15,
FT_LOST_AND_FOUND = 16,
FT_ANIMATION = 20,
FT_GESTURE = 21,
FT_FAVORITE = 23,
FT_ENSEMBLE_START = 26,
FT_ENSEMBLE_END = 45,
// This range is reserved for special clothing folder types.
FT_CURRENT_OUTFIT = 46,
FT_OUTFIT = 47,
FT_MY_OUTFITS = 48,
FT_MESH = 49,
FT_INBOX = 50,
FT_OUTBOX = 51,
FT_BASIC_ROOT = 52,
FT_MARKETPLACE_LISTINGS = 53,
FT_MARKETPLACE_STOCK = 54,
FT_MARKETPLACE_VERSION = 55, // Note: We actually *never* create folders with that type. This is used for icon override only.
FT_SETTINGS = 56,
FT_MATERIAL = 57,
// <FS:Ansariel> Folder types for our own virtual system folders
FT_FIRESTORM = 58,
FT_PHOENIX = 59,
FT_RLV = 60,
// </FS:Ansariel> Folder types for our own virtual system folders
FT_MY_SUITCASE = 100, // <FS:Ansariel> OpenSim HG-support
FT_COUNT,
FT_NONE = -1
// When adding, see note at bottom of LLAssetType::Etype
};
static EType lookup(const std::string& type_name);
static const std::string& lookup(EType folder_type);
static bool lookupIsProtectedType(EType folder_type);
static bool lookupIsAutomaticType(EType folder_type);
static bool lookupIsSingletonType(EType folder_type);
static bool lookupIsEnsembleType(EType folder_type);
static LLAssetType::EType folderTypeToAssetType(LLFolderType::EType folder_type);
static LLFolderType::EType assetTypeToFolderType(LLAssetType::EType asset_type);
static const std::string& badLookup(); // error string when a lookup fails
protected:
LLFolderType() {}
~LLFolderType() {}
};
#endif // LL_LLFOLDERTYPE_H
File diff suppressed because it is too large Load Diff
+293
View File
@@ -0,0 +1,293 @@
/**
* @file llinventory.h
* @brief LLInventoryItem and LLInventoryCategory class declaration.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLINVENTORY_H
#define LL_LLINVENTORY_H
#include "llfoldertype.h"
#include "llinventorytype.h"
#include "llpermissions.h"
#include "llrefcount.h"
#include "llsaleinfo.h"
#include "llsd.h"
#include "lluuid.h"
#include "lltrace.h"
class LLMessageSystem;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryObject
//
// Base class for anything in the user's inventory. Handles the common code
// between items and categories.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryObject : public LLRefCount
{
public:
typedef std::list<LLPointer<LLInventoryObject> > object_list_t;
typedef std::list<LLConstPointer<LLInventoryObject> > const_object_list_t;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
public:
LLInventoryObject();
LLInventoryObject(const LLUUID& uuid,
const LLUUID& parent_uuid,
LLAssetType::EType type,
const std::string& name);
void copyObject(const LLInventoryObject* other); // LLRefCount requires custom copy
protected:
virtual ~LLInventoryObject();
//--------------------------------------------------------------------
// Accessors
//--------------------------------------------------------------------
public:
virtual const LLUUID& getUUID() const; // inventoryID that this item points to
virtual const LLUUID& getLinkedUUID() const; // inventoryID that this item points to, else this item's inventoryID
const LLUUID& getParentUUID() const;
virtual const LLUUID& getThumbnailUUID() const;
virtual const std::string& getName() const;
virtual LLAssetType::EType getType() const;
LLAssetType::EType getActualType() const; // bypasses indirection for linked items
bool getIsLinkType() const;
virtual time_t getCreationDate() const;
//--------------------------------------------------------------------
// Mutators
// Will not call updateServer
//--------------------------------------------------------------------
public:
void setUUID(const LLUUID& new_uuid);
virtual void rename(const std::string& new_name);
void setParent(const LLUUID& new_parent);
virtual void setThumbnailUUID(const LLUUID& thumbnail_uuid);
void setType(LLAssetType::EType type);
virtual void setCreationDate(time_t creation_date_utc); // only stored for items
// in place correction for inventory name string
static void correctInventoryName(std::string& name);
//--------------------------------------------------------------------
// File Support
// Implemented here so that a minimal information set can be transmitted
// between simulator and viewer.
//--------------------------------------------------------------------
virtual bool importLegacyStream(std::istream& input_stream);
virtual bool exportLegacyStream(std::ostream& output_stream, bool include_asset_key = true) const;
virtual void updateParentOnServer(bool) const;
virtual void updateServer(bool) const;
//--------------------------------------------------------------------
// Member Variables
//--------------------------------------------------------------------
protected:
LLUUID mUUID;
LLUUID mParentUUID; // Parent category. Root categories have LLUUID::NULL.
LLUUID mThumbnailUUID;
LLAssetType::EType mType;
std::string mName;
time_t mCreationDate; // seconds from 1/1/1970, UTC
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryItem
//
// An item in the current user's inventory.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryItem : public LLInventoryObject
{
public:
typedef std::vector<LLPointer<LLInventoryItem> > item_array_t;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
public:
LLInventoryItem(const LLUUID& uuid,
const LLUUID& parent_uuid,
const LLPermissions& permissions,
const LLUUID& asset_uuid,
LLAssetType::EType type,
LLInventoryType::EType inv_type,
const std::string& name,
const std::string& desc,
const LLSaleInfo& sale_info,
U32 flags,
S32 creation_date_utc);
LLInventoryItem();
// Create a copy of an inventory item from a pointer to another item
// Note: Because InventoryItems are ref counted, reference copy (a = b)
// is prohibited
LLInventoryItem(const LLInventoryItem* other);
virtual void copyItem(const LLInventoryItem* other); // LLRefCount requires custom copy
void generateUUID() { mUUID.generate(); }
protected:
~LLInventoryItem(); // ref counted
//--------------------------------------------------------------------
// Accessors
//--------------------------------------------------------------------
public:
virtual const LLUUID& getLinkedUUID() const;
virtual const LLPermissions& getPermissions() const;
virtual const LLUUID& getCreatorUUID() const;
virtual const LLUUID& getAssetUUID() const;
virtual const std::string& getDescription() const;
virtual const std::string& getActualDescription() const; // Does not follow links
virtual const LLSaleInfo& getSaleInfo() const;
virtual LLInventoryType::EType getInventoryType() const;
virtual U32 getFlags() const;
virtual time_t getCreationDate() const;
virtual U32 getCRC32() const; // really more of a checksum.
//--------------------------------------------------------------------
// Mutators
// Will not call updateServer and will never fail
// (though it may correct to sane values)
//--------------------------------------------------------------------
public:
void setAssetUUID(const LLUUID& asset_id);
static void correctInventoryDescription(std::string& name);
void setDescription(const std::string& new_desc);
void setSaleInfo(const LLSaleInfo& sale_info);
void setPermissions(const LLPermissions& perm);
void setInventoryType(LLInventoryType::EType inv_type);
void setFlags(U32 flags);
void setCreator(const LLUUID& creator); // only used for calling cards
// Check for changes in permissions masks and sale info
// and set the corresponding bits in mFlags.
void accumulatePermissionSlamBits(const LLInventoryItem& old_item);
// Put this inventory item onto the current outgoing mesage.
// Assumes you have already called nextBlock().
virtual void packMessage(LLMessageSystem* msg) const;
// Returns true if the inventory item came through the network correctly.
// Uses a simple crc check which is defeatable, but we want to detect
// network mangling somehow.
virtual bool unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
//--------------------------------------------------------------------
// File Support
//--------------------------------------------------------------------
public:
virtual bool importLegacyStream(std::istream& input_stream);
virtual bool exportLegacyStream(std::ostream& output_stream, bool include_asset_key = true) const;
//--------------------------------------------------------------------
// Helper Functions
//--------------------------------------------------------------------
public:
LLSD asLLSD() const;
void asLLSD( LLSD& sd ) const;
bool fromLLSD(const LLSD& sd, bool is_new = true);
//--------------------------------------------------------------------
// Member Variables
//--------------------------------------------------------------------
protected:
LLPermissions mPermissions;
LLUUID mAssetUUID;
std::string mDescription;
LLSaleInfo mSaleInfo;
LLInventoryType::EType mInventoryType;
U32 mFlags;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryCategory
//
// A category/folder of inventory items. Users come with a set of default
// categories, and can create new ones as needed.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryCategory : public LLInventoryObject
{
public:
typedef std::vector<LLPointer<LLInventoryCategory> > cat_array_t;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
public:
LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
LLFolderType::EType preferred_type,
const std::string& name);
LLInventoryCategory();
LLInventoryCategory(const LLInventoryCategory* other);
void copyCategory(const LLInventoryCategory* other); // LLRefCount requires custom copy
protected:
virtual ~LLInventoryCategory();
//--------------------------------------------------------------------
// Accessors And Mutators
//--------------------------------------------------------------------
public:
LLFolderType::EType getPreferredType() const;
void setPreferredType(LLFolderType::EType type);
LLSD asLLSD() const;
LLSD asAISCreateCatLLSD() const;
bool fromLLSD(const LLSD& sd);
//--------------------------------------------------------------------
// Messaging
//--------------------------------------------------------------------
public:
virtual void packMessage(LLMessageSystem* msg) const;
virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
//--------------------------------------------------------------------
// File Support
//--------------------------------------------------------------------
public:
virtual bool importLegacyStream(std::istream& input_stream);
virtual bool exportLegacyStream(std::ostream& output_stream, bool include_asset_key = true) const;
LLSD exportLLSD() const;
bool importLLSD(const LLSD& cat_data);
//--------------------------------------------------------------------
// Member Variables
//--------------------------------------------------------------------
protected:
LLFolderType::EType mPreferredType; // Type that this category was "meant" to hold (although it may hold any type).
};
//-----------------------------------------------------------------------------
// Convertors
//
// These functions convert between structured data and an inventory
// item, appropriate for serialization.
//-----------------------------------------------------------------------------
LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
#endif // LL_LLINVENTORY_H
+31
View File
@@ -0,0 +1,31 @@
/**
* @file llinventorydefines.cpp
* @brief Implementation of the inventory defines.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llinventorydefines.h"
const U8 TASK_INVENTORY_ITEM_KEY = 0;
const U8 TASK_INVENTORY_ASSET_KEY = 1;
+101
View File
@@ -0,0 +1,101 @@
/**
* @file llinventorydefines.h
* @brief LLInventoryDefines
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLINVENTORYDEFINES_H
#define LL_LLINVENTORYDEFINES_H
// Consts for "key" field in the task inventory update message
extern const U8 TASK_INVENTORY_ITEM_KEY;
extern const U8 TASK_INVENTORY_ASSET_KEY;
// Max inventory buffer size (for use in packBinaryBucket)
enum
{
MAX_INVENTORY_BUFFER_SIZE = 1024
};
//--------------------------------------------------------------------
// Inventory item flags enums
// The shared flags at the top are shared among all inventory
// types. After that section, all values of flags are type
// dependent. The shared flags will start at 2^30 and work
// down while item type specific flags will start at 2^0 and work up.
//--------------------------------------------------------------------
class LLInventoryItemFlags
{
public:
enum EType
{
II_FLAGS_NONE = 0,
II_FLAGS_SHARED_SINGLE_REFERENCE = 0x40000000,
// The asset has only one reference in the system. If the
// inventory item is deleted, or the assetid updated, then we
// can remove the old reference.
II_FLAGS_LANDMARK_VISITED = 1,
II_FLAGS_OBJECT_SLAM_PERM = 0x100,
// Object permissions should have next owner perm be more
// restrictive on rez. We bump this into the second byte of the
// flags since the low byte is used to track attachment points.
II_FLAGS_OBJECT_SLAM_SALE = 0x1000,
// The object sale information has been changed.
II_FLAGS_OBJECT_PERM_OVERWRITE_BASE = 0x010000,
II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER = 0x020000,
II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP = 0x040000,
II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE = 0x080000,
II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER = 0x100000,
// Specify which permissions masks to overwrite
// upon rez. Normally, if no permissions slam (above) or
// overwrite flags are set, the asset's permissions are
// used and the inventory's permissions are ignored. If
// any of these flags are set, the inventory's permissions
// take precedence.
II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS = 0x200000,
// Whether a returned object is composed of multiple items.
II_FLAGS_SUBTYPE_MASK = 0x0000ff,
// Some items like Wearables and settings use the low order byte
// of flags to store the sub type of the inventory item.
// see LLWearableType::EType enumeration found in newview/llwearable.h
II_FLAGS_PERM_OVERWRITE_MASK = (II_FLAGS_OBJECT_SLAM_PERM |
II_FLAGS_OBJECT_SLAM_SALE |
II_FLAGS_OBJECT_PERM_OVERWRITE_BASE |
II_FLAGS_OBJECT_PERM_OVERWRITE_OWNER |
II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP |
II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE |
II_FLAGS_OBJECT_PERM_OVERWRITE_NEXT_OWNER),
// These bits need to be cleared whenever the asset_id is updated
// on a pre-existing inventory item (DEV-28098 and DEV-30997)
};
};
#endif // LL_LLINVENTORYDEFINES_H
+120
View File
@@ -0,0 +1,120 @@
/**
* @file llinventorysettings.cpp
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llinventorysettings.h"
#include "llinventorytype.h"
#include "llinventorydefines.h"
#include "lldictionary.h"
#include "llsingleton.h"
#include "llinvtranslationbrdg.h"
//=========================================================================
struct SettingsEntry : public LLDictionaryEntry
{
SettingsEntry(const std::string &name,
const std::string& default_new_name,
LLInventoryType::EIconName iconName) :
LLDictionaryEntry(name),
mDefaultNewName(default_new_name),
mLabel(name),
mIconName(iconName)
{
std::string transdname = LLSettingsType::getInstance()->mTranslator->getString(mLabel);
if (!transdname.empty())
{
mLabel = transdname;
}
// <FS:Ansariel> Name of newly created setting is not translated
transdname = LLSettingsType::getInstance()->mTranslator->getString(mDefaultNewName);
if (!transdname.empty())
{
mDefaultNewName = transdname;
}
// </FS:Ansariel>
}
std::string mLabel;
std::string mDefaultNewName; //keep mLabel for backward compatibility
LLInventoryType::EIconName mIconName;
};
class LLSettingsDictionary : public LLSingleton<LLSettingsDictionary>,
public LLDictionary<LLSettingsType::type_e, SettingsEntry>
{
LLSINGLETON(LLSettingsDictionary);
void initSingleton() override;
};
LLSettingsDictionary::LLSettingsDictionary()
{
}
void LLSettingsDictionary::initSingleton()
{
addEntry(LLSettingsType::ST_SKY, new SettingsEntry("sky", "New Sky", LLInventoryType::ICONNAME_SETTINGS_SKY));
addEntry(LLSettingsType::ST_WATER, new SettingsEntry("water", "New Water", LLInventoryType::ICONNAME_SETTINGS_WATER));
addEntry(LLSettingsType::ST_DAYCYCLE, new SettingsEntry("day", "New Day", LLInventoryType::ICONNAME_SETTINGS_DAY));
addEntry(LLSettingsType::ST_NONE, new SettingsEntry("none", "New Settings", LLInventoryType::ICONNAME_SETTINGS));
addEntry(LLSettingsType::ST_INVALID, new SettingsEntry("invalid", "New Settings", LLInventoryType::ICONNAME_SETTINGS));
}
//=========================================================================
LLSettingsType::LLSettingsType(LLTranslationBridge::ptr_t &trans)
{
mTranslator = trans;
}
LLSettingsType::~LLSettingsType()
{
mTranslator.reset();
}
LLSettingsType::type_e LLSettingsType::fromInventoryFlags(U32 flags)
{
return (LLSettingsType::type_e)(flags & LLInventoryItemFlags::II_FLAGS_SUBTYPE_MASK);
}
LLInventoryType::EIconName LLSettingsType::getIconName(LLSettingsType::type_e type)
{
const SettingsEntry *entry = LLSettingsDictionary::instance().lookup(type);
if (!entry)
return getIconName(ST_INVALID);
return entry->mIconName;
}
std::string LLSettingsType::getDefaultName(LLSettingsType::type_e type)
{
const SettingsEntry *entry = LLSettingsDictionary::instance().lookup(type);
if (!entry)
return getDefaultName(ST_INVALID);
return entry->mDefaultNewName;
}
+63
View File
@@ -0,0 +1,63 @@
/**
* @file llinventorysettings.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_INVENTORY_SETTINGS_H
#define LL_INVENTORY_SETTINGS_H
#include "llinventorytype.h"
#include "llinvtranslationbrdg.h"
#include "llsingleton.h"
class LLSettingsType : public LLParamSingleton<LLSettingsType>
{
LLSINGLETON(LLSettingsType, LLTranslationBridge::ptr_t &trans);
~LLSettingsType();
friend struct SettingsEntry;
public:
enum type_e
{
ST_SKY = 0,
ST_WATER = 1,
ST_DAYCYCLE = 2,
ST_INVALID = 255,
ST_NONE = -1
};
static type_e fromInventoryFlags(U32 flags);
static LLInventoryType::EIconName getIconName(type_e type);
static std::string getDefaultName(type_e type);
protected:
LLTranslationBridge::ptr_t mTranslator;
};
#endif
+247
View File
@@ -0,0 +1,247 @@
/**
* @file llinventorytype.cpp
* @brief Inventory item type, more specific than an asset type.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llinventorytype.h"
#include "lldictionary.h"
#include "llmemory.h"
#include "llsingleton.h"
static const std::string empty_string;
///----------------------------------------------------------------------------
/// Class LLInventoryType
///----------------------------------------------------------------------------
struct InventoryEntry : public LLDictionaryEntry
{
InventoryEntry(const std::string &name, // unlike asset type names, not limited to 8 characters; need not match asset type names
const std::string &human_name, // for decoding to human readable form; put any and as many printable characters you want in each one.
int num_asset_types = 0, ...)
:
LLDictionaryEntry(name),
mHumanName(human_name)
{
va_list argp;
va_start(argp, num_asset_types);
// Read in local textures
for (U8 i=0; i < num_asset_types; i++)
{
LLAssetType::EType t = (LLAssetType::EType)va_arg(argp,int);
mAssetTypes.push_back(t);
}
va_end(argp);
}
const std::string mHumanName;
typedef std::vector<LLAssetType::EType> asset_vec_t;
asset_vec_t mAssetTypes;
};
class LLInventoryDictionary : public LLSingleton<LLInventoryDictionary>,
public LLDictionary<LLInventoryType::EType, InventoryEntry>
{
LLSINGLETON(LLInventoryDictionary);
};
LLInventoryDictionary::LLInventoryDictionary()
{
addEntry(LLInventoryType::IT_TEXTURE, new InventoryEntry("texture", "texture", 1, LLAssetType::AT_TEXTURE));
addEntry(LLInventoryType::IT_SOUND, new InventoryEntry("sound", "sound", 1, LLAssetType::AT_SOUND));
addEntry(LLInventoryType::IT_CALLINGCARD, new InventoryEntry("callcard", "calling card", 1, LLAssetType::AT_CALLINGCARD));
addEntry(LLInventoryType::IT_LANDMARK, new InventoryEntry("landmark", "landmark", 1, LLAssetType::AT_LANDMARK));
addEntry(LLInventoryType::IT_OBJECT, new InventoryEntry("object", "object", 1, LLAssetType::AT_OBJECT));
addEntry(LLInventoryType::IT_NOTECARD, new InventoryEntry("notecard", "note card", 1, LLAssetType::AT_NOTECARD));
addEntry(LLInventoryType::IT_CATEGORY, new InventoryEntry("category", "folder" ));
addEntry(LLInventoryType::IT_ROOT_CATEGORY, new InventoryEntry("root", "root" ));
addEntry(LLInventoryType::IT_LSL, new InventoryEntry("script", "script", 2, LLAssetType::AT_LSL_TEXT, LLAssetType::AT_LSL_BYTECODE));
addEntry(LLInventoryType::IT_SNAPSHOT, new InventoryEntry("snapshot", "snapshot", 1, LLAssetType::AT_TEXTURE));
addEntry(LLInventoryType::IT_ATTACHMENT, new InventoryEntry("attach", "attachment", 1, LLAssetType::AT_OBJECT));
addEntry(LLInventoryType::IT_WEARABLE, new InventoryEntry("wearable", "wearable", 2, LLAssetType::AT_CLOTHING, LLAssetType::AT_BODYPART));
addEntry(LLInventoryType::IT_ANIMATION, new InventoryEntry("animation", "animation", 1, LLAssetType::AT_ANIMATION));
addEntry(LLInventoryType::IT_GESTURE, new InventoryEntry("gesture", "gesture", 1, LLAssetType::AT_GESTURE));
addEntry(LLInventoryType::IT_MESH, new InventoryEntry("mesh", "mesh", 1, LLAssetType::AT_MESH));
addEntry(LLInventoryType::IT_GLTF, new InventoryEntry("gltf", "gltf", 1, LLAssetType::AT_GLTF));
addEntry(LLInventoryType::IT_GLTF_BIN, new InventoryEntry("glbin", "glbin", 1, LLAssetType::AT_GLTF_BIN));
addEntry(LLInventoryType::IT_WIDGET, new InventoryEntry("widget", "widget", 1, LLAssetType::AT_WIDGET));
addEntry(LLInventoryType::IT_PERSON, new InventoryEntry("person", "person", 1, LLAssetType::AT_PERSON));
addEntry(LLInventoryType::IT_SETTINGS, new InventoryEntry("settings", "settings", 1, LLAssetType::AT_SETTINGS));
addEntry(LLInventoryType::IT_MATERIAL, new InventoryEntry("material", "render material", 1, LLAssetType::AT_MATERIAL));
}
// Maps asset types to the default inventory type for that kind of asset.
// Thus, "Lost and Found" is a "Category"
static const LLInventoryType::EType
DEFAULT_ASSET_FOR_INV_TYPE[LLAssetType::AT_COUNT] =
{
LLInventoryType::IT_TEXTURE, // 0 AT_TEXTURE
LLInventoryType::IT_SOUND, // 1 AT_SOUND
LLInventoryType::IT_CALLINGCARD, // 2 AT_CALLINGCARD
LLInventoryType::IT_LANDMARK, // 3 AT_LANDMARK
LLInventoryType::IT_LSL, // 4 AT_SCRIPT
LLInventoryType::IT_WEARABLE, // 5 AT_CLOTHING
LLInventoryType::IT_OBJECT, // 6 AT_OBJECT
LLInventoryType::IT_NOTECARD, // 7 AT_NOTECARD
LLInventoryType::IT_CATEGORY, // 8 AT_CATEGORY
LLInventoryType::IT_NONE, // 9 (null entry)
LLInventoryType::IT_LSL, // 10 AT_LSL_TEXT
LLInventoryType::IT_LSL, // 11 AT_LSL_BYTECODE
LLInventoryType::IT_TEXTURE, // 12 AT_TEXTURE_TGA
LLInventoryType::IT_WEARABLE, // 13 AT_BODYPART
LLInventoryType::IT_CATEGORY, // 14 AT_TRASH
LLInventoryType::IT_CATEGORY, // 15 AT_SNAPSHOT_CATEGORY
LLInventoryType::IT_CATEGORY, // 16 AT_LOST_AND_FOUND
LLInventoryType::IT_SOUND, // 17 AT_SOUND_WAV
LLInventoryType::IT_NONE, // 18 AT_IMAGE_TGA
LLInventoryType::IT_NONE, // 19 AT_IMAGE_JPEG
LLInventoryType::IT_ANIMATION, // 20 AT_ANIMATION
LLInventoryType::IT_GESTURE, // 21 AT_GESTURE
LLInventoryType::IT_NONE, // 22 AT_SIMSTATE
LLInventoryType::IT_NONE, // 23 AT_LINK
LLInventoryType::IT_NONE, // 24 AT_LINK_FOLDER
LLInventoryType::IT_NONE, // 25 AT_NONE
LLInventoryType::IT_NONE, // 26 AT_NONE
LLInventoryType::IT_NONE, // 27 AT_NONE
LLInventoryType::IT_NONE, // 28 AT_NONE
LLInventoryType::IT_NONE, // 29 AT_NONE
LLInventoryType::IT_NONE, // 30 AT_NONE
LLInventoryType::IT_NONE, // 31 AT_NONE
LLInventoryType::IT_NONE, // 32 AT_NONE
LLInventoryType::IT_NONE, // 33 AT_NONE
LLInventoryType::IT_NONE, // 34 AT_NONE
LLInventoryType::IT_NONE, // 35 AT_NONE
LLInventoryType::IT_NONE, // 36 AT_NONE
LLInventoryType::IT_NONE, // 37 AT_NONE
LLInventoryType::IT_NONE, // 38 AT_NONE
LLInventoryType::IT_NONE, // 39 AT_NONE
LLInventoryType::IT_WIDGET, // 40 AT_WIDGET
LLInventoryType::IT_NONE, // 41 AT_NONE
LLInventoryType::IT_NONE, // 42 AT_NONE
LLInventoryType::IT_NONE, // 43 AT_NONE
LLInventoryType::IT_NONE, // 44 AT_NONE
LLInventoryType::IT_PERSON, // 45 AT_PERSON
LLInventoryType::IT_NONE, // 46 AT_NONE
LLInventoryType::IT_NONE, // 47 AT_NONE
LLInventoryType::IT_NONE, // 48 AT_NONE
LLInventoryType::IT_MESH, // 49 AT_MESH
LLInventoryType::IT_NONE, // 50 AT_RESERVED_1
LLInventoryType::IT_NONE, // 51 AT_RESERVED_2
LLInventoryType::IT_NONE, // 52 AT_RESERVED_3
LLInventoryType::IT_NONE, // 53 AT_RESERVED_4
LLInventoryType::IT_NONE, // 54 AT_RESERVED_5
LLInventoryType::IT_NONE, // 55 AT_RESERVED_6
LLInventoryType::IT_SETTINGS, // 56 AT_SETTINGS
LLInventoryType::IT_MATERIAL, // 57 AT_MATERIAL
LLInventoryType::IT_GLTF, // 58 AT_GLTF
LLInventoryType::IT_GLTF_BIN, // 59 AT_GLTF_BIN
};
// static
const std::string &LLInventoryType::lookup(EType type)
{
const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
if (!entry) return empty_string;
return entry->mName;
}
// static
LLInventoryType::EType LLInventoryType::lookup(const std::string& name)
{
return LLInventoryDictionary::getInstance()->lookup(name);
}
// XUI:translate
// translation from a type to a human readable form.
// static
const std::string &LLInventoryType::lookupHumanReadable(EType type)
{
const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
if (!entry) return empty_string;
return entry->mHumanName;
}
// return the default inventory for the given asset type.
// static
LLInventoryType::EType LLInventoryType::defaultForAssetType(LLAssetType::EType asset_type)
{
if((asset_type >= 0) && (asset_type < LLAssetType::AT_COUNT))
{
return DEFAULT_ASSET_FOR_INV_TYPE[S32(asset_type)];
}
else
{
return IT_UNKNOWN;
}
}
// add any types that we don't want the user to be able to change permissions on.
// static
bool LLInventoryType::cannotRestrictPermissions(LLInventoryType::EType type)
{
switch(type)
{
case IT_CALLINGCARD:
case IT_LANDMARK:
return true;
default:
return false;
}
}
// Should show permissions that apply only to objects rezed in world.
bool LLInventoryType::showInWorldPermissions(LLInventoryType::EType type)
{
return (type != IT_SETTINGS);
}
bool inventory_and_asset_types_match(LLInventoryType::EType inventory_type,
LLAssetType::EType asset_type)
{
// Links can be of any inventory type.
if (LLAssetType::lookupIsLinkType(asset_type))
return true;
const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(inventory_type);
if (!entry) return false;
for (InventoryEntry::asset_vec_t::const_iterator iter = entry->mAssetTypes.begin();
iter != entry->mAssetTypes.end();
iter++)
{
const LLAssetType::EType type = (*iter);
if(type == asset_type)
{
return true;
}
}
return false;
}
+159
View File
@@ -0,0 +1,159 @@
/**
* @file llinventorytype.h
* @brief Inventory item type, more specific than an asset type.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LLINVENTORYTYPE_H
#define LLINVENTORYTYPE_H
#include "llassettype.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryType
//
// Class used to encapsulate operations around inventory type.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryType
{
public:
enum EType
{
IT_TEXTURE = 0,
IT_SOUND = 1,
IT_CALLINGCARD = 2,
IT_LANDMARK = 3,
//IT_SCRIPT = 4,
//IT_CLOTHING = 5,
IT_OBJECT = 6,
IT_NOTECARD = 7,
IT_CATEGORY = 8,
IT_ROOT_CATEGORY = 9,
IT_LSL = 10,
//IT_LSL_BYTECODE = 11,
//IT_TEXTURE_TGA = 12,
//IT_BODYPART = 13,
//IT_TRASH = 14,
IT_SNAPSHOT = 15,
//IT_LOST_AND_FOUND = 16,
IT_ATTACHMENT = 17,
IT_WEARABLE = 18,
IT_ANIMATION = 19,
IT_GESTURE = 20,
IT_MESH = 22,
IT_WIDGET = 23,
IT_PERSON = 24,
IT_SETTINGS = 25,
IT_MATERIAL = 26,
IT_GLTF = 27,
IT_GLTF_BIN = 28,
IT_COUNT = 29,
IT_UNKNOWN = 255,
IT_NONE = -1
};
enum EIconName
{
ICONNAME_TEXTURE,
ICONNAME_SOUND,
ICONNAME_CALLINGCARD_ONLINE,
ICONNAME_CALLINGCARD_OFFLINE,
ICONNAME_LANDMARK,
ICONNAME_LANDMARK_VISITED,
ICONNAME_SCRIPT,
ICONNAME_CLOTHING,
ICONNAME_OBJECT,
ICONNAME_OBJECT_MULTI,
ICONNAME_NOTECARD,
ICONNAME_BODYPART,
ICONNAME_SNAPSHOT,
ICONNAME_BODYPART_SHAPE,
ICONNAME_BODYPART_SKIN,
ICONNAME_BODYPART_HAIR,
ICONNAME_BODYPART_EYES,
ICONNAME_CLOTHING_SHIRT,
ICONNAME_CLOTHING_PANTS,
ICONNAME_CLOTHING_SHOES,
ICONNAME_CLOTHING_SOCKS,
ICONNAME_CLOTHING_JACKET,
ICONNAME_CLOTHING_GLOVES,
ICONNAME_CLOTHING_UNDERSHIRT,
ICONNAME_CLOTHING_UNDERPANTS,
ICONNAME_CLOTHING_SKIRT,
ICONNAME_CLOTHING_ALPHA,
ICONNAME_CLOTHING_TATTOO,
ICONNAME_CLOTHING_UNIVERSAL,
ICONNAME_ANIMATION,
ICONNAME_GESTURE,
ICONNAME_CLOTHING_PHYSICS,
ICONNAME_LINKITEM,
ICONNAME_LINKFOLDER,
ICONNAME_MESH,
ICONNAME_SETTINGS,
ICONNAME_SETTINGS_SKY,
ICONNAME_SETTINGS_WATER,
ICONNAME_SETTINGS_DAY,
ICONNAME_MATERIAL,
ICONNAME_INVALID,
ICONNAME_UNKNOWN,
ICONNAME_COUNT,
ICONNAME_NONE = -1
};
// machine transation between type and strings
static EType lookup(const std::string& name);
static const std::string &lookup(EType type);
// translation from a type to a human readable form.
static const std::string &lookupHumanReadable(EType type);
// return the default inventory for the given asset type.
static EType defaultForAssetType(LLAssetType::EType asset_type);
// true if this type cannot have restricted permissions.
static bool cannotRestrictPermissions(EType type);
static bool showInWorldPermissions(EType type);
private:
// don't instantiate or derive one of these objects
LLInventoryType( void );
~LLInventoryType( void );
};
// helper function that returns true if inventory type and asset type
// are potentially compatible. For example, an attachment must be an
// object, but a wearable can be a bodypart or clothing asset.
bool inventory_and_asset_types_match(LLInventoryType::EType inventory_type,
LLAssetType::EType asset_type);
#endif
+41
View File
@@ -0,0 +1,41 @@
/**
* @file llinvtranslationbrdg.h
* @brief Translation adapter for inventory.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_TRANSLATIONBRDG_H
#define LL_TRANSLATIONBRDG_H
class LLTranslationBridge
{
public:
typedef std::shared_ptr<LLTranslationBridge> ptr_t;
// clang needs this to be happy
virtual ~LLTranslationBridge() {}
virtual std::string getString(const std::string &xml_desc) = 0;
};
#endif
+322
View File
@@ -0,0 +1,322 @@
/**
* @file lllandmark.cpp
* @brief Landmark asset class
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lllandmark.h"
#include <errno.h>
#include "message.h"
#include "llregionhandle.h"
std::pair<LLUUID, U64> LLLandmark::mLocalRegion;
LLLandmark::region_map_t LLLandmark::mRegions;
LLLandmark::region_callback_map_t LLLandmark::sRegionCallbackMap;
LLLandmark::LLLandmark() :
mGlobalPositionKnown(false)
{
}
LLLandmark::LLLandmark(const LLVector3d& pos) :
mGlobalPositionKnown(true),
mGlobalPos( pos )
{
}
bool LLLandmark::getGlobalPos(LLVector3d& pos)
{
if(mGlobalPositionKnown)
{
pos = mGlobalPos;
}
else if(mRegionID.notNull())
{
F32 g_x = -1.0f;
F32 g_y = -1.0f;
if(mRegionID == mLocalRegion.first)
{
from_region_handle(mLocalRegion.second, &g_x, &g_y);
}
else
{
region_map_t::iterator it = mRegions.find(mRegionID);
if(it != mRegions.end())
{
from_region_handle((*it).second.mRegionHandle, &g_x, &g_y);
}
}
if((g_x > 0.f) && (g_y > 0.f))
{
pos.mdV[0] = g_x + mRegionPos.mV[0];
pos.mdV[1] = g_y + mRegionPos.mV[1];
pos.mdV[2] = mRegionPos.mV[2];
setGlobalPos(pos);
}
}
return mGlobalPositionKnown;
}
void LLLandmark::setGlobalPos(const LLVector3d& pos)
{
mGlobalPos = pos;
mGlobalPositionKnown = true;
}
bool LLLandmark::getRegionID(LLUUID& region_id)
{
if(mRegionID.notNull())
{
region_id = mRegionID;
return true;
}
return false;
}
LLVector3 LLLandmark::getRegionPos() const
{
return mRegionPos;
}
// static
LLLandmark* LLLandmark::constructFromString(const char *buffer, const S32 buffer_size)
{
S32 chars_read = 0;
S32 chars_read_total = 0;
S32 count = 0;
U32 version = 0;
bool bad_block = false;
LLLandmark* result = NULL;
// read version
count = sscanf( buffer, "Landmark version %u\n%n", &version, &chars_read );
chars_read_total += chars_read;
if (count != 1
|| chars_read_total >= buffer_size)
{
bad_block = true;
}
if (!bad_block)
{
switch (version)
{
case 1:
{
LLVector3d pos;
// read position
count = sscanf(buffer + chars_read_total, "position %lf %lf %lf\n%n", pos.mdV + VX, pos.mdV + VY, pos.mdV + VZ, &chars_read);
if (count != 3)
{
bad_block = true;
}
else
{
LL_DEBUGS("Landmark") << "Landmark read: " << pos << LL_ENDL;
result = new LLLandmark(pos);
}
break;
}
case 2:
{
// *NOTE: Changing the buffer size will require changing the
// scanf call below.
char region_id_str[MAX_STRING];
LLVector3 pos;
LLUUID region_id;
count = sscanf( buffer + chars_read_total,
"region_id %254s\n%n",
region_id_str,
&chars_read);
chars_read_total += chars_read;
if (count != 1
|| chars_read_total >= buffer_size
|| !LLUUID::validate(region_id_str))
{
bad_block = true;
}
if (!bad_block)
{
region_id.set(region_id_str);
if (region_id.isNull())
{
bad_block = true;
}
}
if (!bad_block)
{
count = sscanf(buffer + chars_read_total, "local_pos %f %f %f\n%n", pos.mV + VX, pos.mV + VY, pos.mV + VZ, &chars_read);
if (count != 3)
{
bad_block = true;
}
else
{
result = new LLLandmark;
result->mRegionID = region_id;
result->mRegionPos = pos;
}
}
break;
}
default:
{
LL_INFOS("Landmark") << "Encountered Unknown landmark version " << version << LL_ENDL;
break;
}
}
}
if (bad_block)
{
LL_INFOS("Landmark") << "Bad Landmark Asset: bad _DATA_ block." << LL_ENDL;
}
return result;
}
// static
void LLLandmark::registerCallbacks(LLMessageSystem* msg)
{
msg->setHandlerFunc("RegionIDAndHandleReply", &processRegionIDAndHandle);
}
// static
void LLLandmark::requestRegionHandle(
LLMessageSystem* msg,
const LLHost& upstream_host,
const LLUUID& region_id,
region_handle_callback_t callback)
{
if(region_id.isNull())
{
// don't bother with checking - it's 0.
LL_DEBUGS("Landmark") << "requestRegionHandle: null" << LL_ENDL;
if(callback)
{
const U64 U64_ZERO = 0;
callback(region_id, U64_ZERO);
}
}
else
{
if(region_id == mLocalRegion.first)
{
LL_DEBUGS("Landmark") << "requestRegionHandle: local" << LL_ENDL;
if(callback)
{
callback(region_id, mLocalRegion.second);
}
}
else
{
region_map_t::iterator it = mRegions.find(region_id);
if(it == mRegions.end())
{
LL_DEBUGS("Landmark") << "requestRegionHandle: upstream" << LL_ENDL;
if(callback)
{
region_callback_map_t::value_type vt(region_id, callback);
sRegionCallbackMap.insert(vt);
}
LL_DEBUGS("Landmark") << "Landmark requesting information about: "
<< region_id << LL_ENDL;
msg->newMessage("RegionHandleRequest");
msg->nextBlock("RequestBlock");
msg->addUUID("RegionID", region_id);
msg->sendReliable(upstream_host);
}
else if(callback)
{
// we have the answer locally - just call the callack.
LL_DEBUGS("Landmark") << "requestRegionHandle: ready" << LL_ENDL;
callback(region_id, (*it).second.mRegionHandle);
}
}
}
// As good a place as any to expire old entries.
expireOldEntries();
}
// static
void LLLandmark::setRegionHandle(const LLUUID& region_id, U64 region_handle)
{
mLocalRegion.first = region_id;
mLocalRegion.second = region_handle;
}
// static
void LLLandmark::processRegionIDAndHandle(LLMessageSystem* msg, void**)
{
LLUUID region_id;
msg->getUUID("ReplyBlock", "RegionID", region_id);
mRegions.erase(region_id);
CacheInfo info;
const F32 CACHE_EXPIRY_SECONDS = 60.0f * 10.0f; // ten minutes
info.mTimer.setTimerExpirySec(CACHE_EXPIRY_SECONDS);
msg->getU64("ReplyBlock", "RegionHandle", info.mRegionHandle);
region_map_t::value_type vt(region_id, info);
mRegions.insert(vt);
#if LL_DEBUG
U32 grid_x, grid_y;
grid_from_region_handle(info.mRegionHandle, &grid_x, &grid_y);
LL_DEBUGS() << "Landmark got reply for region: " << region_id << " "
<< grid_x << "," << grid_y << LL_ENDL;
#endif
// make all the callbacks here.
region_callback_map_t::iterator it;
while((it = sRegionCallbackMap.find(region_id)) != sRegionCallbackMap.end())
{
(*it).second(region_id, info.mRegionHandle);
sRegionCallbackMap.erase(it);
}
}
// static
void LLLandmark::expireOldEntries()
{
for(region_map_t::iterator it = mRegions.begin(); it != mRegions.end(); )
{
if((*it).second.mTimer.hasExpired())
{
mRegions.erase(it++);
}
else
{
++it;
}
}
}
+108
View File
@@ -0,0 +1,108 @@
/**
* @file lllandmark.h
* @brief Landmark asset class
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLLANDMARK_H
#define LL_LLLANDMARK_H
#include <map>
#include <boost/function.hpp>
#include "llframetimer.h"
#include "lluuid.h"
#include "v3dmath.h"
class LLMessageSystem;
class LLHost;
class LLLandmark
{
public:
// for calling back interested parties when a region handle comes back.
typedef boost::function<void(const LLUUID& region_id, const U64& region_handle)> region_handle_callback_t;
~LLLandmark() {}
// returns true if the position is known.
bool getGlobalPos(LLVector3d& pos);
// setter used in conjunction if more information needs to be
// collected from the server.
void setGlobalPos(const LLVector3d& pos);
// return true if the region is known
bool getRegionID(LLUUID& region_id);
// return the local coordinates if known
LLVector3 getRegionPos() const;
// constructs a new LLLandmark from a string
// return NULL if there's an error
static LLLandmark* constructFromString(const char *buffer, const S32 buffer_size);
// register callbacks that this class handles
static void registerCallbacks(LLMessageSystem* msg);
// request information about region_id to region_handle.Pass in a
// callback pointer which will be erase but NOT deleted after the
// callback is made. This function may call into the message
// system to get the information.
static void requestRegionHandle(
LLMessageSystem* msg,
const LLHost& upstream_host,
const LLUUID& region_id,
region_handle_callback_t callback);
// Call this method to create a lookup for this region. This
// simplifies a lot of the code.
static void setRegionHandle(const LLUUID& region_id, U64 region_handle);
private:
LLLandmark();
LLLandmark(const LLVector3d& pos);
static void processRegionIDAndHandle(LLMessageSystem* msg, void**);
static void expireOldEntries();
private:
LLUUID mRegionID;
LLVector3 mRegionPos;
bool mGlobalPositionKnown;
LLVector3d mGlobalPos;
struct CacheInfo
{
U64 mRegionHandle;
LLFrameTimer mTimer;
};
static std::pair<LLUUID, U64> mLocalRegion;
typedef std::map<LLUUID, CacheInfo> region_map_t;
static region_map_t mRegions;
typedef std::multimap<LLUUID, region_handle_callback_t> region_callback_map_t;
static region_callback_map_t sRegionCallbackMap;
};
#endif
+289
View File
@@ -0,0 +1,289 @@
/**
* @file llnotecard.cpp
* @brief LLNotecard class definition
*
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llnotecard.h"
#include "llstreamtools.h"
LLNotecard::LLNotecard(S32 max_text)
: mMaxText(max_text),
mVersion(0),
mEmbeddedVersion(0)
{
}
LLNotecard::~LLNotecard()
{
}
bool LLNotecard::importEmbeddedItemsStream(std::istream& str)
{
// Version 1 format:
// LLEmbeddedItems version 1
// {
// count <number of entries being used and not deleted>
// {
// ext char index <index>
// <InventoryItem chunk>
// }
// }
S32 i;
S32 count = 0;
str >> std::ws >> "LLEmbeddedItems version" >> mEmbeddedVersion >> "\n";
if (str.fail())
{
LL_WARNS() << "Invalid Linden text file header" << LL_ENDL;
goto import_file_failed;
}
if( 1 != mEmbeddedVersion )
{
LL_WARNS() << "Invalid LLEmbeddedItems version: " << mEmbeddedVersion << LL_ENDL;
goto import_file_failed;
}
str >> std::ws >> "{\n";
if(str.fail())
{
LL_WARNS() << "Invalid Linden text file format: missing {" << LL_ENDL;
goto import_file_failed;
}
str >> std::ws >> "count " >> count >> "\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems count" << LL_ENDL;
goto import_file_failed;
}
if((count < 0))
{
LL_WARNS() << "Invalid LLEmbeddedItems count value: " << count << LL_ENDL;
goto import_file_failed;
}
for(i = 0; i < count; i++)
{
str >> std::ws >> "{\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems file format: missing {" << LL_ENDL;
goto import_file_failed;
}
U32 index = 0;
str >> std::ws >> "ext char index " >> index >> "\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems file format: missing ext char index" << LL_ENDL;
goto import_file_failed;
}
str >> std::ws >> "inv_item\t0\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems file format: missing inv_item" << LL_ENDL;
goto import_file_failed;
}
LLPointer<LLInventoryItem> item = new LLInventoryItem;
if (!item->importLegacyStream(str))
{
LL_INFOS() << "notecard import failed" << LL_ENDL;
goto import_file_failed;
}
mItems.push_back(item);
str >> std::ws >> "}\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems file format: missing }" << LL_ENDL;
goto import_file_failed;
}
}
str >> std::ws >> "}\n";
if(str.fail())
{
LL_WARNS() << "Invalid LLEmbeddedItems file format: missing }" << LL_ENDL;
goto import_file_failed;
}
return true;
import_file_failed:
return false;
}
bool LLNotecard::importStream(std::istream& str)
{
// Version 1 format:
// Linden text version 1
// {
// <EmbeddedItemList chunk>
// Text length
// <ASCII text; 0x80 | index = embedded item>
// }
// Version 2 format: (NOTE: Imports identically to version 1)
// Linden text version 2
// {
// <EmbeddedItemList chunk>
// Text length
// <UTF8 text; FIRST_EMBEDDED_CHAR + index = embedded item>
// }
str >> std::ws >> "Linden text version " >> mVersion >> "\n";
if(str.fail())
{
LL_WARNS() << "Invalid Linden text file header " << LL_ENDL;
return false;
}
if( 1 != mVersion && 2 != mVersion)
{
LL_WARNS() << "Invalid Linden text file version: " << mVersion << LL_ENDL;
return false;
}
str >> std::ws >> "{\n";
if(str.fail())
{
LL_WARNS() << "Invalid Linden text file format" << LL_ENDL;
return false;
}
if(!importEmbeddedItemsStream(str))
{
return false;
}
char line_buf[STD_STRING_BUF_SIZE]; /* Flawfinder: ignore */
str.getline(line_buf, STD_STRING_BUF_SIZE);
if(str.fail())
{
LL_WARNS() << "Invalid Linden text length field" << LL_ENDL;
return false;
}
line_buf[STD_STRING_STR_LEN] = '\0';
S32 text_len = 0;
if( 1 != sscanf(line_buf, "Text length %d", &text_len) )
{
LL_WARNS() << "Invalid Linden text length field" << LL_ENDL;
return false;
}
if(text_len > mMaxText || text_len < 0)
{
LL_WARNS() << "Invalid Linden text length: " << text_len << LL_ENDL;
return false;
}
bool success = true;
char* text = new char[text_len + 1];
fullread(str, text, text_len);
if(str.fail())
{
LL_WARNS() << "Invalid Linden text: text shorter than text length: " << text_len << LL_ENDL;
success = false;
}
text[text_len] = '\0';
if(success)
{
// Actually set the text
mText = std::string(text);
}
delete[] text;
return success;
}
////////////////////////////////////////////////////////////////////////////
bool LLNotecard::exportEmbeddedItemsStream( std::ostream& out_stream )
{
out_stream << "LLEmbeddedItems version 1\n";
out_stream << "{\n";
out_stream << llformat("count %d\n", mItems.size() );
S32 idx = 0;
for (std::vector<LLPointer<LLInventoryItem> >::iterator iter = mItems.begin();
iter != mItems.end(); ++iter)
{
LLInventoryItem* item = *iter;
if (item)
{
out_stream << "{\n";
out_stream << llformat("ext char index %d\n", idx );
if( !item->exportLegacyStream( out_stream ) )
{
return false;
}
out_stream << "}\n";
}
++idx;
}
out_stream << "}\n";
return true;
}
bool LLNotecard::exportStream( std::ostream& out_stream )
{
out_stream << "Linden text version 2\n";
out_stream << "{\n";
if( !exportEmbeddedItemsStream( out_stream ) )
{
return false;
}
out_stream << llformat("Text length %d\n", mText.length() );
out_stream << mText;
out_stream << "}\n";
return true;
}
////////////////////////////////////////////////////////////////////////////
void LLNotecard::setItems(const std::vector<LLPointer<LLInventoryItem> >& items)
{
mItems = items;
}
void LLNotecard::setText(const std::string& text)
{
mText = text;
}
+69
View File
@@ -0,0 +1,69 @@
/**
* @file llnotecard.h
* @brief LLNotecard class declaration
*
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_NOTECARD_H
#define LL_NOTECARD_H
#include "llpointer.h"
#include "llinventory.h"
class LLNotecard
{
public:
/**
* @brief anonymous enumeration to set max size.
*/
enum
{
MAX_SIZE = 65536
};
LLNotecard(S32 max_text = LLNotecard::MAX_SIZE);
virtual ~LLNotecard();
bool importStream(std::istream& str);
bool exportStream(std::ostream& str);
const std::vector<LLPointer<LLInventoryItem> >& getItems() const { return mItems; }
const std::string& getText() const { return mText; }
std::string& getText() { return mText; }
void setItems(const std::vector<LLPointer<LLInventoryItem> >& items);
void setText(const std::string& text);
S32 getVersion() { return mVersion; }
S32 getEmbeddedVersion() { return mEmbeddedVersion; }
private:
bool importEmbeddedItemsStream(std::istream& str);
bool exportEmbeddedItemsStream(std::ostream& str);
std::vector<LLPointer<LLInventoryItem> > mItems;
std::string mText;
S32 mMaxText;
S32 mVersion;
S32 mEmbeddedVersion;
};
#endif /* LL_NOTECARD_H */
File diff suppressed because it is too large Load Diff
+677
View File
@@ -0,0 +1,677 @@
/**
* @file llparcel.h
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLPARCEL_H
#define LL_LLPARCEL_H
#include <time.h>
#include <iostream>
#include "lluuid.h"
#include "llparcelflags.h"
#include "llpermissions.h"
#include "lltimer.h"
#include "v3math.h"
#include "llsettingsdaycycle.h"
// Grid out of which parcels taken is stepped every 4 meters.
const F32 PARCEL_GRID_STEP_METERS = 4.f;
// Area of one "square" of parcel
const S32 PARCEL_UNIT_AREA = 16;
// Height _above_ground_ that parcel boundary ends
const F32 PARCEL_HEIGHT = 50.f;
//Height above ground which parcel boundries exist for explicitly banned avatars
const F32 BAN_HEIGHT = 5000.f;
// Maximum number of entries in an access list
const S32 PARCEL_MAX_ACCESS_LIST = 300;
//Maximum number of entires in an update packet
//for access/ban lists.
const F32 PARCEL_MAX_ENTRIES_PER_PACKET = 48.f;
// Maximum number of experiences
const S32 PARCEL_MAX_EXPERIENCE_LIST = 24;
// Weekly charge for listing a parcel in the directory
const S32 PARCEL_DIRECTORY_FEE = 30;
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
const S32 PARCEL_OVERLAY_CHUNKS = 4;
// Bottom three bits are a color index for the land overlay
const U8 PARCEL_COLOR_MASK = 0x07;
const U8 PARCEL_PUBLIC = 0x00;
const U8 PARCEL_OWNED = 0x01;
const U8 PARCEL_GROUP = 0x02;
const U8 PARCEL_SELF = 0x03;
const U8 PARCEL_FOR_SALE = 0x04;
const U8 PARCEL_AUCTION = 0x05;
// unused 0x06
// unused 0x07
// flag, unused 0x08
const U8 PARCEL_HIDDENAVS = 0x10; // avatars not visible outside of parcel. Used for 'see avs' feature, but must be off for compatibility
const U8 PARCEL_SOUND_LOCAL = 0x20;
const U8 PARCEL_WEST_LINE = 0x40; // flag, property line on west edge
const U8 PARCEL_SOUTH_LINE = 0x80; // flag, property line on south edge
// Transmission results for parcel properties
const S32 PARCEL_RESULT_NO_DATA = -1;
const S32 PARCEL_RESULT_SUCCESS = 0; // got exactly one parcel
const S32 PARCEL_RESULT_MULTIPLE = 1; // got multiple parcels
const S32 SELECTED_PARCEL_SEQ_ID = -10000;
const S32 COLLISION_NOT_IN_GROUP_PARCEL_SEQ_ID = -20000;
const S32 COLLISION_BANNED_PARCEL_SEQ_ID = -30000;
const S32 COLLISION_NOT_ON_LIST_PARCEL_SEQ_ID = -40000;
const S32 HOVERED_PARCEL_SEQ_ID = -50000;
const U32 RT_NONE = 0x1 << 0;
const U32 RT_OWNER = 0x1 << 1;
const U32 RT_GROUP = 0x1 << 2;
const U32 RT_OTHER = 0x1 << 3;
const U32 RT_LIST = 0x1 << 4;
const U32 RT_SELL = 0x1 << 5;
const S32 INVALID_PARCEL_ID = -1;
const S32 INVALID_PARCEL_ENVIRONMENT_VERSION = -2;
// if Region settings are used, parcel env. version is -1
const S32 UNSET_PARCEL_ENVIRONMENT_VERSION = -1;
// Timeouts for parcels
// default is 21 days * 24h/d * 60m/h * 60s/m *1000000 usec/s = 1814400000000
const U64 DEFAULT_USEC_CONVERSION_TIMEOUT = U64L(1814400000000);
// ***** TESTING is 10 minutes
//const U64 DEFAULT_USEC_CONVERSION_TIMEOUT = U64L(600000000);
// group is 60 days * 24h/d * 60m/h * 60s/m *1000000 usec/s = 5184000000000
const U64 GROUP_USEC_CONVERSION_TIMEOUT = U64L(5184000000000);
// ***** TESTING is 10 minutes
//const U64 GROUP_USEC_CONVERSION_TIMEOUT = U64L(600000000);
// default sale timeout is 2 days -> 172800000000
const U64 DEFAULT_USEC_SALE_TIMEOUT = U64L(172800000000);
// ***** TESTING is 10 minutes
//const U64 DEFAULT_USEC_SALE_TIMEOUT = U64L(600000000);
// more grace period extensions.
const U64 SEVEN_DAYS_IN_USEC = U64L(604800000000);
// if more than 100,000s before sale revert, and no extra extension
// has been given, go ahead and extend it more. That's about 1.2 days.
const S32 EXTEND_GRACE_IF_MORE_THAN_SEC = 100000;
class LLMessageSystem;
class LLSD;
class LLAccessEntry
{
public:
typedef std::map<LLUUID,LLAccessEntry> map;
LLAccessEntry()
: mTime(0),
mFlags(0)
{}
LLUUID mID; // Agent ID
S32 mTime; // Time (unix seconds) when entry expires
U32 mFlags; // Not used - currently should always be zero
};
class LLParcel
{
public:
enum EOwnershipStatus
{
OS_LEASED = 0,
OS_LEASE_PENDING = 1,
OS_ABANDONED = 2,
OS_COUNT = 3,
OS_NONE = -1
};
enum ECategory
{
C_NONE = 0,
C_LINDEN,
C_ADULT,
C_ARTS, // "arts & culture"
C_BUSINESS, // was "store"
C_EDUCATIONAL,
C_GAMING, // was "game"
C_HANGOUT, // was "gathering place"
C_NEWCOMER,
C_PARK, // "parks & nature"
C_RESIDENTIAL, // was "homestead"
C_SHOPPING,
C_STAGE,
C_OTHER,
C_RENTAL,
C_COUNT,
C_ANY = -1 // only useful in queries
};
enum EAction
{
A_CREATE = 0,
A_RELEASE = 1,
A_ABSORB = 2,
A_ABSORBED = 3,
A_DIVIDE = 4,
A_DIVISION = 5,
A_ACQUIRE = 6,
A_RELINQUISH = 7,
A_CONFIRM = 8,
A_COUNT = 9,
A_UNKNOWN = -1
};
enum ELandingType
{
L_NONE = 0,
L_LANDING_POINT = 1,
L_DIRECT = 2
};
// CREATORS
LLParcel();
LLParcel(
const LLUUID &owner_id,
bool modify,
bool terraform,
bool damage,
time_t claim_date,
S32 claim_price,
S32 rent_price,
S32 area,
S32 sim_object_limit,
F32 parcel_object_bonus,
bool is_group_owned = false);
virtual ~LLParcel();
void init(
const LLUUID &owner_id,
bool modify,
bool terraform,
bool damage,
time_t claim_date,
S32 claim_price,
S32 rent_price,
S32 area,
S32 sim_object_limit,
F32 parcel_object_bonus,
bool is_group_owned = false);
// TODO: make an actual copy constructor for this
void overrideParcelFlags(U32 flags);
// if you specify an agent id here, the group id will be zeroed
void overrideOwner(
const LLUUID& owner_id,
bool is_group_owned = false);
void overrideSaleTimerExpires(F32 secs_left) { mSaleTimerExpires.setTimerExpirySec(secs_left); }
// MANIPULATORS
void generateNewID() { mID.generate(); }
void setName(const std::string& name);
void setDesc(const std::string& desc);
void setMusicURL(const std::string& url);
void setMediaURL(const std::string& url);
void setMediaType(const std::string& type);
void setMediaDesc(const std::string& desc);
void setMediaID(const LLUUID& id) { mMediaID = id; }
void setMediaAutoScale ( U8 flagIn ) { mMediaAutoScale = flagIn; }
void setMediaLoop (U8 loop) { mMediaLoop = loop; }
void setMediaWidth(S32 width);
void setMediaHeight(S32 height);
void setMediaCurrentURL(const std::string& url);
void setMediaAllowNavigate(U8 enable) { mMediaAllowNavigate = enable; }
void setMediaURLTimeout(F32 timeout) { mMediaURLTimeout = timeout; }
void setMediaPreventCameraZoom(U8 enable) { mMediaPreventCameraZoom = enable; }
void setMediaURLResetTimer(F32 time);
virtual void setLocalID(S32 local_id);
// blow away all the extra stuff lurking in parcels, including urls, access lists, etc
void clearParcel();
// This value is not persisted out to the parcel file, it is only
// a per-process blocker for attempts to purchase.
void setInEscrow(bool in_escrow) { mInEscrow = in_escrow; }
void setAuthorizedBuyerID(const LLUUID& id) { mAuthBuyerID = id; }
//void overrideBuyerID(const LLUUID& id) { mBuyerID = id; }
void setCategory(ECategory category) { mCategory = category; }
void setSnapshotID(const LLUUID& id) { mSnapshotID = id; }
void setUserLocation(const LLVector3& pos) { mUserLocation = pos; }
void setUserLookAt(const LLVector3& rot) { mUserLookAt = rot; }
void setLandingType(const ELandingType type) { mLandingType = type; }
void setSeeAVs(bool see_avs) { mSeeAVs = see_avs; }
void setHaveNewParcelLimitData(bool have_new_parcel_data) { mHaveNewParcelLimitData = have_new_parcel_data; } // Remove this once hidden AV feature is fully available grid-wide
void setAuctionID(U32 auction_id) { mAuctionID = auction_id;}
void setAllParcelFlags(U32 flags);
void setParcelFlag(U32 flag, bool b);
virtual void setArea(S32 area, S32 sim_object_limit);
void setDiscountRate(F32 rate);
void setAllowModify(bool b) { setParcelFlag(PF_CREATE_OBJECTS, b); }
void setAllowGroupModify(bool b) { setParcelFlag(PF_CREATE_GROUP_OBJECTS, b); }
void setAllowAllObjectEntry(bool b) { setParcelFlag(PF_ALLOW_ALL_OBJECT_ENTRY, b); }
void setAllowGroupObjectEntry(bool b) { setParcelFlag(PF_ALLOW_GROUP_OBJECT_ENTRY, b); }
void setAllowTerraform(bool b){setParcelFlag(PF_ALLOW_TERRAFORM, b); }
void setAllowDamage(bool b) { setParcelFlag(PF_ALLOW_DAMAGE, b); }
void setAllowFly(bool b) { setParcelFlag(PF_ALLOW_FLY, b); }
void setAllowGroupScripts(bool b) { setParcelFlag(PF_ALLOW_GROUP_SCRIPTS, b); }
void setAllowOtherScripts(bool b) { setParcelFlag(PF_ALLOW_OTHER_SCRIPTS, b); }
void setAllowDeedToGroup(bool b) { setParcelFlag(PF_ALLOW_DEED_TO_GROUP, b); }
void setContributeWithDeed(bool b) { setParcelFlag(PF_CONTRIBUTE_WITH_DEED, b); }
void setForSale(bool b) { setParcelFlag(PF_FOR_SALE, b); }
void setSoundOnly(bool b) { setParcelFlag(PF_SOUND_LOCAL, b); }
void setDenyAnonymous(bool b) { setParcelFlag(PF_DENY_ANONYMOUS, b); }
void setDenyAgeUnverified(bool b) { setParcelFlag(PF_DENY_AGEUNVERIFIED, b); }
void setRestrictPushObject(bool b) { setParcelFlag(PF_RESTRICT_PUSHOBJECT, b); }
void setAllowGroupAVSounds(bool b) { mAllowGroupAVSounds = b; }
void setAllowAnyAVSounds(bool b) { mAllowAnyAVSounds = b; }
void setObscureMOAP(bool b) { mObscureMOAP = b; }
void setDrawDistance(F32 dist) { mDrawDistance = dist; }
void setSalePrice(S32 price) { mSalePrice = price; }
void setGroupID(const LLUUID& id) { mGroupID = id; }
//void setGroupName(const std::string& s) { mGroupName.assign(s); }
void setPassPrice(S32 price) { mPassPrice = price; }
void setPassHours(F32 hours) { mPassHours = hours; }
// bool importStream(std::istream& input_stream);
bool importAccessEntry(std::istream& input_stream, LLAccessEntry* entry);
// bool exportStream(std::ostream& output_stream);
void packMessage(LLMessageSystem* msg);
void packMessage(LLSD& msg);
void unpackMessage(LLMessageSystem* msg);
void packAccessEntries(LLMessageSystem* msg,
const std::map<LLUUID,LLAccessEntry>& list);
void unpackAccessEntries(LLMessageSystem* msg,
std::map<LLUUID,LLAccessEntry>* list);
void unpackExperienceEntries(LLMessageSystem* msg, U32 type);
void setAABBMin(const LLVector3& min) { mAABBMin = min; }
void setAABBMax(const LLVector3& max) { mAABBMax = max; }
// Extend AABB to include rectangle from min to max.
void extendAABB(const LLVector3& box_min, const LLVector3& box_max);
void dump();
// Scans the pass list and removes any items with an expiration
// time earlier than "now".
void expirePasses(S32 now);
// Add to list, suppressing duplicates. Returns true if added.
bool addToAccessList(const LLUUID& agent_id, S32 time);
bool addToBanList(const LLUUID& agent_id, S32 time);
bool removeFromAccessList(const LLUUID& agent_id);
bool removeFromBanList(const LLUUID& agent_id);
// ACCESSORS
const LLUUID& getID() const { return mID; }
const std::string& getName() const { return mName; }
const std::string& getDesc() const { return mDesc; }
const std::string& getMusicURL() const { return mMusicURL; }
const std::string& getMediaURL() const { return mMediaURL; }
const std::string& getMediaDesc() const { return mMediaDesc; }
const std::string& getMediaType() const { return mMediaType; }
const LLUUID& getMediaID() const { return mMediaID; }
S32 getMediaWidth() const { return mMediaWidth; }
S32 getMediaHeight() const { return mMediaHeight; }
U8 getMediaAutoScale() const { return mMediaAutoScale; }
U8 getMediaLoop() const { return mMediaLoop; }
const std::string& getMediaCurrentURL() const { return mMediaCurrentURL; }
U8 getMediaAllowNavigate() const { return mMediaAllowNavigate; }
F32 getMediaURLTimeout() const { return mMediaURLTimeout; }
U8 getMediaPreventCameraZoom() const { return mMediaPreventCameraZoom; }
S32 getLocalID() const { return mLocalID; }
const LLUUID& getOwnerID() const { return mOwnerID; }
const LLUUID& getGroupID() const { return mGroupID; }
S32 getPassPrice() const { return mPassPrice; }
F32 getPassHours() const { return mPassHours; }
bool getIsGroupOwned() const { return mGroupOwned; }
U32 getAuctionID() const { return mAuctionID; }
bool isInEscrow() const { return mInEscrow; }
bool isPublic() const;
// Region-local user-specified position
const LLVector3& getUserLocation() const { return mUserLocation; }
const LLVector3& getUserLookAt() const { return mUserLookAt; }
ELandingType getLandingType() const { return mLandingType; }
bool getSeeAVs() const { return mSeeAVs; }
bool getHaveNewParcelLimitData() const { return mHaveNewParcelLimitData; }
// User-specified snapshot
const LLUUID& getSnapshotID() const { return mSnapshotID; }
// the authorized buyer id is the person who is the only
// agent/group that has authority to purchase. (ie, ui specified a
// particular agent could buy the plot).
const LLUUID& getAuthorizedBuyerID() const { return mAuthBuyerID; }
// helper function
bool isBuyerAuthorized(const LLUUID& buyer_id) const;
// The buyer of a plot is set when someone indicates they want to
// buy the plot, and the system is simply waiting for tier-up
// approval
//const LLUUID& getBuyerID() const { return mBuyerID; }
// functions to deal with ownership status.
EOwnershipStatus getOwnershipStatus() const { return mStatus; }
static const std::string& getOwnershipStatusString(EOwnershipStatus status);
void setOwnershipStatus(EOwnershipStatus status) { mStatus = status; }
// dealing with parcel category information
ECategory getCategory() const {return mCategory; }
static const std::string& getCategoryString(ECategory category);
static const std::string& getCategoryUIString(ECategory category);
static ECategory getCategoryFromString(const std::string& string);
static ECategory getCategoryFromUIString(const std::string& string);
// functions for parcel action (used for logging)
static const std::string& getActionString(EAction action);
// dealing with sales and parcel conversion.
//
// the isSaleTimerExpired will trivially return false if there is
// no sale going on. Pass in the current time in usec which will
// be used for comparison.
bool isSaleTimerExpired(const U64& time);
F32 getSaleTimerExpires() { return mSaleTimerExpires.getRemainingTimeF32(); }
// should the parcel join on complete?
//U32 getJoinNeighbors() const { return mJoinNeighbors; }
// need to record a few things with the parcel when a sale
// starts.
void startSale(const LLUUID& buyer_id, bool is_buyer_group);
// do the expiration logic, which needs to return values usable in
// a L$ transaction.
void expireSale(U32& type, U8& flags, LLUUID& from_id, LLUUID& to_id);
void completeSale(U32& type, U8& flags, LLUUID& to_id);
void clearSale();
bool isMediaResetTimerExpired(const U64& time);
// more accessors
U32 getParcelFlags() const { return mParcelFlags; }
bool getParcelFlag(U32 flag) const { return (mParcelFlags & flag) != 0; }
// objects can be added or modified by anyone (only parcel owner if disabled)
bool getAllowModify() const { return getParcelFlag(PF_CREATE_OBJECTS); }
// objects can be added or modified by group members
bool getAllowGroupModify() const { return getParcelFlag(PF_CREATE_GROUP_OBJECTS); }
// the parcel can be deeded to the group
bool getAllowDeedToGroup() const { return getParcelFlag(PF_ALLOW_DEED_TO_GROUP); }
// Does the owner want to make a contribution along with the deed.
bool getContributeWithDeed() const { return getParcelFlag(PF_CONTRIBUTE_WITH_DEED); }
// heightfield can be modified
bool getAllowTerraform() const { return getParcelFlag(PF_ALLOW_TERRAFORM); }
// avatars can be hurt here
bool getAllowDamage() const { return getParcelFlag(PF_ALLOW_DAMAGE); }
bool getAllowFly() const { return getParcelFlag(PF_ALLOW_FLY); }
bool getAllowGroupScripts() const { return getParcelFlag(PF_ALLOW_GROUP_SCRIPTS); }
bool getAllowOtherScripts() const { return getParcelFlag(PF_ALLOW_OTHER_SCRIPTS); }
bool getAllowAllObjectEntry() const { return getParcelFlag(PF_ALLOW_ALL_OBJECT_ENTRY); }
bool getAllowGroupObjectEntry() const { return getParcelFlag(PF_ALLOW_GROUP_OBJECT_ENTRY); }
bool getForSale() const { return getParcelFlag(PF_FOR_SALE); }
bool getSoundLocal() const { return getParcelFlag(PF_SOUND_LOCAL); }
bool getParcelFlagAllowVoice() const { return getParcelFlag(PF_ALLOW_VOICE_CHAT); }
bool getParcelFlagUseEstateVoiceChannel() const { return getParcelFlag(PF_USE_ESTATE_VOICE_CHAN); }
bool getAllowPublish() const { return getParcelFlag(PF_ALLOW_PUBLISH); }
bool getMaturePublish() const { return getParcelFlag(PF_MATURE_PUBLISH); }
bool getRestrictPushObject() const { return getParcelFlag(PF_RESTRICT_PUSHOBJECT); }
bool getRegionPushOverride() const { return mRegionPushOverride; }
bool getRegionDenyAnonymousOverride() const { return mRegionDenyAnonymousOverride; }
bool getRegionDenyAgeUnverifiedOverride() const { return mRegionDenyAgeUnverifiedOverride; }
bool getRegionAllowAccessOverride() const { return mRegionAllowAccessoverride; }
bool getRegionAllowEnvironmentOverride() const { return mRegionAllowEnvironmentOverride; }
S32 getParcelEnvironmentVersion() const { return mCurrentEnvironmentVersion; }
bool getAllowGroupAVSounds() const { return mAllowGroupAVSounds; }
bool getAllowAnyAVSounds() const { return mAllowAnyAVSounds; }
bool getObscureMOAP() const { return mObscureMOAP; }
F32 getDrawDistance() const { return mDrawDistance; }
S32 getSalePrice() const { return mSalePrice; }
time_t getClaimDate() const { return mClaimDate; }
S32 getClaimPricePerMeter() const { return mClaimPricePerMeter; }
S32 getRentPricePerMeter() const { return mRentPricePerMeter; }
// Area is NOT automatically calculated. You must calculate it
// and store it with setArea.
S32 getArea() const { return mArea; }
// deprecated 12/11/2003
//F32 getDiscountRate() const { return mDiscountRate; }
S32 getClaimPrice() const { return mClaimPricePerMeter * mArea; }
// Can this agent create objects here?
bool allowModifyBy(const LLUUID &agent_id, const LLUUID &group_id) const;
// Can this agent change the shape of the land?
bool allowTerraformBy(const LLUUID &agent_id) const;
bool operator==(const LLParcel &rhs) const;
// Calculate rent - area * rent * discount rate
S32 getTotalRent() const;
F32 getAdjustedRentPerMeter() const;
const LLVector3& getAABBMin() const { return mAABBMin; }
const LLVector3& getAABBMax() const { return mAABBMax; }
LLVector3 getCenterpoint() const;
// simwide
S32 getSimWideMaxPrimCapacity() const { return mSimWideMaxPrimCapacity; }
S32 getSimWidePrimCount() const { return mSimWidePrimCount; }
// this parcel only (not simwide)
S32 getMaxPrimCapacity() const { return mMaxPrimCapacity; } // Does not include prim bonus
S32 getPrimCount() const { return mOwnerPrimCount + mGroupPrimCount + mOtherPrimCount + mSelectedPrimCount; }
S32 getOwnerPrimCount() const { return mOwnerPrimCount; }
S32 getGroupPrimCount() const { return mGroupPrimCount; }
S32 getOtherPrimCount() const { return mOtherPrimCount; }
S32 getSelectedPrimCount() const{ return mSelectedPrimCount; }
S32 getTempPrimCount() const { return mTempPrimCount; }
F32 getParcelPrimBonus() const { return mParcelPrimBonus; }
S32 getCleanOtherTime() const { return mCleanOtherTime; }
void setMaxPrimCapacity(S32 max) { mMaxPrimCapacity = max; } // Does not include prim bonus
// simwide
void setSimWideMaxPrimCapacity(S32 current) { mSimWideMaxPrimCapacity = current; }
void setSimWidePrimCount(S32 current) { mSimWidePrimCount = current; }
// this parcel only (not simwide)
void setOwnerPrimCount(S32 current) { mOwnerPrimCount = current; }
void setGroupPrimCount(S32 current) { mGroupPrimCount = current; }
void setOtherPrimCount(S32 current) { mOtherPrimCount = current; }
void setSelectedPrimCount(S32 current) { mSelectedPrimCount = current; }
void setTempPrimCount(S32 current) { mTempPrimCount = current; }
void setParcelPrimBonus(F32 bonus) { mParcelPrimBonus = bonus; }
void setCleanOtherTime(S32 time) { mCleanOtherTime = time; }
void setRegionPushOverride(bool override) {mRegionPushOverride = override; }
void setRegionDenyAnonymousOverride(bool override) { mRegionDenyAnonymousOverride = override; }
void setRegionDenyAgeUnverifiedOverride(bool override) { mRegionDenyAgeUnverifiedOverride = override; }
void setRegionAllowAccessOverride(bool override) { mRegionAllowAccessoverride = override; }
void setRegionAllowEnvironmentOverride(bool override) { mRegionAllowEnvironmentOverride = override; }
void setParcelEnvironmentVersion(S32 version) { mCurrentEnvironmentVersion = version; }
// Accessors for parcel sellWithObjects
void setPreviousOwnerID(LLUUID prev_owner) { mPreviousOwnerID = prev_owner; }
void setPreviouslyGroupOwned(bool b) { mPreviouslyGroupOwned = b; }
void setSellWithObjects(bool b) { setParcelFlag(PF_SELL_PARCEL_OBJECTS, b); }
LLUUID getPreviousOwnerID() const { return mPreviousOwnerID; }
bool getPreviouslyGroupOwned() const { return mPreviouslyGroupOwned; }
bool getSellWithObjects() const { return getParcelFlag(PF_SELL_PARCEL_OBJECTS); }
protected:
LLUUID mID;
LLUUID mOwnerID;
LLUUID mGroupID;
bool mGroupOwned; // true if mOwnerID is a group_id
LLUUID mPreviousOwnerID;
bool mPreviouslyGroupOwned;
EOwnershipStatus mStatus;
ECategory mCategory;
LLUUID mAuthBuyerID;
LLUUID mSnapshotID;
LLVector3 mUserLocation;
LLVector3 mUserLookAt;
ELandingType mLandingType;
bool mSeeAVs; // Avatars on this parcel are visible from outside it
bool mHaveNewParcelLimitData; // Remove once hidden AV feature is grid-wide
LLTimer mSaleTimerExpires;
LLTimer mMediaResetTimer;
S32 mGraceExtension;
// This value is non-zero if there is an auction associated with
// the parcel.
U32 mAuctionID;
// value used to temporarily lock attempts to purchase the parcel.
bool mInEscrow;
time_t mClaimDate; // UTC Unix-format time
S32 mClaimPricePerMeter; // meter squared
S32 mRentPricePerMeter; // meter squared
S32 mArea; // meter squared
F32 mDiscountRate; // 0.0-1.0
F32 mDrawDistance;
U32 mParcelFlags;
S32 mSalePrice; // linden dollars
std::string mName;
std::string mDesc;
std::string mMusicURL;
std::string mMediaURL;
std::string mMediaDesc;
std::string mMediaType;
S32 mMediaWidth;
S32 mMediaHeight;
U8 mMediaAutoScale;
U8 mMediaLoop;
std::string mMediaCurrentURL;
LLUUID mMediaID;
U8 mMediaAllowNavigate;
U8 mMediaPreventCameraZoom;
F32 mMediaURLTimeout;
S32 mPassPrice;
F32 mPassHours;
LLVector3 mAABBMin;
LLVector3 mAABBMax;
S32 mMaxPrimCapacity; // Prims allowed on parcel, does not include prim bonus
S32 mSimWidePrimCount;
S32 mSimWideMaxPrimCapacity;
//S32 mSimWidePrimCorrection;
S32 mOwnerPrimCount;
S32 mGroupPrimCount;
S32 mOtherPrimCount;
S32 mSelectedPrimCount;
S32 mTempPrimCount;
F32 mParcelPrimBonus;
S32 mCleanOtherTime;
bool mRegionPushOverride;
bool mRegionDenyAnonymousOverride;
bool mRegionDenyAgeUnverifiedOverride;
bool mRegionAllowAccessoverride;
bool mRegionAllowEnvironmentOverride;
bool mAllowGroupAVSounds;
bool mAllowAnyAVSounds;
bool mObscureMOAP;
S32 mCurrentEnvironmentVersion;
bool mIsDefaultDayCycle;
public:
// HACK, make private
S32 mLocalID;
LLUUID mBanListTransactionID;
LLUUID mAccessListTransactionID;
std::map<LLUUID,LLAccessEntry> mAccessList;
std::map<LLUUID,LLAccessEntry> mBanList;
std::map<LLUUID,LLAccessEntry> mTempBanList;
std::map<LLUUID,LLAccessEntry> mTempAccessList;
typedef std::map<LLUUID, U32> xp_type_map_t;
void setExperienceKeyType(const LLUUID& experience_key, U32 type);
U32 countExperienceKeyType(U32 type);
LLAccessEntry::map getExperienceKeysByType(U32 type)const;
void clearExperienceKeysByType(U32 type);
private:
xp_type_map_t mExperienceKeys;
};
const std::string& ownership_status_to_string(LLParcel::EOwnershipStatus status);
LLParcel::EOwnershipStatus ownership_string_to_status(const std::string& s);
LLParcel::ECategory category_string_to_category(const std::string& s);
const std::string& category_to_string(LLParcel::ECategory category);
#endif
+134
View File
@@ -0,0 +1,134 @@
/**
* @file llparcelflags.h
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLPARCEL_FLAGS_H
#define LL_LLPARCEL_FLAGS_H
//---------------------------------------------------------------------------
// Parcel Flags (PF) constants
//---------------------------------------------------------------------------
const U32 PF_ALLOW_FLY = 1 << 0;// Can start flying
const U32 PF_ALLOW_OTHER_SCRIPTS= 1 << 1;// Scripts by others can run.
const U32 PF_FOR_SALE = 1 << 2;// Can buy this land
const U32 PF_FOR_SALE_OBJECTS = 1 << 7;// Can buy all objects on this land
const U32 PF_ALLOW_LANDMARK = 1 << 3;// Always true/deprecated
const U32 PF_ALLOW_TERRAFORM = 1 << 4;
const U32 PF_ALLOW_DAMAGE = 1 << 5;
const U32 PF_CREATE_OBJECTS = 1 << 6;
// 7 is moved above
const U32 PF_USE_ACCESS_GROUP = 1 << 8;
const U32 PF_USE_ACCESS_LIST = 1 << 9;
const U32 PF_USE_BAN_LIST = 1 << 10;
const U32 PF_USE_PASS_LIST = 1 << 11;
const U32 PF_SHOW_DIRECTORY = 1 << 12;
const U32 PF_ALLOW_DEED_TO_GROUP = 1 << 13;
const U32 PF_CONTRIBUTE_WITH_DEED = 1 << 14;
const U32 PF_SOUND_LOCAL = 1 << 15; // Hear sounds in this parcel only
const U32 PF_SELL_PARCEL_OBJECTS = 1 << 16; // Objects on land are included as part of the land when the land is sold
const U32 PF_ALLOW_PUBLISH = 1 << 17; // Allow publishing of parcel information on the web
const U32 PF_MATURE_PUBLISH = 1 << 18; // The information on this parcel is mature
const U32 PF_URL_WEB_PAGE = 1 << 19; // The "media URL" is an HTML page
const U32 PF_URL_RAW_HTML = 1 << 20; // The "media URL" is a raw HTML string like <H1>Foo</H1>
const U32 PF_RESTRICT_PUSHOBJECT = 1 << 21; // Restrict push object to either on agent or on scripts owned by parcel owner
const U32 PF_DENY_ANONYMOUS = 1 << 22; // Deny all non identified/transacted accounts
// const U32 PF_DENY_IDENTIFIED = 1 << 23; // Deny identified accounts
// const U32 PF_DENY_TRANSACTED = 1 << 24; // Deny identified accounts
const U32 PF_ALLOW_GROUP_SCRIPTS = 1 << 25; // Allow scripts owned by group
const U32 PF_CREATE_GROUP_OBJECTS = 1 << 26; // Allow object creation by group members or objects
const U32 PF_ALLOW_ALL_OBJECT_ENTRY = 1 << 27; // Allow all objects to enter a parcel
const U32 PF_ALLOW_GROUP_OBJECT_ENTRY = 1 << 28; // Only allow group (and owner) objects to enter the parcel
const U32 PF_ALLOW_VOICE_CHAT = 1 << 29; // Allow residents to use voice chat on this parcel
const U32 PF_USE_ESTATE_VOICE_CHAN = 1 << 30;
const U32 PF_DENY_AGEUNVERIFIED = 1 << 31; // Prevent residents who aren't age-verified
// NOTE: At one point we have used all of the bits.
// We have deprecated two of them in 1.19.0 which *could* be reused,
// but only after we are certain there are no simstates using those bits.
//const U32 PF_RESERVED = 1U << 31;
// If any of these are true the parcel is restricting access in some maner.
const U32 PF_USE_RESTRICTED_ACCESS = PF_USE_ACCESS_GROUP
| PF_USE_ACCESS_LIST
| PF_USE_BAN_LIST
| PF_USE_PASS_LIST
| PF_DENY_ANONYMOUS
| PF_DENY_AGEUNVERIFIED;
const U32 PF_NONE = 0x00000000;
const U32 PF_ALL = 0xFFFFFFFF;
const U32 PF_DEFAULT = PF_ALLOW_FLY
| PF_ALLOW_OTHER_SCRIPTS
| PF_ALLOW_GROUP_SCRIPTS
| PF_ALLOW_LANDMARK
| PF_CREATE_OBJECTS
| PF_CREATE_GROUP_OBJECTS
| PF_USE_BAN_LIST
| PF_ALLOW_ALL_OBJECT_ENTRY
| PF_ALLOW_GROUP_OBJECT_ENTRY
| PF_ALLOW_VOICE_CHAT
| PF_USE_ESTATE_VOICE_CHAN;
// Access list flags
const U32 AL_ACCESS = (1 << 0);
const U32 AL_BAN = (1 << 1);
const U32 AL_ALLOW_EXPERIENCE = (1 << 3);
const U32 AL_BLOCK_EXPERIENCE = (1 << 4);
//const U32 AL_RENTER = (1 << 2);
// Block access return values. BA_ALLOWED is the only success case
// since some code in the simulator relies on that assumption. All
// other BA_ values should be reasons why you are not allowed.
const S32 BA_ALLOWED = 0;
const S32 BA_NOT_IN_GROUP = 1;
const S32 BA_NOT_ON_LIST = 2;
const S32 BA_BANNED = 3;
const S32 BA_NO_ACCESS_LEVEL = 4;
const S32 BA_NOT_AGE_VERIFIED = 5;
// ParcelRelease flags
const U32 PR_NONE = 0x0;
const U32 PR_GOD_FORCE = (1 << 0);
enum EObjectCategory
{
OC_INVALID = -1,
OC_NONE = 0,
OC_TOTAL = 0, // yes zero, like OC_NONE
OC_OWNER,
OC_GROUP,
OC_OTHER,
OC_SELECTED,
OC_TEMP,
OC_COUNT
};
const S32 PARCEL_DETAILS_NAME = 0;
const S32 PARCEL_DETAILS_DESC = 1;
const S32 PARCEL_DETAILS_OWNER = 2;
const S32 PARCEL_DETAILS_GROUP = 3;
const S32 PARCEL_DETAILS_AREA = 4;
const S32 PARCEL_DETAILS_ID = 5;
const S32 PARCEL_DETAILS_SEE_AVATARS = 6;
#endif
File diff suppressed because it is too large Load Diff
+452
View File
@@ -0,0 +1,452 @@
/**
* @file llpermissions.h
* @brief Permissions structures for objects.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLPERMISSIONS_H
#define LL_LLPERMISSIONS_H
#include "llpermissionsflags.h"
#include "llsd.h"
#include "lluuid.h"
#include "llxmlnode.h"
#include "llinventorytype.h"
// prototypes
class LLMessageSystem;
extern void mask_to_string(U32 mask, char* str, bool isOpenSim=false);
extern std::string mask_to_string(U32 mask, bool isOpenSim=false);
template<class T> class LLMetaClassT;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLPermissions
//
// Class which encapsulates object and inventory permissions/ownership/etc.
//
// Permissions where originally a static state creator/owner and set
// of cap bits. Since then, it has grown to include group information,
// last owner, masks for different people. The implementation has been
// chosen such that a uuid is stored for each current/past owner, and
// a bitmask is stored for the base permissions, owner permissions,
// group permissions, and everyone else permissions.
//
// The base permissions represent the most permissive state that the
// permissions can possibly be in. Thus, if the base permissions do
// not allow copying, no one can ever copy the object. The permissions
// also maintain a tree-like hierarchy of permissions, thus, if we
// (for sake of discussions) denote more permissive as '>', then this
// is invariant:
//
// base mask >= owner mask >= group mask
// >= everyone mask
// >= next owner mask
// NOTE: the group mask does not effect everyone or next, everyone
// does not effect group or next, etc.
//
// It is considered a fair use right to move or delete any object you
// own. Another fair use right is the ability to give away anything
// which you cannot copy. One way to look at that is that if you have
// a unique item, you can always give that one copy you have to
// someone else.
//
// Most of the bitmask is easy to understand, PERM_COPY means you can
// copy !PERM_TRANSFER means you cannot transfer, etc. Given that we
// now track the concept of 'next owner' inside of the permissions
// object, we can describe some new meta-meaning to the PERM_MODIFY
// flag. PERM_MODIFY is usually meant to note if you can change an
// item, but since we record next owner permissions, we can interpret
// a no-modify object as 'you cannot modify this object and you cannot
// make derivative works.' When evaluating functionality, and
// comparisons against permissions, keep this concept in mind for
// logical consistency.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLPermissions
{
private:
LLUUID mCreator; // null if object created by system
LLUUID mOwner; // null if object "unowned" (owned by system)
LLUUID mLastOwner; // object's last owner
LLUUID mGroup; // The group association
PermissionMask mMaskBase; // initially permissive, progressively AND restricted by each owner
PermissionMask mMaskOwner; // set by owner, applies to owner only, restricts lower permissions
PermissionMask mMaskEveryone; // set by owner, applies to everyone else
PermissionMask mMaskGroup; // set by owner, applies to group that is associated with permissions
PermissionMask mMaskNextOwner; // set by owner, applied to base on transfer.
// Usually set in the fixOwnership() method based on current uuid
// values.
bool mIsGroupOwned;
// Correct for fair use - you can never take away the right to
// move stuff you own, and you can never take away the right to
// transfer something you cannot otherwise copy.
void fixFairUse();
// Fix internal consistency for group/agent ownership
void fixOwnership();
public:
static const LLPermissions DEFAULT;
LLPermissions(); // defaults to created by system
//~LLPermissions();
// base initialization code
void init(const LLUUID& creator, const LLUUID& owner,
const LLUUID& last_owner, const LLUUID& group);
void initMasks(PermissionMask base, PermissionMask owner,
PermissionMask everyone, PermissionMask group,
PermissionMask next);
// adjust permissions based on inventory type.
void initMasks(LLInventoryType::EType type);
//
// ACCESSORS
//
// return the agent_id of the agent that created the item
const LLUUID& getCreator() const { return mCreator; }
// return the agent_id of the owner. returns LLUUID::null if group
// owned or public (a really big group).
const LLUUID& getOwner() const { return mOwner; }
// return the group_id of the group associated with the
// object.
const LLUUID& getGroup() const { return mGroup; }
// return the agent_id of the last agent owner. Only returns
// LLUUID::null if there has never been a previous owner (*note: this is apparently not true, say for textures in inventory, it may return LLUUID::null even if there was a previous owner).
const LLUUID& getLastOwner() const { return mLastOwner; }
U32 getMaskBase() const { return mMaskBase; }
U32 getMaskOwner() const { return mMaskOwner; }
U32 getMaskGroup() const { return mMaskGroup; }
U32 getMaskEveryone() const { return mMaskEveryone; }
U32 getMaskNextOwner() const { return mMaskNextOwner; }
// return true if the object has any owner
bool isOwned() const { return (mOwner.notNull() || mIsGroupOwned); }
// return true if group_id is owner.
bool isGroupOwned() const { return mIsGroupOwned; }
// This API returns true if the object is owned at all, and false
// otherwise. If it is owned at all, owner id is filled with
// either the owner id or the group id, and the is_group_owned
// parameter is appropriately filled. The values of owner_id and
// is_group_owned are not changed if the object is not owned.
bool getOwnership(LLUUID& owner_id, bool& is_group_owned) const;
// Gets the 'safe' owner. This should never return LLUUID::null.
// If no group owned, return the agent owner id normally.
// If group owned, return the group id.
// If not owned, return a random uuid which should have no power.
LLUUID getSafeOwner() const;
// return a cheap crc
U32 getCRC32() const;
//
// MANIPULATORS
//
// Fix hierarchy of permissions, applies appropriate permissions
// at each level to ensure that base permissions are respected,
// and also ensures that if base cannot transfer, then group and
// other cannot copy.
void fix();
// All of these methods just do exactly what they say. There is no
// permissions checking to see if the operation is allowed, and do
// not fix the permissions hierarchy. So please only use these
// methods when you are know what you're doing and coding on
// behalf of the system - ie, acting as god.
void set(const LLPermissions& permissions);
void setMaskBase(U32 mask) { mMaskBase = mask; }
void setMaskOwner(U32 mask) { mMaskOwner = mask; }
void setMaskEveryone(U32 mask) { mMaskEveryone = mask;}
void setMaskGroup(U32 mask) { mMaskGroup = mask;}
void setMaskNext(U32 mask) { mMaskNextOwner = mask; }
// Allow accumulation of permissions. Results in the tightest
// permissions possible. In the case of clashing UUIDs, it sets
// the ID to LLUUID::null.
void accumulate(const LLPermissions& perm);
//
// CHECKED MANIPULATORS
//
// These functions return true on success. They return false if
// the given agent isn't allowed to make the change. You can pass
// LLUUID::null as the agent id if the change is being made by the
// simulator itself, not on behalf of any agent - this will always
// succeed. Passing in group id of LLUUID:null means no group, and
// does not offer special permission to do anything.
// saves last owner, sets current owner, and sets the group.
// set is_atomic = true means that this permission represents
// an atomic permission and not a collection of permissions.
// Currently, the only way to have a collection is when an object
// has inventory and is then itself rolled up into an inventory
// item.
bool setOwnerAndGroup(const LLUUID& agent, const LLUUID& owner, const LLUUID& group, bool is_atomic);
// only call this if you know what you're doing
// there are usually perm-bit consequences when the
// ownerhsip changes
void yesReallySetOwner(const LLUUID& owner, bool group_owned);
// Last owner doesn't have much in the way of permissions so it's
//not too dangerous to do this.
void setLastOwner(const LLUUID& last_owner);
// saves last owner, sets owner to uuid null, sets group
// owned. group_id must be the group of the object (that's who it
// is being deeded to) and the object must be group
// modify. Technically, the agent id and group id are not
// necessary, but I wanted this function to look like the other
// checked manipulators (since that is how it is used.) If the
// agent is the system or (group == mGroup and group modify and
// owner transfer) then this function will deed the permissions,
// set the next owner mask, and return true. Otherwise, no change
// is effected, and the function returns false.
bool deedToGroup(const LLUUID& agent, const LLUUID& group);
// Attempt to set or clear the given bitmask. Returns true if you
// are allowed to modify the permissions. If you attempt to turn
// on bits not allowed by the base bits, the function will return
// true, but those bits will not be set.
bool setBaseBits( const LLUUID& agent, bool set, PermissionMask bits);
bool setOwnerBits( const LLUUID& agent, bool set, PermissionMask bits);
bool setGroupBits( const LLUUID& agent, const LLUUID& group, bool set, PermissionMask bits);
bool setEveryoneBits(const LLUUID& agent, const LLUUID& group, bool set, PermissionMask bits);
bool setNextOwnerBits(const LLUUID& agent, const LLUUID& group, bool set, PermissionMask bits);
// This is currently only used in the Viewer to handle calling cards
// where the creator is actually used to store the target. Use with care.
void setCreator(const LLUUID& creator) { mCreator = creator; }
//
// METHODS
//
// All the allow* functions return true if the given agent or
// group can perform the function. Prefer using this set of
// operations to check permissions on an object. These return
// true if the given agent or group can perform the function.
// They also return true if the object isn't owned, or the
// requesting agent is a system agent. See llpermissionsflags.h
// for bits.
bool allowOperationBy(PermissionBit op, const LLUUID& agent, const LLUUID& group = LLUUID::null) const;
inline bool allowModifyBy(const LLUUID &agent_id) const;
inline bool allowCopyBy(const LLUUID& agent_id) const;
inline bool allowMoveBy(const LLUUID& agent_id) const;
inline bool allowModifyBy(const LLUUID &agent_id, const LLUUID& group) const;
inline bool allowCopyBy(const LLUUID& agent_id, const LLUUID& group) const;
inline bool allowMoveBy(const LLUUID &agent_id, const LLUUID &group) const;
// This somewhat specialized function is meant for testing if the
// current owner is allowed to transfer to the specified agent id.
inline bool allowTransferTo(const LLUUID &agent_id) const;
// Returns true if the object can exported by the given agent
// (e.g. saved as a local .gltf file)
// The current test should return true if the agent is the owner
// AND the creator of the object.
inline bool allowExportBy(const LLUUID& agent_id) const;
#ifdef OPENSIM
inline bool allowOpenSimExportBy(const LLUUID& agent_id) const; // <FS:CR> OpenSim export permission
#endif
//
// MISC METHODS and OPERATORS
//
LLSD packMessage() const;
void unpackMessage(LLSD perms);
// For messaging system support
void packMessage(LLMessageSystem* msg) const;
void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
bool importLegacyStream(std::istream& input_stream);
bool exportLegacyStream(std::ostream& output_stream) const;
bool operator==(const LLPermissions &rhs) const;
bool operator!=(const LLPermissions &rhs) const;
friend std::ostream& operator<<(std::ostream &s, const LLPermissions &perm);
};
// Inlines
bool LLPermissions::allowModifyBy(const LLUUID& agent, const LLUUID& group) const
{
return allowOperationBy(PERM_MODIFY, agent, group);
}
bool LLPermissions::allowCopyBy(const LLUUID& agent, const LLUUID& group) const
{
return allowOperationBy(PERM_COPY, agent, group);
}
bool LLPermissions::allowMoveBy(const LLUUID& agent, const LLUUID& group) const
{
return allowOperationBy(PERM_MOVE, agent, group);
}
bool LLPermissions::allowModifyBy(const LLUUID& agent) const
{
return allowOperationBy(PERM_MODIFY, agent, LLUUID::null);
}
bool LLPermissions::allowCopyBy(const LLUUID& agent) const
{
return allowOperationBy(PERM_COPY, agent, LLUUID::null);
}
bool LLPermissions::allowMoveBy(const LLUUID& agent) const
{
return allowOperationBy(PERM_MOVE, agent, LLUUID::null);
}
bool LLPermissions::allowExportBy(const LLUUID& agent) const
{
return agent == mOwner && agent == mCreator;
}
// <FS:CR> Opensim Export Permissions
#ifdef OPENSIM
bool LLPermissions::allowOpenSimExportBy(const LLUUID& agent) const
{
return ((mCreator == agent) ? true : (allowOperationBy(PERM_EXPORT, agent, LLUUID::null)));
}
#endif
// </FS:CR>
bool LLPermissions::allowTransferTo(const LLUUID &agent_id) const
{
if (mIsGroupOwned)
{
return allowOperationBy(PERM_TRANSFER, mGroup, mGroup);
}
else
{
return ((mOwner == agent_id) ? true : allowOperationBy(PERM_TRANSFER, mOwner));
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLAggregatePermissions
//
// Class which encapsulates object and inventory permissions,
// ownership, etc. Currently, it only aggregates PERM_COPY,
// PERM_MODIFY, and PERM_TRANSFER.
//
// Usually you will construct an instance and hand the object several
// permissions masks to aggregate the copy, modify, and
// transferability into a nice trinary value.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLAggregatePermissions
{
public:
enum EValue
{
AP_EMPTY = 0x00,
AP_NONE = 0x01,
AP_SOME = 0x02,
AP_ALL = 0x03
};
// construct an empty aggregate permissions
LLAggregatePermissions();
// pass in a PERM_COPY, PERM_TRANSFER, etc, and get out a EValue
// enumeration describing the current aggregate permissions.
EValue getValue(PermissionBit bit) const;
// returns the permissions packed into the 6 LSB of a U8:
// 00TTMMCC
// where TT = transfer, MM = modify, and CC = copy
// LSB is to the right
U8 getU8() const;
// return true is the aggregate permissions are empty, otherwise false.
bool isEmpty() const ;
// pass in a PERM_COPY, PERM_TRANSFER, etc, and an EValue
// enumeration to specifically set that value. Not implemented
// because I'm not sure it's a useful api.
//void setValue(PermissionBit bit, EValue);
// Given a mask, aggregate the useful permissions.
void aggregate(PermissionMask mask);
// Aggregate aggregates
void aggregate(const LLAggregatePermissions& ag);
// message handling
void packMessage(LLMessageSystem* msg, const char* field) const;
void unpackMessage(LLMessageSystem* msg, const char* block, const char *field, S32 block_num = 0);
static const LLAggregatePermissions empty;
friend std::ostream& operator<<(std::ostream &s, const LLAggregatePermissions &perm);
protected:
enum EPermIndex
{
PI_COPY = 0,
PI_MODIFY = 1,
PI_TRANSFER = 2,
PI_END = 3,
PI_COUNT = 3
};
void aggregateBit(EPermIndex idx, bool allowed);
void aggregateIndex(EPermIndex idx, U8 bits);
static EPermIndex perm2PermIndex(PermissionBit bit);
// structure used to store the aggregate so far.
U8 mBits[PI_COUNT];
};
// These functions convert between structured data and permissions as
// appropriate for serialization. The permissions are a map of things
// like 'creator_id', 'owner_id', etc, with the value copied from the
// permission object.
LLSD ll_create_sd_from_permissions(const LLPermissions& perm);
LLPermissions ll_permissions_from_sd(const LLSD& sd_perm);
#endif
+97
View File
@@ -0,0 +1,97 @@
/**
* @file llpermissionsflags.h
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLPERMISSIONSFLAGS_H
#define LL_LLPERMISSIONSFLAGS_H
// Flags for various permissions bits.
// Shared between viewer and simulator.
// permission bits
typedef U32 PermissionMask;
typedef U32 PermissionBit;
// Do you have permission to transfer ownership of the object or
// item. Fair use rules dictate that if you cannot copy, you can
// always transfer.
constexpr PermissionBit PERM_TRANSFER = (1 << 13); // 0x00002000
// objects, scale or change textures
// parcels, allow building on it
constexpr PermissionBit PERM_MODIFY = (1 << 14); // 0x00004000
// objects, allow copy
constexpr PermissionBit PERM_COPY = (1 << 15); // 0x00008000
// <FS:CR> OpenSim export permission
const PermissionBit PERM_EXPORT = (1 << 16); // 0x00010000
// </FS:CR>
// parcels, allow entry, deprecated
//constexpr PermissionBit PERM_ENTER = (1 << 16); // 0x00010000
// parcels, allow terraform, deprecated
//constexpr PermissionBit PERM_TERRAFORM = (1 << 17); // 0x00020000
// NOTA BENE: This flag is NO LONGER USED!!! However, it is possible that some
// objects in the universe have it set so DON"T USE IT going forward.
//constexpr PermissionBit PERM_OWNER_DEBIT = (1 << 18); // 0x00040000
// objects, can grab/translate/rotate
constexpr PermissionBit PERM_MOVE = (1 << 19); // 0x00080000
// parcels, avatars take damage, deprecated
//const PermissionBit PERM_DAMAGE = (1 << 20); // 0x00100000
// don't use bit 31 -- printf/scanf with "%x" assume signed numbers
constexpr PermissionBit PERM_RESERVED = ((U32)1) << 31;
constexpr PermissionMask PERM_NONE = 0x00000000;
constexpr PermissionMask PERM_ALL = 0x7FFFFFFF;
//constexpr PermissionMask PERM_ALL_PARCEL = PERM_MODIFY | PERM_ENTER | PERM_TERRAFORM | PERM_DAMAGE;
constexpr PermissionMask PERM_ITEM_UNRESTRICTED = PERM_MODIFY | PERM_COPY | PERM_TRANSFER;
// Useful stuff for transmission.
// Which permissions field are we trying to change?
constexpr U8 PERM_BASE = 0x01;
// TODO: Add another PERM_OWNER operation type for allowOperationBy DK 04/03/06
constexpr U8 PERM_OWNER = 0x02;
constexpr U8 PERM_GROUP = 0x04;
constexpr U8 PERM_EVERYONE = 0x08;
constexpr U8 PERM_NEXT_OWNER = 0x10;
// This is just a quickie debugging key
// no modify: PERM_ALL & ~PERM_MODIFY = 0x7fffbfff
// no copy: PERM_ALL & ~PERM_COPY = 0x7fff7fff
// no modify or copy: = 0x7fff3fff
// no transfer: PERM_ALL & ~PERM_TRANSFER = 0x7fffdfff
// no modify, no transfer = 0x7fff9fff
// no copy, no transfer (INVALID!) = 0x7fff5fff
// no modify, no copy, no transfer (INVALID!) = 0x7fff1fff
#endif
+321
View File
@@ -0,0 +1,321 @@
/**
* @file llsaleinfo.cpp
* @brief
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include <iostream>
#include "linden_common.h"
#include "llsaleinfo.h"
#include "llerror.h"
#include "message.h"
#include "llsdutil.h"
// use this to avoid temporary object creation
const LLSaleInfo LLSaleInfo::DEFAULT;
///----------------------------------------------------------------------------
/// Local function declarations, constants, enums, and typedefs
///----------------------------------------------------------------------------
const char* FOR_SALE_NAMES[] =
{
"not",
"orig",
"copy",
"cntn"
};
///----------------------------------------------------------------------------
/// Class llsaleinfo
///----------------------------------------------------------------------------
// Default constructor
LLSaleInfo::LLSaleInfo() :
mSaleType(LLSaleInfo::FS_NOT),
mSalePrice(DEFAULT_PRICE)
{
}
LLSaleInfo::LLSaleInfo(EForSale sale_type, S32 sale_price) :
mSaleType(sale_type),
mSalePrice(sale_price)
{
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
}
bool LLSaleInfo::isForSale() const
{
return (FS_NOT != mSaleType);
}
U32 LLSaleInfo::getCRC32() const
{
U32 rv = (U32)mSalePrice;
rv += (mSaleType * 0x07073096);
return rv;
}
bool LLSaleInfo::exportLegacyStream(std::ostream& output_stream) const
{
output_stream << "\tsale_info\t0\n\t{\n";
output_stream << "\t\tsale_type\t" << lookup(mSaleType) << "\n";
output_stream << "\t\tsale_price\t" << mSalePrice << "\n";
output_stream <<"\t}\n";
return true;
}
LLSD LLSaleInfo::asLLSD() const
{
LLSD sd;
const char* type = lookup(mSaleType);
if (!type)
{
LL_WARNS_ONCE() << "Unknown sale type: " << mSaleType << LL_ENDL;
type = lookup(LLSaleInfo::FS_NOT);
}
sd["sale_type"] = type;
sd["sale_price"] = mSalePrice;
return sd;
}
bool LLSaleInfo::fromLLSD(const LLSD& sd, bool& has_perm_mask, U32& perm_mask)
{
const char *w;
if (sd["sale_type"].isString())
{
mSaleType = lookup(sd["sale_type"].asString().c_str());
}
else if(sd["sale_type"].isInteger())
{
S8 type = (U8)sd["sale_type"].asInteger();
mSaleType = static_cast<LLSaleInfo::EForSale>(type);
}
mSalePrice = llclamp(sd["sale_price"].asInteger(), 0, S32_MAX);
w = "perm_mask";
if (sd.has(w))
{
has_perm_mask = true;
perm_mask = ll_U32_from_sd(sd[w]);
}
return true;
}
bool LLSaleInfo::importLegacyStream(std::istream& input_stream, bool& has_perm_mask, U32& perm_mask)
{
has_perm_mask = false;
// *NOTE: Changing the buffer size will require changing the scanf
// calls below.
char buffer[MAX_STRING]; /* Flawfinder: ignore */
char keyword[MAX_STRING]; /* Flawfinder: ignore */
char valuestr[MAX_STRING]; /* Flawfinder: ignore */
bool success = true;
keyword[0] = '\0';
valuestr[0] = '\0';
while(success && input_stream.good())
{
input_stream.getline(buffer, MAX_STRING);
sscanf( /* Flawfinder: ignore */
buffer,
" %254s %254s",
keyword, valuestr);
if(!keyword[0])
{
continue;
}
if(0 == strcmp("{",keyword))
{
continue;
}
if(0 == strcmp("}", keyword))
{
break;
}
else if(0 == strcmp("sale_type", keyword))
{
mSaleType = lookup(valuestr);
}
else if(0 == strcmp("sale_price", keyword))
{
sscanf(valuestr, "%d", &mSalePrice);
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
}
else if (!strcmp("perm_mask", keyword))
{
//LL_INFOS() << "found deprecated keyword perm_mask" << LL_ENDL;
has_perm_mask = true;
sscanf(valuestr, "%x", &perm_mask);
}
else
{
LL_WARNS() << "unknown keyword '" << keyword
<< "' in sale info import" << LL_ENDL;
}
}
return success;
}
void LLSaleInfo::setSalePrice(S32 price)
{
mSalePrice = price;
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
}
LLSD LLSaleInfo::packMessage() const
{
LLSD result;
U8 sale_type = static_cast<U8>(mSaleType);
result["sale-type"] = (U8)sale_type;
result["sale-price"] = (S32)mSalePrice;
//result[_PREHASH_NextOwnerMask] = mNextOwnerPermMask;
return result;
}
void LLSaleInfo::packMessage(LLMessageSystem* msg) const
{
U8 sale_type = static_cast<U8>(mSaleType);
msg->addU8Fast(_PREHASH_SaleType, sale_type);
msg->addS32Fast(_PREHASH_SalePrice, mSalePrice);
//msg->addU32Fast(_PREHASH_NextOwnerMask, mNextOwnerPermMask);
}
void LLSaleInfo::unpackMessage(LLSD sales)
{
U8 sale_type = (U8)sales["sale-type"].asInteger();
mSaleType = static_cast<EForSale>(sale_type);
mSalePrice = (S32)sales["sale-price"].asInteger();
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
//msg->getU32Fast(block, _PREHASH_NextOwnerMask, mNextOwnerPermMask);
}
void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block)
{
U8 sale_type;
msg->getU8Fast(block, _PREHASH_SaleType, sale_type);
mSaleType = static_cast<EForSale>(sale_type);
msg->getS32Fast(block, _PREHASH_SalePrice, mSalePrice);
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
//msg->getU32Fast(block, _PREHASH_NextOwnerMask, mNextOwnerPermMask);
}
void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block,
S32 block_num)
{
U8 sale_type;
msg->getU8Fast(block, _PREHASH_SaleType, sale_type, block_num);
mSaleType = static_cast<EForSale>(sale_type);
msg->getS32Fast(block, _PREHASH_SalePrice, mSalePrice, block_num);
mSalePrice = llclamp(mSalePrice, 0, S32_MAX);
//msg->getU32Fast(block, _PREHASH_NextOwnerMask, mNextOwnerPermMask, block_num);
}
LLSaleInfo::EForSale LLSaleInfo::lookup(const char* name)
{
for(S32 i = 0; i < FS_COUNT; i++)
{
if(0 == strcmp(name, FOR_SALE_NAMES[i]))
{
// match
return (EForSale)i;
}
}
return FS_NOT;
}
const char* LLSaleInfo::lookup(EForSale type)
{
if((type >= 0) && (type < FS_COUNT))
{
return FOR_SALE_NAMES[S32(type)];
}
else
{
return NULL;
}
}
// Allow accumulation of sale info. The price of each is added,
// conflict in sale type results in FS_NOT, and the permissions are
// tightened.
void LLSaleInfo::accumulate(const LLSaleInfo& sale_info)
{
if(mSaleType != sale_info.mSaleType)
{
mSaleType = FS_NOT;
}
mSalePrice += sale_info.mSalePrice;
//mNextOwnerPermMask &= sale_info.mNextOwnerPermMask;
}
bool LLSaleInfo::operator==(const LLSaleInfo &rhs) const
{
return (
(mSaleType == rhs.mSaleType) &&
(mSalePrice == rhs.mSalePrice)
);
}
bool LLSaleInfo::operator!=(const LLSaleInfo &rhs) const
{
return (
(mSaleType != rhs.mSaleType) ||
(mSalePrice != rhs.mSalePrice)
);
}
///----------------------------------------------------------------------------
/// Local function definitions
///----------------------------------------------------------------------------
///----------------------------------------------------------------------------
/// exported functions
///----------------------------------------------------------------------------
static const std::string ST_TYPE_LABEL("sale_type");
static const std::string ST_PRICE_LABEL("sale_price");
LLSD ll_create_sd_from_sale_info(const LLSaleInfo& sale)
{
LLSD rv;
const char* type = LLSaleInfo::lookup(sale.getSaleType());
if(!type) type = LLSaleInfo::lookup(LLSaleInfo::FS_NOT);
rv[ST_TYPE_LABEL] = type;
rv[ST_PRICE_LABEL] = sale.getSalePrice();
return rv;
}
LLSaleInfo ll_sale_info_from_sd(const LLSD& sd)
{
LLSaleInfo rv;
rv.setSaleType(LLSaleInfo::lookup(sd[ST_TYPE_LABEL].asString().c_str()));
rv.setSalePrice(llclamp((S32)sd[ST_PRICE_LABEL], 0, S32_MAX));
return rv;
}
+120
View File
@@ -0,0 +1,120 @@
/**
* @file llsaleinfo.h
* @brief LLSaleInfo class header file.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLSALEINFO_H
#define LL_LLSALEINFO_H
#include "llpermissionsflags.h"
#include "llsd.h"
#include "llxmlnode.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLSaleInfo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// L$ default price for objects
const S32 DEFAULT_PRICE = 10;
class LLMessageSystem;
class LLSaleInfo
{
public:
// use this to avoid temporary object creation
static const LLSaleInfo DEFAULT;
enum EForSale
{
// item is not to be considered for transactions
FS_NOT = 0,
// the origional is on sale
FS_ORIGINAL = 1,
// A copy is for sale
FS_COPY = 2,
// Valid only for tasks, the inventory is for sale
// at the price in this structure.
FS_CONTENTS = 3,
FS_COUNT
};
protected:
EForSale mSaleType;
S32 mSalePrice;
public:
// default constructor is fine usually
LLSaleInfo();
LLSaleInfo(EForSale sale_type, S32 sale_price);
// accessors
bool isForSale() const;
EForSale getSaleType() const { return mSaleType; }
S32 getSalePrice() const { return mSalePrice; }
U32 getCRC32() const;
// mutators
void setSaleType(EForSale type) { mSaleType = type; }
void setSalePrice(S32 price);
//void setNextOwnerPermMask(U32 mask) { mNextOwnerPermMask = mask; }
bool exportLegacyStream(std::ostream& output_stream) const;
LLSD asLLSD() const;
operator LLSD() const { return asLLSD(); }
bool fromLLSD(const LLSD& sd, bool& has_perm_mask, U32& perm_mask);
bool importLegacyStream(std::istream& input_stream, bool& has_perm_mask, U32& perm_mask);
LLSD packMessage() const;
void unpackMessage(LLSD sales);
// message serialization
void packMessage(LLMessageSystem* msg) const;
void unpackMessage(LLMessageSystem* msg, const char* block);
void unpackMultiMessage(LLMessageSystem* msg, const char* block,
S32 block_num);
// static functionality for determine for sale status.
static EForSale lookup(const char* name);
static const char* lookup(EForSale type);
// Allow accumulation of sale info. The price of each is added,
// conflict in sale type results in FS_NOT, and the permissions
// are tightened.
void accumulate(const LLSaleInfo& sale_info);
bool operator==(const LLSaleInfo &rhs) const;
bool operator!=(const LLSaleInfo &rhs) const;
};
// These functions convert between structured data and sale info as
// appropriate for serialization.
LLSD ll_create_sd_from_sale_info(const LLSaleInfo& sale);
LLSaleInfo ll_sale_info_from_sd(const LLSD& sd);
#endif // LL_LLSALEINFO_H
+829
View File
@@ -0,0 +1,829 @@
/**
* @file llsettingsbase.cpp
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llsettingsbase.h"
#include "llmath.h"
#include <algorithm>
#include "llsdserialize.h"
#include <boost/bind.hpp>
//=========================================================================
namespace
{
const LLSettingsBase::TrackPosition BREAK_POINT = 0.5;
}
const LLSettingsBase::TrackPosition LLSettingsBase::INVALID_TRACKPOS(-1.0);
const std::string LLSettingsBase::DEFAULT_SETTINGS_NAME("_default_");
//=========================================================================
std::ostream &operator <<(std::ostream& os, LLSettingsBase &settings)
{
LLSDSerialize::serialize(settings.getSettings(), os, LLSDSerialize::LLSD_NOTATION);
return os;
}
//=========================================================================
const std::string LLSettingsBase::SETTING_ID("id");
const std::string LLSettingsBase::SETTING_NAME("name");
const std::string LLSettingsBase::SETTING_HASH("hash");
const std::string LLSettingsBase::SETTING_TYPE("type");
const std::string LLSettingsBase::SETTING_ASSETID("asset_id");
const std::string LLSettingsBase::SETTING_FLAGS("flags");
const U32 LLSettingsBase::FLAG_NOCOPY(0x01 << 0);
const U32 LLSettingsBase::FLAG_NOMOD(0x01 << 1);
const U32 LLSettingsBase::FLAG_NOTRANS(0x01 << 2);
const U32 LLSettingsBase::FLAG_NOSAVE(0x01 << 3);
const U32 LLSettingsBase::Validator::VALIDATION_PARTIAL(0x01 << 0);
//=========================================================================
LLSettingsBase::LLSettingsBase():
mSettings(LLSD::emptyMap()),
mDirty(true),
mLLSDDirty(true),
mReplaced(false),
mBlendedFactor(0.0),
mSettingFlags(0)
{
}
LLSettingsBase::LLSettingsBase(const LLSD setting) :
mSettings(setting),
mLLSDDirty(true),
mDirty(true),
mReplaced(false),
mBlendedFactor(0.0),
mSettingFlags(0)
{
}
//virtual
void LLSettingsBase::loadValuesFromLLSD()
{
mLLSDDirty = false;
mAssetId = mSettings[SETTING_ASSETID].asUUID();
mSettingId = getValue(SETTING_ID).asUUID();
mSettingName = getValue(SETTING_NAME).asString();
if (mSettings.has(SETTING_FLAGS))
{
mSettingFlags = (U32)mSettings[SETTING_FLAGS].asInteger();
}
else
{
mSettingFlags = 0;
}
}
//virtual
void LLSettingsBase::saveValuesToLLSD()
{
mLLSDDirty = false;
mSettings[SETTING_NAME] = mSettingName;
if (mAssetId.isNull())
{
mSettings.erase(SETTING_ASSETID);
}
else
{
mSettings[SETTING_ASSETID] = mAssetId;
}
mSettings[SETTING_FLAGS] = LLSD::Integer(mSettingFlags);
}
void LLSettingsBase::saveValuesIfNeeded()
{
if (mLLSDDirty)
{
saveValuesToLLSD();
}
}
//=========================================================================
void LLSettingsBase::lerpVector2(LLVector2& a, const LLVector2& b, F32 mix)
{
a.mV[0] = lerp(a.mV[0], b.mV[0], mix);
a.mV[1] = lerp(a.mV[1], b.mV[1], mix);
}
void LLSettingsBase::lerpVector3(LLVector3& a, const LLVector3& b, F32 mix)
{
a.mV[0] = lerp(a.mV[0], b.mV[0], mix);
a.mV[1] = lerp(a.mV[1], b.mV[1], mix);
a.mV[2] = lerp(a.mV[2], b.mV[2], mix);
}
void LLSettingsBase::lerpColor(LLColor3& a, const LLColor3& b, F32 mix)
{
a.mV[0] = lerp(a.mV[0], b.mV[0], mix);
a.mV[1] = lerp(a.mV[1], b.mV[1], mix);
a.mV[2] = lerp(a.mV[2], b.mV[2], mix);
}
LLSD LLSettingsBase::combineSDMaps(const LLSD &settings, const LLSD &other)
{
LLSD newSettings;
for (LLSD::map_const_iterator it = settings.beginMap(); it != settings.endMap(); ++it)
{
std::string key_name = (*it).first;
LLSD value = (*it).second;
LLSD::Type setting_type = value.type();
switch (setting_type)
{
case LLSD::TypeMap:
newSettings[key_name] = combineSDMaps(value, LLSD());
break;
case LLSD::TypeArray:
newSettings[key_name] = LLSD::emptyArray();
for (LLSD::array_const_iterator ita = value.beginArray(); ita != value.endArray(); ++ita)
{
newSettings[key_name].append(*ita);
}
break;
//case LLSD::TypeInteger:
//case LLSD::TypeReal:
//case LLSD::TypeBoolean:
//case LLSD::TypeString:
//case LLSD::TypeUUID:
//case LLSD::TypeURI:
//case LLSD::TypeDate:
//case LLSD::TypeBinary:
default:
newSettings[key_name] = value;
break;
}
}
if (!other.isUndefined())
{
for (LLSD::map_const_iterator it = other.beginMap(); it != other.endMap(); ++it)
{
std::string key_name = (*it).first;
LLSD value = (*it).second;
LLSD::Type setting_type = value.type();
switch (setting_type)
{
case LLSD::TypeMap:
newSettings[key_name] = combineSDMaps(value, LLSD());
break;
case LLSD::TypeArray:
newSettings[key_name] = LLSD::emptyArray();
for (LLSD::array_const_iterator ita = value.beginArray(); ita != value.endArray(); ++ita)
{
newSettings[key_name].append(*ita);
}
break;
//case LLSD::TypeInteger:
//case LLSD::TypeReal:
//case LLSD::TypeBoolean:
//case LLSD::TypeString:
//case LLSD::TypeUUID:
//case LLSD::TypeURI:
//case LLSD::TypeDate:
//case LLSD::TypeBinary:
default:
newSettings[key_name] = value;
break;
}
}
}
return newSettings;
}
LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, F64 mix, const stringset_t& skip, const stringset_t& slerps)
{
LLSD newSettings;
llassert(mix >= 0.0f && mix <= 1.0f);
for (LLSD::map_const_iterator it = settings.beginMap(); it != settings.endMap(); ++it)
{
std::string key_name = (*it).first;
LLSD value = (*it).second;
if (skip.find(key_name) != skip.end())
continue;
LLSD other_value;
if (other.has(key_name))
{
other_value = other[key_name];
}
else
{
parammapping_t::const_iterator def_iter = defaults.find(key_name);
if (def_iter != defaults.end())
{
other_value = def_iter->second.getDefaultValue();
}
else if (value.type() == LLSD::TypeMap)
{
// interpolate in case there are defaults inside (part of legacy)
other_value = LLSDMap();
}
else
{
// The other or defaults does not contain this setting, keep the original value
// TODO: Should I blend this out instead?
newSettings[key_name] = value;
continue;
}
}
newSettings[key_name] = interpolateSDValue(key_name, value, other_value, defaults, mix, skip, slerps);
}
// Special handling cases
// Flags
if (settings.has(SETTING_FLAGS))
{
U32 flags = (U32)settings[SETTING_FLAGS].asInteger();
if (other.has(SETTING_FLAGS))
flags |= (U32)other[SETTING_FLAGS].asInteger();
newSettings[SETTING_FLAGS] = LLSD::Integer(flags);
}
// Now add anything that is in other but not in the settings
for (LLSD::map_const_iterator it = other.beginMap(); it != other.endMap(); ++it)
{
std::string key_name = (*it).first;
if (skip.find(key_name) != skip.end())
continue;
if (settings.has(key_name))
continue;
parammapping_t::const_iterator def_iter = defaults.find(key_name);
if (def_iter != defaults.end())
{
// Blend against default value
newSettings[key_name] = interpolateSDValue(key_name, def_iter->second.getDefaultValue(), (*it).second, defaults, mix, skip, slerps);
}
else if ((*it).second.type() == LLSD::TypeMap)
{
// interpolate in case there are defaults inside (part of legacy)
newSettings[key_name] = interpolateSDValue(key_name, LLSDMap(), (*it).second, defaults, mix, skip, slerps);
}
// else do nothing when no known defaults
// TODO: Should I blend this out instead?
}
// Note: writes variables from skip list, bug?
for (LLSD::map_const_iterator it = other.beginMap(); it != other.endMap(); ++it)
{
// TODO: Should I blend this in instead?
if (skip.find((*it).first) == skip.end())
continue;
if (!settings.has((*it).first))
continue;
newSettings[(*it).first] = (*it).second;
}
return newSettings;
}
LLSD LLSettingsBase::interpolateSDValue(const std::string& key_name, const LLSD &value, const LLSD &other_value, const parammapping_t& defaults, BlendFactor mix, const stringset_t& skip, const stringset_t& slerps)
{
LLSD new_value;
LLSD::Type setting_type = value.type();
if (other_value.type() != setting_type)
{
// The data type mismatched between this and other. Hard switch when we pass the break point
// but issue a warning.
LL_WARNS("SETTINGS") << "Setting lerp between mismatched types for '" << key_name << "'." << LL_ENDL;
new_value = (mix > BREAK_POINT) ? other_value : value;
}
switch (setting_type)
{
case LLSD::TypeInteger:
// lerp between the two values rounding the result to the nearest integer.
new_value = LLSD::Integer(llroundf(lerp((F32)value.asReal(), (F32)other_value.asReal(), (F32)mix)));
break;
case LLSD::TypeReal:
// lerp between the two values.
new_value = LLSD::Real(lerp((F32)value.asReal(), (F32)other_value.asReal(), (F32)mix));
break;
case LLSD::TypeMap:
// deep copy.
new_value = interpolateSDMap(value, other_value, defaults, mix, skip, slerps);
break;
case LLSD::TypeArray:
{
LLSD new_array(LLSD::emptyArray());
if (slerps.find(key_name) != slerps.end())
{
LLQuaternion a(value);
LLQuaternion b(other_value);
LLQuaternion q = slerp((F32)mix, a, b);
new_array = q.getValue();
}
else
{ // TODO: We could expand this to inspect the type and do a deep lerp based on type.
// for now assume a heterogeneous array of reals.
size_t len = std::max(value.size(), other_value.size());
for (size_t i = 0; i < len; ++i)
{
new_array[i] = lerp((F32)value[i].asReal(), (F32)other_value[i].asReal(), (F32)mix);
}
}
new_value = new_array;
}
break;
case LLSD::TypeUUID:
new_value = value.asUUID();
break;
// case LLSD::TypeBoolean:
// case LLSD::TypeString:
// case LLSD::TypeURI:
// case LLSD::TypeBinary:
// case LLSD::TypeDate:
default:
// atomic or unknown data types. Lerping between them does not make sense so switch at the break.
new_value = (mix > BREAK_POINT) ? other_value : value;
break;
}
return new_value;
}
LLSettingsBase::stringset_t LLSettingsBase::getSkipInterpolateKeys() const
{
static stringset_t skipSet;
if (skipSet.empty())
{
skipSet.insert(SETTING_FLAGS);
skipSet.insert(SETTING_HASH);
}
return skipSet;
}
LLSD& LLSettingsBase::getSettings()
{
saveValuesIfNeeded();
return mSettings;
}
LLSD LLSettingsBase::cloneSettings()
{
saveValuesIfNeeded();
LLSD settings(combineSDMaps(getSettings(), LLSD()));
if (U32 flags = getFlags())
{
settings[SETTING_FLAGS] = LLSD::Integer(flags);
}
return settings;
}
size_t LLSettingsBase::getHash()
{ // get a shallow copy of the LLSD filtering out values to not include in the hash
LLSD hash_settings = llsd_shallow(getSettings(),
LLSDMap(SETTING_NAME, false)(SETTING_ID, false)(SETTING_HASH, false)("*", true));
boost::hash<LLSD> hasher;
return hasher(hash_settings);
}
bool LLSettingsBase::validate()
{
validation_list_t validations = getValidationList();
if (!mSettings.has(SETTING_TYPE))
{
mSettings[SETTING_TYPE] = getSettingsType();
}
saveValuesIfNeeded();
LLSD result = LLSettingsBase::settingValidation(mSettings, validations);
loadValuesFromLLSD();
if (result["errors"].size() > 0)
{
LL_WARNS("SETTINGS") << "Validation errors: " << result["errors"] << LL_ENDL;
}
if (result["warnings"].size() > 0)
{
LL_DEBUGS("SETTINGS") << "Validation warnings: " << result["warnings"] << LL_ENDL;
}
return result["success"].asBoolean();
}
LLSD LLSettingsBase::settingValidation(LLSD &settings, validation_list_t &validations, bool partial)
{
static Validator validateName(SETTING_NAME, false, LLSD::TypeString, boost::bind(&Validator::verifyStringLength, _1, _2, 63));
static Validator validateId(SETTING_ID, false, LLSD::TypeUUID);
static Validator validateHash(SETTING_HASH, false, LLSD::TypeInteger);
static Validator validateType(SETTING_TYPE, false, LLSD::TypeString);
static Validator validateAssetId(SETTING_ASSETID, false, LLSD::TypeUUID);
static Validator validateFlags(SETTING_FLAGS, false, LLSD::TypeInteger);
stringset_t validated;
stringset_t strip;
bool isValid(true);
LLSD errors(LLSD::emptyArray());
LLSD warnings(LLSD::emptyArray());
U32 flags(0);
if (partial)
flags |= Validator::VALIDATION_PARTIAL;
// Fields common to all settings.
if (!validateName.verify(settings, flags))
{
errors.append( LLSD::String("Unable to validate 'name'.") );
isValid = false;
}
validated.insert(validateName.getName());
if (!validateId.verify(settings, flags))
{
errors.append( LLSD::String("Unable to validate 'id'.") );
isValid = false;
}
validated.insert(validateId.getName());
if (!validateHash.verify(settings, flags))
{
errors.append( LLSD::String("Unable to validate 'hash'.") );
isValid = false;
}
validated.insert(validateHash.getName());
if (!validateAssetId.verify(settings, flags))
{
errors.append(LLSD::String("Invalid asset Id"));
isValid = false;
}
validated.insert(validateAssetId.getName());
if (!validateType.verify(settings, flags))
{
errors.append( LLSD::String("Unable to validate 'type'.") );
isValid = false;
}
validated.insert(validateType.getName());
if (!validateFlags.verify(settings, flags))
{
errors.append(LLSD::String("Unable to validate 'flags'."));
isValid = false;
}
validated.insert(validateFlags.getName());
// Fields for specific settings.
for (validation_list_t::iterator itv = validations.begin(); itv != validations.end(); ++itv)
{
#ifdef VALIDATION_DEBUG
LLSD oldvalue;
if (settings.has((*itv).getName()))
{
oldvalue = llsd_clone(mSettings[(*itv).getName()]);
}
#endif
if (!(*itv).verify(settings, flags))
{
std::stringstream errtext;
errtext << "Settings LLSD fails validation and could not be corrected for '" << (*itv).getName() << "'!\n";
errors.append( errtext.str() );
isValid = false;
}
validated.insert((*itv).getName());
#ifdef VALIDATION_DEBUG
if (!oldvalue.isUndefined())
{
if (!compare_llsd(settings[(*itv).getName()], oldvalue))
{
LL_WARNS("SETTINGS") << "Setting '" << (*itv).getName() << "' was changed: " << oldvalue << " -> " << settings[(*itv).getName()] << LL_ENDL;
}
}
#endif
}
// strip extra entries
for (LLSD::map_const_iterator itm = settings.beginMap(); itm != settings.endMap(); ++itm)
{
if (validated.find((*itm).first) == validated.end())
{
std::stringstream warntext;
warntext << "Stripping setting '" << (*itm).first << "'";
warnings.append( warntext.str() );
strip.insert((*itm).first);
}
}
for (stringset_t::iterator its = strip.begin(); its != strip.end(); ++its)
{
settings.erase(*its);
}
return LLSDMap("success", LLSD::Boolean(isValid))
("errors", errors)
("warnings", warnings);
}
//=========================================================================
bool LLSettingsBase::Validator::verify(LLSD &data, U32 flags)
{
if (!data.has(mName) || (data.has(mName) && data[mName].isUndefined()))
{
if ((flags & VALIDATION_PARTIAL) != 0) // we are doing a partial validation. Do no attempt to set a default if missing (or fail even if required)
return true;
if (!mDefault.isUndefined())
{
data[mName] = mDefault;
return true;
}
if (mRequired)
LL_WARNS("SETTINGS") << "Missing required setting '" << mName << "' with no default." << LL_ENDL;
return !mRequired;
}
if (data[mName].type() != mType)
{
LL_WARNS("SETTINGS") << "Setting '" << mName << "' is incorrect type." << LL_ENDL;
return false;
}
if (!mVerify.empty() && !mVerify(data[mName], flags))
{
LL_WARNS("SETTINGS") << "Setting '" << mName << "' fails validation." << LL_ENDL;
return false;
}
return true;
}
bool LLSettingsBase::Validator::verifyColor(LLSD &value, U32)
{
return (value.size() == 3 || value.size() == 4);
}
bool LLSettingsBase::Validator::verifyVector(LLSD &value, U32, S32 length)
{
return (value.size() == length);
}
bool LLSettingsBase::Validator::verifyVectorNormalized(LLSD &value, U32, S32 length)
{
if (value.size() != length)
return false;
LLSD newvector;
switch (length)
{
case 2:
{
LLVector2 vect(value);
if (is_approx_equal(vect.normalize(), 1.0f))
return true;
newvector = vect.getValue();
break;
}
case 3:
{
LLVector3 vect(value);
if (is_approx_equal(vect.normalize(), 1.0f))
return true;
newvector = vect.getValue();
break;
}
case 4:
{
LLVector4 vect(value);
if (is_approx_equal(vect.normalize(), 1.0f))
return true;
newvector = vect.getValue();
break;
}
default:
return false;
}
return true;
}
bool LLSettingsBase::Validator::verifyVectorMinMax(LLSD &value, U32, LLSD minvals, LLSD maxvals)
{
for (S32 index = 0; index < value.size(); ++index)
{
if (minvals[index].asString() != "*")
{
if (minvals[index].asReal() > value[index].asReal())
{
value[index] = minvals[index].asReal();
}
}
if (maxvals[index].asString() != "*")
{
if (maxvals[index].asReal() < value[index].asReal())
{
value[index] = maxvals[index].asReal();
}
}
}
return true;
}
bool LLSettingsBase::Validator::verifyQuaternion(LLSD &value, U32)
{
return (value.size() == 4);
}
bool LLSettingsBase::Validator::verifyQuaternionNormal(LLSD &value, U32)
{
if (value.size() != 4)
return false;
LLQuaternion quat(value);
if (is_approx_equal(quat.normalize(), 1.0f))
return true;
LLSD newquat = quat.getValue();
for (S32 index = 0; index < 4; ++index)
{
value[index] = newquat[index];
}
return true;
}
bool LLSettingsBase::Validator::verifyFloatRange(LLSD &value, U32, LLSD range)
{
F64 real = value.asReal();
F64 clampedval = llclamp(LLSD::Real(real), range[0].asReal(), range[1].asReal());
if (is_approx_equal(clampedval, real))
return true;
value = LLSD::Real(clampedval);
return true;
}
bool LLSettingsBase::Validator::verifyIntegerRange(LLSD &value, U32, LLSD range)
{
S32 ival = value.asInteger();
S32 clampedval = llclamp(LLSD::Integer(ival), range[0].asInteger(), range[1].asInteger());
if (clampedval == ival)
return true;
value = LLSD::Integer(clampedval);
return true;
}
bool LLSettingsBase::Validator::verifyStringLength(LLSD &value, U32, S32 length)
{
std::string sval = value.asString();
if (!sval.empty())
{
sval = sval.substr(0, length);
value = LLSD::String(sval);
}
return true;
}
//=========================================================================
void LLSettingsBlender::update(const LLSettingsBase::BlendFactor& blendf)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
F64 res = setBlendFactor(blendf);
llassert(res >= 0.0 && res <= 1.0);
(void)res;
// <FS:Beq> FIRE-34805 another issue with missing EEP on or shortly after login.
// Ideally we'll find the true fix at a higher level. But for now fix the symptom.
// mTarget->update();
if(mTarget)
{
mTarget->update();
}
// </FS:Beq>
}
F64 LLSettingsBlender::setBlendFactor(const LLSettingsBase::BlendFactor& blendf_in)
{
LLSettingsBase::TrackPosition blendf = (F32)blendf_in;
llassert(!isnan(blendf));
if (blendf >= 1.0)
{
triggerComplete();
}
blendf = llclamp(blendf, 0.0f, 1.0f);
if (mTarget)
{
mTarget->replaceSettings(mInitial);
mTarget->blend(mFinal, blendf);
}
else
{
LL_WARNS("SETTINGS") << "No target for settings blender." << LL_ENDL;
}
return blendf;
}
void LLSettingsBlender::triggerComplete()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
if (mTarget)
mTarget->replaceSettings(mFinal);
LLSettingsBlender::ptr_t hold = shared_from_this(); // prevents this from deleting too soon
mTarget->update();
mOnFinished(shared_from_this());
}
//-------------------------------------------------------------------------
const LLSettingsBase::BlendFactor LLSettingsBlenderTimeDelta::MIN_BLEND_DELTA(FLT_EPSILON);
LLSettingsBase::BlendFactor LLSettingsBlenderTimeDelta::calculateBlend(const LLSettingsBase::TrackPosition& spanpos, const LLSettingsBase::TrackPosition& spanlen) const
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
return LLSettingsBase::BlendFactor(fmod((F64)spanpos, (F64)spanlen) / (F64)spanlen);
}
bool LLSettingsBlenderTimeDelta::applyTimeDelta(const LLSettingsBase::Seconds& timedelta)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
mTimeSpent += timedelta;
if (mTimeSpent > mBlendSpan)
{
triggerComplete();
return false;
}
LLSettingsBase::BlendFactor blendf = calculateBlend((F32)mTimeSpent.value(), mBlendSpan);
if (fabs(mLastBlendF - blendf) < mBlendFMinDelta)
{
return false;
}
mLastBlendF = blendf;
update(blendf);
return true;
}
+543
View File
@@ -0,0 +1,543 @@
/**
* @file llsettingsbase.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_SETTINGS_BASE_H
#define LL_SETTINGS_BASE_H
#include <string>
#include <map>
#include <vector>
#include <boost/signals2.hpp>
#include "llsd.h"
#include "llsdutil.h"
#include "v2math.h"
#include "v3math.h"
#include "v4math.h"
#include "llquaternion.h"
#include "v4color.h"
#include "v3color.h"
#include "llunits.h"
#include "llinventorysettings.h"
#define PTR_NAMESPACE std
#define SETTINGS_OVERRIDE override
class LLSettingsBase :
public PTR_NAMESPACE::enable_shared_from_this<LLSettingsBase>,
private boost::noncopyable
{
friend class LLEnvironment;
friend class LLSettingsDay;
friend std::ostream &operator <<(std::ostream& os, LLSettingsBase &settings);
protected:
LOG_CLASS(LLSettingsBase);
public:
typedef F64Seconds Seconds;
typedef F64 BlendFactor;
typedef F32 TrackPosition; // 32-bit as these are stored in LLSD as such
static const TrackPosition INVALID_TRACKPOS;
static const std::string DEFAULT_SETTINGS_NAME;
static const std::string SETTING_ID;
static const std::string SETTING_NAME;
static const std::string SETTING_HASH;
static const std::string SETTING_TYPE;
static const std::string SETTING_ASSETID;
static const std::string SETTING_FLAGS;
static const U32 FLAG_NOCOPY;
static const U32 FLAG_NOMOD;
static const U32 FLAG_NOTRANS;
static const U32 FLAG_NOSAVE;
class DefaultParam
{
public:
DefaultParam(S32 key, const LLSD& value) : mShaderKey(key), mDefaultValue(value) {}
DefaultParam() : mShaderKey(-1) {}
S32 getShaderKey() const { return mShaderKey; }
const LLSD getDefaultValue() const { return mDefaultValue; }
private:
S32 mShaderKey;
LLSD mDefaultValue;
};
// Contains settings' names (map key), related shader id-key and default
// value for revert in case we need to reset shader (no need to search each time)
typedef std::map<std::string, DefaultParam> parammapping_t;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsBase> ptr_t;
virtual ~LLSettingsBase() { };
//---------------------------------------------------------------------
virtual std::string getSettingsType() const = 0;
virtual LLSettingsType::type_e getSettingsTypeValue() const = 0;
//---------------------------------------------------------------------
// Settings status
inline bool hasSetting(const std::string &param) const { return mSettings.has(param); }
virtual bool isDirty() const { return mDirty; }
virtual bool isVeryDirty() const { return mReplaced; }
inline void setDirtyFlag(bool dirty) { mDirty = dirty; clearAssetId(); }
inline void setReplaced() { mReplaced = true; }
size_t getHash(); // Hash will not include Name, ID or a previously stored Hash
inline LLUUID getId() const
{
return mSettingId;
}
inline std::string getName() const
{
return mSettingName;
}
inline void setName(std::string val)
{
mSettingName = val;
setDirtyFlag(true);
setLLSDDirty();
}
inline LLUUID getAssetId() const
{
return mAssetId;
}
inline U32 getFlags() const
{
return mSettingFlags;
}
inline void setFlags(U32 value)
{
mSettingFlags = value;
setDirtyFlag(true);
setLLSDDirty();
}
inline bool getFlag(U32 flag) const
{
return (mSettingFlags & flag) == flag;
}
inline void setFlag(U32 flag)
{
mSettingFlags |= flag;
setLLSDDirty();
}
inline void clearFlag(U32 flag)
{
mSettingFlags &= ~flag;
setLLSDDirty();
}
virtual void replaceSettings(LLSD settings)
{
mBlendedFactor = 0.0;
setDirtyFlag(true);
mReplaced = true;
mSettings = settings;
loadValuesFromLLSD();
}
virtual void replaceSettings(const ptr_t& other)
{
mBlendedFactor = 0.0;
setDirtyFlag(true);
mReplaced = true;
mSettingFlags = other->getFlags();
mSettingName = other->getName();
mSettingId = other->getId();
mAssetId = other->getAssetId();
setLLSDDirty();
}
void setSettings(LLSD settings)
{
setDirtyFlag(true);
mSettings = settings;
loadValuesFromLLSD();
}
// if you are using getSettings to edit them, call setSettings(settings),
// replaceSettings(settings) or loadValuesFromLLSD() afterwards
virtual LLSD& getSettings();
virtual void setLLSDDirty()
{
mLLSDDirty = true;
}
//---------------------------------------------------------------------
//
inline void setLLSD(const std::string &name, const LLSD &value)
{
saveValuesIfNeeded();
mSettings[name] = value;
mDirty = true;
if (name != SETTING_ASSETID)
clearAssetId();
}
inline void setValue(const std::string &name, const LLSD &value)
{
setLLSD(name, value);
}
inline LLSD getValue(const std::string &name, const LLSD &deflt = LLSD())
{
saveValuesIfNeeded();
if (!mSettings.has(name))
return deflt;
return mSettings[name];
}
inline void setValue(const std::string &name, F32 v)
{
setLLSD(name, LLSD::Real(v));
}
inline void setValue(const std::string &name, const LLVector2 &value)
{
setValue(name, value.getValue());
}
inline void setValue(const std::string &name, const LLVector3 &value)
{
setValue(name, value.getValue());
}
inline void setValue(const std::string &name, const LLVector4 &value)
{
setValue(name, value.getValue());
}
inline void setValue(const std::string &name, const LLQuaternion &value)
{
setValue(name, value.getValue());
}
inline void setValue(const std::string &name, const LLColor3 &value)
{
setValue(name, value.getValue());
}
inline void setValue(const std::string &name, const LLColor4 &value)
{
setValue(name, value.getValue());
}
inline BlendFactor getBlendFactor() const
{
return mBlendedFactor;
}
// Note this method is marked const but may modify the settings object.
// (note the internal const cast). This is so that it may be called without
// special consideration from getters.
inline void update() const
{
if ((!mDirty) && (!mReplaced))
return;
(const_cast<LLSettingsBase *>(this))->updateSettings();
}
virtual void blend(ptr_t &end, BlendFactor blendf) = 0;
virtual bool validate();
virtual ptr_t buildDerivedClone() = 0;
class Validator
{
public:
static const U32 VALIDATION_PARTIAL;
typedef boost::function<bool(LLSD &, U32)> verify_pr;
Validator(std::string name, bool required, LLSD::Type type, verify_pr verify = verify_pr(), LLSD defval = LLSD()) :
mName(name),
mRequired(required),
mType(type),
mVerify(verify),
mDefault(defval)
{ }
std::string getName() const { return mName; }
bool isRequired() const { return mRequired; }
LLSD::Type getType() const { return mType; }
bool verify(LLSD &data, U32 flags);
// Some basic verifications
static bool verifyColor(LLSD &value, U32 flags);
static bool verifyVector(LLSD &value, U32 flags, S32 length);
static bool verifyVectorMinMax(LLSD &value, U32 flags, LLSD minvals, LLSD maxvals);
static bool verifyVectorNormalized(LLSD &value, U32 flags, S32 length);
static bool verifyQuaternion(LLSD &value, U32 flags);
static bool verifyQuaternionNormal(LLSD &value, U32 flags);
static bool verifyFloatRange(LLSD &value, U32 flags, LLSD range);
static bool verifyIntegerRange(LLSD &value, U32 flags, LLSD range);
static bool verifyStringLength(LLSD &value, U32 flags, S32 length);
private:
std::string mName;
bool mRequired;
LLSD::Type mType;
verify_pr mVerify;
LLSD mDefault;
};
typedef std::vector<Validator> validation_list_t;
static LLSD settingValidation(LLSD &settings, validation_list_t &validations, bool partial = false);
inline void setAssetId(LLUUID value)
{ // note that this skips setLLSD
mAssetId = value;
mLLSDDirty = true;
}
inline void clearAssetId()
{
mAssetId.setNull();
mLLSDDirty = true;
}
// Calculate any custom settings that may need to be cached.
virtual void updateSettings() { mDirty = false; mReplaced = false; }
LLSD cloneSettings();
static void lerpVector2(LLVector2& a, const LLVector2& b, F32 mix);
static void lerpVector3(LLVector3& a, const LLVector3& b, F32 mix);
static void lerpColor(LLColor3& a, const LLColor3& b, F32 mix);
protected:
LLSettingsBase();
LLSettingsBase(const LLSD setting);
typedef std::set<std::string> stringset_t;
// combining settings maps where it can based on mix rate
// @settings initial value (mix==0)
// @other target value (mix==1)
// @defaults list of default values for legacy fields and (re)setting shaders
// @mix from 0 to 1, ratio or rate of transition from initial 'settings' to 'other'
// return interpolated and combined LLSD map
static LLSD interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& skip, const stringset_t& slerps);
static LLSD interpolateSDValue(const std::string& name, const LLSD &value, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& skip, const stringset_t& slerps);
/// when lerping between settings, some may require special handling.
/// Get a list of these key to be skipped by the default settings lerp.
/// (handling should be performed in the override of lerpSettings.
virtual stringset_t getSkipInterpolateKeys() const;
// A list of settings that represent quaternions and should be slerped
// rather than lerped.
virtual stringset_t getSlerpKeys() const { return stringset_t(); }
virtual validation_list_t getValidationList() const = 0;
// Apply settings.
virtual void applyToUniforms(void *) { };
virtual void applySpecial(void*, bool force = false) { };
virtual parammapping_t getParameterMap() const { return parammapping_t(); }
inline void setBlendFactor(BlendFactor blendfactor)
{
mBlendedFactor = blendfactor;
}
virtual void replaceWith(const LLSettingsBase::ptr_t other)
{
replaceSettings(other);
setBlendFactor(other->getBlendFactor());
}
virtual void loadValuesFromLLSD();
virtual void saveValuesToLLSD();
void saveValuesIfNeeded();
LLUUID mAssetId;
LLUUID mSettingId;
std::string mSettingName;
U32 mSettingFlags;
private:
bool mLLSDDirty;
bool mDirty;
bool mReplaced; // super dirty!
static LLSD combineSDMaps(const LLSD &first, const LLSD &other);
LLSD mSettings;
BlendFactor mBlendedFactor;
};
class LLSettingsBlender : public PTR_NAMESPACE::enable_shared_from_this<LLSettingsBlender>
{
LOG_CLASS(LLSettingsBlender);
public:
typedef PTR_NAMESPACE::shared_ptr<LLSettingsBlender> ptr_t;
typedef boost::signals2::signal<void(const ptr_t )> finish_signal_t;
typedef boost::signals2::connection connection_t;
LLSettingsBlender(const LLSettingsBase::ptr_t &target,
const LLSettingsBase::ptr_t &initsetting, const LLSettingsBase::ptr_t &endsetting) :
mOnFinished(),
mTarget(target),
mInitial(initsetting),
mFinal(endsetting)
{
if (mInitial && mTarget)
mTarget->replaceSettings(mInitial->getSettings());
if (!mFinal)
mFinal = mInitial;
}
virtual ~LLSettingsBlender() {}
virtual void reset( LLSettingsBase::ptr_t &initsetting, const LLSettingsBase::ptr_t &endsetting, const LLSettingsBase::TrackPosition&)
{
// note: the 'span' reset parameter is unused by the base class.
if (!mInitial)
LL_WARNS("BLENDER") << "Reseting blender with empty initial setting. Expect badness in the future." << LL_ENDL;
mInitial = initsetting;
mFinal = endsetting;
if (!mFinal)
mFinal = mInitial;
if (mTarget)
mTarget->replaceSettings(mInitial->getSettings());
}
LLSettingsBase::ptr_t getTarget() const
{
return mTarget;
}
LLSettingsBase::ptr_t getInitial() const
{
return mInitial;
}
LLSettingsBase::ptr_t getFinal() const
{
return mFinal;
}
connection_t setOnFinished(const finish_signal_t::slot_type &onfinished)
{
return mOnFinished.connect(onfinished);
}
virtual void update(const LLSettingsBase::BlendFactor& blendf);
virtual bool applyTimeDelta(const LLSettingsBase::Seconds& timedelta)
{
llassert(false);
// your derived class needs to implement an override of this func
return false;
}
virtual F64 setBlendFactor(const LLSettingsBase::BlendFactor& position);
virtual void switchTrack(S32 trackno, const LLSettingsBase::TrackPosition& position) { /*NoOp*/ }
protected:
void triggerComplete();
finish_signal_t mOnFinished;
LLSettingsBase::ptr_t mTarget;
LLSettingsBase::ptr_t mInitial;
LLSettingsBase::ptr_t mFinal;
};
class LLSettingsBlenderTimeDelta : public LLSettingsBlender
{
protected:
LOG_CLASS(LLSettingsBlenderTimeDelta);
public:
static const LLSettingsBase::BlendFactor MIN_BLEND_DELTA;
LLSettingsBlenderTimeDelta(const LLSettingsBase::ptr_t &target,
const LLSettingsBase::ptr_t &initsetting, const LLSettingsBase::ptr_t &endsetting, const LLSettingsBase::Seconds& blend_span) :
LLSettingsBlender(target, initsetting, endsetting),
mBlendSpan((F32)blend_span.value()),
mLastUpdate(0.0f),
mTimeSpent(0.0f),
mBlendFMinDelta(MIN_BLEND_DELTA),
mLastBlendF(-1.0f)
{
mTimeStart = LLSettingsBase::Seconds(LLDate::now().secondsSinceEpoch());
mLastUpdate = mTimeStart;
}
virtual ~LLSettingsBlenderTimeDelta()
{
}
virtual void reset(LLSettingsBase::ptr_t &initsetting, const LLSettingsBase::ptr_t &endsetting, const LLSettingsBase::TrackPosition& blend_span) SETTINGS_OVERRIDE
{
LLSettingsBlender::reset(initsetting, endsetting, blend_span);
mBlendSpan = blend_span;
mTimeStart = LLSettingsBase::Seconds(LLDate::now().secondsSinceEpoch());
mLastUpdate = mTimeStart;
mTimeSpent = LLSettingsBase::Seconds(0.0f);
mLastBlendF = LLSettingsBase::BlendFactor(-1.0f);
}
virtual bool applyTimeDelta(const LLSettingsBase::Seconds& timedelta) SETTINGS_OVERRIDE;
inline void setTimeSpent(LLSettingsBase::Seconds time) { mTimeSpent = time; }
protected:
LLSettingsBase::BlendFactor calculateBlend(const LLSettingsBase::TrackPosition& spanpos, const LLSettingsBase::TrackPosition& spanlen) const;
LLSettingsBase::TrackPosition mBlendSpan;
LLSettingsBase::Seconds mLastUpdate;
LLSettingsBase::Seconds mTimeSpent;
LLSettingsBase::Seconds mTimeStart;
LLSettingsBase::BlendFactor mBlendFMinDelta;
LLSettingsBase::BlendFactor mLastBlendF;
};
#endif
+908
View File
@@ -0,0 +1,908 @@
/**
* @file llsettingsdaycycle.cpp
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llsettingsdaycycle.h"
#include "llerror.h"
#include <algorithm>
#include "lltrace.h"
#include "llfasttimer.h"
#include "v3colorutil.h"
#include "llsettingssky.h"
#include "llsettingswater.h"
#include "llframetimer.h"
//=========================================================================
namespace
{
template<typename T>
inline T get_wrapping_distance(T begin, T end)
{
if (begin < end)
{
return end - begin;
}
else if (begin > end)
{
return T(1.0) - (begin - end);
}
return 0;
}
LLSettingsDay::CycleTrack_t::iterator get_wrapping_atafter(LLSettingsDay::CycleTrack_t &collection, const LLSettingsBase::TrackPosition& key)
{
if (collection.empty())
return collection.end();
LLSettingsDay::CycleTrack_t::iterator it = collection.upper_bound(key);
if (it == collection.end())
{ // wrap around
it = collection.begin();
}
return it;
}
LLSettingsDay::CycleTrack_t::iterator get_wrapping_atbefore(LLSettingsDay::CycleTrack_t &collection, const LLSettingsBase::TrackPosition& key)
{
if (collection.empty())
return collection.end();
LLSettingsDay::CycleTrack_t::iterator it = collection.lower_bound(key);
if (it == collection.end())
{ // all keyframes are lower, take the last one.
--it; // we know the range is not empty
}
else if ((*it).first > key)
{ // the keyframe we are interested in is smaller than the found.
if (it == collection.begin())
it = collection.end();
--it;
}
return it;
}
}
//=========================================================================
const std::string LLSettingsDay::SETTING_KEYID("key_id");
const std::string LLSettingsDay::SETTING_KEYNAME("key_name");
const std::string LLSettingsDay::SETTING_KEYKFRAME("key_keyframe");
const std::string LLSettingsDay::SETTING_KEYHASH("key_hash");
const std::string LLSettingsDay::SETTING_TRACKS("tracks");
const std::string LLSettingsDay::SETTING_FRAMES("frames");
const LLSettingsDay::Seconds LLSettingsDay::MINIMUM_DAYLENGTH(14400); // 4 hours
const LLSettingsDay::Seconds LLSettingsDay::DEFAULT_DAYLENGTH(14400); // 4 hours
const LLSettingsDay::Seconds LLSettingsDay::MAXIMUM_DAYLENGTH(604800); // 7 days
const LLSettingsDay::Seconds LLSettingsDay::MINIMUM_DAYOFFSET(0);
const LLSettingsDay::Seconds LLSettingsDay::DEFAULT_DAYOFFSET(57600); // +16 hours == -8 hours (SLT time offset)
const LLSettingsDay::Seconds LLSettingsDay::MAXIMUM_DAYOFFSET(86400); // 24 hours
const LLSettingsDay::Seconds LLSettingsDay::INVALID_DAYOFFSET(-1); // KC
const U32 LLSettingsDay::TRACK_WATER(0); // water track is 0
const U32 LLSettingsDay::TRACK_GROUND_LEVEL(1);
const U32 LLSettingsDay::TRACK_MAX(5); // 5 tracks, 4 skys, 1 water
const U32 LLSettingsDay::FRAME_MAX(56);
const F32 LLSettingsDay::DEFAULT_FRAME_SLOP_FACTOR(0.02501f);
const LLUUID LLSettingsDay::DEFAULT_ASSET_ID("5646d39e-d3d7-6aff-ed71-30fc87d64a91");
// Minimum value to prevent multislider in edit floaters from eating up frames that 'encroach' on one another's space
static const F32 DEFAULT_MULTISLIDER_INCREMENT(0.005f);
//=========================================================================
LLSettingsDay::LLSettingsDay(const LLSD &data) :
LLSettingsBase(data),
mInitialized(false),
mDaySettings(LLSD::emptyMap())
{
mDayTracks.resize(TRACK_MAX);
loadValuesFromLLSD();
}
LLSettingsDay::LLSettingsDay() :
LLSettingsBase(),
mInitialized(false),
mDaySettings(LLSD::emptyMap())
{
mDayTracks.resize(TRACK_MAX);
replaceSettings(defaults());
}
//=========================================================================
LLSD& LLSettingsDay::getSettings()
{
mDaySettings = LLSD::emptyMap();
LLSD& settings = LLSettingsBase::getSettings();
if (settings.has(SETTING_NAME))
mDaySettings[SETTING_NAME] = settings[SETTING_NAME];
if (settings.has(SETTING_ID))
mDaySettings[SETTING_ID] = settings[SETTING_ID];
if (settings.has(SETTING_ASSETID))
mDaySettings[SETTING_ASSETID] = settings[SETTING_ASSETID];
mDaySettings[SETTING_TYPE] = getSettingsType();
std::map<std::string, LLSettingsBase::ptr_t> in_use;
LLSD tracks(LLSD::emptyArray());
for (CycleList_t::const_iterator itTrack = mDayTracks.begin(); itTrack != mDayTracks.end(); ++itTrack)
{
LLSD trackout(LLSD::emptyArray());
for (CycleTrack_t::const_iterator itFrame = (*itTrack).begin(); itFrame != (*itTrack).end(); ++itFrame)
{
F32 frame = (*itFrame).first;
LLSettingsBase::ptr_t data = (*itFrame).second;
size_t datahash = data->getHash();
std::stringstream keyname;
keyname << datahash;
trackout.append(LLSD(LLSDMap(SETTING_KEYKFRAME, LLSD::Real(frame))(SETTING_KEYNAME, keyname.str())));
in_use[keyname.str()] = data;
}
tracks.append(trackout);
}
mDaySettings[SETTING_TRACKS] = tracks;
LLSD frames(LLSD::emptyMap());
for (std::map<std::string, LLSettingsBase::ptr_t>::iterator itFrame = in_use.begin(); itFrame != in_use.end(); ++itFrame)
{
LLSD framesettings = llsd_clone((*itFrame).second->getSettings(),
LLSDMap("*", true)(SETTING_NAME, false)(SETTING_ID, false)(SETTING_HASH, false));
frames[(*itFrame).first] = framesettings;
}
mDaySettings[SETTING_FRAMES] = frames;
return mDaySettings;
}
void LLSettingsDay::setLLSDDirty()
{
mDaySettings = LLSD::emptyMap();
LLSettingsBase::setLLSDDirty();
}
bool LLSettingsDay::initialize(bool validate_frames)
{
LLSD tracks = mSettings[SETTING_TRACKS];
LLSD frames = mSettings[SETTING_FRAMES];
// save for later...
LLUUID assetid;
if (mSettings.has(SETTING_ASSETID))
{
assetid = mSettings[SETTING_ASSETID].asUUID();
}
std::map<std::string, LLSettingsBase::ptr_t> used;
for (LLSD::map_const_iterator itFrame = frames.beginMap(); itFrame != frames.endMap(); ++itFrame)
{
std::string name = (*itFrame).first;
LLSD data = (*itFrame).second;
LLSettingsBase::ptr_t keyframe;
if (data[SETTING_TYPE].asString() == "sky")
{
keyframe = buildSky(data);
}
else if (data[SETTING_TYPE].asString() == "water")
{
keyframe = buildWater(data);
}
else
{
LL_WARNS("DAYCYCLE") << "Unknown child setting type '" << data[SETTING_TYPE].asString() << "' named '" << name << "'" << LL_ENDL;
}
if (!keyframe)
{
LL_WARNS("DAYCYCLE") << "Invalid frame data" << LL_ENDL;
continue;
}
used[name] = keyframe;
}
bool haswater(false);
bool hassky(false);
for (S32 i = 0; (i < tracks.size()) && (i < TRACK_MAX); ++i)
{
mDayTracks[i].clear();
LLSD curtrack = tracks[i];
for (LLSD::array_const_iterator it = curtrack.beginArray(); it != curtrack.endArray(); ++it)
{
LLSettingsBase::TrackPosition keyframe = LLSettingsBase::TrackPosition((*it)[SETTING_KEYKFRAME].asReal());
keyframe = llclamp(keyframe, 0.0f, 1.0f);
LLSettingsBase::ptr_t setting;
if ((*it).has(SETTING_KEYNAME))
{
std::string key_name = (*it)[SETTING_KEYNAME];
if (i == TRACK_WATER)
{
setting = used[key_name];
if (setting && setting->getSettingsType() != "water")
{
LL_WARNS("DAYCYCLE") << "Water track referencing " << setting->getSettingsType() << " frame at " << keyframe << "." << LL_ENDL;
setting.reset();
}
}
else
{
setting = used[key_name];
if (setting && setting->getSettingsType() != "sky")
{
LL_WARNS("DAYCYCLE") << "Sky track #" << i << " referencing " << setting->getSettingsType() << " frame at " << keyframe << "." << LL_ENDL;
setting.reset();
}
}
}
if (setting)
{
if (i == TRACK_WATER)
haswater |= true;
else
hassky |= true;
if (validate_frames && mDayTracks[i].size() > 0)
{
// check if we hit close to anything in the list
LLSettingsDay::CycleTrack_t::value_type frame = getSettingsNearKeyframe(keyframe, i, DEFAULT_FRAME_SLOP_FACTOR);
if (frame.second)
{
// figure out direction of search
LLSettingsBase::TrackPosition found = frame.first;
LLSettingsBase::TrackPosition new_frame = keyframe;
F32 total_frame_shift = 0;
// We consider frame DEFAULT_FRAME_SLOP_FACTOR away as still encroaching, so add minimum increment
F32 move_factor = DEFAULT_FRAME_SLOP_FACTOR + DEFAULT_MULTISLIDER_INCREMENT;
bool move_forward = true;
if ((new_frame < found && (found - new_frame) <= DEFAULT_FRAME_SLOP_FACTOR)
|| (new_frame > found && (new_frame - found) > DEFAULT_FRAME_SLOP_FACTOR))
{
move_forward = false;
}
if (move_forward)
{
CycleTrack_t::iterator iter = mDayTracks[i].find(found);
new_frame = found; // for total_frame_shift
while (total_frame_shift < 1)
{
// calculate shifted position from previous found point
total_frame_shift += move_factor + (found >= new_frame ? found : found + 1) - new_frame;
new_frame = found + move_factor;
if (new_frame > 1) new_frame--;
// we know that current point is too close, go for next one
iter++;
if (iter == mDayTracks[i].end())
{
iter = mDayTracks[i].begin();
}
if (((iter->first >= (new_frame - DEFAULT_MULTISLIDER_INCREMENT)) && ((new_frame + DEFAULT_FRAME_SLOP_FACTOR) >= iter->first))
|| ((iter->first < new_frame) && ((new_frame + DEFAULT_FRAME_SLOP_FACTOR) >= (iter->first + 1))))
{
// we are encroaching at new point as well
found = iter->first;
}
else // (new_frame + DEFAULT_FRAME_SLOP_FACTOR < iter->first)
{
//we found clear spot
break;
}
}
}
else
{
CycleTrack_t::reverse_iterator iter = mDayTracks[i].rbegin();
while (iter->first != found)
{
iter++;
}
new_frame = found; // for total_frame_shift
while (total_frame_shift < 1)
{
// calculate shifted position from current found point
total_frame_shift += move_factor + new_frame - (found <= new_frame ? found : found - 1);
new_frame = found - move_factor;
if (new_frame < 0) new_frame++;
// we know that current point is too close, go for next one
iter++;
if (iter == mDayTracks[i].rend())
{
iter = mDayTracks[i].rbegin();
}
if ((iter->first <= (new_frame + DEFAULT_MULTISLIDER_INCREMENT) && (new_frame - DEFAULT_FRAME_SLOP_FACTOR) <= iter->first)
|| ((iter->first > new_frame) && ((new_frame - DEFAULT_FRAME_SLOP_FACTOR) <= (iter->first - 1))))
{
// we are encroaching at new point as well
found = iter->first;
}
else // (new_frame - DEFAULT_FRAME_SLOP_FACTOR > iter->first)
{
//we found clear spot
break;
}
}
}
if (total_frame_shift >= 1)
{
LL_WARNS("SETTINGS") << "Could not fix frame position, adding as is to position: " << keyframe << LL_ENDL;
}
else
{
// Mark as new position
keyframe = new_frame;
}
}
}
mDayTracks[i][keyframe] = setting;
}
}
}
if (!haswater || !hassky)
{
LL_WARNS("DAYCYCLE") << "Must have at least one water and one sky frame!" << LL_ENDL;
return false;
}
// these are no longer needed and just take up space now.
mSettings.erase(SETTING_TRACKS);
mSettings.erase(SETTING_FRAMES);
if (!assetid.isNull())
{
mSettings[SETTING_ASSETID] = assetid;
}
loadValuesFromLLSD();
mInitialized = true;
return true;
}
//=========================================================================
LLSD LLSettingsDay::defaults()
{
static LLSD dfltsetting;
if (dfltsetting.size() == 0)
{
dfltsetting[SETTING_NAME] = DEFAULT_SETTINGS_NAME;
dfltsetting[SETTING_TYPE] = "daycycle";
LLSD frames(LLSD::emptyMap());
LLSD waterTrack;
LLSD skyTrack;
const U32 FRAME_COUNT = 8;
const F32 FRAME_STEP = 1.0f / F32(FRAME_COUNT);
F32 time = 0.0f;
for (U32 i = 0; i < FRAME_COUNT; i++)
{
std::string name(DEFAULT_SETTINGS_NAME);
name += ('a' + i);
std::string water_frame_name("water:");
std::string sky_frame_name("sky:");
water_frame_name += name;
sky_frame_name += name;
waterTrack[SETTING_KEYKFRAME] = time;
waterTrack[SETTING_KEYNAME] = water_frame_name;
skyTrack[SETTING_KEYKFRAME] = time;
skyTrack[SETTING_KEYNAME] = sky_frame_name;
frames[water_frame_name] = LLSettingsWater::defaults(time);
frames[sky_frame_name] = LLSettingsSky::defaults(time);
time += FRAME_STEP;
}
LLSD tracks;
tracks.append(llsd::array(waterTrack));
tracks.append(llsd::array(skyTrack));
dfltsetting[SETTING_TRACKS] = tracks;
dfltsetting[SETTING_FRAMES] = frames;
}
return dfltsetting;
}
void LLSettingsDay::blend(LLSettingsBase::ptr_t &other, F64 mix)
{
LL_ERRS("DAYCYCLE") << "Day cycles are not blendable!" << LL_ENDL;
}
namespace
{
bool validateDayCycleTrack(LLSD &value, U32 flags)
{
// Trim extra tracks.
while (value.size() > LLSettingsDay::TRACK_MAX)
{
value.erase(static_cast<LLSD::Integer>(value.size()) - 1);
}
S32 framecount(0);
for (LLSD::array_iterator track = value.beginArray(); track != value.endArray(); ++track)
{
S32 index = 0;
while (index < (*track).size())
{
LLSD& elem = (*track)[index];
++framecount;
if (index >= LLSettingsDay::FRAME_MAX)
{
(*track).erase(index);
continue;
}
if (!elem.has(LLSettingsDay::SETTING_KEYKFRAME))
{
(*track).erase(index);
continue;
}
if (!elem[LLSettingsDay::SETTING_KEYKFRAME].isReal())
{
(*track).erase(index);
continue;
}
if (!elem.has(LLSettingsDay::SETTING_KEYNAME) &&
!elem.has(LLSettingsDay::SETTING_KEYID))
{
(*track).erase(index);
continue;
}
LLSettingsBase::TrackPosition frame = (F32)elem[LLSettingsDay::SETTING_KEYKFRAME].asReal();
if ((frame < 0.0) || (frame > 1.0))
{
frame = llclamp(frame, 0.0f, 1.0f);
elem[LLSettingsDay::SETTING_KEYKFRAME] = frame;
}
++index;
}
}
int waterTracks = static_cast<int>(value[0].size());
int skyTracks = framecount - waterTracks;
if (waterTracks < 1)
{
LL_WARNS("SETTINGS") << "Missing water track" << LL_ENDL;
return false;
}
if (skyTracks < 1)
{
LL_WARNS("SETTINGS") << "Missing sky tracks" << LL_ENDL;
return false;
}
return true;
}
bool validateDayCycleFrames(LLSD &value, U32 flags)
{
bool hasSky(false);
bool hasWater(false);
for (LLSD::map_iterator itf = value.beginMap(); itf != value.endMap(); ++itf)
{
LLSD frame = (*itf).second;
std::string ftype = frame[LLSettingsBase::SETTING_TYPE];
if (ftype == "sky")
{
LLSettingsSky::validation_list_t valid_sky = LLSettingsSky::validationList();
LLSD res_sky = LLSettingsBase::settingValidation(frame, valid_sky, flags);
if (res_sky["success"].asInteger() == 0)
{
LL_WARNS("SETTINGS") << "Sky setting named '" << (*itf).first << "' validation failed!: " << res_sky << LL_ENDL;
LL_WARNS("SETTINGS") << "Sky: " << frame << LL_ENDL;
continue;
}
hasSky |= true;
}
else if (ftype == "water")
{
LLSettingsWater::validation_list_t valid_h2o = LLSettingsWater::validationList();
LLSD res_h2o = LLSettingsBase::settingValidation(frame, valid_h2o, flags);
if (res_h2o["success"].asInteger() == 0)
{
LL_WARNS("SETTINGS") << "Water setting named '" << (*itf).first << "' validation failed!: " << res_h2o << LL_ENDL;
LL_WARNS("SETTINGS") << "Water: " << frame << LL_ENDL;
continue;
}
hasWater |= true;
}
else
{
LL_WARNS("SETTINGS") << "Unknown settings block of type '" << ftype << "' named '" << (*itf).first << "'" << LL_ENDL;
return false;
}
}
if ((flags & LLSettingsBase::Validator::VALIDATION_PARTIAL) == 0)
{
if (!hasSky)
{
LL_WARNS("SETTINGS") << "No skies defined." << LL_ENDL;
return false;
}
if (!hasWater)
{
LL_WARNS("SETTINGS") << "No waters defined." << LL_ENDL;
return false;
}
}
return true;
}
}
LLSettingsDay::validation_list_t LLSettingsDay::getValidationList() const
{
return LLSettingsDay::validationList();
}
LLSettingsDay::validation_list_t LLSettingsDay::validationList()
{
static validation_list_t validation;
if (validation.empty())
{
validation.push_back(Validator(SETTING_TRACKS, true, LLSD::TypeArray,
&validateDayCycleTrack));
validation.push_back(Validator(SETTING_FRAMES, true, LLSD::TypeMap,
&validateDayCycleFrames));
}
return validation;
}
LLSettingsDay::CycleTrack_t& LLSettingsDay::getCycleTrack(S32 track)
{
static CycleTrack_t emptyTrack;
if (mDayTracks.size() <= track)
return emptyTrack;
return mDayTracks[track];
}
const LLSettingsDay::CycleTrack_t& LLSettingsDay::getCycleTrackConst(S32 track) const
{
static CycleTrack_t emptyTrack;
if (mDayTracks.size() <= track)
return emptyTrack;
return mDayTracks[track];
}
bool LLSettingsDay::clearCycleTrack(S32 track)
{
if ((track < 0) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to clear track (#" << track << ") out of range!" << LL_ENDL;
return false;
}
mDayTracks[track].clear();
clearAssetId();
setDirtyFlag(true);
return true;
}
bool LLSettingsDay::replaceCycleTrack(S32 track, const CycleTrack_t &source)
{
if (source.empty())
{
LL_WARNS("DAYCYCLE") << "Attempt to copy an empty track." << LL_ENDL;
return false;
}
{
LLSettingsBase::ptr_t first((*source.begin()).second);
std::string setting_type = first->getSettingsType();
if (((setting_type == "water") && (track != 0)) ||
((setting_type == "sky") && (track == 0)))
{
LL_WARNS("DAYCYCLE") << "Attempt to copy track missmatch" << LL_ENDL;
return false;
}
}
if (!clearCycleTrack(track))
return false;
mDayTracks[track] = source;
return true;
}
bool LLSettingsDay::isTrackEmpty(S32 track) const
{
if ((track < 0) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to test track (#" << track << ") out of range!" << LL_ENDL;
return true;
}
return mDayTracks[track].empty();
}
//=========================================================================
void LLSettingsDay::startDayCycle()
{
if (!mInitialized)
{
LL_WARNS("DAYCYCLE") << "Attempt to start day cycle on uninitialized object." << LL_ENDL;
return;
}
}
void LLSettingsDay::updateSettings()
{
}
//=========================================================================
LLSettingsDay::KeyframeList_t LLSettingsDay::getTrackKeyframes(S32 trackno)
{
if ((trackno < 0) || (trackno >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt get track (#" << trackno << ") out of range!" << LL_ENDL;
return KeyframeList_t();
}
KeyframeList_t keyframes;
CycleTrack_t &track = mDayTracks[trackno];
keyframes.reserve(track.size());
for (CycleTrack_t::iterator it = track.begin(); it != track.end(); ++it)
{
keyframes.push_back((*it).first);
}
return keyframes;
}
bool LLSettingsDay::moveTrackKeyframe(S32 trackno, const LLSettingsBase::TrackPosition& old_frame, const LLSettingsBase::TrackPosition& new_frame)
{
if ((trackno < 0) || (trackno >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt get track (#" << trackno << ") out of range!" << LL_ENDL;
return false;
}
if (llabs(old_frame - new_frame) < F_APPROXIMATELY_ZERO)
{
return false;
}
CycleTrack_t &track = mDayTracks[trackno];
CycleTrack_t::iterator iter = track.find(old_frame);
if (iter != track.end())
{
LLSettingsBase::ptr_t base = iter->second;
track.erase(iter);
track[llclamp(new_frame, 0.0f, 1.0f)] = base;
track[new_frame] = base;
return true;
}
return false;
}
bool LLSettingsDay::removeTrackKeyframe(S32 trackno, const LLSettingsBase::TrackPosition& frame)
{
if ((trackno < 0) || (trackno >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt get track (#" << trackno << ") out of range!" << LL_ENDL;
return false;
}
CycleTrack_t &track = mDayTracks[trackno];
CycleTrack_t::iterator iter = track.find(frame);
if (iter != track.end())
{
LLSettingsBase::ptr_t base = iter->second;
track.erase(iter);
return true;
}
return false;
}
void LLSettingsDay::setWaterAtKeyframe(const LLSettingsWaterPtr_t &water, const LLSettingsBase::TrackPosition& keyframe)
{
setSettingsAtKeyframe(water, keyframe, TRACK_WATER);
}
LLSettingsWater::ptr_t LLSettingsDay::getWaterAtKeyframe(const LLSettingsBase::TrackPosition& keyframe) const
{
LLSettingsBase* p = getSettingsAtKeyframe(keyframe, TRACK_WATER).get();
return LLSettingsWater::ptr_t((LLSettingsWater*)p);
}
void LLSettingsDay::setSkyAtKeyframe(const LLSettingsSky::ptr_t &sky, const LLSettingsBase::TrackPosition& keyframe, S32 track)
{
if ((track < 1) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to set sky track (#" << track << ") out of range!" << LL_ENDL;
return;
}
setSettingsAtKeyframe(sky, keyframe, track);
}
LLSettingsSky::ptr_t LLSettingsDay::getSkyAtKeyframe(const LLSettingsBase::TrackPosition& keyframe, S32 track) const
{
if ((track < 1) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to set sky track (#" << track << ") out of range!" << LL_ENDL;
return LLSettingsSky::ptr_t();
}
return PTR_NAMESPACE::dynamic_pointer_cast<LLSettingsSky>(getSettingsAtKeyframe(keyframe, track));
}
void LLSettingsDay::setSettingsAtKeyframe(const LLSettingsBase::ptr_t &settings, const LLSettingsBase::TrackPosition& keyframe, S32 track)
{
if ((track < 0) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to set track (#" << track << ") out of range!" << LL_ENDL;
return;
}
std::string type = settings->getSettingsType();
if ((track == TRACK_WATER) && (type != "water"))
{
LL_WARNS("DAYCYCLE") << "Attempt to add frame of type '" << type << "' to water track!" << LL_ENDL;
llassert(type == "water");
return;
}
else if ((track != TRACK_WATER) && (type != "sky"))
{
LL_WARNS("DAYCYCLE") << "Attempt to add frame of type '" << type << "' to sky track!" << LL_ENDL;
llassert(type == "sky");
return;
}
mDayTracks[track][llclamp(keyframe, 0.0f, 1.0f)] = settings;
setDirtyFlag(true);
}
LLSettingsBase::ptr_t LLSettingsDay::getSettingsAtKeyframe(const LLSettingsBase::TrackPosition& keyframe, S32 track) const
{
if ((track < 0) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to set sky track (#" << track << ") out of range!" << LL_ENDL;
return LLSettingsBase::ptr_t();
}
// todo: better way to identify keyframes?
CycleTrack_t::const_iterator iter = mDayTracks[track].find(keyframe);
if (iter != mDayTracks[track].end())
{
return iter->second;
}
return LLSettingsBase::ptr_t();
}
LLSettingsDay::CycleTrack_t::value_type LLSettingsDay::getSettingsNearKeyframe(const LLSettingsBase::TrackPosition &keyframe, S32 track, F32 fudge) const
{
if ((track < 0) || (track >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt to get track (#" << track << ") out of range!" << LL_ENDL;
return CycleTrack_t::value_type(TrackPosition(INVALID_TRACKPOS), LLSettingsBase::ptr_t());
}
if (mDayTracks[track].empty())
{
LL_INFOS("DAYCYCLE") << "Empty track" << LL_ENDL;
return CycleTrack_t::value_type(TrackPosition(INVALID_TRACKPOS), LLSettingsBase::ptr_t());
}
TrackPosition startframe(keyframe - fudge);
if (startframe < 0.0f)
startframe = 1.0f + startframe;
LLSettingsDay::CycleTrack_t collection = const_cast<CycleTrack_t &>(mDayTracks[track]);
CycleTrack_t::iterator it = get_wrapping_atafter(collection, startframe);
F32 dist = get_wrapping_distance(startframe, (*it).first);
CycleTrack_t::iterator next_it = std::next(it);
if ((dist <= DEFAULT_MULTISLIDER_INCREMENT) && next_it != collection.end())
return (*next_it);
else if (dist <= (fudge * 2.0f))
return (*it);
return CycleTrack_t::value_type(TrackPosition(INVALID_TRACKPOS), LLSettingsBase::ptr_t());
}
LLSettingsBase::TrackPosition LLSettingsDay::getUpperBoundFrame(S32 track, const LLSettingsBase::TrackPosition& keyframe)
{
return get_wrapping_atafter(mDayTracks[track], keyframe)->first;
}
LLSettingsBase::TrackPosition LLSettingsDay::getLowerBoundFrame(S32 track, const LLSettingsBase::TrackPosition& keyframe)
{
return get_wrapping_atbefore(mDayTracks[track], keyframe)->first;
}
LLSettingsDay::TrackBound_t LLSettingsDay::getBoundingEntries(LLSettingsDay::CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe)
{
return TrackBound_t(get_wrapping_atbefore(track, keyframe), get_wrapping_atafter(track, keyframe));
}
LLUUID LLSettingsDay::GetDefaultAssetId()
{
return DEFAULT_ASSET_ID;
}
//=========================================================================
+157
View File
@@ -0,0 +1,157 @@
/**
* @file llsettingsdaycycle.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_SETTINGS_DAYCYCLE_H
#define LL_SETTINGS_DAYCYCLE_H
#include "llsettingsbase.h"
class LLSettingsWater;
class LLSettingsSky;
// These are alias for LLSettingsWater::ptr_t and LLSettingsSky::ptr_t respectively.
// Here for definitions only.
typedef PTR_NAMESPACE::shared_ptr<LLSettingsWater> LLSettingsWaterPtr_t;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsSky> LLSettingsSkyPtr_t;
class LLSettingsDay : public LLSettingsBase
{
public:
// 32-bit as LLSD only supports that width at present
typedef S32Seconds Seconds;
static const std::string SETTING_KEYID;
static const std::string SETTING_KEYNAME;
static const std::string SETTING_KEYKFRAME;
static const std::string SETTING_KEYHASH;
static const std::string SETTING_TRACKS;
static const std::string SETTING_FRAMES;
static const Seconds MINIMUM_DAYLENGTH;
static const Seconds DEFAULT_DAYLENGTH;
static const Seconds MAXIMUM_DAYLENGTH;
static const Seconds MINIMUM_DAYOFFSET;
static const Seconds DEFAULT_DAYOFFSET;
static const Seconds MAXIMUM_DAYOFFSET;
static const Seconds INVALID_DAYOFFSET; // KC
static const U32 TRACK_WATER;
static const U32 TRACK_GROUND_LEVEL;
static const U32 TRACK_MAX;
static const U32 FRAME_MAX;
static const F32 DEFAULT_FRAME_SLOP_FACTOR;
static const LLUUID DEFAULT_ASSET_ID;
typedef std::map<LLSettingsBase::TrackPosition, LLSettingsBase::ptr_t> CycleTrack_t;
typedef std::vector<CycleTrack_t> CycleList_t;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsDay> ptr_t;
typedef PTR_NAMESPACE::weak_ptr<LLSettingsDay> wptr_t;
typedef std::vector<LLSettingsBase::TrackPosition> KeyframeList_t;
typedef std::pair<CycleTrack_t::iterator, CycleTrack_t::iterator> TrackBound_t;
//---------------------------------------------------------------------
LLSettingsDay(const LLSD &data);
virtual ~LLSettingsDay() { };
bool initialize(bool validate_frames = false);
virtual ptr_t buildClone() = 0;
virtual ptr_t buildDeepCloneAndUncompress() = 0;
virtual LLSD& getSettings() SETTINGS_OVERRIDE;
virtual void setLLSDDirty() override;
virtual LLSettingsType::type_e getSettingsTypeValue() const SETTINGS_OVERRIDE { return LLSettingsType::ST_DAYCYCLE; }
//---------------------------------------------------------------------
virtual std::string getSettingsType() const SETTINGS_OVERRIDE { return std::string("daycycle"); }
// Settings status
virtual void blend(LLSettingsBase::ptr_t &other, F64 mix) SETTINGS_OVERRIDE;
static LLSD defaults();
//---------------------------------------------------------------------
KeyframeList_t getTrackKeyframes(S32 track);
bool moveTrackKeyframe(S32 track, const LLSettingsBase::TrackPosition& old_frame, const LLSettingsBase::TrackPosition& new_frame);
bool removeTrackKeyframe(S32 track, const LLSettingsBase::TrackPosition& frame);
void setWaterAtKeyframe(const LLSettingsWaterPtr_t &water, const LLSettingsBase::TrackPosition& keyframe);
LLSettingsWaterPtr_t getWaterAtKeyframe(const LLSettingsBase::TrackPosition& keyframe) const;
void setSkyAtKeyframe(const LLSettingsSkyPtr_t &sky, const LLSettingsBase::TrackPosition& keyframe, S32 track);
LLSettingsSkyPtr_t getSkyAtKeyframe(const LLSettingsBase::TrackPosition& keyframe, S32 track) const;
void setSettingsAtKeyframe(const LLSettingsBase::ptr_t &settings, const LLSettingsBase::TrackPosition& keyframe, S32 track);
LLSettingsBase::ptr_t getSettingsAtKeyframe(const LLSettingsBase::TrackPosition& keyframe, S32 track) const;
CycleTrack_t::value_type getSettingsNearKeyframe(const LLSettingsBase::TrackPosition &keyframe, S32 track, F32 fudge) const;
//---------------------------------------------------------------------
void startDayCycle();
virtual LLSettingsSkyPtr_t getDefaultSky() const = 0;
virtual LLSettingsWaterPtr_t getDefaultWater() const = 0;
virtual LLSettingsSkyPtr_t buildSky(LLSD) const = 0;
virtual LLSettingsWaterPtr_t buildWater(LLSD) const = 0;
void setInitialized(bool value = true) { mInitialized = value; }
CycleTrack_t & getCycleTrack(S32 track);
const CycleTrack_t & getCycleTrackConst(S32 track) const;
bool clearCycleTrack(S32 track);
bool replaceCycleTrack(S32 track, const CycleTrack_t &source);
bool isTrackEmpty(S32 track) const;
virtual validation_list_t getValidationList() const SETTINGS_OVERRIDE;
static validation_list_t validationList();
virtual LLSettingsBase::ptr_t buildDerivedClone() SETTINGS_OVERRIDE { return buildClone(); }
LLSettingsBase::TrackPosition getUpperBoundFrame(S32 track, const LLSettingsBase::TrackPosition& keyframe);
LLSettingsBase::TrackPosition getLowerBoundFrame(S32 track, const LLSettingsBase::TrackPosition& keyframe);
static LLUUID GetDefaultAssetId();
protected:
LLSettingsDay();
virtual void updateSettings() SETTINGS_OVERRIDE;
bool mInitialized;
private:
CycleList_t mDayTracks;
LLSD mDaySettings;
LLSettingsBase::Seconds mLastUpdateTime;
static CycleTrack_t::iterator getEntryAtOrBefore(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
static CycleTrack_t::iterator getEntryAtOrAfter(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
TrackBound_t getBoundingEntries(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
};
#endif
File diff suppressed because it is too large Load Diff
+457
View File
@@ -0,0 +1,457 @@
/**
* @file llsettingssky.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_SETTINGS_SKY_H
#define LL_SETTINGS_SKY_H
#include "llsettingsbase.h"
#include "v4coloru.h"
const F32 EARTH_RADIUS = 6.370e6f;
const F32 SUN_RADIUS = 695.508e6f;
const F32 SUN_DIST = 149598.260e6f;
const F32 MOON_RADIUS = 1.737e6f;
const F32 MOON_DIST = 384.400e6f;
class LLSettingsSky: public LLSettingsBase
{
public:
static const std::string SETTING_AMBIENT;
static const std::string SETTING_BLOOM_TEXTUREID;
static const std::string SETTING_RAINBOW_TEXTUREID;
static const std::string SETTING_HALO_TEXTUREID;
static const std::string SETTING_BLUE_DENSITY;
static const std::string SETTING_BLUE_HORIZON;
static const std::string SETTING_DENSITY_MULTIPLIER;
static const std::string SETTING_DISTANCE_MULTIPLIER;
static const std::string SETTING_HAZE_DENSITY;
static const std::string SETTING_HAZE_HORIZON;
static const std::string SETTING_CLOUD_COLOR;
static const std::string SETTING_CLOUD_POS_DENSITY1;
static const std::string SETTING_CLOUD_POS_DENSITY2;
static const std::string SETTING_CLOUD_SCALE;
static const std::string SETTING_CLOUD_SCROLL_RATE;
static const std::string SETTING_CLOUD_SHADOW;
static const std::string SETTING_CLOUD_TEXTUREID;
static const std::string SETTING_CLOUD_VARIANCE;
static const std::string SETTING_DOME_OFFSET;
static const std::string SETTING_DOME_RADIUS;
static const std::string SETTING_GAMMA;
static const std::string SETTING_GLOW;
static const std::string SETTING_LIGHT_NORMAL;
static const std::string SETTING_MAX_Y;
static const std::string SETTING_MOON_ROTATION;
static const std::string SETTING_MOON_SCALE;
static const std::string SETTING_MOON_TEXTUREID;
static const std::string SETTING_MOON_BRIGHTNESS;
static const std::string SETTING_STAR_BRIGHTNESS;
static const std::string SETTING_SUNLIGHT_COLOR;
static const std::string SETTING_SUN_ROTATION;
static const std::string SETTING_SUN_SCALE;
static const std::string SETTING_SUN_TEXTUREID;
static const std::string SETTING_PLANET_RADIUS;
static const std::string SETTING_SKY_BOTTOM_RADIUS;
static const std::string SETTING_SKY_TOP_RADIUS;
static const std::string SETTING_SUN_ARC_RADIANS;
static const std::string SETTING_MIE_ANISOTROPY_FACTOR;
static const std::string SETTING_RAYLEIGH_CONFIG;
static const std::string SETTING_MIE_CONFIG;
static const std::string SETTING_ABSORPTION_CONFIG;
static const std::string KEY_DENSITY_PROFILE;
static const std::string SETTING_DENSITY_PROFILE_WIDTH;
static const std::string SETTING_DENSITY_PROFILE_EXP_TERM;
static const std::string SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR;
static const std::string SETTING_DENSITY_PROFILE_LINEAR_TERM;
static const std::string SETTING_DENSITY_PROFILE_CONSTANT_TERM;
static const std::string SETTING_SKY_MOISTURE_LEVEL;
static const std::string SETTING_SKY_DROPLET_RADIUS;
static const std::string SETTING_SKY_ICE_LEVEL;
static const std::string SETTING_REFLECTION_PROBE_AMBIANCE;
static const std::string SETTING_LEGACY_HAZE;
static const LLUUID DEFAULT_ASSET_ID;
static const F32 DEFAULT_AUTO_ADJUST_PROBE_AMBIANCE;
static F32 sAutoAdjustProbeAmbiance;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsSky> ptr_t;
//---------------------------------------------------------------------
LLSettingsSky(const LLSD &data);
virtual ~LLSettingsSky() { };
virtual ptr_t buildClone() = 0;
//---------------------------------------------------------------------
virtual std::string getSettingsType() const SETTINGS_OVERRIDE { return std::string("sky"); }
virtual LLSettingsType::type_e getSettingsTypeValue() const SETTINGS_OVERRIDE { return LLSettingsType::ST_SKY; }
// Settings status
virtual void blend(LLSettingsBase::ptr_t &end, F64 blendf) SETTINGS_OVERRIDE;
virtual void replaceSettings(LLSD settings) SETTINGS_OVERRIDE;
virtual void replaceSettings(const LLSettingsBase::ptr_t& other_sky) override;
void replaceWithSky(const LLSettingsSky::ptr_t& pother);
static LLSD defaults(const LLSettingsBase::TrackPosition& position = 0.0f);
void loadValuesFromLLSD() override;
void saveValuesToLLSD() override;
F32 getPlanetRadius() const;
F32 getSkyBottomRadius() const;
F32 getSkyTopRadius() const;
F32 getSunArcRadians() const;
F32 getMieAnisotropy() const;
F32 getSkyMoistureLevel() const;
F32 getSkyDropletRadius() const;
F32 getSkyIceLevel() const;
// get the probe ambiance setting as stored in the sky settings asset
// auto_adjust - if true and canAutoAdjust() is true, return 1.0
F32 getReflectionProbeAmbiance(bool auto_adjust = false) const;
// Return first (only) profile layer represented in LLSD
LLSD getRayleighConfig() const;
LLSD getMieConfig() const;
LLSD getAbsorptionConfig() const;
// Return entire LLSDArray of profile layers represented in LLSD
LLSD getRayleighConfigs() const;
LLSD getMieConfigs() const;
LLSD getAbsorptionConfigs() const;
LLUUID getBloomTextureId() const;
LLUUID getRainbowTextureId() const;
LLUUID getHaloTextureId() const;
void setRayleighConfigs(const LLSD& rayleighConfig);
void setMieConfigs(const LLSD& mieConfig);
void setAbsorptionConfigs(const LLSD& absorptionConfig);
void setPlanetRadius(F32 radius);
void setSkyBottomRadius(F32 radius);
void setSkyTopRadius(F32 radius);
void setSunArcRadians(F32 radians);
void setMieAnisotropy(F32 aniso_factor);
void setSkyMoistureLevel(F32 moisture_level);
void setSkyDropletRadius(F32 radius);
void setSkyIceLevel(F32 ice_level);
void setReflectionProbeAmbiance(F32 ambiance);
//---------------------------------------------------------------------
LLColor3 getAmbientColor() const;
void setAmbientColor(const LLColor3 &val);
LLColor3 getCloudColor() const;
void setCloudColor(const LLColor3 &val);
LLUUID getCloudNoiseTextureId() const;
void setCloudNoiseTextureId(const LLUUID &id);
LLColor3 getCloudPosDensity1() const;
void setCloudPosDensity1(const LLColor3 &val);
LLColor3 getCloudPosDensity2() const;
void setCloudPosDensity2(const LLColor3 &val);
F32 getCloudScale() const;
void setCloudScale(F32 val);
LLVector2 getCloudScrollRate() const;
void setCloudScrollRate(const LLVector2 &val);
void setCloudScrollRateX(F32 val);
void setCloudScrollRateY(F32 val);
F32 getCloudShadow() const;
void setCloudShadow(F32 val);
F32 getCloudVariance() const;
void setCloudVariance(F32 val);
F32 getDomeOffset() const;
F32 getDomeRadius() const;
F32 getGamma() const;
F32 getHDRMin(bool auto_adjust = false) const;
F32 getHDRMax(bool auto_adjust = false) const;
F32 getHDROffset(bool auto_adjust = false) const;
F32 getTonemapMix(bool auto_adjust = false) const;
void setTonemapMix(F32 mix);
void setGamma(F32 val);
LLColor3 getGlow() const;
void setGlow(const LLColor3 &val);
F32 getMaxY() const;
void setMaxY(F32 val);
LLQuaternion getMoonRotation() const;
void setMoonRotation(const LLQuaternion &val);
F32 getMoonScale() const;
void setMoonScale(F32 val);
LLUUID getMoonTextureId() const;
void setMoonTextureId(LLUUID id);
F32 getMoonBrightness() const;
void setMoonBrightness(F32 brightness_factor);
F32 getStarBrightness() const;
void setStarBrightness(F32 val);
LLColor3 getSunlightColor() const;
void setSunlightColor(const LLColor3 &val);
LLQuaternion getSunRotation() const;
void setSunRotation(const LLQuaternion &val) ;
F32 getSunScale() const;
void setSunScale(F32 val);
LLUUID getSunTextureId() const;
void setSunTextureId(LLUUID id);
//=====================================================================
// transient properties used in animations.
LLUUID getNextSunTextureId() const;
LLUUID getNextMoonTextureId() const;
LLUUID getNextCloudNoiseTextureId() const;
LLUUID getNextBloomTextureId() const;
//=====================================================================
virtual void loadTextures() { };
//=====================================================================
virtual validation_list_t getValidationList() const SETTINGS_OVERRIDE;
static validation_list_t validationList();
static LLSD translateLegacySettings(const LLSD& legacy);
// LEGACY_ATMOSPHERICS
static LLSD translateLegacyHazeSettings(const LLSD& legacy);
LLColor3 getLightAttenuation(F32 distance) const;
LLColor3 getLightTransmittance(F32 distance) const;
LLColor3 getLightTransmittanceFast(const LLColor3& total_density, const F32 density_multiplier, const F32 distance) const;
LLColor3 getTotalDensity() const;
LLColor3 gammaCorrect(const LLColor3& in,const F32 &gamma) const;
LLColor3 getBlueDensity() const;
LLColor3 getBlueHorizon() const;
F32 getHazeDensity() const;
F32 getHazeHorizon() const;
F32 getDensityMultiplier() const;
F32 getDistanceMultiplier() const;
void setBlueDensity(const LLColor3 &val);
void setBlueHorizon(const LLColor3 &val);
void setDensityMultiplier(F32 val);
void setDistanceMultiplier(F32 val);
void setHazeDensity(F32 val);
void setHazeHorizon(F32 val);
// Internal/calculated settings
bool getIsSunUp() const;
bool getIsMoonUp() const;
// determines how much the haze glow effect occurs in rendering
F32 getSunMoonGlowFactor() const;
LLVector3 getLightDirection() const;
LLColor3 getLightDiffuse() const;
LLVector3 getSunDirection() const;
LLVector3 getMoonDirection() const;
// color based on brightness
LLColor3 getMoonlightColor() const;
LLColor4 getMoonAmbient() const;
LLColor3 getMoonDiffuse() const;
LLColor4 getSunAmbient() const;
LLColor3 getSunDiffuse() const;
LLColor4 getTotalAmbient() const;
LLColor4 getHazeColor() const;
LLColor3 getSunlightColorClamped() const;
LLColor3 getAmbientColorClamped() const;
virtual LLSettingsBase::ptr_t buildDerivedClone() SETTINGS_OVERRIDE { return buildClone(); }
static LLUUID GetDefaultAssetId();
static LLUUID GetDefaultSunTextureId();
static LLUUID GetBlankSunTextureId();
static LLUUID GetDefaultMoonTextureId();
static LLUUID GetDefaultCloudNoiseTextureId();
static LLUUID GetDefaultBloomTextureId();
static LLUUID GetDefaultRainbowTextureId();
static LLUUID GetDefaultHaloTextureId();
static LLSD createDensityProfileLayer(
F32 width,
F32 exponential_term,
F32 exponential_scale_factor,
F32 linear_term,
F32 constant_term,
F32 aniso_factor = 0.0f);
static LLSD createSingleLayerDensityProfile(
F32 width,
F32 exponential_term,
F32 exponential_scale_factor,
F32 linear_term,
F32 constant_term,
F32 aniso_factor = 0.0f);
virtual void updateSettings() SETTINGS_OVERRIDE;
// if true, this sky is a candidate for auto-adjustment
bool canAutoAdjust() const;
protected:
static const std::string SETTING_LEGACY_EAST_ANGLE;
static const std::string SETTING_LEGACY_ENABLE_CLOUD_SCROLL;
static const std::string SETTING_LEGACY_SUN_ANGLE;
LLSettingsSky();
virtual stringset_t getSlerpKeys() const SETTINGS_OVERRIDE;
virtual stringset_t getSkipInterpolateKeys() const SETTINGS_OVERRIDE;
LLUUID mSunTextureId;
LLUUID mMoonTextureId;
LLUUID mCloudTextureId;
LLUUID mBloomTextureId;
LLUUID mRainbowTextureId;
LLUUID mHaloTextureId;
LLUUID mNextSunTextureId;
LLUUID mNextMoonTextureId;
LLUUID mNextCloudTextureId;
LLUUID mNextBloomTextureId;
LLUUID mNextRainbowTextureId;
LLUUID mNextHaloTextureId;
bool mCanAutoAdjust;
LLQuaternion mSunRotation;
LLQuaternion mMoonRotation;
LLColor3 mSunlightColor;
LLColor3 mGlow;
F32 mReflectionProbeAmbiance;
F32 mSunScale;
F32 mStarBrightness;
F32 mMoonBrightness;
F32 mMoonScale;
F32 mMaxY;
F32 mGamma;
F32 mCloudVariance;
F32 mCloudShadow;
F32 mCloudScale;
F32 mTonemapMix;
F32 mHDROffset;
F32 mHDRMax;
F32 mHDRMin;
LLVector2 mScrollRate;
LLColor3 mCloudPosDensity1;
LLColor3 mCloudPosDensity2;
LLColor3 mCloudColor;
LLSD mAbsorptionConfigs;
LLSD mMieConfigs;
LLSD mRayleighConfigs;
F32 mSunArcRadians;
F32 mSkyTopRadius;
F32 mSkyBottomRadius;
F32 mSkyMoistureLevel;
F32 mSkyDropletRadius;
F32 mSkyIceLevel;
F32 mPlanetRadius;
F32 mHazeHorizon;
F32 mHazeDensity;
F32 mDistanceMultiplier;
F32 mDensityMultiplier;
LLColor3 mBlueHorizon;
LLColor3 mBlueDensity;
LLColor3 mAmbientColor;
bool mHasLegacyHaze;
bool mLegacyHazeHorizon;
bool mLegacyHazeDensity;
bool mLegacyDistanceMultiplier;
bool mLegacyDensityMultiplier;
bool mLegacyBlueHorizon;
bool mLegacyBlueDensity;
bool mLegacyAmbientColor;
private:
static LLSD rayleighConfigDefault();
static LLSD absorptionConfigDefault();
static LLSD mieConfigDefault();
LLColor3 getColor(const std::string& key, const LLColor3& default_value);
F32 getFloat(const std::string& key, F32 default_value);
void calculateHeavenlyBodyPositions() const;
void calculateLightSettings() const;
static void clampColor(LLColor3& color, F32 gamma, const F32 scale = 1.0f);
mutable LLVector3 mSunDirection;
mutable LLVector3 mMoonDirection;
mutable LLVector3 mLightDirection;
static const F32 DOME_RADIUS;
static const F32 DOME_OFFSET;
mutable LLColor4 mMoonAmbient;
mutable LLColor3 mMoonDiffuse;
mutable LLColor4 mSunAmbient;
mutable LLColor3 mSunDiffuse;
mutable LLColor4 mTotalAmbient;
mutable LLColor4 mHazeColor;
typedef std::map<std::string, S32> mapNameToUniformId_t;
static mapNameToUniformId_t sNameToUniformMapping;
};
#endif
+400
View File
@@ -0,0 +1,400 @@
/**
* @file llsettingswater.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llsettingswater.h"
#include <algorithm>
#include "lltrace.h"
#include "llfasttimer.h"
#include "v3colorutil.h"
#include "indra_constants.h"
#include <boost/bind.hpp>
const std::string LLSettingsWater::SETTING_BLUR_MULTIPLIER("blur_multiplier");
const std::string LLSettingsWater::SETTING_FOG_COLOR("water_fog_color");
const std::string LLSettingsWater::SETTING_FOG_DENSITY("water_fog_density");
const std::string LLSettingsWater::SETTING_FOG_MOD("underwater_fog_mod");
const std::string LLSettingsWater::SETTING_FRESNEL_OFFSET("fresnel_offset");
const std::string LLSettingsWater::SETTING_FRESNEL_SCALE("fresnel_scale");
const std::string LLSettingsWater::SETTING_TRANSPARENT_TEXTURE("transparent_texture");
const std::string LLSettingsWater::SETTING_NORMAL_MAP("normal_map");
const std::string LLSettingsWater::SETTING_NORMAL_SCALE("normal_scale");
const std::string LLSettingsWater::SETTING_SCALE_ABOVE("scale_above");
const std::string LLSettingsWater::SETTING_SCALE_BELOW("scale_below");
const std::string LLSettingsWater::SETTING_WAVE1_DIR("wave1_direction");
const std::string LLSettingsWater::SETTING_WAVE2_DIR("wave2_direction");
const std::string LLSettingsWater::SETTING_LEGACY_BLUR_MULTIPLIER("blurMultiplier");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_COLOR("waterFogColor");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_DENSITY("waterFogDensity");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_MOD("underWaterFogMod");
const std::string LLSettingsWater::SETTING_LEGACY_FRESNEL_OFFSET("fresnelOffset");
const std::string LLSettingsWater::SETTING_LEGACY_FRESNEL_SCALE("fresnelScale");
const std::string LLSettingsWater::SETTING_LEGACY_NORMAL_MAP("normalMap");
const std::string LLSettingsWater::SETTING_LEGACY_NORMAL_SCALE("normScale");
const std::string LLSettingsWater::SETTING_LEGACY_SCALE_ABOVE("scaleAbove");
const std::string LLSettingsWater::SETTING_LEGACY_SCALE_BELOW("scaleBelow");
const std::string LLSettingsWater::SETTING_LEGACY_WAVE1_DIR("wave1Dir");
const std::string LLSettingsWater::SETTING_LEGACY_WAVE2_DIR("wave2Dir");
const LLUUID LLSettingsWater::DEFAULT_ASSET_ID("59d1a851-47e7-0e5f-1ed7-6b715154f41a");
static const LLUUID DEFAULT_TRANSPARENT_WATER_TEXTURE("2bfd3884-7e27-69b9-ba3a-3e673f680004");
static const LLUUID DEFAULT_OPAQUE_WATER_TEXTURE("43c32285-d658-1793-c123-bf86315de055");
//=========================================================================
LLSettingsWater::LLSettingsWater(const LLSD &data) :
LLSettingsBase(data),
mNextNormalMapID(),
mNextTransparentTextureID()
{
loadValuesFromLLSD();
}
LLSettingsWater::LLSettingsWater() :
LLSettingsBase(),
mNextNormalMapID(),
mNextTransparentTextureID()
{
replaceSettings(defaults());
}
//=========================================================================
LLSD LLSettingsWater::defaults(const LLSettingsBase::TrackPosition& position)
{
static LLSD dfltsetting;
if (dfltsetting.size() == 0)
{
// give the normal scale offset some variability over track time...
F32 normal_scale_offset = (position * 0.5f) - 0.25f;
// Magic constants copied form defaults.xml
dfltsetting[SETTING_BLUR_MULTIPLIER] = LLSD::Real(0.04000f);
dfltsetting[SETTING_FOG_COLOR] = LLColor3(0.0156f, 0.1490f, 0.2509f).getValue();
dfltsetting[SETTING_FOG_DENSITY] = LLSD::Real(2.0f);
dfltsetting[SETTING_FOG_MOD] = LLSD::Real(0.25f);
dfltsetting[SETTING_FRESNEL_OFFSET] = LLSD::Real(0.5f);
dfltsetting[SETTING_FRESNEL_SCALE] = LLSD::Real(0.3999);
dfltsetting[SETTING_TRANSPARENT_TEXTURE] = GetDefaultTransparentTextureAssetId();
dfltsetting[SETTING_NORMAL_MAP] = GetDefaultWaterNormalAssetId();
dfltsetting[SETTING_NORMAL_SCALE] = LLVector3(2.0f + normal_scale_offset, 2.0f + normal_scale_offset, 2.0f + normal_scale_offset).getValue();
dfltsetting[SETTING_SCALE_ABOVE] = LLSD::Real(0.0299f);
dfltsetting[SETTING_SCALE_BELOW] = LLSD::Real(0.2000f);
dfltsetting[SETTING_WAVE1_DIR] = LLVector2(1.04999f, -0.42000f).getValue();
dfltsetting[SETTING_WAVE2_DIR] = LLVector2(1.10999f, -1.16000f).getValue();
dfltsetting[SETTING_TYPE] = "water";
}
return dfltsetting;
}
void LLSettingsWater::loadValuesFromLLSD()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
LLSettingsBase::loadValuesFromLLSD();
LLSD& settings = getSettings();
mBlurMultiplier = (F32)settings[SETTING_BLUR_MULTIPLIER].asReal();
mWaterFogColor = LLColor3(settings[SETTING_FOG_COLOR]);
mWaterFogDensity = (F32)settings[SETTING_FOG_DENSITY].asReal();
mFogMod = (F32)settings[SETTING_FOG_MOD].asReal();
mFresnelOffset = (F32)settings[SETTING_FRESNEL_OFFSET].asReal();
mFresnelScale = (F32)settings[SETTING_FRESNEL_SCALE].asReal();
mNormalScale = LLVector3(settings[SETTING_NORMAL_SCALE]);
mScaleAbove = (F32)settings[SETTING_SCALE_ABOVE].asReal();
mScaleBelow = (F32)settings[SETTING_SCALE_BELOW].asReal();
mWave1Dir = LLVector2(settings[SETTING_WAVE1_DIR]);
mWave2Dir = LLVector2(settings[SETTING_WAVE2_DIR]);
mNormalMapID = settings[SETTING_NORMAL_MAP].asUUID();
mTransparentTextureID = settings[SETTING_TRANSPARENT_TEXTURE].asUUID();
}
void LLSettingsWater::saveValuesToLLSD()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
LLSettingsBase::saveValuesToLLSD();
LLSD & settings = getSettings();
settings[SETTING_BLUR_MULTIPLIER] = LLSD::Real(mBlurMultiplier);
settings[SETTING_FOG_COLOR] = mWaterFogColor.getValue();
settings[SETTING_FOG_DENSITY] = LLSD::Real(mWaterFogDensity);
settings[SETTING_FOG_MOD] = LLSD::Real(mFogMod);
settings[SETTING_FRESNEL_OFFSET] = LLSD::Real(mFresnelOffset);
settings[SETTING_FRESNEL_SCALE] = LLSD::Real(mFresnelScale);
settings[SETTING_NORMAL_SCALE] = mNormalScale.getValue();
settings[SETTING_SCALE_ABOVE] = LLSD::Real(mScaleAbove);
settings[SETTING_SCALE_BELOW] = LLSD::Real(mScaleBelow);
settings[SETTING_WAVE1_DIR] = mWave1Dir.getValue();
settings[SETTING_WAVE2_DIR] = mWave2Dir.getValue();
settings[SETTING_NORMAL_MAP] = mNormalMapID;
settings[SETTING_TRANSPARENT_TEXTURE] = mTransparentTextureID;
}
LLSD LLSettingsWater::translateLegacySettings(LLSD legacy)
{
bool converted_something(false);
LLSD newsettings(defaults());
if (legacy.has(SETTING_LEGACY_BLUR_MULTIPLIER))
{
newsettings[SETTING_BLUR_MULTIPLIER] = LLSD::Real(legacy[SETTING_LEGACY_BLUR_MULTIPLIER].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_FOG_COLOR))
{
newsettings[SETTING_FOG_COLOR] = LLColor3(legacy[SETTING_LEGACY_FOG_COLOR]).getValue();
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_FOG_DENSITY))
{
newsettings[SETTING_FOG_DENSITY] = LLSD::Real(legacy[SETTING_LEGACY_FOG_DENSITY]);
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_FOG_MOD))
{
newsettings[SETTING_FOG_MOD] = LLSD::Real(legacy[SETTING_LEGACY_FOG_MOD].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_FRESNEL_OFFSET))
{
newsettings[SETTING_FRESNEL_OFFSET] = LLSD::Real(legacy[SETTING_LEGACY_FRESNEL_OFFSET].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_FRESNEL_SCALE))
{
newsettings[SETTING_FRESNEL_SCALE] = LLSD::Real(legacy[SETTING_LEGACY_FRESNEL_SCALE].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_NORMAL_MAP))
{
newsettings[SETTING_NORMAL_MAP] = LLSD::UUID(legacy[SETTING_LEGACY_NORMAL_MAP].asUUID());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_NORMAL_SCALE))
{
newsettings[SETTING_NORMAL_SCALE] = LLVector3(legacy[SETTING_LEGACY_NORMAL_SCALE]).getValue();
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_SCALE_ABOVE))
{
newsettings[SETTING_SCALE_ABOVE] = LLSD::Real(legacy[SETTING_LEGACY_SCALE_ABOVE].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_SCALE_BELOW))
{
newsettings[SETTING_SCALE_BELOW] = LLSD::Real(legacy[SETTING_LEGACY_SCALE_BELOW].asReal());
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_WAVE1_DIR))
{
newsettings[SETTING_WAVE1_DIR] = LLVector2(legacy[SETTING_LEGACY_WAVE1_DIR]).getValue();
converted_something |= true;
}
if (legacy.has(SETTING_LEGACY_WAVE2_DIR))
{
newsettings[SETTING_WAVE2_DIR] = LLVector2(legacy[SETTING_LEGACY_WAVE2_DIR]).getValue();
converted_something |= true;
}
if (!converted_something)
return LLSD();
return newsettings;
}
void LLSettingsWater::blend(LLSettingsBase::ptr_t &end, F64 blendf)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_ENVIRONMENT;
LLSettingsWater::ptr_t other = PTR_NAMESPACE::static_pointer_cast<LLSettingsWater>(end);
if (other)
{
mSettingFlags |= other->mSettingFlags;
mBlurMultiplier = lerp(mBlurMultiplier, other->mBlurMultiplier, (F32)blendf);
lerpColor(mWaterFogColor, other->mWaterFogColor, (F32)blendf);
mWaterFogDensity = lerp(mWaterFogDensity, other->mWaterFogDensity, (F32)blendf);
mFogMod = lerp(mFogMod, other->mFogMod, (F32)blendf);
mFresnelOffset = lerp(mFresnelOffset, other->mFresnelOffset, (F32)blendf);
mFresnelScale = lerp(mFresnelScale, other->mFresnelScale, (F32)blendf);
lerpVector3(mNormalScale, other->mNormalScale, (F32)blendf);
mScaleAbove = lerp(mScaleAbove, other->mScaleAbove, (F32)blendf);
mScaleBelow = lerp(mScaleBelow, other->mScaleBelow, (F32)blendf);
lerpVector2(mWave1Dir, other->mWave1Dir, (F32)blendf);
lerpVector2(mWave2Dir, other->mWave2Dir, (F32)blendf);
setDirtyFlag(true);
setReplaced();
setLLSDDirty();
mNextNormalMapID = other->getNormalMapID();
mNextTransparentTextureID = other->getTransparentTextureID();
}
else
{
LL_WARNS("SETTINGS") << "Could not cast end settings to water. No blend performed." << LL_ENDL;
}
setBlendFactor(blendf);
}
void LLSettingsWater::replaceSettings(LLSD settings)
{
LLSettingsBase::replaceSettings(settings);
mNextNormalMapID.setNull();
mNextTransparentTextureID.setNull();
}
void LLSettingsWater::replaceSettings(const LLSettingsBase::ptr_t& other_water)
{
LLSettingsBase::replaceSettings(other_water);
llassert(getSettingsType() == other_water->getSettingsType());
LLSettingsWater::ptr_t other = PTR_NAMESPACE::dynamic_pointer_cast<LLSettingsWater>(other_water);
mBlurMultiplier = other->mBlurMultiplier;
mWaterFogColor = other->mWaterFogColor;
mWaterFogDensity = other->mWaterFogDensity;
mFogMod = other->mFogMod;
mFresnelOffset = other->mFresnelOffset;
mFresnelScale = other->mFresnelScale;
mNormalScale = other->mNormalScale;
mScaleAbove = other->mScaleAbove;
mScaleBelow = other->mScaleBelow;
mWave1Dir = other->mWave1Dir;
mWave2Dir = other->mWave2Dir;
mNormalMapID = other->mNormalMapID;
mTransparentTextureID = other->mTransparentTextureID;
mNextNormalMapID.setNull();
mNextTransparentTextureID.setNull();
}
void LLSettingsWater::replaceWithWater(const LLSettingsWater::ptr_t& other)
{
replaceWith(other);
mNextNormalMapID = other->mNextNormalMapID;
mNextTransparentTextureID = other->mNextTransparentTextureID;
}
LLSettingsWater::validation_list_t LLSettingsWater::getValidationList() const
{
return LLSettingsWater::validationList();
}
LLSettingsWater::validation_list_t LLSettingsWater::validationList()
{
static validation_list_t validation;
if (validation.empty())
{
validation.push_back(Validator(SETTING_BLUR_MULTIPLIER, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(-0.5f, 0.5f))));
validation.push_back(Validator(SETTING_FOG_COLOR, true, LLSD::TypeArray,
boost::bind(&Validator::verifyVectorMinMax, _1, _2,
llsd::array(0.0f, 0.0f, 0.0f, 1.0f),
llsd::array(1.0f, 1.0f, 1.0f, 1.0f))));
validation.push_back(Validator(SETTING_FOG_DENSITY, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.001f, 100.0f))));
validation.push_back(Validator(SETTING_FOG_MOD, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.0f, 20.0f))));
validation.push_back(Validator(SETTING_FRESNEL_OFFSET, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.0f, 1.0f))));
validation.push_back(Validator(SETTING_FRESNEL_SCALE, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.0f, 1.0f))));
validation.push_back(Validator(SETTING_NORMAL_MAP, true, LLSD::TypeUUID));
validation.push_back(Validator(SETTING_NORMAL_SCALE, true, LLSD::TypeArray,
boost::bind(&Validator::verifyVectorMinMax, _1, _2,
llsd::array(0.0f, 0.0f, 0.0f),
llsd::array(10.0f, 10.0f, 10.0f))));
validation.push_back(Validator(SETTING_SCALE_ABOVE, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.0f, 3.0f))));
validation.push_back(Validator(SETTING_SCALE_BELOW, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, _2, llsd::array(0.0f, 3.0f))));
validation.push_back(Validator(SETTING_WAVE1_DIR, true, LLSD::TypeArray,
boost::bind(&Validator::verifyVectorMinMax, _1, _2,
llsd::array(-20.0f, -20.0f),
llsd::array(20.0f, 20.0f))));
validation.push_back(Validator(SETTING_WAVE2_DIR, true, LLSD::TypeArray,
boost::bind(&Validator::verifyVectorMinMax, _1, _2,
llsd::array(-20.0f, -20.0f),
llsd::array(20.0f, 20.0f))));
}
return validation;
}
LLUUID LLSettingsWater::GetDefaultAssetId()
{
return DEFAULT_ASSET_ID;
}
LLUUID LLSettingsWater::GetDefaultWaterNormalAssetId()
{
return DEFAULT_WATER_NORMAL;
}
LLUUID LLSettingsWater::GetDefaultTransparentTextureAssetId()
{
return DEFAULT_TRANSPARENT_WATER_TEXTURE;
}
LLUUID LLSettingsWater::GetDefaultOpaqueTextureAssetId()
{
return DEFAULT_OPAQUE_WATER_TEXTURE;
}
F32 LLSettingsWater::getModifiedWaterFogDensity(bool underwater) const
{
F32 fog_density = getWaterFogDensity();
F32 underwater_fog_mod = getFogMod();
if (underwater && underwater_fog_mod > 0.0f)
{
underwater_fog_mod = llclamp(underwater_fog_mod, 0.0f, 10.0f);
// BUG-233797/BUG-233798 -ve underwater fog density can cause (unrecoverable) blackout.
// raising a negative number to a non-integral power results in a non-real result (which is NaN for our purposes)
// Two methods were tested, number 2 is being used:
// 1) Force the fog_mod to be integral. The effect is unlikely to be nice, but it is better than blackness.
// In this method a few of the combinations are "usable" but the water colour is effectively inverted (blue becomes yellow)
// this seems to be unlikely to be a desirable use case for the majority.
// 2) Force density to be an arbitrary non-negative (i.e. 1) when underwater and modifier is not an integer (1 was aribtrarily chosen as it gives at least some notion of fog in the transition)
// This is more restrictive, effectively forcing a density under certain conditions, but allowing the range of #1 and avoiding blackness in other cases
// at the cost of overriding the fog density.
if(fog_density < 0.0f && underwater_fog_mod != (F32)llround(underwater_fog_mod) )
{
fog_density = 1.0f;
}
fog_density = pow(fog_density, underwater_fog_mod);
}
return fog_density;
}
+292
View File
@@ -0,0 +1,292 @@
/**
* @file llsettingssky.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_SETTINGS_WATER_H
#define LL_SETTINGS_WATER_H
#include "llsettingsbase.h"
class LLSettingsWater : public LLSettingsBase
{
public:
static const std::string SETTING_BLUR_MULTIPLIER;
static const std::string SETTING_FOG_COLOR;
static const std::string SETTING_FOG_DENSITY;
static const std::string SETTING_FOG_MOD;
static const std::string SETTING_FRESNEL_OFFSET;
static const std::string SETTING_FRESNEL_SCALE;
static const std::string SETTING_TRANSPARENT_TEXTURE;
static const std::string SETTING_NORMAL_MAP;
static const std::string SETTING_NORMAL_SCALE;
static const std::string SETTING_SCALE_ABOVE;
static const std::string SETTING_SCALE_BELOW;
static const std::string SETTING_WAVE1_DIR;
static const std::string SETTING_WAVE2_DIR;
static const LLUUID DEFAULT_ASSET_ID;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsWater> ptr_t;
//---------------------------------------------------------------------
LLSettingsWater(const LLSD &data);
virtual ~LLSettingsWater() { };
virtual ptr_t buildClone() = 0;
//---------------------------------------------------------------------
virtual std::string getSettingsType() const SETTINGS_OVERRIDE { return std::string("water"); }
virtual LLSettingsType::type_e getSettingsTypeValue() const SETTINGS_OVERRIDE { return LLSettingsType::ST_WATER; }
// Settings status
virtual void blend(LLSettingsBase::ptr_t &end, F64 blendf) SETTINGS_OVERRIDE;
virtual void replaceSettings(LLSD settings) SETTINGS_OVERRIDE;
virtual void replaceSettings(const LLSettingsBase::ptr_t& other_water) override;
void replaceWithWater(const LLSettingsWater::ptr_t& other);
static LLSD defaults(const LLSettingsBase::TrackPosition& position = 0.0f);
void loadValuesFromLLSD() override;
void saveValuesToLLSD() override;
//---------------------------------------------------------------------
F32 getBlurMultiplier() const
{
return mBlurMultiplier;
}
void setBlurMultiplier(F32 val)
{
mBlurMultiplier = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLColor3 getWaterFogColor() const
{
return mWaterFogColor;
}
void setWaterFogColor(LLColor3 val)
{
mWaterFogColor = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getWaterFogDensity() const
{
return mWaterFogDensity;
}
F32 getModifiedWaterFogDensity(bool underwater) const;
void setWaterFogDensity(F32 val)
{
mWaterFogDensity = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getFogMod() const
{
return mFogMod;
}
void setFogMod(F32 val)
{
mFogMod = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getFresnelOffset() const
{
return mFresnelOffset;
}
void setFresnelOffset(F32 val)
{
mFresnelOffset = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getFresnelScale() const
{
return mFresnelScale;
}
void setFresnelScale(F32 val)
{
mFresnelScale = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLUUID getTransparentTextureID() const
{
return mTransparentTextureID;
}
void setTransparentTextureID(LLUUID val)
{
mTransparentTextureID = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLUUID getNormalMapID() const
{
return mNormalMapID;
}
void setNormalMapID(LLUUID val)
{
mNormalMapID = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLVector3 getNormalScale() const
{
return mNormalScale;
}
void setNormalScale(LLVector3 val)
{
mNormalScale = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getScaleAbove() const
{
return mScaleAbove;
}
void setScaleAbove(F32 val)
{
mScaleAbove = val;
setDirtyFlag(true);
setLLSDDirty();
}
F32 getScaleBelow() const
{
return mScaleBelow;
}
void setScaleBelow(F32 val)
{
mScaleBelow = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLVector2 getWave1Dir() const
{
return mWave1Dir;
}
void setWave1Dir(LLVector2 val)
{
mWave1Dir = val;
setDirtyFlag(true);
setLLSDDirty();
}
LLVector2 getWave2Dir() const
{
return mWave2Dir;
}
void setWave2Dir(LLVector2 val)
{
mWave2Dir = val;
setDirtyFlag(true);
setLLSDDirty();
}
//-------------------------------------------
LLUUID getNextNormalMapID() const
{
return mNextNormalMapID;
}
LLUUID getNextTransparentTextureID() const
{
return mNextTransparentTextureID;
}
virtual validation_list_t getValidationList() const SETTINGS_OVERRIDE;
static validation_list_t validationList();
static LLSD translateLegacySettings(LLSD legacy);
virtual LLSettingsBase::ptr_t buildDerivedClone() SETTINGS_OVERRIDE { return buildClone(); }
static LLUUID GetDefaultAssetId();
static LLUUID GetDefaultWaterNormalAssetId();
static LLUUID GetDefaultTransparentTextureAssetId();
static LLUUID GetDefaultOpaqueTextureAssetId();
protected:
static const std::string SETTING_LEGACY_BLUR_MULTIPLIER;
static const std::string SETTING_LEGACY_FOG_COLOR;
static const std::string SETTING_LEGACY_FOG_DENSITY;
static const std::string SETTING_LEGACY_FOG_MOD;
static const std::string SETTING_LEGACY_FRESNEL_OFFSET;
static const std::string SETTING_LEGACY_FRESNEL_SCALE;
static const std::string SETTING_LEGACY_NORMAL_MAP;
static const std::string SETTING_LEGACY_NORMAL_SCALE;
static const std::string SETTING_LEGACY_SCALE_ABOVE;
static const std::string SETTING_LEGACY_SCALE_BELOW;
static const std::string SETTING_LEGACY_WAVE1_DIR;
static const std::string SETTING_LEGACY_WAVE2_DIR;
LLSettingsWater();
LLUUID mTransparentTextureID;
LLUUID mNormalMapID;
LLUUID mNextTransparentTextureID;
LLUUID mNextNormalMapID;
F32 mBlurMultiplier;
LLColor3 mWaterFogColor;
F32 mWaterFogDensity;
F32 mFogMod;
F32 mFresnelOffset;
F32 mFresnelScale;
LLVector3 mNormalScale;
F32 mScaleAbove;
F32 mScaleBelow;
LLVector2 mWave1Dir;
LLVector2 mWave2Dir;
};
#endif
+179
View File
@@ -0,0 +1,179 @@
/**
* @file lltransactionflags.cpp
* @brief Some exported symbols and functions for dealing with
* transaction flags.
*
* $LicenseInfo:firstyear=2003&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lluuid.h"
#include "lltransactionflags.h"
#include "lltransactiontypes.h"
#include "tea.h" // <FS:AW opensim currency support>
const U8 TRANSACTION_FLAGS_NONE = 0;
const U8 TRANSACTION_FLAG_SOURCE_GROUP = 1;
const U8 TRANSACTION_FLAG_DEST_GROUP = 2;
const U8 TRANSACTION_FLAG_OWNER_GROUP = 4;
const U8 TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION = 8;
const U8 TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION_REMOVAL = 16;
U8 pack_transaction_flags(bool is_source_group, bool is_dest_group)
{
U8 rv = 0;
if(is_source_group) rv |= TRANSACTION_FLAG_SOURCE_GROUP;
if(is_dest_group) rv |= TRANSACTION_FLAG_DEST_GROUP;
return rv;
}
bool is_tf_source_group(TransactionFlags flags)
{
return ((flags & TRANSACTION_FLAG_SOURCE_GROUP) == TRANSACTION_FLAG_SOURCE_GROUP);
}
bool is_tf_dest_group(TransactionFlags flags)
{
return ((flags & TRANSACTION_FLAG_DEST_GROUP) == TRANSACTION_FLAG_DEST_GROUP);
}
bool is_tf_owner_group(TransactionFlags flags)
{
return ((flags & TRANSACTION_FLAG_OWNER_GROUP) == TRANSACTION_FLAG_OWNER_GROUP);
}
void append_reason(std::ostream& ostr, S32 transaction_type, const std::string& description); // <FS:CR>
void append_reason(
std::ostream& ostr,
S32 transaction_type,
const std::string& description)
{
switch( transaction_type )
{
case TRANS_OBJECT_SALE:
ostr << " for " << (description.length() > 0 ? description : std::string("<unknown>"));
break;
case TRANS_LAND_SALE:
ostr << " for a parcel of land";
break;
case TRANS_LAND_PASS_SALE:
ostr << " for a land access pass";
break;
case TRANS_GROUP_LAND_DEED:
ostr << " for deeding land";
break;
default:
break;
}
}
std::string build_transfer_message_to_source(
S32 amount,
const LLUUID& source_id,
const LLUUID& dest_id,
const std::string& dest_name,
S32 transaction_type,
const std::string& description)
{
LL_DEBUGS() << "build_transfer_message_to_source: " << amount << " "
<< source_id << " " << dest_id << " " << dest_name << " "
<< transaction_type << " "
<< (description.empty() ? "(no desc)" : description)
<< LL_ENDL;
if(source_id.isNull())
{
return description;
}
if((0 == amount) && description.empty())
{
return description;
}
std::ostringstream ostr;
if(dest_id.isNull())
{
// *NOTE: Do not change these strings! The viewer matches
// them in llviewermessage.cpp to perform localization.
// If you need to make changes, add a new, localizable message. JC
// <FS:AW opensim currency support>
// ostr << "You paid L$" << amount;
ostr << Tea::wrapCurrency("You paid L$") << amount;
// </FS:AW opensim currency support>
switch(transaction_type)
{
case TRANS_GROUP_CREATE:
ostr << " to create a group";
break;
case TRANS_GROUP_JOIN:
ostr << " to join a group";
break;
case TRANS_UPLOAD_CHARGE:
ostr << " to upload";
break;
default:
break;
}
}
else
{
// <FS:AW opensim currency support>
// ostr << "You paid " << dest_name << " L$" << amount;
ostr << "You paid " << dest_name << Tea::wrapCurrency(" L$") << amount;
// </FS:AW opensim currency support>
append_reason(ostr, transaction_type, description);
}
ostr << ".";
return ostr.str();
}
std::string build_transfer_message_to_destination(
S32 amount,
const LLUUID& dest_id,
const LLUUID& source_id,
const std::string& source_name,
S32 transaction_type,
const std::string& description)
{
LL_DEBUGS() << "build_transfer_message_to_dest: " << amount << " "
<< dest_id << " " << source_id << " " << source_name << " "
<< transaction_type << " " << (description.empty() ? "(no desc)" : description)
<< LL_ENDL;
if(0 == amount)
{
return std::string();
}
if(dest_id.isNull())
{
return description;
}
std::ostringstream ostr;
// *NOTE: Do not change these strings! The viewer matches
// them in llviewermessage.cpp to perform localization.
// If you need to make changes, add a new, localizable message. JC
// <FS:AW opensim currency support>
// ostr << source_name << " paid you L$" << amount;
ostr << source_name << Tea::wrapCurrency(" paid you L$") << amount;
// </FS:AW opensim currency support>
append_reason(ostr, transaction_type, description);
ostr << ".";
return ostr.str();
}
+65
View File
@@ -0,0 +1,65 @@
/**
* @file lltransactionflags.h
*
* $LicenseInfo:firstyear=2003&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLTRANSACTIONFLAGS_H
#define LL_LLTRANSACTIONFLAGS_H
class LLUUID;
typedef U8 TransactionFlags;
// defined in common/llinventory/lltransactionflags.cpp
extern const TransactionFlags TRANSACTION_FLAGS_NONE;
extern const TransactionFlags TRANSACTION_FLAG_SOURCE_GROUP;
extern const TransactionFlags TRANSACTION_FLAG_DEST_GROUP;
extern const TransactionFlags TRANSACTION_FLAG_OWNER_GROUP;
extern const TransactionFlags TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION;
extern const TransactionFlags TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION_REMOVAL;
// very simple helper functions
TransactionFlags pack_transaction_flags(bool is_source_group, bool is_dest_group);
bool is_tf_source_group(TransactionFlags flags);
bool is_tf_dest_group(TransactionFlags flags);
bool is_tf_owner_group(TransactionFlags flags);
// stupid helper functions which should be replaced with some kind of
// internationalizeable message.
std::string build_transfer_message_to_source(
S32 amount,
const LLUUID& source_id,
const LLUUID& dest_id,
const std::string& dest_name,
S32 transaction_type,
const std::string& description);
std::string build_transfer_message_to_destination(
S32 amount,
const LLUUID& dest_id,
const LLUUID& source_id,
const std::string& source_name,
S32 transaction_type,
const std::string& description);
#endif // LL_LLTRANSACTIONFLAGS_H
+124
View File
@@ -0,0 +1,124 @@
/**
* @file lltransactiontypes.h
*
* $LicenseInfo:firstyear=2003&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLTRANSACTIONTYPES_H
#define LL_LLTRANSACTIONTYPES_H
// *NOTE: The constants in this file are also in the
// transaction_description table in the database. If you add a
// constant here, please add it to the database. eg:
//
// insert into transaction_description
// set type = 1000, description = 'Object Claim';
//
// Also add it to the various L$ string lookups on the dataserver
// in lldatamoney
// Money transaction failure codes
const U8 TRANS_FAIL_SIMULATOR_TIMEOUT = 1;
const U8 TRANS_FAIL_DATASERVER_TIMEOUT = 2;
const U8 TRANS_FAIL_APPLICATION = 3;
// Codes up to 999 for error conditions
const S32 TRANS_NULL = 0;
// Codes 1000-1999 reserved for one-time charges
const S32 TRANS_OBJECT_CLAIM = 1000;
const S32 TRANS_LAND_CLAIM = 1001;
const S32 TRANS_GROUP_CREATE = 1002;
const S32 TRANS_OBJECT_PUBLIC_CLAIM = 1003;
const S32 TRANS_GROUP_JOIN = 1004; // May be moved to group transactions eventually
const S32 TRANS_TELEPORT_CHARGE = 1100; // FF not sure why this jumps to 1100...
const S32 TRANS_UPLOAD_CHARGE = 1101;
const S32 TRANS_LAND_AUCTION = 1102;
const S32 TRANS_CLASSIFIED_CHARGE = 1103;
// Codes 2000-2999 reserved for recurrent charges
const S32 TRANS_OBJECT_TAX = 2000;
const S32 TRANS_LAND_TAX = 2001;
const S32 TRANS_LIGHT_TAX = 2002;
const S32 TRANS_PARCEL_DIR_FEE = 2003;
const S32 TRANS_GROUP_TAX = 2004; // Taxes incurred as part of group membership
const S32 TRANS_CLASSIFIED_RENEW = 2005;
// Codes 2100-2999 reserved for recurring billing services
// New codes can be created through an admin interface so may not
// automatically end up in the list below :-(
// So make sure you check the transaction_description table
const S32 TRANS_RECURRING_GENERIC = 2100;
// Codes 3000-3999 reserved for inventory transactions
const S32 TRANS_GIVE_INVENTORY = 3000;
// Codes 5000-5999 reserved for transfers between users
const S32 TRANS_OBJECT_SALE = 5000;
const S32 TRANS_GIFT = 5001;
const S32 TRANS_LAND_SALE = 5002;
const S32 TRANS_REFER_BONUS = 5003;
const S32 TRANS_INVENTORY_SALE = 5004;
const S32 TRANS_REFUND_PURCHASE = 5005;
const S32 TRANS_LAND_PASS_SALE = 5006;
const S32 TRANS_DWELL_BONUS = 5007;
const S32 TRANS_PAY_OBJECT = 5008;
const S32 TRANS_OBJECT_PAYS = 5009;
// Codes 5100-5999 reserved for recurring billing transfers between users
// New codes can be created through an admin interface so may not
// automatically end up in the list below :-(
// So make sure you check the transaction_description table
const S32 TRANS_RECURRING_GENERIC_USER = 5100;
// Codes 6000-6999 reserved for group transactions
//const S32 TRANS_GROUP_JOIN = 6000; //reserved for future use
const S32 TRANS_GROUP_LAND_DEED = 6001;
const S32 TRANS_GROUP_OBJECT_DEED = 6002;
const S32 TRANS_GROUP_LIABILITY = 6003;
const S32 TRANS_GROUP_DIVIDEND = 6004;
const S32 TRANS_MEMBERSHIP_DUES = 6005;
// Codes 8000-8999 reserved for one-type credits
const S32 TRANS_OBJECT_RELEASE = 8000;
const S32 TRANS_LAND_RELEASE = 8001;
const S32 TRANS_OBJECT_DELETE = 8002;
const S32 TRANS_OBJECT_PUBLIC_DECAY = 8003;
const S32 TRANS_OBJECT_PUBLIC_DELETE= 8004;
// Code 9000-9099 reserved for usertool transactions
const S32 TRANS_LINDEN_ADJUSTMENT = 9000;
const S32 TRANS_LINDEN_GRANT = 9001;
const S32 TRANS_LINDEN_PENALTY = 9002;
const S32 TRANS_EVENT_FEE = 9003;
const S32 TRANS_EVENT_PRIZE = 9004;
// These must match entries in money_stipend table in MySQL
// Codes 10000-10999 reserved for stipend credits
const S32 TRANS_STIPEND_BASIC = 10000;
const S32 TRANS_STIPEND_DEVELOPER = 10001;
const S32 TRANS_STIPEND_ALWAYS = 10002;
const S32 TRANS_STIPEND_DAILY = 10003;
const S32 TRANS_STIPEND_RATING = 10004;
const S32 TRANS_STIPEND_DELTA = 10005;
#endif
+112
View File
@@ -0,0 +1,112 @@
/**
* @file lluserrelations.cpp
* @author Phoenix
* @date 2006-10-12
* @brief Implementation of a simple cache of user relations.
*
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lluserrelations.h"
// static
const U8 LLRelationship::GRANTED_VISIBLE_MASK = LLRelationship::GRANT_MODIFY_OBJECTS | LLRelationship::GRANT_MAP_LOCATION;
const LLRelationship LLRelationship::DEFAULT_RELATIONSHIP = LLRelationship(GRANT_ONLINE_STATUS, GRANT_ONLINE_STATUS, false);
LLRelationship::LLRelationship() :
mGrantToAgent(0),
mGrantFromAgent(0),
mChangeSerialNum(0),
mIsOnline(false)
{
}
LLRelationship::LLRelationship(S32 grant_to, S32 grant_from, bool is_online) :
mGrantToAgent(grant_to),
mGrantFromAgent(grant_from),
mChangeSerialNum(0),
mIsOnline(is_online)
{
}
bool LLRelationship::isOnline() const
{
return mIsOnline;
}
void LLRelationship::online(bool is_online)
{
mIsOnline = is_online;
mChangeSerialNum++;
}
bool LLRelationship::isRightGrantedTo(S32 rights) const
{
return ((mGrantToAgent & rights) == rights);
}
bool LLRelationship::isRightGrantedFrom(S32 rights) const
{
return ((mGrantFromAgent & rights) == rights);
}
S32 LLRelationship::getRightsGrantedTo() const
{
return mGrantToAgent;
}
S32 LLRelationship::getRightsGrantedFrom() const
{
return mGrantFromAgent;
}
void LLRelationship::grantRights(S32 to_agent, S32 from_agent)
{
mGrantToAgent |= to_agent;
mGrantFromAgent |= from_agent;
mChangeSerialNum++;
}
void LLRelationship::revokeRights(S32 to_agent, S32 from_agent)
{
mGrantToAgent &= ~to_agent;
mGrantFromAgent &= ~from_agent;
mChangeSerialNum++;
}
/*
bool LLGrantedRights::getNextRights(
LLUUID& agent_id,
S32& to_agent,
S32& from_agent) const
{
rights_map_t::const_iterator iter = mRights.upper_bound(agent_id);
if(iter == mRights.end()) return false;
agent_id = (*iter).first;
to_agent = (*iter).second.mToAgent;
from_agent = (*iter).second.mFromAgent;
return true;
}
*/
+183
View File
@@ -0,0 +1,183 @@
/**
* @file lluserrelations.h
* @author Phoenix
* @date 2006-10-12
* @brief Declaration of a class for handling granted rights.
*
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLUSERRELAIONS_H
#define LL_LLUSERRELAIONS_H
#include <map>
#include "lluuid.h"
/**
* @class LLRelationship
*
* This class represents a relationship between two agents, where the
* related agent is stored and the other agent is the relationship is
* implicit by container ownership.
* This is merely a cache of this information used by the sim
* and viewer.
*
* You are expected to use this in a map or similar structure, eg:
* typedef std::map<LLUUID, LLRelationship> agent_relationship_map;
*/
class LLRelationship
{
public:
/**
* @brief Constructors.
*/
LLRelationship();
LLRelationship(S32 grant_to, S32 grant_from, bool is_online);
static const LLRelationship DEFAULT_RELATIONSHIP;
/**
* @name Status functionality
*
* I thought it would be keen to have a generic status interface,
* but the only thing we currently cache is online status. As this
* assumption changes, this API may evolve.
*/
//@{
/**
* @brief Does this instance believe the related agent is currently
* online or available.
*
* NOTE: This API may be deprecated if there is any transient status
* other than online status, for example, away/busy/etc.
*
* This call does not check any kind of central store or make any
* deep information calls - it simply checks a cache of online
* status.
* @return Returns true if this relationship believes the agent is
* online.
*/
bool isOnline() const;
/**
* @brief Set the online status.
*
* NOTE: This API may be deprecated if there is any transient status
* other than online status.
* @param is_online Se the online status
*/
void online(bool is_online);
//@}
/* @name Granted rights
*/
//@{
/**
* @brief Anonymous enumeration for specifying rights.
*/
enum
{
GRANT_NONE = 0x0,
GRANT_ONLINE_STATUS = 0x1,
GRANT_MAP_LOCATION = 0x2,
GRANT_MODIFY_OBJECTS = 0x4,
};
/**
* ???
*/
static const U8 GRANTED_VISIBLE_MASK;
/**
* @brief Check for a set of rights granted to agent.
*
* @param rights A bitfield to check for rights.
* @return Returns true if all rights have been granted.
*/
bool isRightGrantedTo(S32 rights) const;
/**
* @brief Check for a set of rights granted from an agent.
*
* @param rights A bitfield to check for rights.
* @return Returns true if all rights have been granted.
*/
bool isRightGrantedFrom(S32 rights) const;
/**
* @brief Get the rights granted to the other agent.
*
* @return Returns the bitmask of granted rights.
*/
S32 getRightsGrantedTo() const;
/**
* @brief Get the rights granted from the other agent.
*
* @return Returns the bitmask of granted rights.
*/
S32 getRightsGrantedFrom() const;
void setRightsTo(S32 to_agent) { mGrantToAgent = to_agent; mChangeSerialNum++; }
void setRightsFrom(S32 from_agent) { mGrantFromAgent = from_agent; mChangeSerialNum++;}
/**
* @brief Get the change count for this agent
*
* Every change to rights will increment the serial number
* allowing listeners to determine when a relationship value is actually new
*
* @return change serial number for relationship
*/
S32 getChangeSerialNum() const { return mChangeSerialNum; }
/**
* @brief Grant a set of rights.
*
* Any bit which is set will grant that right if it is set in the
* instance. You can pass in LLGrantedRights::NONE to not change
* that field.
* @param to_agent The rights to grant to agent_id.
* @param from_agent The rights granted from agent_id.
*/
void grantRights(S32 to_agent, S32 from_agent);
/**
* @brief Revoke a set of rights.
*
* Any bit which is set will revoke that right if it is set in the
* instance. You can pass in LLGrantedRights::NONE to not change
* that field.
* @param to_agent The rights to grant to agent_id.
* @param from_agent The rights granted from agent_id.
*/
void revokeRights(S32 to_agent, S32 from_agent);
//@}
protected:
S32 mGrantToAgent;
S32 mGrantFromAgent;
S32 mChangeSerialNum;
bool mIsOnline;
};
#endif // LL_LLUSERRELAIONS_H
@@ -0,0 +1,512 @@
/**
* @file inventory.cpp
* @author Phoenix
* @date 2005-11-15
* @brief Functions for inventory test framework
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llsd.h"
#include "llsdserialize.h"
#include "../llinventory.h"
#include "../test/lltut.h"
#if LL_WINDOWS
// disable unreachable code warnings
#pragma warning(disable: 4702)
#endif
LLPointer<LLInventoryItem> create_random_inventory_item()
{
LLUUID item_id;
item_id.generate();
LLUUID parent_id;
parent_id.generate();
LLPermissions perm;
LLUUID creator_id;
creator_id.generate();
LLUUID owner_id;
owner_id.generate();
LLUUID last_owner_id;
last_owner_id.generate();
LLUUID group_id;
group_id.generate();
perm.init(creator_id, owner_id, last_owner_id, group_id);
perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY);
LLUUID asset_id;
asset_id.generate();
S32 price = rand();
LLSaleInfo sale_info(LLSaleInfo::FS_COPY, price);
U32 flags = rand();
S32 creation = (S32)time(NULL);
LLPointer<LLInventoryItem> item = new LLInventoryItem(
item_id,
parent_id,
perm,
asset_id,
LLAssetType::AT_OBJECT,
LLInventoryType::IT_ATTACHMENT,
std::string("Sample Object"),
std::string("Used for Testing"),
sale_info,
flags,
creation);
return item;
}
LLPointer<LLInventoryCategory> create_random_inventory_cat()
{
LLUUID item_id;
item_id.generate();
LLUUID parent_id;
parent_id.generate();
LLPointer<LLInventoryCategory> cat = new LLInventoryCategory(
item_id,
parent_id,
LLFolderType::FT_NONE,
std::string("Sample category"));
return cat;
}
namespace tut
{
struct inventory_data
{
};
typedef test_group<inventory_data> inventory_test;
typedef inventory_test::object inventory_object;
tut::inventory_test inv("LLInventory");
//***class LLInventoryType***//
template<> template<>
void inventory_object::test<1>()
{
LLInventoryType::EType retType = LLInventoryType::lookup(std::string("sound"));
ensure("1.LLInventoryType::lookup(char*) failed", retType == LLInventoryType::IT_SOUND);
retType = LLInventoryType::lookup(std::string("snapshot"));
ensure("2.LLInventoryType::lookup(char*) failed", retType == LLInventoryType::IT_SNAPSHOT);
}
template<> template<>
void inventory_object::test<2>()
{
static std::string retType = LLInventoryType::lookup(LLInventoryType::IT_CALLINGCARD);
ensure("1.LLInventoryType::lookup(EType) failed", (retType == "callcard"));
retType = LLInventoryType::lookup(LLInventoryType::IT_LANDMARK);
ensure("2.LLInventoryType::lookup(EType) failed", (retType == "landmark"));
}
template<> template<>
void inventory_object::test<3>()
{
static std::string retType = LLInventoryType::lookupHumanReadable(LLInventoryType::IT_CALLINGCARD);
ensure("1.LLInventoryType::lookupHumanReadable(EType) failed", (retType == "calling card"));
retType = LLInventoryType::lookupHumanReadable(LLInventoryType::IT_LANDMARK);
ensure("2.LLInventoryType::lookupHumanReadable(EType) failed", (retType == "landmark"));
}
template<> template<>
void inventory_object::test<4>()
{
static LLInventoryType::EType retType = LLInventoryType::defaultForAssetType(LLAssetType::AT_TEXTURE);
ensure("1.LLInventoryType::defaultForAssetType(LLAssetType EType) failed", retType == LLInventoryType::IT_TEXTURE);
retType = LLInventoryType::defaultForAssetType(LLAssetType::AT_LANDMARK);
ensure("2.LLInventoryType::defaultForAssetType(LLAssetType EType) failed", retType == LLInventoryType::IT_LANDMARK);
}
//*****class LLInventoryItem*****//
template<> template<>
void inventory_object::test<5>()
{
LLPointer<LLInventoryItem> src = create_random_inventory_item();
LLSD sd = ll_create_sd_from_inventory_item(src);
//LL_INFOS() << "sd: " << *sd << LL_ENDL;
LLPointer<LLInventoryItem> dst = new LLInventoryItem;
bool successful_parse = dst->fromLLSD(sd);
ensure_equals("0.LLInventoryItem::fromLLSD()", successful_parse, true);
ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src->getUUID());
ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID());
ensure_equals("3.name::getName() failed", dst->getName(), src->getName());
ensure_equals("4.type::getType() failed", dst->getType(), src->getType());
ensure_equals("5.permissions::getPermissions() failed", dst->getPermissions(), src->getPermissions());
ensure_equals("6.description::getDescription() failed", dst->getDescription(), src->getDescription());
ensure_equals("7.sale type::getSaleType() failed", dst->getSaleInfo().getSaleType(), src->getSaleInfo().getSaleType());
ensure_equals("8.sale price::getSalePrice() failed", dst->getSaleInfo().getSalePrice(), src->getSaleInfo().getSalePrice());
ensure_equals("9.asset id::getAssetUUID() failed", dst->getAssetUUID(), src->getAssetUUID());
ensure_equals("10.inventory type::getInventoryType() failed", dst->getInventoryType(), src->getInventoryType());
ensure_equals("11.flags::getFlags() failed", dst->getFlags(), src->getFlags());
ensure_equals("12.creation::getCreationDate() failed", dst->getCreationDate(), src->getCreationDate());
LLUUID new_item_id, new_parent_id;
new_item_id.generate();
src->setUUID(new_item_id);
new_parent_id.generate();
src->setParent(new_parent_id);
std::string new_name = "LindenLab";
src->rename(new_name);
src->setType(LLAssetType::AT_SOUND);
LLUUID new_asset_id;
new_asset_id.generate();
src->setAssetUUID(new_asset_id);
std::string new_desc = "SecondLife Testing";
src->setDescription(new_desc);
S32 new_price = rand();
LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price);
src->setSaleInfo(new_sale_info);
U32 new_flags = rand();
S32 new_creation = (S32)time(NULL);
LLPermissions new_perm;
LLUUID new_creator_id;
new_creator_id.generate();
LLUUID new_owner_id;
new_owner_id.generate();
LLUUID last_owner_id;
last_owner_id.generate();
LLUUID new_group_id;
new_group_id.generate();
new_perm.init(new_creator_id, new_owner_id, last_owner_id, new_group_id);
new_perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY);
src->setPermissions(new_perm);
src->setInventoryType(LLInventoryType::IT_SOUND);
src->setFlags(new_flags);
src->setCreationDate(new_creation);
sd = ll_create_sd_from_inventory_item(src);
//LL_INFOS() << "sd: " << *sd << LL_ENDL;
successful_parse = dst->fromLLSD(sd);
ensure_equals("13.item id::getUUID() failed", dst->getUUID(), src->getUUID());
ensure_equals("14.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID());
ensure_equals("15.name::getName() failed", dst->getName(), src->getName());
ensure_equals("16.type::getType() failed", dst->getType(), src->getType());
ensure_equals("17.permissions::getPermissions() failed", dst->getPermissions(), src->getPermissions());
ensure_equals("18.description::getDescription() failed", dst->getDescription(), src->getDescription());
ensure_equals("19.sale type::getSaleType() failed type", dst->getSaleInfo().getSaleType(), src->getSaleInfo().getSaleType());
ensure_equals("20.sale price::getSalePrice() failed price", dst->getSaleInfo().getSalePrice(), src->getSaleInfo().getSalePrice());
ensure_equals("21.asset id::getAssetUUID() failed id", dst->getAssetUUID(), src->getAssetUUID());
ensure_equals("22.inventory type::getInventoryType() failed type", dst->getInventoryType(), src->getInventoryType());
ensure_equals("23.flags::getFlags() failed", dst->getFlags(), src->getFlags());
ensure_equals("24.creation::getCreationDate() failed", dst->getCreationDate(), src->getCreationDate());
}
template<> template<>
void inventory_object::test<6>()
{
LLPointer<LLInventoryItem> src = create_random_inventory_item();
LLUUID new_item_id, new_parent_id;
new_item_id.generate();
src->setUUID(new_item_id);
new_parent_id.generate();
src->setParent(new_parent_id);
std::string new_name = "LindenLab";
src->rename(new_name);
src->setType(LLAssetType::AT_SOUND);
LLUUID new_asset_id;
new_asset_id.generate();
src->setAssetUUID(new_asset_id);
std::string new_desc = "SecondLife Testing";
src->setDescription(new_desc);
S32 new_price = rand();
LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price);
src->setSaleInfo(new_sale_info);
U32 new_flags = rand();
S32 new_creation = (S32)time(NULL);
LLPermissions new_perm;
LLUUID new_creator_id;
new_creator_id.generate();
LLUUID new_owner_id;
new_owner_id.generate();
LLUUID last_owner_id;
last_owner_id.generate();
LLUUID new_group_id;
new_group_id.generate();
new_perm.init(new_creator_id, new_owner_id, last_owner_id, new_group_id);
new_perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY);
src->setPermissions(new_perm);
src->setInventoryType(LLInventoryType::IT_SOUND);
src->setFlags(new_flags);
src->setCreationDate(new_creation);
// test a save/load cycle to LLSD and back again
LLSD sd = ll_create_sd_from_inventory_item(src);
LLPointer<LLInventoryItem> dst = new LLInventoryItem;
bool successful_parse = dst->fromLLSD(sd);
ensure_equals("0.LLInventoryItem::fromLLSD()", successful_parse, true);
LLPointer<LLInventoryItem> src1 = create_random_inventory_item();
src1->copyItem(src);
ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src1->getUUID());
ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src1->getParentUUID());
ensure_equals("3.name::getName() failed", dst->getName(), src1->getName());
ensure_equals("4.type::getType() failed", dst->getType(), src1->getType());
ensure_equals("5.permissions::getPermissions() failed", dst->getPermissions(), src1->getPermissions());
ensure_equals("6.description::getDescription() failed", dst->getDescription(), src1->getDescription());
ensure_equals("7.sale type::getSaleType() failed type", dst->getSaleInfo().getSaleType(), src1->getSaleInfo().getSaleType());
ensure_equals("8.sale price::getSalePrice() failed price", dst->getSaleInfo().getSalePrice(), src1->getSaleInfo().getSalePrice());
ensure_equals("9.asset id::getAssetUUID() failed id", dst->getAssetUUID(), src1->getAssetUUID());
ensure_equals("10.inventory type::getInventoryType() failed type", dst->getInventoryType(), src1->getInventoryType());
ensure_equals("11.flags::getFlags() failed", dst->getFlags(), src1->getFlags());
ensure_equals("12.creation::getCreationDate() failed", dst->getCreationDate(), src1->getCreationDate());
// quick test to make sure generateUUID() really works
src1->generateUUID();
ensure_not_equals("13.item id::generateUUID() failed", src->getUUID(), src1->getUUID());
}
template<> template<>
void inventory_object::test<7>()
{
std::string filename("linden_file.dat");
llofstream fileXML(filename.c_str());
if (!fileXML.is_open())
{
LL_ERRS() << "file could not be opened\n" << LL_ENDL;
return;
}
LLPointer<LLInventoryItem> src1 = create_random_inventory_item();
fileXML << LLSDOStreamer<LLSDNotationFormatter>(src1->asLLSD()) << std::endl;
fileXML.close();
LLPointer<LLInventoryItem> src2 = new LLInventoryItem();
llifstream file(filename.c_str());
if (!file.is_open())
{
LL_ERRS() << "file could not be opened\n" << LL_ENDL;
return;
}
std::string line;
LLPointer<LLSDParser> parser = new LLSDNotationParser();
std::getline(file, line);
LLSD s_item;
std::istringstream iss(line);
if (parser->parse(iss, s_item, line.length()) == LLSDParser::PARSE_FAILURE)
{
LL_ERRS()<< "Parsing cache failed" << LL_ENDL;
return;
}
src2->fromLLSD(s_item);
file.close();
ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID());
ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID());
ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions());
ensure_equals("4.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice());
ensure_equals("5.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID());
ensure_equals("6.type::getType() failed", src1->getType(), src2->getType());
ensure_equals("7.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType());
ensure_equals("8.name::getName() failed", src1->getName(), src2->getName());
ensure_equals("9.description::getDescription() failed", src1->getDescription(), src2->getDescription());
ensure_equals("10.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate());
}
template<> template<>
void inventory_object::test<8>()
{
LLPointer<LLInventoryItem> src1 = create_random_inventory_item();
std::ostringstream ostream;
src1->exportLegacyStream(ostream, true);
std::istringstream istream(ostream.str());
LLPointer<LLInventoryItem> src2 = new LLInventoryItem();
src2->importLegacyStream(istream);
ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID());
ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID());
ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions());
ensure_equals("4.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice());
ensure_equals("5.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID());
ensure_equals("6.type::getType() failed", src1->getType(), src2->getType());
ensure_equals("7.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType());
ensure_equals("8.name::getName() failed", src1->getName(), src2->getName());
ensure_equals("9.description::getDescription() failed", src1->getDescription(), src2->getDescription());
ensure_equals("10.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate());
}
template<> template<>
void inventory_object::test<9>()
{
// Deleted LLInventoryItem::exportFileXML() and LLInventoryItem::importXML()
// because I can't find any non-test code references to it. 2009-05-04 JC
}
template<> template<>
void inventory_object::test<11>()
{
LLPointer<LLInventoryItem> src1 = create_random_inventory_item();
LLSD retSd = src1->asLLSD();
LLPointer<LLInventoryItem> src2 = new LLInventoryItem();
src2->fromLLSD(retSd);
ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID());
ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID());
ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions());
ensure_equals("4.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID());
ensure_equals("5.type::getType() failed", src1->getType(), src2->getType());
ensure_equals("6.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType());
ensure_equals("7.flags::getFlags() failed", src1->getFlags(), src2->getFlags());
ensure_equals("8.sale type::getSaleType() failed type", src1->getSaleInfo().getSaleType(), src2->getSaleInfo().getSaleType());
ensure_equals("9.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice());
ensure_equals("10.name::getName() failed", src1->getName(), src2->getName());
ensure_equals("11.description::getDescription() failed", src1->getDescription(), src2->getDescription());
ensure_equals("12.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate());
}
//******class LLInventoryCategory*******//
template<> template<>
void inventory_object::test<12>()
{
LLPointer<LLInventoryCategory> src = create_random_inventory_cat();
LLSD sd = ll_create_sd_from_inventory_category(src);
LLPointer<LLInventoryCategory> dst = ll_create_category_from_sd(sd);
ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src->getUUID());
ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID());
ensure_equals("3.name::getName() failed", dst->getName(), src->getName());
ensure_equals("4.type::getType() failed", dst->getType(), src->getType());
ensure_equals("5.preferred type::getPreferredType() failed", dst->getPreferredType(), src->getPreferredType());
src->setPreferredType( LLFolderType::FT_TEXTURE);
sd = ll_create_sd_from_inventory_category(src);
dst = ll_create_category_from_sd(sd);
ensure_equals("6.preferred type::getPreferredType() failed", dst->getPreferredType(), src->getPreferredType());
}
template<> template<>
void inventory_object::test<13>()
{
std::string filename("linden_file.dat");
llofstream fileXML(filename.c_str());
if (!fileXML.is_open())
{
LL_ERRS() << "file could not be opened\n" << LL_ENDL;
return;
}
LLPointer<LLInventoryCategory> src1 = create_random_inventory_cat();
fileXML << LLSDOStreamer<LLSDNotationFormatter>(src1->exportLLSD()) << std::endl;
fileXML.close();
llifstream file(filename.c_str());
if (!file.is_open())
{
LL_ERRS() << "file could not be opened\n" << LL_ENDL;
return;
}
std::string line;
LLPointer<LLSDParser> parser = new LLSDNotationParser();
std::getline(file, line);
LLSD s_item;
std::istringstream iss(line);
if (parser->parse(iss, s_item, line.length()) == LLSDParser::PARSE_FAILURE)
{
LL_ERRS()<< "Parsing cache failed" << LL_ENDL;
return;
}
file.close();
LLPointer<LLInventoryCategory> src2 = new LLInventoryCategory();
src2->importLLSD(s_item);
ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID());
ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID());
ensure_equals("3.type::getType() failed", src1->getType(), src2->getType());
ensure_equals("4.preferred type::getPreferredType() failed", src1->getPreferredType(), src2->getPreferredType());
ensure_equals("5.name::getName() failed", src1->getName(), src2->getName());
}
template<> template<>
void inventory_object::test<14>()
{
LLPointer<LLInventoryCategory> src1 = create_random_inventory_cat();
std::ostringstream ostream;
src1->exportLegacyStream(ostream, true);
std::istringstream istream(ostream.str());
LLPointer<LLInventoryCategory> src2 = new LLInventoryCategory();
src2->importLegacyStream(istream);
ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID());
ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID());
ensure_equals("3.type::getType() failed", src1->getType(), src2->getType());
ensure_equals("4.preferred type::getPreferredType() failed", src1->getPreferredType(), src2->getPreferredType());
ensure_equals("5.name::getName() failed", src1->getName(), src2->getName());
}
}
+69
View File
@@ -0,0 +1,69 @@
/**
* @file llinventoryparcel_tut.cpp
* @author Moss
* @date 2007-04-17
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include <string>
#include "linden_common.h"
#include "../llparcel.h"
#include "../test/lltut.h"
namespace tut
{
struct llinventoryparcel_data
{
};
typedef test_group<llinventoryparcel_data> llinventoryparcel_test;
typedef llinventoryparcel_test::object llinventoryparcel_object;
tut::llinventoryparcel_test llinventoryparcel("LLInventoryParcel");
template<> template<>
void llinventoryparcel_object::test<1>()
{
for (S32 i=0; i<LLParcel::C_COUNT; ++i)
{
const std::string& catstring = LLParcel::getCategoryString(LLParcel::ECategory(i));
ensure("LLParcel::getCategoryString(i)",
!catstring.empty());
const std::string& catuistring = LLParcel::getCategoryUIString(LLParcel::ECategory(i));
ensure("LLParcel::getCategoryUIString(i)",
!catuistring.empty());
ensure_equals("LLParcel::ECategory mapping of string back to enum", LLParcel::getCategoryFromString(catstring), i);
ensure_equals("LLParcel::ECategory mapping of uistring back to enum", LLParcel::getCategoryFromUIString(catuistring), i);
}
// test the C_ANY case, which has to work for UI strings
const std::string& catuistring = LLParcel::getCategoryUIString(LLParcel::C_ANY);
ensure("LLParcel::getCategoryUIString(C_ANY)",
!catuistring.empty());
ensure_equals("LLParcel::ECategory mapping of uistring back to enum", LLParcel::getCategoryFromUIString(catuistring), LLParcel::C_ANY);
}
}