• 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ón38c1f0b78e472f0d067f947b699c9d783c04c43f (tree)
Tiempo2021-04-25 15:57:29
Autorsebastian_bugiu
Commitersebastian_bugiu

Log Message

Added getDuration for sounds.

Cambiar Resumen

Diferencia incremental

diff -r d41a6a0910f3 -r 38c1f0b78e47 core/src/headwayent/blackholedarksun/world/WorldManager.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManager.java Sun Apr 25 05:47:27 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManager.java Sun Apr 25 09:57:29 2021 +0300
@@ -598,6 +598,8 @@
598598 return;
599599 }
600600 lastSoundUpdateTime = currentTime;
601+// System.out.println("updateSounds()");
602+// System.gc();
601603 Entity playerShip = getShip(getPlayerShipEntityId());
602604 if (playerShip != null) {
603605 EntityProperties playerShipEntityProperties = entityPropertiesComponentMapper.get(playerShip);
@@ -612,7 +614,8 @@
612614 ArrayList<Sound> soundsToBeDeleted = new ArrayList<>();
613615 for (Sound snd : entry.getValue()) {
614616 int volume = (int) ((ENG_SoundManager.MAX_SOUND_VOLUME - (int) (distance / snd.maxDistance * 100.0f)) * snd.volumeMultiplier);
615- if ((!snd.loop && ENG_Utility.hasTimePassed(snd.beginTime, SOUND_LIFETIME))
617+ // You cannot have a looping sound that also has a beginTime.
618+ if ((!snd.loop && ENG_Utility.hasTimePassed(snd.beginTime, snd.duration))
616619 || (snd.stopSound) || (snd.startOnProximity && volume <= 0 && snd.started)) {
617620 sound.stopSound(snd.name, snd.id);
618621 if (snd.startOnProximity && snd.started) {
@@ -695,6 +698,7 @@
695698
696699 public Sound playSoundBasedOnDistance(ENG_SceneNode listeningNode, ENG_Playable playable,
697700 String soundName, boolean loop, boolean startOnProximity) {
701+ ENG_ISoundRoot soundRoot = MainApp.getGame().getSound();
698702 if (startOnProximity) {
699703 // Do not start the sound unless in close proximity of the ship
700704 ArrayList<Sound> list = currentPlayingSounds.get(playable);
@@ -702,21 +706,20 @@
702706 list = new ArrayList<>();
703707 currentPlayingSounds.put(playable, list);
704708 }
705- Sound sound = new Sound(soundName, loop, true, true);
706- list.add(sound);
707- return sound;
709+ Sound snd = new Sound(soundName, loop, true, true, currentTimeMillis(), soundRoot.getSoundDuration(soundName));
710+ list.add(snd);
711+ return snd;
708712 } else {
709713
710714 float distance = playable.getPosition().distance(listeningNode.getPosition());
711715 // if (distance < MAX_SOUND_DISTANCE) {
712- ENG_ISoundRoot sound = MainApp.getGame().getSound();
713716 int volume = ENG_SoundManager.MAX_SOUND_VOLUME - (int) (distance / MAX_SOUND_DISTANCE * 100.0f);
714717 volume = ENG_Math.clamp(volume, 0, ENG_SoundManager.MAX_SOUND_VOLUME);
715718 // if (volume > 0) {
716719 // sound.setVolume(soundName, volume);
717720 // Timer timer = ENG_Utility.createTimerAndStart();
718721 float pan = getSoundPan(listeningNode._getFullTransform(), playable);
719- long id = sound.playSound(soundName, volume, pan, loop ? PlayType.PLAY_LOOP : PlayType.PLAY_ONCE);
722+ long id = soundRoot.playSound(soundName, volume, pan, loop ? PlayType.PLAY_LOOP : PlayType.PLAY_ONCE);
720723 // ENG_Utility.stopTimer(timer, "playSoundBasedOnDistance()");
721724 if (id != -1) {
722725 ArrayList<Sound> list = currentPlayingSounds.get(playable);
@@ -726,9 +729,9 @@
726729 }
727730 Sound snd;
728731 if (!loop) {
729- snd = new Sound(soundName, id, volume, pan, currentTimeMillis());
732+ snd = new Sound(soundName, id, volume, pan, currentTimeMillis(), soundRoot.getSoundDuration(soundName));
730733 } else {
731- snd = new Sound(soundName, id, volume, pan, true);
734+ snd = new Sound(soundName, id, volume, pan, true, currentTimeMillis(), soundRoot.getSoundDuration(soundName));
732735 }
733736 list.add(snd);
734737 return snd;
diff -r d41a6a0910f3 -r 38c1f0b78e47 core/src/headwayent/blackholedarksun/world/WorldManagerBase.java
--- a/core/src/headwayent/blackholedarksun/world/WorldManagerBase.java Sun Apr 25 05:47:27 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/world/WorldManagerBase.java Sun Apr 25 09:57:29 2021 +0300
@@ -80,6 +80,7 @@
8080 public String name;
8181 public long id = -1;
8282 public long beginTime;
83+ public long duration;
8384 public boolean loop;
8485 public boolean stopSound;
8586 public float maxDistance = MAX_SOUND_DISTANCE;
@@ -95,41 +96,46 @@
9596
9697 }
9798
98- public Sound(String name, long id, long beginTime) {
99- this.name = name;
100- this.id = id;
101- this.beginTime = beginTime;
102- }
99+// public Sound(String name, long id, long beginTime) {
100+// this.name = name;
101+// this.id = id;
102+// this.beginTime = beginTime;
103+// }
103104
104- public Sound(String name, long id, boolean loop) {
105- this.name = name;
106- this.id = id;
107- this.loop = loop;
108- }
105+// public Sound(String name, long id, boolean loop) {
106+// this.name = name;
107+// this.id = id;
108+// this.loop = loop;
109+// }
109110
110111 public Sound(String name, /*long id,*/ boolean loop, boolean startOnProximity,
111- boolean doNotDeleteWhenOutOfRange) {
112+ boolean doNotDeleteWhenOutOfRange, long beginTime, long duration) {
112113 this.name = name;
113114 // this.id = id;
114115 this.loop = loop;
115116 this.startOnProximity = startOnProximity;
116117 this.doNotDelete = doNotDeleteWhenOutOfRange;
118+ this.beginTime = beginTime;
119+ this.duration = duration;
117120 }
118121
119- public Sound(String soundName, long id, int volume, float pan, long beginTime) {
122+ public Sound(String soundName, long id, int volume, float pan, long beginTime, long duration) {
120123 this.name = soundName;
121124 this.id = id;
122125 this.volume = volume;
123126 this.pan = pan;
124127 this.beginTime = beginTime;
128+ this.duration = duration;
125129 }
126130
127- public Sound(String soundName, long id, int volume, float pan, boolean loop) {
131+ public Sound(String soundName, long id, int volume, float pan, boolean loop, long beginTime, long duration) {
128132 this.name = soundName;
129133 this.id = id;
130134 this.volume = volume;
131135 this.pan = pan;
132136 this.loop = loop;
137+ this.beginTime = beginTime;
138+ this.duration = duration;
133139 }
134140 }
135141
diff -r d41a6a0910f3 -r 38c1f0b78e47 core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java Sun Apr 25 05:47:27 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_ISoundRoot.java Sun Apr 25 09:57:29 2021 +0300
@@ -127,6 +127,8 @@
127127 // Not possible
128128 // public float getPan(String name, long id);
129129
130+ long getSoundDuration(String name);
131+
130132 /**
131133 * Registers a listener for a particular event. Note that the same listener can
132134 * be registered for multiple events (The event type for which the event has
diff -r d41a6a0910f3 -r 38c1f0b78e47 core/src/headwayent/hotshotengine/audio/ENG_Sound.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_Sound.java Sun Apr 25 05:47:27 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_Sound.java Sun Apr 25 09:57:29 2021 +0300
@@ -103,6 +103,10 @@
103103 }
104104 }
105105
106+ public long getSoundDuration(String name) {
107+ return soundManager.getSoundDuration(name);
108+ }
109+
106110 /**
107111 * Loads a sound into the HashMap and to the SoundPool itself
108112 *
diff -r d41a6a0910f3 -r 38c1f0b78e47 core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java
--- a/core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java Sun Apr 25 05:47:27 2021 +0300
+++ b/core/src/headwayent/hotshotengine/audio/ENG_SoundManager.java Sun Apr 25 09:57:29 2021 +0300
@@ -289,6 +289,14 @@
289289 return false;
290290 }
291291
292+ public long getSoundDuration(String name) {
293+ SoundInternal sound = sounds.get(name);
294+ if (sound == null) {
295+ throw new IllegalArgumentException(name + " is not a valid sound name");
296+ }
297+ return sound.getDuration();
298+ }
299+
292300 /**
293301 * Loads a sound into the HashMap and to the SoundPool itself
294302 * @param name Name of the sound to be loaded for a specified path The path
diff -r d41a6a0910f3 -r 38c1f0b78e47 desktop/raw/robovm.ini
--- a/desktop/raw/robovm.ini Sun Apr 25 05:47:27 2021 +0300
+++ b/desktop/raw/robovm.ini Sun Apr 25 09:57:29 2021 +0300
@@ -1,1 +1,2 @@
1-ms512M
\ No newline at end of file
1+ms256M
2+EnableGCHeapStats
\ No newline at end of file