Jelajahi Sumber

snd.Manager: avoid map alloc every frame

trethaller 6 tahun lalu
induk
melakukan
a21cf7aa92
2 mengubah file dengan 8 tambahan dan 7 penghapusan
  1. 5 5
      hxd/snd/Manager.hx
  2. 3 2
      hxd/snd/SoundGroup.hx

+ 5 - 5
hxd/snd/Manager.hx

@@ -383,19 +383,19 @@ class Manager {
 		// virtualize sounds that puts the put the audible count over the maximum number of sources
 		// virtualize sounds that puts the put the audible count over the maximum number of sources
 		// --------------------------------------------------------------------
 		// --------------------------------------------------------------------
 
 
-		var sgroupRefs = new Map<SoundGroup, Int>();
 		var audibleCount = 0;
 		var audibleCount = 0;
 		var c = channels;
 		var c = channels;
 		while (c != null && !c.isVirtual) {
 		while (c != null && !c.isVirtual) {
 			if (++audibleCount > sources.length) c.isVirtual = true;
 			if (++audibleCount > sources.length) c.isVirtual = true;
 			else if (c.soundGroup.maxAudible >= 0) {
 			else if (c.soundGroup.maxAudible >= 0) {
-				var sgRefs = sgroupRefs.get(c.soundGroup);
-				if (sgRefs == null) sgRefs = 0;
-				if (++sgRefs > c.soundGroup.maxAudible) {
+				if(c.soundGroup.lastUpdate != now) {
+					c.soundGroup.lastUpdate = now;
+					c.soundGroup.numAudible = 0;
+				}
+				if (++c.soundGroup.numAudible > c.soundGroup.maxAudible) {
 					c.isVirtual = true;
 					c.isVirtual = true;
 					--audibleCount;
 					--audibleCount;
 				}
 				}
-				sgroupRefs.set(c.soundGroup, sgRefs);
 			}
 			}
 			c = c.next;
 			c = c.next;
 		}
 		}

+ 3 - 2
hxd/snd/SoundGroup.hx

@@ -6,8 +6,9 @@ class SoundGroup {
 	public var volume               : Float;
 	public var volume               : Float;
 	public var maxAudible           : Int;
 	public var maxAudible           : Int;
 	public var mono					: Bool;
 	public var mono					: Bool;
-	
-	var numAudible : Int; // only used when maxAudible >= 0
+
+	var numAudible : Int;
+	var lastUpdate : Float;
 
 
 	public function new(name : String) {
 	public function new(name : String) {
 		this.name  = name;
 		this.name  = name;