Description:
Switch over to SoundEffectsEngine Replace inline calls to play sounds to a dedicated engine. Having an engine will also make it easier to have audio settings.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r581:36b2118dd380 -

@@ -0,0 +1,56
1 using System.Collections.Generic;
2
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Content;
5 using Microsoft.Xna.Framework.Audio;
6
7 using Encompass;
8
9 using isometricparkfna.Messages;
10
11 namespace isometricparkfna.Engines
12 {
13
14 [Receives(typeof(PlaySoundMessage))]
15 public class SoundEffectEngine : Engine
16 {
17 public static Dictionary<string, SoundEffect> sounds = new Dictionary<string, SoundEffect>();
18 public float volume = 1.0f;
19 public float pitch = 0.0f;
20 public float pan = 0.0f;
21
22
23 public static SoundEffect LoadSound(ContentManager content, string path) {
24 return LoadSound(content, path, path);
25 }
26
27 public static SoundEffect LoadSound(ContentManager content,
28 string path, string name) {
29 var sfx = content.Load<SoundEffect>(path);
30 sounds.Add(name, sfx);
31 return sfx;
32
33 }
34
35 public static void DisposeSounds() {
36
37 foreach (KeyValuePair<string, SoundEffect> entry in sounds ) {
38 entry.Value.Dispose();
39 }
40
41 }
42
43 public override void Update(double dt) {
44
45 foreach(ref readonly var message
46 in ReadMessages<PlaySoundMessage>()) {
47 var sound = sounds[message.SoundName];
48
49 sound.Play(this.volume, this.pitch, this.pan);
50
51 }
52
53 }
54
55 }
56 }
@@ -0,0 +1,15
1 using Microsoft.Xna.Framework.Audio;
2
3
4 using Encompass;
5
6
7 namespace isometricparkfna.Messages
8 {
9
10 public struct PlaySoundMessage : IMessage
11 {
12 public string SoundName;
13
14 }
15 }
@@ -25,8 +25,8
25 typeof(GameStateMessage),
25 typeof(GameStateMessage),
26 typeof(QuitGameMessage),
26 typeof(QuitGameMessage),
27 typeof(SpawnSelection),
27 typeof(SpawnSelection),
28 typeof(AdjustSelection)
28 typeof(AdjustSelection),
29 )]
29 typeof(PlaySoundMessage))]
30 [Reads(typeof(WindowTypeComponent),
30 [Reads(typeof(WindowTypeComponent),
31 typeof(GameStateComponent),
31 typeof(GameStateComponent),
32 typeof(VisibilityComponent),
32 typeof(VisibilityComponent),
@@ -51,9 +51,7
51 private SoundEffect endSound;
51 private SoundEffect endSound;
52
52
53 public InputEngine(int menuBarHeight, Camera camera,
53 public InputEngine(int menuBarHeight, Camera camera,
54 GraphicsDeviceManager gdm, int height, int width,
54 GraphicsDeviceManager gdm, int height, int width) {
55 SoundEffect sound, SoundEffect startSound,
56 SoundEffect endSound) {
57 //initialize to blank for now
55 //initialize to blank for now
58 this.keyboardPrev = new KeyboardState();
56 this.keyboardPrev = new KeyboardState();
59 this.menuBarHeight = menuBarHeight;
57 this.menuBarHeight = menuBarHeight;
@@ -279,7 +277,7
279 if (isPlaying && !io.WantCaptureMouse) {
277 if (isPlaying && !io.WantCaptureMouse) {
280 if (mouseCur.RightButton == ButtonState.Pressed && mousePrev.RightButton == ButtonState.Released)
278 if (mouseCur.RightButton == ButtonState.Pressed && mousePrev.RightButton == ButtonState.Released)
281 {
279 {
282 this.sound.Play(1.0f, 0.0f, 0.0f);
280 SendMessage(new PlaySoundMessage { SoundName = "Click" });
283 SendMessage(new JumpCameraMessage {Movement = original_point});
281 SendMessage(new JumpCameraMessage {Movement = original_point});
284 }
282 }
285
283
@@ -316,10 +314,10
316 }
314 }
317 else if (ImGui.IsAnyItemHovered()) {
315 else if (ImGui.IsAnyItemHovered()) {
318 if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released) {
316 if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released) {
319 this.startSound.Play(1.0f, 0.0f, 0.0f);
317 SendMessage(new PlaySoundMessage { SoundName = "ClickPart1" });
320 }
318 }
321 else if (mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed) {
319 else if (mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed) {
322 this.endSound.Play(1.0f, 0.0f, 0.0f);
320 SendMessage(new PlaySoundMessage { SoundName = "ClickPart2" });
323 }
321 }
324 }
322 }
325
323
@@ -46,9 +46,6
46 private SpriteBatch tileBatch;
46 private SpriteBatch tileBatch;
47 // #if DEBUG
47 // #if DEBUG
48 private SoundEffect sound;
48 private SoundEffect sound;
49 private SoundEffect clickSound;
50 private SoundEffect clickStartSound;
51 private SoundEffect clickEndSound;
52 // #endif
49 // #endif
53 private SpriteFont monoFont;
50 private SpriteFont monoFont;
54 private SpriteFont largeMonoFont;
51 private SpriteFont largeMonoFont;
@@ -197,10 +194,10
197 this.tileBatch = new SpriteBatch(GraphicsDevice);
194 this.tileBatch = new SpriteBatch(GraphicsDevice);
198
195
199 // #if DEBUG
196 // #if DEBUG
200 this.sound = Content.Load<SoundEffect>("FNASound");
197 SoundEffectEngine.LoadSound(Content, "FNASound");
201 this.clickSound = Content.Load<SoundEffect>("Click");
198 SoundEffectEngine.LoadSound(Content, "Click");
202 this.clickStartSound = Content.Load<SoundEffect>("ClickPart1");
199 SoundEffectEngine.LoadSound(Content, "ClickPart1");
203 this.clickEndSound = Content.Load<SoundEffect>("ClickPart2");
200 SoundEffectEngine.LoadSound(Content, "ClickPart2");
204 // #endif
201 // #endif
205 Tile.TileSetTexture = Content.Load<Texture2D>(@"merged_tileset");
202 Tile.TileSetTexture = Content.Load<Texture2D>(@"merged_tileset");
206 var texture = Content.Load<Texture2D>(@"solid_tileset");
203 var texture = Content.Load<Texture2D>(@"solid_tileset");
@@ -272,8 +269,7
272 Logging.Debug(this.Story.ContinueMaximally());
269 Logging.Debug(this.Story.ContinueMaximally());
273
270
274 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm,
271 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm,
275 this.simulation.map.MapHeight, this.simulation.map.MapWidth,
272 this.simulation.map.MapHeight, this.simulation.map.MapWidth));
276 this.clickSound, this.clickStartSound, this.clickEndSound));
277 WorldBuilder.AddEngine(new UIEngine(this.Story));
273 WorldBuilder.AddEngine(new UIEngine(this.Story));
278 WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar));
274 WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar));
279
275
@@ -297,6 +293,7
297 WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar));
293 WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar));
298 WorldBuilder.AddEngine(new SimulationGameRateBridgeEngine(this.simulation));
294 WorldBuilder.AddEngine(new SimulationGameRateBridgeEngine(this.simulation));
299 WorldBuilder.AddEngine(new BuildToolEngine(this.simulation.map));
295 WorldBuilder.AddEngine(new BuildToolEngine(this.simulation.map));
296 WorldBuilder.AddEngine(new SoundEffectEngine());
300
297
301 WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1);
298 WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1);
302 WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2);
299 WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2);
@@ -433,9 +430,8
433 batch.Dispose();
430 batch.Dispose();
434 // #if DEBUG
431 // #if DEBUG
435 sound.Dispose();
432 sound.Dispose();
436 clickSound.Dispose();
433 SoundEffectEngine.DisposeSounds();
437 clickStartSound.Dispose();
434
438 clickEndSound.Dispose();
439 // #endif
435 // #endif
440 Tile.TileSetTexture.Dispose();
436 Tile.TileSetTexture.Dispose();
441 Logging.Success("Disposed of Tile texture.");
437 Logging.Success("Disposed of Tile texture.");
@@ -19,6 +19,8
19
19
20 public static bool newFullscreen;
20 public static bool newFullscreen;
21 public static Vector2 newResolution;
21 public static Vector2 newResolution;
22 public static float newSoundEffects;
23 public static bool newSoundEffectsMute;
22
24
23 private static string fontName = "Iosevka";
25 private static string fontName = "Iosevka";
24 private static int fontSize = 15;
26 private static int fontSize = 15;
@@ -135,6 +137,21
135
137
136 ImGui.Checkbox("Fullscreen", ref newFullscreen);
138 ImGui.Checkbox("Fullscreen", ref newFullscreen);
137
139
140
141
142 ImGui.Separator();
143
144 ImGui.PushFont(italicFont);
145 ImGui.Text("Audio");
146 ImGui.PopFont();
147 ImGui.Text("Sound Effects:\t");
148
149 ImGui.SameLine();
150 ImGui.DragFloat("##Sfx", ref newSoundEffects, 0.005f, 0.0f, 1.0f, "%.2f");
151 ImGui.SameLine();
152 ImGui.Checkbox("Mute", ref newSoundEffectsMute);
153
154
138 ImGui.Separator();
155 ImGui.Separator();
139
156
140 ImGui.PushFont(italicFont);
157 ImGui.PushFont(italicFont);
You need to be logged in to leave comments. Login now