ReadFloat() публичный Метод

4字节读出
public ReadFloat ( ) : float
Результат float
Пример #1
0
        public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
        {
            int eventIndex     = msg.ReadRangedInteger(0, (int)Math.Ceiling(MaxNodeCount / (float)MaxNodesPerNetworkEvent));
            int nodeCount      = msg.ReadRangedInteger(0, MaxNodesPerNetworkEvent);
            int nodeStartIndex = eventIndex * MaxNodesPerNetworkEvent;

            Vector2[] nodePositions = new Vector2[nodeStartIndex + nodeCount];
            for (int i = 0; i < nodes.Count && i < nodePositions.Length; i++)
            {
                nodePositions[i] = nodes[i];
            }

            for (int i = 0; i < nodeCount; i++)
            {
                nodePositions[nodeStartIndex + i] = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (nodePositions.Any(n => !MathUtils.IsValid(n)))
            {
                nodes.Clear();
                return;
            }

            nodes = nodePositions.ToList();
            UpdateSections();
            Drawable = nodes.Any();
        }
Пример #2
0
        void R_RolledBackServerPlayer(NetConnection server, NetBuffer data, ushort numArgs)
        {
            Vector3 origin = new Vector3(data.ReadFloat(), data.ReadFloat(), data.ReadFloat());
            Team    team   = (Team)data.ReadByte();

            debugRenderer.AddPlayerRollback(origin, team == Team.A ? TeamAColor : TeamBColor);
        }
Пример #3
0
 /// <inheritdoc />
 public void ReadFromBuffer(NetBuffer buffer)
 {
     Id   = new Guid(buffer.ReadBytes(16));
     Type = (GamePieceType)buffer.ReadByte();
     X    = buffer.ReadFloat();
     Y    = buffer.ReadFloat();
 }
Пример #4
0
        public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
        {
            var newTargetPosition = new Vector2(
                msg.ReadFloat(),
                msg.ReadFloat());

            //already interpolating with more up-to-date data -> ignore
            if (subBody.MemPos.Count > 1 && subBody.MemPos[0].Timestamp > sendingTime)
            {
                return;
            }

            int index = 0;

            while (index < subBody.MemPos.Count && sendingTime > subBody.MemPos[index].Timestamp)
            {
                index++;
            }

            //position with the same timestamp already in the buffer (duplicate packet?)
            //  -> no need to add again
            if (index < subBody.MemPos.Count && sendingTime == subBody.MemPos[index].Timestamp)
            {
                return;
            }

            subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, 0.0f, sendingTime));
        }
Пример #5
0
        public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
        {
            bool    shouldBeAttached = msg.ReadBoolean();
            Vector2 simPosition      = new Vector2(msg.ReadFloat(), msg.ReadFloat());

            if (!attachable)
            {
                DebugConsole.ThrowError("Received an attachment event for item: " + item.Name.ToString() + " that's not attachable.");
                return;
            }

            if (shouldBeAttached)
            {
                Drop(false, null);
                item.SetTransform(simPosition, 0.0f);
                AttachToWall();
            }
            else
            {
                if (attached)
                {
                    DropConnectedWires(null);

                    if (body != null)
                    {
                        item.body         = body;
                        item.body.Enabled = true;
                    }
                    IsActive = false;

                    DeattachFromWall();
                }
            }
        }
Пример #6
0
 public static Quaternion ReadQuaternion(this NetBuffer buf)
 {
     return(new Quaternion(
                buf.ReadFloat(),
                buf.ReadFloat(),
                buf.ReadFloat(),
                buf.ReadFloat()));
 }
Пример #7
0
 public static Color ReadColor(this NetBuffer buf, bool alpha)
 {
     return(new Color(
                buf.ReadFloat(),
                buf.ReadFloat(),
                buf.ReadFloat(),
                alpha ? buf.ReadFloat() : 1));
 }
Пример #8
0
        public static Tile Unpack(NetBuffer netBuffer)
        {
            // check for a null tile
            if (netBuffer.ReadBoolean() == false)
            {
                return(null);
            }


            // Check for blank tile?
            if (netBuffer.ReadBoolean())
            {
                return(new Tile());
            }
            else
            {
                var animated    = netBuffer.ReadBoolean();
                var lightSource = netBuffer.ReadBoolean();
                var lightRadius = netBuffer.ReadInt32();
                var lightColor  = new Color(new Vector4(netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte(),
                                                        netBuffer.ReadByte()));
                var teleporter = netBuffer.ReadBoolean();

                var tilesetPath = Constants.FILEPATH_DATA + netBuffer.ReadString();

                var sprite = Client.ServiceLocator.GetService <ContentManagerService>().ContentManager
                             .LoadTexture2D(tilesetPath);

                Color color = new Color(new Vector4(netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte(),
                                                    netBuffer.ReadByte()));
                Rectangle sourceRectangle = new Rectangle(netBuffer.ReadInt32(), netBuffer.ReadInt32(),
                                                          netBuffer.ReadInt32(), netBuffer.ReadInt32());
                Vector2 position = new Vector2(netBuffer.ReadFloat(), netBuffer.ReadFloat());

                var frameCount = netBuffer.ReadInt32();

                var tile = new Tile(sprite, sourceRectangle, position)
                {
                    Animated    = animated,
                    LightSource = lightSource,
                    Teleporter  = teleporter,
                    Color       = color,
                    FrameCount  = frameCount,
                };

                if (lightSource)
                {
                    PointLight pointLight = new PointLight();
                    pointLight.Color    = lightColor;
                    pointLight.Radius   = lightRadius;
                    pointLight.Position = new Vector2(position.X - (lightRadius / 2f) + (EngineConstants.TILE_WIDTH / 2f),
                                                      position.Y - (lightRadius / 2f) + (EngineConstants.TILE_HEIGHT / 2f));
                    Client.ServiceLocator.GetService <LightManagerService>().Component.Lights.Add(pointLight);
                }

                return(tile);
            }
        }
Пример #9
0
 public PlayerData(NetBuffer msg) : this()
 {
     ID        = msg.ReadUInt64();
     Position  = new Vec2(msg.ReadFloat(), msg.ReadFloat());
     Type      = (ChampionTypes)msg.ReadByte();
     Team      = msg.ReadBoolean() ? Teams.Left : Teams.Right;
     MaxHealth = msg.ReadFloat();
     Health    = msg.ReadFloat();
 }
Пример #10
0
        public PosInfo ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime, string parentDebugName)
        {
            float MaxVel        = NetConfig.MaxPhysicsBodyVelocity;
            float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity;

            Vector2 newPosition        = SimPosition;
            float?  newRotation        = null;
            bool    awake              = body.Awake;
            Vector2 newVelocity        = LinearVelocity;
            float?  newAngularVelocity = null;

            newPosition = new Vector2(
                msg.ReadFloat(),
                msg.ReadFloat());

            awake = msg.ReadBoolean();
            bool fixedRotation = msg.ReadBoolean();

            if (!fixedRotation)
            {
                newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 8);
            }
            if (awake)
            {
                newVelocity = new Vector2(
                    msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
                    msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
                newVelocity = NetConfig.Quantize(newVelocity, -MaxVel, MaxVel, 12);

                if (!fixedRotation)
                {
                    newAngularVelocity = msg.ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8);
                    newAngularVelocity = NetConfig.Quantize(newAngularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8);
                }
            }
            msg.ReadPadBits();

            if (!MathUtils.IsValid(newPosition) ||
                !MathUtils.IsValid(newVelocity) ||
                (newRotation.HasValue && !MathUtils.IsValid(newRotation.Value)) ||
                (newAngularVelocity.HasValue && !MathUtils.IsValid(newAngularVelocity.Value)))
            {
                string errorMsg = "Received invalid position data for \"" + parentDebugName
                                  + "\" (position: " + newPosition + ", rotation: " + (newRotation ?? 0) + ", velocity: " + newVelocity + ", angular velocity: " + (newAngularVelocity ?? 0) + ")";
#if DEBUG
                DebugConsole.ThrowError(errorMsg);
#endif
                GameAnalyticsManager.AddErrorEventOnce("PhysicsBody.ClientRead:InvalidData" + parentDebugName,
                                                       GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
                                                       errorMsg);
                return(null);
            }

            return(lastProcessedNetworkState > sendingTime ?
                   null :
                   new PosInfo(newPosition, newRotation, newVelocity, newAngularVelocity, sendingTime));
        }
Пример #11
0
        public static Matrix ReadMatrix(this NetBuffer Message)
        {
            var Quaternion = ReadQuaternion(Message, 24);
            var Matrix     = Microsoft.Xna.Framework.Matrix.CreateFromQuaternion(Quaternion);

            Matrix.M41 = Message.ReadFloat();
            Matrix.M42 = Message.ReadFloat();
            Matrix.M43 = Message.ReadFloat();
            return(Matrix);
        }
Пример #12
0
        public static MapObject Unpack(NetBuffer netBuffer)
        {
            // can we view it?
            if (!netBuffer.ReadBoolean())
            {
                return(null);
            }

            var   textureName     = Path.ChangeExtension(netBuffer.ReadString(), null);
            var   sourceRectangle = new Rectangle(netBuffer.ReadInt32(), netBuffer.ReadInt32(), netBuffer.ReadInt32(), netBuffer.ReadInt32());
            var   color           = new Color(new Vector4(netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte()));
            var   position        = new Vector2(netBuffer.ReadFloat(), netBuffer.ReadFloat());
            var   animated        = netBuffer.ReadBoolean();
            float zIndex          = netBuffer.ReadSingle();
            var   frameTime       = netBuffer.ReadInt32();

            var sprite =
                new AnimatedSprite(Client.ServiceLocator.GetService <ContentManagerService>().ContentManager.LoadTexture2D(
                                       Constants.FILEPATH_ROOT + textureName))
            {
                SourceRectangle = sourceRectangle,
                Color           = color,
                Position        = position,
                LayerDepth      = zIndex
            };

            var mapObject = new MapObject(sprite, animated)
            {
                FrameTime = frameTime
            };


            // is it a light source?
            if (netBuffer.ReadBoolean() == true)
            {
                var lightColor = new Color(new Vector4(netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte(), netBuffer.ReadByte()));
                var radius     = netBuffer.ReadFloat();

                PointLight pointLight = new PointLight
                {
                    Position  = position,
                    Scale     = new Vector2(radius),
                    Color     = lightColor,
                    Intensity = .7f,
                };

                Client.ServiceLocator.GetService <LightManagerService>().Component.Lights.Add(pointLight);

                mapObject.Light = pointLight;
            }

            return(mapObject);
        }
Пример #13
0
        public void Unpack(NetBuffer netBuffer, Layer layer)
        {
            var position = new Vector2(netBuffer.ReadFloat(), netBuffer.ReadFloat());

            _name = netBuffer.ReadString();

            var textureName = netBuffer.ReadString();

            _sprite = new Sprite(Client.ServiceLocator.Get <ContentManagerService>()
                                 .ContentManager.LoadTexture2D(Constants.FILEPATH_GFX + "/Items/" + textureName));

            _sprite.Transform.Position   = position;
            _sprite.Transform.LayerDepth = layer.ZIndex + .001f; // the .001f makes it so that the item spawns above the map layer, but just below actors
        }
        protected override void OnDeserialize(NetBuffer buffer)
        {
            Hits.Clear();

            int numHits = buffer.ReadUInt16();

            for (int i = 0; i < numHits; i++)
            {
                Vector3 vec = new Vector3(
                    buffer.ReadFloat(),
                    buffer.ReadFloat(),
                    buffer.ReadFloat());

                Hits.Add(vec);
            }
        }
Пример #15
0
        void R_ThrowGrenade(NetConnection client, NetBuffer buffer, ushort numArgs)
        {
            float ox = buffer.ReadFloat();
            float oy = buffer.ReadFloat();
            float oz = buffer.ReadFloat();

            float dx = buffer.ReadFloat();
            float dy = buffer.ReadFloat();
            float dz = buffer.ReadFloat();

            float power = buffer.ReadFloat();

            ServerMPPlayer player;

            if (players.TryGetValue(client, out player))
            {
                if (player.NumGrenades > 0)
                {
                    ThrowGrenade(player, new Vector3(ox, oy, oz), new Vector3(dx, dy, dz), power);

                    if (!DashCMD.GetCVar <bool>("ch_infammo"))
                    {
                        player.NumGrenades--;
                    }
                }
            }
        }
Пример #16
0
        public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
        {
            Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            float   newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
            bool    awake       = msg.ReadBoolean();
            Vector2 newVelocity = Vector2.Zero;

            if (awake)
            {
                newVelocity = new Vector2(
                    msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
                    msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
            }

            if (body == null)
            {
                DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")");
                return;
            }

            body.FarseerBody.Awake = awake;
            if (body.FarseerBody.Awake)
            {
                if ((newVelocity - body.LinearVelocity).Length() > 8.0f)
                {
                    body.LinearVelocity = newVelocity;
                }
            }
            else
            {
                body.FarseerBody.Enabled = false;
            }

            if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f)
            {
                body.SetTransform(newPosition, newRotation);

                Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
                rect.X = (int)(displayPos.X - rect.Width / 2.0f);
                rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
            }
        }
        protected override void OnDeserialize(NetBuffer buffer)
        {
            bullets.Clear();

            int numBullets = buffer.ReadUInt16();

            for (int i = 0; i < numBullets; i++)
            {
                float x = buffer.ReadFloat();
                float y = buffer.ReadFloat();
                float z = buffer.ReadFloat();

                float camYaw   = buffer.ReadFloat();
                float camPitch = buffer.ReadFloat();

                int tickDeltaTime = buffer.ReadUInt16();

                bullets.Add(new NetworkBullet(new Vector3(x, y, z), camYaw, camPitch, tickDeltaTime));
            }
        }
Пример #18
0
        INetCreatable I_CreateIntel(ushort id, bool isAppOwner, NetBuffer data)
        {
            // Read the packet
            float x    = data.ReadFloat();
            float y    = data.ReadFloat();
            float z    = data.ReadFloat();
            Team  team = (Team)data.ReadByte();

            Intel intel = new Intel(new Vector3(x, y, z), team);

            if (team == Team.A)
            {
                redIntel = intel;
            }
            else
            {
                blueIntel = intel;
            }

            return(intel);
        }
Пример #19
0
        INetCreatable I_CreateCommandPost(ushort id, bool isAppOwner, NetBuffer data)
        {
            // Read the packet
            float x    = data.ReadFloat();
            float y    = data.ReadFloat();
            float z    = data.ReadFloat();
            Team  team = (Team)data.ReadByte();

            CommandPost post = new CommandPost(new Vector3(x, y, z), team);

            if (team == Team.A)
            {
                redPost = post;
            }
            else
            {
                bluePost = post;
            }

            return(post);
        }
Пример #20
0
        void R_ShootMelon(NetConnection client, NetBuffer buffer, ushort numArgs)
        {
            float ox = buffer.ReadFloat();
            float oy = buffer.ReadFloat();
            float oz = buffer.ReadFloat();

            float dx = buffer.ReadFloat();
            float dy = buffer.ReadFloat();
            float dz = buffer.ReadFloat();

            ServerMPPlayer player;

            if (players.TryGetValue(client, out player))
            {
                if (player.NumMelons > 0)
                {
                    ShootMelon(player, new Vector3(ox, oy, oz), new Vector3(dx, dy, dz));

                    if (!DashCMD.GetCVar <bool>("ch_infammo"))
                    {
                        player.NumMelons--;
                    }
                }
            }
        }
        internal NetworkP2PHandoverInstance(NetBuffer buffer)
        {
            _networkView = null;

            position   = new Vector3(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat());
            rotation   = new Quaternion(buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat(), buffer.ReadFloat());
            relativeTo = (NetworkP2PSpace)buffer.ReadByte();

            remoteViewID           = new NetworkViewID(buffer);
            group                  = new NetworkGroup(buffer);
            authFlags              = (NetworkAuthFlags)buffer.ReadByte();
            isInstantiatedRemotely = buffer.ReadBoolean();

            proxyPrefab  = buffer.ReadString();
            ownerPrefab  = buffer.ReadString();
            serverPrefab = buffer.ReadString();

            cellAuthPrefab  = buffer.ReadString();
            cellProxyPrefab = buffer.ReadString();

            uint initialSize = buffer.ReadVariableUInt32();

            _initialData = initialSize != 0 ? buffer.ReadBytes((int)initialSize) : new byte[0];

            uint handoverSize = buffer.ReadVariableUInt32();

            _handoverData = handoverSize != 0 ? buffer.ReadBytes((int)handoverSize) : new byte[0];

            _isInstantiatable = true;
            _networkP2P       = null;
        }
Пример #22
0
        public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
        {
            nodes.Clear();

            int nodeCount = msg.ReadByte();

            Vector2[] nodePositions = new Vector2[nodeCount];

            for (int i = 0; i < nodeCount; i++)
            {
                nodePositions[i] = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (nodePositions.Any(n => !MathUtils.IsValid(n)))
            {
                return;
            }

            nodes = nodePositions.ToList();

            UpdateSections();
            Drawable = nodes.Any();
        }
        INetCreatable I_CreatePlayer(ushort id, bool isAppOwner, NetBuffer data)
        {
            // Read the packet
            float x    = data.ReadFloat();
            float y    = data.ReadFloat();
            float z    = data.ReadFloat();
            Team  team = (Team)data.ReadByte();

            ClientPlayer player;

            if (isAppOwner)
            {
                // It's our player, so create a little differently
                OurPlayer = new ClientMPPlayer(renderer, World, Camera.Active, new Vector3(x, y, z), team);
                player    = OurPlayer;
            }
            else
            {
                // Someone else's player, create normally
                player = new ReplicatedPlayer(renderer, World, new SimpleCamera(), new Vector3(x, y, z), team);
            }

            return(player);
        }
Пример #24
0
        void R_ThrowGrenade(NetConnection server, NetBuffer data, ushort numArgs)
        {
            float x = data.ReadFloat();
            float y = data.ReadFloat();
            float z = data.ReadFloat();

            float vx = data.ReadFloat();
            float vy = data.ReadFloat();
            float vz = data.ReadFloat();

            float power = data.ReadFloat();

            ThrowGrenadeRep(null, new Vector3(x, y, z), new Vector3(vx, vy, vz), power);
        }
Пример #25
0
        public static CBody ReadCBody(this NetBuffer message)
        {
            CBody retval = new CBody();

            retval.Radius             = message.ReadFloat();
            retval.InvMass            = message.ReadFloat();
            retval.LinDrag            = message.ReadFloat();
            retval.Restitution        = message.ReadFloat();
            retval.SpeedMultiplier    = message.ReadFloat();
            retval.RotationMultiplier = message.ReadFloat();
            retval.Velocity           = message.ReadVector3();
            retval.MaxVelocity        = message.ReadFloat();
            retval.EnableRot          = message.ReadBoolean();
            retval.Rot    = message.ReadRotation(8);
            retval.RotAx  = message.ReadVector3();
            retval.RotVel = message.ReadFloat();
            return(retval);
        }
Пример #26
0
        void R_ShootMelon(NetConnection server, NetBuffer data, ushort numArgs)
        {
            float x = data.ReadFloat();
            float y = data.ReadFloat();
            float z = data.ReadFloat();

            float vx = data.ReadFloat();
            float vy = data.ReadFloat();
            float vz = data.ReadFloat();

            ShootMelonRep(null, new Vector3(x, y, z), new Vector3(vx, vy, vz));
        }
Пример #27
0
        static object ReadPrimitive(NetBuffer buffer, SnapshotPrimitiveType type)
        {
            switch (type)
            {
            case SnapshotPrimitiveType.Byte:
                return(buffer.ReadByte());

            case SnapshotPrimitiveType.Char:
                return(buffer.ReadChar());

            case SnapshotPrimitiveType.Boolean:
                return(buffer.ReadBool());

            case SnapshotPrimitiveType.Int16:
            case SnapshotPrimitiveType.SByte:     // SByte is written as a short
                return(buffer.ReadInt16());

            case SnapshotPrimitiveType.UInt16:
                return(buffer.ReadUInt16());

            case SnapshotPrimitiveType.Int32:
                return(buffer.ReadInt32());

            case SnapshotPrimitiveType.UInt32:
                return(buffer.ReadUInt32());

            case SnapshotPrimitiveType.Int64:
                return(buffer.ReadInt64());

            case SnapshotPrimitiveType.UInt64:
                return(buffer.ReadUInt64());

            case SnapshotPrimitiveType.Single:
                return(buffer.ReadFloat());

            case SnapshotPrimitiveType.Double:
                return(buffer.ReadDouble());

            case SnapshotPrimitiveType.ByteFlag:
                return(buffer.ReadByteFlag());

            default:
                throw new Exception("Snapshot primitive type '" + type + "' is not supported!");
            }
        }
 /// <summary>
 /// Reads a <see cref="Vector4"/> value from the <see cref="NetBuffer"/>.
 /// </summary>
 /// <param name="message">The buffer to read from</param>
 /// <returns>A <see cref="Vector4"/> value</returns>
 public static Vector4 ReadVector4(this NetBuffer message)
 {
     return(new Vector4(message.ReadFloat(), message.ReadFloat(), message.ReadFloat(), message.ReadFloat()));
 }
 /// <summary>
 /// Reads a <see cref="Matrix"/> value from the <see cref="NetBuffer"/>.
 /// </summary>
 /// <param name="message">The buffer to write to</param>
 /// <returns>A <see cref="Matrix"/> value</returns>
 public static Matrix ReadMatrix(this NetBuffer message)
 {
     return(new Matrix(
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat(),
                message.ReadFloat()));
 }
 /// <summary>
 /// Reads a <see cref="Quaternion"/> value from the <see cref="NetBuffer"/>.
 /// </summary>
 /// <param name="message">The buffer to write to</param>
 /// <returns>A <see cref="Quaternion"/> value</returns>
 public static Quaternion ReadQuaternion(this NetBuffer message)
 {
     return(new Quaternion(message.ReadFloat(), message.ReadFloat(), message.ReadFloat(), message.ReadFloat()));
 }