Browse Source

added syncWith

ncannasse 10 năm trước cách đây
mục cha
commit
2ec86f2553
2 tập tin đã thay đổi với 25 bổ sung0 xóa
  1. 10 0
      hxd/snd/Channel.hx
  2. 15 0
      hxd/snd/Worker.hx

+ 10 - 0
hxd/snd/Channel.hx

@@ -37,6 +37,16 @@ class Channel {
 		}
 	}
 
+	public function syncWith( src : Channel ) {
+		if( w != null ) {
+			playTime = src.playTime;
+			w.send(Sync(id, src.id));
+		}
+		else {
+			position = src.position;
+		}
+	}
+
 	function get_currentTime() {
 		return haxe.Timer.stamp() - playTime;
 	}

+ 15 - 0
hxd/snd/Worker.hx

@@ -13,6 +13,7 @@ private enum Message {
 	FadeEnd( id : Int, uid : Int );
 	Active( b : Bool );
 	StopAll;
+	Sync( dst : Int, src : Int );
 }
 
 private class WorkerChannel extends NativeChannel {
@@ -182,9 +183,23 @@ class Worker extends hxd.Worker<Message> {
 			volume = v;
 		case StopAll:
 			stopAll();
+		case Sync(dst, src):
+			var cdst = cmap.get(dst);
+			var csrc = cmap.get(src);
+			if( cdst == null || csrc == null ) return;
+			moveChannel(cdst, csrc.channel);
+			cdst.syncWith(csrc);
 		}
 	}
 
+	function moveChannel( c : Channel, to : NativeChannelData ) {
+		if( c.channel == null || to == null || c.channel == to )
+			return;
+		c.channel.channels.remove(c);
+		to.channels.push(c);
+		c.channel = to;
+	}
+
 	override function setupMain() {
 		#if flash
 		// make sure that the sounds system is initialized