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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -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 | 25 | typeof(GameStateMessage), |
|
26 | 26 | typeof(QuitGameMessage), |
|
27 | 27 | typeof(SpawnSelection), |
|
28 | typeof(AdjustSelection) | |
|
29 | )] | |
|
28 | typeof(AdjustSelection), | |
|
29 | typeof(PlaySoundMessage))] | |
|
30 | 30 | [Reads(typeof(WindowTypeComponent), |
|
31 | 31 | typeof(GameStateComponent), |
|
32 | 32 | typeof(VisibilityComponent), |
@@ -51,9 +51,7 | |||
|
51 | 51 | private SoundEffect endSound; |
|
52 | 52 | |
|
53 | 53 | public InputEngine(int menuBarHeight, Camera camera, |
|
54 |
GraphicsDeviceManager gdm, int height, int width |
|
|
55 | SoundEffect sound, SoundEffect startSound, | |
|
56 | SoundEffect endSound) { | |
|
54 | GraphicsDeviceManager gdm, int height, int width) { | |
|
57 | 55 | //initialize to blank for now |
|
58 | 56 | this.keyboardPrev = new KeyboardState(); |
|
59 | 57 | this.menuBarHeight = menuBarHeight; |
@@ -279,7 +277,7 | |||
|
279 | 277 | if (isPlaying && !io.WantCaptureMouse) { |
|
280 | 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 | 281 | SendMessage(new JumpCameraMessage {Movement = original_point}); |
|
284 | 282 | } |
|
285 | 283 | |
@@ -316,10 +314,10 | |||
|
316 | 314 | } |
|
317 | 315 | else if (ImGui.IsAnyItemHovered()) { |
|
318 | 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 | 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 | 46 | private SpriteBatch tileBatch; |
|
47 | 47 | // #if DEBUG |
|
48 | 48 | private SoundEffect sound; |
|
49 | private SoundEffect clickSound; | |
|
50 | private SoundEffect clickStartSound; | |
|
51 | private SoundEffect clickEndSound; | |
|
52 | 49 | // #endif |
|
53 | 50 | private SpriteFont monoFont; |
|
54 | 51 | private SpriteFont largeMonoFont; |
@@ -197,10 +194,10 | |||
|
197 | 194 | this.tileBatch = new SpriteBatch(GraphicsDevice); |
|
198 | 195 | |
|
199 | 196 | // #if DEBUG |
|
200 | this.sound = Content.Load<SoundEffect>("FNASound"); | |
|
201 | this.clickSound = Content.Load<SoundEffect>("Click"); | |
|
202 | this.clickStartSound = Content.Load<SoundEffect>("ClickPart1"); | |
|
203 | this.clickEndSound = Content.Load<SoundEffect>("ClickPart2"); | |
|
197 | SoundEffectEngine.LoadSound(Content, "FNASound"); | |
|
198 | SoundEffectEngine.LoadSound(Content, "Click"); | |
|
199 | SoundEffectEngine.LoadSound(Content, "ClickPart1"); | |
|
200 | SoundEffectEngine.LoadSound(Content, "ClickPart2"); | |
|
204 | 201 | // #endif |
|
205 | 202 | Tile.TileSetTexture = Content.Load<Texture2D>(@"merged_tileset"); |
|
206 | 203 | var texture = Content.Load<Texture2D>(@"solid_tileset"); |
@@ -272,8 +269,7 | |||
|
272 | 269 | Logging.Debug(this.Story.ContinueMaximally()); |
|
273 | 270 | |
|
274 | 271 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm, |
|
275 |
this.simulation.map.MapHeight, this.simulation.map.MapWidth |
|
|
276 | this.clickSound, this.clickStartSound, this.clickEndSound)); | |
|
272 | this.simulation.map.MapHeight, this.simulation.map.MapWidth)); | |
|
277 | 273 | WorldBuilder.AddEngine(new UIEngine(this.Story)); |
|
278 | 274 | WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar)); |
|
279 | 275 | |
@@ -297,6 +293,7 | |||
|
297 | 293 | WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar)); |
|
298 | 294 | WorldBuilder.AddEngine(new SimulationGameRateBridgeEngine(this.simulation)); |
|
299 | 295 | WorldBuilder.AddEngine(new BuildToolEngine(this.simulation.map)); |
|
296 | WorldBuilder.AddEngine(new SoundEffectEngine()); | |
|
300 | 297 | |
|
301 | 298 | WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1); |
|
302 | 299 | WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2); |
@@ -433,9 +430,8 | |||
|
433 | 430 | batch.Dispose(); |
|
434 | 431 | // #if DEBUG |
|
435 | 432 | sound.Dispose(); |
|
436 |
|
|
|
437 | clickStartSound.Dispose(); | |
|
438 | clickEndSound.Dispose(); | |
|
433 | SoundEffectEngine.DisposeSounds(); | |
|
434 | ||
|
439 | 435 | // #endif |
|
440 | 436 | Tile.TileSetTexture.Dispose(); |
|
441 | 437 | Logging.Success("Disposed of Tile texture."); |
@@ -19,6 +19,8 | |||
|
19 | 19 | |
|
20 | 20 | public static bool newFullscreen; |
|
21 | 21 | public static Vector2 newResolution; |
|
22 | public static float newSoundEffects; | |
|
23 | public static bool newSoundEffectsMute; | |
|
22 | 24 | |
|
23 | 25 | private static string fontName = "Iosevka"; |
|
24 | 26 | private static int fontSize = 15; |
@@ -135,6 +137,21 | |||
|
135 | 137 | |
|
136 | 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 | 155 | ImGui.Separator(); |
|
139 | 156 | |
|
140 | 157 | ImGui.PushFont(italicFont); |
You need to be logged in to leave comments.
Login now