Пример #1
0
        private static void MigrateDoubleBuffer(DoubleBuffers newBuffer, InputDevice[] devices, int deviceCount, DoubleBuffers oldBuffer)
        {
            // Nothing to migrate if we no longer keep a buffer of the corresponding type.
            if (!newBuffer.valid)
            {
                return;
            }

            // We do the same if we don't had a corresponding buffer before.
            if (!oldBuffer.valid)
            {
                return;
            }

            // Migrate every device that has allocated state blocks.
            var newStateBlockOffset = 0u;

            for (var i = 0; i < deviceCount; ++i)
            {
                var device = devices[i];

                // Stop as soon as we're hitting a new device. Newly added devices *must* be *appended* to the
                // array as otherwise our computing of offsets into the old buffer may be wrong.
                // NOTE: This also means that device indices of
                if (device.m_StateBlock.byteOffset == InputStateBlock.InvalidOffset)
                {
                    #if DEVELOPMENT_BUILD || UNITY_EDITOR
                    for (var n = i + 1; n < deviceCount; ++n)
                    {
                        Debug.Assert(devices[n].m_StateBlock.byteOffset == InputStateBlock.InvalidOffset,
                                     "New devices must be appended to the array; found an old device coming in the array after a newly added device");
                    }
                    #endif
                    break;
                }

                var oldDeviceIndex = device.m_DeviceIndex;
                var newDeviceIndex = i;
                var numBytes       = device.m_StateBlock.alignedSizeInBytes;

                var oldFrontPtr = (byte *)oldBuffer.GetFrontBuffer(oldDeviceIndex) + (int)device.m_StateBlock.byteOffset; // m_StateBlock still refers to oldBuffer.
                var oldBackPtr  = (byte *)oldBuffer.GetBackBuffer(oldDeviceIndex) + (int)device.m_StateBlock.byteOffset;

                var newFrontPtr = (byte *)newBuffer.GetFrontBuffer(newDeviceIndex) + (int)newStateBlockOffset;
                var newBackPtr  = (byte *)newBuffer.GetBackBuffer(newDeviceIndex) + (int)newStateBlockOffset;

                // Copy state.
                UnsafeUtility.MemCpy(newFrontPtr, oldFrontPtr, numBytes);
                UnsafeUtility.MemCpy(newBackPtr, oldBackPtr, numBytes);

                newStateBlockOffset = NextDeviceOffset(newStateBlockOffset, device);
            }
        }
Пример #2
0
        private unsafe void MigrateDoubleBuffer(DoubleBuffers newBuffer, InputDevice[] devices, int deviceCount, uint[] newStateBlockOffsets, DoubleBuffers oldBuffer, int[] oldDeviceIndices)
        {
            // Nothing to migrate if we no longer keep a buffer of the corresponding type.
            if (!newBuffer.valid)
            {
                return;
            }

            // We do the same if we don't had a corresponding buffer before.
            if (!oldBuffer.valid)
            {
                return;
            }

            ////TOOD: if we assume linear layouts of devices in 'devices' and assume that new devices are only added
            ////      at the end and only single devices can be removed, we can copy state buffers much more efficiently
            ////      in bulk rather than device-by-device

            // Migrate every device that has allocated state blocks.
            var newDeviceCount = deviceCount;
            var oldDeviceCount = oldDeviceIndices != null ? oldDeviceIndices.Length : newDeviceCount;

            for (var i = 0; i < newDeviceCount && i < oldDeviceCount; ++i)
            {
                var device = devices[i];
                Debug.Assert(device.m_DeviceIndex == i);

                // Skip device if it's a newly added device.
                if (device.m_StateBlock.byteOffset == InputStateBlock.kInvalidOffset)
                {
                    continue;
                }

                ////FIXME: this is not protecting against devices that have changed their formats between domain reloads

                var oldDeviceIndex = oldDeviceIndices != null ? oldDeviceIndices[i] : i;
                var newDeviceIndex = i;
                var numBytes       = device.m_StateBlock.alignedSizeInBytes;

                var oldFrontPtr = (byte *)oldBuffer.GetFrontBuffer(oldDeviceIndex).ToPointer() + (int)device.m_StateBlock.byteOffset;
                var oldBackPtr  = (byte *)oldBuffer.GetBackBuffer(oldDeviceIndex).ToPointer() + (int)device.m_StateBlock.byteOffset;

                var newFrontPtr = (byte *)newBuffer.GetFrontBuffer(newDeviceIndex).ToPointer() + (int)newStateBlockOffsets[i];
                var newBackPtr  = (byte *)newBuffer.GetBackBuffer(newDeviceIndex).ToPointer() + (int)newStateBlockOffsets[i];

                // Copy state.
                UnsafeUtility.MemCpy(newFrontPtr, oldFrontPtr, numBytes);
                UnsafeUtility.MemCpy(newBackPtr, oldBackPtr, numBytes);
            }
        }
Пример #3
0
 public static IntPtr GetBackBufferForDevice(int deviceIndex)
 {
     return(s_CurrentBuffers.GetBackBuffer(deviceIndex));
 }