| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts 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/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : WWAudio *
- * *
- * $Archive:: /Commando/Code/WWAudio/LogicalSound.cpp $Modtime:: 7/02/99 10:18a $*
- * *
- * $Revision:: 6 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "LogicalSound.H"
- #include "WWAudio.H"
- #include "SoundScene.H"
- #include "SoundChunkIDs.h"
- #include "persistfactory.h"
- //////////////////////////////////////////////////////////////////////////////////
- // Static factories
- //////////////////////////////////////////////////////////////////////////////////
- SimplePersistFactoryClass<LogicalSoundClass, CHUNKID_LOGICALSOUND> _LogicalSoundPersistFactory;
- //////////////////////////////////////////////////////////////////////////////////
- // Save/Load constants
- //////////////////////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_VARIABLES = 0x03270459,
- CHUNKID_BASE_CLASS
- };
- enum
- {
- VARID_DROP_OFF_RADIUS = 0x01,
- VARID_IS_SINGLE_SHOT,
- VARID_TYPE_MASK,
- VARID_XXX1,
- VARID_POSITION,
- VARID_MAX_LISTENERS,
- VARID_NOTIFY_DELAY,
- VARID_LAST_NOTIFY,
- };
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // LogicalSoundClass
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- LogicalSoundClass::LogicalSoundClass (void)
- : m_DropOffRadius (1),
- m_TypeMask (0),
- m_Position (0, 0, 0),
- m_IsSingleShot (false),
- m_OldestListenerTimestamp (0),
- m_MaxListeners (0),
- m_NotifyDelayInMS (2000),
- m_LastNotification (0)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // ~LogicalSoundClass
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- LogicalSoundClass::~LogicalSoundClass (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Add_To_Scene
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- void
- LogicalSoundClass::Add_To_Scene (bool /*start_playing*/)
- {
- SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
- if ((scene != NULL) && (m_Scene == NULL)) {
-
- //
- // Add this sound to the culling system
- //
- m_Scene = scene;
- scene->Add_Logical_Sound (this, m_IsSingleShot);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Remove_From_Scene
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- void
- LogicalSoundClass::Remove_From_Scene (void)
- {
- if (m_Scene != NULL) {
- //
- // Remove this sound from the culling system
- //
- m_Scene->Remove_Logical_Sound (this, m_IsSingleShot);
- m_Scene = NULL;
- m_PhysWrapper = NULL;
- m_LastNotification = 0;
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Allow_Notify
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- bool
- LogicalSoundClass::Allow_Notify (uint32 timestamp)
- {
- bool retval = false;
- if (m_IsSingleShot || timestamp > (m_LastNotification + m_NotifyDelayInMS)) {
- retval = true;
- m_LastNotification = timestamp;
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // On_Frame_Update
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- bool
- LogicalSoundClass::On_Frame_Update (unsigned int milliseconds)
- {
- //
- // Update the sound's position if its linked to a render object
- //
- Apply_Auto_Position ();
- return SoundSceneObjClass::On_Frame_Update (milliseconds);;
- }
- /////////////////////////////////////////////////////////////////////////////////
- //
- // Get_Factory
- //
- /////////////////////////////////////////////////////////////////////////////////
- const PersistFactoryClass &
- LogicalSoundClass::Get_Factory (void) const
- {
- return _LogicalSoundPersistFactory;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //
- // Save
- //
- //////////////////////////////////////////////////////////////////////////////////
- bool
- LogicalSoundClass::Save (ChunkSaveClass &csave)
- {
- csave.Begin_Chunk (CHUNKID_BASE_CLASS);
- SoundSceneObjClass::Save (csave);
- csave.End_Chunk ();
- csave.Begin_Chunk (CHUNKID_VARIABLES);
- WRITE_MICRO_CHUNK (csave, VARID_DROP_OFF_RADIUS, m_DropOffRadius);
- WRITE_MICRO_CHUNK (csave, VARID_IS_SINGLE_SHOT, m_IsSingleShot);
- WRITE_MICRO_CHUNK (csave, VARID_TYPE_MASK, m_TypeMask);
- WRITE_MICRO_CHUNK (csave, VARID_POSITION, m_Position);
- WRITE_MICRO_CHUNK (csave, VARID_MAX_LISTENERS, m_MaxListeners);
- WRITE_MICRO_CHUNK (csave, VARID_NOTIFY_DELAY, m_NotifyDelayInMS);
- WRITE_MICRO_CHUNK (csave, VARID_LAST_NOTIFY, m_LastNotification);
- csave.End_Chunk ();
- return true;
- }
- //////////////////////////////////////////////////////////////////////////////////
- //
- // Load
- //
- //////////////////////////////////////////////////////////////////////////////////
- bool
- LogicalSoundClass::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
- case CHUNKID_BASE_CLASS:
- PersistClass::Load (cload);
- break;
- case CHUNKID_VARIABLES:
- {
- //
- // Read all the variables from their micro-chunks
- //
- while (cload.Open_Micro_Chunk ()) {
- switch (cload.Cur_Micro_Chunk_ID ()) {
- READ_MICRO_CHUNK (cload, VARID_DROP_OFF_RADIUS, m_DropOffRadius);
- READ_MICRO_CHUNK (cload, VARID_IS_SINGLE_SHOT, m_IsSingleShot);
- READ_MICRO_CHUNK (cload, VARID_TYPE_MASK, m_TypeMask);
- READ_MICRO_CHUNK (cload, VARID_POSITION, m_Position);
- READ_MICRO_CHUNK (cload, VARID_MAX_LISTENERS, m_MaxListeners);
- READ_MICRO_CHUNK (cload, VARID_NOTIFY_DELAY, m_NotifyDelayInMS);
- READ_MICRO_CHUNK (cload, VARID_LAST_NOTIFY, m_LastNotification);
- }
- cload.Close_Micro_Chunk ();
- }
- }
- break;
- }
- cload.Close_Chunk ();
- }
- return true;
- }
|