// Use this for initialization private void Start() { _lastUpdatedState = new PlayerPosition(Time.time, transform.position, -1, GetComponent <Health>().GetCurrentHealth()); _positionChannel = new PlayerPositionStateChannel(this, new TrivialStrategy(), 0.1f); _inputChannel = new InputSequenceEventChannel((a) => { }, new TrivialStrategy()); ClientConnectionManager.Instance.ChannelManager.RegisterChannel((int)RegisteredChannels.PlayerPositionChannel, _positionChannel); ClientConnectionManager.Instance.ChannelManager.RegisterChannel((int)RegisteredChannels.PlayerInputChannel, _inputChannel); GetComponent <Rigidbody> ().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; health = GetComponent <Health>(); }
public void SetupChannels(ChannelManager cm) { _positionChannel = new PlayerPositionStateChannel(this, new TrivialStrategy(), 0.1f); cm.RegisterChannel((int)RegisteredChannels.PlayerPositionChannel, _positionChannel); _positionChannel.StartSending(); _inputChannel = new InputSequenceEventChannel((a) => { foreach (var playerAction in a) { _inputManager.ReceivePlayerAction(playerAction); } }, new TrivialStrategy()); cm.RegisterChannel((int)RegisteredChannels.PlayerInputChannel, _inputChannel); }
public void UpdateStateFromTexture(Texture source, int sourceChannel = 0, StateChannel targetStateChannel = StateChannel.SurfaceHeight, float scale = 1f, float bias = 0f) { Graphics.Blit(_stateTexture, _stateTextureBuffer); Debugger.Instance.Display("StateSource", source); _copyMat.SetTexture("_PrevTex", _stateTextureBuffer); _copyMat.SetTexture("_HTex", source); _copyMat.SetInt("_SrcChannel", sourceChannel); _copyMat.SetInt("_TgtChannel", (int)targetStateChannel); _copyMat.SetFloat("_Scale", scale); _copyMat.SetFloat("_Bias", bias); Graphics.Blit(null, _stateTexture, _copyMat); }
public void AsyncStateChannel() { using AsyncFiber fiber = new AsyncFiber(); string result = null; AutoResetEvent reset = new AutoResetEvent(false); Task Handle(string s) { result = s; reset.Set(); return(Task.CompletedTask); } StateChannel <string> channel = new StateChannel <string>("none"); TimeSpan fromSeconds = TimeSpan.FromSeconds(1); using (IDisposable sub = channel.Subscribe(fiber, Handle)) { Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("none", result); channel.Publish("one"); Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("one", result); } result = null; channel.Publish("two"); Thread.Sleep(100); Assert.IsNull(result); using (IDisposable sub = channel.Subscribe(fiber, Handle)) { Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("two", result); channel.Publish("three"); Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("three", result); } }
public void StateChannelNoInit() { using Fiber fiber = new Fiber(); string result = null; AutoResetEvent reset = new AutoResetEvent(false); void Handle(string s) { result = s; reset.Set(); } StateChannel <string> channel = new StateChannel <string>(); TimeSpan fromSeconds = TimeSpan.FromSeconds(0.1); using (IDisposable sub = channel.Subscribe(fiber, Handle)) { Assert.IsFalse(reset.WaitOne(fromSeconds)); Assert.IsNull(result); channel.Publish("one"); Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("one", result); } result = null; channel.Publish("two"); Thread.Sleep(100); Assert.IsNull(result); using (IDisposable sub = channel.Subscribe(fiber, Handle)) { Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("two", result); channel.Publish("three"); Assert.IsTrue(reset.WaitOne(fromSeconds)); Assert.AreEqual("three", result); } }