コード例 #1
0
 //This could do with some work
 void SendPositionUpdates()
 {
     foreach (var player in Players)
     {
         var tr = player.Value.GetTransform();
         player.Key.Position    = tr.Transform(Vector3.Zero);
         player.Key.Orientation = tr.ExtractRotation();
     }
     foreach (var player in Players)
     {
         List <PackedShipUpdate> ps = new List <PackedShipUpdate>();
         foreach (var otherPlayer in Players)
         {
             if (otherPlayer.Key == player.Key)
             {
                 continue;
             }
             var update = new PackedShipUpdate();
             update.ID             = otherPlayer.Key.ID;
             update.HasPosition    = true;
             update.Position       = otherPlayer.Key.Position;
             update.HasOrientation = true;
             update.Orientation    = otherPlayer.Key.Orientation;
             ps.Add(update);
         }
         player.Key.SendUpdate(new ObjectUpdatePacket()
         {
             Updates = ps.ToArray()
         });
     }
 }
コード例 #2
0
        void UpdateObject(uint tick, PackedShipUpdate update)
        {
            if (!objects.ContainsKey(update.ID))
            {
                return;
            }
            var obj = objects[update.ID];
            //Component only present in multiplayer
            var netPos = obj.GetComponent <CNetPositionComponent>();

            if (netPos != null)
            {
                if (update.HasPosition)
                {
                    netPos.QueuePosition(tick, update.Position);
                }
                if (update.HasOrientation)
                {
                    netPos.QueueOrientation(tick, update.Orientation);
                }
            }
            else
            {
                var tr  = obj.GetTransform();
                var pos = update.HasPosition ? update.Position : Vector3.Transform(Vector3.Zero, tr);
                var rot = update.HasOrientation ? update.Orientation : tr.ExtractRotation();
                obj.Transform = Matrix4x4.CreateFromQuaternion(rot) * Matrix4x4.CreateTranslation(pos);
            }
        }
コード例 #3
0
        void UpdateObject(PackedShipUpdate update)
        {
            var obj = objects[update.ID];
            var tr  = obj.GetTransform();
            var pos = update.HasPosition ? update.Position : Vector3.Transform(Vector3.Zero, tr);
            var rot = update.HasOrientation ? update.Orientation : tr.ExtractRotation();

            obj.Transform = Matrix4x4.CreateFromQuaternion(rot) * Matrix4x4.CreateTranslation(pos);
        }
コード例 #4
0
ファイル: Packets.cs プロジェクト: Regenhardt/Librelancer
        public static PackedShipUpdate ReadFrom(ref BitReader message)
        {
            var p = new PackedShipUpdate();

            p.ID     = (int)message.GetUInt(32);
            p.Hidden = message.GetBool();
            if (p.Hidden)
            {
                return(p);
            }
            p.CruiseThrust   = (CruiseThrustState)message.GetUInt(2);
            p.HasPosition    = message.GetBool();
            p.HasOrientation = message.GetBool();
            p.HasHealth      = message.GetBool();
            p.HasGuns        = message.GetBool();
            p.DockingLights  = message.GetBool();
            if (p.HasPosition)
            {
                p.Position          = message.GetVector3();
                p.EngineThrottlePct = message.GetByte();
            }
            if (p.HasOrientation)
            {
                p.Orientation = message.GetQuaternion();
            }
            if (p.HasHealth)
            {
                p.HasShield = message.GetBool();
                p.HasHull   = message.GetBool();
                p.HasParts  = message.GetBool();
                if (p.HasParts)
                {
                    p.Parts = new byte[message.GetByte()];
                    for (int i = 0; i < p.Parts.Length; i++)
                    {
                        p.Parts[i] = (byte)message.GetUInt(3);
                    }
                }
                if (p.HasShield)
                {
                    p.ShieldHp = message.GetFloat();
                }
                if (p.HasHull)
                {
                    p.HullHp = message.GetInt();
                }
            }
            if (p.HasGuns)
            {
                p.GunOrients = new GunOrient[message.GetByte()];
                for (int i = 0; i < p.GunOrients.Length; i++)
                {
                    p.GunOrients[i].ReadIn(ref message);
                }
            }
            return(p);
        }
コード例 #5
0
        public static object Read(NetIncomingMessage message)
        {
            var p = new ObjectUpdatePacket();

            p.Updates = new PackedShipUpdate[message.ReadVariableUInt32()];
            for (int i = 0; i < p.Updates.Length; i++)
            {
                p.Updates[i] = PackedShipUpdate.ReadFrom(message);
            }
            return(p);
        }
コード例 #6
0
        //This could do with some work
        void SendPositionUpdates(bool mp, uint tick)
        {
            foreach (var player in Players)
            {
                var tr = player.Value.GetTransform();
                player.Key.Position    = Vector3.Transform(Vector3.Zero, tr);
                player.Key.Orientation = tr.ExtractRotation();
            }
            IEnumerable <Player> targets;

            if (mp)
            {
                targets = Players.Keys.Where(x => x.Client is RemotePacketClient);
            }
            else
            {
                targets = Players.Keys.Where(x => x.Client is LocalPacketClient);
            }
            foreach (var player in targets)
            {
                List <PackedShipUpdate> ps = new List <PackedShipUpdate>();
                foreach (var otherPlayer in Players.Keys)
                {
                    if (otherPlayer == player)
                    {
                        continue;
                    }
                    var update = new PackedShipUpdate();
                    update.ID             = otherPlayer.ID;
                    update.HasPosition    = true;
                    update.Position       = otherPlayer.Position;
                    update.HasOrientation = true;
                    update.Orientation    = otherPlayer.Orientation;
                    ps.Add(update);
                }
                foreach (var obj in updatingObjects)
                {
                    var update = new PackedShipUpdate();
                    update.ID          = obj.NetID;
                    update.HasPosition = true;
                    var tr = obj.GetTransform();
                    update.Position       = Vector3.Transform(Vector3.Zero, tr);
                    update.HasOrientation = true;
                    update.Orientation    = tr.ExtractRotation();
                    ps.Add(update);
                }
                player.SendUpdate(new ObjectUpdatePacket()
                {
                    Tick    = tick,
                    Updates = ps.ToArray()
                });
            }
        }
コード例 #7
0
        public static object Read(NetPacketReader message)
        {
            var p = new ObjectUpdatePacket();

            p.Tick = message.GetUInt();
            var pack        = new BitReader(message.GetRemainingBytes(), 0);
            var updateCount = pack.GetUInt(8);

            p.Updates = new PackedShipUpdate[updateCount];
            for (int i = 0; i < p.Updates.Length; i++)
            {
                p.Updates[i] = PackedShipUpdate.ReadFrom(ref pack);
            }
            return(p);
        }
コード例 #8
0
        public static PackedShipUpdate ReadFrom(NetIncomingMessage message)
        {
            var p = new PackedShipUpdate();

            p.ID     = message.ReadInt32();
            p.Hidden = message.ReadBoolean();
            if (p.Hidden)
            {
                message.ReadPadBits();
                return(p);
            }
            p.CruiseThrust   = (CruiseThrustState)message.ReadRangedInteger(0, 3);
            p.HasPosition    = message.ReadBoolean();
            p.HasOrientation = message.ReadBoolean();
            p.HasHealth      = message.ReadBoolean();
            p.HasGuns        = message.ReadBoolean();
            p.DockingLights  = message.ReadBoolean();
            if (p.HasPosition)
            {
                p.Position          = message.ReadVector3();
                p.EngineThrottlePct = message.ReadByte();
            }
            if (p.HasOrientation)
            {
                p.Orientation = message.ReadQuaternion();
            }
            if (p.CruiseThrust == CruiseThrustState.CruiseCharging)
            {
                p.CruiseChargePct = message.ReadByte();
            }
            if (p.HasHealth)
            {
                p.HasShield = message.ReadBoolean();
                p.HasHull   = message.ReadBoolean();
                p.HasParts  = message.ReadBoolean();
                if (p.HasParts)
                {
                    p.Parts = new byte[message.ReadByte()];
                    for (int i = 0; i < p.Parts.Length; i++)
                    {
                        p.Parts[i] = (byte)message.ReadRangedInteger(0, 7); //3 bits
                    }
                    message.ReadPadBits();
                }
                if (p.HasShield)
                {
                    p.ShieldHp = message.ReadInt32();
                }
                if (p.HasHull)
                {
                    p.HullHp = message.ReadInt32();
                }
            }
            if (p.HasGuns)
            {
                p.GunOrients = new GunOrient[message.ReadByte()];
                for (int i = 0; i < p.GunOrients.Length; i++)
                {
                    p.GunOrients[i].ReadIn(message);
                }
            }
            return(p);
        }
コード例 #9
0
ファイル: ServerWorld.cs プロジェクト: Regenhardt/Librelancer
        //This could do with some work
        void SendPositionUpdates(bool mp, uint tick)
        {
            foreach (var player in Players)
            {
                var tr = player.Value.WorldTransform;
                player.Key.Position    = Vector3.Transform(Vector3.Zero, tr);
                player.Key.Orientation = tr.ExtractRotation();
            }
            IEnumerable <KeyValuePair <Player, GameObject> > targets;

            if (mp)
            {
                targets = Players.Where(x => x.Key.Client is RemotePacketClient);
            }
            else
            {
                targets = Players.Where(x => x.Key.Client is LocalPacketClient);
            }
            foreach (var player in targets)
            {
                List <PackedShipUpdate> ps = new List <PackedShipUpdate>();
                var phealthcomponent       = player.Value.GetComponent <SHealthComponent>();
                var phealth = phealthcomponent.CurrentHealth;
                var pshield = phealthcomponent.ShieldHealth;

                foreach (var otherPlayer in Players)
                {
                    if (otherPlayer.Key == player.Key)
                    {
                        continue;
                    }
                    var update = new PackedShipUpdate();
                    update.ID                = otherPlayer.Key.ID;
                    update.HasPosition       = true;
                    update.Position          = otherPlayer.Key.Position;
                    update.EngineThrottlePct = (byte)(otherPlayer.Value.GetComponent <SEngineComponent>().Speed * 255f);
                    update.HasOrientation    = true;
                    update.Orientation       = otherPlayer.Key.Orientation;
                    update.HasHealth         = true;
                    update.HasHull           = true;
                    update.HasShield         = true;
                    var ohealth = otherPlayer.Value.GetComponent <SHealthComponent>();
                    update.HullHp   = (int)(ohealth.CurrentHealth);
                    update.ShieldHp = ohealth.ShieldHealth;
                    ps.Add(update);
                }
                foreach (var obj in updatingObjects)
                {
                    var update = new PackedShipUpdate();
                    update.ID          = obj.NetID;
                    update.HasPosition = true;
                    var tr = obj.WorldTransform;
                    update.Position = Vector3.Transform(Vector3.Zero, tr);
                    if (obj.TryGetComponent <SEngineComponent>(out var engine))
                    {
                        update.EngineThrottlePct = (byte)(engine.Speed * 255f);
                    }
                    update.HasOrientation = true;
                    update.Orientation    = tr.ExtractRotation();
                    if (obj.TryGetComponent <SHealthComponent>(out var health))
                    {
                        update.HasHealth = true;
                        update.HasHull   = true;
                        update.HasShield = true;
                        update.HullHp    = (int)health.CurrentHealth;
                        update.ShieldHp  = health.ShieldHealth;
                    }
                    if (obj.TryGetComponent <WeaponControlComponent>(out var weapons))
                    {
                        update.HasGuns    = true;
                        update.GunOrients = weapons.GetRotations();
                    }
                    ps.Add(update);
                }
                player.Key.SendUpdate(new ObjectUpdatePacket()
                {
                    Tick         = tick,
                    PlayerHealth = phealth,
                    PlayerShield = pshield,
                    Updates      = ps.ToArray()
                });
            }
        }