Beispiel #1
0
        public void UpdateRenderTargetSize(CanvasDevice device, GameGeometry geometry)
        {
            RenderTargetAspectRatio = geometry.AspectRatio;
            if (RenderTargetAspectRatio < 0.1f)
            {
                RenderTargetAspectRatio = (float)(geometry.BaseWidth) / geometry.BaseHeight;
            }

            if (RenderTarget != null)
            {
                var currentSize = RenderTarget.Size;
                if (currentSize.Width >= geometry.MaxWidth && currentSize.Height >= geometry.MaxHeight)
                {
                    return;
                }
            }

            lock (RenderTargetLock)
            {
                var size = Math.Max(Math.Max(geometry.MaxWidth, geometry.MaxHeight), RenderTargetMinSize);
                size = ClosestGreaterPowerTwo(size);

                RenderTarget?.Dispose();
                RenderTargetSurface?.Dispose();
                RenderTargetSurface = D3DSurfaceMap.CreateMappableD3DSurface(device, size, size);
                RenderTarget        = CanvasBitmap.CreateFromDirect3D11Surface(device, RenderTargetSurface);
            }
        }
Beispiel #2
0
        public void UpdateRenderTargetSize(ICanvasResourceCreator resourceCreator, GameGeometry geometry)
        {
            RenderTargetAspectRatio = geometry.AspectRatio;
            if (RenderTargetAspectRatio < 0.1f)
            {
                RenderTargetAspectRatio = (float)(geometry.BaseWidth) / geometry.BaseHeight;
            }

            if (RenderTarget != null)
            {
                var currentSize = RenderTarget.Size;
                if (currentSize.Width >= geometry.MaxWidth && currentSize.Height >= geometry.MaxHeight)
                {
                    return;
                }
            }

            lock (RenderTargetLock)
            {
                var size = Math.Max(Math.Max(geometry.MaxWidth, geometry.MaxHeight), RenderTargetMinSize);
                size = ClosestGreaterPowerTwo(size);
                RenderTargetBuffer = new byte[size * size * RenderTargetPixelSize];

                RenderTarget?.Dispose();
                RenderTarget = CanvasBitmap.CreateFromBytes(resourceCreator, RenderTargetBuffer, (int)size, (int)size, RenderTargetPixelFormat);
            }
        }
Beispiel #3
0
 public void Reset()
 {
     GameState = GameStates.Preload;
     if (HistoryItems == null) // if game is not loading
     {
         ActivePlayer = null;
     }
     GameGeometry.Update(_dimension, _badgesToWin);
 }
Beispiel #4
0
        // build a way for the user of core to passthrough their choice of commands to handle
        private bool environmentCallback(uint command, IntPtr data)
        {
            switch ((EnvironmentCommand)command)
            {
            case EnvironmentCommand.GetOverscan:
                Marshal.WriteByte(data, 0, Convert.ToByte(true));
                return(true);

            case EnvironmentCommand.GetCanDupe:
                Marshal.WriteByte(data, 0, Convert.ToByte(true));
                return(true);

            case EnvironmentCommand.SetPerformanceLevel:
                uint temp = (uint)Marshal.ReadInt32(data);     // this isn't being stored anywhere
                return(true);

            case EnvironmentCommand.GetSystemDirectory:
                Marshal.WriteIntPtr(data, Marshal.StringToHGlobalAnsi(_systemDirectoryPath));
                return(true);

            case EnvironmentCommand.SetPixelFormat:
                PixelFormat = (PixelFormat)Marshal.ReadInt32(data);
                return(true);

            case EnvironmentCommand.SetInputDescriptors:
                IntPtr inputDescriptorAddress = data;
                while (true)
                {
                    InputDescriptor inputDescriptor = (InputDescriptor)Marshal.PtrToStructure(inputDescriptorAddress, typeof(InputDescriptor));
                    if (inputDescriptor.Description == null)
                    {
                        break;
                    }
                    Inputs.Add(new Input(inputDescriptor));
                    inputDescriptorAddress = (IntPtr)((long)inputDescriptorAddress + Marshal.SizeOf(inputDescriptor));
                }
                return(true);

            case EnvironmentCommand.GetVariable:
                Variable             variable         = (Variable)Marshal.PtrToStructure(data, typeof(Variable));
                IEnumerable <string> matchedVariables = Variables.Where(v => v.Key == variable.Key).Select(v => v.Value);
                if (matchedVariables.Any())
                {
                    string firstValue = Variables.Where(v => v.Key == variable.Key).Select(v => v.Value).First();
                    firstValue = firstValue.Substring(firstValue.IndexOf(';') + 2);
                    if (firstValue.Contains("|"))
                    {
                        firstValue = firstValue.Substring(0, firstValue.IndexOf('|'));
                    }
                    variable.Value = firstValue;
                    Marshal.StructureToPtr(variable, data, false);
                }
                return(true);

            case EnvironmentCommand.SetVariables:
                IntPtr variableAddress = data;
                while (true)
                {
                    variable = (Variable)Marshal.PtrToStructure(variableAddress, typeof(Variable));
                    if (variable.Key == null)
                    {
                        break;
                    }
                    Variables.Add(variable);
                    variableAddress = (IntPtr)((long)variableAddress + Marshal.SizeOf(variable));
                }
                return(true);

            case EnvironmentCommand.GetVariableUpdate:
                Marshal.WriteByte(data, 0, Convert.ToByte(_variablesDirty));
                _variablesDirty = false;
                return(true);

            case EnvironmentCommand.GetLogInterface:
                _logCallback = new LogCallback();
                if (LogPassthroughHandler == null)
                {
                    _logCallback.Log = logCallback;
                }
                else
                {
                    _logCallback.Log = LogPassthroughHandler;
                }
                Marshal.StructureToPtr(_logCallback, data, false);
                return(true);

            case EnvironmentCommand.GetSaveDirectory:
                Marshal.WriteIntPtr(data, Marshal.StringToHGlobalAnsi(Directory.GetCurrentDirectory()));
                return(true);

            case EnvironmentCommand.SetMemoryMaps:     // not saved anywhere
                return(true);

            case EnvironmentCommand.SetGeometry:
                GameGeometry gameGeometry = (GameGeometry)Marshal.PtrToStructure(data, typeof(GameGeometry));
                return(true);

            case EnvironmentCommand.GetCurrentSoftwareFrameBuffer:     // not implemented
                return(false);

            default:
                Debug.WriteLine("Unhandled Environment Command: " + command);
                return(false);
            }
        }
Beispiel #5
0
 public void GeometryChanged(GameGeometry geometry)
 {
     RenderTargetManager.UpdateRenderTargetSize(RenderPanel.Device, geometry);
 }