• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-c誰得cocoaqtpythonrubywindowsphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwitterdombtronvb.nettestarduinodirectxpreviewerゲームエンジン

Commit MetaInfo

Revisiónd41a6a0910f3df86644c02bd09776f018ab80bf1 (tree)
Tiempo2021-04-25 11:47:27
Autorsebastian_bugiu
Commitersebastian_bugiu

Log Message

Added limiter for multiple concurrent sounds. Commented out debug traces. Sound is no longer updated every frame.

Cambiar Resumen

Diferencia incremental

diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/HudManager.java
--- a/core/src/headwayent/blackholedarksun/HudManager.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/HudManager.java Sun Apr 25 05:47:27 2021 +0300
@@ -318,7 +318,7 @@
318318 // In this case we are dead since visibilityDataSet will become true with no
319319 // actual data behind it.
320320 for (RadarVisibilityData visibilityData : next.getValue()) {
321- System.out.println("Getting rid of visibilityData: " + visibilityData.entityName);
321+// System.out.println("Getting rid of visibilityData: " + visibilityData.entityName);
322322 radarVisibilityDataQueue.add(visibilityData);
323323 }
324324
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/animations/ShipHitWithoutRenderingAnimation.java
--- a/core/src/headwayent/blackholedarksun/animations/ShipHitWithoutRenderingAnimation.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/animations/ShipHitWithoutRenderingAnimation.java Sun Apr 25 05:47:27 2021 +0300
@@ -6,7 +6,7 @@
66 * Created by sebas on 19.11.2015.
77 */
88 public abstract class ShipHitWithoutRenderingAnimation extends Animation {
9- public static final long TOTAL_ANIM_TIME = 15000;
9+ public static final long TOTAL_ANIM_TIME = 2000;
1010
1111 public ShipHitWithoutRenderingAnimation(String name, long totalTime) {
1212 super(name, totalTime);
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/gamestatedebugger/FrameInterval.java
--- a/core/src/headwayent/blackholedarksun/gamestatedebugger/FrameInterval.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/gamestatedebugger/FrameInterval.java Sun Apr 25 05:47:27 2021 +0300
@@ -66,6 +66,7 @@
6666 public static final String CARGO_SCAN_TIME = "password_char_time ";
6767 public static final String SET_AFTERBURNER_ACTIVE = "set_afterburner_active ";
6868 public static final String UPDATE_COLLISION_PLAYER_SHIP_HIT_ANIMATION = "update_collision_player_ship_hit_animation";
69+ public static final String SOUND_SHOULD_PLAY_SOUND = "should_play_sound ";
6970
7071
7172 public static class GameFrameIntervalFactory extends FrameIntervalFactory {
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/input/InGameInputConvertorListener.java
--- a/core/src/headwayent/blackholedarksun/input/InGameInputConvertorListener.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/input/InGameInputConvertorListener.java Sun Apr 25 05:47:27 2021 +0300
@@ -195,7 +195,7 @@
195195 }
196196
197197 if (result.length() > 0.0f) {
198- System.out.println("result: " + result.length());
198+// System.out.println("result: " + result.length());
199199 }
200200
201201 boolean normalized = false;
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/physics/EntityContactListener.java
--- a/core/src/headwayent/blackholedarksun/physics/EntityContactListener.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/physics/EntityContactListener.java Sun Apr 25 05:47:27 2021 +0300
@@ -107,7 +107,7 @@
107107 }
108108
109109 if (projectileProperties != null) {
110- System.out.println("Projectile: " + entityProperties.getName() + " collided");
110+// System.out.println("Projectile: " + entityProperties.getName() + " collided");
111111 }
112112
113113 boolean decreaseHealth = true;
@@ -119,7 +119,7 @@
119119 decreaseHealth = false;
120120 collisionResolved = false;
121121 showHitAnimation = false;
122- System.out.println("Projectile: " + entityProperties.getName() + " collided with mother ship: " + othEntityProp.getName());
122+// System.out.println("Projectile: " + entityProperties.getName() + " collided with mother ship: " + othEntityProp.getName());
123123 }
124124 }
125125 if (shipProperties != null && othProjectileProperties != null) {
@@ -127,7 +127,7 @@
127127 decreaseHealth = false;
128128 collisionResolved = false;
129129 showHitAnimation = false;
130- System.out.println("Projectile: " + othEntityProp.getName() + " collided with mother ship: " + entityProperties.getName());
130+// System.out.println("Projectile: " + othEntityProp.getName() + " collided with mother ship: " + entityProperties.getName());
131131 }
132132 }
133133 // Projectile launched from the same ship are immune to one another
@@ -136,7 +136,7 @@
136136 decreaseHealth = false;
137137 collisionResolved = false;
138138 showHitAnimation = false;
139- System.out.println("Projectiles collided with each other: " + entityProperties.getName() + " " + othEntityProp.getName());
139+// System.out.println("Projectiles collided with each other: " + entityProperties.getName() + " " + othEntityProp.getName());
140140 }
141141 }
142142
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/world/WorldManager.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManager.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManager.java Sun Apr 25 05:47:27 2021 +0300
@@ -39,6 +39,8 @@
3939 public abstract class WorldManager extends WorldManagerBase {
4040 public static final String LEVEL_LIGHT = "LevelLight";
4141 public static final String LEVEL_LIGHT_NODE = "LevelLightNode";
42+ public static final long SOUND_UPDATE_MIN_DELTA = 70;
43+ private long lastSoundUpdateTime;
4244 private boolean levelDirectionalLightingCreated;
4345
4446 // protected static WorldManager mgr;
@@ -591,7 +593,11 @@
591593 return pan;
592594 }
593595
594- protected void updateSounds() {
596+ protected void updateSounds(long currentTime) {
597+ if (currentTime - lastSoundUpdateTime <= SOUND_UPDATE_MIN_DELTA) {
598+ return;
599+ }
600+ lastSoundUpdateTime = currentTime;
595601 Entity playerShip = getShip(getPlayerShipEntityId());
596602 if (playerShip != null) {
597603 EntityProperties playerShipEntityProperties = entityPropertiesComponentMapper.get(playerShip);
@@ -634,7 +640,11 @@
634640 if (snd.id != -1) {
635641 float pan = getSoundPan(playerShipEntityProperties, entry.getKey());
636642 snd.pan = pan;
637- sound.setPan(snd.name, snd.id, pan, snd.volume);
643+ snd.previousVolume = snd.volume;
644+ snd.volume = volume;
645+ if (snd.previousVolume != 0 || snd.volume != 0) {
646+ sound.setPan(snd.name, snd.id, pan, snd.volume);
647+ }
638648
639649 // System.out.println("sound " + snd.name +
640650 // " set volume with id: " + snd.id +
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/world/WorldManagerBase.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManagerBase.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManagerBase.java Sun Apr 25 05:47:27 2021 +0300
@@ -85,6 +85,7 @@
8585 public float maxDistance = MAX_SOUND_DISTANCE;
8686 public float volumeMultiplier = 1.0f;
8787 public int volume; // 0 - 100.
88+ public int previousVolume; // If we already setVolume() to 0 no need to do it again.
8889 public float pan;
8990 public boolean startOnProximity;
9091 public boolean doNotDelete;
@@ -206,7 +207,7 @@
206207 public static final String BUNDLE_MISSION_DEBRIEFING = "bundle";
207208 protected static final float PAN_DISTANCE = 200.0f;
208209 protected static final float PAN_DISTANCE_INV = 1.0f / PAN_DISTANCE;
209- protected static final int SOUND_LIFETIME = 10000;
210+ protected static final int SOUND_LIFETIME = 5000; // No sound should be longer than 5 secs.
210211 protected static final int MAX_HUMAN_DEMO_SHIPS = 4;
211212 protected static final int MAX_ALIEN_DEMO_SHIPS = 4;
212213 protected static final int DEMO_SHIP_SPAWN_CHANCE = 10;
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/world/WorldManagerMP.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManagerMP.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManagerMP.java Sun Apr 25 05:47:27 2021 +0300
@@ -378,6 +378,8 @@
378378
379379 gameWorld.getSystem(GameLogicEntityRemoverMPSystem.class).process();
380380
381+ updateSounds(currentTime);
382+
381383 updateAnimations();
382384
383385 clearLists();
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/blackholedarksun/world/WorldManagerSP.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManagerSP.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManagerSP.java Sun Apr 25 05:47:27 2021 +0300
@@ -93,7 +93,7 @@
9393 // removeRemovableEntities();
9494
9595
96- updateSounds();
96+ updateSounds(currentTime);
9797
9898 updateAnimations();
9999
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/ENG_SoundLoader.java
--- a/core/src/headwayent/hotshotengine/ENG_SoundLoader.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/ENG_SoundLoader.java Sun Apr 25 05:47:27 2021 +0300
@@ -15,13 +15,13 @@
1515 ArrayList<ENG_CompiledSound> compiledSound = new ENG_SoundCompiler().compile(fileName, path, fromSDCard);
1616 for (ENG_CompiledSound snd : compiledSound) {
1717 String[] pathAndFileName = ENG_CompilerUtil.getPathAndFileName(snd.filename);
18- loadSound(snd.name, pathAndFileName[1], pathAndFileName[0], fromSDCard);
18+ loadSound(snd.name, snd.duration, snd.priority, pathAndFileName[1], pathAndFileName[0], fromSDCard);
1919 }
2020 }
2121
22- public static void loadSound(String name, String fileName, String path, boolean fromSDCard) {
22+ public static void loadSound(String name, long duration, int priority, String fileName, String path, boolean fromSDCard) {
2323 if (fromSDCard) {
24- MainApp.getGame().getSound().loadSound(name, path + File.separator + fileName);
24+ MainApp.getGame().getSound().loadSound(name, path + File.separator + fileName, duration, priority);
2525 } else {
2626 throw new UnsupportedOperationException();
2727 }
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java Sun Apr 25 05:47:27 2021 +0300
@@ -44,10 +44,12 @@
4444 * Loads a sound and prepares it for future use
4545 *
4646 * @param name The sound name to be loaded
47+ * @param duration
48+ * @param priority
4749 * @throws IllegalArgumentException if no such file exists or the format is not
4850 * supported
4951 */
50- void loadSound(String name, String filename);
52+ void loadSound(String name, String filename, long duration, int priority);
5153
5254 /**
5355 * Specifically for android
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/audio/ENG_Sound.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_Sound.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_Sound.java Sun Apr 25 05:47:27 2021 +0300
@@ -109,9 +109,9 @@
109109 * @param name Name of the sound to be loaded for a specified path The path
110110 * must be specified using setPath()
111111 */
112- public void loadSound(String name, String filename) {
112+ public void loadSound(String name, String filename, long duration, int priority) {
113113
114- soundManager.loadSound(name, filename);
114+ soundManager.loadSound(name, filename, duration, priority);
115115 }
116116
117117 public void loadSound(String name, int handle) {
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java Sun Apr 25 05:47:27 2021 +0300
@@ -1,8 +1,13 @@
11 package headwayent.hotshotengine.audio;
22
3+import headwayent.blackholedarksun.gamestatedebugger.FrameInterval;
4+import headwayent.blackholedarksun.world.WorldManagerBase;
35 import headwayent.hotshotengine.ENG_Math;
6+import headwayent.hotshotengine.ENG_Utility;
47
8+import java.util.ArrayList;
59 import java.util.HashMap;
10+import java.util.Iterator;
611
712 import com.badlogic.gdx.Audio;
813 import com.badlogic.gdx.Gdx;
@@ -17,27 +22,83 @@
1722
1823 public class ENG_SoundManager {
1924
20- // This is pretty useless as a class as of now.
2125 private static class SoundInternal {
22- public Sound soundID;
26+
27+ private final String name; // For debugging
28+ private final Sound soundID;
29+ private final long duration;
30+ private final int priority; // 0 is the highest priority. 1, 2, 3 are lower priorities.
2331 // public float leftVolume = 1.0f, rightVolume = 1.0f; // These concepts are now obsolete.
2432 // public float volume; // 0.0f - 1.0f.
2533
26- public SoundInternal() {
27-
34+ public SoundInternal(String name, Sound soundID, long duration, int priority) {
35+ this.name = name;
36+ this.soundID = soundID;
37+ this.duration = duration;
38+ this.priority = priority;
2839 }
2940
30- public SoundInternal(Sound soundID) {
31- this.soundID = soundID;
41+ public String getName() {
42+ return name;
43+ }
44+
45+ public Sound getSoundID() {
46+ return soundID;
47+ }
48+
49+ public long getDuration() {
50+ return duration;
51+ }
52+
53+ public int getPriority() {
54+ return priority;
3255 }
3356 }
3457
58+ private static class ActiveSound {
59+ private final long playId;
60+ private final long startTime;
61+ private final SoundInternal sound;
62+ private final int currentPriority; // This is derived based on SoundInternal priority and volume at sound start.
63+ private final boolean looping;
64+
65+ public ActiveSound(long playId, long startTime, SoundInternal sound, int currentPriority, boolean isLooping) {
66+ this.playId = playId;
67+ this.startTime = startTime;
68+ this.sound = sound;
69+ this.currentPriority = currentPriority;
70+ this.looping = isLooping;
71+ }
72+
73+ public long getPlayId() {
74+ return playId;
75+ }
76+
77+ public long getStartTime() {
78+ return startTime;
79+ }
80+
81+ public SoundInternal getSound() {
82+ return sound;
83+ }
84+
85+ public int getCurrentPriority() {
86+ return currentPriority;
87+ }
88+
89+ public boolean isLooping() {
90+ return looping;
91+ }
92+ }
93+
94+ public static final int MAX_CONCURRENT_SOUNDS = 16;
3595 public static final int MAX_SOUND_VOLUME = 100;
36- private static final boolean DEBUG = false;
96+ public static final int SOUND_LOWEST_PRIORITY = 999;
97+ private static final boolean DEBUG = true;
3798 public static final boolean IGNORE_SOUND = false; // For faster loading on mobile
3899 public static final boolean FORCE_PLAY = true;
39- private final HashMap<String, SoundInternal> sounds =
40- new HashMap<>();
100+ private final HashMap<String, SoundInternal> sounds = new HashMap<>();
101+ private final ArrayList<ActiveSound> activeSounds = new ArrayList<>(MAX_CONCURRENT_SOUNDS);
41102 // private SoundPool player;
42103 private final Audio audioManager;
43104 // private Context context;
@@ -122,6 +183,10 @@
122183 return -1;
123184 }
124185
186+ if (volume == 0) {
187+ return -1;
188+ }
189+
125190 if (volume < 0 || volume > 100) {
126191 throw new IllegalArgumentException("volume sent is: " + volume);
127192 }
@@ -132,6 +197,9 @@
132197 if (sound == null) {
133198 throw new IllegalArgumentException(name + " is not a valid sound name");
134199 }
200+ if (!shouldPlaySound(sound)) {
201+ return playID;
202+ }
135203 /* player.play(sound.soundID, sound.leftVolume, sound.rightVolume, 10,
136204 isLooping, 1);*/
137205 float vol = (float) volume / (float) MAX_SOUND_VOLUME;
@@ -139,29 +207,96 @@
139207
140208 pan = ENG_Math.clamp(pan, -1.0f, 1.0f);
141209 if (isLooping) {
142- playID = sound.soundID.loop(vol, 1.0f, pan);
210+ playID = sound.getSoundID().loop(vol, 1.0f, pan);
143211 } else {
144- playID = sound.soundID.play(vol, 1.0f, pan);
212+ playID = sound.getSoundID().play(vol, 1.0f, pan);
145213 }
146214 if (playID == -1) {
147215 // throw new ENG_SoundException("Could not play sound: " + name);
148216 System.out.println("Could not play sound: " + name);
217+ } else {
218+ activeSounds.add(new ActiveSound(playID, ENG_Utility.currentTimeMillis(),
219+ sound, volume == 0 ? SOUND_LOWEST_PRIORITY : sound.getPriority(), isLooping));
149220 }
150221 if (DEBUG) {
151-// System.out.println("playing sound: " + name);
222+ System.out.println("Starting sound " + name + " playId " + playID + " sound volume: " + volume + " pan: " + pan);
152223 }
153224
154225 }
155226 return playID;
156227 }
157228
229+ private boolean shouldPlaySound(SoundInternal soundToBePlayed) {
230+ // Remove sounds that have finished playing from the active sounds list.
231+ removeFinishedSounds();
232+
233+ System.out.println("Current active sounds num: " + activeSounds.size());
234+ System.out.println("Attempting to play " + soundToBePlayed.getName() + " with default priority " + soundToBePlayed.getPriority());
235+
236+ // If we still have all sounds playing we need to try to make room for the new
237+ // sound based on priority.
238+ if (activeSounds.size() == MAX_CONCURRENT_SOUNDS) {
239+ System.out.println("Max concurrent sounds " + MAX_CONCURRENT_SOUNDS + " reached");
240+ ActiveSound activeSoundWithLowestPriority = null;
241+ for (ActiveSound activeSound : activeSounds) {
242+ if (activeSoundWithLowestPriority == null ||
243+ activeSound.getCurrentPriority() > activeSoundWithLowestPriority.getCurrentPriority()) {
244+ activeSoundWithLowestPriority = activeSound;
245+ }
246+ }
247+ // If there were more with the lowest priority in the active sounds list
248+ // then we selected the one longest playing. If the new sound has the same
249+ // priority then we evict the one with the same priority but longest playing.
250+ if (activeSoundWithLowestPriority.getCurrentPriority() >= soundToBePlayed.getPriority()) {
251+ System.out.println("Evicting sound " +
252+ activeSoundWithLowestPriority.getSound().getName() +
253+ " with lowest priority " +
254+ activeSoundWithLowestPriority.getCurrentPriority() +
255+ " to make room for " + soundToBePlayed.getName() +
256+ " with priority " + soundToBePlayed.getPriority());
257+ activeSounds.remove(activeSoundWithLowestPriority);
258+ stopSound(activeSoundWithLowestPriority.getSound(), activeSoundWithLowestPriority.getPlayId());
259+ } else {
260+ System.out.println("Sound " + soundToBePlayed.getName() + " with default priority " + soundToBePlayed.getPriority() + " could not be played");
261+ return false;
262+ }
263+ }
264+ return true;
265+ }
266+
267+ private void removeFinishedSounds() {
268+ for (Iterator<ActiveSound> iterator = activeSounds.iterator(); iterator.hasNext(); ) {
269+ ActiveSound activeSound = iterator.next();
270+ if (!activeSound.isLooping() && ENG_Utility.hasTimePassed(FrameInterval.SOUND_SHOULD_PLAY_SOUND +
271+ activeSound.getSound().getName() + " " +
272+ activeSound.getPlayId(),
273+ activeSound.getStartTime(),
274+ activeSound.getSound().getDuration())) {
275+// System.out.println("Removing sound that finished playing " + activeSound.getSound().getName() +
276+// " with play id " + activeSound.getPlayId() +
277+// " and priority " + activeSound.getCurrentPriority());
278+ iterator.remove();
279+ }
280+ }
281+ }
282+
283+ private boolean isSoundActive(long playId) {
284+ for (ActiveSound activeSound : activeSounds) {
285+ if (activeSound.getPlayId() == playId) {
286+ return true;
287+ }
288+ }
289+ return false;
290+ }
291+
158292 /**
159293 * Loads a sound into the HashMap and to the SoundPool itself
160- *
161- * @param name Name of the sound to be loaded for a specified path The path
294+ * @param name Name of the sound to be loaded for a specified path The path
162295 * is specified in the class field "path"
296+ * @param duration
297+ * @param priority
163298 */
164- public void loadSound(String name, String filename) {
299+ public void loadSound(String name, String filename, long duration, int priority) {
165300
166301 // throw new UnsupportedOperationException("Must use the id version");
167302
@@ -169,7 +304,7 @@
169304 if (IGNORE_SOUND) {
170305 return;
171306 }
172- sounds.put(name, new SoundInternal(Gdx.audio.newSound(Gdx.files.local(filename))));
307+ sounds.put(name, new SoundInternal(name, Gdx.audio.newSound(Gdx.files.local(filename)), duration, priority));
173308 }
174309
175310 public void loadSound(String name, int handle) {
@@ -196,7 +331,7 @@
196331 // player.pause(sound.soundID);
197332 // sound.soundID.
198333 // throw new UnsupportedOperationException();
199- sound.soundID.pause();
334+ sound.getSoundID().pause();
200335 }
201336
202337 }
@@ -210,7 +345,7 @@
210345 if (sound == null) {
211346 throw new IllegalArgumentException(name + " is not a valid sound name");
212347 }
213- sound.soundID.pause(id);
348+ sound.getSoundID().pause(id);
214349 }
215350 }
216351
@@ -223,7 +358,7 @@
223358 if (sound == null) {
224359 throw new IllegalArgumentException(name + " is not a valid sound name");
225360 }
226- sound.soundID.resume();
361+ sound.getSoundID().resume();
227362 }
228363 }
229364
@@ -236,7 +371,7 @@
236371 if (sound == null) {
237372 throw new IllegalArgumentException(name + " is not a valid sound name");
238373 }
239- sound.soundID.resume(id);
374+ sound.getSoundID().resume(id);
240375 }
241376 }
242377
@@ -258,7 +393,7 @@
258393 throw new IllegalArgumentException(name + " is not a valid sound name");
259394 }
260395 // player.stop(sound.soundID);
261- sound.soundID.stop();
396+ sound.getSoundID().stop();
262397 }
263398
264399 }
@@ -272,10 +407,24 @@
272407 if (sound == null) {
273408 throw new IllegalArgumentException(name + " is not a valid sound name");
274409 }
275- sound.soundID.stop(id);
410+ for (Iterator<ActiveSound> iterator = activeSounds.iterator(); iterator.hasNext(); ) {
411+ ActiveSound activeSound = iterator.next();
412+ if (activeSound.getPlayId() == id) {
413+ System.out.println("Removing sound by stopping " + activeSound.getSound().getName() +
414+ " with play id " + activeSound.getPlayId() +
415+ " and priority " + activeSound.getCurrentPriority());
416+ iterator.remove();
417+ }
418+ }
419+
420+ stopSound(sound, id);
276421 }
277422 }
278423
424+ private void stopSound(SoundInternal sound, long id) {
425+ sound.getSoundID().stop(id);
426+ }
427+
279428 public void setVolume(String name, long id, int volume, boolean vibrate) {
280429 if (IGNORE_SOUND) {
281430 return;
@@ -288,9 +437,9 @@
288437 float vol = volume * 0.01f;
289438 vol = ENG_Math.clamp(vol, 0.0f, 1.0f);
290439 if (DEBUG) {
291- System.out.println(name + " sound volume: " + volume);
440+ System.out.println(name + " playId " + id + " sound volume: " + volume);
292441 }
293- sound.soundID.setVolume(id, vol);
442+ sound.getSoundID().setVolume(id, vol);
294443 // sound.leftVolume = vol;
295444 // sound.rightVolume = vol;
296445 }
@@ -434,7 +583,7 @@
434583 if (sound == null) {
435584 throw new IllegalArgumentException(name + " is not a valid sound name");
436585 }
437- sound.soundID.dispose();
586+ sound.getSoundID().dispose();
438587 }
439588
440589
@@ -443,20 +592,28 @@
443592 if (IGNORE_SOUND) {
444593 return;
445594 }
595+
596+ // Optimization to no longer pan and set volume for stopped sounds.
597+ removeFinishedSounds();
598+ if (!isSoundActive(id)) {
599+ return;
600+ }
601+
446602 SoundInternal sound = sounds.get(name);
447603 if (sound == null) {
448604 throw new IllegalArgumentException(name + " is not a valid sound name");
449605 }
450606 float vol = volume * 0.01f;
451607 vol = ENG_Math.clamp(vol, 0.0f, 1.0f);
608+ pan = ENG_Math.clamp(pan, -1.0f, 1.0f);
452609 if (DEBUG) {
453- System.out.println(name + " sound volume: " + volume);
610+// System.out.println(name + " playId " + id + " sound volume: " + volume + " pan: " + pan);
454611 }
455612 // sound.soundID.setVolume(id, vol);
456613 // sound.leftVolume = vol;
457614 // sound.rightVolume = vol;
458615 pan = ENG_Math.clamp(pan, -1.0f, 1.0f);
459- sound.soundID.setPan(id, pan, volume);
616+ sound.getSoundID().setPan(id, pan, vol);
460617 }
461618
462619
@@ -466,7 +623,7 @@
466623 return;
467624 }
468625 for (SoundInternal sound : sounds.values()) {
469- sound.soundID.dispose();
626+ sound.getSoundID().dispose();
470627 }
471628 sounds.clear();
472629 }
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/renderer/ENG_Node.java
--- a/core/src/headwayent/hotshotengine/renderer/ENG_Node.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/renderer/ENG_Node.java Sun Apr 25 05:47:27 2021 +0300
@@ -555,7 +555,7 @@
555555
556556 public ENG_Node getChild(String name) {
557557 ENG_Node node = childrenList.get(name);
558- System.out.println("Getting child node: " + name);
558+// System.out.println("Getting child node: " + name);
559559 if (MainActivity.isDebugmode()) {
560560 if (node == null) {
561561 throw new IllegalArgumentException(name + " child node not found");
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/resource/ENG_CompiledSound.java
--- a/core/src/headwayent/hotshotengine/resource/ENG_CompiledSound.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/resource/ENG_CompiledSound.java Sun Apr 25 05:47:27 2021 +0300
@@ -4,13 +4,17 @@
44
55 public String name;
66 public String filename;
7+ public long duration;
8+ public int priority;
79
810 public ENG_CompiledSound() {
911
1012 }
1113
12- public ENG_CompiledSound(String name, String filename) {
14+ public ENG_CompiledSound(String name, String filename, long duration, int priority) {
1315 this.name = name;
1416 this.filename = filename;
17+ this.duration = duration;
18+ this.priority = priority;
1519 }
1620 }
diff -r fc68aa3a9dea -r d41a6a0910f3 core/src/headwayent/hotshotengine/scriptcompiler/ENG_SoundCompiler.java
--- a/core/src/headwayent/hotshotengine/scriptcompiler/ENG_SoundCompiler.java Thu Apr 22 22:16:34 2021 +0300
+++ b/core/src/headwayent/hotshotengine/scriptcompiler/ENG_SoundCompiler.java Sun Apr 25 05:47:27 2021 +0300
@@ -19,7 +19,9 @@
1919 String name = ENG_CompilerUtil.getNextWord(fp0);
2020 String filename = ENG_CompilerUtil.getNextWord(fp0);
2121 if (name != null && filename != null) {
22- list.add(new ENG_CompiledSound(name, filename));
22+ int priority = getInt(fp0);
23+ long duration = getLong(fp0);
24+ list.add(new ENG_CompiledSound(name, filename, duration, priority));
2325 } else {
2426 break;
2527 }
diff -r fc68aa3a9dea -r d41a6a0910f3 desktop/raw/hotshot_gamedata/level_retribution.txt
--- a/desktop/raw/hotshot_gamedata/level_retribution.txt Thu Apr 22 22:16:34 2021 +0300
+++ b/desktop/raw/hotshot_gamedata/level_retribution.txt Sun Apr 25 05:47:27 2021 +0300
@@ -311,7 +311,7 @@
311311 {
312312 none
313313 }
314- delay secs 1200
314+ delay secs 120
315315 spawn
316316 {
317317 obj Defender5
diff -r fc68aa3a9dea -r d41a6a0910f3 desktop/raw/hotshot_gamedata/sound_list.txt
--- a/desktop/raw/hotshot_gamedata/sound_list.txt Thu Apr 22 22:16:34 2021 +0300
+++ b/desktop/raw/hotshot_gamedata/sound_list.txt Sun Apr 25 05:47:27 2021 +0300
@@ -1,58 +1,58 @@
1-beep raw/hotshot_gamedata/sounds/snd_beep.mp3
2-
3-asteroid_explosion0 raw/hotshot_gamedata/sounds/snd_asteroid_explosion0.mp3
4-
5-ship_explosion0 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion0.mp3
6-ship_explosion1 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion1.mp3
7-ship_explosion2 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion2.mp3
8-ship_explosion3 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion3.mp3
9-ship_explosion4 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion4.mp3
10-
11-cargo_ship_explosion0 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion0.mp3
12-cargo_ship_explosion1 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion1.mp3
13-cargo_ship_explosion2 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion2.mp3
14-cargo_ship_explosion3 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion3.mp3
15-cargo_ship_explosion4 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion4.mp3
16-
17-concussion_hit raw/hotshot_gamedata/sounds/snd_missile_hit_concussion.mp3
18-homing_hit raw/hotshot_gamedata/sounds/snd_missile_hit_homing.mp3
19-piranha_hit raw/hotshot_gamedata/sounds/snd_missile_hit_piranha.mp3
20-mega_hit raw/hotshot_gamedata/sounds/snd_missile_hit_mega.mp3
21-laser_hit raw/hotshot_gamedata/sounds/snd_laser_hit.mp3
22-plasma_hit raw/hotshot_gamedata/sounds/snd_plasma_hit.mp3
1+beep raw/hotshot_gamedata/sounds/snd_beep.mp3 0 340
232
24-concussion_launch raw/hotshot_gamedata/sounds/snd_missile_launch_concussion.mp3
25-homing_launch raw/hotshot_gamedata/sounds/snd_missile_launch_homing.mp3
26-piranha_launch raw/hotshot_gamedata/sounds/snd_missile_launch_piranha.mp3
27-mega_launch raw/hotshot_gamedata/sounds/snd_missile_launch_mega.mp3
28-laser_launch raw/hotshot_gamedata/sounds/snd_laser_launch.mp3
29-plasma_launch raw/hotshot_gamedata/sounds/snd_plasma_launch.mp3
30-
31-countermeasures raw/hotshot_gamedata/sounds/snd_countermeasures.mp3
32-
33-afterburner raw/hotshot_gamedata/sounds/snd_afterburner.mp3
34-
35-portal_entering raw/hotshot_gamedata/sounds/snd_portal_entering.mp3
36-portal_exiting raw/hotshot_gamedata/sounds/snd_portal_exiting.mp3
3+asteroid_explosion0 raw/hotshot_gamedata/sounds/snd_asteroid_explosion0.mp3 6 993
374
38-ship_alien0_engine raw/hotshot_gamedata/sounds/snd_ship_alien0.mp3
39-ship_alien1_engine raw/hotshot_gamedata/sounds/snd_ship_alien1.mp3
40-ship_alien2_engine raw/hotshot_gamedata/sounds/snd_ship_alien2.mp3
41-ship_alien3_engine raw/hotshot_gamedata/sounds/snd_ship_alien3.mp3
42-ship_alien4_engine raw/hotshot_gamedata/sounds/snd_ship_alien4.mp3
5+ship_explosion0 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion0.mp3 3 3709
6+ship_explosion1 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion1.mp3 3 3456
7+ship_explosion2 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion2.mp3 3 1944
8+ship_explosion3 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion3.mp3 3 1829
9+ship_explosion4 raw/hotshot_gamedata/sounds/snd_fighter_ship_explosion4.mp3 3 2090
4310
44-ship_human0_engine raw/hotshot_gamedata/sounds/snd_ship_human0.mp3
45-ship_human1_engine raw/hotshot_gamedata/sounds/snd_ship_human1.mp3
46-ship_human2_engine raw/hotshot_gamedata/sounds/snd_ship_human2.mp3
47-ship_human3_engine raw/hotshot_gamedata/sounds/snd_ship_human3.mp3
11+cargo_ship_explosion0 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion0.mp3 2 3096
12+cargo_ship_explosion1 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion1.mp3 2 2952
13+cargo_ship_explosion2 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion2.mp3 2 6984
14+cargo_ship_explosion3 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion3.mp3 2 2560
15+cargo_ship_explosion4 raw/hotshot_gamedata/sounds/snd_cargo_ship_explosion4.mp3 2 2403
4816
49-ship_reloader_engine raw/hotshot_gamedata/sounds/snd_ship_reloader.mp3
17+concussion_hit raw/hotshot_gamedata/sounds/snd_missile_hit_concussion.mp3 4 862
18+homing_hit raw/hotshot_gamedata/sounds/snd_missile_hit_homing.mp3 4 2090
19+piranha_hit raw/hotshot_gamedata/sounds/snd_missile_hit_piranha.mp3 4 1202
20+mega_hit raw/hotshot_gamedata/sounds/snd_missile_hit_mega.mp3 4 9900
21+laser_hit raw/hotshot_gamedata/sounds/snd_laser_hit.mp3 4 1045
22+plasma_hit raw/hotshot_gamedata/sounds/snd_plasma_hit.mp3 4 967
5023
51-ship_alien_big0_engine raw/hotshot_gamedata/sounds/snd_ship_alien_big0.mp3
52-ship_alien_big1_engine raw/hotshot_gamedata/sounds/snd_ship_alien_big1.mp3
24+concussion_launch raw/hotshot_gamedata/sounds/snd_missile_launch_concussion.mp3 1 1080
25+homing_launch raw/hotshot_gamedata/sounds/snd_missile_launch_homing.mp3 1 2168
26+piranha_launch raw/hotshot_gamedata/sounds/snd_missile_launch_piranha.mp3 1 2325
27+mega_launch raw/hotshot_gamedata/sounds/snd_missile_launch_mega.mp3 1 4415
28+laser_launch raw/hotshot_gamedata/sounds/snd_laser_launch.mp3 1 653
29+plasma_launch raw/hotshot_gamedata/sounds/snd_plasma_launch.mp3 1 1541
5330
54-ship_human_big0_engine raw/hotshot_gamedata/sounds/snd_ship_human_big0.mp3
55-ship_human_big1_engine raw/hotshot_gamedata/sounds/snd_ship_human_big1.mp3
56-ship_human_big2_engine raw/hotshot_gamedata/sounds/snd_ship_human_big2.mp3
31+countermeasures raw/hotshot_gamedata/sounds/snd_countermeasures.mp3 0 2325
32+
33+afterburner raw/hotshot_gamedata/sounds/snd_afterburner.mp3 0 4023
34+
35+portal_entering raw/hotshot_gamedata/sounds/snd_portal_entering.mp3 5 6557
36+portal_exiting raw/hotshot_gamedata/sounds/snd_portal_exiting.mp3 5 8986
37+
38+ship_alien0_engine raw/hotshot_gamedata/sounds/snd_ship_alien0.mp3 7 9143
39+ship_alien1_engine raw/hotshot_gamedata/sounds/snd_ship_alien1.mp3 7 3448
40+ship_alien2_engine raw/hotshot_gamedata/sounds/snd_ship_alien2.mp3 7 2795
41+ship_alien3_engine raw/hotshot_gamedata/sounds/snd_ship_alien3.mp3 7 1620
42+ship_alien4_engine raw/hotshot_gamedata/sounds/snd_ship_alien4.mp3 7 1463
43+
44+ship_human0_engine raw/hotshot_gamedata/sounds/snd_ship_human0.mp3 7 1280
45+ship_human1_engine raw/hotshot_gamedata/sounds/snd_ship_human1.mp3 7 3056
46+ship_human2_engine raw/hotshot_gamedata/sounds/snd_ship_human2.mp3 7 2090
47+ship_human3_engine raw/hotshot_gamedata/sounds/snd_ship_human3.mp3 7 9848
48+
49+ship_reloader_engine raw/hotshot_gamedata/sounds/snd_ship_reloader.mp3 7 6818
50+
51+ship_alien_big0_engine raw/hotshot_gamedata/sounds/snd_ship_alien_big0.mp3 7 2299
52+ship_alien_big1_engine raw/hotshot_gamedata/sounds/snd_ship_alien_big1.mp3 7 8882
53+
54+ship_human_big0_engine raw/hotshot_gamedata/sounds/snd_ship_human_big0.mp3 7 9848
55+ship_human_big1_engine raw/hotshot_gamedata/sounds/snd_ship_human_big1.mp3 7 1646
56+ship_human_big2_engine raw/hotshot_gamedata/sounds/snd_ship_human_big2.mp3 7 2717
5757
5858