Example #1
0
        public static Span2D <byte> InitializePackets(this Span2D <byte> buffer)
        {
#if NO_LOCAL_INIT
            for (var i = 0; i < buffer.Height; i++)
            {
                buffer.GetRowSpan(i)[0] = 0;
            }
#endif
            return(buffer);
        }
    internal static ulong HashXx3(this Span2D <byte> data)
    {
        ulong currentHash = Default;

        for (int i = 0; i < data.Height; ++i)
        {
            currentHash = Combine(currentHash, data.GetRowSpan(i).HashXx3());
        }
        return(currentHash);
    }
Example #3
0
        public static Span2D <T> FlipVertical <T>(Span2D <T> span)
        {
            var flipped = new T[span.Height, span.Width];

            for (var col = span.Height - 1; col >= 0; col--)
            {
                var source = span.GetRowSpan(col);
                var target = flipped.GetRowSpan((span.Height - 1) - col);

                source.CopyTo(target);
            }

            return(flipped);
        }
Example #4
0
        public static T[,] FlipHorizontal <T>(Span2D <T> span)
        {
            var flipped = new T[span.Height, span.Width];

            for (var col = 0; col < span.Height; col++)
            {
                var source = span.GetRowSpan(col);
                var target = flipped.GetRowSpan(col);

                source.CopyTo(target);
                target.Reverse();
            }

            return(flipped);
        }
        // Requires a buffer of 16 packets, 17bytes per packet (272 bytes).
        // Requires cache to have the first byte of each packet zeroed.
        public static void SendMobileMovingUsingCache(this NetState ns, Span2D <byte> cache, Mobile target, int noto)
        {
            if (ns == null)
            {
                return;
            }

            var stygianAbyss = ns.StygianAbyss;
            var row          = noto * 2 + (stygianAbyss ? 1 : 0);
            var buffer       = cache.GetRowSpan(row);

            CreateMobileMoving(buffer, target, noto, stygianAbyss);

            ns.Send(buffer);
        }
Example #6
0
    private static bool CheckIsDataChanged <T>(
        XTexture2D instance,
        int level,
        int arraySlice,
        XRectangle?inRect,
        T[] data,
        int startIndex,
        int elementCount
        ) where T : unmanaged
    {
        Bounds rect = inRect ?? instance.Bounds;

        if (instance.TryMeta(out var meta) && meta.CachedData is { } cachedData)
        {
            var dataSpan = data.AsReadOnlySpan().Cast <T, byte>();

            unsafe {
                var inSpan      = dataSpan;
                int inOffset    = 0;
                int inRowLength = rect.Width * sizeof(T);

                var cachedSpan = new Span2D <byte>(
                    array: cachedData,
                    offset: startIndex * sizeof(T),
                    width: rect.Width * sizeof(T),
                    height: rect.Height,
                    pitch: (instance.Width - rect.Width) * sizeof(T)
                    );

                for (int y = 0; y < rect.Height; ++y)
                {
                    var inSpanRow     = inSpan.SliceUnsafe(inOffset, inRowLength);
                    var cachedSpanRow = cachedSpan.GetRowSpan(y);
                    if (!inSpanRow.SequenceEqual(cachedSpanRow))
                    {
                        return(true);
                    }
                    inOffset += inRowLength;
                }

                return(false);
            }
        }

        return(true);
    }