public void DuplicateNode()
 {
     GroundSceneCallbacks.AddUpdateLoopCall(() =>
     {
         var obj = Game.PlayerLookAtTargetObject;
         if (obj != null)
         {
             var node = WorldSnapshotReaderWriter.Get().GetNodeById((int)obj.NetworkId, obj.ParentObject);
             if (node != null)
             {
                 var newNode = WorldSnapshot.CreateNodeCopy(node, obj.Transform);
                 if (newNode != null)
                 {
                     editorPlugin.AddUndoCommand(this, new AddUndoCommandEventArgs(new AddWorldSnapshotNodeCommand(newNode)));
                 }
             }
         }
     });
 }
        public void PasteNode()
        {
            GroundSceneCallbacks.AddUpdateLoopCall(() =>
            {
                if (copiedNode != null)
                {
                    var copiedTransform = new Transform(copiedNode.Transform)
                    {
                        Position = cui_hud.GetCursorWorldPosition()
                    };

                    var newNode = WorldSnapshot.CreateNodeCopy(copiedNode, copiedTransform);
                    if (newNode != null)
                    {
                        editorPlugin.AddUndoCommand(this, new AddUndoCommandEventArgs(new AddWorldSnapshotNodeCommand(newNode)));
                    }
                }
            });
        }
 public void RemoveNode()
 {
     if (EnableNodeEditing)
     {
         GroundSceneCallbacks.AddUpdateLoopCall(() =>
         {
             var obj = Game.PlayerLookAtTargetObject;
             if (obj != null)
             {
                 var node = WorldSnapshotReaderWriter.Get().GetNodeById((int)obj.NetworkId, obj.ParentObject);
                 if (node != null)
                 {
                     editorPlugin.AddUndoCommand(this, new AddUndoCommandEventArgs(new RemoveWorldSnapshotNodeCommand(node)));
                     WorldSnapshot.RemoveNode(node);
                 }
             }
         });
     }
 }
예제 #4
0
        private void ConvertDragDropObjectToWorldSnapshotNode(string objectFilename)
        {
            GroundSceneCallbacks.AddUpdateLoopCall(() =>
            {
                if (!hasValidDragLocation)
                {
                    // Cleanup the temporary DragDrop object
                    CleanUpDragDropObject();
                    return;
                }

                WorldSnapshotReaderWriter.Node node = WorldSnapshot.CreateAddNode(objectFilename, dragDropObject.Transform);

                if (node != null)
                {
                    editorPlugin.AddUndoCommand(this, new AddUndoCommandEventArgs(new AddWorldSnapshotNodeCommand(node)));
                }

                // Cleanup the temporary DragDrop object
                CleanUpDragDropObject();
            });
        }
예제 #5
0
    public void SendWorldSnapshot(WorldSnapshot WorldSnapshot)
    {
        PacketBuffer buffer = new PacketBuffer();

        buffer.WriteInt32((int)ServerPackets.SWorldSnapshot);

        buffer.WriteInt64(WorldSnapshot.createTime);
        buffer.WriteInt32(WorldSnapshot.RoundNumber);
        buffer.WriteInt32(WorldSnapshot.TankData.Count);
        foreach (var Tank in WorldSnapshot.TankData)
        {
            buffer.WriteVector3(Tank.Position);
            buffer.WriteVector3(Tank.Forward);
            buffer.WriteQuaternion(Tank.Rotation);
            buffer.WriteVector3(Tank.Velocity);

            buffer.WriteFloat(Tank.Health);
            buffer.WriteBoolean(Tank.Dead);
            buffer.WriteFloat(Tank.Speed);
            buffer.WriteFloat(Tank.TurnSpeed);
            buffer.WriteInt32(Tank.Wins);

            buffer.WriteFloat(Tank.Inputs.Movement);
            buffer.WriteFloat(Tank.Inputs.Rotating);

            buffer.WriteInt32(Tank.index);
        }

        for (int i = 0; i < _clients.Length; i++)
        {
            if (_clients[i].Socket != null)
            {
                SendDataTo(i, buffer.ToArray());
            }
        }

        buffer.Dispose();
    }
예제 #6
0
        private void SetRotation(Transform transform)
        {
            GroundSceneCallbacks.AddUpdateLoopCall(() =>
            {
                var obj = Network.GetObjectById(nodeCopy.Id);
                obj.Transform.CopyRotation(transform);

                WorldSnapshotReaderWriter.Node node;
                if (nodeCopy.ParentId > 0)
                {
                    node = nodeCopy.ParentNode.GetChildById(nodeCopy.Id);
                }
                else
                {
                    node = WorldSnapshotReaderWriter.Get().GetNodeById(nodeCopy.Id);
                }

                obj.PositionAndRotationChanged(false, node.Transform.Position);
                node.Transform.CopyRotation(transform);

                WorldSnapshot.DetailLevelChanged();
            });
        }
예제 #7
0
        public override void Update(float deltaTime)
        {
            if (AOSClient.Instance != null)
            {
                if (snapshotComponent == null)
                {
                    snapshotComponent = AOSClient.Instance.GetComponent <SnapshotNetComponent>();
                }

                WorldSnapshot worldSnapshot = snapshotComponent.WorldSnapshot;

                if (worldSnapshot != null)
                {
                    foreach (NetworkPlayer player in netPlayerComponent.NetPlayers)
                    {
                        if (player.Team == Team.None)
                        {
                            continue;
                        }

                        PlayerFrame frame;
                        if (playerFrames.TryGetValue(player.Id, out frame))
                        {
                            if (frame.Parent == teamAFrame && player.Team == Team.B ||
                                frame.Parent == teamBFrame && player.Team == Team.A)
                            {
                                RemovePlayer(frame);
                                AddPlayer(player);
                            }
                        }
                    }

                    int totalAScore = 0, totalBScore = 0;

                    foreach (NetworkPlayer player in netPlayerComponent.NetPlayers)
                    {
                        if (player.Team == Team.None)
                        {
                            continue;
                        }

                        if (player.Team == Team.A)
                        {
                            totalAScore += player.Score;
                        }
                        if (player.Team == Team.B)
                        {
                            totalBScore += player.Score;
                        }

                        PlayerFrame frame;
                        if (playerFrames.TryGetValue(player.Id, out frame))
                        {
                            frame.SetScore(player.Score);
                            frame.SetName(player.Name);
                            frame.SetPing(player.Ping);
                        }
                        else
                        {
                            AddPlayer(player);
                        }
                    }

                    foreach (PlayerFrame frame in playerFrames.Values)
                    {
                        if (!netPlayerComponent.HasNetPlayer(frame.NetPlayer.Id))
                        {
                            RemovePlayer(frame);
                            break;
                        }
                    }

                    AlignAndSortLists();
                    UpdatePrimaryScores(totalAScore, totalBScore);
                }

                gamemodeLabel.Text = string.Format("Current Gamemode: {0}",
                                                   gamemode != null ? gamemode.Type.ToString() : "--");
            }

            base.Update(deltaTime);
        }
예제 #8
0
 private void SnapshotComponent_OnWorldSnapshotOutbound(object sender, WorldSnapshot e)
 {
 }
예제 #9
0
 void SnapshotComponent_OnWorldSnapshotInbound(object sender, WorldSnapshot e)
 {
     // Synchronize the time of day
     TimeOfDay = e.Time;
 }
예제 #10
0
        void Update()
        {
            if (!string.IsNullOrEmpty(_socket.Error))
            {
                Debug.LogWarning(_socket.Error);
                Start();
                return;
            }

            Profiler.BeginSample("socket.recv");
            byte[] data = _socket.Recv();
            Profiler.EndSample();

            if (data == null || data.Length == 0)
            {
                return;
            }

            if (_state == ConnectionState.UNKNOWN)
            {
                _state = ConnectionState.CONNECTED;
            }

            if (data.Length < 4)
            {
                Debug.Log("partial message!");
                _storeAddPartial(data);
            }

            if (_partial_message != null)
            {
                Debug.Log("reconstructing partial message!");
                data             = ArrayUtil.sumArrays(_partial_message, data);
                _partial_message = null;
            }

            int messageLen = BitConverter.ToInt32(data, 0);
            int realLen    = data.Length - 5;

            if (realLen < messageLen)
            {
                _storeAddPartial(data);
                return;
            }
            else if (realLen > messageLen)
            {
                Debug.LogError("AHAHAH");
                return;
            }

            if (data[4] == DebugPackage.ID)
            {
                var dm = new DebugPackage(data);
                Debug.Log("debug message from: " + dm.sender + "::" + dm.message);
            }

            if (_state == ConnectionState.CONNECTED)
            {
                if (data[4] == Welcome.ID)
                {
                    _game.showWelcomeData(new Welcome(data));
                    _state = ConnectionState.WELCOMED;
                }
                else
                {
                    Debug.LogError("expected welcome, got :" + data[4].ToString() + " instead");
                    return;
                }
            }
            else if (_state == ConnectionState.AUTHORIZING)
            {
                if (data[4] == ResponseEnterWorld.ID)
                {
                    var res = new ResponseEnterWorld(data);
                    if (res.status == EnterWorldStatus.ENTER_SUCCESS)
                    {
                        Debug.Log("authorize success at world " + _lastWorldAttempt +
                                  " with name " + _lastNameAttempt + "::" + res.myId.ToString());
                        _state = ConnectionState.AUTHORIZED;
                        _game.rememberMe(_lastNameAttempt, res.myId, _lastWorldAttempt);
                    }
                    else
                    {
                        Debug.Log("authorize failed!");
                        _game.showWelcomeData();
                        _state = ConnectionState.WELCOMED;
                    }
                }
                else
                {
                    Debug.LogError("expected auth response or new seed, got :" + data[4].ToString() + " instead");
                    return;
                }
            }
            else if (_state == ConnectionState.AUTHORIZED)
            {
                if (data[4] == WorldData.ID)
                {
                    Debug.Log("world data received!");
                    var wData = new WorldData(data);
                    _game.initializeWorld(wData);
                    _state = ConnectionState.IN_WORLD;

                    _socket.Send(new DebugPackage(_game.myName, "привет друзья").encode());
                }
                else
                {
                    Debug.LogError("expected world data, got :" + data[4].ToString() + " instead");
                    return;
                }
            }
            else if (_state == ConnectionState.IN_WORLD)
            {
                if (data[4] == WorldSnapshot.ID)
                {
                    Profiler.BeginSample("recv.snapshot");
//                    Debug.Log("snapshot received!");
                    Profiler.BeginSample("unpack snapshot");
                    var snap = new WorldSnapshot(data);
                    Profiler.EndSample();

                    Profiler.BeginSample("decode snapshot");
                    var s = new byte[snap.snapshot.Length];
                    for (int i = 0; i < snap.snapshot.Length; i++)
                    {
                        s[i] = (byte.Parse(snap.snapshot[i].ToString()));
                    }
                    Profiler.EndSample();

                    Profiler.BeginSample("push snapshot");
                    _game.pushSnapshot(s);
                    Profiler.EndSample();
                    Profiler.EndSample();
                }
                else
                if (data[4] == NewSeed.ID)
                {
                    Debug.Log("new seed received ");
                    var seed = new NewSeed(data);
                    _game.pushSeed(seed.location, seed.owner);
                }
                else
                if (data[4] == SeedDestroyed.ID)
                {
                    var seedD = new SeedDestroyed(data);
                    Debug.Log("seed dest: " + seedD.location);
                    _game.destroySeed(seedD.location);
                }
                else
                if (data[4] == DeployBomb.ID)
                {
                    var enemy_bomb = new DeployBomb(data);
                    Debug.Log("enemy bomb: " + enemy_bomb.target);
                    _game.pushBomb(enemy_bomb.target);
                }
            }
        }
 public NetConnectionSnapshotState(SnapshotSystem snapshotSystem, NetConnection conn)
 {
     WorldSnapshot = new WorldSnapshot(snapshotSystem, conn);
     Connection    = conn;
     Stats         = new SnapshotStats();
 }
        void SendSnapshotTo(NetConnection conn, NetConnectionSnapshotState connState, float deltaTime)
        {
            WorldSnapshot worldSnapshot = connState.WorldSnapshot;

            ushort epid = connState.OutboundSnapshotId;

            connState.OutboundSnapshotId++;

            //connState.TimeSinceLastSend -= deltaTime;
            //connState.GotPacket = false;

            connState.WorldSnapshot.MaxClientTickrate  = DashCMD.GetCVar <ushort>("ag_max_cl_tickrate");
            connState.WorldSnapshot.ForceSnapshotAwait = DashCMD.GetCVar <bool>("ag_cl_force_await_snap");

            NetOutboundPacket packet = new NetOutboundPacket(NetDeliveryMethod.Unreliable);

            packet.SendImmediately = true;
            int size = packet.Length;

            packet.Write((byte)CustomPacketType.Snapshot);
            packet.Write(epid);
            int _packetheader = packet.Length - size; size = packet.Length;

            // Write snapshot system data
            snapshotSystem.OnOutbound(packet, conn);
            int _acks = packet.Length - size; size = packet.Length;

            // Write players
            charSnapshotSystem.OnServerOutbound(packet, connState);

            // Invoke event
            if (OnWorldSnapshotOutbound != null)
            {
                OnWorldSnapshotOutbound(this, worldSnapshot);
            }

            // Serialize snapshot
            NetBuffer buffer = new NetBuffer();

            worldSnapshot.Serialize(buffer);

            packet.Write((ushort)buffer.Length);
            packet.WriteBytes(buffer.Data, 0, buffer.Length);


            int _playerdata  = packet.Length - size; size = packet.Length;
            int _terraindata = connState.WorldSnapshot.TerrainSnapshot.LastByteSize;

            _playerdata -= _terraindata;

            // Send packet
            conn.SendPacket(packet);

            if (connState != null)
            {
                SnapshotStats stats = connState.Stats;
                stats.PacketHeader = _packetheader;
                stats.Acks         = _acks;
                stats.PlayerData   = _playerdata;
                stats.TerrainData  = _terraindata;
            }
        }
예제 #13
0
        public override void OnConnected(NetConnection connection)
        {
            WorldSnapshot = new WorldSnapshot(snapshotSystem, connection, true);

            base.OnConnected(connection);
        }
예제 #14
0
 void Server_OnWorldSnapshotOutbound(object sender, WorldSnapshot e)
 {
     e.Time = timeOfDay;
 }