ScummVM API documentation
sound_logic.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_SOUND_LOGIC_H_INCLUDED
28 #define ICB_SOUND_LOGIC_H_INCLUDED
29 
30 #include "engines/icb/p4.h"
31 #include "engines/icb/debug.h"
32 #include "engines/icb/session.h"
33 #include "engines/icb/global_objects.h"
34 #include "engines/icb/sound_logic_entry.h"
35 #include "engines/icb/common/px_sfx_description.h"
36 #include "engines/icb/mission.h"
37 
38 namespace ICB {
39 
40 // This is the maximum registrations of megas interested in sounds we can have.
41 #define SL_MAX_SUBSCRIBERS MAX_voxel_list
42 
43 // This defines the maximum number of sounds any one mega can be registered for.
44 #define SL_MAX_SOUND_REGISTRATIONS 10
45 
46 // The sound logic engine maintains the x,z position of this many sounds, which is the maximum number
47 // that will be audible at any one time.
48 #define SL_MAX_CONCURRENT_SOUNDS 24
49 
50 // The boundary around a floor (cm) which is used when deciding if a sound is on a floor.
51 #define SL_SAME_FLOOR_BOUNDARY 40
52 
53 // Some default values for the size of a sound (used in development only).
54 #define SL_MIN_SOUND 1000 // 10 metres
55 #define SL_MAX_SOUND 15000 // 150 metres
56 
57 // This defines how much the sound drops when travelling across unlinked floor rectangles.
58 #define SL_FLOOR_RECT_DROP_FACTOR 2
59 
60 // These define where the SFX subtitle appears.
61 #define SL_SFX_SUBTITLE_X (SCREEN_WIDTH / 2)
62 #define SL_SFX_SUBTITLE_Y (SCREEN_DEPTH - 20)
63 #define SL_SUBTITLE_WIDTH 300
64 
65 #define SL_SUBTITLE_R 255
66 #define SL_SUBTITLE_G 255
67 #define SL_SUBTITLE_B 255
68 
69 // This value gets returned if a coordinate cannot be found for a requested sound.
70 #define SL_UNDEFINED_COORDINATE (1000000)
71 
72 // Maximum number of floors that can be linked for sound events.
73 #define SL_MAX_FLOOR_LINKS 10
74 
75 // struct _sound_position
76 // This holds the x,z position of happening sounds (not half, pop pickers).
78  uint32 nSoundHash;
79  int32 nX, nZ;
80  uint32 nTimer;
81 };
82 
83 // This class is used to define a single global object, which makes the decisions about which megas
84 // heard what sounds and posts events in the event manager when required.
85 class _sound_logic {
86 public:
87  // Default constructor and destructor.
88  inline _sound_logic();
89  ~_sound_logic() { ; }
90 
91  // Call this to initialise the sound logic engine at the start of each session.
92  void Initialise();
93 
94  // This function is called every logic cycle to clean out expired sound events.
95  void Cycle();
96 
97  // This returns true if there is a sound event pending for the supplied ID, false if not.
98  bool8 SoundEventPendingForID(uint32 nID);
99 
100  // This clears any outstanding sound event for an object.
101  void ClearHeardFlag(uint32 nID);
102 
103  // This function is called by the real sound engine once for each sound currently happening.
104  inline uint32 ProcessSound(int32 fX, int32 fY, int32 fZ, const CSfx *pSFX) const;
105 
106  // This gets called whenever a new SFX is started.
107  void NewSound(uint32 nObjectID, int32 nX, int32 nY, int32 nZ, const CSfx *pSFX, uint32 nSoundHash);
108 
109  // These are used by mission.cpp to tell when to draw a SFX subtitle.
110  bool8 SubtitleActive() const { return ((m_nSFXSubtitleTimer == 0) ? FALSE8 : TRUE8); }
111  void DrawSubtitle() const;
112 
113  // This function suspends/unsuspends sound event processing for a mega.
114  void SetSuspendedFlag(uint32 nID, bool8 bSuspend);
115 
116  // These functions have direct script counterparts.
117  void AddSubscription(uint32 nID, const char *pcSoundID);
118  void RemoveSubscription(uint32 nID, const char *pcSoundID);
119  void RemoveAllSubscriptions(uint32 nID);
120  void SetHearingSensitivity(uint32 nID, uint32 nSensitivity);
121  bool8 MegaHeardSomething(uint32 nID);
122  bool8 MegaHeardThis(uint32 nID, const char *pcSoundID);
123  int32 GetSoundX(uint32 nSoundHash) const;
124  int32 GetSoundZ(uint32 nSoundHash) const;
125  void LinkFloorsForSoundEvents(const char *pcFloor1, const char *pcFloor2);
126 
127 private:
128  enum SoundVolumeMode { ACTUAL_VOLUME = 0, LOGIC_VOLUME };
129 
130  uint32 m_nNumSubscribers; // Number of current subscriptions.
131  uint32 m_nSFXSubtitleTimer; // Timer for displaying SFX subtitles.
132  const char *m_pcSFXSubtitleText; // Pointer to SFX subtitle text.
133  _sound_logic_entry m_pSubscribers[SL_MAX_SUBSCRIBERS]; // Current registrations of interest in certain sounds.
134  _sound_position m_pPositions[SL_MAX_CONCURRENT_SOUNDS]; // A list of audible sounds and their positions.
135  uint32 m_pnLinkedFloors[SL_MAX_FLOOR_LINKS][2]; // A list of floors linked for sound events.
136  uint32 m_nNumLinkedFloors; // Number of items in previous array.
137 
138  _sound_logic(const _sound_logic &) { ; }
139  void operator=(const _sound_logic &) { ; }
140 
141  uint32 FindMegaInList(uint32 nID) const;
142 
143  uint8 CalculateEffectiveVolume(SoundVolumeMode eMode, uint32 nMegaID, int32 nSoundX, int32 nSoundY, int32 nSoundZ, const CSfx *pSFX) const;
144 
145  bool8 SoundAndEarOnSameOrLinkedFloors(uint32 nEarID, PXreal fSoundX, PXreal fSoundY, PXreal fSoundZ) const;
146 
147  bool8 FloorsLinkedForSounds(uint32 nFloor1, uint32 nFloor2) const;
148 };
149 
150 inline _sound_logic::_sound_logic() { Initialise(); }
151 
152 inline uint32 _sound_logic::ProcessSound(int32 nX, int32 nY, int32 nZ, const CSfx *pSFX) const {
153  // Calculate volume at player's hearing position for the sound engine.
154  int32 watch = MS->player.Fetch_player_id();
155 
156  if (g_mission->camera_follow_id_overide) {
157  watch = g_mission->camera_follow_id_overide;
158  }
159 
160  return (CalculateEffectiveVolume(ACTUAL_VOLUME, watch, nX, nY, nZ, pSFX));
161 }
162 
163 extern _sound_logic *g_oSoundLogicEngine;
164 
165 } // End of namespace ICB
166 
167 #endif // #if !defined( SOUND_LOGIC_H_INCLUDED )
Definition: sound_logic.h:77
Definition: actor.h:32
Definition: px_sfx_description.h:59
Definition: sound_logic.h:85
Definition: sound_logic_entry.h:50