[Scummvm-git-logs] scummvm master -> 078f7ad1c7700c8cf12276fa82a8329560fe0f68
aquadran
aquadran at gmail.com
Sun Mar 14 07:50:24 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
078f7ad1c7 ICB: Reworked global constructor
Commit: 078f7ad1c7700c8cf12276fa82a8329560fe0f68
https://github.com/scummvm/scummvm/commit/078f7ad1c7700c8cf12276fa82a8329560fe0f68
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-03-14T08:50:19+01:00
Commit Message:
ICB: Reworked global constructor
Changed paths:
engines/icb/global_vars.cpp
engines/icb/sound.cpp
engines/icb/sound.h
diff --git a/engines/icb/global_vars.cpp b/engines/icb/global_vars.cpp
index 7a91cc4fa0..f72e1656dd 100644
--- a/engines/icb/global_vars.cpp
+++ b/engines/icb/global_vars.cpp
@@ -168,6 +168,8 @@ void CreateGlobalObjects() {
gtetrans = new MATRIX;
gtecolour = new MATRIX;
gtelight = new MATRIX;
+ for (int i = 0; i < MAX_REGISTERED_SOUNDS; i++)
+ g_registeredSounds[i] = new CRegisteredSound;
// The order of creation matters:
g_oEventManager = new _event_manager;
@@ -209,6 +211,8 @@ void DestroyGlobalObjects() {
delete gtetrans;
delete gtecolour;
delete gtelight;
+ for (int i = 0; i < MAX_REGISTERED_SOUNDS; i++)
+ delete g_registeredSounds[i];
delete g_oEventManager;
delete g_oLineOfSight;
diff --git a/engines/icb/sound.cpp b/engines/icb/sound.cpp
index a17e019563..75bee490fb 100644
--- a/engines/icb/sound.cpp
+++ b/engines/icb/sound.cpp
@@ -389,100 +389,11 @@ int32 GetFreeChannel() {
return -1;
}
-#define NO_REGISTERED_SOUND 0xffffffff
-#define MAX_REGISTERED_SOUNDS 128
#define UPDATES_PER_SECOND 10
#define MAX_ENV_POSITION (128 * 128)
#define VOLUME_SLIDE 48 // how quickly we fade out a sound when it's time to cut off (this happens rarely but we don't want a pop)
-class CRegisteredSound {
-
-public:
- uint32 m_objID; // id of object calling us
- uint32 m_sndHash; // hash of sound id
- int32 m_channel; // -1 for no channel needed for the turn everything off hack...
-
- PXreal m_x;
- PXreal m_y;
- PXreal m_z;
-
- int32 m_restart_time;
- int32 m_volume;
-
-private:
- int32 m_sfxNumber; // hash value of sfx
-
- int32 m_velocity;
- int32 m_position; // position*128
-
- int32 m_current_pitch;
- int32 m_sample_pitch;
- int32 m_rand_pitch_value;
- int32 m_next_random_pos;
- int32 m_pan;
-
- PXreal m_xoffset;
- PXreal m_yoffset;
- PXreal m_zoffset;
-
- int8 m_objMoving;
- int8 m_volume_offset; // offset of volume, 127 is normal full volume effect, anything less scales down
-
-public:
- inline void Wipe();
-
- CRegisteredSound() : m_objID(NO_REGISTERED_SOUND) { Wipe(); }
-
- ~CRegisteredSound() {}
-
- inline uint32 GetObjectID() { return m_objID; }
-
- bool8 IsThisSound(uint32 obj, uint32 sndHash) {
-
- if ((obj == m_objID) && (sndHash == m_sndHash))
- return TRUE8;
- else
- return FALSE8;
- }
-
- inline bool8 IsFree() { return (bool8)(m_objID == NO_REGISTERED_SOUND); }
- inline bool8 IsUsed() { return (bool8)(m_objID != NO_REGISTERED_SOUND); }
-
- int32 GetChannel() { return m_channel; }
-
- bool8 SetHearable();
- void SetUnhearable();
-
- void Update10Hz(); // update 10hz (updates position etc)
-
- void GetPosition();
-
- void TurnOff();
-
- // update every game cycle (starts samples if required, updates vol, pitch, pan, stops if end reached, etc...)
- void UpdateGameCycle(int32 newVol, int32 newPan);
-
- void GetRandom(CSfx *sfx); // update random value
- void Register(const char *sndName, const char *sfxName, uint32 sfxHash, int8 volume);
-
- void RegisterFromObject(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal xo, PXreal yo, PXreal zo, int8 volume);
- void RegisterFromAbsolute(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal x, PXreal y, PXreal z, int8 volume);
-
- void Remove();
-
- CSfx *GetSfx(); // should be reasonably fast now...
-
- // volume and pan together (faster than seperate)
- void GetVolumeAndPan(int32 &vol, int32 &pan);
-
- private:
- bool8 m_inSession; // if TRUE sfx is in session cluster, otherwise sfx is in mission cluster
- bool8 m_turnOff; // turning off
- bool8 m_remove; // if true then when finihsed turning off remove the sound
- uint8 padding1;
-};
-
// Get sfx for this registered sound
CSfx *CRegisteredSound::GetSfx() {
CSfx *the_sfx = 0;
@@ -502,7 +413,7 @@ CSfx *CRegisteredSound::GetSfx() {
}
// Zero out all the values of a sound
-inline void CRegisteredSound::Wipe() {
+void CRegisteredSound::Wipe() {
m_objID = NO_REGISTERED_SOUND;
m_sndHash = NULL_HASH;
m_channel = -1;
@@ -912,7 +823,7 @@ void CRegisteredSound::GetVolumeAndPan(int32 &vol, int32 &pan) {
return;
}
-CRegisteredSound registeredSounds[MAX_REGISTERED_SOUNDS];
+CRegisteredSound *g_registeredSounds[MAX_REGISTERED_SOUNDS];
int32 assignedSounds = 0;
@@ -921,51 +832,46 @@ void UpdateSounds10Hz() {
int32 i;
for (i = 0; i < MAX_REGISTERED_SOUNDS; i++)
- registeredSounds[i].Update10Hz();
+ g_registeredSounds[i]->Update10Hz();
}
// called every game cycle sets hearable and unhearable sounds...
void UpdateHearableSounds() {
int32 i;
int32 assigned;
- CRegisteredSound *snd;
-
int32 volume;
int32 pan;
assigned = 0;
- snd = &(registeredSounds[0]);
// no sound...
currentSoundLevel = 0;
for (i = 0; i < MAX_REGISTERED_SOUNDS; i++) {
-
// we might need to do this even if sound is not currently used
- snd->TurnOff();
+ g_registeredSounds[i]->TurnOff();
- if (snd->IsUsed()) {
+ if (g_registeredSounds[i]->IsUsed()) {
// work out if is current hearable by the camera
// if speical sound or sound is not paused then we get the volume and pan from manager
- if (((snd->m_objID == SPECIAL_SOUND) && (snd->m_sndHash == menuSoundIDHash)) || (!pauseSound)) {
- snd->GetVolumeAndPan(volume, pan);
+ if (((g_registeredSounds[i]->m_objID == SPECIAL_SOUND) && (g_registeredSounds[i]->m_sndHash == menuSoundIDHash)) || (!pauseSound)) {
+ g_registeredSounds[i]->GetVolumeAndPan(volume, pan);
// if volume is greater than zero
if (volume > 0) {
- if (!snd->SetHearable())
+ if (!g_registeredSounds[i]->SetHearable())
Fatal_error("Can't find a free channel to play sound");
} else
- snd->SetUnhearable(); // no Update required we are turning off or are off screen....
+ g_registeredSounds[i]->SetUnhearable(); // no Update required we are turning off or are off screen....
} else {
volume = 0;
pan = 0;
}
// update the wave etc
- snd->UpdateGameCycle(volume, pan);
+ g_registeredSounds[i]->UpdateGameCycle(volume, pan);
}
- snd++;
}
currentSoundLevel = (currentSoundLevel * 100) / (128 * 128);
@@ -1027,14 +933,14 @@ int32 GetSoundCloser(int32 objID, PXreal x, PXreal y, PXreal z) {
int32 channelReplace = -1;
for (i = 0; i < MAX_REGISTERED_SOUNDS; i++) {
- c = registeredSounds[i].m_channel;
+ c = g_registeredSounds[i]->m_channel;
// can only replace a sound that has a channel and is not a special sound
- if ((c != -1) && (registeredSounds[i].m_objID != SPECIAL_SOUND)) {
- registeredSounds[i].GetPosition();
- x = registeredSounds[i].m_x - px;
- y = registeredSounds[i].m_y - py;
- z = registeredSounds[i].m_z - pz;
+ if ((c != -1) && (g_registeredSounds[i]->m_objID != SPECIAL_SOUND)) {
+ g_registeredSounds[i]->GetPosition();
+ x = g_registeredSounds[i]->m_x - px;
+ y = g_registeredSounds[i]->m_y - py;
+ z = g_registeredSounds[i]->m_z - pz;
thisDist = x * x + y * y + z * z;
// if this distance from player is more than the maximum so far then this is the furthest sound
@@ -1056,7 +962,7 @@ int32 GetSoundCloser(int32 objID, PXreal x, PXreal y, PXreal z) {
Tdebug("sounds.txt", "replacing sound %d (channel %d) because it's too far away (dist: %g, our dist: %g)", sfxReplace, channelReplace, maxDist, dist);
// the sfx now has no channel
- registeredSounds[sfxReplace].m_channel = -1;
+ g_registeredSounds[sfxReplace]->m_channel = -1;
// we return the channel we have just pinched
@@ -1074,11 +980,12 @@ void TurnOnSound() { soundOn = TRUE8; }
int32 GetFreeSound(const char *sfxName) {
int32 i;
- for (i = 0; i < MAX_REGISTERED_SOUNDS; i++)
- if (registeredSounds[i].IsFree()) {
+ for (i = 0; i < MAX_REGISTERED_SOUNDS; i++) {
+ if (g_registeredSounds[i]->IsFree()) {
Tdebug("sounds.txt", "sfx: %s registered sound: %d", sfxName, i);
return i;
}
+ }
Fatal_error("No free sounds! %s", sfxName);
return -1;
@@ -1087,9 +994,10 @@ int32 GetFreeSound(const char *sfxName) {
int32 FindSound(uint32 obj, uint32 sndHash, int32 start = 0) {
int32 i;
- for (i = start; i < MAX_REGISTERED_SOUNDS; i++)
- if (registeredSounds[i].IsThisSound(obj, sndHash))
+ for (i = start; i < MAX_REGISTERED_SOUNDS; i++) {
+ if (g_registeredSounds[i]->IsThisSound(obj, sndHash))
return i;
+ }
// should this be a fatal error..??
return -1;
@@ -1114,12 +1022,12 @@ void RegisterSoundOffset(uint32 obj, const char *offsetName, const char *sfxName
// special sound
if (obj == SPECIAL_SOUND) {
- registeredSounds[i].RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
+ g_registeredSounds[i]->RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
}
// absolute sound (no name)
else if ((offsetName == NULL) || (strcmp(offsetName, "") == 0)) {
// absolute address
- registeredSounds[i].RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
+ g_registeredSounds[i]->RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
}
// object is a nico marker
else if (isNico) {
@@ -1129,18 +1037,18 @@ void RegisterSoundOffset(uint32 obj, const char *offsetName, const char *sfxName
x = fi->x;
y = fi->y;
z = fi->z;
- registeredSounds[i].RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, x + xo, y + yo, z + zo, volume_offset);
+ g_registeredSounds[i]->RegisterFromAbsolute(obj, sndID, sfxName, sfxHash, x + xo, y + yo, z + zo, volume_offset);
}
// object is a mega
else {
// is mega object so attach sound to it
// obj=
obj = MS->objects->Fetch_item_number_by_name(offsetName);
- registeredSounds[i].RegisterFromObject(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
+ g_registeredSounds[i]->RegisterFromObject(obj, sndID, sfxName, sfxHash, xo, yo, zo, volume_offset);
}
Tdebug("sounds.txt", "restart time is %d %d\n", (-1) - (time), time);
- registeredSounds[i].m_restart_time = (-1) - (time);
+ g_registeredSounds[i]->m_restart_time = (-1) - (time);
}
// register a sound from an object
@@ -1200,10 +1108,9 @@ void RemoveRegisteredSound(uint32 obj, const char *sndID) {
do {
i = FindSound(obj, sndIDHash, start);
-
// okay we have one (either object or special)
if (i != -1)
- registeredSounds[i].Remove();
+ g_registeredSounds[i]->Remove();
// next start of search is one above this...
start = i + 1;
@@ -1220,7 +1127,7 @@ void RemoveRegisteredSound(uint32 obj, const char *sndID) {
// okay we have one (either object or special)
if (i != -1)
- registeredSounds[i].Remove();
+ g_registeredSounds[i]->Remove();
// next start of search is one above this...
start = i + 1;
@@ -1234,8 +1141,8 @@ void RemoveAllSoundsWithID(uint32 obj) {
int32 i;
for (i = 0; i < MAX_REGISTERED_SOUNDS; i++) {
- if (registeredSounds[i].GetObjectID() == obj)
- registeredSounds[i].Remove();
+ if (g_registeredSounds[i]->GetObjectID() == obj)
+ g_registeredSounds[i]->Remove();
}
}
@@ -1244,7 +1151,7 @@ void StopAllSoundsNow() {
uint32 i;
for (i = 0; i < MAX_REGISTERED_SOUNDS; i++) {
- registeredSounds[i].Wipe();
+ g_registeredSounds[i]->Wipe();
}
for (i = 0; i < NUMBER_CHANNELS; i++) {
diff --git a/engines/icb/sound.h b/engines/icb/sound.h
index 160d2f8d6a..3f9c7fb5d8 100644
--- a/engines/icb/sound.h
+++ b/engines/icb/sound.h
@@ -30,6 +30,7 @@
#include "engines/icb/common/px_common.h"
#include "engines/icb/common/px_clu_api.h"
+#include "engines/icb/common/px_sfx_description.h"
#include "engines/icb/sound_lowlevel.h"
namespace ICB {
@@ -93,6 +94,98 @@ extern const char *tinkleSfxVar;
extern const char *defaultTinkleSfx;
extern const char *tinkleDesc;
+#define NO_REGISTERED_SOUND 0xffffffff
+#define MAX_REGISTERED_SOUNDS 128
+
+class CRegisteredSound {
+
+public:
+ uint32 m_objID; // id of object calling us
+ uint32 m_sndHash; // hash of sound id
+ int32 m_channel; // -1 for no channel needed for the turn everything off hack...
+
+ PXreal m_x;
+ PXreal m_y;
+ PXreal m_z;
+
+ int32 m_restart_time;
+ int32 m_volume;
+
+private:
+ int32 m_sfxNumber; // hash value of sfx
+
+ int32 m_velocity;
+ int32 m_position; // position*128
+
+ int32 m_current_pitch;
+ int32 m_sample_pitch;
+ int32 m_rand_pitch_value;
+ int32 m_next_random_pos;
+ int32 m_pan;
+
+ PXreal m_xoffset;
+ PXreal m_yoffset;
+ PXreal m_zoffset;
+
+ int8 m_objMoving;
+ int8 m_volume_offset; // offset of volume, 127 is normal full volume effect, anything less scales down
+
+public:
+ void Wipe();
+
+ CRegisteredSound() : m_objID(NO_REGISTERED_SOUND) { Wipe(); }
+
+ ~CRegisteredSound() {}
+
+ inline uint32 GetObjectID() { return m_objID; }
+
+ bool8 IsThisSound(uint32 obj, uint32 sndHash) {
+
+ if ((obj == m_objID) && (sndHash == m_sndHash))
+ return TRUE8;
+ else
+ return FALSE8;
+ }
+
+ inline bool8 IsFree() { return (bool8)(m_objID == NO_REGISTERED_SOUND); }
+ inline bool8 IsUsed() { return (bool8)(m_objID != NO_REGISTERED_SOUND); }
+
+ int32 GetChannel() { return m_channel; }
+
+ bool8 SetHearable();
+ void SetUnhearable();
+
+ void Update10Hz(); // update 10hz (updates position etc)
+
+ void GetPosition();
+
+ void TurnOff();
+
+ // update every game cycle (starts samples if required, updates vol, pitch, pan, stops if end reached, etc...)
+ void UpdateGameCycle(int32 newVol, int32 newPan);
+
+ void GetRandom(CSfx *sfx); // update random value
+ void Register(const char *sndName, const char *sfxName, uint32 sfxHash, int8 volume);
+
+ void RegisterFromObject(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal xo, PXreal yo, PXreal zo, int8 volume);
+ void RegisterFromAbsolute(const uint32 objID, const char *sndName, const char *sfxName, uint32 sfxHash, PXreal x, PXreal y, PXreal z, int8 volume);
+
+ void Remove();
+
+ CSfx *GetSfx(); // should be reasonably fast now...
+
+ // volume and pan together (faster than seperate)
+ void GetVolumeAndPan(int32 &vol, int32 &pan);
+
+private:
+ bool8 m_inSession; // if TRUE sfx is in session cluster, otherwise sfx is in mission cluster
+ bool8 m_turnOff; // turning off
+ bool8 m_remove; // if true then when finihsed turning off remove the sound
+ uint8 padding1;
+};
+
+extern CRegisteredSound *g_registeredSounds[MAX_REGISTERED_SOUNDS];
+
bool8 SfxExists(uint32 sfxHash);
bool8 SfxExists(const char *sfx);
More information about the Scummvm-git-logs
mailing list