Thread: [Opentnl-cvs] tnl/zap sparkManager.cpp,1.6,1.7 sparkManager.h,1.5,1.6
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2004-05-06 01:36:09
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4906/zap Modified Files: sparkManager.cpp sparkManager.h Log Message: New Vector resizing scheme to fix reallocation bug in vector Rolled back Ben's sparkManager changes Index: sparkManager.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** sparkManager.h 5 May 2004 09:50:35 -0000 1.5 --- sparkManager.h 6 May 2004 01:36:01 -0000 1.6 *************** *** 42,46 **** void tick( F32 dT); void render(); - void init(); }; --- 42,45 ---- Index: sparkManager.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sparkManager.cpp 5 May 2004 09:50:35 -0000 1.6 --- sparkManager.cpp 6 May 2004 01:36:01 -0000 1.7 *************** *** 42,46 **** F32 ttl; Point vel; - Spark *mNext, *mPrev; }; --- 42,45 ---- *************** *** 49,133 **** }; - Spark *mFree; - Spark *mActive; - Spark *mActiveTail; - U32 firstFreeIndex = 0; Spark gSparks[MaxSparks]; - void init() - { - // Put all the sparks (from gSparks) onto the free list and mark the tail. - U32 i; - for(i=0; i<MaxSparks-1; i++) - gSparks[i].mNext = &gSparks[i+1]; - gSparks[i+1].mNext = NULL; - - mFree = gSparks; - - // No active sparks yet. - mActive = NULL; - mActiveTail = NULL; - } - - Spark *getSpark() - { - // Are there any in the free list? - Spark *newSpark = NULL; - - if(mFree) - { - newSpark = mFree; - mFree = mFree->mNext; - if(mFree) mFree->mPrev = NULL; - } - else - { - // Reuse one from the active list... - if(mActiveTail) - { - newSpark = mActiveTail; - - if(newSpark->mPrev) newSpark->mPrev->mNext = NULL; - mActiveTail = newSpark->mPrev; - } - else - return NULL; - } - - // Put it at the head of the active list - newSpark->mPrev = NULL; - newSpark->mNext = mActive; - if(mActive) mActive->mPrev = newSpark; - mActive = newSpark; - - return newSpark; - } - - void freeSpark(Spark *s) - { - // Remove it safely from the list it's in... - if(s->mNext) s->mNext->mPrev = s->mPrev; - if(s->mPrev) s->mPrev->mNext = s->mNext; - if(s==mActive) mActive = mActive->mNext; - - // Update tail info - if(s->mNext == NULL) - mActiveTail = s->mPrev; - - // And add it to the free list - s->mNext = mFree; - s->mPrev = NULL; - if(mFree) mFree->mPrev = s; - mFree = s; - - } - void emitSpark(Point pos, Point vel, Color color, F32 ttl) { ! Spark *s = getSpark(); ! ! if(!s) return; s->pos = pos; --- 48,60 ---- }; U32 firstFreeIndex = 0; Spark gSparks[MaxSparks]; void emitSpark(Point pos, Point vel, Color color, F32 ttl) { ! if(firstFreeIndex >= MaxSparks) return; + Spark *s = gSparks + firstFreeIndex; + firstFreeIndex++; s->pos = pos; *************** *** 144,158 **** void tick( F32 dT ) { ! Spark *theSpark = mActive; ! while(theSpark) { if(theSpark->ttl <= dT) { ! Spark *t = theSpark->mNext; ! freeSpark(theSpark); ! theSpark = t; ! continue; // Skip to the next one... } ! theSpark->ttl -= dT; theSpark->pos += theSpark->vel * dT; --- 71,84 ---- void tick( F32 dT ) { ! for(U32 i = 0; i < firstFreeIndex; ) { + Spark *theSpark = gSparks + i; if(theSpark->ttl <= dT) { ! firstFreeIndex--; ! *theSpark = gSparks[firstFreeIndex]; } ! else ! { theSpark->ttl -= dT; theSpark->pos += theSpark->vel * dT; *************** *** 161,166 **** else theSpark->alpha = theSpark->ttl * 0.5; ! ! theSpark = theSpark->mNext; } } --- 87,92 ---- else theSpark->alpha = theSpark->ttl * 0.5; ! i++; ! } } } *************** *** 175,203 **** glEnableClientState(GL_VERTEX_ARRAY); ! // Prepare buffers... ! static struct SparkRender ! { ! Point pos; ! Color color; ! F32 alpha; ! } renderData[MaxSparks]; ! ! Spark *theSpark = mActive; ! SparkRender *r = renderData; ! while(theSpark) ! { ! r->pos = theSpark->pos; ! r->color = theSpark->color; ! r->alpha = theSpark->alpha; ! ! // Advance pointers ! r++; ! theSpark = theSpark->mNext; ! } ! ! glVertexPointer(2, GL_FLOAT, sizeof(SparkRender), &renderData[0].pos); ! glColorPointer(4, GL_FLOAT , sizeof(SparkRender), &renderData[0].color); ! glDrawArrays(GL_POINTS, 0, (r - renderData)); glDisableClientState(GL_COLOR_ARRAY); --- 101,108 ---- glEnableClientState(GL_VERTEX_ARRAY); ! glVertexPointer(2, GL_FLOAT, sizeof(Spark), &gSparks[0].pos); ! glColorPointer(4, GL_FLOAT , sizeof(Spark), &gSparks[0].color); ! glDrawArrays(GL_POINTS, 0, firstFreeIndex); glDisableClientState(GL_COLOR_ARRAY); *************** *** 212,215 **** --- 117,121 ---- for(U32 i = 0; i < (500.0 * size); i++) { + F32 th = Random::readF() * 2 * 3.14; F32 f = (Random::readF() * 2 - 1) * 400 * size; *************** *** 224,227 **** --- 130,134 ---- for(U32 i = 0; i < (500.0 * size); i++) { + F32 th = Random::readF() * 2 * 3.14; F32 f = (Random::readF() * 2 - 1) * 400 * size; *************** *** 239,242 **** --- 146,150 ---- for(U32 i = 0; i < (250.0 * size); i++) { + F32 th = Random::readF() * 2 * 3.14; F32 f = (Random::readF() * 0.1 + 0.9) * 200 * size; *************** *** 264,268 **** mDropFreq = dropFrequency; mLength = len; - mNodes.clear(); registerTrail(); } --- 172,175 ---- |