Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HUDSounds.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: HUDSounds.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  HUDSounds singleton class utility implementation
13 */
14 
15 #include "MemDebug.h"
16 #include "HUDSounds.h"
17 #include "AudioConfig.h"
18 
19 #include "Sound.h"
20 #include "DataLoader.h"
21 
22 // +--------------------------------------------------------------------+
23 
24 static Sound* mfd_mode = 0;
25 static Sound* nav_mode = 0;
26 static Sound* wep_mode = 0;
27 static Sound* wep_disp = 0;
28 static Sound* hud_mode = 0;
29 static Sound* hud_widget = 0;
30 static Sound* shield_level = 0;
31 static Sound* red_alert = 0;
32 static Sound* tac_accept = 0;
33 static Sound* tac_reject = 0;
34 
35 // +--------------------------------------------------------------------+
36 
37 static void LoadInterfaceSound(DataLoader* loader, const char* wave, Sound*& s)
38 {
39  loader->LoadSound(wave, s, 0, true); // optional sound effect
40 }
41 
42 void
44 {
46  loader->SetDataPath("Sounds/");
47 
48  LoadInterfaceSound(loader, "mfd_mode.wav", mfd_mode);
49  LoadInterfaceSound(loader, "nav_mode.wav", nav_mode);
50  LoadInterfaceSound(loader, "wep_mode.wav", wep_mode);
51  LoadInterfaceSound(loader, "wep_disp.wav", wep_disp);
52  LoadInterfaceSound(loader, "hud_mode.wav", hud_mode);
53  LoadInterfaceSound(loader, "hud_widget.wav", hud_widget);
54  LoadInterfaceSound(loader, "shield_level.wav", shield_level);
55  LoadInterfaceSound(loader, "alarm.wav", red_alert);
56  LoadInterfaceSound(loader, "tac_accept.wav", tac_accept);
57  LoadInterfaceSound(loader, "tac_reject.wav", tac_reject);
58 
59  if (red_alert)
61 
62  loader->SetDataPath(0);
63 }
64 
65 // +--------------------------------------------------------------------+
66 
67 void
69 {
70  delete mfd_mode;
71  delete nav_mode;
72  delete wep_mode;
73  delete wep_disp;
74  delete hud_mode;
75  delete hud_widget;
76  delete shield_level;
77  delete red_alert;
78  delete tac_accept;
79  delete tac_reject;
80 }
81 
83 {
84  Sound* sound = 0;
85 
86  switch (n) {
87  default:
88  case SND_MFD_MODE: if (mfd_mode) sound = mfd_mode->Duplicate(); break;
89  case SND_NAV_MODE: if (nav_mode) sound = nav_mode->Duplicate(); break;
90  case SND_WEP_MODE: if (wep_mode) sound = wep_mode->Duplicate(); break;
91  case SND_WEP_DISP: if (wep_disp) sound = wep_disp->Duplicate(); break;
92  case SND_HUD_MODE: if (hud_mode) sound = hud_mode->Duplicate(); break;
93  case SND_HUD_WIDGET: if (hud_widget) sound = hud_widget->Duplicate(); break;
94  case SND_SHIELD_LEVEL: if (shield_level) sound = shield_level->Duplicate(); break;
95  case SND_TAC_ACCEPT: if (tac_accept) sound = tac_accept->Duplicate(); break;
96  case SND_TAC_REJECT: if (tac_reject) sound = tac_reject->Duplicate(); break;
97 
98  // RED ALERT IS A SPECIAL CASE!
99  case SND_RED_ALERT:
100  if (red_alert) {
101  sound = red_alert;
102  }
103  break;
104  }
105 
106  if (sound && !sound->IsPlaying()) {
107  int gui_volume = AudioConfig::GuiVolume();
108  sound->SetVolume(gui_volume);
109  sound->Play();
110  }
111 }
112 
114 {
115  if (n == SND_RED_ALERT && red_alert) {
116  red_alert->Stop();
117  }
118 }