예제 #1
0
        //
        public void LoadContent(ContentManager content)
        {
            // Load in textures
            WeaponsList[0].LoadContent(content.Load <Texture2D>("Sprites/Weapons/mg/mg_UI_icon"), content.Load <Texture2D>("Sprites/Weapons/mg/mg_side"), content.Load <Texture2D>("Sprites/Weapons/mg/bulleta"));
            WeaponsList[1].LoadContent(content.Load <Texture2D>("Sprites/Weapons/Shotgun/shot_side"), content.Load <Texture2D>("Sprites/Weapons/Shotgun/shot_side"), content.Load <Texture2D>("Sprites/Weapons/mg/bulleta"));

            // Equip first weapon
            EquipWeapon(0);
            OnWeaponSwap?.Invoke(ref equippedWeapon, ref equippedWeapon);
        }
예제 #2
0
 protected override void OnSearchDown()
 {
     if (Equals(nil))
     {
         return;
     }
     if (_rev)
     {
         var temp = LeftChild;
         LeftChild        = RightChild;
         RightChild       = temp;
         LeftChild._rev  ^= _rev;
         RightChild._rev ^= _rev;
         _rev             = false;
     }
     if (_operations != null)
     {
         LeftChild._operations  += _operations;
         RightChild._operations += _operations;
         _operations.Invoke(ref _data);
         _operations = null;
     }
 }
예제 #3
0
        /// <summary>
        /// Iterate over each pixel of <paramref name="bitmap"/> and passes the pixel values to <paramref name="currPixelAction"/>
        /// </summary>
        /// <param name="bitmap">The bitmap to modify</param>
        /// <param name="currPixelAction">The pixel action which should be called</param>
        /// <param name="editPixelOperatorList">A list of pixel operators which should be applied on each pixel</param>
        private static unsafe void EditPixels(this SoftwareBitmap bitmap, ActionRef <byte> currPixelAction = null, IEnumerable <IEditPixelOperator> editPixelOperatorList = null, uint width = 0, uint height = 0)
        {
            if (bitmap == null)
            {
                throw new ArgumentException(nameof(currPixelAction));
            }
            if (bitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8)
            {
                throw new ArgumentException(nameof(bitmap), $"{BitmapPixelFormat.Bgra8} expected");
            }

            if (editPixelOperatorList == null)
            {
                editPixelOperatorList = new List <IEditPixelOperator>();
            }

            // Effect is hard-coded to operate on BGRA8 format only
            if (bitmap.BitmapPixelFormat == BitmapPixelFormat.Bgra8)
            {
                // In BGRA8 format, each pixel is defined by 4 bytes
                const int BYTES_PER_PIXEL = 4;

                using (var buffer = bitmap.LockBuffer(BitmapBufferAccessMode.ReadWrite))
                    using (var reference = buffer.CreateReference())
                    {
                        // Get a pointer to the pixel buffer
                        byte *data;
                        uint  capacity;
                        ((IMemoryBufferByteAccess)reference).GetBuffer(out data, out capacity);

                        // Get information about the BitmapBuffer
                        var desc = buffer.GetPlaneDescription(0);

                        // Iterate over all pixels
                        for (uint row = height; row < desc.Height; row++)
                        {
                            for (uint col = width; col < desc.Width; col++)
                            {
                                // 8 bit or 1 byte for one data field 0... 255

                                // Index of the current pixel in the buffer (defined by the next 4 bytes, BGRA8)
                                var currPixel = desc.StartIndex + desc.Stride * row + BYTES_PER_PIXEL * col;

                                // Read the current pixel information into b,g,r channels
                                currPixelAction?.Invoke(
                                    ref data[currPixel + 0],
                                    ref data[currPixel + 1],
                                    ref data[currPixel + 2],
                                    ref data[currPixel + 3]
                                    );
                                //iterate over pixel modification list
                                foreach (IEditPixelOperator editPixel in editPixelOperatorList)
                                {
                                    // Read the current pixel information into b,g,r channels and pass it to the pixeloperators
                                    editPixel.EditPixel(
                                        ref data[currPixel + 0],
                                        ref data[currPixel + 1],
                                        ref data[currPixel + 2],
                                        ref data[currPixel + 3]
                                        );
                                }
                            }
                        }
                        //tell the editpixel interface that the pixel modification is completed
                        foreach (IEditPixelOperator editPixel in editPixelOperatorList)
                        {
                            editPixel.SetResult();
                        }
                    }
            }
        }