2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

CWE Directory Reorganization

Rearrange directory structure of CWE to be loosely equivalent to
the H'uru Plasma repository.

Part 1: Movement of directories and files.
This commit is contained in:
rarified
2021-05-15 12:49:46 -06:00
parent c3f4a640a3
commit 96903e8dca
4002 changed files with 159 additions and 644 deletions

View File

@ -0,0 +1,56 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef pfAudioCreatable_inc
#define pfAudioCreatable_inc
#include "../pnFactory/plCreator.h"
#include "plListener.h"
REGISTER_CREATABLE( plListener );
#include "plRandomSoundMod.h"
REGISTER_CREATABLE( plRandomSoundMod );
#endif // pfCharacterCreatable_inc

View File

@ -0,0 +1,328 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsMatrix44.h"
#include "hsTypes.h"
#include "plListener.h"
#include "plgDispatch.h"
#include "../plAudio/plAudioSystem.h"
#include "../pnMessage/plTimeMsg.h"
#include "../pnMessage/plAudioSysMsg.h"
#include "../pnKeyedObject/plKey.h"
#include "../pnSceneObject/plSceneObject.h"
#include "../pnSceneObject/plCoordinateInterface.h"
#include "../pnSceneObject/plSimulationInterface.h"
#include "../pfCamera/plVirtualCamNeu.h"
#include "../plMessage/plListenerMsg.h"
#include "../plNetClient/plNetClientMgr.h"
#include "../plPipeline/plDebugText.h"
#include "../plAvatar/plAvatarMgr.h"
#include "../plAvatar/plArmatureMod.h"
#include "../plAvatar/plPhysicalControllerCore.h"
hsBool plListener::fPrintDbgInfo = false;
hsBool plListener::IEval(double secs, hsScalar del, UInt32 dirty)
{
// if (!plgAudioSys::Active())
// return true;
plSceneObject *pRefObject = nil;
int y = 16 + 12, x = 400;
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, 16, "Listener:", (UInt32)0xffffffff, plDebugText::kStyleBold );
// Get the avatar's SceneObject
plKey key = plNetClientMgr::GetInstance()->GetLocalPlayerKey();
if(key)
pRefObject = plSceneObject::ConvertNoRef(key->ObjectIsLoaded());
if( pRefObject == nil && fVCam == nil )
{
// We don't have a position to init by, so do NOT eval yet!!!
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, y, "Not eval-ing yet", (UInt32)0xffffffff );
return true;
}
// Changed 2.19.02 mcn - Basing it off the head bone isn't what we really want, esp. since
// it isn't what the camera uses. What we *really* want is a head-ish-positioned non-bobbing node
// that we base both off of. Until then, we're just going to have to use the avatar's root (i.e. his
// feet) and add in an appropriate height. See plAvBrain.cpp::BindAudioListener() for the other half
// of the hack.
// Note the 2nd: since GetAxis() is buggy, we'll just add in a constant vector. Of course, this implies
// that the avatar is always oriented up, but then it also implies he's always of constant height, so
// there.
const hsVector3 kAvatarHeightVector = hsVector3( 0, 0, 6.33f ); // isn't *everyone* 6'4"?
/// Collect the current values for our parameters
hsPoint3 position;
hsVector3 velocity, dir, up;
enum
{
kInvalid = 0,
kVCam,
kObject
} facingType = kInvalid, posType = kInvalid, velType = kInvalid;
// Facing
if( fFacingRatio == 1.f )
{
if( pRefObject != nil && pRefObject->GetCoordinateInterface() )
{
hsMatrix44 facingL2W = pRefObject->GetCoordinateInterface()->GetLocalToWorld();
dir = facingL2W.GetAxis( hsMatrix44::kView );
up = facingL2W.GetAxis( hsMatrix44::kUp );
facingType = kObject;
}
}
else if( fVCam != nil )
{
dir = hsVector3( fVCam->GetCameraPOA() - fVCam->GetCameraPos() );
up = fVCam->GetCameraUp();
facingType = kVCam;
}
// Position
if( fPosRatio == 1.f )
{
if( pRefObject != nil && pRefObject->GetCoordinateInterface() )
{
position = pRefObject->GetCoordinateInterface()->GetLocalToWorld().GetTranslate();
position += kAvatarHeightVector;
posType = kObject;
}
}
else if( fVCam != nil )
{
position = fVCam->GetCameraPos();
posType = kVCam;
}
// Velocity
if( fVelRatio == 1.f )
{
if( pRefObject != nil )
{
plArmatureMod* arm = plAvatarMgr::GetInstance()->GetLocalAvatar();
if (arm)
{
plPhysicalControllerCore* controller = arm->GetController();
if (controller)
{
velocity = controller->GetLinearVelocity();
velType = kObject;
}
}
}
}
else if( fVCam != nil )
{
// Darn, can't do it
}
if( facingType == kInvalid || posType == kInvalid || velType == kInvalid )
{
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, y, "Not eval-ing: missing one or more parameter bases", (UInt32)0xff0000ff );
return true;
}
// Got the params, now construct and send out the message, as well as update the audio system
plListenerMsg* msg = TRACKED_NEW plListenerMsg;
msg->SetDirection( dir );
msg->SetUp( up );
msg->SetPosition( position );
msg->SetVelocity( velocity );
plgAudioSys::SetListenerOrientation( dir, up );
plgAudioSys::SetListenerPos( position );
plgAudioSys::SetListenerVelocity( velocity );
if( fPrintDbgInfo )
{
char str[ 256 ];
sprintf( str, "Direction: (%3.2f,%3.2f,%3.2f) from %s", dir.fX, dir.fY, dir.fZ, ( facingType == kObject ) ? pRefObject->GetKey()->GetUoid().GetObjectName() : "VCam" );
plDebugText::Instance().DrawString( x, y, str, (UInt32)0xffffffff );
y += 12;
sprintf( str, "Up: (%3.2f,%3.2f,%3.2f) from %s", up.fX, up.fY, up.fZ, ( facingType == kObject ) ? pRefObject->GetKey()->GetUoid().GetObjectName() : "VCam" );
plDebugText::Instance().DrawString( x, y, str, (UInt32)0xffffffff );
y += 12;
sprintf( str, "Position: (%3.2f,%3.2f,%3.2f) from %s", position.fX, position.fY, position.fZ, ( posType == kObject ) ? pRefObject->GetKey()->GetUoid().GetObjectName() : "VCam" );
plDebugText::Instance().DrawString( x, y, str, (UInt32)0xffffffff );
y += 12;
sprintf( str, "Velocity: (%3.2f,%3.2f,%3.2f) from %s", velocity.fX, velocity.fY, velocity.fZ, ( velType == kObject ) ? pRefObject->GetKey()->GetUoid().GetObjectName() : "VCam" );
plDebugText::Instance().DrawString( x, y, str, (UInt32)0xffffffff );
y += 12;
}
plgDispatch::MsgSend( msg );
return true;
}
void plListener::ISetRef( const plKey &ref, hsBool binding, int type )
{
if( binding )
hsgResMgr::ResMgr()->AddViaNotify( ref, TRACKED_NEW plGenRefMsg( GetKey(), plGenRefMsg::kOnReplace, -1, type ), plRefFlags::kPassiveRef );
else
GetKey()->Release( ref );
}
void plListener::IEnsureVCamValid( void )
{
if( fPosRatio == 1.f && fFacingRatio == 1.f && fVelRatio == 1.f )
{
// All of our params are purely using objects, so we don't need a virtual camera pointer at all
if( fVCam != nil )
ISetRef( fVCam->GetKey(), false, kRefVCam );
}
else
{
// One or more of our params are using the vcam as a basis, so make sure we have it
if( fVCam == nil )
{
plVirtualCam1 *vCam = plVirtualCam1::Instance();
if( vCam == nil )
{
hsAssert( false, "Unable to grab virtual camera instance; no basis for listener!!!" );
return;
}
ISetRef( vCam->GetKey(), true, kRefVCam );
}
}
}
void plListener::ICheckAudio( void ) const
{
if( ( fPosRatio < 1.f || fFacingRatio < 1.f || fVelRatio < 1.f ) && fVCam == nil )
plgAudioSys::SetMuted( true );
}
hsBool plListener::MsgReceive(plMessage* msg)
{
plSetListenerMsg *setMsg = plSetListenerMsg::ConvertNoRef( msg );
if( setMsg != nil )
{
hsBool useVCam;
if( setMsg->GetType() & plSetListenerMsg::kVCam )
{
// Reset any ratios
if( setMsg->GetType() & plSetListenerMsg::kPosition )
fPosRatio = 0.f;
if( setMsg->GetType() & plSetListenerMsg::kVelocity )
fVelRatio = 0.f;
if( setMsg->GetType() & plSetListenerMsg::kFacing )
fFacingRatio = 0.f;
IEnsureVCamValid();
}
else
{
useVCam = setMsg->IsBinding();
if( setMsg->GetType() & plSetListenerMsg::kPosition )
fPosRatio = 1.f;
if( setMsg->GetType() & plSetListenerMsg::kVelocity )
fVelRatio = 1.f;
if( setMsg->GetType() & plSetListenerMsg::kFacing )
fFacingRatio = 1.f;
if( fPosRatio > 0.f || fVelRatio > 0.f || fFacingRatio > 0.f )
// Need this, so store it now
ISetRef( setMsg->GetSrcKey(), setMsg->IsBinding(), kRefObject );
}
return true;
}
plEvalMsg* pEMsg = plEvalMsg::ConvertNoRef(msg);
if (pEMsg)
{
IEval(pEMsg->GetTimeStamp(), pEMsg->DelSeconds(), true);
if( fInitMe )
{
// By default, position and orientation are camera based
plSetListenerMsg *set = TRACKED_NEW plSetListenerMsg( plSetListenerMsg::kVCam | plSetListenerMsg::kFacing, nil, true );
set->Send();
set = TRACKED_NEW plSetListenerMsg( plSetListenerMsg::kVCam | plSetListenerMsg::kPosition, nil, true );
set->Send();
fInitMe = false;
}
return true;
}
plGenRefMsg* refMsg = plGenRefMsg::ConvertNoRef( msg );
if( refMsg != nil )
{
if( refMsg->fType == kRefVCam )
{
if( refMsg->GetContext() & ( plRefMsg::kOnCreate | plRefMsg::kOnRequest | plRefMsg::kOnReplace ) )
{
fVCam = plVirtualCam1::ConvertNoRef( refMsg->GetRef() );
}
else if( refMsg->GetContext() & ( plRefMsg::kOnRemove | plRefMsg::kOnDestroy ) )
{
if( plVirtualCam1::ConvertNoRef( refMsg->GetRef() ) == fVCam )
fVCam = nil;
}
ICheckAudio();
}
return true;
}
return plSingleModifier::MsgReceive(msg);
}

View File

@ -0,0 +1,98 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plListener_h
#define plListener_h
#include "../pnModifier/plSingleModifier.h"
class plSceneObject;
class plVirtualCam1;
class plListener : public plSingleModifier
{
public:
plListener() : fVCam(nil), fInitMe(true){;}
~plListener(){;}
CLASSNAME_REGISTER( plListener );
GETINTERFACE_ANY( plListener, plSingleModifier );
virtual hsBool MsgReceive(plMessage* msg);
static void ShowDebugInfo( hsBool s ) { fPrintDbgInfo = s; }
// Get info for which object these things are attached to - camera or refObject
UInt8 GetAttachedPosType() { return (UInt8)fPosRatio; }
UInt8 GetAttachedFacingType() { return (UInt8)fFacingRatio; }
UInt8 GetAttachedVelType() { return (UInt8)fVelRatio; }
enum
{
kCamera = 0,
kAvatar = 1
};
protected:
enum Refs
{
kRefObject,
kRefVCam
};
plVirtualCam1* fVCam;
hsScalar fPosRatio, fFacingRatio, fVelRatio; // 0 is vCam, 1 is refObject
hsBool fInitMe;
static hsBool fPrintDbgInfo;
virtual hsBool IEval(double secs, hsScalar del, UInt32 dirty);
void ISetRef( const plKey &ref, hsBool binding, int type );
void ICheckAudio( void ) const;
void IEnsureVCamValid( void );
};
#endif //plWin32Sound_h

View File

@ -0,0 +1,431 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "plRandomSoundMod.h"
#include "../pnSceneObject/plSceneObject.h"
#include "../pnSceneObject/plAudioInterface.h"
#include "../pnMessage/plSoundMsg.h"
#include "../plMessage/plAnimCmdMsg.h"
#include "../plAudio/plAudioSystem.h"
#include "../plAudio/plSound.h"
#include "../plAudio/plWin32GroupedSound.h" // EEK BAD
#include "plgDispatch.h"
#include "hsTimer.h"
#include "../plStatusLog/plStatusLog.h"
plRandomSoundModGroup::plRandomSoundModGroup() : fNumSounds(0), fIndices(nil), fGroupedIdx(-1), fCurrent(-1)
{
}
plRandomSoundModGroup::~plRandomSoundModGroup()
{
delete [] fIndices;
}
void plRandomSoundModGroup::Read(hsStream *s)
{
fNumSounds = s->ReadSwap16();
fGroupedIdx = s->ReadSwap16();
fIndices = TRACKED_NEW UInt16[fNumSounds];
int i;
for (i = 0; i < fNumSounds; i++)
fIndices[i] = s->ReadSwap16();
}
void plRandomSoundModGroup::Write(hsStream *s)
{
s->WriteSwap16(fNumSounds);
s->WriteSwap16(fGroupedIdx);
int i;
for (i = 0; i < fNumSounds; i++)
s->WriteSwap16(fIndices[i]);
}
///////////////////////////////////////////////////////////////////////////////////////
plRandomSoundMod::plRandomSoundMod() : fCurrentGroup(0), fNumGroups(0), fGroups(nil), fOldPriority(-1), fFirstTimePlay(true)
{
}
plRandomSoundMod::~plRandomSoundMod()
{
delete [] fGroups;
}
void plRandomSoundMod::IPlayNextIfMaster()
{
if( !fTarget )
IRetry(2.f);
if( IStopped() )
return;
IPlayNext();
}
// If we recieve a stop message, actually stop the sound
void plRandomSoundMod::IStop()
{
plRandomCommandMod::IStop();
plAudioInterface *ai = nil;
if( !plgAudioSys::Active() ) return;
ai = IGetTargetAudioInterface(0);
if(!ai) return;
if( fGroups != nil && fGroups[ fCurrentGroup ].fGroupedIdx != -1 )
{
plSoundMsg *msg = TRACKED_NEW plSoundMsg();
msg->SetCmd(plSoundMsg::kStop);
msg->fIndex = fGroups[ fCurrentGroup ].fIndices[ fCurrent ];
plgDispatch::MsgSend(msg);
}
else
{
if(fCurrent == -1) return;
UInt16 currentSndIdx = ( fGroups != nil ) ? fGroups[fCurrentGroup].fIndices[fCurrent] : fActiveList[fCurrent];
plSoundMsg* snd = TRACKED_NEW plSoundMsg(GetKey(), GetTarget()->GetKey(), nil);
snd->SetCmd(plSoundMsg::kStop);
snd->fIndex = currentSndIdx;
plgDispatch::MsgSend(snd);
}
}
void plRandomSoundMod::IPlayNext()
{
if( !plgAudioSys::Active() )
{
IRetry(10.f);
return;
}
plAudioInterface* ai = IGetTargetAudioInterface(0);
if( !ai )
{
IRetry(2.f);
return;
}
int i;
UInt16 currentSndIdx;
int nSounds = (fGroups == nil ? ai->GetNumSounds() : fGroups[fCurrentGroup].fNumSounds);
fEndTimes.ExpandAndZero(nSounds);
plSound *pSound = nil;
// The global sound priority has changed, update the active random sounds list
if(fOldPriority != plgAudioSys::GetPriorityCutoff() && fGroups == nil)
{
fActiveList.clear();
fOldPriority = plgAudioSys::GetPriorityCutoff();
for(i = 0; i < nSounds; i++)
{
pSound = ai->GetSound(i);
if(pSound && pSound->GetPriority() <= plgAudioSys::GetPriorityCutoff())
{
fActiveList.push_back(i);
}
}
// There are no sounds that should play
if(fGroups == nil && fActiveList.empty() && nSounds)
{
// If no sounds in this component even attempt to play this component gets mad and will never play any sounds again.
// So, give it a zero to make it happy. This sound will still be rejected when it tries to play which is exactly what
// we want since if we get here no sounds in this component should play.
fActiveList.push_back(0);
}
}
// if this is the first time this component is going to play a sound check to see if it has a delay time
if(fFirstTimePlay)
{
fFirstTimePlay = false;
if( !(fMode & kOneCmd) )
{
hsScalar delay = IGetDelay(0);
double t = hsTimer::GetSysSeconds() + delay;
plAnimCmdMsg* anim = TRACKED_NEW plAnimCmdMsg(GetKey(), GetKey(), &t);
anim->SetCmd(plAnimCmdMsg::kContinue);
plgDispatch::MsgSend(anim);
return;
}
}
if( !ISelectNext(fGroups == nil ? fActiveList.size() : nSounds) )
{
plRandomCommandMod::IStop();
return;
}
// We don't want random sounds to synch, since we don't synch the randomness. So force this next
// sound to not synch
hsScalar currLen;
if( fGroups != nil && fGroups[ fCurrentGroup ].fGroupedIdx != -1 )
{
currentSndIdx = fGroups[ fCurrentGroup ].fIndices[ fCurrent ];
plWin32GroupedSound *sound = plWin32GroupedSound::ConvertNoRef( ai->GetSound( fGroups[ fCurrentGroup ].fGroupedIdx ) );
if (!sound)
{
hsAssert( sound != nil, "Invalid sound type in plRandomSoundMod" );
return;
}
sound->SetLocalOnly(true);
// Send msg to the grouped sound to switch sounds
plSoundMsg *snd = TRACKED_NEW plSoundMsg();
snd->SetCmd( plSoundMsg::kSelectFromGroup );
snd->fIndex = currentSndIdx;
snd->Send( sound->GetKey() );
// Now tell the audio interface to play the sound (probably should change this....)
snd = TRACKED_NEW plSoundMsg(GetKey(), GetTarget()->GetKey(), nil);
snd->SetCmd(plSoundMsg::kGoToTime);
snd->fTime = (0);
snd->SetCmd(plSoundMsg::kStop);
snd->SetCmd(plSoundMsg::kPlay);
snd->fIndex = fGroups[ fCurrentGroup ].fGroupedIdx;
plgDispatch::MsgSend(snd);
currLen = sound->GetSoundLength( currentSndIdx );
}
else
{
currentSndIdx = ( fGroups != nil ) ? fGroups[fCurrentGroup].fIndices[fCurrent] : fActiveList[fCurrent];
if (ai->GetSound(currentSndIdx))
{
ai->GetSound( currentSndIdx )->SetLocalOnly(true);
ai->GetSound(currentSndIdx)->Stop();
ai->GetSound(currentSndIdx)->Play();
}
if (ai->GetSound(currentSndIdx))
currLen = (hsScalar)(ai->GetSound(currentSndIdx)->GetLength());
else
currLen = 0;
}
if (plgAudioSys::AreExtendedLogsEnabled())
{
if (fGroups)
plStatusLog::AddLineS("audio.log", "%s: Playing sound #%d from group %d", GetTarget(0)->GetKeyName(), fCurrent, fCurrentGroup);
else
plStatusLog::AddLineS("audio.log", "%s: Playing sound #%d", GetTarget(0)->GetKeyName(), fCurrent);
}
fEndTimes[fCurrent] = hsTimer::GetSysSeconds() + currLen;
if( !(fMode & kOneCmd) )
{
hsScalar delay = IGetDelay(currLen);
double t = hsTimer::GetSysSeconds() + delay;
plAnimCmdMsg* anim = TRACKED_NEW plAnimCmdMsg(GetKey(), GetKey(), &t);
anim->SetCmd(plAnimCmdMsg::kContinue);
plgDispatch::MsgSend(anim);
}
else
{
plRandomCommandMod::IStop();
}
}
void plRandomSoundMod::SetCurrentGroup(UInt16 group)
{
hsAssert(group < fNumGroups, "Setting an invalid group on a random sound modifier");
if (group != fCurrentGroup && group < fNumGroups)
{
fGroups[fCurrentGroup].fExcluded = fExcluded;
fGroups[fCurrentGroup].fCurrent = fCurrent;
fExcluded = fGroups[group].fExcluded;
fCurrent = fGroups[group].fCurrent;
fCurrentGroup = group;
}
}
void plRandomSoundMod::Read(hsStream *s, hsResMgr *mgr)
{
plRandomCommandMod::Read(s, mgr);
fNumGroups = s->ReadSwap16();
if (fNumGroups > 0)
{
fGroups = TRACKED_NEW plRandomSoundModGroup[fNumGroups];
int i;
for (i = 0; i < fNumGroups; i++)
fGroups[i].Read(s);
}
}
void plRandomSoundMod::Write(hsStream *s, hsResMgr *mgr)
{
plRandomCommandMod::Write(s, mgr);
s->WriteSwap16(fNumGroups);
if (fNumGroups > 0)
{
int i;
for (i = 0; i < fNumGroups; i++)
fGroups[i].Write(s);
}
}
void plRandomSoundMod::ForceSoundLoadState( hsBool loaded )
{
UInt16 i, j;
plAudioInterface* ai = IGetTargetAudioInterface(0);
if( ai == nil )
return;
if( fGroups != nil )
{
for( i = 0; i < fNumGroups; i++ )
{
if( fGroups[ i ].fGroupedIdx != -1 )
{
plSound *sound = ai->GetSound( fGroups[ i ].fGroupedIdx );
if (!sound)
return;
if( loaded )
sound->ForceLoad();
else
sound->ForceUnload();
}
else
{
for( j = 0; j < fGroups[ i ].fNumSounds; j++ )
{
plSound *sound = ai->GetSound( fGroups[ i ].fIndices[ j ] );
if (!sound)
return;
if( loaded )
sound->ForceLoad();
else
sound->ForceUnload();
}
}
}
}
else
{
for( i = 0; i < ai->GetNumSounds(); i++ )
{
plSound *sound = ai->GetSound( i );
if (!sound)
return;
if( loaded )
sound->ForceLoad();
else
sound->ForceUnload();
}
}
}
// Overload this to handle volume changes
hsBool plRandomSoundMod::MsgReceive(plMessage* msg)
{
plAnimCmdMsg* anim = plAnimCmdMsg::ConvertNoRef(msg);
if( anim )
{
// Actually sets the volume
if( anim->Cmd(plAnimCmdMsg::kSetSpeed) )
{
ISetVolume(anim->fSpeed);
}
}
// Don't understand, pass on to base class.
return plRandomCommandMod::MsgReceive(msg);
}
void plRandomSoundMod::ISetVolume(hsScalar volume)
{
plSound *pSound = nil;
pSound = IGetSoundPtr();
if(pSound)
pSound->SetVolume(volume);
}
float plRandomSoundMod::GetVolume()
{
float volume = 1.0;
plSound *pSound;
pSound = IGetSoundPtr();
if(pSound)
volume = pSound->GetMaxVolume();
return volume;
}
void plRandomSoundMod::ISetPosition(hsPoint3 pos)
{
plSound *pSound = IGetSoundPtr();
if(pSound)
{
pSound->SetPosition(pos);
}
}
plSound *plRandomSoundMod::IGetSoundPtr()
{
plSound *pSound = nil;
if(fGroups != nil) return nil;
if(fCurrent == -1) return nil; // sound list hasn't been initialized yet, don't try and access it
int currentSndIdx = fActiveList[fCurrent];
plAudioInterface* ai = IGetTargetAudioInterface(0);
if( !ai )
return nil;
pSound = ai->GetSound( currentSndIdx );
return pSound;
}

View File

@ -0,0 +1,105 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plRandomSoundMod_inc
#define plRandomSoundMod_inc
#include "../pfAnimation/plRandomCommandMod.h"
class plSound;
struct hsPoint3;
class plRandomSoundModGroup
{
public:
hsBitVector fExcluded;
Int8 fCurrent;
UInt16 fNumSounds;
UInt16 *fIndices;
Int16 fGroupedIdx; // Only used if we point to a groupedSound, in which case fIndices are indices into
// that sound. -1 if unused.
plRandomSoundModGroup();
~plRandomSoundModGroup();
void Read(hsStream *s);
void Write(hsStream *s);
};
class plRandomSoundMod : public plRandomCommandMod
{
protected:
UInt16 fCurrentGroup;
UInt16 fNumGroups;
plRandomSoundModGroup *fGroups;
std::vector<UInt16> fActiveList; // list of sounds we're allowed to choose
int fOldPriority; // old sound priority
hsBool fFirstTimePlay;
virtual void IPlayNext();
virtual void IPlayNextIfMaster();
virtual void IStop();
void ISetVolume(hsScalar volume);
void ISetPosition(hsPoint3);
plSound *IGetSoundPtr();
public:
plRandomSoundMod();
~plRandomSoundMod();
CLASSNAME_REGISTER( plRandomSoundMod );
GETINTERFACE_ANY( plRandomSoundMod, plRandomCommandMod );
virtual void Read(hsStream* s, hsResMgr* mgr);
virtual void Write(hsStream* s, hsResMgr* mgr);
void SetCurrentGroup(UInt16 group);
void ForceSoundLoadState( hsBool loaded );
hsBool MsgReceive(plMessage* msg);
float GetVolume();
// EXPORT ONLY
void SetGroupInfo(UInt16 numGroups, plRandomSoundModGroup *groups) { fNumGroups = numGroups; fGroups = groups; }
};
#endif // plRandomSoundMod_inc