Ejemplo n.º 1
0
        public void OnPhotonInstantiate(PhotonMessageInfo info)
        {
            object[] instantiationData = info.photonView.InstantiationData;

            NetworkArgs args = null;

            if (instantiationData?.Length > 0)
            {
                args = instantiationData[0] as NetworkArgs;
            }

            object[] remotePlayerArgs = new object[]
            {
                photonView,
                args,
            };

            if (photonView.IsMine)
            {
                _networkSystem.CreateRemotePlayerLocalPlayer(this, remotePlayerArgs);
            }
            else
            {
                _networkSystem.CreatedRemotePlayer(this, remotePlayerArgs);
            }

            _networkSystem.ReceivedRemotePlayerCustomData(this, args);
        }
Ejemplo n.º 2
0
        private void CreatedRemotePlayer(IRemotePlayer remotePlayer, object args)
        {
            PlayerID pid = _infra.ResolvePlayerID(args);

            NetworkArgs nargs = null;

            if (args is object[] argList)
            {
                if (argList.Length >= 2)
                {
                    if (argList[1] is NetworkArgs result)
                    {
                        nargs = result;
                    }
                }
            }

            IAvatar avatar = GetOrCreateAvatar(pid, nargs);

            avatar.SetAvatarController(remotePlayer);

            remotePlayer.PlayerID = pid;
            remotePlayer.OnDestroyingRemotePlayer += HandleRemotePlayerDestroying;

            OnCreatedRemotePlayer?.Invoke(avatar, remotePlayer);
        }
Ejemplo n.º 3
0
        public void AdaptedFriis()
        {
            // arrange
            var comArgs   = new WirelessCommArgs();
            var radioArgs = base.GetRadioArgs();
            var sceneArgs = new InvariantSceneArgs();
            var netArgs   = new NetworkArgs();

            // TODO: add the runtime and secure the existence of needed arguments commArgs and sceneArgs
            var sim = new AdaptedFriisSimulator()
                      .With(radioArgs)                              // own arguments
                      .With(comArgs)                                // additional arguments...
                      .With(sceneArgs)
                      .With(netArgs);                               // false positive

            sim.OnExecuting += (obj, e) =>
            {
                _log.Trace($"{obj} started");
            };

            sim.Executed += (obj, e) =>
            {
                _log.Trace($"{obj} finished");
            };

            // act
            sim.Run();

            // assert
            Assert.IsTrue(radioArgs.RxValues.All(f => f != 0), "float should contain a attenuation");

            radioArgs.RxPositions
            .Zip(radioArgs.RxValues, (a, b) => $"Pos: {a.ToString()} with {b} dBm")
            .ToList();
        }
Ejemplo n.º 4
0
 public void LogChatMessage(object sender, NetworkArgs <ChatMessageData> args)
 {
     if (args.Data == null)
     {
         return;
     }
     print($"{args.Data.PlayerName} send message: {args.Data.Message}");
 }
Ejemplo n.º 5
0
 public void LogPing(object sender, NetworkArgs <bool> args)
 {
     if (!logPing)
     {
         return;
     }
     print("Ping Recieved");
 }
Ejemplo n.º 6
0
 public void AddMessageToArea(object sender, NetworkArgs <ChatMessageData> args)
 {
     if (args.Data == null)
     {
         return;
     }
     ChatArea.AppendTextToNewLine(args.Data.Message);
 }
Ejemplo n.º 7
0
        private IAvatar GetOrCreateAvatar(PlayerID playerID, NetworkArgs args)
        {
            AvatarID avatarID = _infra.GetAvatarID(playerID);

            (IAvatar avatar, IAvatarBody _) = _remoteAvatarBuilder.Build(avatarID, args.BodyType);

            _infra.RegisterAvatar(playerID, avatar.AvatarID);

            return(avatar);
        }
Ejemplo n.º 8
0
 private void RefreshWhenPlayerDataRecieved(object sender, NetworkArgs <PlayerData> e)
 {
     MainThreadHelperService.AddJob(() => {
         try {
             Object.RefreshQuestList(status);
         }
         catch (Exception ex) {
             LOG.Log(ex);
             throw;
         }
     });
 }
Ejemplo n.º 9
0
        void IMultiplayerNetworkSystem.CreateRemotePlayerForLocalPlayer(NetworkArgs args)
        {
            Debug.Log("Will create Remote Player for Local Player.");

            IAvatar avatar = _avatarService.GetMain();

            if (_mainAvatarController == null)
            {
                _mainAvatarController = avatar.AvatarController;
            }

            _infra.RegisterMainAvatar(avatar.AvatarID);
            _infra.CreateRemotePlayer(args);
        }
Ejemplo n.º 10
0
        public async Task RunBatterySimulation()
        {
            // arrange
            var runtime = new RuntimeController(new EnergyValidator());

            // TODO: seem to have a bug when setting up a higher cutoff voltage --> test and fix it
            _battery.CutoffVoltage = 1.2F;
            var s           = _battery.State;
            var batteryArgs = new BatteryArgs();

            batteryArgs.Batteries.Add(_battery);

            var netArgs = new NetworkArgs();
            var device  = new SimpleDevice();

            device.Parts.Add(_battery);
            netArgs.Network.Add(device);

            var batterySim = new BatteryPackSimulator();

            batterySim
            .With(batteryArgs)
            .With(netArgs)
            .With(runtime.Arguments);

            var repo = new SimulatorRepository();

            repo.Add(batterySim);
            if (!runtime.BindSimulators(repo).Validate())
            {
                Assert.Fail("error on validating the simulation");
            }

            // act
            await runtime.RunAsync((rt) =>
            {
                // assert
                return(!_battery.State.IsDepleted);
            });

            Assert.AreNotEqual(s.Initial.ElapsedTime, s.Now.ElapsedTime, "ElapsedTime should not be equal");
            Assert.AreNotEqual(s.Initial.Charge, s.Now.Charge, "Charge should not be equal");
            Assert.AreNotEqual(s.Initial.SoD, s.Now.SoD, "SoD should not be equal");
            Assert.AreNotEqual(s.Initial.Voltage, s.Now.Voltage, "Voltage should not be equal");
            Assert.IsTrue(_battery.State.IsDepleted, "battery should be empty");
        }
Ejemplo n.º 11
0
        private void SetupDemoRepo(RuntimeBase runtime)
        {
            var sceneArgs   = new InvariantSceneArgs();
            var radioArgs   = base.GetRadioArgs();
            var comArgs     = new WirelessCommArgs();
            var netArgs     = new NetworkArgs();
            var antennaArgs = new SimpleAntennaArgs();

            _repo = new SimulatorRepository();
            _repo.AddRange(new ISimulatable[] {
                new SceneSimulator(runtime)
                .With(sceneArgs),
                new AdaptedFriisSimulator(runtime)
                .With(radioArgs)
                .With(comArgs),
                new SimpleAntennaSimulator(runtime)
                .With(antennaArgs),
                new PeerToPeerNetworkSimulator(runtime)
                .With(netArgs),
                new LrwpanSimulator(runtime)
                .With(comArgs)
            });
        }
Ejemplo n.º 12
0
        public async Task RunNetwork()
        {
            // arrange
            var runtime = new RuntimeController(new BasicValidator());


            var netSim  = new PeerToPeerNetworkSimulator(runtime);
            var netArgs = new NetworkArgs();

            netSim.OnExecuting += (o, e) =>
            {
                _network.AssociationMatrix.Each(ApplyAssociations);
            };
            netSim.With(netArgs);
            _network = netArgs.Network;
            _network.AddRange(ImportDevices().First());

            var simRepo = new SimulatorRepository();

            simRepo.Add(netSim);


            var pass      = 0;
            var maxPasses = 3;

            runtime.IterationPassed += (o, e) =>
            {
                pass++;
                if (pass == maxPasses)
                {
                    var dev = netArgs.Network.Items[0];
                    dev.Controls.Off();
                    _log.Trace($"Device '{dev.Name}' was turned off.");
                }
            };
            runtime.BindSimulators(simRepo)
            .Validate();

            // act iterations until availability is below 100%
            await runtime.RunAsync((r) =>
            {
                if (netArgs.Network.Availability() < 1)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            });

            // assert
            Assert.IsTrue(pass >= maxPasses, $"The iterations should be more than {maxPasses}.");
            netArgs.Network.DistanceMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(v > 0, $"position at row '{r}' and col '{c}' should not be '{v}'");
                _log.Trace($"{r}:{c} -> distance: {v}");
                return(v);
            });

            netArgs.Network.AngleMatrix.Each((r, c, v) =>
            {
                Assert.IsTrue(!float.IsNaN(v.Azimuth), $"Azimuth at position at row '{r}' and col '{c}' should not be NaN");
                Assert.IsTrue(!float.IsNaN(v.Elevation), $"Elevation at position at row '{r}' and col '{c}' should not be NaN");
                _log.Trace($"{r}:{c} -> angle: {v}");
                return(v);
            });
        }
Ejemplo n.º 13
0
 public static void FireChatMessageRecievedEvent(NetworkArgs <ChatMessageData> args)
 {
     OnChatMessageRecieved(null, args);
 }
Ejemplo n.º 14
0
 public void LogAreaSync(object sender, NetworkArgs <AreaSyncData> args)
 {
     print("Area sync recieved");
 }
Ejemplo n.º 15
0
 public static void FirePingRecievedEvent(NetworkArgs <bool> args)
 {
     OnPingRecieved(null, args);
 }
Ejemplo n.º 16
0
 public static void FireAreaSyncEvent(NetworkArgs <AreaSyncData> args)
 {
     OnAreaSyncRecieved(null, args);
 }
Ejemplo n.º 17
0
 public static void FirePlayerDataSyncEvent(NetworkArgs <PlayerData> args)
 {
     OnPlayerDataSyncRecieved(null, args);
 }
Ejemplo n.º 18
0
        IRemotePlayer IMultiplayerNetworkInfrastructure.CreateRemotePlayer(NetworkArgs args)
        {
            GameObject remoteGO = PhotonNetwork.Instantiate(_remotePlayerPath, Vector3.zero, Quaternion.identity, 0, new object[] { args });

            return(remoteGO.GetComponent <IRemotePlayer>());
        }
Ejemplo n.º 19
0
 IRemotePlayer IMultiplayerNetworkInfrastructure.CreateRemotePlayer(NetworkArgs args)
 {
     return(null);
 }
Ejemplo n.º 20
0
 public void ReceivedRemotePlayerCustomData(IRemotePlayer remotePlayer, NetworkArgs args)
 {
     OnReceivedRemotePlayerCustomData?.Invoke(remotePlayer, args);
 }