浏览代码

snd.Manager: avoid map alloc every frame

trethaller 6 年之前
父节点
当前提交
a21cf7aa92
共有 2 个文件被更改,包括 8 次插入7 次删除
  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
 		// --------------------------------------------------------------------
 
-		var sgroupRefs = new Map<SoundGroup, Int>();
 		var audibleCount = 0;
 		var c = channels;
 		while (c != null && !c.isVirtual) {
 			if (++audibleCount > sources.length) c.isVirtual = true;
 			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;
 					--audibleCount;
 				}
-				sgroupRefs.set(c.soundGroup, sgRefs);
 			}
 			c = c.next;
 		}

+ 3 - 2
hxd/snd/SoundGroup.hx

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