コード例 #1
0
        protected override void SendGameStateNow()
        {
            if (Screen == null)
            {
                return;
            }

            packageCount = 0;

            NetworkDataTools.SetByteWithHighBits(out MSG_FORWARD[2], SessionID, 16);
            NetworkDataTools.SetByteWithLowBits(out MSG_FORWARD[3], SessionID, 16);
            NetworkDataTools.SetSplitByte(out MSG_FORWARD[4], SessionUserID, SessionSecret, 4, 12, 4, 4);
            NetworkDataTools.SetByteWithLowBits(out MSG_FORWARD[5], SessionSecret, 12);
            NetworkDataTools.SetSingle(out MSG_FORWARD[6], out MSG_FORWARD[7], out MSG_FORWARD[8], out MSG_FORWARD[9], Screen.LevelTime);

            int p = PACKAGE_FORWARD_HEADER_SIZE;

            SendForwardBulletCannons(ref p);
            SendForwardLaserCannons(ref p);
            SendForwardMiniguns(ref p);
            SendForwardShieldProjectors(ref p);
            SendForwardRelayCannons(ref p);
            SendForwardTrishotCannons(ref p);
            SendForwardBullets(ref p);
            SendAndReset(ref p);
        }
コード例 #2
0
        protected void SendForwardShieldProjectors(ref int idx)
        {
            var data = Screen.GetEntities <ShieldProjectorCannon>().ToList();

            if (data.Count == 0)
            {
                return;
            }

            if (idx + 2 >= MAX_PACKAGE_SIZE_BYTES)
            {
                SendAndReset(ref idx);
            }

            MSG_FORWARD[idx] = AREA_SHIELDPROJECTORS;
            idx++;

            byte arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_SHIELDPROJECTOR);

            int posSize = idx;

            MSG_FORWARD[posSize] = 0xFF;
            idx++;

            int i = 0;

            foreach (var cannon in data)
            {
                if (!ShouldSendData(cannon))
                {
                    continue;
                }

                // [8: ID] [3: Fraction] [5: Boost] [32: RotationActual] [32: RotationTarget] [8: Health] [8:ChargeTime]

                NetworkDataTools.SetByte(out MSG_FORWARD[idx + 0], cannon.BlueprintCannonID);
                NetworkDataTools.SetSplitByte(out MSG_FORWARD[idx + 1], Screen.GetFractionID(cannon.Fraction), cannon.IntegerBoost, 3, 5, 3, 5);
                NetworkDataTools.SetSingle(out MSG_FORWARD[idx + 2], out MSG_FORWARD[idx + 3], out MSG_FORWARD[idx + 4], out MSG_FORWARD[idx + 5], cannon.Rotation.ActualValue);
                NetworkDataTools.SetSingle(out MSG_FORWARD[idx + 6], out MSG_FORWARD[idx + 7], out MSG_FORWARD[idx + 8], out MSG_FORWARD[idx + 9], cannon.Rotation.TargetValue);
                NetworkDataTools.SetByteFloor(out MSG_FORWARD[idx + 10], FloatMath.Clamp(cannon.CannonHealth.TargetValue, 0f, 1f) * 255);
                NetworkDataTools.SetByteFloor(out MSG_FORWARD[idx + 11], FloatMath.Clamp(cannon.ChargeTime / Cannon.SHIELDLASER_CHARGE_COOLDOWN_MAX, 0f, 1f) * 255);

                idx += PLEN_LASERCANNON;

                i++;
                if (i >= arrsize)
                {
                    MSG_FORWARD[posSize] = (byte)i;
                    SendAndReset(ref idx);
                    MSG_FORWARD[idx] = AREA_SHIELDPROJECTORS;
                    idx++;
                    i      -= arrsize;
                    arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_SHIELDPROJECTOR);
                    posSize = idx;
                    MSG_FORWARD[posSize] = 0xFF;
                    idx++;
                }
            }
            MSG_FORWARD[posSize] = (byte)i;
        }
コード例 #3
0
        protected void SendForwardRelayCannons(ref int idx)
        {
            var data = Screen.GetEntities <RelayCannon>().ToList();

            if (data.Count == 0)
            {
                return;
            }

            if (idx + 2 >= MAX_PACKAGE_SIZE_BYTES)
            {
                SendAndReset(ref idx);
            }

            MSG_FORWARD[idx] = AREA_BULLETCANNONS;
            idx++;

            byte arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_RELAYCANNON);

            int posSize = idx;

            MSG_FORWARD[posSize] = 0xFF;
            idx++;

            int i = 0;

            foreach (var cannon in data)
            {
                if (!ShouldSendData(cannon))
                {
                    continue;
                }

                // [8: ID] [3: Fraction] [5: Boost] [8: RotationActual] [8: RotationTarget] [8:Shield]

                NetworkDataTools.SetByte(out MSG_FORWARD[idx + 0], cannon.BlueprintCannonID);
                NetworkDataTools.SetSplitByte(out MSG_FORWARD[idx + 1], Screen.GetFractionID(cannon.Fraction), cannon.IntegerBoost, 3, 5, 3, 5);
                NetworkDataTools.SetByte(out MSG_FORWARD[idx + 2], NetworkDataTools.ConvertFromRadians(cannon.Rotation.ActualValue, 8));
                NetworkDataTools.SetByte(out MSG_FORWARD[idx + 3], NetworkDataTools.ConvertFromRadians(cannon.Rotation.TargetValue, 8));
                NetworkDataTools.SetByteFloorRange(out MSG_FORWARD[idx + 4], 0, Cannon.MAX_SHIELD_TIME, cannon.ShieldTime);

                idx += PLEN_RELAYCANNON;

                i++;
                if (i >= arrsize)
                {
                    MSG_FORWARD[posSize] = (byte)i;
                    SendAndReset(ref idx);
                    MSG_FORWARD[idx] = AREA_RELAYCANNONS;
                    idx++;
                    i      -= arrsize;
                    arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_RELAYCANNON);
                    posSize = idx;
                    MSG_FORWARD[posSize] = 0xFF;
                    idx++;
                }
            }
            MSG_FORWARD[posSize] = (byte)i;
        }
コード例 #4
0
        protected void SendForwardBullets(ref int idx)
        {
            if (idx + 2 >= MAX_PACKAGE_SIZE_BYTES)
            {
                SendAndReset(ref idx);
            }

            MSG_FORWARD[idx] = AREA_BULLETS;
            idx++;

            byte arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_BULLETS);

            int posSize = idx;

            MSG_FORWARD[posSize] = 0xFF;
            idx++;

            int i = 0;

            for (int bid = 0; bid < GDGameScreen.MAX_BULLET_ID; bid++)
            {
                if (Screen.BulletMapping[bid].Bullet == null)
                {
                    continue;
                }
                if (Screen.BulletMapping[bid].State != RemoteBullet.RemoteBulletState.Normal && Screen.BulletMapping[bid].RemainingPostDeathTransmitions <= 0)
                {
                    Screen.BulletMapping[bid].Bullet = null;                     // for GC
                    continue;
                }

                Screen.BulletMapping[bid].RemainingPostDeathTransmitions--;

                // [12: ID] [4: State] [16: PosX] [16: PosY] [10: VecRot] [11: VecLen] [3: Fraction] [8: Scale]

                var    b = Screen.BulletMapping[bid].Bullet;
                var    state = Screen.BulletMapping[bid].State;
                var    veloc = b.Velocity;
                ushort px, py;
                Screen.PositionTo2Byte(b.Position, out px, out py);
                ushort rot  = (ushort)((FloatMath.NormalizeAngle(veloc.ToAngle()) / FloatMath.TAU) * 1024);          // 10bit
                ushort len  = (ushort)FloatMath.IClamp(FloatMath.Round(veloc.Length() * 8), 0, 2048);                // 11bit (fac=8)
                byte   frac = Screen.GetFractionID(b.Fraction);


                NetworkDataTools.SetByteWithHighBits(out MSG_FORWARD[idx + 0], bid, 12);
                NetworkDataTools.SetSplitByte(out MSG_FORWARD[idx + 1], bid, (int)state, 12, 4, 4, 4);
                NetworkDataTools.SetUInt16(out MSG_FORWARD[idx + 2], out MSG_FORWARD[idx + 3], px);
                NetworkDataTools.SetUInt16(out MSG_FORWARD[idx + 4], out MSG_FORWARD[idx + 5], py);
                NetworkDataTools.SetByteWithHighBits(out MSG_FORWARD[idx + 6], rot, 10);
                NetworkDataTools.SetSplitByte(out MSG_FORWARD[idx + 7], rot, len, 10, 11, 2, 6);
                NetworkDataTools.SetSplitByte(out MSG_FORWARD[idx + 8], len, frac, 11, 3, 5, 3);
                NetworkDataTools.SetByteClamped(out MSG_FORWARD[idx + 9], (int)((b.Scale / 16f) * 255));

                idx += PLEN_BULLETS;

                i++;
                if (i >= arrsize)
                {
                    MSG_FORWARD[posSize] = (byte)i;
                    SendAndReset(ref idx);
                    MSG_FORWARD[idx] = AREA_BULLETS;
                    idx++;
                    i      -= arrsize;
                    arrsize = (byte)((MAX_PACKAGE_SIZE_BYTES - idx - 2) / PLEN_BULLETS);
                    posSize = idx;
                    MSG_FORWARD[posSize] = 0xFF;
                    idx++;
                }
            }
            MSG_FORWARD[posSize] = (byte)i;
        }