[Opentnl-cvs] tnl/zap game.cpp,1.18,1.19 gameItems.cpp,1.2,1.3 main.cpp,1.20,1.21 projectile.cpp,1.8
Brought to you by:
mark_frohnmayer,
s_alanet
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1314/zap Modified Files: game.cpp gameItems.cpp main.cpp projectile.cpp sfx.cpp sfx.h ship.cpp ship.h sparkManager.cpp sparkManager.h Log Message: - Added sounds for turbo, health, shield impacts, and commander map activate/deactivate. - Added particles back for engine trails. - Rewrote particle allocation manager to prevent particle starvation. (It seemed that the old allocator assumed that particles were sorted by TTL, but they weren't, so it tended to hold on to dead particles and even deallocate active ones). - Changed energy consumed by shooting. Now you gain energy slowly even if you're firing. - Added better error reporting to sound code on missing sounds. - Doc fixes in GhostConnection. Index: ship.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ship.h 3 May 2004 22:06:16 -0000 1.13 --- ship.h 5 May 2004 09:50:35 -0000 1.14 *************** *** 30,33 **** --- 30,34 ---- #include "moveObject.h" #include "sparkManager.h" + #include "sfx.h" namespace Zap *************** *** 75,78 **** --- 76,80 ---- StringTableEntry mPlayerName; bool mShield, mTurbo, mCooldown; + SFXHandle mTurboNoise; S32 mLastTrailPoint[TrailCount]; Index: sparkManager.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** sparkManager.cpp 30 Apr 2004 21:58:10 -0000 1.5 --- sparkManager.cpp 5 May 2004 09:50:35 -0000 1.6 *************** *** 42,45 **** --- 42,46 ---- F32 ttl; Point vel; + Spark *mNext, *mPrev; }; *************** *** 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; --- 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; *************** *** 71,92 **** 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; ! if(theSpark->ttl > 2) ! theSpark->alpha = 1; ! else ! theSpark->alpha = theSpark->ttl * 0.5; ! i++; ! } } } --- 144,166 ---- 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; + if(theSpark->ttl > 2) + theSpark->alpha = 1; else ! theSpark->alpha = theSpark->ttl * 0.5; ! ! theSpark = theSpark->mNext; } } *************** *** 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); --- 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); *************** *** 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; --- 212,215 ---- *************** *** 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; --- 224,227 ---- *************** *** 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; --- 239,242 ---- *************** *** 172,175 **** --- 264,268 ---- mDropFreq = dropFrequency; mLength = len; + mNodes.clear(); registerTrail(); } Index: projectile.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/projectile.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** projectile.cpp 26 Apr 2004 07:36:06 -0000 1.8 --- projectile.cpp 5 May 2004 09:50:35 -0000 1.9 *************** *** 114,118 **** { SparkManager::emitExplosion(collisionPoint, 0.4, SparkColors, NumSparkColors); ! SFXObject::play(SFXPhaserImpact, pos, velocity); } } --- 114,123 ---- { SparkManager::emitExplosion(collisionPoint, 0.4, SparkColors, NumSparkColors); ! ! Ship *s = dynamic_cast<Ship*>(hitObject); ! if(s && s->mShield) ! SFXObject::play(SFXBounceShield, pos, velocity); ! else ! SFXObject::play(SFXPhaserImpact, pos, velocity); } } Index: sfx.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** sfx.cpp 22 Apr 2004 07:46:20 -0000 1.9 --- sfx.cpp 5 May 2004 09:50:35 -0000 1.10 *************** *** 42,45 **** --- 42,47 ---- { "phaser_impact.wav", false, 0.7f, false, 150, 600 }, { "ship_explode.wav", false, 1.0, false, 300, 1000 }, + { "ship_heal.wav", false, 1.0, false, 300, 1000 }, + { "ship_turbo.wav", false, 1.0, true, 300, 1000 }, { "flag_capture.wav", true, 0.45f, false, 0, 0 }, { "flag_drop.wav", true, 0.45f, false, 0, 0 }, *************** *** 50,54 **** --- 52,59 ---- { "bounce_wall.wav", false, 0.7f, false, 150, 600 }, { "bounce_obj.wav", false, 0.7f, false, 150, 600 }, + { "bounce_shield.wav", false, 0.7f, false, 150, 600 }, { "boop.wav", true, 0.4f, false, 150, 600 }, + { "comm_up.wav", true, 0.4f, false, 150, 600 }, + { "comm_down.wav", true, 0.4f, false, 150, 600 }, { NULL, false, 0, false, 0, 0 }, }; *************** *** 255,263 **** --- 260,274 ---- #endif if(alGetError() != AL_NO_ERROR) + { + logprintf("Failure (1) loading sound file '%s'", gSFXProfiles[i].fileName); return; + } alBufferData(gBuffers[i], format, data, size, freq); alutUnloadWAV(format, data, size, freq); if(alGetError() != AL_NO_ERROR) + { + logprintf("Failure (2) loading sound file '%s'", gSFXProfiles[i].fileName); return; + } } gSFXValid = true; Index: sparkManager.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sparkManager.h 30 Apr 2004 21:58:10 -0000 1.4 --- sparkManager.h 5 May 2004 09:50:35 -0000 1.5 *************** *** 42,45 **** --- 42,46 ---- void tick( F32 dT); void render(); + void init(); }; Index: gameItems.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/gameItems.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gameItems.cpp 25 Apr 2004 06:01:30 -0000 1.2 --- gameItems.cpp 5 May 2004 09:50:35 -0000 1.3 *************** *** 56,60 **** theShip->damageObject(&di); ! return true; } --- 56,60 ---- theShip->damageObject(&di); ! SFXObject::play(SFXShipHeal, getRenderPos(), getRenderVel()); return true; } Index: game.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/game.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** game.cpp 3 May 2004 23:31:45 -0000 1.18 --- game.cpp 5 May 2004 09:50:35 -0000 1.19 *************** *** 393,397 **** { mInCommanderMap = !mInCommanderMap; ! UserInterface::playBoop(); GameConnection *conn = getConnectionToServer(); --- 393,401 ---- { mInCommanderMap = !mInCommanderMap; ! if(mInCommanderMap) ! SFXObject::play(SFXUICommUp); ! else ! SFXObject::play(SFXUICommDown); ! GameConnection *conn = getConnectionToServer(); Index: main.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/main.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** main.cpp 4 May 2004 19:46:34 -0000 1.20 --- main.cpp 5 May 2004 09:50:35 -0000 1.21 *************** *** 36,40 **** #include "UI.h" #include "UIGame.h" ! #include "UINameEntry.h" #include "UIMenus.h" #include "game.h" --- 36,40 ---- #include "UI.h" #include "UIGame.h" ! #include "UINameEntry.h" #include "UIMenus.h" #include "game.h" *************** *** 42,45 **** --- 42,46 ---- #include "masterConnection.h" #include "sfx.h" + #include "sparkManager.h" namespace Zap *************** *** 367,370 **** --- 368,372 ---- if(hasClient) { + SparkManager::init(); SFXObject::init(); glutInitWindowSize(800, 600); Index: sfx.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sfx.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** sfx.h 22 Apr 2004 07:46:20 -0000 1.5 --- sfx.h 5 May 2004 09:50:35 -0000 1.6 *************** *** 41,44 **** --- 41,46 ---- SFXPhaserImpact, SFXShipExplode, + SFXShipHeal, + SFXShipTurbo, SFXFlagCapture, SFXFlagDrop, *************** *** 49,53 **** --- 51,58 ---- SFXBounceWall, SFXBounceObject, + SFXBounceShield, SFXUIBoop, + SFXUICommUp, + SFXUICommDown, NumSFXBuffers }; Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ship.cpp 3 May 2004 22:06:16 -0000 1.23 --- ship.cpp 5 May 2004 09:50:35 -0000 1.24 *************** *** 74,77 **** --- 74,78 ---- mTurbo = false; mCooldown = false; + mTurboNoise = NULL; } *************** *** 153,157 **** if(currentTime - lastFireTime > FireDelay) { ! mEnergy -= 1.f; lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); --- 154,158 ---- if(currentTime - lastFireTime > FireDelay) { ! mEnergy -= 0.5f; lastFireTime = currentTime; Point dir(sin(mMoveState[ActualState].angle), cos(mMoveState[ActualState].angle) ); *************** *** 255,258 **** --- 256,262 ---- SFXObject::setListenerParams(mMoveState[RenderState].pos, mMoveState[RenderState].vel); + + if(mTurboNoise) + mTurboNoise->setMovementParams(mMoveState[RenderState].pos, mMoveState[RenderState].vel); } *************** *** 267,270 **** --- 271,277 ---- for(U32 i=0; i<TrailCount; i++) mTrail[i].tick(deltaT); + + if(mTurboNoise) + mTurboNoise->setMovementParams(mMoveState[RenderState].pos, mMoveState[RenderState].vel); } *************** *** 378,381 **** --- 385,399 ---- else interpTime = 1; + + // Update the turbo noise + if(mTurbo && mTurboNoise.isNull()) + mTurboNoise = SFXObject::play(SFXShipTurbo, mMoveState[RenderState].pos, mMoveState[RenderState].vel); + + if(!mTurbo && mTurboNoise.isValid()) + { + mTurboNoise->setGain(0); + mTurboNoise->stop(); + mTurboNoise = NULL; + } } *************** *** 522,525 **** --- 540,554 ---- emitShipExplosion(mMoveState[ActualState].pos); } + + // Update the turbo noise + if(mTurbo && mTurboNoise.isNull()) + mTurboNoise = SFXObject::play(SFXShipTurbo, mMoveState[RenderState].pos, mMoveState[RenderState].vel); + + if(!mTurbo && mTurboNoise.isValid()) + { + mTurboNoise->setGain(0); + mTurboNoise->stop(); + mTurboNoise = NULL; + } } *************** *** 695,698 **** --- 724,773 ---- } + // Finally, do some particles + Point velDir(lastMove.right - lastMove.left, lastMove.down - lastMove.up); + F32 len = velDir.len(); + + if(len > 0) + { + if(len > 1) + velDir *= 1 / len; + + Point shipDirs[4]; + shipDirs[0].set(sin(mMoveState[RenderState].angle), cos(mMoveState[RenderState].angle) ); + shipDirs[1].set(-shipDirs[0]); + shipDirs[2].set(shipDirs[0].y, -shipDirs[0].x); + shipDirs[3].set(-shipDirs[0].y, shipDirs[0].x); + + for(U32 i = 0; i < 4; i++) + { + F32 th = shipDirs[i].dot(velDir); + + if(th > 0.1) + { + // shoot some sparks... + if(th >= 1*TNL::Random::readF() * velDir.len()) + { + Point chaos(TNL::Random::readF(),TNL::Random::readF()); + chaos *= 5; + + //interp give us some nice enginey colors... + Color dim(1, 0, 0); + Color light(1, 1, 0); + Color thrust; + + F32 t = TNL::Random::readF(); + thrust.interp(t, dim, light); + + SparkManager::emitSpark( + mMoveState[RenderState].pos - shipDirs[i] * 13, + -shipDirs[i] * 100 + chaos, + thrust, + 1.5 * Random::readF() + ); + } + } + } + } + } |