Fixing up/classifying Nicky D's fsvopartgroup code

Liny 2014-07-21 20:50:36 -07:00
parent b37c6e7cf0
commit 1fcb6f4086
5 changed files with 155 additions and 34 deletions

View File

@ -184,6 +184,7 @@ set(viewer_SOURCE_FILES
fsradarmenu.cpp
fsscriptlibrary.cpp
fsslurlcommand.cpp
fsvopartgroup.cpp
fswsassetblacklist.cpp
groupchatlistener.cpp
#growlmanager.cpp
@ -885,6 +886,7 @@ set(viewer_HEADER_FILES
fsscriptlibrary.h
fsslurl.h
fsslurlcommand.h
fsvopartgroup.h
fswsassetblacklist.h
groupchatlistener.h
llaccountingcost.h

View File

@ -1,8 +1,46 @@
U32 sFreeIndex[LL_MAX_PARTICLE_COUNT/32] = {0};
U32 sIndexGeneration = 1;
U32 sTotalParticles = 0;
/**
* @file fsvopartgroup.cpp
* @brief fsvopartgroup base class
*
* $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$
*/
U32 bitMasks[ 32 ] = { 0xFFFFFFFF, 0x80000000, 0xC0000000, 0xE0000000,
#include "llviewerprecompiledheaders.h"
#include "llviewerpartsim.h" // For LL_MAX_PARTICLE_COUNT
#include "fsvopartgroup.h"
FSVOPartGroup::FSVOPartGroup()
{
for(int i = 0; i < sFreeIndexSize; i++)
{
setFreeIndex(i,0);
}
setIndexGeneration(1);
setTotalParticles(0);
U32 bitMasksTmp[ 32 ] = { 0xFFFFFFFF, 0x80000000, 0xC0000000, 0xE0000000,
0xF0000000, 0xF8000000, 0xFC000000, 0xFE000000,
0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000,
@ -11,12 +49,19 @@ U32 bitMasks[ 32 ] = { 0xFFFFFFFF, 0x80000000, 0xC0000000, 0xE0000000,
0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0,
0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE };
bool findAvailableVBSlots( S32 &idxStart, S32 &idxEnd, U32 amount )
for(int i = 0;i<32;i++)
{
bitMasks[i] = bitMasksTmp[i];
}
}
bool FSVOPartGroup::findAvailableVBSlots( S32 &idxStart, S32 &idxEnd, U32 amount )
{
idxStart = idxEnd = -1;
if( amount + sTotalParticles > LL_MAX_PARTICLE_COUNT )
amount = LL_MAX_PARTICLE_COUNT - sTotalParticles;
if( amount + getTotalParticles() > LL_MAX_PARTICLE_COUNT )
amount = LL_MAX_PARTICLE_COUNT - getTotalParticles();
U32 u32Count = amount/32;
U32 bitsLeft = amount - (u32Count*32);
@ -28,17 +73,17 @@ bool findAvailableVBSlots( S32 &idxStart, S32 &idxEnd, U32 amount )
int maxI = LL_MAX_PARTICLE_COUNT/32-u32Count;
do
{
while( sFreeIndex[i] != 0xFFFFFFFF && i <= maxI )
while( getFreeIndex(i) != 0xFFFFFFFF && i <= maxI )
++i;
if( i > maxI )
continue;
int j = i;
while( sFreeIndex[j] == 0xFFFFFFFF && j <= LL_MAX_PARTICLE_COUNT/32 && (j-i) != u32Count )
while( getFreeIndex(j) == 0xFFFFFFFF && j <= LL_MAX_PARTICLE_COUNT/32 && (j-i) != u32Count )
++j;
if( j > LL_MAX_PARTICLE_COUNT/32 || (i-j) != u32Count || (sFreeIndex[j-1] & maskLast) != maskLast )
if( j > LL_MAX_PARTICLE_COUNT/32 || (i-j) != u32Count || (getFreeIndex(j-1) & maskLast) != maskLast )
{
++i;
continue;
@ -52,13 +97,13 @@ bool findAvailableVBSlots( S32 &idxStart, S32 &idxEnd, U32 amount )
for( int l = 0; k != amount && l < 32; ++l )
{
U32 mask = 1 << l;
sFreeIndex[ i ] &= ~mask;
setFreeIndex(i, getFreeIndex(i) & ~mask);
++k;
}
++i;
}
sTotalParticles += amount;
setTotalParticles(getTotalParticles() + amount);
return true;
} while( i <= maxI);

View File

@ -0,0 +1,57 @@
/**
* @file fsvopartgroup.h
* @brief fsvopartgroup base class
*
* $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 FS_VOPARTGROUP_H
#define FS_VOPARTGROUP_H
#include "stdtypes.h"
#define sFreeIndexSize LL_MAX_PARTICLE_COUNT/32
class FSVOPartGroup
{
public:
FSVOPartGroup();
~FSVOPartGroup() {};
U32 getFreeIndex(int i) {return sFreeIndex[i];}
U32 getIndexGeneration() {return sIndexGeneration;}
U32 getTotalParticles() {return sTotalParticles;}
void setFreeIndex(int i, U32 val) {sFreeIndex[i] = val;}
void setIndexGeneration(U32 val) {sIndexGeneration = val;}
void setTotalParticles(U32 val) {sTotalParticles = val;}
bool findAvailableVBSlots( S32 &idxStart, S32 &idxEnd, U32 amount );
private:
U32 sFreeIndex[sFreeIndexSize];
U32 sIndexGeneration;
U32 sTotalParticles;
U32 bitMasks[ 32 ];
};
#endif // FS_VOPARTGROUP_H

View File

@ -51,7 +51,8 @@ extern U64MicrosecondsImplicit gFrameTime;
LLPointer<LLVertexBuffer> LLVOPartGroup::sVB = NULL;
S32 LLVOPartGroup::sVBSlotCursor = 0;
#include "fsvopartgroup.cpp"
#include "fsvopartgroup.h" //<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
FSVOPartGroup *LLVOPartGroup::fsvopartgroup = NULL;
void LLVOPartGroup::initClass()
{
@ -61,11 +62,12 @@ void LLVOPartGroup::initClass()
//static
void LLVOPartGroup::restoreGL()
{
sIndexGeneration += 2;
//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
fsvopartgroup->setIndexGeneration( fsvopartgroup->getIndexGeneration() + 2);
for( int i = 0; i < LL_MAX_PARTICLE_COUNT/32; ++i )
sFreeIndex[i] = 0xFFFFFFFF;
fsvopartgroup->setFreeIndex(i, 0xFFFFFFFF);
//</FS:LO>
//TODO: optimize out binormal mask here. Specular and normal coords as well.
sVB = new LLVertexBuffer(VERTEX_DATA_MASK | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2, GL_STREAM_DRAW_ARB);
@ -125,11 +127,19 @@ void LLVOPartGroup::destroyGL()
//static
S32 LLVOPartGroup::findAvailableVBSlot()
{
//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
/*if (sVBSlotCursor >= LL_MAX_PARTICLE_COUNT)
{ //no more available slots
return -1;
}
return sVBSlotCursor++;*/
for( int i = 0; i < LL_MAX_PARTICLE_COUNT/32; ++i )
{
if( sFreeIndex[i] != 0 )
if( fsvopartgroup->getFreeIndex(i) != 0 )
{
U32 val = sFreeIndex[i];
U32 val = fsvopartgroup->getFreeIndex(i);
U32 mask = 1;
int j(0);
for( j = 0; j < 32; ++j )
@ -143,21 +153,15 @@ S32 LLVOPartGroup::findAvailableVBSlot()
mask <<= 1;
}
sFreeIndex[ i ] = val & mask;
++sTotalParticles;
fsvopartgroup->setFreeIndex(i, val & mask);
fsvopartgroup->setTotalParticles(fsvopartgroup->getTotalParticles()+1);
return i*32+j;
}
}
return -1;
// if (sVBSlotCursor >= LL_MAX_PARTICLE_COUNT)
// { //no more available slots
// return -1;
// }
//
// return sVBSlotCursor++;
//</FS:LO>
}
bool ll_is_part_idx_allocated(S32 idx, S32* start, S32* end)
@ -176,6 +180,7 @@ bool ll_is_part_idx_allocated(S32 idx, S32* start, S32* end)
}
//static
//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
// void LLVOPartGroup::freeVBSlot(S32 idx)
void LLVOPartGroup::freeVBSlot(S32 idx, U32 generation )
{
@ -192,9 +197,10 @@ void LLVOPartGroup::freeVBSlot(S32 idx, U32 generation )
if( idx < 0 || idx >= LL_MAX_PARTICLE_COUNT )
return;
--sTotalParticles;
//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
fsvopartgroup->setTotalParticles(fsvopartgroup->getTotalParticles()-1);
if( sIndexGeneration != generation )
if( fsvopartgroup->getIndexGeneration() != generation )
return;
U32 i = (idx & ~0x0000001F) / 32;
@ -202,7 +208,8 @@ void LLVOPartGroup::freeVBSlot(S32 idx, U32 generation )
U32 mask = 1 << j;
sFreeIndex[ i ] |= mask;
fsvopartgroup->setFreeIndex(i, fsvopartgroup->getFreeIndex(i) | mask);
//</FS:LO>
}
LLVOPartGroup::LLVOPartGroup(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
@ -212,6 +219,7 @@ LLVOPartGroup::LLVOPartGroup(const LLUUID &id, const LLPCode pcode, LLViewerRegi
setNumTEs(1);
setTETexture(0, LLUUID::null);
mbCanSelect = FALSE; // users can't select particle systems
fsvopartgroup = new FSVOPartGroup();
}
@ -914,7 +922,7 @@ void LLParticlePartition::getGeometry(LLSpatialGroup* group)
(*itr)->setGeomIndex( 0 );
S32 idxStart, idxEnd;
bool bValidRange = findAvailableVBSlots( idxStart, idxEnd, mFaceList.size() );
bool bValidRange = LLVOPartGroup::getFsvopartgroup()->findAvailableVBSlots( idxStart, idxEnd, mFaceList.size() );
// </FS:ND>
for (std::vector<LLFace*>::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i)
@ -935,14 +943,14 @@ void LLParticlePartition::getGeometry(LLSpatialGroup* group)
}
else
idx = LLVOPartGroup::findAvailableVBSlot();
// <FS:ND>
// </FS:ND>
if (idx >= 0)
{
// <FS:ND> Face needs to release the index when it gets destroyed.
// facep->setGeomIndex(idx*4);
facep->setGeomIndex(idx*4, sIndexGeneration);
// <FS:ND>
facep->setGeomIndex(idx*4, LLVOPartGroup::getFsvopartgroup()->getIndexGeneration());
// </FS:ND>
facep->setIndicesIndex(idx*6);
facep->setVertexBuffer(LLVOPartGroup::sVB);

View File

@ -36,6 +36,8 @@
class LLViewerPartGroup;
class FSVOPartGroup; //<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
class LLVOPartGroup : public LLAlphaObject
{
public:
@ -106,6 +108,8 @@ public:
void setViewerPartGroup(LLViewerPartGroup *part_groupp) { mViewerPartGroupp = part_groupp; }
LLViewerPartGroup* getViewerPartGroup() { return mViewerPartGroupp; }
static FSVOPartGroup* getFsvopartgroup() {return fsvopartgroup;}//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
protected:
~LLVOPartGroup();
@ -113,6 +117,11 @@ protected:
virtual LLVector3 getCameraPosition() const;
//<FS:LO> Fixing up/classifying Nicky D's fsvopartgroup code
private:
static FSVOPartGroup* fsvopartgroup;
//</FS:LO>
};