diff --git a/Exomia.Framework.sln b/Exomia.Framework.sln
index 9fa7ab4c..26bddbbf 100644
--- a/Exomia.Framework.sln
+++ b/Exomia.Framework.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exomia.Framework", "Exomia.Framework\Exomia.Framework.csproj", "{2311CF3A-095C-49B0-BBEA-FC3892E9134E}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exomia.Framework", "src\Exomia.Framework\Exomia.Framework.csproj", "{2311CF3A-095C-49B0-BBEA-FC3892E9134E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Exomia.Framework/EventHandler.cs b/Exomia.Framework/EventHandler.cs
deleted file mode 100644
index 70746c5c..00000000
--- a/Exomia.Framework/EventHandler.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-#region License
-
-// Copyright (c) 2018-2019, exomia
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree.
-
-#endregion
-
-namespace Exomia.Framework
-{
- ///
- /// Represents the method that will handle an event that has no event data and no sender
- /// specified.
- ///
- public delegate void EventHandler();
-
- ///
- /// Represents the method that will handle an event that has no event data.
- ///
- /// .
- /// .
- public delegate void EventHandler(TEventArgs e);
-
- ///
- /// Represents the method that will handle an event when the event provides data.
- ///
- /// .
- /// .
- /// .
- /// .
- public delegate void EventHandler(TClass sender, TEventArgs e);
-}
\ No newline at end of file
diff --git a/Exomia.Framework/Input/IInputDevice.cs b/Exomia.Framework/Input/IInputDevice.cs
deleted file mode 100644
index 37d6458a..00000000
--- a/Exomia.Framework/Input/IInputDevice.cs
+++ /dev/null
@@ -1,201 +0,0 @@
-#region License
-
-// Copyright (c) 2018-2019, exomia
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree.
-
-#endregion
-
-using System;
-
-namespace Exomia.Framework.Input
-{
- ///
- /// MouseButtons enum.
- ///
- [Flags]
- public enum MouseButtons
- {
- ///
- /// default
- ///
- None = 0,
-
- ///
- /// Left mouse button
- ///
- Left = 1 << 1,
-
- ///
- /// Middle mouse button
- ///
- Middle = 1 << 2,
-
- ///
- /// Right mouse button
- ///
- Right = 1 << 3,
-
- ///
- /// Button4 mouse button
- ///
- Button4 = 1 << 4,
-
- ///
- /// Button5 mouse button
- ///
- Button5 = 1 << 5
- }
-
- ///
- /// default KeyEventHandler.
- ///
- /// keyValue.
- /// shift key pressed.
- /// alt key pressed.
- /// ctrl key pressed.
- public delegate void KeyEventHandler(int keyValue, bool shift, bool alt, bool ctrl);
-
- ///
- /// default KeyPressEventHandler.
- ///
- /// key.
- public delegate void KeyPressEventHandler(char key);
-
- ///
- /// default MouseEventHandler.
- ///
- /// mouse position x.
- /// mouse position y.
- /// pressed buttons.
- /// clicks.
- /// wheelDelta.
- public delegate void MouseEventHandler(int x, int y, MouseButtons buttons, int clicks, int wheelDelta);
-
- ///
- /// IInputDevice interface.
- ///
- public interface IInputDevice
- {
- ///
- /// called than a key is down once.
- ///
- event KeyEventHandler KeyDown;
-
- ///
- /// called every time a key is pressed.
- ///
- event KeyPressEventHandler KeyPress;
-
- ///
- /// called than a key is up once after a key was down.
- ///
- event KeyEventHandler KeyUp;
-
- ///
- /// called every time a mouse button is clicked.
- ///
- event MouseEventHandler MouseClick;
-
- ///
- /// called than a mouse button is down once.
- ///
- event MouseEventHandler MouseDown;
-
- ///
- /// called than the mouse moves.
- ///
- event MouseEventHandler MouseMove;
-
- ///
- /// called than a mose button is up once after a button was down.
- ///
- event MouseEventHandler MouseUp;
-
- ///
- /// called if the wheel delta is changed.
- ///
- event MouseEventHandler MouseWheel;
-
- ///
- /// check if a specified keyValue is down.
- ///
- /// keyValue.
- ///
- /// true if the specified keyValue is down; false otherwise.
- ///
- bool IsKeyDown(int keyValue);
-
- ///
- /// check if one of the specified keyValues is down.
- ///
- /// keyValues.
- ///
- /// true if one of the specified keyValues is down; false otherwise.
- ///
- bool IsKeyDown(params int[] keyValues);
-
- ///
- /// check if a specified keyValue is up.
- ///
- /// keyValue.
- ///
- /// true if the specified keyValue is up; false otherwise.
- ///
- bool IsKeyUp(int keyValues);
-
- ///
- /// check if one of the specified keyValues is up.
- ///
- /// keyValues.
- ///
- /// true if one of the specified keyValues is up; false otherwise.
- ///
- bool IsKeyUp(params int[] keyValues);
-
- ///
- /// check if a specified mouse button is down.
- ///
- /// MouseButtons.
- ///
- /// true if the specified button is down; false otherwise.
- ///
- bool IsMouseButtonDown(MouseButtons button);
-
- ///
- /// check if one of the specified mouse buttons is down.
- ///
- /// MouseButtons.
- ///
- /// true if one of the specified buttons is down; false otherwise.
- ///
- bool IsMouseButtonDown(params MouseButtons[] buttons);
-
- ///
- /// check if a specified mouse button is up.
- ///
- /// MouseButtons.
- ///
- /// true if the specified button is up; false otherwise.
- ///
- bool IsMouseButtonUp(MouseButtons button);
-
- ///
- /// check if one of the specified mouse buttons is up.
- ///
- /// MouseButtons.
- ///
- /// true if one of the specified buttons is up; false otherwise.
- ///
- bool IsMouseButtonUp(params MouseButtons[] buttons);
-
- ///
- /// set the mouse to a specified position on the current window.
- ///
- /// x-position.
- /// y-position.
- void SetMousePosition(int x, int y);
- }
-}
\ No newline at end of file
diff --git a/Exomia.Framework/Input/IRawInputDevice.cs b/Exomia.Framework/Input/IRawInputDevice.cs
deleted file mode 100644
index 0469059d..00000000
--- a/Exomia.Framework/Input/IRawInputDevice.cs
+++ /dev/null
@@ -1,228 +0,0 @@
-#region License
-
-// Copyright (c) 2018-2019, exomia
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree.
-
-#endregion
-
-using System;
-using System.Windows.Forms;
-using Exomia.Framework.Game;
-using SharpDX.RawInput;
-
-namespace Exomia.Framework.Input
-{
- ///
- /// Delegate for handling RKey events.
- ///
- /// The key.
- /// The state.
- /// Information describing the extra.
- /// The keys.
- public delegate void RKeyEventHandler(int key, KeyState state, int extraInformation, RSpecialKeys sKeys);
-
- ///
- /// Delegate for handling RMouse events.
- ///
- /// The x coordinate.
- /// The y coordinate.
- /// The buttons.
- /// The clicks.
- /// The wheel delta.
- public delegate void RMouseEventHandler(int x, int y, RMouseButtons buttons, int clicks, int wheelDelta);
-
- ///
- /// Bitfield of flags for specifying RMouseButtons.
- ///
- [Flags]
- public enum RMouseButtons
- {
- ///
- /// A binary constant representing the left flag.
- ///
- Left = 1 << 0,
-
- ///
- /// A binary constant representing the middle flag.
- ///
- Middle = 1 << 1,
-
- ///
- /// A binary constant representing the right flag.
- ///
- Right = 1 << 2,
-
- ///
- /// A binary constant representing the button 4 flag.
- ///
- Button4 = 1 << 3,
-
- ///
- /// A binary constant representing the button 5 flag.
- ///
- Button5 = 1 << 4
- }
-
- ///
- /// Bitfield of flags for specifying RSpecialKeys.
- ///
- [Flags]
- public enum RSpecialKeys
- {
- ///
- /// A binary constant representing the none flag.
- ///
- None = 1 << 0,
-
- ///
- /// A binary constant representing the shift flag.
- ///
- Shift = 1 << 1,
-
- ///
- /// A binary constant representing the Alternate flag.
- ///
- Alt = 1 << 2,
-
- ///
- /// A binary constant representing the control flag.
- ///
- Control = 1 << 3
- }
-
- ///
- /// Interface for raw input device.
- ///
- public interface IRawInputDevice
- {
- ///
- /// Occurs when Key Down.
- ///
- event RKeyEventHandler KeyDown;
-
- ///
- /// Occurs when Key Press.
- ///
- event RKeyEventHandler KeyPress;
-
- ///
- /// Occurs when Key Up.
- ///
- event RKeyEventHandler KeyUp;
-
- ///
- /// Occurs when Mouse Down.
- ///
- event RMouseEventHandler MouseDown;
-
- ///
- /// Occurs when Mouse Move.
- ///
- event RMouseEventHandler MouseMove;
-
- ///
- /// Occurs when Mouse Up.
- ///
- event RMouseEventHandler MouseUp;
-
- ///
- /// Gets information describing the wheel.
- ///
- ///
- /// Information describing the wheel.
- ///
- int WheelData { get; }
-
- ///
- /// Ends an update.
- ///
- void EndUpdate();
-
- ///
- /// Initializes this object.
- ///
- /// The window.
- void Initialize(IGameWindow window);
-
- ///
- /// Initializes this object.
- ///
- /// The panel.
- void Initialize(Panel panel);
-
- ///
- /// Query if 'key' is key down.
- ///
- /// A variable-length parameters list containing key.
- ///
- /// True if key down, false if not.
- ///
- bool IsKeyDown(int key);
-
- ///
- /// Query if 'key' is key down.
- ///
- /// A variable-length parameters list containing key.
- ///
- /// True if key down, false if not.
- ///
- bool IsKeyDown(params int[] key);
-
- ///
- /// Query if 'key' is key up.
- ///
- /// The button.
- ///
- /// True if key up, false if not.
- ///
- bool IsKeyUp(RMouseButtons button);
-
- ///
- /// Query if 'key' is key up.
- ///
- /// A variable-length parameters list containing buttons.
- ///
- /// True if key up, false if not.
- ///
- bool IsKeyUp(params RMouseButtons[] buttons);
-
- ///
- /// Query if 'key' is key up.
- ///
- /// A variable-length parameters list containing key.
- ///
- /// True if key up, false if not.
- ///
- bool IsKeyUp(int key);
-
- ///
- /// Query if 'key' is key up.
- ///
- /// A variable-length parameters list containing key.
- ///
- /// True if key up, false if not.
- ///
- bool IsKeyUp(params int[] key);
-
- ///
- /// Query if 'buttons' is mouse button down.
- ///
- /// The button.
- ///
- /// True if mouse button down, false if not.
- ///
- bool IsMouseButtonDown(RMouseButtons button);
-
- ///
- /// Query if 'buttons' is mouse button down.
- ///
- /// A variable-length parameters list containing buttons.
- ///
- /// True if mouse button down, false if not.
- ///
- bool IsMouseButtonDown(params RMouseButtons[] buttons);
- }
-}
\ No newline at end of file
diff --git a/Exomia.Framework/Input/RawInputDevice.cs b/Exomia.Framework/Input/RawInputDevice.cs
deleted file mode 100644
index 9a4025ed..00000000
--- a/Exomia.Framework/Input/RawInputDevice.cs
+++ /dev/null
@@ -1,371 +0,0 @@
-#region License
-
-// Copyright (c) 2018-2019, exomia
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree.
-
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Windows.Forms;
-using Exomia.Framework.Game;
-using SharpDX.Multimedia;
-using SharpDX.RawInput;
-
-namespace Exomia.Framework.Input
-{
- ///
- /// A raw input device. This class cannot be inherited.
- ///
- public sealed class RawInputDevice : IRawInputDevice, IDisposable
- {
- ///
- /// Occurs when Key Down.
- ///
- public event RKeyEventHandler KeyDown;
-
- ///
- /// Occurs when Key Press.
- ///
- public event RKeyEventHandler KeyPress;
-
- ///
- /// Occurs when Key Up.
- ///
- public event RKeyEventHandler KeyUp;
-
- ///
- /// Occurs when Mouse Down.
- ///
- public event RMouseEventHandler MouseDown;
-
- ///
- /// Occurs when Mouse Move.
- ///
- public event RMouseEventHandler MouseMove;
-
- ///
- /// Occurs when Mouse Up.
- ///
- public event RMouseEventHandler MouseUp;
-
- ///
- /// The pressed keys.
- ///
- private readonly HashSet _pressedKeys;
-
- ///
- /// The mouse position.
- ///
- private Point _mousePosition = Point.Empty;
-
- ///
- /// Buffer for mouse wheel data data.
- ///
- private int _mouseWheelDataBuffer;
-
- ///
- /// The panel.
- ///
- private Panel _panel;
-
- ///
- /// The pressed mouse buttons.
- ///
- private RMouseButtons _pressedMouseButtons = 0;
-
- ///
- /// The window.
- ///
- private IGameWindow _window;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public RawInputDevice()
- {
- _pressedKeys = new HashSet();
-
- Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None);
- Device.KeyboardInput += Device_KeyboardInput;
-
- Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, DeviceFlags.None);
- Device.MouseInput += Device_MouseInput;
- }
-
- ///
- public void EndUpdate()
- {
- WheelData = _mouseWheelDataBuffer;
- _mouseWheelDataBuffer = 0;
- }
-
- ///
- public void Initialize(IGameWindow window)
- {
- _window = window;
- if (_window is IWinFormsGameWindow formsWindow)
- {
- formsWindow.RenderForm.MouseMove += RenderForm_MouseMove;
- }
- }
-
- ///
- public void Initialize(Panel panel)
- {
- _panel = panel;
- _panel.MouseMove += RenderForm_MouseMove;
- }
-
- ///
- /// Event handler. Called by RenderForm for mouse move events.
- ///
- /// Source of the event.
- /// Mouse event information.
- private void RenderForm_MouseMove(object sender, MouseEventArgs e)
- {
- _mousePosition = e.Location;
- MouseMove?.Invoke(e.X, e.Y, _pressedMouseButtons, 1, e.Delta);
- }
-
- //TODO: CHANGE TO FORM INPUT INSTEAD OF RAW INPUT
-
- #region Device MouseInput
-
- ///
- /// Event handler. Called by Device for mouse input events.
- ///
- /// Source of the event.
- /// Mouse input event information.
- private void Device_MouseInput(object sender, MouseInputEventArgs e)
- {
- if ((e.ButtonFlags & MouseButtonFlags.MouseWheel) == MouseButtonFlags.MouseWheel)
- {
- _mouseWheelDataBuffer += e.WheelDelta > 0 ? -1 : 1;
- }
-
- if ((e.ButtonFlags & MouseButtonFlags.LeftButtonDown) == MouseButtonFlags.LeftButtonDown)
- {
- _pressedMouseButtons |= RMouseButtons.Left;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Left, 1, e.WheelDelta);
- }
- else if ((e.ButtonFlags & MouseButtonFlags.LeftButtonUp) == MouseButtonFlags.LeftButtonUp)
- {
- _pressedMouseButtons &= ~RMouseButtons.Left;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Left, 1, e.WheelDelta);
- }
-
- if ((e.ButtonFlags & MouseButtonFlags.RightButtonDown) == MouseButtonFlags.RightButtonDown)
- {
- _pressedMouseButtons |= RMouseButtons.Right;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Right, 1, e.WheelDelta);
- }
- else if ((e.ButtonFlags & MouseButtonFlags.RightButtonUp) == MouseButtonFlags.RightButtonUp)
- {
- _pressedMouseButtons &= ~RMouseButtons.Right;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Right, 1, e.WheelDelta);
- }
-
- if ((e.ButtonFlags & MouseButtonFlags.MiddleButtonDown) == MouseButtonFlags.MiddleButtonDown)
- {
- _pressedMouseButtons |= RMouseButtons.Middle;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Middle, 1, e.WheelDelta);
- }
- else if ((e.ButtonFlags & MouseButtonFlags.MiddleButtonUp) == MouseButtonFlags.MiddleButtonUp)
- {
- _pressedMouseButtons &= ~RMouseButtons.Middle;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Left, 1, e.WheelDelta);
- }
-
- if ((e.ButtonFlags & MouseButtonFlags.Button4Down) == MouseButtonFlags.Button4Down)
- {
- _pressedMouseButtons |= RMouseButtons.Button4;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Button4, 1, e.WheelDelta);
- }
- else if ((e.ButtonFlags & MouseButtonFlags.Button4Up) == MouseButtonFlags.Button4Up)
- {
- _pressedMouseButtons &= ~RMouseButtons.Button4;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Button4, 1, e.WheelDelta);
- }
-
- if ((e.ButtonFlags & MouseButtonFlags.Button5Down) == MouseButtonFlags.Button5Down)
- {
- _pressedMouseButtons |= RMouseButtons.Button5;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Button5, 1, e.WheelDelta);
- }
- else if ((e.ButtonFlags & MouseButtonFlags.Button5Up) == MouseButtonFlags.Button5Up)
- {
- _pressedMouseButtons &= ~RMouseButtons.Button5;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, RMouseButtons.Button5, 1, e.WheelDelta);
- }
- }
-
- ///
- public bool IsMouseButtonDown(RMouseButtons button)
- {
- //return _pressedMouseButtons.Contains(button);
- return (_pressedMouseButtons & button) == button;
- }
-
- ///
- public bool IsMouseButtonDown(params RMouseButtons[] buttons)
- {
- int l = buttons.Length;
- for (int i = 0; i < l; i++)
- {
- //if (_pressedMouseButtons.Contains(buttons[i])) { return true; }
- if (IsMouseButtonDown(buttons[i])) { return true; }
- }
- return false;
- }
-
- ///
- public bool IsKeyUp(RMouseButtons button)
- {
- return !IsMouseButtonDown(button);
- }
-
- ///
- public bool IsKeyUp(params RMouseButtons[] buttons)
- {
- int l = buttons.Length;
- for (int i = 0; i < l; i++)
- {
- if (!IsMouseButtonDown(buttons[i])) { return true; }
- }
- return false;
- }
-
- ///
- public int WheelData { get; private set; }
-
- #endregion
-
- #region Device KeyboardInput
-
- ///
- /// Event handler. Called by Device for keyboard input events.
- ///
- /// Source of the event.
- /// Keyboard input event information.
- private void Device_KeyboardInput(object sender, KeyboardInputEventArgs e)
- {
- RSpecialKeys sKeys = RSpecialKeys.None;
- if (IsKeyDown(Key.ShiftKey))
- {
- sKeys |= RSpecialKeys.Shift;
- }
- if (IsKeyDown(Key.Alt))
- {
- sKeys |= RSpecialKeys.Alt;
- }
- if (IsKeyDown(Key.ControlKey))
- {
- sKeys |= RSpecialKeys.Control;
- }
- if (e.State == KeyState.KeyDown)
- {
- if (_pressedKeys.Add((int)e.Key))
- {
- KeyDown?.Invoke((int)e.Key, e.State, e.ExtraInformation, sKeys);
- }
- }
- if (e.State == KeyState.KeyUp)
- {
- if (_pressedKeys.Remove((int)e.Key))
- {
- KeyPress?.Invoke((int)e.Key, e.State, e.ExtraInformation, sKeys);
- }
- KeyUp?.Invoke((int)e.Key, e.State, e.ExtraInformation, sKeys);
- }
- }
-
- ///
- public bool IsKeyDown(int key)
- {
- return _pressedKeys.Contains(key);
- }
-
- ///
- public bool IsKeyDown(params int[] key)
- {
- int l = key.Length;
- for (int i = 0; i < l; i++)
- {
- if (_pressedKeys.Contains(key[i])) { return true; }
- }
- return false;
- }
-
- ///
- public bool IsKeyUp(int key)
- {
- return !_pressedKeys.Contains(key);
- }
-
- ///
- public bool IsKeyUp(params int[] key)
- {
- int l = key.Length;
- for (int i = 0; i < l; i++)
- {
- if (!_pressedKeys.Contains(key[i])) { return true; }
- }
- return false;
- }
-
- #endregion
-
- #region IDisposable Support
-
- ///
- /// True to disposed value.
- ///
- private bool _disposedValue;
-
- ///
- /// Releases the unmanaged resources used by the Exomia.Framework.Input.RawInputDevice and
- /// optionally releases the managed resources.
- ///
- ///
- /// True to release both managed and unmanaged resources; false to
- /// release only unmanaged resources.
- ///
- private void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing) { }
-
- Device.KeyboardInput -= Device_KeyboardInput;
- Device.MouseInput -= Device_MouseInput;
-
- if (_window != null)
- {
- if (_window is IWinFormsGameWindow formsWindow)
- {
- formsWindow.RenderForm.MouseMove -= RenderForm_MouseMove;
- }
- }
- if (_panel != null)
- {
- _panel.MouseMove -= RenderForm_MouseMove;
- }
-
- _disposedValue = true;
- }
- }
-
- ///
- public void Dispose()
- {
- Dispose(true);
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/Exomia.Framework/Input/WinFormsInputDevice.cs b/Exomia.Framework/Input/WinFormsInputDevice.cs
deleted file mode 100644
index 5df6e5c5..00000000
--- a/Exomia.Framework/Input/WinFormsInputDevice.cs
+++ /dev/null
@@ -1,424 +0,0 @@
-#region License
-
-// Copyright (c) 2018-2019, exomia
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree.
-
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Runtime.CompilerServices;
-using System.Windows.Forms;
-using Exomia.Framework.Game;
-
-namespace Exomia.Framework.Input
-{
- ///
- /// A window forms input device. This class cannot be inherited.
- ///
- public sealed class WinFormsInputDevice : IInputDevice, IDisposable
- {
- ///
- /// Occurs when Key Down.
- ///
- ///
- public event KeyEventHandler KeyDown;
-
- ///
- /// Occurs when Key Press.
- ///
- ///
- public event KeyPressEventHandler KeyPress;
-
- ///
- /// Occurs when Key Up.
- ///
- ///
- public event KeyEventHandler KeyUp;
-
- ///
- /// Occurs when Mouse Click.
- ///
- ///
- public event MouseEventHandler MouseClick;
-
- ///
- /// Occurs when Mouse Down.
- ///
- ///
- public event MouseEventHandler MouseDown;
-
- ///
- /// Occurs when Mouse Move.
- ///
- ///
- public event MouseEventHandler MouseMove;
-
- ///
- /// Occurs when Mouse Up.
- ///
- ///
- public event MouseEventHandler MouseUp;
-
- ///
- /// Occurs when Mouse Wheel.
- ///
- ///
- public event MouseEventHandler MouseWheel;
-
- ///
- /// The pressed keys.
- ///
- private readonly HashSet _pressedKeys = new HashSet();
-
- ///
- /// The window.
- ///
- private readonly IWinFormsGameWindow _window;
-
- ///
- /// The mouse position.
- ///
- private Point _mousePosition = Point.Empty;
-
- ///
- /// The pressed mouse buttons.
- ///
- private MouseButtons _pressedMouseButtons = MouseButtons.None;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The game.
- public WinFormsInputDevice(Game.Game game)
- : this(game.GameWindow as IWinFormsGameWindow) { }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The win forms game window.
- /// Thrown when one or more required arguments are null.
- public WinFormsInputDevice(IWinFormsGameWindow window)
- {
- _window = window ?? throw new ArgumentNullException(nameof(window));
-
- _window.RenderForm.MouseMove += Renderform_MouseMove;
- _window.RenderForm.MouseClick += RenderForm_MouseClick;
- _window.RenderForm.MouseDown += RenderForm_MouseDown;
- _window.RenderForm.MouseUp += RenderForm_MouseUp;
- _window.RenderForm.MouseWheel += RenderForm_MouseWheel;
-
- _window.RenderForm.KeyDown += RenderForm_KeyDown;
- _window.RenderForm.KeyUp += RenderForm_KeyUp;
- _window.RenderForm.KeyPress += RenderForm_KeyPress;
- }
-
- ///
- /// WinFormsInputDevice destructor.
- ///
- ~WinFormsInputDevice()
- {
- Dispose(false);
- }
-
- #region Device MouseInput
-
- ///
- /// TODO: CHECK LATER PERFORMANCE LIMIT MOUSE MOVE?
- ///
- /// Source of the event.
- /// Mouse event information.
- private void Renderform_MouseMove(object sender, MouseEventArgs e)
- {
- if (_mousePosition != e.Location)
- {
- _mousePosition = e.Location;
- MouseMove?.Invoke(e.X, e.Y, _pressedMouseButtons, e.Clicks, e.Delta);
- }
- }
-
- ///
- /// Event handler. Called by RenderForm for mouse wheel events.
- ///
- /// Source of the event.
- /// Mouse event information.
- private void RenderForm_MouseWheel(object sender, MouseEventArgs e)
- {
- MouseWheel?.Invoke(_mousePosition.X, _mousePosition.Y, _pressedMouseButtons, e.Clicks, e.Delta);
- }
-
- ///
- /// Event handler. Called by RenderForm for mouse up events.
- ///
- /// Source of the event.
- /// Mouse event information.
- private void RenderForm_MouseUp(object sender, MouseEventArgs e)
- {
- switch (e.Button)
- {
- case System.Windows.Forms.MouseButtons.Left:
- _pressedMouseButtons &= ~MouseButtons.Left;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Left, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Middle:
- _pressedMouseButtons &= ~MouseButtons.Middle;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Middle, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Right:
- _pressedMouseButtons &= ~MouseButtons.Right;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Right, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton1:
- _pressedMouseButtons &= ~MouseButtons.Button4;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button4, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton2:
- _pressedMouseButtons &= ~MouseButtons.Button5;
- MouseUp?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button5, e.Clicks, e.Delta);
- break;
- }
- }
-
- ///
- /// Event handler. Called by RenderForm for mouse down events.
- ///
- /// Source of the event.
- /// Mouse event information.
- private void RenderForm_MouseDown(object sender, MouseEventArgs e)
- {
- switch (e.Button)
- {
- case System.Windows.Forms.MouseButtons.Left:
- _pressedMouseButtons |= MouseButtons.Left;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Left, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Middle:
- _pressedMouseButtons |= MouseButtons.Middle;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Middle, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Right:
- _pressedMouseButtons |= MouseButtons.Right;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Right, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton1:
- _pressedMouseButtons |= MouseButtons.Button4;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button4, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton2:
- _pressedMouseButtons |= MouseButtons.Button5;
- MouseDown?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button5, e.Clicks, e.Delta);
- break;
- }
- }
-
- ///
- /// Event handler. Called by RenderForm for mouse click events.
- ///
- /// Source of the event.
- /// Mouse event information.
- private void RenderForm_MouseClick(object sender, MouseEventArgs e)
- {
- switch (e.Button)
- {
- case System.Windows.Forms.MouseButtons.Left:
- MouseClick?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Left, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Middle:
- MouseClick?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Middle, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.Right:
- MouseClick?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Right, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton1:
- MouseClick?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button4, e.Clicks, e.Delta);
- break;
- case System.Windows.Forms.MouseButtons.XButton2:
- MouseClick?.Invoke(_mousePosition.X, _mousePosition.Y, MouseButtons.Button5, e.Clicks, e.Delta);
- break;
- }
- }
-
- #endregion
-
- #region Device KeyboardInput
-
- ///
- /// Event handler. Called by RenderForm for key down events.
- ///
- /// Source of the event.
- /// Key event information.
- private void RenderForm_KeyDown(object sender, KeyEventArgs e)
- {
- if (_pressedKeys.Add(e.KeyValue))
- {
- KeyDown?.Invoke(e.KeyValue, e.Shift, e.Alt, e.Control);
- }
- }
-
- ///
- /// Event handler. Called by RenderForm for key press events.
- ///
- /// Source of the event.
- /// Key press event information.
- private void RenderForm_KeyPress(object sender, KeyPressEventArgs e)
- {
- KeyPress?.Invoke(e.KeyChar);
- }
-
- ///
- /// Event handler. Called by RenderForm for key up events.
- ///
- /// Source of the event.
- /// Key event information.
- private void RenderForm_KeyUp(object sender, KeyEventArgs e)
- {
- if (_pressedKeys.Remove(e.KeyValue))
- {
- KeyUp?.Invoke(e.KeyValue, e.Shift, e.Alt, e.Control);
- }
- }
-
- #endregion
-
- #region MouseHelper
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsMouseButtonDown(MouseButtons button)
- {
- return (_pressedMouseButtons & button) == button;
- }
-
- ///
- public bool IsMouseButtonDown(params MouseButtons[] buttons)
- {
- int l = buttons.Length;
- for (int i = 0; i < l; i++)
- {
- if (IsMouseButtonDown(buttons[i])) { return true; }
- }
- return false;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsMouseButtonUp(MouseButtons button)
- {
- return (_pressedMouseButtons & button) != button;
- }
-
- ///
- public bool IsMouseButtonUp(params MouseButtons[] buttons)
- {
- int l = buttons.Length;
- for (int i = 0; i < l; i++)
- {
- if (IsMouseButtonUp(buttons[i])) { return true; }
- }
- return false;
- }
-
- ///
- public void SetMousePosition(int x, int y)
- {
- if (_window?.RenderForm != null)
- {
- Cursor.Position = _window.RenderForm.PointToScreen(new Point(x, y));
- }
- }
-
- #endregion
-
- #region KeyboardHelper
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsKeyDown(int keyValue)
- {
- return _pressedKeys.Contains(keyValue);
- }
-
- ///
- public bool IsKeyDown(params int[] keyValues)
- {
- int l = keyValues.Length;
- for (int i = 0; i < l; i++)
- {
- if (_pressedKeys.Contains(keyValues[i])) { return true; }
- }
- return false;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsKeyUp(int keyValues)
- {
- return !_pressedKeys.Contains(keyValues);
- }
-
- ///
- public bool IsKeyUp(params int[] keyValues)
- {
- int l = keyValues.Length;
- for (int i = 0; i < l; i++)
- {
- if (!_pressedKeys.Contains(keyValues[i])) { return true; }
- }
- return false;
- }
-
- #endregion
-
- #region IDisposable Support
-
- ///
- /// True if disposed.
- ///
- private bool _disposed;
-
- ///
- /// Releases the unmanaged resources used by the Exomia.Framework.Input.WinFormsInputDevice
- /// and optionally releases the managed resources.
- ///
- ///
- /// True to release both managed and unmanaged resources; false to
- /// release only unmanaged resources.
- ///
- private void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- if (disposing)
- {
- if (_window != null)
- {
- _window.RenderForm.MouseMove -= Renderform_MouseMove;
- _window.RenderForm.MouseClick -= RenderForm_MouseClick;
- _window.RenderForm.MouseDown -= RenderForm_MouseDown;
- _window.RenderForm.MouseUp -= RenderForm_MouseUp;
- _window.RenderForm.MouseWheel -= RenderForm_MouseWheel;
-
- _window.RenderForm.KeyDown -= RenderForm_KeyDown;
- _window.RenderForm.KeyUp -= RenderForm_KeyUp;
- _window.RenderForm.KeyPress -= RenderForm_KeyPress;
- }
- }
-
- _disposed = true;
- }
- }
-
- ///
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/framework.wiki b/framework.wiki
index 78ac4c85..89a89a1e 160000
--- a/framework.wiki
+++ b/framework.wiki
@@ -1 +1 @@
-Subproject commit 78ac4c85b3b53ff132e267b4c6e38835aa17a094
+Subproject commit 89a89a1eb294ba8b9586b362e6c0c92c4451dcd0
diff --git a/Exomia.Framework/Activator.cs b/src/Exomia.Framework/Activator.cs
similarity index 98%
rename from Exomia.Framework/Activator.cs
rename to src/Exomia.Framework/Activator.cs
index d14e65f3..6e8cf696 100644
--- a/Exomia.Framework/Activator.cs
+++ b/src/Exomia.Framework/Activator.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -138,7 +138,7 @@ public static Creator GetCreator(params Type[] constructorParameters
///
public static Creator GetCreator(IEnumerable constructorParameters)
{
- return GetCreator(constructorParameters?.ToArray());
+ return GetCreator(constructorParameters.ToArray());
}
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Audio/AudioManager.cs b/src/Exomia.Framework/Audio/AudioManager.cs
similarity index 86%
rename from Exomia.Framework/Audio/AudioManager.cs
rename to src/Exomia.Framework/Audio/AudioManager.cs
index bb5ea5fa..904e2ae6 100644
--- a/Exomia.Framework/Audio/AudioManager.cs
+++ b/src/Exomia.Framework/Audio/AudioManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -34,84 +34,84 @@ public sealed class AudioManager : IAudioManager
private readonly Listener _listener;
///
- /// The bgm volume.
+ /// List of environment linked sounds.
///
- private float _bgmVolume = 1.0f;
+ private readonly LinkedSoundList _envLinkedSoundList;
///
- /// The current bgm.
+ /// The environment submix voice.
///
- private SourceVoice _currentBgm;
+ private readonly SubmixVoice _envSubmixVoice;
///
- /// List of environment linked sounds.
+ /// List of effects linked sounds.
///
- private LinkedSoundList _envLinkedSoundList;
+ private readonly LinkedSoundList _fxLinkedSoundList;
///
- /// The environment submix voice.
+ /// The effects submix voice.
///
- private SubmixVoice _envSubmixVoice;
+ private readonly SubmixVoice _fxSubmixVoice;
///
- /// Information describing the environment voice send.
+ /// The mastering voice.
///
- private VoiceSendDescriptor _envVoiceSendDescriptor;
+ private readonly MasteringVoice _masteringVoice;
///
- /// The environment volume.
+ /// Buffer for sound data.
///
- private float _envVolume = 1.0f;
+ private readonly Dictionary _soundBuffer;
///
- /// List of effects linked sounds.
+ /// The 3DAudio.
///
- private LinkedSoundList _fxLinkedSoundList;
+ private readonly X3DAudio _x3DAudio;
///
- /// The effects submix voice.
+ /// The XAudio2.
///
- private SubmixVoice _fxSubmixVoice;
+ private readonly XAudio2 _xAudio2;
///
- /// Information describing the effects voice send.
+ /// The bgm volume.
///
- private VoiceSendDescriptor _fxVoiceSendDescriptor;
+ private float _bgmVolume = 1.0f;
///
- /// The effects volume.
+ /// The current bgm.
///
- private float _fxVolume = 1.0f;
+ private SourceVoice? _currentBgm;
///
- /// The mastering voice.
+ /// Information describing the environment voice send.
///
- private MasteringVoice _masteringVoice;
+ private VoiceSendDescriptor _envVoiceSendDescriptor;
///
- /// The master volume.
+ /// The environment volume.
///
- private float _masterVolume = 0.5f;
+ private float _envVolume = 1.0f;
///
- /// Buffer for sound data.
+ /// Information describing the effects voice send.
///
- private Dictionary _soundBuffer;
+ private VoiceSendDescriptor _fxVoiceSendDescriptor;
///
- /// Zero-based index of the sound buffer.
+ /// The effects volume.
///
- private int _soundBufferIndex;
+ private float _fxVolume = 1.0f;
///
- /// The 3 d audio.
+ /// The master volume.
///
- private X3DAudio _x3DAudio;
+ private float _masterVolume = 0.5f;
///
- /// The second x coordinate audio.
+ /// Zero-based index of the sound buffer.
///
- private XAudio2 _xAudio2;
+ private int _soundBufferIndex;
///
public float BgmVolume
@@ -134,7 +134,7 @@ public float EnvironmentVolume
set
{
_envVolume = MathUtil.Clamp(value, 0.0f, 1.0f);
- _envSubmixVoice?.SetVolume(_envVolume);
+ _envSubmixVoice.SetVolume(_envVolume);
}
}
@@ -145,7 +145,7 @@ public float FxVolume
set
{
_fxVolume = MathUtil.Clamp(value, 0.0f, 1.0f);
- _fxSubmixVoice?.SetVolume(_fxVolume);
+ _fxSubmixVoice.SetVolume(_fxVolume);
}
}
@@ -156,7 +156,7 @@ public float MasterVolume
set
{
_masterVolume = MathUtil.Clamp(value, 0.0f, 1.0f);
- _masteringVoice?.SetVolume(_masterVolume);
+ _masteringVoice.SetVolume(_masterVolume);
}
}
@@ -183,18 +183,20 @@ public Vector3 ListenerVelocity
RecalculateEnvSounds();
}
}
-
+
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The listener.
/// The effects sound pool limit.
/// The speakers.
/// (Optional) Identifier for the device.
- /// Thrown when one or more arguments have unsupported or
- /// illegal values.
+ ///
+ /// Thrown when one or more arguments have unsupported or
+ /// illegal values.
+ ///
/// Thrown when an exception error condition occurs.
- public AudioManager(Listener listener, int fxSoundPoolLimit, Speakers speakers, string deviceID = null)
+ public AudioManager(Listener listener, int fxSoundPoolLimit, Speakers speakers, string? deviceID = null)
{
_listener = listener;
if (fxSoundPoolLimit <= 0)
@@ -217,18 +219,20 @@ public AudioManager(Listener listener, int fxSoundPoolLimit, Speakers speakers,
_masteringVoice = new MasteringVoice(
_xAudio2, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceID27);
}
+ else
+ {
+ _masteringVoice = new MasteringVoice(
+ _xAudio2, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceID);
+ }
}
else
{
_masteringVoice = new MasteringVoice(
_xAudio2, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceID);
}
- if (_masteringVoice == null)
- {
- throw new Exception("can't create MasteringVoice");
- }
_masteringVoice.SetVolume(_masterVolume);
- _x3DAudio = new X3DAudio(speakers, X3DAudio.SpeedOfSound / 1000f);
+
+ _x3DAudio = new X3DAudio(speakers, X3DAudio.SpeedOfSound);
_masteringVoice.GetVoiceDetails(out VoiceDetails details);
_inputChannelCount = details.InputChannelCount;
@@ -295,16 +299,22 @@ public void PauseFxSounds()
}
///
- public void PlayEnvSound(int soundID, Vector3 emitterPos, float volume, float maxDistance,
- Action onFxEnd = null)
+ public void PlayEnvSound(int soundID,
+ Vector3 emitterPos,
+ float volume,
+ float maxDistance,
+ Action? onFxEnd = null)
{
PlaySound(
soundID, emitterPos, volume, maxDistance, _envLinkedSoundList, ref _envVoiceSendDescriptor, onFxEnd);
}
///
- public void PlayFxSound(int soundID, Vector3 emitterPos, float volume, float maxDistance,
- Action onFxEnd = null)
+ public void PlayFxSound(int soundID,
+ Vector3 emitterPos,
+ float volume,
+ float maxDistance,
+ Action? onFxEnd = null)
{
if (_fxLinkedSoundList.Count >= _fxLinkedSoundList.Capacity)
{
@@ -315,13 +325,13 @@ public void PlayFxSound(int soundID, Vector3 emitterPos, float volume
}
///
- public void PlayEnvSound(int soundID, Emitter emitter, float volume, Action onFxEnd = null)
+ public void PlayEnvSound(int soundID, Emitter emitter, float volume, Action? onFxEnd = null)
{
PlaySound(soundID, emitter, volume, _envLinkedSoundList, ref _envVoiceSendDescriptor, onFxEnd);
}
///
- public void PlayFxSound(int soundID, Emitter emitter, float volume, Action onFxEnd = null)
+ public void PlayFxSound(int soundID, Emitter emitter, float volume, Action? onFxEnd = null)
{
if (_fxLinkedSoundList.Count >= _fxLinkedSoundList.Capacity)
{
@@ -358,7 +368,7 @@ public void ResumeFxSounds()
}
///
- public void RunBgm(int songID, Action onBgmEnd = null)
+ public void RunBgm(int songID, Action? onBgmEnd = null)
{
if (!_soundBuffer.TryGetValue(songID, out SoundBuffer buffer))
{
@@ -443,9 +453,13 @@ public bool UnloadSound(int soundID)
/// The list.
/// [in,out] Information describing the voice send.
/// (Optional) The on effects end.
- private void PlaySound(int soundID, Vector3 emitterPos, float volume,
- float maxDistance, LinkedSoundList list,
- ref VoiceSendDescriptor voiceSendDescriptor, Action onFxEnd = null)
+ private void PlaySound(int soundID,
+ Vector3 emitterPos,
+ float volume,
+ float maxDistance,
+ LinkedSoundList list,
+ ref VoiceSendDescriptor voiceSendDescriptor,
+ Action? onFxEnd = null)
{
PlaySound(
soundID,
@@ -475,9 +489,12 @@ private void PlaySound(int soundID, Vector3
/// The list.
/// [in,out] Information describing the voice send.
/// (Optional) The on effects end.
- private void PlaySound(int soundID, Emitter emitter, float volume,
+ private void PlaySound(int soundID,
+ Emitter emitter,
+ float volume,
LinkedSoundList list,
- ref VoiceSendDescriptor voiceSendDescriptor, Action onFxEnd = null)
+ ref VoiceSendDescriptor voiceSendDescriptor,
+ Action? onFxEnd = null)
{
if (!_soundBuffer.TryGetValue(soundID, out SoundBuffer buffer))
{
@@ -604,30 +621,21 @@ private void Dispose(bool disposing)
_currentBgm?.Dispose();
_currentBgm = null;
- _fxLinkedSoundList?.Clear();
- _fxLinkedSoundList = null;
-
- _envLinkedSoundList?.Clear();
- _envLinkedSoundList = null;
+ _fxLinkedSoundList.Clear();
+ _envLinkedSoundList.Clear();
UnloadAll();
- _soundBuffer = null;
- _fxSubmixVoice?.DestroyVoice();
- _fxSubmixVoice?.Dispose();
- _fxSubmixVoice = null;
+ _fxSubmixVoice.DestroyVoice();
+ _fxSubmixVoice.Dispose();
- _envSubmixVoice?.DestroyVoice();
- _envSubmixVoice?.Dispose();
- _envSubmixVoice = null;
+ _envSubmixVoice.DestroyVoice();
+ _envSubmixVoice.Dispose();
- _masteringVoice?.DestroyVoice();
- _masteringVoice?.Dispose();
- _masteringVoice = null;
+ _masteringVoice.DestroyVoice();
+ _masteringVoice.Dispose();
- _xAudio2?.Dispose();
- _xAudio2 = null;
- _x3DAudio = null;
+ _xAudio2.Dispose();
}
_disposed = true;
diff --git a/Exomia.Framework/Audio/IAudioManager.cs b/src/Exomia.Framework/Audio/IAudioManager.cs
similarity index 88%
rename from Exomia.Framework/Audio/IAudioManager.cs
rename to src/Exomia.Framework/Audio/IAudioManager.cs
index eb033e12..f55841e3 100644
--- a/Exomia.Framework/Audio/IAudioManager.cs
+++ b/src/Exomia.Framework/Audio/IAudioManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -100,8 +100,11 @@ public interface IAudioManager : IDisposable
/// volume.
/// max distance to hear the sound.
/// (Optional) called than the sound ends.
- void PlayEnvSound(int soundID, Vector3 emitterPos, float volume, float maxDistance,
- Action onFxEnd = null);
+ void PlayEnvSound(int soundID,
+ Vector3 emitterPos,
+ float volume,
+ float maxDistance,
+ Action? onFxEnd = null);
///
/// play a fx sound.
@@ -111,8 +114,11 @@ void PlayEnvSound(int soundID, Vector3 emitterPos, float volume, floa
/// volume.
/// max distance to hear the sound.
/// (Optional) called than the sound ends.
- void PlayFxSound(int soundID, Vector3 emitterPos, float volume, float maxDistance,
- Action onFxEnd = null);
+ void PlayFxSound(int soundID,
+ Vector3 emitterPos,
+ float volume,
+ float maxDistance,
+ Action? onFxEnd = null);
///
/// play an environment sound.
@@ -121,7 +127,7 @@ void PlayFxSound(int soundID, Vector3 emitterPos, float volume, float
/// the emitter.
/// volume.
/// (Optional) called than the sound ends.
- void PlayEnvSound(int soundID, Emitter emitter, float volume, Action onFxEnd = null);
+ void PlayEnvSound(int soundID, Emitter emitter, float volume, Action? onFxEnd = null);
///
/// play a fx sound.
@@ -130,7 +136,7 @@ void PlayFxSound(int soundID, Vector3 emitterPos, float volume, float
/// the emitter.
/// volume.
/// (Optional) called than the sound ends.
- void PlayFxSound(int soundID, Emitter emitter, float volume, Action onFxEnd = null);
+ void PlayFxSound(int soundID, Emitter emitter, float volume, Action? onFxEnd = null);
///
/// resume a bgm song.
@@ -152,7 +158,7 @@ void PlayFxSound(int soundID, Vector3 emitterPos, float volume, float
///
/// the song id.
/// (Optional) called than the song ends.
- void RunBgm(int songID, Action onBgmEnd = null);
+ void RunBgm(int songID, Action? onBgmEnd = null);
///
/// stop a bgm song.
diff --git a/Exomia.Framework/Audio/LinkedSoundList.cs b/src/Exomia.Framework/Audio/LinkedSoundList.cs
similarity index 94%
rename from Exomia.Framework/Audio/LinkedSoundList.cs
rename to src/Exomia.Framework/Audio/LinkedSoundList.cs
index 59fc852b..b08a1055 100644
--- a/Exomia.Framework/Audio/LinkedSoundList.cs
+++ b/src/Exomia.Framework/Audio/LinkedSoundList.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -34,7 +34,7 @@ sealed class LinkedSoundList : IEnumerable
///
/// The head.
///
- private Sound _head;
+ private Sound? _head;
///
/// Number of.
@@ -114,8 +114,8 @@ public void Add(Sound sound)
sound.Next = _head;
sound.Previous = _head.Previous;
- _head.Previous.Next = sound;
- _head.Previous = sound;
+ _head.Previous!.Next = sound;
+ _head.Previous = sound;
}
_count++;
@@ -147,8 +147,8 @@ public void Remove(Sound sound)
if (sound.Next == sound) { _head = null; }
else
{
- sound.Previous.Next = sound.Next;
- sound.Next.Previous = sound.Previous;
+ sound.Previous!.Next = sound.Next;
+ sound.Next!.Previous = sound.Previous;
if (_head == sound) { _head = sound.Next; }
}
sound.Invalidate();
@@ -183,12 +183,12 @@ public struct Enumerator : IEnumerator
///
/// The node.
///
- private Sound _current, _node;
+ private Sound? _current, _node;
///
public Sound Current
{
- get { return _current; }
+ get { return _current!; }
}
///
@@ -253,12 +253,12 @@ internal sealed class Sound
///
/// The next.
///
- internal Sound Next;
+ internal Sound? Next;
///
/// The previous.
///
- internal Sound Previous;
+ internal Sound? Previous;
///
/// Initializes a new instance of the class.
diff --git a/Exomia.Framework/Buffers/ArrayPool.cs b/src/Exomia.Framework/Buffers/ArrayPool.cs
similarity index 92%
rename from Exomia.Framework/Buffers/ArrayPool.cs
rename to src/Exomia.Framework/Buffers/ArrayPool.cs
index fd2c8b89..035a6f11 100644
--- a/Exomia.Framework/Buffers/ArrayPool.cs
+++ b/src/Exomia.Framework/Buffers/ArrayPool.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -30,12 +30,12 @@ public sealed class ArrayPool
///
/// The buffers.
///
- private readonly T[][] _buffers;
+ private readonly T[]?[] _buffers;
///
/// The lock.
///
- private readonly SpinLock _lock;
+ private SpinLock _lock;
///
/// The index.
@@ -53,7 +53,7 @@ public sealed class ArrayPool
///
public ArrayPool(int bufferLength, int numberOfBuffers = 10)
{
- if (bufferLength <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferLength)); }
+ if (bufferLength <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferLength)); }
if (numberOfBuffers <= 0) { throw new ArgumentOutOfRangeException(nameof(numberOfBuffers)); }
_bufferLength = bufferLength;
@@ -67,9 +67,9 @@ public ArrayPool(int bufferLength, int numberOfBuffers = 10)
///
/// A T[].
///
- public T[] Rent()
+ public T[]? Rent()
{
- T[] buffer = null;
+ T[]? buffer = null;
bool lockTaken = false;
try
diff --git a/Exomia.Framework/Buffers/CircularBuffer.cs b/src/Exomia.Framework/Buffers/CircularBuffer.cs
similarity index 97%
rename from Exomia.Framework/Buffers/CircularBuffer.cs
rename to src/Exomia.Framework/Buffers/CircularBuffer.cs
index c9e0b578..3580f00e 100644
--- a/Exomia.Framework/Buffers/CircularBuffer.cs
+++ b/src/Exomia.Framework/Buffers/CircularBuffer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -29,7 +29,7 @@ public class CircularBuffer
///
/// this lock.
///
- private readonly SpinLock _thisLock;
+ private SpinLock _thisLock;
///
/// The head.
@@ -94,7 +94,7 @@ public T this[int index]
index = (_tail + index) % _buffer.Length;
T buffer = _buffer[index];
- _buffer[index] = default;
+ _buffer[index] = default!;
return buffer;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -120,7 +120,7 @@ public T this[int index]
/// Thrown when one or more arguments have unsupported or
/// illegal values.
///
- public CircularBuffer(int capacity = 1024, T[] items = null)
+ public CircularBuffer(int capacity = 1024, T[] items = null!)
{
if (capacity < 1)
{
@@ -175,7 +175,7 @@ public T Get()
}
T item = _buffer[_tail];
- _buffer[_tail] = default;
+ _buffer[_tail] = default!;
_tail = (_tail + 1) % _buffer.Length;
_size--;
@@ -207,7 +207,7 @@ public ref T GetR()
}
ref T item = ref _buffer[_tail];
- _buffer[_tail] = default;
+ _buffer[_tail] = default!;
_tail = (_tail + 1) % _buffer.Length;
_size--;
diff --git a/Exomia.Framework/Buffers/CircularBuffer2.cs b/src/Exomia.Framework/Buffers/CircularBuffer2.cs
similarity index 97%
rename from Exomia.Framework/Buffers/CircularBuffer2.cs
rename to src/Exomia.Framework/Buffers/CircularBuffer2.cs
index 0c918a56..d04eec34 100644
--- a/Exomia.Framework/Buffers/CircularBuffer2.cs
+++ b/src/Exomia.Framework/Buffers/CircularBuffer2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -36,7 +36,7 @@ public class CircularBuffer2
///
/// this lock.
///
- private readonly SpinLock _thisLock;
+ private SpinLock _thisLock;
///
/// The head.
@@ -100,7 +100,7 @@ public T this[int index]
}
index = (_tail + index) & _mask;
T buffer = _buffer[index];
- _buffer[index] = default;
+ _buffer[index] = default!;
return buffer;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -126,7 +126,7 @@ public T this[int index]
/// Thrown when one or more arguments have unsupported or
/// illegal values.
///
- public CircularBuffer2(int capacity = 1024, T[] items = null)
+ public CircularBuffer2(int capacity = 1024, T[]? items = null)
{
if (capacity < 1)
{
@@ -185,7 +185,7 @@ public T Get()
int index = _tail++ & _mask;
T item = _buffer[index];
- _buffer[index] = default;
+ _buffer[index] = default!;
_size--;
return item;
@@ -217,7 +217,7 @@ public ref T GetR()
int index = _tail++ & _mask;
ref T item = ref _buffer[index];
- _buffer[index] = default;
+ _buffer[index] = default!;
_size--;
return ref item;
diff --git a/Exomia.Framework/Collections/LinkedList.cs b/src/Exomia.Framework/Collections/LinkedList.cs
similarity index 92%
rename from Exomia.Framework/Collections/LinkedList.cs
rename to src/Exomia.Framework/Collections/LinkedList.cs
index 90d6e80d..cbe88b91 100644
--- a/Exomia.Framework/Collections/LinkedList.cs
+++ b/src/Exomia.Framework/Collections/LinkedList.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -23,7 +23,7 @@ public sealed class LinkedList : IEnumerable
///
/// The head.
///
- private LinkedListNode _head;
+ private LinkedListNode? _head;
///
/// Gets the number of.
@@ -39,7 +39,7 @@ public sealed class LinkedList : IEnumerable
///
/// The first.
///
- public LinkedListNode First
+ public LinkedListNode? First
{
get { return _head; }
}
@@ -50,7 +50,7 @@ public LinkedListNode First
///
/// The last.
///
- public LinkedListNode Last
+ public LinkedListNode? Last
{
get { return _head?.Previous; }
}
@@ -112,8 +112,8 @@ public LinkedListNode AddFirst(in T item)
node.Next = _head;
node.Previous = _head.Previous;
- _head.Previous.Next = node;
- _head.Previous = node;
+ _head.Previous!.Next = node;
+ _head.Previous = node;
_head = node;
}
@@ -142,8 +142,8 @@ public LinkedListNode AddLast(in T item)
node.Next = _head;
node.Previous = _head.Previous;
- _head.Previous.Next = node;
- _head.Previous = node;
+ _head.Previous!.Next = node;
+ _head.Previous = node;
}
Count++;
return node;
@@ -172,7 +172,7 @@ public IEnumerable AsEnumerable()
do
{
yield return node;
- node = node.Next;
+ node = node.Next!;
} while (node != _head);
}
}
@@ -189,7 +189,7 @@ public void ForEach(Action action)
do
{
action(node);
- node = node.Next;
+ node = node.Next!;
} while (node != _head);
}
}
@@ -205,8 +205,8 @@ public void Remove(LinkedListNode node)
if (node.Next == node) { _head = null; }
else
{
- node.Previous.Next = node.Next;
- node.Next.Previous = node.Previous;
+ node.Previous!.Next = node.Next;
+ node.Next!.Previous = node.Previous;
if (_head == node) { _head = node.Next; }
}
node.Invalidate();
@@ -230,7 +230,7 @@ public void RemoveFirst()
public void RemoveLast()
{
if (_head == null) { throw new InvalidOperationException("the linked list is empty."); }
- Remove(_head.Previous);
+ Remove(_head.Previous!);
}
///
@@ -260,7 +260,7 @@ public sealed class LinkedListNode
///
/// The next.
///
- public LinkedListNode Next { get; internal set; }
+ public LinkedListNode? Next { get; internal set; }
///
/// Gets the previous.
@@ -268,7 +268,7 @@ public sealed class LinkedListNode
///
/// The previous.
///
- public LinkedListNode Previous { get; internal set; }
+ public LinkedListNode? Previous { get; internal set; }
///
/// Initializes a new instance of the class.
@@ -314,7 +314,7 @@ public struct Enumerator : IEnumerator
///
/// The node.
///
- private LinkedListNode _node;
+ private LinkedListNode? _node;
///
/// The current.
@@ -330,7 +330,7 @@ public T Current
///
object IEnumerator.Current
{
- get { return Current; }
+ get { return Current!; }
}
///
@@ -341,7 +341,7 @@ public Enumerator(LinkedList list)
{
_list = list;
_node = list._head;
- _current = default;
+ _current = default!;
}
///
@@ -363,7 +363,7 @@ public bool MoveNext()
///
public void Reset()
{
- _current = default;
+ _current = default!;
_node = _list._head;
}
diff --git a/Exomia.Framework/Collections/List.cs b/src/Exomia.Framework/Collections/List.cs
similarity index 80%
rename from Exomia.Framework/Collections/List.cs
rename to src/Exomia.Framework/Collections/List.cs
index 050fe2a3..a3809489 100644
--- a/Exomia.Framework/Collections/List.cs
+++ b/src/Exomia.Framework/Collections/List.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -37,7 +37,7 @@ public sealed class List
private static readonly T[] s_emptyArray = new T[0];
///
- /// The size of.
+ /// The size of T in bytes.
///
private readonly int _sizeOf;
@@ -49,10 +49,7 @@ public sealed class List
///
/// Sets the capacity.
///
- ///
- /// Thrown when one or more arguments are outside
- /// the required range.
- ///
+ /// Thrown when one or more arguments are outside the required range.
///
/// The capacity.
///
@@ -80,7 +77,7 @@ public int Capacity
}
///
- /// Gets the number of.
+ /// Gets the number of items in the list.
///
///
/// The count.
@@ -163,6 +160,7 @@ public List(int capacity)
/// Thrown when one or more required arguments are null.
public List(IEnumerable collection)
{
+ // ReSharper disable once ConvertIfStatementToSwitchStatement
if (collection == null) { throw new ArgumentNullException(nameof(collection)); }
if (collection is ICollection c)
{
@@ -180,43 +178,32 @@ public List(IEnumerable collection)
Count = 0;
_items = s_emptyArray;
- using (IEnumerator en = collection.GetEnumerator())
+ using IEnumerator en = collection.GetEnumerator();
+ while (en.MoveNext())
{
- while (en.MoveNext())
- {
- Add(en.Current);
- }
+ Add(en.Current);
}
}
}
///
- /// Adds item.
+ /// Adds the item to the end of the list.
///
- /// The item to remove.
+ /// The item to add to the end of the list.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(in T item)
{
- if (Count == _items.Length) { EnsureCapacity(Count + 1); }
- _items[Count++] = item;
+ Insert(Count, item);
}
///
- /// Adds a range to 'items'.
+ /// Adds a range of items to the end of the list.
///
- /// Zero-based index of the.
- /// The items.
+ /// The items to add to the end of the list.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void AddRange(int index, T[] items)
+ public void AddRange(T[] items)
{
- if (Count + items.Length == _items.Length) { EnsureCapacity(Count + items.Length); }
- if (index < Count)
- {
- Buffer.BlockCopy(
- _items, index, _items, index + items.Length, (Count - (index + items.Length)) * _sizeOf);
- }
- Buffer.BlockCopy(items, 0, _items, index, items.Length * _sizeOf);
- Count += items.Length;
+ InsertRange(Count, items);
}
///
@@ -235,7 +222,7 @@ public void Clear()
///
/// Query if this object contains the given item.
///
- /// The item to remove.
+ /// The item to look for.
///
/// True if the object is in this collection, false if not.
///
@@ -251,7 +238,7 @@ public bool Contains(in T item)
}
for (int i = 0; i < Count; ++i)
{
- if (_items[i].Equals(item)) { return true; }
+ if (_items[i]?.Equals(item) ?? false) { return true; }
}
return false;
}
@@ -259,7 +246,7 @@ public bool Contains(in T item)
///
/// Gets a reference t using the given index.
///
- /// Zero-based index of the.
+ /// Zero-based index of the item to get.
///
/// A ref T.
///
@@ -272,7 +259,7 @@ public ref T Get(int index)
///
/// Gets a reference t using the given index.
///
- /// Zero-based index of the.
+ /// Zero-based index of the item to get.
///
/// A ref T.
///
@@ -285,7 +272,7 @@ public ref T Get(uint index)
///
/// Finds the range of the given arguments.
///
- /// Zero-based index of the.
+ /// Zero-based index to start copying from.
/// Number of.
///
/// The calculated range.
@@ -302,7 +289,7 @@ public List GetRange(int index, int count)
///
/// Searches for the first match.
///
- /// The item to remove.
+ /// The item to find the index of.
///
/// An int.
///
@@ -315,8 +302,8 @@ public int IndexOf(in T item)
///
/// Searches for the first match.
///
- /// The item to remove.
- /// Zero-based index of the.
+ /// The item to find the index of.
+ /// Zero-based index to start searching from.
///
/// An int.
///
@@ -329,9 +316,9 @@ public int IndexOf(in T item, int index)
///
/// Searches for the first match.
///
- /// The item to remove.
- /// Zero-based index of the.
- /// Number of.
+ /// The item to find the index of.
+ /// Zero-based index to start searching from.
+ /// Number of the search range.
///
/// An int.
///
@@ -342,23 +329,37 @@ public int IndexOf(in T item, int index, int count)
}
///
- /// Inserts.
+ /// Inserts the item into the list.
///
- /// Zero-based index of the.
- /// The item to remove.
+ /// Zero-based index to insert the item.
+ /// The item to insert at index.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Insert(int index, in T item)
{
- if (Count == _items.Length) { EnsureCapacity(Count + 1); }
- if (index < Count) { Buffer.BlockCopy(_items, index, _items, index + 1, (Count - index) * _sizeOf); }
- _items[index] = item;
- Count++;
+ if (index >= _items.Length) { EnsureCapacity(Count + 1); }
+ if (index < Count) { Array.Copy(_items, index, _items, index + 1, Count - index); }
+ _items[index] = item;
+ Count += 1;
+ }
+
+ ///
+ /// Inserts the range of items into the list.
+ ///
+ /// Zero-based index to start inserting at.
+ /// The items to insert at index.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void InsertRange(int index, T[] items)
+ {
+ if (index + items.Length >= _items.Length) { EnsureCapacity(Count + items.Length); }
+ if (index < Count) { Array.Copy(_items, index, _items, index + _items.Length, Count - index); }
+ Buffer.BlockCopy(items, 0, _items, index, items.Length * _sizeOf);
+ Count += _items.Length;
}
///
/// Searches for the last match.
///
- /// The item to remove.
+ /// The item to find the last index of.
///
/// An int.
///
@@ -371,8 +372,8 @@ public int LastIndexOf(in T item)
///
/// Searches for the last match.
///
- /// The item to remove.
- /// Zero-based index of the.
+ /// The item to find the last index of.
+ /// Zero-based index to start searching from.
///
/// An int.
///
@@ -385,9 +386,9 @@ public int LastIndexOf(in T item, int index)
///
/// Searches for the last match.
///
- /// The item to remove.
- /// Zero-based index of the.
- /// Number of.
+ /// The item to find the last index of.
+ /// Zero-based index to start searching from.
+ /// Number of the search range.
///
/// An int.
///
@@ -419,30 +420,27 @@ public bool Remove(in T item)
///
/// Removes at described by index.
///
- /// Zero-based index of the.
+ /// Zero-based index of the item to remove.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RemoveAt(int index)
{
Count--;
- if (index < Count) { Buffer.BlockCopy(_items, index + 1, _items, index, (Count - index) * _sizeOf); }
- _items[Count] = default;
+ if (index < Count) { Array.Copy(_items, index + 1, _items, index, Count - index); }
+ _items[Count] = default!;
}
///
/// Removes the range.
///
- /// Zero-based index of the.
- /// Number of.
+ /// Zero-based index of the items to remove.
+ /// Number of items to remove.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RemoveRange(int index, int count)
{
if (count > 0)
{
Count -= count;
- if (index < Count)
- {
- Buffer.BlockCopy(_items, index + count, _items, index, (Count - index) * _sizeOf);
- }
+ if (index < Count) { Array.Copy(_items, index + count, _items, index, Count - index); }
Array.Clear(_items, Count, count);
}
}
@@ -473,7 +471,7 @@ public void Reverse(int index, int count)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Sort()
{
- Sort(0, Count, null);
+ Sort(0, Count, null!);
}
///
diff --git a/Exomia.Framework/Component.cs b/src/Exomia.Framework/Component.cs
similarity index 93%
rename from Exomia.Framework/Component.cs
rename to src/Exomia.Framework/Component.cs
index de9e73c8..8d034ec3 100644
--- a/Exomia.Framework/Component.cs
+++ b/src/Exomia.Framework/Component.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -8,6 +8,8 @@
#endregion
+#pragma warning disable IDE0069
+
using System;
using Exomia.Framework.Game;
using SharpDX;
@@ -22,12 +24,12 @@ public abstract class Component : IComponent, IInitializable, IContentable, IUpd
///
/// Occurs when Enabled Changed.
///
- public event EventHandler EnabledChanged;
+ public event EventHandler? EnabledChanged;
///
/// Occurs when Update Order Changed.
///
- public event EventHandler UpdateOrderChanged;
+ public event EventHandler? UpdateOrderChanged;
///
/// flag to identify if the component is already initialized.
@@ -42,7 +44,7 @@ public abstract class Component : IComponent, IInitializable, IContentable, IUpd
///
/// The collector.
///
- private DisposeCollector _collector;
+ private readonly DisposeCollector _collector;
///
/// True to enable, false to disable.
@@ -187,12 +189,7 @@ private void Dispose(bool disposing)
if (!_disposed)
{
OnDispose(disposing);
- if (disposing)
- {
- /* USER CODE */
- _collector.DisposeAndClear();
- _collector = null;
- }
+ _collector.DisposeAndClear(disposing);
_disposed = true;
}
}
diff --git a/Exomia.Framework/Components/DebugComponent.cs b/src/Exomia.Framework/Components/DebugComponent.cs
similarity index 90%
rename from Exomia.Framework/Components/DebugComponent.cs
rename to src/Exomia.Framework/Components/DebugComponent.cs
index d14aca91..e0d06a84 100644
--- a/Exomia.Framework/Components/DebugComponent.cs
+++ b/src/Exomia.Framework/Components/DebugComponent.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -40,7 +40,7 @@ public class DebugComponent : DrawableComponent
///
/// The arial 12 px.
///
- private SpriteFont _arial12Px;
+ private SpriteFont? _arial12Px;
///
/// Information describing the CPU.
@@ -55,12 +55,12 @@ public class DebugComponent : DrawableComponent
///
/// The first CPU performance counter.
///
- private PerformanceCounter _cpuPerformanceCounter1;
+ private PerformanceCounter? _cpuPerformanceCounter1;
///
/// The second CPU performance counter.
///
- private PerformanceCounter _cpuPerformanceCounter2;
+ private PerformanceCounter? _cpuPerformanceCounter2;
///
/// The elapsed time.
@@ -90,7 +90,7 @@ public class DebugComponent : DrawableComponent
///
/// The game window.
///
- private IGameWindow _gameWindow;
+ private IGameWindow? _gameWindow;
///
/// Name of the GPU.
@@ -130,7 +130,7 @@ public class DebugComponent : DrawableComponent
///
/// The first ram performance counter.
///
- private PerformanceCounter _ramPerformanceCounter1;
+ private PerformanceCounter? _ramPerformanceCounter1;
///
/// Buffer for sample data.
@@ -145,7 +145,7 @@ public class DebugComponent : DrawableComponent
///
/// The sprite batch.
///
- private SpriteBatch _spriteBatch;
+ private SpriteBatch? _spriteBatch;
///
/// The title.
@@ -199,18 +199,18 @@ public override void Draw(GameTime gameTime)
if (!_firstCalc) { return; }
if (EnableTitleInformation)
{
- _gameWindow.Title = _title + " " + _fpsInfo;
+ _gameWindow!.Title = _title + " " + _fpsInfo;
}
- _spriteBatch.Begin();
+ _spriteBatch!.Begin();
if (ShowFullInformation)
{
- _spriteBatch.DrawText(_arial12Px, $"{_cpuInfo}\n\n{_ramInfo}", _position1, Color.White, 0.0f);
+ _spriteBatch.DrawText(_arial12Px!, $"{_cpuInfo}\n\n{_ramInfo}", _position1, Color.White, 0.0f);
}
_spriteBatch.DrawText(
- _arial12Px, _fpsInfo, _position2, _fpsCurrent <= FRAME_DANGER_THRESHOLD ? Color.Red : Color.White,
+ _arial12Px!, _fpsInfo, _position2, _fpsCurrent <= FRAME_DANGER_THRESHOLD ? Color.Red : Color.White,
0.0f);
_spriteBatch.End();
@@ -237,10 +237,10 @@ public override void Update(GameTime gameTime)
{
if (ShowFullInformation)
{
- _totalMemoryBytes = _ramPerformanceCounter1.NextValue();
+ _totalMemoryBytes = _ramPerformanceCounter1!.NextValue();
- _processorLoadT1 = _cpuPerformanceCounter1.NextValue() / Environment.ProcessorCount;
- _processorLoadT2 = _cpuPerformanceCounter2.NextValue();
+ _processorLoadT1 = _cpuPerformanceCounter1!.NextValue() / Environment.ProcessorCount;
+ _processorLoadT2 = _cpuPerformanceCounter2!.NextValue();
_cpuInfo = $"{_cpuName}\nCPU-Load: {_processorLoadT1:0.0}% Total: {_processorLoadT2:0.0}%";
_ramInfo =
diff --git a/Exomia.Framework/Content/ContentManager.cs b/src/Exomia.Framework/Content/ContentManager.cs
similarity index 98%
rename from Exomia.Framework/Content/ContentManager.cs
rename to src/Exomia.Framework/Content/ContentManager.cs
index 8eba0b08..18906ed8 100644
--- a/Exomia.Framework/Content/ContentManager.cs
+++ b/src/Exomia.Framework/Content/ContentManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -62,7 +62,7 @@ public sealed class ContentManager : IContentManager
///
/// Pathname of the root directory.
///
- private string _rootDirectory;
+ private string _rootDirectory = string.Empty;
///
public string RootDirectory
@@ -307,7 +307,6 @@ public void Unload()
if (loadedAsset is IDisposable disposable)
{
disposable.Dispose();
- disposable = null;
}
}
@@ -354,7 +353,6 @@ public bool Unload(Type assetType, string assetName)
if (asset is IDisposable disposable)
{
disposable.Dispose();
- disposable = null;
}
return true;
@@ -392,14 +390,14 @@ private Stream ResolveStream(string assetName)
$"No {nameof(IContentResolver)} registered to this content manager");
}
- Exception lastException = null;
+ Exception? lastException = null;
foreach (IContentResolver contentResolver in resolvers)
{
try
{
if (contentResolver.Exists(assetName))
{
- Stream stream = contentResolver.Resolve(assetName);
+ Stream? stream = contentResolver.Resolve(assetName);
if (stream != null) { return stream; }
}
}
@@ -436,14 +434,14 @@ private Stream ResolveEmbeddedResourceStream(Type assetType, string assetName)
$"No {nameof(IEmbeddedResourceResolver)} registered to this content manager");
}
- Exception lastException = null;
+ Exception? lastException = null;
foreach (IEmbeddedResourceResolver contentResolver in resolvers)
{
try
{
if (contentResolver.Exists(assetType, assetName, out Assembly assembly))
{
- Stream stream = contentResolver.Resolve(assembly, assetName);
+ Stream? stream = contentResolver.Resolve(assembly, assetName);
if (stream != null) { return stream; }
}
}
diff --git a/Exomia.Framework/Content/ContentReadableAttribute.cs b/src/Exomia.Framework/Content/ContentReadableAttribute.cs
similarity index 97%
rename from Exomia.Framework/Content/ContentReadableAttribute.cs
rename to src/Exomia.Framework/Content/ContentReadableAttribute.cs
index 7de1e85c..841b8764 100644
--- a/Exomia.Framework/Content/ContentReadableAttribute.cs
+++ b/src/Exomia.Framework/Content/ContentReadableAttribute.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/ContentReaderParameters.cs b/src/Exomia.Framework/Content/ContentReaderParameters.cs
similarity index 97%
rename from Exomia.Framework/Content/ContentReaderParameters.cs
rename to src/Exomia.Framework/Content/ContentReaderParameters.cs
index ed92362c..efae4863 100644
--- a/Exomia.Framework/Content/ContentReaderParameters.cs
+++ b/src/Exomia.Framework/Content/ContentReaderParameters.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs b/src/Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs
similarity index 92%
rename from Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs
rename to src/Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs
index 2167d1cc..e08e6509 100644
--- a/Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs
+++ b/src/Exomia.Framework/Content/Exceptions/AssetNotFoundException.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -41,7 +41,7 @@ public AssetNotFoundException(string message)
///
/// The exception message.
/// The inner exception.
- public AssetNotFoundException(string message, Exception innerException)
+ public AssetNotFoundException(string message, Exception? innerException)
: base(message, innerException) { }
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/IContentManager.cs b/src/Exomia.Framework/Content/IContentManager.cs
similarity index 99%
rename from Exomia.Framework/Content/IContentManager.cs
rename to src/Exomia.Framework/Content/IContentManager.cs
index 9ebdbff2..d16e8aea 100644
--- a/Exomia.Framework/Content/IContentManager.cs
+++ b/src/Exomia.Framework/Content/IContentManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/IContentReader.cs b/src/Exomia.Framework/Content/IContentReader.cs
similarity index 85%
rename from Exomia.Framework/Content/IContentReader.cs
rename to src/Exomia.Framework/Content/IContentReader.cs
index d7a44ceb..7d6965ff 100644
--- a/Exomia.Framework/Content/IContentReader.cs
+++ b/src/Exomia.Framework/Content/IContentReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -24,6 +24,6 @@ public interface IContentReader
/// The data decoded from the stream, or null if the kind of asset is not supported by this
/// content reader.
///
- object ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters);
+ object? ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/IContentReaderFactory.cs b/src/Exomia.Framework/Content/IContentReaderFactory.cs
similarity index 96%
rename from Exomia.Framework/Content/IContentReaderFactory.cs
rename to src/Exomia.Framework/Content/IContentReaderFactory.cs
index 1b9615dd..502df6f6 100644
--- a/Exomia.Framework/Content/IContentReaderFactory.cs
+++ b/src/Exomia.Framework/Content/IContentReaderFactory.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/ITexture2ContentManager.cs b/src/Exomia.Framework/Content/ITexture2ContentManager.cs
similarity index 98%
rename from Exomia.Framework/Content/ITexture2ContentManager.cs
rename to src/Exomia.Framework/Content/ITexture2ContentManager.cs
index 7d10ccd4..85b25d8b 100644
--- a/Exomia.Framework/Content/ITexture2ContentManager.cs
+++ b/src/Exomia.Framework/Content/ITexture2ContentManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs b/src/Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs
similarity index 96%
rename from Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs
rename to src/Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs
index 572a01b8..28277a8e 100644
--- a/Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs
+++ b/src/Exomia.Framework/Content/Resolver/ContentResolverAttribute.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs b/src/Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs
similarity index 96%
rename from Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs
rename to src/Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs
index 91c253df..f4098f5b 100644
--- a/Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/E0FileStreamContentResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs b/src/Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs
similarity index 72%
rename from Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs
rename to src/Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs
index 8bd6c29b..aae2d256 100644
--- a/Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/E1FileStreamContentResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -27,12 +27,10 @@ public bool Exists(string assetName)
}
///
- public Stream Resolve(string assetName)
+ public Stream? Resolve(string assetName)
{
- using (FileStream stream = new FileStream(assetName, FileMode.Open, FileAccess.Read))
- {
- return ContentCompressor.DecompressStream(stream, out Stream stream2) ? stream2 : null;
- }
+ using FileStream stream = new FileStream(assetName, FileMode.Open, FileAccess.Read);
+ return ContentCompressor.DecompressStream(stream, out Stream stream2) ? stream2 : null;
}
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs
similarity index 88%
rename from Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs
rename to src/Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs
index 76229338..25d1de21 100644
--- a/Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/E0EmbeddedResourceStreamResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -28,13 +28,13 @@ public bool Exists(Type assetType, string assetName, out Assembly assembly)
{
return EmbeddedResourceStreamResolver.ExistsInternal(assetType, assetName, out assembly);
}
-
- assembly = null;
+
+ assembly = null!;
return false;
}
///
- public Stream Resolve(Assembly assembly, string assetName)
+ public Stream? Resolve(Assembly assembly, string assetName)
{
return EmbeddedResourceStreamResolver.GetManifestResourceStreamInternal(assembly, assetName);
}
diff --git a/Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs
similarity index 71%
rename from Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs
rename to src/Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs
index 7b8766bb..8401be5f 100644
--- a/Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/E1EmbeddedResourceStreamResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -28,18 +28,16 @@ public bool Exists(Type assetType, string assetName, out Assembly assembly)
{
return EmbeddedResourceStreamResolver.ExistsInternal(assetType, assetName, out assembly);
}
-
- assembly = null;
+
+ assembly = null!;
return false;
}
///
- public Stream Resolve(Assembly assembly, string assetName)
+ public Stream? Resolve(Assembly assembly, string assetName)
{
- using (Stream stream = EmbeddedResourceStreamResolver.GetManifestResourceStreamInternal(assembly, assetName))
- {
- return ContentCompressor.DecompressStream(stream, out Stream stream2) ? stream2 : null;
- }
+ using Stream stream = EmbeddedResourceStreamResolver.GetManifestResourceStreamInternal(assembly, assetName);
+ return ContentCompressor.DecompressStream(stream, out Stream stream2) ? stream2 : null;
}
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs
similarity index 96%
rename from Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs
rename to src/Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs
index 5d65eddf..94707d2b 100644
--- a/Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/EmbeddedResourceStreamResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -20,31 +20,18 @@ namespace Exomia.Framework.Content.Resolver.EmbeddedResource
[ContentResolver(int.MaxValue)]
class EmbeddedResourceStreamResolver : IEmbeddedResourceResolver
{
- ///
+ ///
public bool Exists(Type assetType, string assetName, out Assembly assembly)
{
return ExistsInternal(assetType, assetName, out assembly);
}
- ///
+ ///
public Stream Resolve(Assembly assembly, string assetName)
{
return GetManifestResourceStreamInternal(assembly, assetName);
}
- ///
- /// Gets the asset name.
- ///
- /// Name of the asset.
- /// [out] The assembly.
- ///
- /// The asset name.
- ///
- private static string GetAssetName(string assetName, Assembly assembly)
- {
- return $"{assembly.GetName().Name}.{assetName}";
- }
-
///
/// Exists internal.
///
@@ -76,7 +63,7 @@ internal static bool ExistsInternal(Type assetType, string assetName, out Assemb
}
}
- assembly = null;
+ assembly = null!;
return false;
}
@@ -92,5 +79,18 @@ internal static Stream GetManifestResourceStreamInternal(Assembly assembly, stri
{
return assembly.GetManifestResourceStream(GetAssetName(assetName, assembly));
}
+
+ ///
+ /// Gets the asset name.
+ ///
+ /// Name of the asset.
+ /// [out] The assembly.
+ ///
+ /// The asset name.
+ ///
+ private static string GetAssetName(string assetName, Assembly assembly)
+ {
+ return $"{assembly.GetName().Name}.{assetName}";
+ }
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs
similarity index 89%
rename from Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs
rename to src/Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs
index 988076dd..9da827c9 100644
--- a/Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/EmbeddedResource/IEmbeddedResourceResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -36,9 +36,8 @@ public interface IEmbeddedResourceResolver
/// The assembly in which the resource exists.
/// Name of the asset.
///
- /// The stream of the asset. This value can be null if this resolver was not able to locate
- /// the asset.
+ /// The stream of the asset. This value can be null if this resolver was not able to locate the asset.
///
- Stream Resolve(Assembly assembly, string assetName);
+ Stream? Resolve(Assembly assembly, string assetName);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs b/src/Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs
similarity index 95%
rename from Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs
rename to src/Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs
index 540fa0e4..b1c5c66e 100644
--- a/Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/FileStreamContentResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Content/Resolver/IContentResolver.cs b/src/Exomia.Framework/Content/Resolver/IContentResolver.cs
similarity index 87%
rename from Exomia.Framework/Content/Resolver/IContentResolver.cs
rename to src/Exomia.Framework/Content/Resolver/IContentResolver.cs
index 7f283869..54f2ce76 100644
--- a/Exomia.Framework/Content/Resolver/IContentResolver.cs
+++ b/src/Exomia.Framework/Content/Resolver/IContentResolver.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -31,9 +31,8 @@ public interface IContentResolver
///
/// Name of the asset.
///
- /// The stream of the asset. This value can be null if this resolver was not able to locate
- /// the asset.
+ /// The stream of the asset. This value can be null if this resolver was not able to locate the asset.
///
- Stream Resolve(string assetName);
+ Stream? Resolve(string assetName);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Content/Texture2ContentManager.cs b/src/Exomia.Framework/Content/Texture2ContentManager.cs
similarity index 94%
rename from Exomia.Framework/Content/Texture2ContentManager.cs
rename to src/Exomia.Framework/Content/Texture2ContentManager.cs
index e6812036..a45bdb84 100644
--- a/Exomia.Framework/Content/Texture2ContentManager.cs
+++ b/src/Exomia.Framework/Content/Texture2ContentManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -64,7 +64,7 @@ public sealed class Texture2ContentManager : ITexture2ContentManager
///
/// The texture.
///
- private Texture _texture;
+ private Texture _texture = Texture.Empty;
///
public bool IsTextureInvalid { get; private set; }
@@ -109,10 +109,8 @@ public Texture2 AddTexture(Stream stream, string assetName, int startIndex = 0)
///
public Texture2 AddTexture(string assetName, int startIndex = 0)
{
- using (FileStream fs = new FileStream(assetName, FileMode.Open, FileAccess.Read))
- {
- return AddTexture(fs, assetName, startIndex);
- }
+ using FileStream fs = new FileStream(assetName, FileMode.Open, FileAccess.Read);
+ return AddTexture(fs, assetName, startIndex);
}
///
@@ -145,7 +143,7 @@ public bool GenerateTexture2DArray(Device5 device, out Texture texture)
}
catch
{
- texture = null;
+ texture = null!;
return false;
}
}
@@ -158,7 +156,6 @@ public void Reset()
_atlasesIndex = 0;
IsTextureInvalid = true;
_texture?.Dispose();
- _texture = null;
}
///
diff --git a/Exomia.Framework/ContentSerialization/CSExtensions.cs b/src/Exomia.Framework/ContentSerialization/CSExtensions.cs
similarity index 97%
rename from Exomia.Framework/ContentSerialization/CSExtensions.cs
rename to src/Exomia.Framework/ContentSerialization/CSExtensions.cs
index cfef0978..4f185c98 100644
--- a/Exomia.Framework/ContentSerialization/CSExtensions.cs
+++ b/src/Exomia.Framework/ContentSerialization/CSExtensions.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -108,8 +108,10 @@ internal static void GetInnerType(this string typeInfo, out string baseTypeInfo,
/// Thrown when a Create struct Reader error condition
/// occurs.
///
- internal static void GetKeyValueInnerType(this string typeInfo, out string keyBaseTypeInfo,
- out string valueBaseTypeInfo, out string valueGenericTypeInfo)
+ internal static void GetKeyValueInnerType(this string typeInfo,
+ out string keyBaseTypeInfo,
+ out string valueBaseTypeInfo,
+ out string valueGenericTypeInfo)
{
Match match = s_valueInnerTypeMatcher.Match(typeInfo);
if (!match.Success)
@@ -216,8 +218,11 @@ internal static void ReadObjectStartTag(this CSStreamReader stream, string key)
/// Thrown when a Create struct Reader error condition
/// occurs.
///
- internal static bool ReadStartTag(this CSStreamReader stream, out string key, out string baseTypeInfo,
- out string genericTypeInfo, out string dimensionInfo)
+ internal static bool ReadStartTag(this CSStreamReader stream,
+ out string key,
+ out string baseTypeInfo,
+ out string genericTypeInfo,
+ out string dimensionInfo)
{
StringBuilder sb = new StringBuilder(128);
diff --git a/Exomia.Framework/ContentSerialization/CSStreamReader.cs b/src/Exomia.Framework/ContentSerialization/CSStreamReader.cs
similarity index 98%
rename from Exomia.Framework/ContentSerialization/CSStreamReader.cs
rename to src/Exomia.Framework/ContentSerialization/CSStreamReader.cs
index 7339fa08..602db41f 100644
--- a/Exomia.Framework/ContentSerialization/CSStreamReader.cs
+++ b/src/Exomia.Framework/ContentSerialization/CSStreamReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Compression/CompressMode.cs b/src/Exomia.Framework/ContentSerialization/Compression/CompressMode.cs
similarity index 97%
rename from Exomia.Framework/ContentSerialization/Compression/CompressMode.cs
rename to src/Exomia.Framework/ContentSerialization/Compression/CompressMode.cs
index a7551031..4de7e93a 100644
--- a/Exomia.Framework/ContentSerialization/Compression/CompressMode.cs
+++ b/src/Exomia.Framework/ContentSerialization/Compression/CompressMode.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs b/src/Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs
similarity index 91%
rename from Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs
rename to src/Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs
index 0c0c463c..32d0457b 100644
--- a/Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs
+++ b/src/Exomia.Framework/ContentSerialization/Compression/ContentCompressor.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -49,11 +49,10 @@ public static class ContentCompressor
/// Thrown when one or more arguments have unsupported or
/// illegal values.
///
- public static bool CompressStream(Stream stream, out Stream streamOut,
+ public static bool CompressStream(Stream stream,
+ out Stream streamOut,
CompressMode compressMode = CompressMode.Gzip)
{
- if (stream == null) { throw new ArgumentNullException(nameof(stream)); }
- streamOut = null;
try
{
stream.Position = 0;
@@ -70,7 +69,11 @@ public static bool CompressStream(Stream stream, out Stream streamOut,
default: throw new ArgumentException("no compression method found", nameof(compressMode));
}
}
- catch { return false; }
+ catch
+ {
+ streamOut = null!;
+ return false;
+ }
return true;
}
@@ -89,15 +92,17 @@ public static bool CompressStream(Stream stream, out Stream streamOut,
///
public static bool DecompressStream(Stream stream, out Stream streamOut)
{
- if (stream == null) { throw new ArgumentNullException(nameof(stream)); }
- streamOut = null;
try
{
stream.Position = 0;
byte[] buffer = new byte[s_magicHeader.Length];
if (stream.Read(buffer, 0, buffer.Length) != s_magicHeader.Length
- && !s_magicHeader.SequenceEqual(buffer)) { return false; }
+ && !s_magicHeader.SequenceEqual(buffer))
+ {
+ streamOut = null!;
+ return false;
+ }
switch ((CompressMode)stream.ReadByte())
{
@@ -107,7 +112,11 @@ public static bool DecompressStream(Stream stream, out Stream streamOut)
default: throw new ArgumentException("no compression method found", nameof(stream));
}
}
- catch { return false; }
+ catch
+ {
+ streamOut = null!;
+ return false;
+ }
return true;
}
diff --git a/Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs b/src/Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs
similarity index 98%
rename from Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs
rename to src/Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs
index 89a41ffe..210331c5 100644
--- a/Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs
+++ b/src/Exomia.Framework/ContentSerialization/ContentSerializableAttribute.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/ContentSerializationContext.cs b/src/Exomia.Framework/ContentSerialization/ContentSerializationContext.cs
similarity index 96%
rename from Exomia.Framework/ContentSerialization/ContentSerializationContext.cs
rename to src/Exomia.Framework/ContentSerialization/ContentSerializationContext.cs
index f6510c35..3686277c 100644
--- a/Exomia.Framework/ContentSerialization/ContentSerializationContext.cs
+++ b/src/Exomia.Framework/ContentSerialization/ContentSerializationContext.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -35,7 +35,7 @@ public T Get(string key)
{
return (T)Content[key].Object;
}
- return default;
+ return default!;
}
///
@@ -46,7 +46,7 @@ public T Get(string key)
/// Object
public void Set(string key, T obj)
{
- Set(key, obj, typeof(T));
+ Set(key, obj!, typeof(T));
}
///
diff --git a/Exomia.Framework/ContentSerialization/ContentSerializationReader.cs b/src/Exomia.Framework/ContentSerialization/ContentSerializationReader.cs
similarity index 92%
rename from Exomia.Framework/ContentSerialization/ContentSerializationReader.cs
rename to src/Exomia.Framework/ContentSerialization/ContentSerializationReader.cs
index 55480c83..8d9c1b83 100644
--- a/Exomia.Framework/ContentSerialization/ContentSerializationReader.cs
+++ b/src/Exomia.Framework/ContentSerialization/ContentSerializationReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -20,7 +20,7 @@ public abstract class ContentSerializationReader : IContentSerializationReade
///
public object Read(ContentSerializationContext context)
{
- return ReadContext(context);
+ return ReadContext(context)!;
}
///
diff --git a/Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs b/src/Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs
similarity index 96%
rename from Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs
rename to src/Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs
index bbcfe2dd..eab4b998 100644
--- a/Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs
+++ b/src/Exomia.Framework/ContentSerialization/ContentSerializationWriter.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/ContentSerializer.cs b/src/Exomia.Framework/ContentSerialization/ContentSerializer.cs
similarity index 98%
rename from Exomia.Framework/ContentSerialization/ContentSerializer.cs
rename to src/Exomia.Framework/ContentSerialization/ContentSerializer.cs
index 443a9977..c941621b 100644
--- a/Exomia.Framework/ContentSerialization/ContentSerializer.cs
+++ b/src/Exomia.Framework/ContentSerialization/ContentSerializer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -25,15 +25,25 @@ namespace Exomia.Framework.ContentSerialization
///
public static class ContentSerializer
{
+ ///
+ /// DEFAULT_EXTENSION.
+ ///
+ public const string DEFAULT_EXTENSION = ".e0";
+
///
/// The tabspace.
///
internal const string TABSPACE = "\t";
///
- /// DEFAULT_EXTENSION.
+ /// The assemblies.
///
- public const string DEFAULT_EXTENSION = ".e0";
+ internal static Dictionary s_assemblies = new Dictionary();
+
+ ///
+ /// The types.
+ ///
+ internal static Dictionary s_types = new Dictionary();
///
/// The content pipe line readers.
@@ -47,22 +57,12 @@ public static class ContentSerializer
private static readonly Dictionary s_contentPipeLineWriters =
new Dictionary();
- ///
- /// The assemblies.
- ///
- internal static Dictionary s_assemblies = new Dictionary();
-
- ///
- /// The types.
- ///
- internal static Dictionary s_types = new Dictionary();
-
///
/// Initializes static members of the class.
///
static ContentSerializer()
{
- #region ADD TYPES
+ #region ADD TYPES
IType pt = new PrimitiveType();
s_types.Add(pt.TypeName, pt);
@@ -121,9 +121,9 @@ static ContentSerializer()
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
- if (a.FullName.StartsWith("System") ||
+ if (a.FullName.StartsWith("System") ||
a.FullName.StartsWith("SharpDX") ||
- a.FullName.StartsWith("ms") ||
+ a.FullName.StartsWith("ms") ||
a.FullName.StartsWith("Xilium.CefGlue")) { continue; }
foreach (Type t in a.GetTypes())
@@ -139,7 +139,7 @@ static ContentSerializer()
#endregion
- #region SharpDX
+ #region SharpDX
AddWriter(new Vector3CW());
AddWriter(new Vector2CW());
diff --git a/Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs b/src/Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs
similarity index 96%
rename from Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs
rename to src/Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs
index 87a10b44..e99ddee9 100644
--- a/Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs
+++ b/src/Exomia.Framework/ContentSerialization/Exceptions/CSContextKeyException.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs b/src/Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs
rename to src/Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs
index 80a7df57..c8373038 100644
--- a/Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs
+++ b/src/Exomia.Framework/ContentSerialization/Exceptions/CSReaderException.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs b/src/Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs
rename to src/Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs
index 8eda1eca..c9710294 100644
--- a/Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs
+++ b/src/Exomia.Framework/ContentSerialization/Exceptions/CSTypeException.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs b/src/Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs
rename to src/Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs
index 208b8521..dbfef29e 100644
--- a/Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs
+++ b/src/Exomia.Framework/ContentSerialization/Exceptions/CSWriterException.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/IContentSerializationReader.cs b/src/Exomia.Framework/ContentSerialization/IContentSerializationReader.cs
similarity index 94%
rename from Exomia.Framework/ContentSerialization/IContentSerializationReader.cs
rename to src/Exomia.Framework/ContentSerialization/IContentSerializationReader.cs
index 3496981e..735680fc 100644
--- a/Exomia.Framework/ContentSerialization/IContentSerializationReader.cs
+++ b/src/Exomia.Framework/ContentSerialization/IContentSerializationReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs b/src/Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs
rename to src/Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs
index 4cc886bf..069b1671 100644
--- a/Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs
+++ b/src/Exomia.Framework/ContentSerialization/IContentSerializationWriter.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Readers/ColorCR.cs b/src/Exomia.Framework/ContentSerialization/Readers/ColorCR.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Readers/ColorCR.cs
rename to src/Exomia.Framework/ContentSerialization/Readers/ColorCR.cs
index 81229a53..37c7c278 100644
--- a/Exomia.Framework/ContentSerialization/Readers/ColorCR.cs
+++ b/src/Exomia.Framework/ContentSerialization/Readers/ColorCR.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs b/src/Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs
similarity index 97%
rename from Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs
rename to src/Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs
index 9055ef61..408aaaef 100644
--- a/Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs
+++ b/src/Exomia.Framework/ContentSerialization/Readers/RectangleFCR.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs b/src/Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs
rename to src/Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs
index f6ac85bc..2a3e2713 100644
--- a/Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs
+++ b/src/Exomia.Framework/ContentSerialization/Readers/Vector2CR.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs b/src/Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs
rename to src/Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs
index 5ebca2e8..f490619f 100644
--- a/Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs
+++ b/src/Exomia.Framework/ContentSerialization/Readers/Vector3CR.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Types/ArrayType.cs b/src/Exomia.Framework/ContentSerialization/Types/ArrayType.cs
similarity index 89%
rename from Exomia.Framework/ContentSerialization/Types/ArrayType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/ArrayType.cs
index 8295ff3d..3a2a1af9 100644
--- a/Exomia.Framework/ContentSerialization/Types/ArrayType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/ArrayType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -108,7 +108,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
@@ -156,8 +159,12 @@ private static string CreateArrayDimensionInfo(Array arr)
/// The dimension.
/// The indices.
/// Thrown when a value was unexpectedly null.
- private static void ForArrayDimension(Action writeHandler, string tabSpace, Array arr,
- Type elementType, int dimension, int[] indices)
+ private static void ForArrayDimension(Action writeHandler,
+ string tabSpace,
+ Array arr,
+ Type elementType,
+ int dimension,
+ int[] indices)
{
for (int i = 0; i < arr.GetLength(dimension); i++)
{
@@ -244,10 +251,12 @@ private static int[] GetArrayDimensionInfo(string arrayTypeInfo)
/// The dimensions.
/// The indices.
/// The current dimension.
- private static void AddArrayContent(CSStreamReader stream, Func readCallback,
- Array arr, int[] dimensions,
- int[] indices,
- int currentDimension)
+ private static void AddArrayContent(CSStreamReader stream,
+ Func readCallback,
+ Array arr,
+ int[] dimensions,
+ int[] indices,
+ int currentDimension)
{
for (int i = 0; i < dimensions[currentDimension]; i++)
{
diff --git a/Exomia.Framework/ContentSerialization/Types/DictionaryType.cs b/src/Exomia.Framework/ContentSerialization/Types/DictionaryType.cs
similarity index 92%
rename from Exomia.Framework/ContentSerialization/Types/DictionaryType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/DictionaryType.cs
index 1fdb6a4b..91cd9a7f 100644
--- a/Exomia.Framework/ContentSerialization/Types/DictionaryType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/DictionaryType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -132,7 +132,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
@@ -156,13 +159,13 @@ private static void ForeachDictionaryDimension(Action entry in dic)
{
- Type elementType = entry.Value.GetType();
+ Type elementType = entry.Value!.GetType();
if (ContentSerializer.s_types.TryGetValue(elementType.Name.ToUpper(), out IType it) ||
ContentSerializer.s_types.TryGetValue(
(elementType.BaseType ?? throw new NullReferenceException()).Name.ToUpper(),
out it))
{
- it.Write(writeHandler, tabSpace, entry.Key.ToString(), entry.Value, false);
+ it.Write(writeHandler, tabSpace, entry.Key!.ToString(), entry.Value, false);
}
else
{
@@ -186,8 +189,11 @@ private static void ForeachDictionaryDimension(Action The key.
/// The content.
/// (Optional) True to use type information.
- private void Write(Action writeHandler, string tabSpace, string key,
- Dictionary content, bool useTypeInfo = true)
+ private void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ Dictionary content,
+ bool useTypeInfo = true)
{
writeHandler(
tabSpace,
@@ -244,7 +250,8 @@ private static int GetDictionaryCount(string dictionaryTypeInfo)
/// Number of.
private static void AddDictionaryContent(CSStreamReader stream,
Func readCallback,
- Dictionary dic, int count)
+ Dictionary dic,
+ int count)
{
for (int i = 0; i < count; i++)
{
diff --git a/Exomia.Framework/ContentSerialization/Types/EnumType.cs b/src/Exomia.Framework/ContentSerialization/Types/EnumType.cs
similarity index 92%
rename from Exomia.Framework/ContentSerialization/Types/EnumType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/EnumType.cs
index 9c128514..acef3a92 100644
--- a/Exomia.Framework/ContentSerialization/Types/EnumType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/EnumType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -92,7 +92,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
diff --git a/Exomia.Framework/ContentSerialization/Types/IType.cs b/src/Exomia.Framework/ContentSerialization/Types/IType.cs
similarity index 91%
rename from Exomia.Framework/ContentSerialization/Types/IType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/IType.cs
index fde26b53..4ad5b194 100644
--- a/Exomia.Framework/ContentSerialization/Types/IType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/IType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -79,7 +79,10 @@ interface IType
/// The key.
/// The content.
/// (Optional) True to use type information.
- void Write(Action writeHandler, string tabSpace, string key, object content,
+ void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/ContentSerialization/Types/ListType.cs b/src/Exomia.Framework/ContentSerialization/Types/ListType.cs
similarity index 89%
rename from Exomia.Framework/ContentSerialization/Types/ListType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/ListType.cs
index fe5d8fb3..7d5ecc13 100644
--- a/Exomia.Framework/ContentSerialization/Types/ListType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/ListType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -115,7 +115,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
@@ -135,7 +138,7 @@ private static void ForeachListDimension(Action writeHandler,
{
foreach (T entry in list)
{
- Type elementType = entry.GetType();
+ Type elementType = entry!.GetType();
if (ContentSerializer.s_types.TryGetValue(elementType.Name.ToUpper(), out IType it) ||
ContentSerializer.s_types.TryGetValue(elementType.BaseType.Name.ToUpper(), out it))
{
@@ -161,7 +164,10 @@ private static void ForeachListDimension(Action writeHandler,
/// The key.
/// The content.
/// (Optional) True to use type information.
- private void Write(Action writeHandler, string tabSpace, string key, List content,
+ private void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ List content,
bool useTypeInfo = true)
{
writeHandler(
@@ -216,12 +222,14 @@ private static int GetListCount(string listTypeInfo)
/// The read callback.
/// The list.
/// Number of.
- private static void AddListContent(CSStreamReader stream, Func readCallback,
- List list, int count)
+ private static void AddListContent(CSStreamReader stream,
+ Func readCallback,
+ List list,
+ int count)
{
for (int i = 0; i < count; i++)
{
- stream.ReadStartTag(out string key, out string dimensionInfo);
+ stream.ReadStartTag(out string _, out string dimensionInfo);
list.Add((dynamic)readCallback(stream, dimensionInfo));
}
diff --git a/Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs b/src/Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs
similarity index 92%
rename from Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs
index 8e876a72..01463860 100644
--- a/Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/PrimitiveType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -97,7 +97,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
diff --git a/Exomia.Framework/ContentSerialization/Types/StringType.cs b/src/Exomia.Framework/ContentSerialization/Types/StringType.cs
similarity index 91%
rename from Exomia.Framework/ContentSerialization/Types/StringType.cs
rename to src/Exomia.Framework/ContentSerialization/Types/StringType.cs
index 04b6d308..f58bf6d0 100644
--- a/Exomia.Framework/ContentSerialization/Types/StringType.cs
+++ b/src/Exomia.Framework/ContentSerialization/Types/StringType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -87,7 +87,10 @@ public object Read(CSStreamReader stream, string key, string genericTypeInfo, st
}
///
- public void Write(Action writeHandler, string tabSpace, string key, object content,
+ public void Write(Action writeHandler,
+ string tabSpace,
+ string key,
+ object content,
bool useTypeInfo = true)
{
//[key:type]content[/key]
diff --git a/Exomia.Framework/ContentSerialization/Writers/ColorCW.cs b/src/Exomia.Framework/ContentSerialization/Writers/ColorCW.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Writers/ColorCW.cs
rename to src/Exomia.Framework/ContentSerialization/Writers/ColorCW.cs
index 8abb0031..e3747862 100644
--- a/Exomia.Framework/ContentSerialization/Writers/ColorCW.cs
+++ b/src/Exomia.Framework/ContentSerialization/Writers/ColorCW.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs b/src/Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs
similarity index 97%
rename from Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs
rename to src/Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs
index 51561321..f92782c0 100644
--- a/Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs
+++ b/src/Exomia.Framework/ContentSerialization/Writers/RectangleFCW.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs b/src/Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs
similarity index 94%
rename from Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs
rename to src/Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs
index d8e10da3..b33ee2bf 100644
--- a/Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs
+++ b/src/Exomia.Framework/ContentSerialization/Writers/Vector2CW.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs b/src/Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs
similarity index 95%
rename from Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs
rename to src/Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs
index 81aab798..29970acd 100644
--- a/Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs
+++ b/src/Exomia.Framework/ContentSerialization/Writers/Vector3CW.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Diagnostic/Diagnostic.cs b/src/Exomia.Framework/Diagnostic/Diagnostic.cs
similarity index 99%
rename from Exomia.Framework/Diagnostic/Diagnostic.cs
rename to src/Exomia.Framework/Diagnostic/Diagnostic.cs
index cc751391..60e63746 100644
--- a/Exomia.Framework/Diagnostic/Diagnostic.cs
+++ b/src/Exomia.Framework/Diagnostic/Diagnostic.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/DrawableComparer.cs b/src/Exomia.Framework/DrawableComparer.cs
similarity index 96%
rename from Exomia.Framework/DrawableComparer.cs
rename to src/Exomia.Framework/DrawableComparer.cs
index 5d28584b..1e6d1dcd 100644
--- a/Exomia.Framework/DrawableComparer.cs
+++ b/src/Exomia.Framework/DrawableComparer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/DrawableComponent.cs b/src/Exomia.Framework/DrawableComponent.cs
similarity index 93%
rename from Exomia.Framework/DrawableComponent.cs
rename to src/Exomia.Framework/DrawableComponent.cs
index 5e8ebe9d..6c80b68b 100644
--- a/Exomia.Framework/DrawableComponent.cs
+++ b/src/Exomia.Framework/DrawableComponent.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -20,12 +20,12 @@ public abstract class DrawableComponent : Component, IDrawable
///
/// Occurs when the property changes.
///
- public event EventHandler DrawOrderChanged;
+ public event EventHandler? DrawOrderChanged;
///
/// Occurs when the property changes.
///
- public event EventHandler VisibleChanged;
+ public event EventHandler? VisibleChanged;
///
/// The draw order.
diff --git a/src/Exomia.Framework/EventHandler.cs b/src/Exomia.Framework/EventHandler.cs
new file mode 100644
index 00000000..4a6e494c
--- /dev/null
+++ b/src/Exomia.Framework/EventHandler.cs
@@ -0,0 +1,41 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+namespace Exomia.Framework
+{
+ ///
+ /// Represents the method that will handle an event that has no event data and no sender
+ /// specified.
+ ///
+ public delegate void EventHandler();
+
+ ///
+ /// Handler, called when the event.
+ ///
+ /// Type of the event arguments.
+ /// T event information.
+ public delegate void EventHandler(TEventArgs e);
+
+ ///
+ /// Delegate for handling Ref events.
+ ///
+ /// Type of the event arguments.
+ /// [in,out] Reference t event information.
+ public delegate void RefEventHandler(ref TEventArgs e) where TEventArgs : struct;
+
+ ///
+ /// Handler, called when the event.
+ ///
+ /// Type of the class.
+ /// Type of the event arguments.
+ /// The sender.
+ /// T event information.
+ public delegate void EventHandler(TClass sender, TEventArgs e);
+}
\ No newline at end of file
diff --git a/Exomia.Framework/Exomia.Framework.csproj b/src/Exomia.Framework/Exomia.Framework.csproj
similarity index 95%
rename from Exomia.Framework/Exomia.Framework.csproj
rename to src/Exomia.Framework/Exomia.Framework.csproj
index d14adfb0..cc5be335 100644
--- a/Exomia.Framework/Exomia.Framework.csproj
+++ b/src/Exomia.Framework/Exomia.Framework.csproj
@@ -1,11 +1,10 @@
- net471;net472
+ net471;net472;net48
exomia
a framework for building 2D and 3D games and more inspired by the XNA/Mono framework
Copyright © $([System.DateTime]::Now.Year) exomia
- 1.1.0.2
- https://raw.githubusercontent.com/exomia/framework/master/LICENSE
+ 1.2.0.0
https://github.com/exomia/framework
true
false
@@ -19,6 +18,8 @@
.
true
+ enable
+ LICENSE
@@ -148,4 +149,11 @@
+
+
+
+ True
+
+
+
\ No newline at end of file
diff --git a/Exomia.Framework/Extensions/MD5Extension.cs b/src/Exomia.Framework/Extensions/MD5Extension.cs
similarity index 97%
rename from Exomia.Framework/Extensions/MD5Extension.cs
rename to src/Exomia.Framework/Extensions/MD5Extension.cs
index 2713e77d..9378bb5c 100644
--- a/Exomia.Framework/Extensions/MD5Extension.cs
+++ b/src/Exomia.Framework/Extensions/MD5Extension.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Game/Game.cs b/src/Exomia.Framework/Game/Game.cs
similarity index 95%
rename from Exomia.Framework/Game/Game.cs
rename to src/Exomia.Framework/Game/Game.cs
index 498948d6..801c5229 100644
--- a/Exomia.Framework/Game/Game.cs
+++ b/src/Exomia.Framework/Game/Game.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -8,6 +8,8 @@
#endregion
+#pragma warning disable IDE0069
+
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -17,6 +19,7 @@
using Exomia.Framework.Components;
using Exomia.Framework.Content;
using Exomia.Framework.Graphics;
+using Exomia.Framework.Input;
using Exomia.Framework.Native;
using Exomia.Framework.Tools;
using SharpDX;
@@ -55,7 +58,7 @@ public abstract class Game : IRunnable
///
/// Occurs when is Running Changed.
///
- private event EventHandler _isRunningChanged;
+ private event EventHandler? _IsRunningChanged;
///
/// The contentable component.
@@ -105,7 +108,7 @@ public abstract class Game : IRunnable
///
/// The collector.
///
- private DisposeCollector _collector;
+ private readonly DisposeCollector _collector;
///
/// Manager for content.
@@ -117,6 +120,11 @@ public abstract class Game : IRunnable
///
private IGameWindow _gameWindow;
+ ///
+ /// The game window initialize.
+ ///
+ private IGameWindowInitialize _gameWindowInitialize;
+
///
/// The graphics device.
///
@@ -210,7 +218,7 @@ public bool IsRunning
{
if (_isRunning != value)
{
- _isRunningChanged?.Invoke(this, value);
+ _IsRunningChanged?.Invoke(this, value);
_isRunning = value;
}
}
@@ -243,14 +251,19 @@ protected Game(string title = "", GCLatencyMode gcLatencyMode = GCLatencyMode.Su
#endif
_serviceRegistry = new ServiceRegistry();
- _gameWindow = new WinFormsGameWindow(title);
- _graphicsDevice = new GraphicsDevice();
+
+ WinFormsGameWindow gameWindow = new WinFormsGameWindow(title);
+ _gameWindow = gameWindow;
+ _gameWindowInitialize = gameWindow;
+
+ _graphicsDevice = new GraphicsDevice();
_contentManager = new ContentManager(_serviceRegistry);
-
+
_serviceRegistry.AddService(_serviceRegistry);
_serviceRegistry.AddService(_graphicsDevice);
_serviceRegistry.AddService(_contentManager);
_serviceRegistry.AddService(_gameWindow);
+ _serviceRegistry.AddService(gameWindow.RenderForm);
_gameComponents = new Dictionary(INITIAL_QUEUE_SIZE);
_pendingInitializables = new List(INITIAL_QUEUE_SIZE);
@@ -513,7 +526,7 @@ public void Shutdown()
}
///
- /// Renderloops this object.
+ /// The Renderloop.
///
private void Renderloop()
{
@@ -534,7 +547,7 @@ void OnIsRunningChanged(Game s, bool v)
else { gameTime.Stop(); }
}
- _isRunningChanged += OnIsRunningChanged;
+ _IsRunningChanged += OnIsRunningChanged;
while (!_shutdown && msg.message != WM_QUIT)
{
@@ -578,7 +591,7 @@ void OnIsRunningChanged(Game s, bool v)
gameTime.Tick();
}
- _isRunningChanged -= OnIsRunningChanged;
+ _IsRunningChanged -= OnIsRunningChanged;
}
#endregion
@@ -644,7 +657,7 @@ private void InitializeGameGraphicsParameters()
OnInitializeGameGraphicsParameters(ref parameters);
- _gameWindow.Initialize(ref parameters);
+ _gameWindowInitialize.Initialize(ref parameters);
_graphicsDevice.Initialize(ref parameters);
GameGraphicsParameters = parameters;
@@ -872,8 +885,11 @@ public Timer2 AddTimer(float tick, bool enabled, uint maxIterations = 0, bool re
///
/// A Timer2.
///
- public Timer2 AddTimer(float tick, bool enabled, EventHandler tickCallback, uint maxIterations = 0,
- bool removeAfterFinished = false)
+ public Timer2 AddTimer(float tick,
+ bool enabled,
+ EventHandler tickCallback,
+ uint maxIterations = 0,
+ bool removeAfterFinished = false)
{
Timer2 timer = Add(new Timer2(tick, tickCallback, maxIterations) { Enabled = enabled });
if (removeAfterFinished)
@@ -895,9 +911,12 @@ public Timer2 AddTimer(float tick, bool enabled, EventHandler tickCallba
///
/// A Timer2.
///
- public Timer2 AddTimer(float tick, bool enabled, EventHandler tickCallback,
+ public Timer2 AddTimer(float tick,
+ bool enabled,
+ EventHandler tickCallback,
EventHandler finishedCallback,
- uint maxIterations, bool removeAfterFinished = false)
+ uint maxIterations,
+ bool removeAfterFinished = false)
{
Timer2 timer = Add(new Timer2(tick, tickCallback, finishedCallback, maxIterations) { Enabled = enabled });
if (removeAfterFinished)
@@ -970,13 +989,12 @@ private void Dispose(bool disposing)
_gameComponents.Clear();
_pendingInitializables.Clear();
- _collector.DisposeAndClear();
- _collector = null;
-
Utilities.Dispose(ref _contentManager);
Utilities.Dispose(ref _graphicsDevice);
Utilities.Dispose(ref _gameWindow);
}
+ _collector.DisposeAndClear(disposing);
+
_disposed = true;
}
}
diff --git a/Exomia.Framework/Game/GameGraphicsParameters.cs b/src/Exomia.Framework/Game/GameGraphicsParameters.cs
similarity index 98%
rename from Exomia.Framework/Game/GameGraphicsParameters.cs
rename to src/Exomia.Framework/Game/GameGraphicsParameters.cs
index 7e602a7a..5a5522c1 100644
--- a/Exomia.Framework/Game/GameGraphicsParameters.cs
+++ b/src/Exomia.Framework/Game/GameGraphicsParameters.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Game/GameTime.cs b/src/Exomia.Framework/Game/GameTime.cs
similarity index 99%
rename from Exomia.Framework/Game/GameTime.cs
rename to src/Exomia.Framework/Game/GameTime.cs
index 3dd0a69d..f0e36d84 100644
--- a/Exomia.Framework/Game/GameTime.cs
+++ b/src/Exomia.Framework/Game/GameTime.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Game/IGameWindow.cs b/src/Exomia.Framework/Game/IGameWindow.cs
similarity index 94%
rename from Exomia.Framework/Game/IGameWindow.cs
rename to src/Exomia.Framework/Game/IGameWindow.cs
index f044bf07..e228c6fe 100644
--- a/Exomia.Framework/Game/IGameWindow.cs
+++ b/src/Exomia.Framework/Game/IGameWindow.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -12,6 +12,23 @@
namespace Exomia.Framework.Game
{
+ interface IGameWindowInitialize
+ {
+ ///
+ /// Gets a value indicating whether this object is initialized.
+ ///
+ ///
+ /// True if this object is initialized, false if not.
+ ///
+ bool IsInitialized { get; }
+
+ ///
+ /// Initializes this object.
+ ///
+ /// [in,out] Options for controlling the operation.
+ void Initialize(ref GameGraphicsParameters parameters);
+ }
+
///
/// IGameWindow interface.
///
@@ -24,15 +41,7 @@ public interface IGameWindow : IDisposable
/// The height.
///
int Height { get; }
-
- ///
- /// Gets a value indicating whether this object is initialized.
- ///
- ///
- /// True if this object is initialized, false if not.
- ///
- bool IsInitialized { get; }
-
+
///
/// Gets or sets the title.
///
@@ -49,12 +58,6 @@ public interface IGameWindow : IDisposable
///
int Width { get; }
- ///
- /// Initializes this object.
- ///
- /// [in,out] Options for controlling the operation.
- void Initialize(ref GameGraphicsParameters parameters);
-
///
/// Resizes.
///
diff --git a/Exomia.Framework/Game/IWinFormsGameWindow.cs b/src/Exomia.Framework/Game/IWinFormsGameWindow.cs
similarity index 98%
rename from Exomia.Framework/Game/IWinFormsGameWindow.cs
rename to src/Exomia.Framework/Game/IWinFormsGameWindow.cs
index 5fbc29e5..158ce651 100644
--- a/Exomia.Framework/Game/IWinFormsGameWindow.cs
+++ b/src/Exomia.Framework/Game/IWinFormsGameWindow.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Game/MultiSampleCount.cs b/src/Exomia.Framework/Game/MultiSampleCount.cs
similarity index 95%
rename from Exomia.Framework/Game/MultiSampleCount.cs
rename to src/Exomia.Framework/Game/MultiSampleCount.cs
index 9c0588aa..a23f347b 100644
--- a/Exomia.Framework/Game/MultiSampleCount.cs
+++ b/src/Exomia.Framework/Game/MultiSampleCount.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/src/Exomia.Framework/Game/RenderForm.cs b/src/Exomia.Framework/Game/RenderForm.cs
new file mode 100644
index 00000000..9c961c2b
--- /dev/null
+++ b/src/Exomia.Framework/Game/RenderForm.cs
@@ -0,0 +1,279 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Windows.Forms;
+using Exomia.Framework.Input;
+using MouseEventHandler = Exomia.Framework.Input.MouseEventHandler;
+
+namespace Exomia.Framework.Game
+{
+ ///
+ /// The RenderForm.
+ ///
+ public class RenderForm : SharpDX.Windows.RenderForm, IRawInputDevice
+ {
+ ///
+ /// Occurs when Raw Input Device. Raw Mouse Down.
+ ///
+ event MouseEventHandler? IRawInputDevice.RawMouseDown
+ {
+ add { _rawMouseDown += value; }
+ remove
+ {
+ if (_rawMouseDown != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawMouseDown -= value;
+ }
+ }
+ }
+
+ ///
+ /// Occurs when Raw Input Device. Raw Mouse Up.
+ ///
+ event MouseEventHandler? IRawInputDevice.RawMouseUp
+ {
+ add { _rawMouseUp += value; }
+ remove
+ {
+ if (_rawMouseUp != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawMouseUp -= value;
+ }
+ }
+ }
+
+ ///
+ /// Occurs when Raw Input Device. Raw Mouse click.
+ ///
+ event MouseEventHandler? IRawInputDevice.RawMouseClick
+ {
+ add { _rawMouseClick += value; }
+ remove
+ {
+ if (_rawMouseClick != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawMouseClick -= value;
+ }
+ }
+ }
+
+ ///
+ /// Occurs when Raw Input Device. Raw Mouse Move.
+ ///
+ event MouseEventHandler? IRawInputDevice.RawMouseMove
+ {
+ add { _rawMouseMove += value; }
+ remove
+ {
+ if (_rawMouseMove != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawMouseMove -= value;
+ }
+ }
+ }
+
+ ///
+ /// Occurs when Raw Input Device. Raw Mouse Wheel.
+ ///
+ event MouseEventHandler? IRawInputDevice.RawMouseWheel
+ {
+ add { _rawMouseWheel += value; }
+ remove
+ {
+ if (_rawMouseWheel != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawMouseWheel -= value;
+ }
+ }
+ }
+
+ ///
+ /// Occurs when raw Input Device. Raw Key.
+ ///
+ event RefEventHandler? IRawInputDevice.RawKeyEvent
+ {
+ add { _rawKeyEvent += value; }
+ remove
+ {
+ if (_rawKeyEvent != null)
+ {
+ // ReSharper disable once DelegateSubtraction
+ _rawKeyEvent -= value;
+ }
+ }
+ }
+
+ ///
+ /// Gets the raw mouse wheel.
+ ///
+ private MouseEventHandler? _rawMouseDown;
+
+ ///
+ /// The raw mouse up.
+ ///
+ private MouseEventHandler? _rawMouseUp;
+
+ ///
+ /// The raw mouse click.
+ ///
+ private MouseEventHandler? _rawMouseClick;
+
+ ///
+ /// The raw mouse move.
+ ///
+ private MouseEventHandler? _rawMouseMove;
+
+ ///
+ /// The raw mouse wheel.
+ ///
+ private MouseEventHandler? _rawMouseWheel;
+
+ ///
+ /// The raw key event.
+ ///
+ private RefEventHandler? _rawKeyEvent;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The text.
+ public RenderForm(string text)
+ : base(text) { }
+
+ ///
+ /// Low word.
+ ///
+ /// Number of.
+ ///
+ /// An int.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static int LowWord(IntPtr number)
+ {
+ return (int)number.ToInt64() & 0x0000FFFF;
+ }
+
+ ///
+ /// High word.
+ ///
+ /// Number of.
+ ///
+ /// An int.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static int HighWord(IntPtr number)
+ {
+ return (int)number.ToInt64() >> 16;
+ }
+
+ private int _state = 0;
+
+ ///
+ /// Gets a state.
+ ///
+ /// The flag.
+ ///
+ /// True if it succeeds, false if it fails.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private bool GetState(int flag)
+ {
+ return (_state & flag) == flag;
+ }
+
+ ///
+ /// Sets a state.
+ ///
+ /// The flag.
+ /// True to value.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void SetState(int flag, bool value)
+ {
+ _state = value ? _state | flag : _state & ~flag;
+ }
+
+ ///
+ /// Raw mouse up.
+ ///
+ /// [in,out] The ref Message to process.
+ /// The buttons.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void RawMouseUp(ref Message m, Input.MouseButtons buttons)
+ {
+ buttons |= (Input.MouseButtons)LowWord(m.WParam);
+ int low = LowWord(m.LParam);
+ int high = HighWord(m.LParam);
+ if (GetState(0x8000000))
+ {
+ _rawMouseClick?.Invoke(low, high, buttons, !GetState(0x4000000) ? 1 : 2, 0);
+ }
+ SetState(0x4000000, false);
+ SetState(0x8000000, false);
+ _rawMouseUp?.Invoke(low, high, buttons, 1, 0);
+ }
+
+ ///
+ protected override void WndProc(ref Message m)
+ {
+ switch (m.Msg)
+ {
+ case Win32Message.WM_KEYDOWN:
+ case Win32Message.WM_KEYUP:
+ case Win32Message.WM_CHAR:
+ case Win32Message.WM_UNICHAR:
+ case Win32Message.WM_SYSKEYDOWN:
+ case Win32Message.WM_SYSKEYUP:
+ _rawKeyEvent?.Invoke(ref m);
+ break;
+ case Win32Message.WM_LBUTTONDOWN:
+ case Win32Message.WM_MBUTTONDOWN:
+ case Win32Message.WM_RBUTTONDOWN:
+ case Win32Message.WM_XBUTTONDOWN:
+ SetState(0x8000000, true);
+ _rawMouseDown?.Invoke(LowWord(m.LParam), HighWord(m.LParam), (Input.MouseButtons)LowWord(m.WParam), 1, 0);
+ break;
+ case Win32Message.WM_LBUTTONUP:
+ RawMouseUp(ref m, Input.MouseButtons.Left);
+ break;
+ case Win32Message.WM_MBUTTONUP:
+ RawMouseUp(ref m, Input.MouseButtons.Middle);
+ break;
+ case Win32Message.WM_RBUTTONUP:
+ RawMouseUp(ref m, Input.MouseButtons.Right);
+ break;
+ case Win32Message.WM_XBUTTONUP:
+ RawMouseUp(ref m, Input.MouseButtons.None);
+ break;
+ case Win32Message.WM_MOUSEMOVE:
+ _rawMouseMove?.Invoke(LowWord(m.LParam), HighWord(m.LParam), (Input.MouseButtons)LowWord(m.WParam), 0, 0);
+ break;
+ case Win32Message.WM_MOUSEWHEEL:
+ _rawMouseWheel?.Invoke(
+ LowWord(m.LParam), HighWord(m.LParam), (Input.MouseButtons)LowWord(m.WParam), 1, HighWord(m.WParam));
+ break;
+ case Win32Message.WM_LBUTTONDBLCLK:
+ case Win32Message.WM_MBUTTONDBLCLK:
+ case Win32Message.WM_RBUTTONDBLCLK:
+ case Win32Message.WM_XBUTTONDBLCLK:
+ SetState(0xC000000, true);
+ _rawMouseDown?.Invoke(LowWord(m.LParam), HighWord(m.LParam), (Input.MouseButtons)LowWord(m.WParam), 2, 0);
+ break;
+ }
+ base.WndProc(ref m);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Exomia.Framework/Game/WinFormsGameWindow.cs b/src/Exomia.Framework/Game/WinFormsGameWindow.cs
similarity index 98%
rename from Exomia.Framework/Game/WinFormsGameWindow.cs
rename to src/Exomia.Framework/Game/WinFormsGameWindow.cs
index c96baa5c..759e9c11 100644
--- a/Exomia.Framework/Game/WinFormsGameWindow.cs
+++ b/src/Exomia.Framework/Game/WinFormsGameWindow.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -13,14 +13,13 @@
using System.Threading;
using System.Windows.Forms;
using SharpDX;
-using SharpDX.Windows;
namespace Exomia.Framework.Game
{
///
/// Form for viewing the window forms game. This class cannot be inherited.
///
- public sealed class WinFormsGameWindow : IWinFormsGameWindow
+ public sealed class WinFormsGameWindow : IWinFormsGameWindow, IGameWindowInitialize
{
///
/// The render form.
diff --git a/Exomia.Framework/Graphics/Canvas.cs b/src/Exomia.Framework/Graphics/Canvas.cs
similarity index 70%
rename from Exomia.Framework/Graphics/Canvas.cs
rename to src/Exomia.Framework/Graphics/Canvas.cs
index b4d69959..ec584a33 100644
--- a/Exomia.Framework/Graphics/Canvas.cs
+++ b/src/Exomia.Framework/Graphics/Canvas.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -69,9 +69,12 @@ private static void IDevice_onResizeFinished(ViewportF viewport) { }
/// Width of the line.
/// The opacity.
/// (Optional) The length factor.
- public void DrawLine(
- in Vector2 point1, in Vector2 point2, in Color color, float lineWidth, float opacity,
- float lengthFactor = 1.0f)
+ public void DrawLine(in Vector2 point1,
+ in Vector2 point2,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ float lengthFactor = 1.0f)
{
DrawFillRectangle(
new RectangleF(point1.X, point1.Y, Vector2.Distance(point1, point2) * lengthFactor, lineWidth), color,
@@ -91,8 +94,12 @@ public void DrawLine(
/// The color.
/// Width of the line.
/// The opacity.
- public void DrawTriangle(
- in Vector2 point1, in Vector2 point2, in Vector2 point3, in Color color, float lineWidth, float opacity) { }
+ public void DrawTriangle(in Vector2 point1,
+ in Vector2 point2,
+ in Vector2 point3,
+ in Color color,
+ float lineWidth,
+ float opacity) { }
///
/// Draw fill triangle.
@@ -103,8 +110,12 @@ public void DrawTriangle(
/// The color.
/// Width of the line.
/// The opacity.
- public void DrawFillTriangle(
- in Vector2 point1, in Vector2 point2, in Vector2 point3, in Color color, float lineWidth, float opacity) { }
+ public void DrawFillTriangle(in Vector2 point1,
+ in Vector2 point2,
+ in Vector2 point3,
+ in Color color,
+ float lineWidth,
+ float opacity) { }
#endregion
@@ -119,9 +130,12 @@ public void DrawFillTriangle(
/// The rotation.
/// The origin.
/// The opacity.
- public void DrawRectangle(
- in RectangleF destinationRectangle, in Color color, float lineWidth, float rotation, in Vector2 origin,
- float opacity) { }
+ public void DrawRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float lineWidth,
+ float rotation,
+ in Vector2 origin,
+ float opacity) { }
///
/// Draw fill rectangle.
@@ -131,8 +145,11 @@ public void DrawRectangle(
/// The rotation.
/// The origin.
/// The opacity.
- public void DrawFillRectangle(
- in RectangleF destinationRectangle, in Color color, float rotation, in Vector2 origin, float opacity) { }
+ public void DrawFillRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity) { }
#endregion
@@ -151,9 +168,16 @@ public void DrawFillRectangle(
/// Width of the line.
/// The opacity.
/// The segments.
- public void DrawArc(
- in Vector2 center, float radius, float start, float end, float width, float height,
- in Color color, float lineWidth, float opacity, int segments) { }
+ public void DrawArc(in Vector2 center,
+ float radius,
+ float start,
+ float end,
+ float width,
+ float height,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ int segments) { }
///
/// Draw fill arc.
@@ -168,9 +192,16 @@ public void DrawArc(
/// Width of the line.
/// The opacity.
/// The segments.
- public void DrawFillArc(
- in Vector2 center, float radius, float start, float end, float width, float height,
- in Color color, float lineWidth, float opacity, int segments) { }
+ public void DrawFillArc(in Vector2 center,
+ float radius,
+ float start,
+ float end,
+ float width,
+ float height,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ int segments) { }
#endregion
@@ -215,8 +246,7 @@ public void DrawFillPolygon(Vector2[] vertex, in Color color, float lineWidth, f
/// The texture.
/// The position.
/// The color.
- public void Draw(
- Texture texture, in Vector2 position, in Color color)
+ public void Draw(Texture texture, in Vector2 position, in Color color)
{
DrawSprite(
texture, new RectangleF(position.X, position.Y, 1f, 1f), true,
@@ -229,8 +259,7 @@ public void Draw(
/// The texture.
/// Destination rectangle.
/// The color.
- public void Draw(
- Texture texture, in RectangleF destinationRectangle, in Color color)
+ public void Draw(Texture texture, in RectangleF destinationRectangle, in Color color)
{
DrawSprite(
texture, destinationRectangle, false,
@@ -244,8 +273,7 @@ public void Draw(
/// The position.
/// Source rectangle.
/// The color.
- public void Draw(
- Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color)
+ public void Draw(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color)
{
DrawSprite(
texture, new RectangleF(position.X, position.Y, 1f, 1f), true,
@@ -259,8 +287,10 @@ public void Draw(
/// Destination rectangle.
/// Source rectangle.
/// The color.
- public void Draw(
- Texture texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle, in Color color)
+ public void Draw(Texture texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color)
{
DrawSprite(
texture, destinationRectangle, false,
@@ -278,9 +308,14 @@ public void Draw(
/// The origin.
/// The opacity.
/// The effects.
- public void Draw(
- Texture texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects)
+ public void Draw(Texture texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
DrawSprite(
texture, destinationRectangle, false,
@@ -299,10 +334,15 @@ public void Draw(
/// The scale.
/// The opacity.
/// The effects.
- public void Draw(
- Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
- SpriteEffects effects)
+ public void Draw(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
+ SpriteEffects effects)
{
DrawSprite(
texture, new RectangleF(position.X, position.Y, scale, scale), true,
@@ -321,10 +361,15 @@ public void Draw(
/// The scale.
/// The opacity.
/// The effects.
- public void Draw(
- Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, in Vector2 scale, float opacity,
- SpriteEffects effects)
+ public void Draw(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ in Vector2 scale,
+ float opacity,
+ SpriteEffects effects)
{
DrawSprite(
texture, new RectangleF(position.X, position.Y, scale.X, scale.Y), true,
@@ -343,11 +388,15 @@ public void Draw(
/// The origin.
/// The opacity.
/// The effects.
- private void DrawSprite(
- Texture texture, in RectangleF destination, bool scaleDestination,
- in Rectangle? sourceRectangle,
- in Color color, float rotation, in Vector2 origin, float opacity,
- SpriteEffects effects) { }
+ private void DrawSprite(Texture texture,
+ in RectangleF destination,
+ bool scaleDestination,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects) { }
#endregion
@@ -360,8 +409,7 @@ private void DrawSprite(
/// The text.
/// The position.
/// The color.
- public void DrawText(
- SpriteFont font, string text, in Vector2 position, in Color color)
+ public void DrawText(SpriteFont font, string text, in Vector2 position, in Color color)
{
font.Draw(DrawTextInternal, text, position, color, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
@@ -374,8 +422,7 @@ public void DrawText(
/// The position.
/// The color.
/// The rotation.
- public void DrawText(
- SpriteFont font, string text, in Vector2 position, in Color color, float rotation)
+ public void DrawText(SpriteFont font, string text, in Vector2 position, in Color color, float rotation)
{
font.Draw(DrawTextInternal, text, position, color, rotation, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
@@ -391,9 +438,14 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, string text, in Vector2 position, in Color color, float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, 0f);
}
@@ -411,10 +463,16 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, string text, int start, int end, in Vector2 position,
- in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(DrawTextInternal, text, start, end, position, color, rotation, origin, opacity, effects, 0f);
}
@@ -433,10 +491,17 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, string text, int start, int end, in Vector2 position,
- in Size2F dimension,
- in Color color, float rotation, in Vector2 origin, float opacity, SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(
DrawTextInternal, text, start, end, position, dimension, color, rotation, origin, opacity, effects, 0f);
@@ -449,8 +514,7 @@ public void DrawText(
/// The text.
/// The position.
/// The color.
- public void DrawText(
- SpriteFont font, StringBuilder text, in Vector2 position, in Color color)
+ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, in Color color)
{
font.Draw(DrawTextInternal, text, position, color, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
@@ -463,8 +527,7 @@ public void DrawText(
/// The position.
/// The color.
/// The rotation.
- public void DrawText(
- SpriteFont font, StringBuilder text, in Vector2 position, in Color color, float rotation)
+ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, in Color color, float rotation)
{
font.Draw(DrawTextInternal, text, position, color, rotation, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
@@ -480,9 +543,14 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, StringBuilder text, in Vector2 position, in Color color, float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, 0f);
}
@@ -500,9 +568,16 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, StringBuilder text, int start, int end, in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity, SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(DrawTextInternal, text, start, end, position, color, rotation, origin, opacity, effects, 0f);
}
@@ -521,10 +596,17 @@ public void DrawText(
/// The origin.
/// The opacity.
/// The effects.
- public void DrawText(
- SpriteFont font, StringBuilder text, int start, int end, in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin, float opacity,
- SpriteEffects effects)
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects)
{
font.Draw(
DrawTextInternal, text, start, end, position, dimension, color, rotation, origin, opacity, effects, 0f);
@@ -543,9 +625,14 @@ public void DrawText(
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void DrawTextInternal(Texture texture, in Vector2 position, in Rectangle? sourceRectangle,
+ internal void DrawTextInternal(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
diff --git a/Exomia.Framework/Graphics/DefaultTextures.cs b/src/Exomia.Framework/Graphics/DefaultTextures.cs
similarity index 87%
rename from Exomia.Framework/Graphics/DefaultTextures.cs
rename to src/Exomia.Framework/Graphics/DefaultTextures.cs
index 9f1536b6..c44803b1 100644
--- a/Exomia.Framework/Graphics/DefaultTextures.cs
+++ b/src/Exomia.Framework/Graphics/DefaultTextures.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -30,22 +30,22 @@ public static class DefaultTextures
///
/// The white texture.
///
- private static Texture s_whiteTexture;
+ private static Texture? s_whiteTexture;
///
/// The black texture.
///
- private static Texture s_blackTexture;
+ private static Texture? s_blackTexture;
///
/// The second s white texture.
///
- private static Texture2 s_whiteTexture2;
+ private static Texture2? s_whiteTexture2;
///
/// The second s black texture.
///
- private static Texture2 s_blackTexture2;
+ private static Texture2? s_blackTexture2;
///
/// True if this object is initialized.
@@ -65,7 +65,7 @@ public static class DefaultTextures
///
public static Texture BlackTexture
{
- get { return s_blackTexture; }
+ get { return s_blackTexture!; }
}
///
@@ -76,7 +76,7 @@ public static Texture BlackTexture
///
public static Texture2 BlackTexture2
{
- get { return s_blackTexture2; }
+ get { return s_blackTexture2!; }
}
///
@@ -87,7 +87,7 @@ public static Texture2 BlackTexture2
///
public static Texture WhiteTexture
{
- get { return s_whiteTexture; }
+ get { return s_whiteTexture!; }
}
///
@@ -98,7 +98,7 @@ public static Texture WhiteTexture
///
public static Texture2 WhiteTexture2
{
- get { return s_whiteTexture2; }
+ get { return s_whiteTexture2!; }
}
///
@@ -114,12 +114,14 @@ internal static void InitializeTextures(Device5 device)
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(WHITE_TEXTURE_BASE64)))
{
- s_whiteTexture = Texture.Load(device, ms);
+ s_whiteTexture = Texture.Load(device, ms) ??
+ throw new NullReferenceException($"{nameof(WhiteTexture)}");
}
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(BLACK_TEXTURE_BASE64)))
{
- s_blackTexture = Texture.Load(device, ms);
+ s_blackTexture = Texture.Load(device, ms) ??
+ throw new NullReferenceException($"{nameof(BlackTexture)}");
}
}
}
diff --git a/Exomia.Framework/Graphics/GraphicsDevice.cs b/src/Exomia.Framework/Graphics/GraphicsDevice.cs
similarity index 89%
rename from Exomia.Framework/Graphics/GraphicsDevice.cs
rename to src/Exomia.Framework/Graphics/GraphicsDevice.cs
index a05b31bd..cce6b6d8 100644
--- a/Exomia.Framework/Graphics/GraphicsDevice.cs
+++ b/src/Exomia.Framework/Graphics/GraphicsDevice.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -36,42 +36,42 @@ public sealed class GraphicsDevice : IGraphicsDevice
///
///
///
- public event EventHandler ResizeFinished;
+ public event EventHandler? ResizeFinished;
///
/// The fourth adapter.
///
- private Adapter4 _adapter4;
+ private Adapter4? _adapter4;
///
/// The current render view.
///
- private RenderTargetView1 _currentRenderView;
+ private RenderTargetView1? _currentRenderView;
///
/// The fifth d 3 d device.
///
- private Device5 _d3DDevice5;
+ private Device5? _d3DDevice5;
///
/// Context for the 3 d device.
///
- private DeviceContext4 _d3DDeviceContext;
+ private DeviceContext4? _d3DDeviceContext;
///
/// The depth stencil view.
///
- private DepthStencilView _depthStencilView;
+ private DepthStencilView? _depthStencilView;
///
/// The fourth dxgi device.
///
- private Device4 _dxgiDevice4;
+ private Device4? _dxgiDevice4;
///
/// The dxgi factory.
///
- private Factory5 _dxgiFactory;
+ private Factory5? _dxgiFactory;
///
/// True to need resize.
@@ -81,12 +81,12 @@ public sealed class GraphicsDevice : IGraphicsDevice
///
/// The output.
///
- private Output _output;
+ private Output? _output;
///
/// The first render view.
///
- private RenderTargetView1 _renderView1;
+ private RenderTargetView1? _renderView1;
///
/// Options for controlling the resize.
@@ -96,7 +96,7 @@ public sealed class GraphicsDevice : IGraphicsDevice
///
/// The fourth swap chain.
///
- private SwapChain4 _swapChain4;
+ private SwapChain4? _swapChain4;
///
/// The synchronise.
@@ -106,31 +106,31 @@ public sealed class GraphicsDevice : IGraphicsDevice
///
public Adapter4 Adapter
{
- get { return _adapter4; }
+ get { return _adapter4!; }
}
///
public Device5 Device
{
- get { return _d3DDevice5; }
+ get { return _d3DDevice5!; }
}
///
public DeviceContext4 DeviceContext
{
- get { return _d3DDeviceContext; }
+ get { return _d3DDeviceContext!; }
}
///
public Device4 DxgiDevice
{
- get { return _dxgiDevice4; }
+ get { return _dxgiDevice4!; }
}
///
public Factory5 Factory
{
- get { return _dxgiFactory; }
+ get { return _dxgiFactory!; }
}
///
@@ -139,13 +139,13 @@ public Factory5 Factory
///
public RenderTargetView1 RenderView
{
- get { return _renderView1; }
+ get { return _renderView1!; }
}
///
public SwapChain4 SwapChain
{
- get { return _swapChain4; }
+ get { return _swapChain4!; }
}
///
@@ -172,9 +172,9 @@ public bool BeginFrame()
///
public void Clear()
{
- lock (_d3DDevice5)
+ lock (_d3DDevice5!)
{
- _d3DDeviceContext.ClearRenderTargetView(_currentRenderView, Color.CornflowerBlue);
+ _d3DDeviceContext!.ClearRenderTargetView(_currentRenderView, Color.CornflowerBlue);
_d3DDeviceContext.ClearDepthStencilView(
_depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
}
@@ -183,9 +183,9 @@ public void Clear()
///
public void Clear(Color color)
{
- lock (_d3DDevice5)
+ lock (_d3DDevice5!)
{
- _d3DDeviceContext.ClearRenderTargetView(_currentRenderView, color);
+ _d3DDeviceContext!.ClearRenderTargetView(_currentRenderView, color);
_d3DDeviceContext.ClearDepthStencilView(
_depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
}
@@ -194,13 +194,13 @@ public void Clear(Color color)
///
public void EndFrame()
{
- _swapChain4.Present(_vSync, PresentFlags.None);
+ _swapChain4!.Present(_vSync, PresentFlags.None);
}
///
public bool GetFullscreenState()
{
- return _swapChain4.IsFullScreen;
+ return _swapChain4!.IsFullScreen;
}
///
@@ -223,7 +223,7 @@ public void Initialize(ref GameGraphicsParameters parameters)
}
_dxgiFactory.MakeWindowAssociation(parameters.Handle, parameters.WindowAssociationFlags);
- _adapter4 = null;
+ _adapter4 = null!;
for (int i = 0; i < _dxgiFactory.GetAdapterCount1(); i++)
{
@@ -248,7 +248,7 @@ public void Initialize(ref GameGraphicsParameters parameters)
out ModeDescription desc);
if (o == 0
- || desc.RefreshRate.Numerator / desc.RefreshRate.Denominator
+ || desc.RefreshRate.Numerator / desc.RefreshRate.Denominator
> modeDescription.RefreshRate.Numerator / modeDescription.RefreshRate.Denominator)
{
modeDescription = desc;
@@ -285,7 +285,7 @@ public void Initialize(ref GameGraphicsParameters parameters)
Console.WriteLine($"Scaling:\t\t{modeDescription.Scaling}");
Console.WriteLine($"ScanlineOrdering:\t{modeDescription.ScanlineOrdering}");
Console.WriteLine();
- Console.WriteLine($"DeviceName:\t\t{_output.Description.DeviceName}");
+ Console.WriteLine($"DeviceName:\t\t{_output!.Description.DeviceName}");
Console.WriteLine(
$"DesktopBounds:\t\t{_output.Description.DesktopBounds.Left};{_output.Description.DesktopBounds.Top};{_output.Description.DesktopBounds.Right};{_output.Description.DesktopBounds.Bottom}");
Console.WriteLine($"MonitorHandle:\t\t{_output.Description.MonitorHandle}");
@@ -366,7 +366,7 @@ public void Resize(int width, int height)
{
_resizeParameters = new ResizeParameters
{
- BufferCount = _swapChain4.Description1.BufferCount,
+ BufferCount = _swapChain4!.Description1.BufferCount,
Width = width,
Height = height,
SwapChainFlags = _swapChain4.Description1.Flags
@@ -375,21 +375,21 @@ public void Resize(int width, int height)
}
///
- public void SetFullscreenState(bool state, Output output = null)
+ public void SetFullscreenState(bool state, Output? output = null)
{
- if (_swapChain4.IsFullScreen != state)
+ if (_swapChain4!.IsFullScreen != state)
{
_swapChain4.SetFullscreenState(state, output);
}
}
///
- public void SetRenderTarget(RenderTargetView1 target)
+ public void SetRenderTarget(RenderTargetView1? target)
{
- lock (_d3DDevice5)
+ lock (_d3DDevice5!)
{
_currentRenderView = target ?? _renderView1;
- _d3DDeviceContext.OutputMerger.SetRenderTargets(_depthStencilView, _currentRenderView);
+ _d3DDeviceContext!.OutputMerger.SetRenderTargets(_depthStencilView, _currentRenderView);
}
}
@@ -399,7 +399,7 @@ public void SetRenderTarget(RenderTargetView1 target)
/// The arguments.
private void Resize(ResizeParameters args)
{
- lock (_d3DDevice5)
+ lock (_d3DDevice5!)
{
if (_renderView1 != null)
{
@@ -407,7 +407,7 @@ private void Resize(ResizeParameters args)
_renderView1 = null;
}
- _swapChain4.ResizeBuffers(
+ _swapChain4!.ResizeBuffers(
args.BufferCount, args.Width, args.Height, Format.Unknown, args.SwapChainFlags);
RenderTargetView renderView;
@@ -437,7 +437,7 @@ private void Resize(ResizeParameters args)
_depthStencilView = new DepthStencilView(
_d3DDevice5, depthBuffer, new DepthStencilViewDescription
{
- Dimension = _swapChain4.Description.SampleDescription.Count > 1 ||
+ Dimension = _swapChain4.Description.SampleDescription.Count > 1 ||
_swapChain4.Description.SampleDescription.Quality > 0
? DepthStencilViewDimension.Texture2DMultisampled
: DepthStencilViewDimension.Texture2D
@@ -446,7 +446,7 @@ private void Resize(ResizeParameters args)
Viewport = new Viewport(0, 0, args.Width, args.Height);
- _d3DDeviceContext.Rasterizer.SetViewport(Viewport);
+ _d3DDeviceContext!.Rasterizer.SetViewport(Viewport);
SetRenderTarget(null);
}
ResizeFinished?.Invoke(Viewport);
diff --git a/Exomia.Framework/Graphics/HLSL/PositionColor.hlsl b/src/Exomia.Framework/Graphics/HLSL/PositionColor.hlsl
similarity index 100%
rename from Exomia.Framework/Graphics/HLSL/PositionColor.hlsl
rename to src/Exomia.Framework/Graphics/HLSL/PositionColor.hlsl
diff --git a/Exomia.Framework/Graphics/HLSL/PositionColorTexture.hlsl b/src/Exomia.Framework/Graphics/HLSL/PositionColorTexture.hlsl
similarity index 100%
rename from Exomia.Framework/Graphics/HLSL/PositionColorTexture.hlsl
rename to src/Exomia.Framework/Graphics/HLSL/PositionColorTexture.hlsl
diff --git a/Exomia.Framework/Graphics/HLSL/PositionColorTexture2.hlsl b/src/Exomia.Framework/Graphics/HLSL/PositionColorTexture2.hlsl
similarity index 100%
rename from Exomia.Framework/Graphics/HLSL/PositionColorTexture2.hlsl
rename to src/Exomia.Framework/Graphics/HLSL/PositionColorTexture2.hlsl
diff --git a/Exomia.Framework/Graphics/IGraphicsDevice.cs b/src/Exomia.Framework/Graphics/IGraphicsDevice.cs
similarity index 96%
rename from Exomia.Framework/Graphics/IGraphicsDevice.cs
rename to src/Exomia.Framework/Graphics/IGraphicsDevice.cs
index 4d678bc8..42a96a5a 100644
--- a/Exomia.Framework/Graphics/IGraphicsDevice.cs
+++ b/src/Exomia.Framework/Graphics/IGraphicsDevice.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -155,7 +155,7 @@ public interface IGraphicsDevice : IDisposable
///
/// True to state.
/// (Optional) The output.
- void SetFullscreenState(bool state, Output output = null);
+ void SetFullscreenState(bool state, Output? output = null);
///
/// Gets fullscreen state.
@@ -169,6 +169,6 @@ public interface IGraphicsDevice : IDisposable
/// Sets render target.
///
/// Target for the.
- void SetRenderTarget(RenderTargetView1 target);
+ void SetRenderTarget(RenderTargetView1? target);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Graphics/ShaderByteCode.cs b/src/Exomia.Framework/Graphics/ShaderByteCode.cs
similarity index 99%
rename from Exomia.Framework/Graphics/ShaderByteCode.cs
rename to src/Exomia.Framework/Graphics/ShaderByteCode.cs
index a8f42070..03ab970d 100644
--- a/Exomia.Framework/Graphics/ShaderByteCode.cs
+++ b/src/Exomia.Framework/Graphics/ShaderByteCode.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/SpriteBatch.cs b/src/Exomia.Framework/Graphics/SpriteBatch.cs
similarity index 85%
rename from Exomia.Framework/Graphics/SpriteBatch.cs
rename to src/Exomia.Framework/Graphics/SpriteBatch.cs
index 8555e999..d20688c1 100644
--- a/Exomia.Framework/Graphics/SpriteBatch.cs
+++ b/src/Exomia.Framework/Graphics/SpriteBatch.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -15,6 +15,7 @@
using System.Text;
using System.Threading.Tasks;
using Exomia.Framework.Graphics.SpriteSort;
+using Exomia.Framework.Mathematics;
using SharpDX;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
@@ -24,7 +25,6 @@
namespace Exomia.Framework.Graphics
{
-
///
/// A sprite batch. This class cannot be inherited.
///
@@ -128,12 +128,12 @@ private static readonly Vector2[]
///
/// The blend state.
///
- private BlendState _defaultBlendState, _blendState;
+ private BlendState? _defaultBlendState, _blendState;
///
/// The default depth stencil state.
///
- private DepthStencilState _defaultDepthStencilState;
+ private DepthStencilState? _defaultDepthStencilState;
///
/// Gets the state of the rasterizer.
@@ -141,7 +141,7 @@ private static readonly Vector2[]
///
/// The rasterizer state.
///
- private RasterizerState _defaultRasterizerState, _defaultRasterizerScissorEnabledState, _rasterizerState;
+ private RasterizerState? _defaultRasterizerState, _defaultRasterizerScissorEnabledState, _rasterizerState;
///
/// Gets the state of the sampler.
@@ -149,12 +149,12 @@ private static readonly Vector2[]
///
/// The sampler state.
///
- private SamplerState _defaultSamplerState, _samplerState;
+ private SamplerState? _defaultSamplerState, _samplerState;
///
/// State of the depth stencil.
///
- private DepthStencilState _depthStencilState;
+ private DepthStencilState? _depthStencilState;
///
/// Gets a value indicating whether the scissor is enabled.
@@ -216,12 +216,12 @@ private static readonly Vector2[]
///
/// The pixel shader.
///
- private PixelShader _pixelShader;
+ private PixelShader? _pixelShader;
///
/// The vertex shader.
///
- private VertexShader _vertexShader;
+ private VertexShader? _vertexShader;
///
/// Initializes static members of the class.
@@ -265,14 +265,11 @@ public SpriteBatch(IGraphicsDevice iDevice, SpriteSortAlgorithm sortAlgorithm =
_device = iDevice.Device;
_context = iDevice.DeviceContext;
- switch (sortAlgorithm)
+ _spriteSort = sortAlgorithm switch
{
- case SpriteSortAlgorithm.MergeSort:
- _spriteSort = new SpriteMergeSort();
- break;
- default:
- throw new ArgumentException($"invalid sort algorithm ({sortAlgorithm})", nameof(sortAlgorithm));
- }
+ SpriteSortAlgorithm.MergeSort => new SpriteMergeSort(),
+ _ => throw new ArgumentException($"invalid sort algorithm ({sortAlgorithm})", nameof(sortAlgorithm))
+ };
Initialize(_device);
@@ -323,7 +320,8 @@ public SpriteBatch(IGraphicsDevice iDevice, SpriteSortAlgorithm sortAlgorithm =
/// The delta x coordinate.
/// The delta y coordinate.
private static unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo spriteInfo,
- VertexPositionColorTexture* vpctPtr, float deltaX,
+ VertexPositionColorTexture* vpctPtr,
+ float deltaX,
float deltaY)
{
Vector2 origin = spriteInfo.Origin;
@@ -362,14 +360,13 @@ private static unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
vertex->A = spriteInfo.Color.A * spriteInfo.Opacity;
corner = s_cornerOffsets[j ^ (int)spriteInfo.SpriteEffects];
- vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
+ vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
vertex->V = (spriteInfo.Source.Y + (corner.Y * spriteInfo.Source.Height)) * deltaY;
}
}
else
{
- float cos = (float)Math.Cos(spriteInfo.Rotation);
- float sin = (float)Math.Sin(spriteInfo.Rotation);
+ Math2.SinCos(spriteInfo.Rotation, out float sin, out float cos);
for (int j = 0; j < VERTICES_PER_SPRITE; j++)
{
VertexPositionColorTexture* vertex = vpctPtr + j;
@@ -379,7 +376,7 @@ private static unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
float posY = (corner.Y - origin.Y) * spriteInfo.Destination.Height;
vertex->X = (spriteInfo.Destination.X + (posX * cos)) - (posY * sin);
- vertex->Y = spriteInfo.Destination.Y + (posX * sin) + (posY * cos);
+ vertex->Y = spriteInfo.Destination.Y + (posX * sin) + (posY * cos);
vertex->Z = spriteInfo.Depth;
vertex->W = 1.0f;
@@ -389,7 +386,7 @@ private static unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
vertex->A = spriteInfo.Color.A * spriteInfo.Opacity;
corner = s_cornerOffsets[j ^ (int)spriteInfo.SpriteEffects];
- vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
+ vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
vertex->V = (spriteInfo.Source.Y + (corner.Y * spriteInfo.Source.Height)) * deltaY;
}
}
@@ -407,14 +404,14 @@ private static unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
/// (Optional) The transform matrix.
/// (Optional) The view matrix.
/// (Optional) The scissor rectangle.
- public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
- BlendState blendState = null,
- SamplerState samplerState = null,
- DepthStencilState depthStencilState = null,
- RasterizerState rasterizerState = null,
- Matrix? transformMatrix = null,
- Matrix? viewMatrix = null,
- Rectangle? scissorRectangle = null)
+ public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
+ BlendState? blendState = null,
+ SamplerState? samplerState = null,
+ DepthStencilState? depthStencilState = null,
+ RasterizerState? rasterizerState = null,
+ Matrix? transformMatrix = null,
+ Matrix? viewMatrix = null,
+ Rectangle? scissorRectangle = null)
{
if (_isBeginCalled)
{
@@ -427,7 +424,7 @@ public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
_depthStencilState = depthStencilState;
_rasterizerState = rasterizerState;
_transformMatrix = transformMatrix ?? Matrix.Identity;
- _viewMatrix = viewMatrix ?? Matrix.Identity;
+ _viewMatrix = viewMatrix ?? Matrix.Identity;
_isScissorEnabled = scissorRectangle.HasValue;
_scissorRectangle = scissorRectangle ?? Rectangle.Empty;
@@ -481,7 +478,7 @@ public void Resize(ViewportF viewport)
/// The height.
public void Resize(float width, float height)
{
- float xRatio = width > 0 ? 1f / width : 0f;
+ float xRatio = width > 0 ? 1f / width : 0f;
float yRatio = height > 0 ? -1f / height : 0f;
_projectionMatrix = new Matrix
{
@@ -782,7 +779,7 @@ private void PrepareForRendering()
_context.VertexShader.Set(_vertexShader);
_context.PixelShader.Set(_pixelShader);
- _context.OutputMerger.SetBlendState(_blendState ?? _defaultBlendState);
+ _context.OutputMerger.SetBlendState(_blendState ?? _defaultBlendState);
_context.OutputMerger.SetDepthStencilState(_depthStencilState ?? _defaultDepthStencilState, 1);
_context.Rasterizer.State = _rasterizerState ?? _defaultRasterizerState;
@@ -989,8 +986,12 @@ private struct VertexPositionColorTexture
/// The rotation.
/// The opacity.
/// Depth of the layer.
- public void DrawRectangle(in RectangleF destinationRectangle, in Color color, float lineWidth, float rotation,
- float opacity, float layerDepth)
+ public void DrawRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float lineWidth,
+ float rotation,
+ float opacity,
+ float layerDepth)
{
DrawRectangle(destinationRectangle, color, lineWidth, rotation, s_vector2Zero, opacity, layerDepth);
}
@@ -1005,8 +1006,13 @@ public void DrawRectangle(in RectangleF destinationRectangle, in Color color, fl
/// The origin.
/// The opacity.
/// Depth of the layer.
- public void DrawRectangle(in RectangleF destinationRectangle, in Color color, float lineWidth, float rotation,
- in Vector2 origin, float opacity, float layerDepth)
+ public void DrawRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float lineWidth,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ float layerDepth)
{
Vector2[] vertex;
@@ -1047,7 +1053,7 @@ public void DrawRectangle(in RectangleF destinationRectangle, in Color color,
vertex[j] = new Vector2(
(destinationRectangle.X + (posX * cos)) - (posY * sin),
- destinationRectangle.Y + (posX * sin) + (posY * cos));
+ destinationRectangle.Y + (posX * sin) + (posY * cos));
}
}
@@ -1074,7 +1080,9 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// The color.
/// The opacity.
/// Depth of the layer.
- public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color, float opacity,
+ public void DrawFillRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float opacity,
float layerDepth)
{
DrawSprite(
@@ -1091,8 +1099,12 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// The origin.
/// The opacity.
/// Depth of the layer.
- public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color, float rotation,
- in Vector2 origin, float opacity, float layerDepth)
+ public void DrawFillRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ float layerDepth)
{
DrawSprite(
DefaultTextures.WhiteTexture, destinationRectangle, true, true, s_nullRectangle, color, rotation,
@@ -1108,7 +1120,11 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// Width of the line.
/// The opacity.
/// Depth of the layer.
- public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float lineWidth, float opacity,
+ public void DrawLine(in Vector2 point1,
+ in Vector2 point2,
+ in Color color,
+ float lineWidth,
+ float opacity,
float layerDepth)
{
DrawLine(point1, point2, color, lineWidth, opacity, 1.0f, layerDepth);
@@ -1124,8 +1140,13 @@ public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float
/// The opacity.
/// The length factor.
/// Depth of the layer.
- public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float lineWidth, float opacity,
- float lengthFactor, float layerDepth)
+ public void DrawLine(in Vector2 point1,
+ in Vector2 point2,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ float lengthFactor,
+ float layerDepth)
{
DrawSprite(
DefaultTextures.WhiteTexture, new RectangleF(
@@ -1166,8 +1187,13 @@ public void DrawPolygon(Vector2[] vertex, in Color color, float lineWidth, float
/// The opacity.
/// The segments.
/// Depth of the layer.
- public void DrawCircle(in Vector2 center, float radius, in Color color, float lineWidth, float opacity,
- int segments, float layerDepth)
+ public void DrawCircle(in Vector2 center,
+ float radius,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ int segments,
+ float layerDepth)
{
DrawCircle(center, radius, 0, MathUtil.TwoPi, color, lineWidth, opacity, segments, layerDepth);
}
@@ -1184,9 +1210,15 @@ public void DrawCircle(in Vector2 center, float radius, in Color color, float
/// The opacity.
/// The segments.
/// Depth of the layer.
- public void DrawCircle(in Vector2 center, float radius, float start, float end, in Color color, float lineWidth,
+ public void DrawCircle(in Vector2 center,
+ float radius,
+ float start,
+ float end,
+ in Color color,
+ float lineWidth,
float opacity,
- int segments, float layerDepth)
+ int segments,
+ float layerDepth)
{
Vector2[] vertex = new Vector2[segments];
@@ -1297,8 +1329,10 @@ public void DrawT(Texture texture, in Vector2 position, in Rectangle? sourceRect
/// Destination rectangle.
/// Source rectangle.
/// The color.
- public void Draw(Texture texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color)
+ public void Draw(Texture texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color)
{
DrawSprite(
texture, destinationRectangle, false, false, sourceRectangle, color, 0f, s_vector2Zero, 1.0f,
@@ -1312,8 +1346,10 @@ public void Draw(Texture texture, in RectangleF destinationRectangle, in Rectan
/// Destination rectangle.
/// Source rectangle.
/// The color.
- public void DrawT(Texture texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color)
+ public void DrawT(Texture texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color)
{
DrawSprite(
texture, destinationRectangle, false, true, sourceRectangle, color, 0f, s_vector2Zero, 1.0f,
@@ -1332,8 +1368,13 @@ public void DrawT(Texture texture, in RectangleF destinationRectangle, in Recta
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ public void Draw(Texture texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1354,8 +1395,13 @@ public void Draw(Texture texture, in RectangleF destinationRectangle, in R
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture texture, in RectangleF destinationRectangle, Rectangle? sourceRectangle,
- in Color color, float rotation, Vector2 origin, float opacity,
+ public void DrawT(Texture texture,
+ in RectangleF destinationRectangle,
+ Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1377,8 +1423,14 @@ public void DrawT(Texture texture, in RectangleF destinationRectangle, Rec
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ public void Draw(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1401,8 +1453,14 @@ public void Draw(Texture texture, in Vector2 position, in Rectangle? sour
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ public void DrawT(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1425,8 +1483,14 @@ public void DrawT(Texture texture, in Vector2 position, in Rectangle? sou
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, in Vector2 scale, float opacity,
+ public void Draw(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ in Vector2 scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1449,8 +1513,14 @@ public void Draw(Texture texture, in Vector2 position, in Rectangle? sour
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, in Vector2 scale, float opacity,
+ public void DrawT(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ in Vector2 scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1479,11 +1549,17 @@ public void DrawT(Texture texture, in Vector2 position, in Rectangle? sou
/// The opacity.
/// The effects.
/// The depth.
- private unsafe void DrawSprite(Texture texture, in RectangleF destination,
- bool scaleDestination,
- bool texelCalculation, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin,
- float opacity, SpriteEffects effects, float depth)
+ private unsafe void DrawSprite(Texture texture,
+ in RectangleF destination,
+ bool scaleDestination,
+ bool texelCalculation,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float depth)
{
if (texture.TextureView == null || texture.TexturePointer == IntPtr.Zero)
{
@@ -1497,7 +1573,7 @@ private unsafe void DrawSprite(Texture texture, in RectangleF destination,
if (_spriteQueueCount >= _spriteQueue.Length)
{
- _sortIndices = new int[_spriteQueue.Length * 2];
+ _sortIndices = new int[_spriteQueue.Length * 2];
_sortedSprites = new SpriteInfo[_spriteQueue.Length * 2];
Array.Resize(ref _spriteQueue, _spriteQueue.Length * 2);
}
@@ -1518,9 +1594,9 @@ private unsafe void DrawSprite(Texture texture, in RectangleF destination,
Rectangle rectangle = sourceRectangle.Value;
if (texelCalculation)
{
- spriteInfo->Source.X = rectangle.X + 0.5f;
- spriteInfo->Source.Y = rectangle.Y + 0.5f;
- width = rectangle.Width - 1.0f;
+ spriteInfo->Source.X = rectangle.X + 0.5f;
+ spriteInfo->Source.Y = rectangle.Y + 0.5f;
+ width = rectangle.Width - 1.0f;
height = rectangle.Height - 1.0f;
}
else
@@ -1537,7 +1613,7 @@ private unsafe void DrawSprite(Texture texture, in RectangleF destination,
{
spriteInfo->Source.X = 0.5f;
spriteInfo->Source.Y = 0.5f;
- width = texture.Width - 1.0f;
+ width = texture.Width - 1.0f;
height = texture.Height - 1.0f;
}
else
@@ -1602,7 +1678,11 @@ public void DrawText(SpriteFont font, string text, in Vector2 position, in Color
/// The color.
/// The rotation.
/// Depth of the layer.
- public void DrawText(SpriteFont font, string text, in Vector2 position, in Color color, float rotation,
+ public void DrawText(SpriteFont font,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
float layerDepth)
{
font.Draw(
@@ -1621,8 +1701,15 @@ public void DrawText(SpriteFont font, string text, in Vector2 position, in Color
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, string text, in Vector2 position, in Color color, float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ public void DrawText(SpriteFont font,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, layerDepth);
}
@@ -1641,10 +1728,17 @@ public void DrawText(SpriteFont font, string text, in Vector2 position,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, string text, int start, int end,
- in Vector2 position, in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects,
- float layerDepth)
+ public void DrawText(SpriteFont font,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, start, end, position, color, rotation, origin, opacity, effects, layerDepth);
@@ -1665,9 +1759,16 @@ public void DrawText(SpriteFont font, string text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, string text, int start, int end,
- in Vector2 position, in Size2F dimension,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ public void DrawText(SpriteFont font,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1698,8 +1799,12 @@ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, i
/// The color.
/// The rotation.
/// Depth of the layer.
- public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, in Color color, float rotation,
- float layerDepth)
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, position, color, rotation, Vector2.Zero, 1.0f, SpriteEffects.None, layerDepth);
@@ -1717,9 +1822,15 @@ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, i
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, in Color color,
- float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, layerDepth);
}
@@ -1738,9 +1849,15 @@ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, i
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, StringBuilder text, int start, int end,
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1763,11 +1880,18 @@ public void DrawText(SpriteFont font, StringBuilder text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont font, StringBuilder text, int start, int end,
+ public void DrawText(SpriteFont font,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
- SpriteEffects effects, float layerDepth)
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, start, end, position, dimension, color, rotation, origin, opacity, effects,
@@ -1787,9 +1911,14 @@ public void DrawText(SpriteFont font, StringBuilder text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void DrawTextInternal(Texture texture, in Vector2 position, in Rectangle? sourceRectangle,
+ internal void DrawTextInternal(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1834,11 +1963,17 @@ private void Dispose(bool disposing)
Utilities.Dispose(ref _defaultBlendState);
Utilities.Dispose(ref _defaultRasterizerState);
Utilities.Dispose(ref _defaultSamplerState);
- Utilities.Dispose(ref _depthStencilState);
+ Utilities.Dispose(ref _defaultRasterizerScissorEnabledState);
+ Utilities.Dispose(ref _defaultDepthStencilState);
Utilities.Dispose(ref _vertexBuffer);
Utilities.Dispose(ref _perFrameBuffer);
Utilities.Dispose(ref _indexBuffer);
+
+ Utilities.Dispose(ref _pixelShader);
+ Utilities.Dispose(ref _vertexShader);
+
+ _vertexInputLayout.Dispose();
}
_disposed = true;
diff --git a/Exomia.Framework/Graphics/SpriteBatch2.cs b/src/Exomia.Framework/Graphics/SpriteBatch2.cs
similarity index 83%
rename from Exomia.Framework/Graphics/SpriteBatch2.cs
rename to src/Exomia.Framework/Graphics/SpriteBatch2.cs
index fbc3e6ee..57652568 100644
--- a/Exomia.Framework/Graphics/SpriteBatch2.cs
+++ b/src/Exomia.Framework/Graphics/SpriteBatch2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -15,6 +15,7 @@
using System.Threading.Tasks;
using Exomia.Framework.Content;
using Exomia.Framework.Graphics.SpriteSort;
+using Exomia.Framework.Mathematics;
using SharpDX;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
@@ -121,12 +122,12 @@ private static readonly Vector2[]
///
/// The blend state.
///
- private BlendState _defaultBlendState, _blendState;
+ private BlendState? _defaultBlendState, _blendState;
///
/// The default depth stencil state.
///
- private DepthStencilState _defaultDepthStencilState;
+ private DepthStencilState? _defaultDepthStencilState;
///
/// Gets the state of the rasterizer.
@@ -134,7 +135,7 @@ private static readonly Vector2[]
///
/// The rasterizer state.
///
- private RasterizerState _defaultRasterizerState, _defaultRasterizerScissorEnabledState, _rasterizerState;
+ private RasterizerState? _defaultRasterizerState, _defaultRasterizerScissorEnabledState, _rasterizerState;
///
/// Gets the state of the sampler.
@@ -142,12 +143,12 @@ private static readonly Vector2[]
///
/// The sampler state.
///
- private SamplerState _defaultSamplerState, _samplerState;
+ private SamplerState? _defaultSamplerState, _samplerState;
///
/// State of the depth stencil.
///
- private DepthStencilState _depthStencilState;
+ private DepthStencilState? _depthStencilState;
///
/// Gets a value indicating whether this object is texture generated.
@@ -178,7 +179,7 @@ private static readonly Vector2[]
///
/// The sort indices.
///
- private int[] _sortIndices;
+ private int[] _sortIndices = Array.Empty();
///
/// Queue of sprites.
@@ -193,7 +194,7 @@ private static readonly Vector2[]
///
/// Array of texture 2 ds.
///
- private Texture _texture2DArray;
+ private Texture _texture2DArray = Texture.Empty;
///
/// Gets the transform matrix.
@@ -206,12 +207,12 @@ private static readonly Vector2[]
///
/// The pixel shader.
///
- private PixelShader _pixelShader;
+ private PixelShader? _pixelShader;
///
/// The vertex shader.
///
- private VertexShader _vertexShader;
+ private VertexShader? _vertexShader;
///
/// Initializes static members of the class.
@@ -252,21 +253,19 @@ static SpriteBatch2()
/// Zero-based index of the device.
/// The manager.
/// (Optional) The sort algorithm.
- public SpriteBatch2(IGraphicsDevice iDevice, ITexture2ContentManager manager,
- SpriteSortAlgorithm sortAlgorithm = SpriteSortAlgorithm.MergeSort)
+ public SpriteBatch2(IGraphicsDevice iDevice,
+ ITexture2ContentManager manager,
+ SpriteSortAlgorithm sortAlgorithm = SpriteSortAlgorithm.MergeSort)
{
- _device = iDevice?.Device ?? throw new NullReferenceException(nameof(iDevice));
+ _device = iDevice?.Device ?? throw new NullReferenceException(nameof(iDevice));
_context = iDevice.DeviceContext ?? throw new NullReferenceException(nameof(iDevice));
- _manager = manager ?? throw new NullReferenceException(nameof(manager));
+ _manager = manager ?? throw new NullReferenceException(nameof(manager));
- switch (sortAlgorithm)
+ _spriteSort = sortAlgorithm switch
{
- case SpriteSortAlgorithm.MergeSort:
- _spriteSort = new SpriteMergeSort();
- break;
- default:
- throw new ArgumentException($"invalid sort algorithm ({sortAlgorithm})", nameof(sortAlgorithm));
- }
+ SpriteSortAlgorithm.MergeSort => new SpriteMergeSort(),
+ _ => throw new ArgumentException($"invalid sort algorithm ({sortAlgorithm})", nameof(sortAlgorithm))
+ };
Initialize(_device);
@@ -317,14 +316,14 @@ public SpriteBatch2(IGraphicsDevice iDevice, ITexture2ContentManager manager
/// (Optional) The transform matrix.
/// (Optional) The view matrix.
/// (Optional) The scissor rectangle.
- public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
- BlendState blendState = null,
- SamplerState samplerState = null,
- DepthStencilState depthStencilState = null,
- RasterizerState rasterizerState = null,
- Matrix? transformMatrix = null,
- Matrix? viewMatrix = null,
- Rectangle? scissorRectangle = null)
+ public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
+ BlendState? blendState = null,
+ SamplerState? samplerState = null,
+ DepthStencilState? depthStencilState = null,
+ RasterizerState? rasterizerState = null,
+ Matrix? transformMatrix = null,
+ Matrix? viewMatrix = null,
+ Rectangle? scissorRectangle = null)
{
if (!_isTextureGenerated)
{
@@ -342,7 +341,7 @@ public void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred,
_depthStencilState = depthStencilState;
_rasterizerState = rasterizerState;
_transformMatrix = transformMatrix ?? Matrix.Identity;
- _viewMatrix = viewMatrix ?? Matrix.Identity;
+ _viewMatrix = viewMatrix ?? Matrix.Identity;
_isScissorEnabled = scissorRectangle.HasValue;
_scissorRectangle = scissorRectangle ?? Rectangle.Empty;
@@ -376,7 +375,8 @@ public void GenerateTexture2DArray()
{
if (_manager.GenerateTexture2DArray(_device, out Texture texture))
{
- Interlocked.Exchange(ref _texture2DArray, texture)?.Dispose();
+ Texture t = Interlocked.Exchange(ref _texture2DArray, texture);
+ if (t.TextureView != null) { t.Dispose(); }
_isTextureGenerated = true;
}
}
@@ -406,7 +406,7 @@ public void Resize(ViewportF viewport)
/// The height.
public void Resize(float width, float height)
{
- float xRatio = width > 0 ? 1f / width : 0f;
+ float xRatio = width > 0 ? 1f / width : 0f;
float yRatio = height > 0 ? -1f / height : 0f;
_projectionMatrix = new Matrix
{
@@ -673,7 +673,7 @@ private void PrepareForRendering()
_context.VertexShader.Set(_vertexShader);
_context.PixelShader.Set(_pixelShader);
- _context.OutputMerger.SetBlendState(_blendState ?? _defaultBlendState);
+ _context.OutputMerger.SetBlendState(_blendState ?? _defaultBlendState);
_context.OutputMerger.SetDepthStencilState(_depthStencilState ?? _defaultDepthStencilState, 1);
_context.Rasterizer.State = _rasterizerState ?? _defaultRasterizerState;
@@ -710,7 +710,8 @@ private void PrepareForRendering()
/// The delta x coordinate.
/// The delta y coordinate.
private unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo spriteInfo,
- VertexPositionColorTexture* vpctPtr, float deltaX,
+ VertexPositionColorTexture* vpctPtr,
+ float deltaX,
float deltaY)
{
Vector2 origin = spriteInfo.Origin;
@@ -749,15 +750,14 @@ private unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
vertex->A = spriteInfo.Color.A * spriteInfo.Opacity;
corner = s_corner_offsets[j ^ (int)spriteInfo.SpriteEffects];
- vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
+ vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
vertex->V = (spriteInfo.Source.Y + (corner.Y * spriteInfo.Source.Height)) * deltaY;
vertex->I = spriteInfo.Index;
}
}
else
{
- float cos = (float)Math.Cos(spriteInfo.Rotation);
- float sin = (float)Math.Sin(spriteInfo.Rotation);
+ Math2.SinCos(spriteInfo.Rotation, out float sin, out float cos);
for (int j = 0; j < VERTICES_PER_SPRITE; j++)
{
VertexPositionColorTexture* vertex = vpctPtr + j;
@@ -767,7 +767,7 @@ private unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
float posY = (corner.Y - origin.Y) * spriteInfo.Destination.Height;
vertex->X = (spriteInfo.Destination.X + (posX * cos)) - (posY * sin);
- vertex->Y = spriteInfo.Destination.Y + (posX * sin) + (posY * cos);
+ vertex->Y = spriteInfo.Destination.Y + (posX * sin) + (posY * cos);
vertex->Z = spriteInfo.Depth;
vertex->W = 1.0f;
@@ -777,7 +777,7 @@ private unsafe void UpdateVertexFromSpriteInfoParallel(ref SpriteInfo
vertex->A = spriteInfo.Color.A * spriteInfo.Opacity;
corner = s_corner_offsets[j ^ (int)spriteInfo.SpriteEffects];
- vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
+ vertex->U = (spriteInfo.Source.X + (corner.X * spriteInfo.Source.Width)) * deltaX;
vertex->V = (spriteInfo.Source.Y + (corner.Y * spriteInfo.Source.Height)) * deltaY;
vertex->I = spriteInfo.Index;
}
@@ -921,8 +921,12 @@ private struct VertexPositionColorTexture
/// The rotation.
/// The opacity.
/// Depth of the layer.
- public void DrawRectangle(in RectangleF destinationRectangle, in Color color, float lineWidth, float rotation,
- float opacity, float layerDepth)
+ public void DrawRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float lineWidth,
+ float rotation,
+ float opacity,
+ float layerDepth)
{
DrawRectangle(destinationRectangle, color, lineWidth, rotation, s_vector2Zero, opacity, layerDepth);
}
@@ -937,8 +941,13 @@ public void DrawRectangle(in RectangleF destinationRectangle, in Color color, fl
/// The origin.
/// The opacity.
/// Depth of the layer.
- public void DrawRectangle(in RectangleF destinationRectangle, in Color color, float lineWidth, float rotation,
- in Vector2 origin, float opacity, float layerDepth)
+ public void DrawRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float lineWidth,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ float layerDepth)
{
Vector2[] vertex;
@@ -979,7 +988,7 @@ public void DrawRectangle(in RectangleF destinationRectangle, in Color color,
vertex[j] = new Vector2(
(destinationRectangle.X + (posX * cos)) - (posY * sin),
- destinationRectangle.Y + (posX * sin) + (posY * cos));
+ destinationRectangle.Y + (posX * sin) + (posY * cos));
}
}
@@ -1006,7 +1015,9 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// The color.
/// The opacity.
/// Depth of the layer.
- public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color, float opacity,
+ public void DrawFillRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float opacity,
float layerDepth)
{
DrawSprite(
@@ -1023,8 +1034,12 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// The origin.
/// The opacity.
/// Depth of the layer.
- public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color, float rotation,
- in Vector2 origin, float opacity, float layerDepth)
+ public void DrawFillRectangle(in RectangleF destinationRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ float layerDepth)
{
DrawSprite(
DefaultTextures.WhiteTexture2, destinationRectangle, true, true, s_nullRectangle, color, rotation,
@@ -1040,7 +1055,11 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// Width of the line.
/// The opacity.
/// Depth of the layer.
- public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float lineWidth, float opacity,
+ public void DrawLine(in Vector2 point1,
+ in Vector2 point2,
+ in Color color,
+ float lineWidth,
+ float opacity,
float layerDepth)
{
DrawLine(point1, point2, color, lineWidth, opacity, 1.0f, layerDepth);
@@ -1056,8 +1075,13 @@ public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float
/// The opacity.
/// The length factor.
/// Depth of the layer.
- public void DrawLine(in Vector2 point1, in Vector2 point2, in Color color, float lineWidth, float opacity,
- float lengthFactor, float layerDepth)
+ public void DrawLine(in Vector2 point1,
+ in Vector2 point2,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ float lengthFactor,
+ float layerDepth)
{
DrawSprite(
DefaultTextures.WhiteTexture2, new RectangleF(
@@ -1098,8 +1122,13 @@ public void DrawPolygon(Vector2[] vertex, in Color color, float lineWidth, float
/// The opacity.
/// The segments.
/// Depth of the layer.
- public void DrawCircle(in Vector2 center, float radius, in Color color, float lineWidth, float opacity,
- int segments, float layerDepth)
+ public void DrawCircle(in Vector2 center,
+ float radius,
+ in Color color,
+ float lineWidth,
+ float opacity,
+ int segments,
+ float layerDepth)
{
DrawCircle(center, radius, 0, MathUtil.TwoPi, color, lineWidth, opacity, segments, layerDepth);
}
@@ -1116,9 +1145,15 @@ public void DrawCircle(in Vector2 center, float radius, in Color color, float
/// The opacity.
/// The segments.
/// Depth of the layer.
- public void DrawCircle(in Vector2 center, float radius, float start, float end, in Color color, float lineWidth,
+ public void DrawCircle(in Vector2 center,
+ float radius,
+ float start,
+ float end,
+ in Color color,
+ float lineWidth,
float opacity,
- int segments, float layerDepth)
+ int segments,
+ float layerDepth)
{
Vector2[] vertex = new Vector2[segments];
@@ -1229,8 +1264,10 @@ public void DrawT(Texture2 texture, in Vector2 position, in Rectangle? sourceRec
/// Destination rectangle.
/// Source rectangle.
/// The color.
- public void Draw(Texture2 texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color)
+ public void Draw(Texture2 texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color)
{
DrawSprite(
texture, destinationRectangle, false, false, sourceRectangle, color, 0f, s_vector2Zero, 1.0f,
@@ -1244,8 +1281,10 @@ public void Draw(Texture2 texture, in RectangleF destinationRectangle, in Rectan
/// Destination rectangle.
/// Source rectangle.
/// The color.
- public void DrawT(Texture2 texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color)
+ public void DrawT(Texture2 texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color)
{
DrawSprite(
texture, destinationRectangle, false, true, sourceRectangle, color, 0f, s_vector2Zero, 1.0f,
@@ -1264,8 +1303,13 @@ public void DrawT(Texture2 texture, in RectangleF destinationRectangle, in Recta
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture2 texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ public void Draw(Texture2 texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1286,8 +1330,12 @@ public void Draw(Texture2 texture, in RectangleF destinationRectangle, in R
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture2 texture, in RectangleF destinationRectangle, in Rectangle? sourceRectangle,
- in Color color, float rotation, in Vector2 origin,
+ public void DrawT(Texture2 texture,
+ in RectangleF destinationRectangle,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
SpriteEffects effects,
float layerDepth)
@@ -1310,8 +1358,14 @@ public void DrawT(Texture2 texture, in RectangleF destinationRectangle, in
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture2 texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ public void Draw(Texture2 texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1334,8 +1388,14 @@ public void Draw(Texture2 texture, in Vector2 position, in Rectangle? sour
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture2 texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
+ public void DrawT(Texture2 texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1358,8 +1418,14 @@ public void DrawT(Texture2 texture, in Vector2 position, in Rectangle? sou
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void Draw(Texture2 texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, in Vector2 scale, float opacity,
+ public void Draw(Texture2 texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ in Vector2 scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1382,8 +1448,14 @@ public void Draw(Texture2 texture, in Vector2 position, in Rectangle? sour
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawT(Texture2 texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, in Vector2 scale, float opacity,
+ public void DrawT(Texture2 texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ in Vector2 scale,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1409,13 +1481,19 @@ public void DrawT(Texture2 texture, in Vector2 position, in Rectangle? sou
/// The opacity.
/// The effects.
/// The depth.
- private unsafe void DrawSprite(Texture2 texture, in RectangleF destination,
- bool scaleDestination,
- bool texelCalculation, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin,
- float opacity, SpriteEffects effects, float depth)
+ private unsafe void DrawSprite(Texture2 texture,
+ in RectangleF destination,
+ bool scaleDestination,
+ bool texelCalculation,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float depth)
{
- if (_texture2DArray == null)
+ if (_texture2DArray.TextureView == null)
{
throw new NullReferenceException("texture2DArray");
}
@@ -1442,8 +1520,8 @@ private unsafe void DrawSprite(Texture2 texture, in RectangleF destination,
{
spriteInfo->Source.X = texture.SourceRectangle.X + rectangle.X + 0.5f;
spriteInfo->Source.Y = texture.SourceRectangle.Y + rectangle.Y + 0.5f;
- width = rectangle.Width - 1.0f;
- height = rectangle.Height - 1.0f;
+ width = rectangle.Width - 1.0f;
+ height = rectangle.Height - 1.0f;
}
else
{
@@ -1458,9 +1536,9 @@ private unsafe void DrawSprite(Texture2 texture, in RectangleF destination,
Rectangle rectangle = texture.SourceRectangle;
if (texelCalculation)
{
- spriteInfo->Source.X = rectangle.X + 0.5f;
- spriteInfo->Source.Y = rectangle.Y + 0.5f;
- width = rectangle.Width - 1.0f;
+ spriteInfo->Source.X = rectangle.X + 0.5f;
+ spriteInfo->Source.Y = rectangle.Y + 0.5f;
+ width = rectangle.Width - 1.0f;
height = rectangle.Height - 1.0f;
}
else
@@ -1519,7 +1597,11 @@ public void DrawText(SpriteFont2 font, string text, in Vector2 position, in Colo
/// The color.
/// The rotation.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, string text, in Vector2 position, in Color color, float rotation,
+ public void DrawText(SpriteFont2 font,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
float layerDepth)
{
font.Draw(
@@ -1538,8 +1620,15 @@ public void DrawText(SpriteFont2 font, string text, in Vector2 position, in Colo
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, string text, in Vector2 position, in Color color, float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ public void DrawText(SpriteFont2 font,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, layerDepth);
}
@@ -1558,10 +1647,17 @@ public void DrawText(SpriteFont2 font, string text, in Vector2 position,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, string text, int start, int end,
- in Vector2 position, in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects,
- float layerDepth)
+ public void DrawText(SpriteFont2 font,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, start, end, position, color, rotation, origin, opacity, effects, layerDepth);
@@ -1582,11 +1678,18 @@ public void DrawText(SpriteFont2 font, string text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, string text, int start, int end,
+ public void DrawText(SpriteFont2 font,
+ string text,
+ int start,
+ int end,
in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
- SpriteEffects effects, float layerDepth)
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, start, end, position, dimension, color, rotation, origin, opacity, effects,
@@ -1601,8 +1704,11 @@ public void DrawText(SpriteFont2 font, string text, int start, int end,
/// The position.
/// The color.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position, in Color color,
- float layerDepth)
+ public void DrawText(SpriteFont2 font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float layerDepth)
{
font.Draw(DrawTextInternal, text, position, color, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, layerDepth);
}
@@ -1616,8 +1722,12 @@ public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position,
/// The color.
/// The rotation.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position, in Color color, float rotation,
- float layerDepth)
+ public void DrawText(SpriteFont2 font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, position, color, rotation, Vector2.Zero, 1.0f, SpriteEffects.None, layerDepth);
@@ -1635,9 +1745,15 @@ public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position, in Color color,
- float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ public void DrawText(SpriteFont2 font,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(DrawTextInternal, text, position, color, rotation, origin, opacity, effects, layerDepth);
}
@@ -1656,9 +1772,15 @@ public void DrawText(SpriteFont2 font, StringBuilder text, in Vector2 position,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, StringBuilder text, int start, int end,
+ public void DrawText(SpriteFont2 font,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1681,11 +1803,18 @@ public void DrawText(SpriteFont2 font, StringBuilder text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- public void DrawText(SpriteFont2 font, StringBuilder text, int start, int end,
+ public void DrawText(SpriteFont2 font,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
- SpriteEffects effects, float layerDepth)
+ SpriteEffects effects,
+ float layerDepth)
{
font.Draw(
DrawTextInternal, text, start, end, position, dimension, color, rotation, origin, opacity, effects,
@@ -1705,10 +1834,16 @@ public void DrawText(SpriteFont2 font, StringBuilder text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void DrawTextInternal(Texture2 texture, in Vector2 position, in Rectangle? sourceRectangle,
+ internal void DrawTextInternal(Texture2 texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
- SpriteEffects effects, float layerDepth)
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
DrawSprite(
texture, new RectangleF(position.X, position.Y, scale, scale), true, false, sourceRectangle, color,
@@ -1749,11 +1884,19 @@ private void Dispose(bool disposing)
Utilities.Dispose(ref _defaultBlendState);
Utilities.Dispose(ref _defaultRasterizerState);
Utilities.Dispose(ref _defaultSamplerState);
- Utilities.Dispose(ref _depthStencilState);
+ Utilities.Dispose(ref _defaultRasterizerScissorEnabledState);
+ Utilities.Dispose(ref _defaultDepthStencilState);
Utilities.Dispose(ref _vertexBuffer);
Utilities.Dispose(ref _perFrameBuffer);
Utilities.Dispose(ref _indexBuffer);
+
+ Utilities.Dispose(ref _pixelShader);
+ Utilities.Dispose(ref _vertexShader);
+
+ _vertexInputLayout.Dispose();
+
+ _texture2DArray.Dispose();
}
_disposed = true;
diff --git a/Exomia.Framework/Graphics/SpriteBatchAtlas.cs b/src/Exomia.Framework/Graphics/SpriteBatchAtlas.cs
similarity index 97%
rename from Exomia.Framework/Graphics/SpriteBatchAtlas.cs
rename to src/Exomia.Framework/Graphics/SpriteBatchAtlas.cs
index 735fb911..e78b08eb 100644
--- a/Exomia.Framework/Graphics/SpriteBatchAtlas.cs
+++ b/src/Exomia.Framework/Graphics/SpriteBatchAtlas.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -78,10 +78,10 @@ sealed class SpriteBatchAtlas : IDisposable
/// The height.
public SpriteBatchAtlas(int width, int height)
{
- if (width < MIN_ATLAS_WIDTH) { width = MIN_ATLAS_WIDTH; }
+ if (width < MIN_ATLAS_WIDTH) { width = MIN_ATLAS_WIDTH; }
if (height < MIN_ATLAS_HEIGHT) { height = MIN_ATLAS_HEIGHT; }
- if (width > MAX_ATLAS_WIDTH) { width = MAX_ATLAS_WIDTH; }
+ if (width > MAX_ATLAS_WIDTH) { width = MAX_ATLAS_WIDTH; }
if (height > MAX_ATLAS_HEIGHT) { height = MAX_ATLAS_HEIGHT; }
_width = width;
@@ -113,7 +113,7 @@ internal bool AddTexture(Stream stream, string assetName, out Rectangle sourceRe
using (Image img = Image.FromStream(stream))
{
- if (img.Width > _width) { throw new OverflowException("the image size is to big!"); }
+ if (img.Width > _width) { throw new OverflowException("the image size is to big!"); }
if (img.Height > _height) { throw new OverflowException("the image size is to big!"); }
if (GetFreeLocation(img.Width, img.Height, out int x, out int y))
diff --git a/Exomia.Framework/Graphics/SpriteEffects.cs b/src/Exomia.Framework/Graphics/SpriteEffects.cs
similarity index 96%
rename from Exomia.Framework/Graphics/SpriteEffects.cs
rename to src/Exomia.Framework/Graphics/SpriteEffects.cs
index 67d1c292..f0c735df 100644
--- a/Exomia.Framework/Graphics/SpriteEffects.cs
+++ b/src/Exomia.Framework/Graphics/SpriteEffects.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/SpriteFont.cs b/src/Exomia.Framework/Graphics/SpriteFont.cs
similarity index 88%
rename from Exomia.Framework/Graphics/SpriteFont.cs
rename to src/Exomia.Framework/Graphics/SpriteFont.cs
index 294ca8cf..cc0e8913 100644
--- a/Exomia.Framework/Graphics/SpriteFont.cs
+++ b/src/Exomia.Framework/Graphics/SpriteFont.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -73,7 +73,7 @@ public Glyph DefaultGlyph
///
/// The face.
///
- public string Face { get; set; }
+ public string? Face { get; set; }
///
/// Gets or sets the glyphs.
@@ -111,7 +111,7 @@ public Dictionary Glyphs
///
/// Information describing the image.
///
- public byte[] ImageData { get; set; }
+ public byte[] ImageData { get; set; } = Array.Empty();
///
/// Gets or sets a value indicating whether the italic.
@@ -180,6 +180,7 @@ public SpriteFont()
{
_glyphs = new Dictionary();
Kernings = new Dictionary();
+ _texture = Texture.Empty;
}
///
@@ -257,10 +258,16 @@ public struct Kerning
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal delegate void DrawFont(
- Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
- SpriteEffects effects, float layerDepth);
+ internal delegate void DrawFont(Texture texture,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth);
#region String
@@ -290,8 +297,8 @@ public Vector2 MeasureText(string text, int start, int end)
Vector2 size = Vector2.Zero;
if (start >= end) { return size; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
float x = 0;
float y = 0;
@@ -371,8 +378,8 @@ public Vector2 MeasureText(string text, int start, int end)
public int HitTest(string text, int start, int end, float xPos, float yPos)
{
if (start >= end) { return end; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
if (xPos < 0) { return -1; }
if (yPos < 0) { return -1; }
@@ -418,7 +425,7 @@ public int HitTest(string text, int start, int end, float xPos, float yPos)
}
float nextX = x + glyph.XAdvance + SpacingX;
- float h = y + LineSpacing;
+ float h = y + LineSpacing;
if (xPos >= x && xPos <= nextX + dx && yPos <= h && yPos >= y)
{
@@ -447,9 +454,15 @@ public int HitTest(string text, int start, int end, float xPos, float yPos)
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, in Vector2 position, in Color color,
- float rotation,
- in Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
float x = 0;
float y = 0;
@@ -522,9 +535,15 @@ internal void Draw(DrawFont drawCallback, string text, in Vector2 position, in
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, int start, int end,
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ int start,
+ int end,
in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -601,10 +620,18 @@ internal void Draw(DrawFont drawCallback, string text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, int start, int end,
- in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
- float opacity, SpriteEffects effects, float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ int start,
+ int end,
+ in Vector2 position,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
if (end <= start || end > text.Length) { end = text.Length; }
@@ -649,7 +676,7 @@ internal void Draw(DrawFont drawCallback, string text, int start, int end,
dx += kerning.Offset;
}
- if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
+ if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
if (y + glyph.OffsetY + glyph.Subrect.Height > dimension.Height) { return; }
drawCallback(
@@ -697,8 +724,8 @@ public Vector2 MeasureText(StringBuilder text, int start, int end)
Vector2 size = Vector2.Zero;
if (start >= end) { return size; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
float x = 0;
float y = 0;
@@ -778,8 +805,8 @@ public Vector2 MeasureText(StringBuilder text, int start, int end)
public int HitTest(StringBuilder text, int start, int end, float xPos, float yPos)
{
if (start >= end) { return end; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
if (xPos < 0) { return -1; }
if (yPos < 0) { return -1; }
@@ -825,7 +852,7 @@ public int HitTest(StringBuilder text, int start, int end, float xPos, float yPo
}
float nextX = x + glyph.XAdvance + SpacingX;
- float h = y + LineSpacing;
+ float h = y + LineSpacing;
if (xPos >= x && xPos <= nextX + dx && yPos <= h && yPos >= y)
{
@@ -854,9 +881,15 @@ public int HitTest(StringBuilder text, int start, int end, float xPos, float yPo
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, in Vector2 position, in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects,
- float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
float x = 0;
float y = 0;
@@ -928,9 +961,15 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, in Vector2 posit
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, int start, int end,
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -1007,11 +1046,18 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, int start, in
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, int start, int end,
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
- SpriteEffects effects, float layerDepth)
+ SpriteEffects effects,
+ float layerDepth)
{
if (end <= start || end > text.Length) { end = text.Length; }
@@ -1056,7 +1102,7 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, int start, in
dx += kerning.Offset;
}
- if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
+ if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
if (y + glyph.OffsetY + glyph.Subrect.Height > dimension.Height) { return; }
drawCallback(
@@ -1102,8 +1148,8 @@ private void Dispose(bool disposing)
Kernings.Clear();
}
- Kernings = null;
- _glyphs = null;
+ Kernings.Clear();
+ _glyphs.Clear();
_disposed = true;
}
diff --git a/Exomia.Framework/Graphics/SpriteFont2.cs b/src/Exomia.Framework/Graphics/SpriteFont2.cs
similarity index 88%
rename from Exomia.Framework/Graphics/SpriteFont2.cs
rename to src/Exomia.Framework/Graphics/SpriteFont2.cs
index 811f28ac..f0de5683 100644
--- a/Exomia.Framework/Graphics/SpriteFont2.cs
+++ b/src/Exomia.Framework/Graphics/SpriteFont2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -73,7 +73,7 @@ public SpriteFont.Glyph DefaultGlyph
///
/// The face.
///
- public string Face { get; set; }
+ public string? Face { get; set; }
///
/// Gets or sets the glyphs.
@@ -111,7 +111,7 @@ public SpriteFont.Glyph DefaultGlyph
///
/// Information describing the image.
///
- public byte[] ImageData { get; set; }
+ public byte[] ImageData { get; set; } = Array.Empty();
///
/// Gets or sets a value indicating whether the italic.
@@ -178,8 +178,9 @@ public Texture2 Texture2
///
public SpriteFont2()
{
- _glyphs = new Dictionary();
- Kernings = new Dictionary();
+ _glyphs = new Dictionary();
+ Kernings = new Dictionary();
+ _texture2 = Texture2.Empty;
}
///
@@ -203,10 +204,16 @@ public SpriteFont2()
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal delegate void DrawFont(
- Texture2 texture2, in Vector2 position, in Rectangle? sourceRectangle, in Color color,
- float rotation, in Vector2 origin, float scale, float opacity,
- SpriteEffects effects, float layerDepth);
+ internal delegate void DrawFont(Texture2 texture2,
+ in Vector2 position,
+ in Rectangle? sourceRectangle,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float scale,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth);
#region String
@@ -236,8 +243,8 @@ public Vector2 MeasureText(string text, int start, int end)
Vector2 size = Vector2.Zero;
if (start >= end) { return size; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
float x = 0;
float y = 0;
@@ -317,8 +324,8 @@ public Vector2 MeasureText(string text, int start, int end)
public int HitTest(string text, int start, int end, float xPos, float yPos)
{
if (start >= end) { return end; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
if (xPos < 0) { return -1; }
if (yPos < 0) { return -1; }
@@ -364,7 +371,7 @@ public int HitTest(string text, int start, int end, float xPos, float yPos)
}
float nextX = x + glyph.XAdvance + SpacingX;
- float h = y + LineSpacing;
+ float h = y + LineSpacing;
if (xPos >= x && xPos <= nextX + dx && yPos <= h && yPos >= y)
{
@@ -393,8 +400,15 @@ public int HitTest(string text, int start, int end, float xPos, float yPos)
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, Vector2 position, Color color, float rotation,
- Vector2 origin, float opacity, SpriteEffects effects, float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ Vector2 position,
+ Color color,
+ float rotation,
+ Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
float x = 0;
float y = 0;
@@ -466,10 +480,17 @@ internal void Draw(DrawFont drawCallback, string text, Vector2 position
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, int start, int end,
- Vector2 position, Color color,
- float rotation, Vector2 origin, float opacity, SpriteEffects effects,
- float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ int start,
+ int end,
+ Vector2 position,
+ Color color,
+ float rotation,
+ Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
if (end <= start || end > text.Length) { end = text.Length; }
@@ -543,8 +564,16 @@ internal void Draw(DrawFont drawCallback, string text, int start, int end,
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, string text, int start, int end, Vector2 position,
- Size2F dimension, Color color, float rotation, Vector2 origin, float opacity,
+ internal void Draw(DrawFont drawCallback,
+ string text,
+ int start,
+ int end,
+ Vector2 position,
+ Size2F dimension,
+ Color color,
+ float rotation,
+ Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -591,7 +620,7 @@ internal void Draw(DrawFont drawCallback, string text, int start, int
dx += kerning.Offset;
}
- if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
+ if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
if (y + glyph.OffsetY + glyph.Subrect.Height > dimension.Height) { return; }
drawCallback(
@@ -638,8 +667,8 @@ public Vector2 MeasureText(StringBuilder text, int start, int end)
Vector2 size = Vector2.Zero;
if (start >= end) { return size; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
float x = 0;
float y = 0;
@@ -719,8 +748,8 @@ public Vector2 MeasureText(StringBuilder text, int start, int end)
public int HitTest(StringBuilder text, int start, int end, float xPos, float yPos)
{
if (start >= end) { return end; }
- if (end > text.Length) { end = text.Length; }
- if (start < 0) { start = 0; }
+ if (end > text.Length) { end = text.Length; }
+ if (start < 0) { start = 0; }
if (xPos < 0) { return -1; }
if (yPos < 0) { return -1; }
@@ -766,7 +795,7 @@ public int HitTest(StringBuilder text, int start, int end, float xPos, float yPo
}
float nextX = x + glyph.XAdvance + SpacingX;
- float h = y + LineSpacing;
+ float h = y + LineSpacing;
if (xPos >= x && xPos <= nextX + dx && yPos <= h && yPos >= y)
{
@@ -795,9 +824,15 @@ public int HitTest(StringBuilder text, int start, int end, float xPos, float yPo
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, in Vector2 position, in Color color,
- float rotation, in Vector2 origin, float opacity, SpriteEffects effects,
- float layerDepth)
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ in Vector2 position,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
+ SpriteEffects effects,
+ float layerDepth)
{
float x = 0;
float y = 0;
@@ -869,9 +904,15 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, in Vector2 posit
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, int start, int end,
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Color color, float rotation, in Vector2 origin, float opacity,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
+ float opacity,
SpriteEffects effects,
float layerDepth)
{
@@ -947,11 +988,18 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, int start, in
/// The opacity.
/// The effects.
/// Depth of the layer.
- internal void Draw(DrawFont drawCallback, StringBuilder text, int start, int end,
+ internal void Draw(DrawFont drawCallback,
+ StringBuilder text,
+ int start,
+ int end,
in Vector2 position,
- in Size2F dimension, in Color color, float rotation, in Vector2 origin,
+ in Size2F dimension,
+ in Color color,
+ float rotation,
+ in Vector2 origin,
float opacity,
- SpriteEffects effects, float layerDepth)
+ SpriteEffects effects,
+ float layerDepth)
{
if (end <= start || end > text.Length) { end = text.Length; }
@@ -996,7 +1044,7 @@ internal void Draw(DrawFont drawCallback, StringBuilder text, int start, in
dx += kerning.Offset;
}
- if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
+ if (x + dx + glyph.Subrect.Width > dimension.Width) { return; }
if (y + glyph.OffsetY + glyph.Subrect.Height > dimension.Height) { return; }
drawCallback(
@@ -1041,8 +1089,8 @@ private void Dispose(bool disposing)
Kernings.Clear();
}
- Kernings = null;
- _glyphs = null;
+ Kernings.Clear();
+ _glyphs.Clear();
_disposed = true;
}
diff --git a/Exomia.Framework/Graphics/SpriteFontCR.cs b/src/Exomia.Framework/Graphics/SpriteFontCR.cs
similarity index 98%
rename from Exomia.Framework/Graphics/SpriteFontCR.cs
rename to src/Exomia.Framework/Graphics/SpriteFontCR.cs
index e7894ecc..5b343924 100644
--- a/Exomia.Framework/Graphics/SpriteFontCR.cs
+++ b/src/Exomia.Framework/Graphics/SpriteFontCR.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/SpriteFontCW.cs b/src/Exomia.Framework/Graphics/SpriteFontCW.cs
similarity index 98%
rename from Exomia.Framework/Graphics/SpriteFontCW.cs
rename to src/Exomia.Framework/Graphics/SpriteFontCW.cs
index 32fcfec7..da3ab1a1 100644
--- a/Exomia.Framework/Graphics/SpriteFontCW.cs
+++ b/src/Exomia.Framework/Graphics/SpriteFontCW.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/SpriteFontContentReader.cs b/src/Exomia.Framework/Graphics/SpriteFontContentReader.cs
similarity index 73%
rename from Exomia.Framework/Graphics/SpriteFontContentReader.cs
rename to src/Exomia.Framework/Graphics/SpriteFontContentReader.cs
index 7641a776..1c03a6bd 100644
--- a/Exomia.Framework/Graphics/SpriteFontContentReader.cs
+++ b/src/Exomia.Framework/Graphics/SpriteFontContentReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -21,7 +21,7 @@ namespace Exomia.Framework.Graphics
sealed class SpriteFontContentReader : IContentReader
{
///
- public object ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
+ public object? ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
{
SpriteFont font = ContentSerializer.Read(parameters.Stream);
if (font?.ImageData == null)
@@ -37,11 +37,9 @@ public object ReadContent(IContentManager contentManager, ref ContentReaderParam
try
{
- using (MemoryStream ms = new MemoryStream(font.ImageData))
- {
- ms.Position = 0;
- font.Texture = Texture.Load(graphicsDevice.Device, ms);
- }
+ using MemoryStream ms = new MemoryStream(font.ImageData) { Position = 0 };
+ font.Texture = Texture.Load(graphicsDevice.Device, ms) ??
+ throw new NullReferenceException($"{nameof(font.Texture)}");
}
catch { return null; }
@@ -55,7 +53,7 @@ public object ReadContent(IContentManager contentManager, ref ContentReaderParam
sealed class SpriteFont2ContentReader : IContentReader
{
///
- public object ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
+ public object? ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
{
SpriteFont2 font = ContentSerializer.Read(parameters.Stream);
@@ -73,11 +71,8 @@ public object ReadContent(IContentManager contentManager, ref ContentReaderParam
try
{
- using (MemoryStream ms = new MemoryStream(font.ImageData))
- {
- ms.Position = 0;
- font.Texture2 = manager.AddTexture(ms, parameters.AssetName);
- }
+ using MemoryStream ms = new MemoryStream(font.ImageData) { Position = 0 };
+ font.Texture2 = manager.AddTexture(ms, parameters.AssetName);
}
catch { return null; }
diff --git a/Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs b/src/Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs
similarity index 98%
rename from Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs
rename to src/Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs
index c77feda9..f8d9bd94 100644
--- a/Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs
+++ b/src/Exomia.Framework/Graphics/SpriteSort/ISpriteSort.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs b/src/Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs
similarity index 84%
rename from Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs
rename to src/Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs
index d20f63a3..29b89749 100644
--- a/Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs
+++ b/src/Exomia.Framework/Graphics/SpriteSort/SpriteMergeSort.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -122,7 +122,10 @@ public void SortFb(SpriteBatch2.SpriteInfo[] sInfo, int[] arr, int offset, int l
/// The left.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSortSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo, int* arr, int left, int right,
+ private static void MergeSortSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int right,
int* tempArray)
{
if (left < right)
@@ -151,7 +154,9 @@ private static void MergeSortSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo, int* a
/// The left.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSortSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo, int* arr, int left,
+ private static void MergeSortSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
int right,
int* tempArray)
{
@@ -181,7 +186,10 @@ private static void MergeSortSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo, int*
/// The left.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSortSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo, int* arr, int left, int right,
+ private static void MergeSortSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int right,
int* tempArray)
{
if (left < right)
@@ -210,7 +218,9 @@ private static void MergeSortSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo, int* a
/// The left.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSortSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo, int* arr, int left,
+ private static void MergeSortSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
int right,
int* tempArray)
{
@@ -240,7 +250,10 @@ private static void MergeSortSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo, int*
/// The left.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSortTextureInfo(SpriteBatch.TextureInfo[] tInfo, int* arr, int left, int right,
+ private static void MergeSortTextureInfo(SpriteBatch.TextureInfo[] tInfo,
+ int* arr,
+ int left,
+ int right,
int* tempArray)
{
if (left < right)
@@ -271,8 +284,13 @@ private static void MergeSortTextureInfo(SpriteBatch.TextureInfo[] tInfo, int* a
/// The first middle.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo, int* arr, int left, int middle,
- int middle1, int right, int* tempArray)
+ private static void MergeSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int middle,
+ int middle1,
+ int right,
+ int* tempArray)
{
int oldPosition = left;
int size = (right - left) + 1;
@@ -310,8 +328,13 @@ private static void MergeSpriteInfoBf(SpriteBatch.SpriteInfo[] sInfo, int* arr
/// The first middle.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo, int* arr, int left, int middle,
- int middle1, int right, int* tempArray)
+ private static void MergeSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int middle,
+ int middle1,
+ int right,
+ int* tempArray)
{
int oldPosition = left;
int size = (right - left) + 1;
@@ -349,8 +372,13 @@ private static void MergeSpriteInfoBf(SpriteBatch2.SpriteInfo[] sInfo, int* ar
/// The first middle.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo, int* arr, int left, int middle,
- int middle1, int right, int* tempArray)
+ private static void MergeSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int middle,
+ int middle1,
+ int right,
+ int* tempArray)
{
int oldPosition = left;
int size = (right - left) + 1;
@@ -388,8 +416,13 @@ private static void MergeSpriteInfoFb(SpriteBatch.SpriteInfo[] sInfo, int* arr
/// The first middle.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo, int* arr, int left, int middle,
- int middle1, int right, int* tempArray)
+ private static void MergeSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo,
+ int* arr,
+ int left,
+ int middle,
+ int middle1,
+ int right,
+ int* tempArray)
{
int oldPosition = left;
int size = (right - left) + 1;
@@ -427,8 +460,13 @@ private static void MergeSpriteInfoFb(SpriteBatch2.SpriteInfo[] sInfo, int* ar
/// The first middle.
/// The right.
/// [in,out] If non-null, array of temporaries.
- private static void MergeTextureInfo(SpriteBatch.TextureInfo[] tInfo, int* arr, int left, int middle,
- int middle1, int right, int* tempArray)
+ private static void MergeTextureInfo(SpriteBatch.TextureInfo[] tInfo,
+ int* arr,
+ int left,
+ int middle,
+ int middle1,
+ int right,
+ int* tempArray)
{
int oldPosition = left;
int size = (right - left) + 1;
diff --git a/Exomia.Framework/Graphics/SpriteSortMode.cs b/src/Exomia.Framework/Graphics/SpriteSortMode.cs
similarity index 96%
rename from Exomia.Framework/Graphics/SpriteSortMode.cs
rename to src/Exomia.Framework/Graphics/SpriteSortMode.cs
index 6b2b2576..1d2054c5 100644
--- a/Exomia.Framework/Graphics/SpriteSortMode.cs
+++ b/src/Exomia.Framework/Graphics/SpriteSortMode.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Graphics/Texture.cs b/src/Exomia.Framework/Graphics/Texture.cs
similarity index 88%
rename from Exomia.Framework/Graphics/Texture.cs
rename to src/Exomia.Framework/Graphics/Texture.cs
index 6df1561b..76c1992d 100644
--- a/Exomia.Framework/Graphics/Texture.cs
+++ b/src/Exomia.Framework/Graphics/Texture.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -27,6 +27,14 @@ public sealed class Texture : IDisposable
///
private ShaderResourceView1 _textureView;
+ ///
+ /// Gets the empty.
+ ///
+ ///
+ /// The empty.
+ ///
+ public static Texture Empty { get; } = new Texture(null!, 0, 0);
+
///
/// Height.
///
@@ -94,16 +102,14 @@ public Texture(ShaderResourceView1 textureView, int width, int height)
///
/// new texture.
///
- public static Texture Load(Device5 device, Stream stream)
+ public static Texture? Load(Device5 device, Stream stream)
{
try
{
- using (Texture2D texture2D = TextureHelper.LoadTexture2D(device, stream))
- {
- return new Texture(
- new ShaderResourceView1(device, texture2D), texture2D.Description.Width,
- texture2D.Description.Height);
- }
+ using Texture2D texture2D = TextureHelper.LoadTexture2D(device, stream);
+ return new Texture(
+ new ShaderResourceView1(device, texture2D), texture2D.Description.Width,
+ texture2D.Description.Height);
}
catch { return null; }
}
@@ -152,6 +158,14 @@ public void Dispose()
[ContentReadable(typeof(Texture2ContentReader))]
public sealed class Texture2 : IDisposable
{
+ ///
+ /// Gets the empty.
+ ///
+ ///
+ /// The empty.
+ ///
+ public static Texture2 Empty { get; } = new Texture2(-1, null!, Rectangle.Empty);
+
///
/// AssetName.
///
diff --git a/Exomia.Framework/Graphics/TextureContentReader.cs b/src/Exomia.Framework/Graphics/TextureContentReader.cs
similarity index 86%
rename from Exomia.Framework/Graphics/TextureContentReader.cs
rename to src/Exomia.Framework/Graphics/TextureContentReader.cs
index 3abd2a72..d6aeb9cf 100644
--- a/Exomia.Framework/Graphics/TextureContentReader.cs
+++ b/src/Exomia.Framework/Graphics/TextureContentReader.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -19,7 +19,7 @@ namespace Exomia.Framework.Graphics
sealed class TextureContentReader : IContentReader
{
///
- public object ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
+ public object? ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
{
IGraphicsDevice graphicsDevice = contentManager.ServiceRegistry.GetService();
if (graphicsDevice == null)
@@ -36,7 +36,7 @@ public object ReadContent(IContentManager contentManager, ref ContentReaderParam
sealed class Texture2ContentReader : IContentReader
{
///
- public object ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
+ public object? ReadContent(IContentManager contentManager, ref ContentReaderParameters parameters)
{
ITexture2ContentManager manager = contentManager.ServiceRegistry.GetService();
if (manager == null)
diff --git a/Exomia.Framework/Graphics/TextureHelper.cs b/src/Exomia.Framework/Graphics/TextureHelper.cs
similarity index 96%
rename from Exomia.Framework/Graphics/TextureHelper.cs
rename to src/Exomia.Framework/Graphics/TextureHelper.cs
index c31c18c3..951bd8ea 100644
--- a/Exomia.Framework/Graphics/TextureHelper.cs
+++ b/src/Exomia.Framework/Graphics/TextureHelper.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -37,7 +37,9 @@ public static class TextureHelper
///
/// The new texture.
///
- public static Texture2D CreateTexture(Device5 device, int width, int height,
+ public static Texture2D CreateTexture(Device5 device,
+ int width,
+ int height,
Format format = Format.B8G8R8A8_UNorm)
{
lock (device)
diff --git a/Exomia.Framework/ICloneable.cs b/src/Exomia.Framework/ICloneable.cs
similarity index 94%
rename from Exomia.Framework/ICloneable.cs
rename to src/Exomia.Framework/ICloneable.cs
index 8e65c74b..86867d75 100644
--- a/Exomia.Framework/ICloneable.cs
+++ b/src/Exomia.Framework/ICloneable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IComponent.cs b/src/Exomia.Framework/IComponent.cs
similarity index 93%
rename from Exomia.Framework/IComponent.cs
rename to src/Exomia.Framework/IComponent.cs
index 81bbc749..1a739091 100644
--- a/Exomia.Framework/IComponent.cs
+++ b/src/Exomia.Framework/IComponent.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IContentable.cs b/src/Exomia.Framework/IContentable.cs
similarity index 95%
rename from Exomia.Framework/IContentable.cs
rename to src/Exomia.Framework/IContentable.cs
index df655533..85dafd63 100644
--- a/Exomia.Framework/IContentable.cs
+++ b/src/Exomia.Framework/IContentable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IDrawable.cs b/src/Exomia.Framework/IDrawable.cs
similarity index 98%
rename from Exomia.Framework/IDrawable.cs
rename to src/Exomia.Framework/IDrawable.cs
index b90e8e0b..4230cddc 100644
--- a/Exomia.Framework/IDrawable.cs
+++ b/src/Exomia.Framework/IDrawable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IInitializable.cs b/src/Exomia.Framework/IInitializable.cs
similarity index 95%
rename from Exomia.Framework/IInitializable.cs
rename to src/Exomia.Framework/IInitializable.cs
index 1296236a..ba3db8dd 100644
--- a/Exomia.Framework/IInitializable.cs
+++ b/src/Exomia.Framework/IInitializable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IRunable.cs b/src/Exomia.Framework/IRunable.cs
similarity index 95%
rename from Exomia.Framework/IRunable.cs
rename to src/Exomia.Framework/IRunable.cs
index 98d542bd..d31e8c66 100644
--- a/Exomia.Framework/IRunable.cs
+++ b/src/Exomia.Framework/IRunable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IServiceRegistry.cs b/src/Exomia.Framework/IServiceRegistry.cs
similarity index 98%
rename from Exomia.Framework/IServiceRegistry.cs
rename to src/Exomia.Framework/IServiceRegistry.cs
index af67a6b4..1dbb0d87 100644
--- a/Exomia.Framework/IServiceRegistry.cs
+++ b/src/Exomia.Framework/IServiceRegistry.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/IUpdateable.cs b/src/Exomia.Framework/IUpdateable.cs
similarity index 97%
rename from Exomia.Framework/IUpdateable.cs
rename to src/Exomia.Framework/IUpdateable.cs
index 67ced021..403775d4 100644
--- a/Exomia.Framework/IUpdateable.cs
+++ b/src/Exomia.Framework/IUpdateable.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Index2.cs b/src/Exomia.Framework/Index2.cs
similarity index 99%
rename from Exomia.Framework/Index2.cs
rename to src/Exomia.Framework/Index2.cs
index 5ff5e3b3..dd022d7f 100644
--- a/Exomia.Framework/Index2.cs
+++ b/src/Exomia.Framework/Index2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Index3.cs b/src/Exomia.Framework/Index3.cs
similarity index 99%
rename from Exomia.Framework/Index3.cs
rename to src/Exomia.Framework/Index3.cs
index ff69bed7..af295c9b 100644
--- a/Exomia.Framework/Index3.cs
+++ b/src/Exomia.Framework/Index3.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/src/Exomia.Framework/Input/IInputHandler.cs b/src/Exomia.Framework/Input/IInputHandler.cs
new file mode 100644
index 00000000..77171efa
--- /dev/null
+++ b/src/Exomia.Framework/Input/IInputHandler.cs
@@ -0,0 +1,38 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+namespace Exomia.Framework.Input
+{
+ ///
+ /// an interface used for input handling.
+ ///
+ public interface IInputHandler : IRawInputHandler
+ {
+ ///
+ /// called than a key is down.
+ ///
+ /// The key value.
+ /// The key modifiers.
+ void Input_KeyDown(int keyValue, KeyModifier modifiers);
+
+ ///
+ /// called than a key is pressed.
+ ///
+ /// key char.
+ void Input_KeyPress(char key);
+
+ ///
+ /// called than a key is up.
+ ///
+ /// key value.
+ /// The key modifiers.
+ void Input_KeyUp(int keyValue, KeyModifier modifiers);
+ }
+}
\ No newline at end of file
diff --git a/src/Exomia.Framework/Input/IRawInputDevice.cs b/src/Exomia.Framework/Input/IRawInputDevice.cs
new file mode 100644
index 00000000..8a7b7c9b
--- /dev/null
+++ b/src/Exomia.Framework/Input/IRawInputDevice.cs
@@ -0,0 +1,36 @@
+using System.Windows.Forms;
+
+namespace Exomia.Framework.Input
+{
+ ///
+ /// Interface for raw input device.
+ ///
+ interface IRawInputDevice
+ {
+ ///
+ /// Occurs when raw mouse down.
+ ///
+ event MouseEventHandler? RawMouseDown;
+ ///
+ /// Occurs when raw mouse up.
+ ///
+ event MouseEventHandler? RawMouseUp;
+ ///
+ /// Occurs when raw mouse down.
+ ///
+ event MouseEventHandler? RawMouseClick;
+ ///
+ /// Occurs when raw mouse move.
+ ///
+ event MouseEventHandler? RawMouseMove;
+ ///
+ /// Occurs when raw mouse wheel.
+ ///
+ event MouseEventHandler? RawMouseWheel;
+
+ ///
+ /// Occurs when raw key event.
+ ///
+ event RefEventHandler? RawKeyEvent;
+ }
+}
diff --git a/Exomia.Framework/Input/IInputHandler.cs b/src/Exomia.Framework/Input/IRawInputHandler.cs
similarity index 67%
rename from Exomia.Framework/Input/IInputHandler.cs
rename to src/Exomia.Framework/Input/IRawInputHandler.cs
index 866b0063..ba4ea673 100644
--- a/Exomia.Framework/Input/IInputHandler.cs
+++ b/src/Exomia.Framework/Input/IRawInputHandler.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -8,36 +8,20 @@
#endregion
+using System.Windows.Forms;
+
namespace Exomia.Framework.Input
{
///
- /// an interface used for input handling.
+ /// Interface for raw input handler.
///
- public interface IInputHandler
+ public interface IRawInputHandler
{
///
- /// called than a key is down.
- ///
- /// key value.
- /// true if shift ley is down; false otherwise.
- /// true if alt key is down; false otherwise.
- /// true if ctrl key is down; false otherwise.
- void Input_KeyDown(int keyValue, bool shift, bool alt, bool ctrl);
-
- ///
- /// called than a key is pressed.
- ///
- /// key char.
- void Input_KeyPress(char key);
-
- ///
- /// called than a key is up.
+ /// called than a key event occured.
///
- /// key value.
- /// true if shift ley is down; false otherwise.
- /// true if alt key is down; false otherwise.
- /// true if ctrl key is down; false otherwise.
- void Input_KeyUp(int keyValue, bool shift, bool alt, bool ctrl);
+ /// [in,out] The message.
+ void Input_KeyEvent(ref Message message);
///
/// called than a mouse button is clicked.
diff --git a/Exomia.Framework/Input/Key.cs b/src/Exomia.Framework/Input/Key.cs
similarity index 99%
rename from Exomia.Framework/Input/Key.cs
rename to src/Exomia.Framework/Input/Key.cs
index 2ca1ebe2..a86eba72 100644
--- a/Exomia.Framework/Input/Key.cs
+++ b/src/Exomia.Framework/Input/Key.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -8,7 +8,6 @@
#endregion
-// ReSharper disable InconsistentNaming
namespace Exomia.Framework.Input
{
///
diff --git a/src/Exomia.Framework/Input/KeyModifier.cs b/src/Exomia.Framework/Input/KeyModifier.cs
new file mode 100644
index 00000000..d0e77a92
--- /dev/null
+++ b/src/Exomia.Framework/Input/KeyModifier.cs
@@ -0,0 +1,36 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+using System;
+
+namespace Exomia.Framework.Input
+{
+ ///
+ /// Values that represent KeyModifier.
+ ///
+ [Flags]
+ public enum KeyModifier
+ {
+ ///
+ /// An enum constant representing the shift option.
+ ///
+ Shift = 1,
+
+ ///
+ /// An enum constant representing the Alternate option.
+ ///
+ Alt = 2,
+
+ ///
+ /// An enum constant representing the control option.
+ ///
+ Control = 4
+ }
+}
\ No newline at end of file
diff --git a/src/Exomia.Framework/Input/MouseButtons.cs b/src/Exomia.Framework/Input/MouseButtons.cs
new file mode 100644
index 00000000..3746fff7
--- /dev/null
+++ b/src/Exomia.Framework/Input/MouseButtons.cs
@@ -0,0 +1,51 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+using System;
+
+namespace Exomia.Framework.Input
+{
+ ///
+ /// MouseButtons enum.
+ ///
+ [Flags]
+ public enum MouseButtons
+ {
+ ///
+ /// default
+ ///
+ None = 0,
+
+ ///
+ /// Left mouse button
+ ///
+ Left = 0x01,
+
+ ///
+ /// Middle mouse button
+ ///
+ Middle = 0x10,
+
+ ///
+ /// Right mouse button
+ ///
+ Right = 0x02,
+
+ ///
+ /// A binary constant representing the button 1 flag.
+ ///
+ XButton1 = 0x20,
+
+ ///
+ /// A binary constant representing the button 2 flag.
+ ///
+ XButton2 = 0x40
+ }
+}
\ No newline at end of file
diff --git a/src/Exomia.Framework/Input/MouseEventHandler.cs b/src/Exomia.Framework/Input/MouseEventHandler.cs
new file mode 100644
index 00000000..58215703
--- /dev/null
+++ b/src/Exomia.Framework/Input/MouseEventHandler.cs
@@ -0,0 +1,12 @@
+namespace Exomia.Framework.Input
+{
+ ///
+ /// Delegate for handling mouse events.
+ ///
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ public delegate void MouseEventHandler(int x, int y, MouseButtons buttons, int clicks, int wheelDelta);
+}
diff --git a/src/Exomia.Framework/Input/Win32Message.cs b/src/Exomia.Framework/Input/Win32Message.cs
new file mode 100644
index 00000000..e42008b1
--- /dev/null
+++ b/src/Exomia.Framework/Input/Win32Message.cs
@@ -0,0 +1,114 @@
+#region License
+
+// Copyright (c) 2018-2020, exomia
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree.
+
+#endregion
+
+namespace Exomia.Framework.Input {
+ static class Win32Message
+ {
+ ///
+ /// The wm keydown.
+ ///
+ public const int WM_KEYDOWN = 0x0100;
+
+ ///
+ /// The wm keyup.
+ ///
+ public const int WM_KEYUP = 0x0101;
+
+ ///
+ /// The wm syskeydown.
+ ///
+ public const int WM_SYSKEYDOWN = 0x0104;
+
+ ///
+ /// The wm syskeyup.
+ ///
+ public const int WM_SYSKEYUP = 0x0105;
+
+ ///
+ /// The wm character.
+ ///
+ public const int WM_CHAR = 0x0102;
+
+ ///
+ /// The wm unichar.
+ ///
+ public const int WM_UNICHAR = 0x0109;
+
+ ///
+ /// The wm mousemove.
+ ///
+ public const int WM_MOUSEMOVE = 0x0200;
+
+ ///
+ /// The wm mousewheel.
+ ///
+ public const int WM_MOUSEWHEEL = 0x020A;
+
+ ///
+ /// The wm lbuttondown.
+ ///
+ public const int WM_LBUTTONDOWN = 0x0201;
+
+ ///
+ /// The wm lbuttonup.
+ ///
+ public const int WM_LBUTTONUP = 0x0202;
+
+ ///
+ /// The wm mbuttondown.
+ ///
+ public const int WM_MBUTTONDOWN = 0x0207;
+
+ ///
+ /// The wm mbuttonup.
+ ///
+ public const int WM_MBUTTONUP = 0x0208;
+
+ ///
+ /// The wm rbuttondown.
+ ///
+ public const int WM_RBUTTONDOWN = 0x0204;
+
+ ///
+ /// The wm rbuttonup.
+ ///
+ public const int WM_RBUTTONUP = 0x0205;
+
+ ///
+ /// The wm xbuttondown.
+ ///
+ public const int WM_XBUTTONDOWN = 0x020B;
+
+ ///
+ /// The wm xbuttonup.
+ ///
+ public const int WM_XBUTTONUP = 0x020C;
+
+ ///
+ /// The wm lbuttondblclk.
+ ///
+ public const int WM_LBUTTONDBLCLK = 0x0203;
+
+ ///
+ /// The wm mbuttondblclk.
+ ///
+ public const int WM_MBUTTONDBLCLK = 0x0209;
+
+ ///
+ /// The wm rbuttondblclk.
+ ///
+ public const int WM_RBUTTONDBLCLK = 0x0206;
+
+ ///
+ /// The wm xbuttondblclk.
+ ///
+ public const int WM_XBUTTONDBLCLK = 0x020D;
+ }
+}
\ No newline at end of file
diff --git a/Exomia.Framework/Linq/ForEach.cs b/src/Exomia.Framework/Linq/ForEach.cs
similarity index 98%
rename from Exomia.Framework/Linq/ForEach.cs
rename to src/Exomia.Framework/Linq/ForEach.cs
index ed47a4e5..1dc53624 100644
--- a/Exomia.Framework/Linq/ForEach.cs
+++ b/src/Exomia.Framework/Linq/ForEach.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Linq/Min.cs b/src/Exomia.Framework/Linq/Min.cs
similarity index 71%
rename from Exomia.Framework/Linq/Min.cs
rename to src/Exomia.Framework/Linq/Min.cs
index 9f0b2c07..0ec9d197 100644
--- a/Exomia.Framework/Linq/Min.cs
+++ b/src/Exomia.Framework/Linq/Min.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -45,33 +45,32 @@ public static partial class LinqExt
/// Thrown when the requested operation is invalid.
/// ###
/// The source sequence is empty.
- public static TSource Min(this IEnumerable source, Func predicate,
- IComparer comparer = null)
+ public static TSource Min(this IEnumerable source,
+ Func predicate,
+ IComparer? comparer = null)
{
- if (source == null) { throw new ArgumentNullException(nameof(source)); }
+ if (source == null) { throw new ArgumentNullException(nameof(source)); }
if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); }
IComparer c = comparer ?? Comparer.Default;
- using (IEnumerator enumerator = source.GetEnumerator())
- {
- if (!enumerator.MoveNext()) { throw new InvalidOperationException("The source sequence is empty."); }
+ using IEnumerator enumerator = source.GetEnumerator();
+ if (!enumerator.MoveNext()) { throw new InvalidOperationException("The source sequence is empty."); }
- TSource r = enumerator.Current;
- T min = predicate(r);
+ TSource r = enumerator.Current;
+ T min = predicate(r);
- while (enumerator.MoveNext())
+ while (enumerator.MoveNext())
+ {
+ T v = predicate(enumerator.Current);
+ if (c.Compare(v, min) < 0)
{
- T v = predicate(enumerator.Current);
- if (c.Compare(v, min) < 0)
- {
- min = v;
- r = enumerator.Current;
- }
+ min = v;
+ r = enumerator.Current;
}
-
- return r;
}
+
+ return r;
}
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Linq/Sum.cs b/src/Exomia.Framework/Linq/Sum.cs
similarity index 99%
rename from Exomia.Framework/Linq/Sum.cs
rename to src/Exomia.Framework/Linq/Sum.cs
index 99f8e3bf..3853c264 100644
--- a/Exomia.Framework/Linq/Sum.cs
+++ b/src/Exomia.Framework/Linq/Sum.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs b/src/Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs
similarity index 98%
rename from Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs
rename to src/Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs
index 513cf80f..7af3bb70 100644
--- a/Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs
+++ b/src/Exomia.Framework/Mathematics/Extensions/Numeric/NumericExtensions.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs b/src/Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs
similarity index 97%
rename from Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs
rename to src/Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs
index 39443be0..163d32bf 100644
--- a/Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs
+++ b/src/Exomia.Framework/Mathematics/Extensions/Vector/Vector2Extensions.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -31,7 +31,7 @@ public static double AngleBetween(this Vector2 vec1, in Vector2 vec2)
{
float scalar = (vec1.X * vec2.X) + (vec1.Y * vec2.Y);
float length = vec1.Length() * vec2.Length();
- return Math.Cos(scalar / length);
+ return Math.Cos(scalar / length);
}
///
diff --git a/Exomia.Framework/Mathematics/Math2.Curves.cs b/src/Exomia.Framework/Mathematics/Math2.Curves.cs
similarity index 98%
rename from Exomia.Framework/Mathematics/Math2.Curves.cs
rename to src/Exomia.Framework/Mathematics/Math2.Curves.cs
index 5a684f8a..0dc3591c 100644
--- a/Exomia.Framework/Mathematics/Math2.Curves.cs
+++ b/src/Exomia.Framework/Mathematics/Math2.Curves.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Mathematics/Math2.MV.cs b/src/Exomia.Framework/Mathematics/Math2.MV.cs
similarity index 84%
rename from Exomia.Framework/Mathematics/Math2.MV.cs
rename to src/Exomia.Framework/Mathematics/Math2.MV.cs
index 0b5096a6..bffacbe8 100644
--- a/Exomia.Framework/Mathematics/Math2.MV.cs
+++ b/src/Exomia.Framework/Mathematics/Math2.MV.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -27,12 +27,15 @@ public static partial class Math2
/// scale.
/// rotation.
/// [out] out transform matrix.
- public static void CalculateTransformMatrix(in Vector2 position, in Vector2 origin, in Vector2 scale,
- float rotation, out Matrix transform)
+ public static void CalculateTransformMatrix(in Vector2 position,
+ in Vector2 origin,
+ in Vector2 scale,
+ float rotation,
+ out Matrix transform)
{
transform = Matrix.Translation(-origin.X, -origin.Y, 0) *
- Matrix.RotationZ(rotation) *
- Matrix.Scaling(scale.X, scale.Y, 0.0f) *
+ Matrix.RotationZ(rotation) *
+ Matrix.Scaling(scale.X, scale.Y, 0.0f) *
Matrix.Translation(position.X, position.Y, 0);
}
@@ -46,12 +49,14 @@ public static void CalculateTransformMatrix(in Vector2 position, in Vector2 ori
///
/// transform matrix.
///
- public static Matrix CalculateTransformMatrix(in Vector2 position, in Vector2 origin, in Vector2 scale,
+ public static Matrix CalculateTransformMatrix(in Vector2 position,
+ in Vector2 origin,
+ in Vector2 scale,
float rotation)
{
return Matrix.Translation(-origin.X, -origin.Y, 0) *
- Matrix.RotationZ(rotation) *
- Matrix.Scaling(scale.X, scale.Y, 0.0f) *
+ Matrix.RotationZ(rotation) *
+ Matrix.Scaling(scale.X, scale.Y, 0.0f) *
Matrix.Translation(position.X, position.Y, 0);
}
@@ -117,8 +122,12 @@ public static RectangleF CreateAABB(in Matrix transform, float width, float heig
///
/// axis aligned bounding box.
///
- public static RectangleF CreateAABB(in Vector2 position, in Vector2 origin, in Vector2 scale, float rotation,
- float width, float height)
+ public static RectangleF CreateAABB(in Vector2 position,
+ in Vector2 origin,
+ in Vector2 scale,
+ float rotation,
+ float width,
+ float height)
{
return CreateAABB(CalculateTransformMatrix(position, origin, scale, rotation), width, height);
}
diff --git a/Exomia.Framework/Mathematics/Math2.cs b/src/Exomia.Framework/Mathematics/Math2.cs
similarity index 78%
rename from Exomia.Framework/Mathematics/Math2.cs
rename to src/Exomia.Framework/Mathematics/Math2.cs
index 51f3b5ce..abb4543a 100644
--- a/Exomia.Framework/Mathematics/Math2.cs
+++ b/src/Exomia.Framework/Mathematics/Math2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -43,72 +43,6 @@ public static int Ceiling(double f)
return (int)(L_OFFSET_MAX - (long)(L_OFFSET_MAX - f));
}
- ///
- /// Returns the number of 'on' bits in x
- ///
- public static int CountOnes(byte x)
- {
- int y = x;
- y -= (y >> 1) & 0x55;
- y = ((y >> 2) & 0x33) + (y & 0x33);
- return (y & 0x0F) + (y >> 4);
- }
-
- ///
- /// Returns the number of 'on' bits in x
- ///
- public static int CountOnes(ushort x)
- {
- int y = x;
- y -= (y >> 1) & 0x5555;
- y = ((y >> 2) & 0x3333) + (y & 0x3333);
- y = ((y >> 4) + y) & 0x0F0F;
- return (y + (y >> 8)) & 0x001F;
- }
-
- ///
- /// Returns the number of 'on' bits in x
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountOnes(int x)
- {
- return CountOnes((uint)x);
- }
-
- ///
- /// Returns the number of 'on' bits in x
- ///
- public static int CountOnes(uint x)
- {
- x -= (x >> 1) & 0x55555555;
- x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
- x = ((x >> 4) + x) & 0x0F0F0F0F;
- x += x >> 8;
- return (int)((x + (x >> 16)) & 0x0000003F);
- }
-
- ///
- /// Returns the number of 'on' bits in x
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountOnes(long x)
- {
- return CountOnes((ulong)x);
- }
-
- ///
- /// Returns the number of 'on' bits in x
- ///
- public static int CountOnes(ulong x)
- {
- x -= (x >> 1) & 0x5555555555555555u;
- x = ((x >> 2) & 0x3333333333333333u) + (x & 0x3333333333333333u);
- x = ((x >> 4) + x) & 0x0F0F0F0F0F0F0F0Fu;
- x += x >> 8;
- x += x >> 16;
- return ((int)x + (int)(x >> 32)) & 0x0000007F;
- }
-
///
/// Returns the largest integer less than or equal to the specified floating-point number.
///
@@ -120,146 +54,6 @@ public static int Floor(double f)
return (int)((long)(f + L_OFFSET_MAX) - L_OFFSET_MAX);
}
- ///
- /// Interpolates between two values using a linear function by a given amount.
- ///
- /// Value to interpolate from.
- /// Value to interpolate to.
- /// Interpolation amount.
- /// The result of linear interpolation of values based on the amount.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static byte Lerp(byte a, byte b, double t)
- {
- return (byte)(a + (t * (b - a)));
- }
-
- ///
- /// Interpolates between two values using a linear function by a given amount.
- ///
- /// Value to interpolate from.
- /// Value to interpolate to.
- /// Interpolation amount.
- /// The result of linear interpolation of values based on the amount.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Lerp(float a, float b, double t)
- {
- return (float)(a + (t * (b - a)));
- }
-
- ///
- /// Interpolates between two values using a linear function by a given amount.
- ///
- /// Value to interpolate from.
- /// Value to interpolate to.
- /// Interpolation amount.
- /// The result of linear interpolation of values based on the amount.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Lerp(double a, double b, double t)
- {
- return a + (t * (b - a));
- }
-
- ///
- /// LinearInterpolate
- ///
- /// a
- /// b
- /// t
- /// new Vector2
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Lerp(Vector2 a, Vector2 b, double t)
- {
- return new Vector2(Lerp(a.X, b.X, t), Lerp(a.Y, b.Y, t));
- }
-
- ///
- /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
- ///
- ///
- /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
- ///
- public static int Log2Floor(uint x)
- {
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- return CountOnes(x | (x >> 16)) - 1;
- }
-
- ///
- /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
- ///
- ///
- /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Log2Floor(int x)
- {
- if (x < 0) { throw new ArgumentOutOfRangeException(nameof(x), "Can't compute Log2Floor of a negative"); }
- return Log2Floor((uint)x);
- }
-
- ///
- /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
- ///
- ///
- /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Log2Floor(ulong x)
- {
- uint xHi = (uint)(x >> 32);
- if (xHi != 0)
- {
- return 32 + Log2Floor(xHi);
- }
- return Log2Floor((uint)x);
- }
-
- ///
- /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
- ///
- ///
- /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Log2Floor(long x)
- {
- if (x < 0) { throw new ArgumentOutOfRangeException(nameof(x), "Can't compute Log2Floor of a negative"); }
- return Log2Floor((ulong)x);
- }
-
- ///
- /// Maps a value from l1 to u1 to l2 to u2
- ///
- /// Value
- /// Lower 1
- /// Upper 1
- /// Lower 2
- /// Upper 2
- /// maped value
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Map(float v, float l1, float u1, float l2, float u2)
- {
- return (((v - l1) / (u1 - l1)) * (u2 - l2)) + l2;
- }
-
- ///
- /// Maps a value from l1 to u1 to l2 to u2
- ///
- /// Value
- /// Lower 1
- /// Upper 1
- /// Lower 2
- /// Upper 2
- /// maped value
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Map(double v, double l1, double u1, double l2, double u2)
- {
- return (((v - l1) / (u1 - l1)) * (u2 - l2)) + l2;
- }
-
///
/// raise b to the power of e
///
@@ -305,6 +99,90 @@ public static float Pow(float b, int e)
}
return result;
}
+
+ private const float PI = (float)Math.PI;
+ private const float TWOPI = (float)(2.0 * Math.PI);
+ private const float ITWOPI = 1.0f / TWOPI;
+ private const float PITWO = (float)(Math.PI * 0.5);
+
+ ///
+ /// Returns the approximated sinus of a specified number.
+ ///
+ /// The value.
+ ///
+ /// A float.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float Sin(float x)
+ {
+ return Cos(x - PITWO);
+ }
+
+ ///
+ /// Returns the approximated cosine of a specified number.
+ ///
+ /// The value.
+ ///
+ /// A float.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float Cos(float x)
+ {
+ x *= ITWOPI;
+ x -= 0.25f + Floor(x + 0.25f);
+ x *= 16.0f * (Math.Abs(x) - 0.5f);
+ x += 0.225f * x * (Math.Abs(x) - 1.0f);
+ return x;
+ }
+
+ ///
+ /// Sine cosine.
+ ///
+ /// The value in radians.
+ /// [out] The sine.
+ /// [out] The cosine.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void SinCos(float x, out float sin, out float cos)
+ {
+ const float A = 1.27323954f, B = 0.405284735f;
+ x -= (TWOPI * Floor((x / TWOPI) + 0.5f));
+ sin = x < 0 ? (A + (B * x)) * x : (A - (B * x)) * x;
+ x += PITWO;
+ if (x > PI) x -= TWOPI;
+ cos = x < 0 ? (A + (B * x)) * x : (A - (B * x)) * x;
+ }
+
+ ///
+ /// Atan 2.
+ ///
+ /// The y value.
+ /// The x value.
+ ///
+ /// A float.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float Atan2(float y, float x)
+ {
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
+ if (x == 0f)
+ {
+ if (y > 0f) return PITWO;
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
+ if (y == 0f) return 0f;
+ return -PITWO;
+ }
+ float atan, z = y / x;
+ if (Math.Abs(z) < 1f)
+ {
+ atan = z / (1f + (0.28f * z * z));
+ if (x < 0f) return atan + (y < 0f ? -PI : PI);
+ return atan;
+ }
+ atan = PITWO - (z / ((z * z) + 0.28f));
+ return y < 0f ? atan - PI : atan;
+ }
+
+ #region RoundUpToPowerOfTwo
///
/// Rounds the given value up to a power of two.
@@ -372,6 +250,10 @@ public static ulong RoundUpToPowerOfTwo(ulong value)
value |= value >> 32;
return value + 1;
}
+
+ #endregion
+
+ #region SQRT
///
/// Returns the square root of a specified number.
@@ -399,7 +281,7 @@ public static uint Sqrt(ulong value)
uint g = 0;
int bshft = Log2Floor(value) >> 1;
- uint b = 1u << bshft;
+ uint b = 1u << bshft;
do
{
ulong temp = (ulong)(g + g + b) << bshft;
@@ -441,7 +323,7 @@ public static uint Sqrt(uint value)
uint g = 0;
int bshft = Log2Floor(value) >> 1;
- uint b = 1u << bshft;
+ uint b = 1u << bshft;
do
{
uint temp = (g + g + b) << bshft;
@@ -455,5 +337,247 @@ public static uint Sqrt(uint value)
return g;
}
+
+
+ ///
+ /// Returns the approximated square root of a specified number.
+ ///
+ /// The number whose square root is to be found.
+ /// the approximation of the square root
+ public static unsafe float SqrtFast(float value)
+ {
+ uint i = *(uint*)&value;
+
+ // adjust bias
+ i += 127 << 23;
+ // approximation of square root
+ i >>= 1;
+
+ return *(float*)&i;
+ }
+
+ #endregion
+
+ #region Log2Floor
+
+ ///
+ /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
+ ///
+ ///
+ /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
+ ///
+ public static int Log2Floor(uint x)
+ {
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ return CountOnes(x | (x >> 16)) - 1;
+ }
+
+ ///
+ /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
+ ///
+ ///
+ /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int Log2Floor(int x)
+ {
+ if (x < 0) { throw new ArgumentOutOfRangeException(nameof(x), "Can't compute Log2Floor of a negative"); }
+ return Log2Floor((uint)x);
+ }
+
+ ///
+ /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
+ ///
+ ///
+ /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int Log2Floor(ulong x)
+ {
+ uint xHi = (uint)(x >> 32);
+ if (xHi != 0)
+ {
+ return 32 + Log2Floor(xHi);
+ }
+ return Log2Floor((uint)x);
+ }
+
+ ///
+ /// Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
+ ///
+ ///
+ /// The return value is -1 for an input of zero (for which the logarithm is technically undefined.)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int Log2Floor(long x)
+ {
+ if (x < 0) { throw new ArgumentOutOfRangeException(nameof(x), "Can't compute Log2Floor of a negative"); }
+ return Log2Floor((ulong)x);
+ }
+
+ #endregion
+
+ #region Lerp
+
+ ///
+ /// Interpolates between two values using a linear function by a given amount.
+ ///
+ /// Value to interpolate from.
+ /// Value to interpolate to.
+ /// Interpolation amount.
+ /// The result of linear interpolation of values based on the amount.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static byte Lerp(byte a, byte b, double t)
+ {
+ return (byte)(a + (t * (b - a)));
+ }
+
+ ///
+ /// Interpolates between two values using a linear function by a given amount.
+ ///
+ /// Value to interpolate from.
+ /// Value to interpolate to.
+ /// Interpolation amount.
+ /// The result of linear interpolation of values based on the amount.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float Lerp(float a, float b, double t)
+ {
+ return (float)(a + (t * (b - a)));
+ }
+
+ ///
+ /// Interpolates between two values using a linear function by a given amount.
+ ///
+ /// Value to interpolate from.
+ /// Value to interpolate to.
+ /// Interpolation amount.
+ /// The result of linear interpolation of values based on the amount.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static double Lerp(double a, double b, double t)
+ {
+ return a + (t * (b - a));
+ }
+
+ ///
+ /// LinearInterpolate
+ ///
+ /// a
+ /// b
+ /// t
+ /// new Vector2
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Vector2 Lerp(Vector2 a, Vector2 b, double t)
+ {
+ return new Vector2(Lerp(a.X, b.X, t), Lerp(a.Y, b.Y, t));
+ }
+
+ #endregion
+
+ #region Map
+
+ ///
+ /// Maps a value from l1 to u1 to l2 to u2
+ ///
+ /// Value
+ /// Lower 1
+ /// Upper 1
+ /// Lower 2
+ /// Upper 2
+ /// maped value
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float Map(float v, float l1, float u1, float l2, float u2)
+ {
+ return (((v - l1) / (u1 - l1)) * (u2 - l2)) + l2;
+ }
+
+ ///
+ /// Maps a value from l1 to u1 to l2 to u2
+ ///
+ /// Value
+ /// Lower 1
+ /// Upper 1
+ /// Lower 2
+ /// Upper 2
+ /// maped value
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static double Map(double v, double l1, double u1, double l2, double u2)
+ {
+ return (((v - l1) / (u1 - l1)) * (u2 - l2)) + l2;
+ }
+
+ #endregion
+
+ #region CountOnes
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ public static int CountOnes(byte x)
+ {
+ int y = x;
+ y -= (y >> 1) & 0x55;
+ y = ((y >> 2) & 0x33) + (y & 0x33);
+ return (y & 0x0F) + (y >> 4);
+ }
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ public static int CountOnes(ushort x)
+ {
+ int y = x;
+ y -= (y >> 1) & 0x5555;
+ y = ((y >> 2) & 0x3333) + (y & 0x3333);
+ y = ((y >> 4) + y) & 0x0F0F;
+ return (y + (y >> 8)) & 0x001F;
+ }
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int CountOnes(int x)
+ {
+ return CountOnes((uint)x);
+ }
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ public static int CountOnes(uint x)
+ {
+ x -= (x >> 1) & 0x55555555;
+ x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
+ x = ((x >> 4) + x) & 0x0F0F0F0F;
+ x += x >> 8;
+ return (int)((x + (x >> 16)) & 0x0000003F);
+ }
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int CountOnes(long x)
+ {
+ return CountOnes((ulong)x);
+ }
+
+ ///
+ /// Returns the number of 'on' bits in x
+ ///
+ public static int CountOnes(ulong x)
+ {
+ x -= (x >> 1) & 0x5555555555555555u;
+ x = ((x >> 2) & 0x3333333333333333u) + (x & 0x3333333333333333u);
+ x = ((x >> 4) + x) & 0x0F0F0F0F0F0F0F0Fu;
+ x += x >> 8;
+ x += x >> 16;
+ return ((int)x + (int)(x >> 32)) & 0x0000007F;
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Mathematics/Random2.cs b/src/Exomia.Framework/Mathematics/Random2.cs
similarity index 99%
rename from Exomia.Framework/Mathematics/Random2.cs
rename to src/Exomia.Framework/Mathematics/Random2.cs
index ec9e59f6..ab68a471 100644
--- a/Exomia.Framework/Mathematics/Random2.cs
+++ b/src/Exomia.Framework/Mathematics/Random2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -55,15 +55,15 @@ public sealed class Random2
/// The w.
///
private uint _x, _y, _z, _w;
-
+
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
public Random2()
: this(DateTime.Now.Ticks ^ Environment.TickCount) { }
-
+
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The seed.
public Random2(long seed)
diff --git a/Exomia.Framework/Native/Kernel32.cs b/src/Exomia.Framework/Native/Kernel32.cs
similarity index 95%
rename from Exomia.Framework/Native/Kernel32.cs
rename to src/Exomia.Framework/Native/Kernel32.cs
index 997f679e..da7039f1 100644
--- a/Exomia.Framework/Native/Kernel32.cs
+++ b/src/Exomia.Framework/Native/Kernel32.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Native/Mem.cs b/src/Exomia.Framework/Native/Mem.cs
similarity index 51%
rename from Exomia.Framework/Native/Mem.cs
rename to src/Exomia.Framework/Native/Mem.cs
index 0f1f6fbf..1ea5c1b5 100644
--- a/Exomia.Framework/Native/Mem.cs
+++ b/src/Exomia.Framework/Native/Mem.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -29,9 +29,23 @@ static unsafe class Mem
[SuppressUnmanagedCodeSecurity]
[DllImport(
"msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
- public static extern void Cpy(
- void* dest,
- void* src,
- int count);
+ public static extern void Cpy(void* dest,
+ void* src,
+ int count);
+
+ ///
+ /// memcpy call
+ /// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by
+ /// destination.
+ ///
+ /// destination ptr
+ /// source ptr
+ /// count of bytes to copy
+ [SuppressUnmanagedCodeSecurity]
+ [DllImport(
+ "msvcrt.dll", EntryPoint = "memmove", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
+ public static extern void Move(void* dest,
+ void* src,
+ int count);
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Native/User32.cs b/src/Exomia.Framework/Native/User32.cs
similarity index 88%
rename from Exomia.Framework/Native/User32.cs
rename to src/Exomia.Framework/Native/User32.cs
index b44855d9..b6ad7137 100644
--- a/Exomia.Framework/Native/User32.cs
+++ b/src/Exomia.Framework/Native/User32.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -45,12 +45,11 @@ static class User32
[SuppressUnmanagedCodeSecurity]
[DllImport("User32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool PeekMessage(
- out MSG lpMsg,
- IntPtr hWnd,
- uint wMsgFilterMin,
- uint wMsgFilterMax,
- uint wRemoveMsg);
+ internal static extern bool PeekMessage(out MSG lpMsg,
+ IntPtr hWnd,
+ uint wMsgFilterMin,
+ uint wMsgFilterMax,
+ uint wRemoveMsg);
///
/// Translate message.
diff --git a/Exomia.Framework/Noise/INoise.cs b/src/Exomia.Framework/Noise/INoise.cs
similarity index 98%
rename from Exomia.Framework/Noise/INoise.cs
rename to src/Exomia.Framework/Noise/INoise.cs
index 37269e84..4f8d4c14 100644
--- a/Exomia.Framework/Noise/INoise.cs
+++ b/src/Exomia.Framework/Noise/INoise.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Noise/NoiseBase.cs b/src/Exomia.Framework/Noise/NoiseBase.cs
similarity index 96%
rename from Exomia.Framework/Noise/NoiseBase.cs
rename to src/Exomia.Framework/Noise/NoiseBase.cs
index cf85cdaf..e1b405c0 100644
--- a/Exomia.Framework/Noise/NoiseBase.cs
+++ b/src/Exomia.Framework/Noise/NoiseBase.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -115,7 +115,9 @@ public abstract class NoiseBase : INoise
///
/// Initializes a new instance of the class.
///
- protected NoiseBase(int seed, float frequency, int octaves,
+ protected NoiseBase(int seed,
+ float frequency,
+ int octaves,
NoiseInterpolationType noiseInterpolationType,
NoiseFractalType noiseFractalType)
: this(seed, frequency, octaves, 2.0f, 0.5f, noiseInterpolationType, noiseFractalType) { }
@@ -124,9 +126,13 @@ protected NoiseBase(int seed, float frequency, int octaves,
///
/// Initializes a new instance of the class.
///
- protected NoiseBase(int seed, float frequency, int octaves,
- float lacunarity, float gain,
- NoiseInterpolationType noiseInterpolationType, NoiseFractalType noiseFractalType)
+ protected NoiseBase(int seed,
+ float frequency,
+ int octaves,
+ float lacunarity,
+ float gain,
+ NoiseInterpolationType noiseInterpolationType,
+ NoiseFractalType noiseFractalType)
{
_seed = seed;
_frequency = frequency;
@@ -463,7 +469,14 @@ protected static float GradCoord3D(int seed, int x, int y, int z, double xd, dou
/// A float.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected static float GradCoord4D(int seed, int x, int y, int z, int w, double xd, double yd, double zd,
+ protected static float GradCoord4D(int seed,
+ int x,
+ int y,
+ int z,
+ int w,
+ double xd,
+ double yd,
+ double zd,
double wd)
{
int hash = seed;
diff --git a/Exomia.Framework/Noise/NoiseFractalType.cs b/src/Exomia.Framework/Noise/NoiseFractalType.cs
similarity index 96%
rename from Exomia.Framework/Noise/NoiseFractalType.cs
rename to src/Exomia.Framework/Noise/NoiseFractalType.cs
index 86fc5297..d54fa048 100644
--- a/Exomia.Framework/Noise/NoiseFractalType.cs
+++ b/src/Exomia.Framework/Noise/NoiseFractalType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Noise/NoiseInterpolationType.cs b/src/Exomia.Framework/Noise/NoiseInterpolationType.cs
similarity index 95%
rename from Exomia.Framework/Noise/NoiseInterpolationType.cs
rename to src/Exomia.Framework/Noise/NoiseInterpolationType.cs
index aa7a013d..44536c3d 100644
--- a/Exomia.Framework/Noise/NoiseInterpolationType.cs
+++ b/src/Exomia.Framework/Noise/NoiseInterpolationType.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Noise/PerlinNoise.cs b/src/Exomia.Framework/Noise/PerlinNoise.cs
similarity index 91%
rename from Exomia.Framework/Noise/PerlinNoise.cs
rename to src/Exomia.Framework/Noise/PerlinNoise.cs
index 6b9692e6..f36ce912 100644
--- a/Exomia.Framework/Noise/PerlinNoise.cs
+++ b/src/Exomia.Framework/Noise/PerlinNoise.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -18,7 +18,9 @@ namespace Exomia.Framework.Noise
public sealed class PerlinNoise : NoiseBase
{
///
- public PerlinNoise(int seed, float frequency, int octaves,
+ public PerlinNoise(int seed,
+ float frequency,
+ int octaves,
NoiseInterpolationType noiseInterpolationType = NoiseInterpolationType.Linear,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
@@ -26,7 +28,11 @@ public PerlinNoise(int seed, float frequency, int octaves,
noiseInterpolationType, noiseFractalType) { }
///
- public PerlinNoise(int seed, float frequency, int octaves, float lacunarity, float gain,
+ public PerlinNoise(int seed,
+ float frequency,
+ int octaves,
+ float lacunarity,
+ float gain,
NoiseInterpolationType noiseInterpolationType = NoiseInterpolationType.Linear,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
diff --git a/Exomia.Framework/Noise/SimplexNoise.cs b/src/Exomia.Framework/Noise/SimplexNoise.cs
similarity index 90%
rename from Exomia.Framework/Noise/SimplexNoise.cs
rename to src/Exomia.Framework/Noise/SimplexNoise.cs
index 77b306c0..c231124d 100644
--- a/Exomia.Framework/Noise/SimplexNoise.cs
+++ b/src/Exomia.Framework/Noise/SimplexNoise.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -43,14 +43,20 @@ public sealed class SimplexNoise : NoiseBase
private const float G33 = (G3 * 3f) - 1f;
///
- public SimplexNoise(int seed, float frequency, int octaves,
+ public SimplexNoise(int seed,
+ float frequency,
+ int octaves,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
seed, frequency, octaves,
NoiseInterpolationType.Linear, noiseFractalType) { }
///
- public SimplexNoise(int seed, float frequency, int octaves, float lacunarity, float gain,
+ public SimplexNoise(int seed,
+ float frequency,
+ int octaves,
+ float lacunarity,
+ float gain,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
seed, frequency, octaves, lacunarity, gain,
@@ -60,7 +66,7 @@ public SimplexNoise(int seed, float frequency, int octaves, float l
protected override float Single(int seed, double x)
{
int x0 = Math2.Floor(x);
- double xd0 = x - x0;
+ double xd0 = x - x0;
double xd1 = x0 - 1.0f;
double t0 = 1.0f - (xd0 * xd0);
@@ -91,8 +97,8 @@ protected override float Single(int seed, double x, double y)
double x1 = (x0 - i1) + G2;
double y1 = (y0 - j1) + G2;
- double x2 = (x0 - 1) + F2;
- double y2 = (y0 - 1) + F2;
+ double x2 = (x0 - 1) + F2;
+ double y2 = (y0 - 1) + F2;
double n0, n1, n2;
@@ -131,7 +137,7 @@ protected override float Single(int seed, double x, double y, double z)
int j = Math2.Floor(y + t);
int k = Math2.Floor(z + t);
- t = (i + j + k) * G3;
+ t = (i + j + k) * G3;
double x0 = x - (i - t);
double y0 = y - (j - t);
double z0 = z - (k - t);
@@ -206,9 +212,9 @@ protected override float Single(int seed, double x, double y, double z)
double x2 = (x0 - i2) + F3;
double y2 = (y0 - j2) + F3;
double z2 = (z0 - k2) + F3;
- double x3 = x0 + G33;
- double y3 = y0 + G33;
- double z3 = z0 + G33;
+ double x3 = x0 + G33;
+ double y3 = y0 + G33;
+ double z3 = z0 + G33;
double n0, n1, n2, n3;
diff --git a/Exomia.Framework/Noise/ValueNoise.cs b/src/Exomia.Framework/Noise/ValueNoise.cs
similarity index 91%
rename from Exomia.Framework/Noise/ValueNoise.cs
rename to src/Exomia.Framework/Noise/ValueNoise.cs
index 8dc9d3c4..f269ce47 100644
--- a/Exomia.Framework/Noise/ValueNoise.cs
+++ b/src/Exomia.Framework/Noise/ValueNoise.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -18,7 +18,9 @@ namespace Exomia.Framework.Noise
public class ValueNoise : NoiseBase
{
///
- public ValueNoise(int seed, float frequency, int octaves,
+ public ValueNoise(int seed,
+ float frequency,
+ int octaves,
NoiseInterpolationType noiseInterpolationType = NoiseInterpolationType.Linear,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
@@ -26,7 +28,11 @@ public ValueNoise(int seed, float frequency, int octaves,
noiseInterpolationType, noiseFractalType) { }
///
- public ValueNoise(int seed, float frequency, int octaves, float lacunarity, float gain,
+ public ValueNoise(int seed,
+ float frequency,
+ int octaves,
+ float lacunarity,
+ float gain,
NoiseInterpolationType noiseInterpolationType = NoiseInterpolationType.Linear,
NoiseFractalType noiseFractalType = NoiseFractalType.BrownianMotion)
: base(
diff --git a/Exomia.Framework/Renderer.cs b/src/Exomia.Framework/Renderer.cs
similarity index 94%
rename from Exomia.Framework/Renderer.cs
rename to src/Exomia.Framework/Renderer.cs
index 2e821583..cc270876 100644
--- a/Exomia.Framework/Renderer.cs
+++ b/src/Exomia.Framework/Renderer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -21,12 +21,12 @@ public abstract class Renderer : IComponent, IInitializable, IDrawable, IDisposa
///
/// Occurs when the property changes.
///
- public event EventHandler DrawOrderChanged;
+ public event EventHandler? DrawOrderChanged;
///
/// Occurs when the property changes.
///
- public event EventHandler VisibleChanged;
+ public event EventHandler? VisibleChanged;
///
/// The draw order.
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_12px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_12px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_12px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_12px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_14px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_14px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_14px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_14px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_16px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_16px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_16px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_16px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_18px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_18px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_18px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_18px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_20px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_20px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_20px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_20px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_22px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_22px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_22px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_22px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_24px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_24px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_24px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_24px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_26px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_26px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_26px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_26px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_28px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_28px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_28px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_28px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_30px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_30px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_30px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_30px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_32px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_32px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_32px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_32px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_34px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_34px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_34px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_34px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_36px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_36px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_36px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_36px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_38px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_38px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_38px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_38px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_40px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_40px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_40px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_40px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_42px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_42px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_42px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_42px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_44px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_44px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_44px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_44px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_46px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_46px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_46px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_46px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_48px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_48px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_48px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_48px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_50px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_50px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_50px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_50px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_52px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_52px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_52px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_52px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_54px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_54px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_54px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_54px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_56px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_56px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_56px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_56px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_58px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_58px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_58px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_58px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_60px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_60px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_60px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_60px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_62px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_62px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_62px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_62px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_64px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_64px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_64px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_64px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_66px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_66px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_66px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_66px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_68px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_68px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_68px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_68px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_70px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_70px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_70px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_70px.e1
diff --git a/Exomia.Framework/Resources/fonts/arial/arial_72px.e1 b/src/Exomia.Framework/Resources/fonts/arial/arial_72px.e1
similarity index 100%
rename from Exomia.Framework/Resources/fonts/arial/arial_72px.e1
rename to src/Exomia.Framework/Resources/fonts/arial/arial_72px.e1
diff --git a/Exomia.Framework/Scene/Default/LoadingScene.cs b/src/Exomia.Framework/Scene/Default/LoadingScene.cs
similarity index 79%
rename from Exomia.Framework/Scene/Default/LoadingScene.cs
rename to src/Exomia.Framework/Scene/Default/LoadingScene.cs
index 6e6d8721..9c145e67 100644
--- a/Exomia.Framework/Scene/Default/LoadingScene.cs
+++ b/src/Exomia.Framework/Scene/Default/LoadingScene.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -26,7 +26,7 @@ public class LoadingScene : SceneBase
///
/// The registry.
///
- private IServiceRegistry _registry;
+ private IServiceRegistry? _registry;
///
/// Initializes a new instance of the class.
@@ -47,24 +47,24 @@ protected override void OnInitialize(IServiceRegistry registry)
}
///
- protected override void OnShow(SceneBase comingFrom, object[] payload)
+ protected override void OnShow(SceneBase? comingFrom, object[] payload)
{
if (_sceneToLoad.State == SceneState.None)
{
- _sceneToLoad.SceneStateChanged += _sceneToLoad_SceneStateChanged;
+ _sceneToLoad.SceneStateChanged += SceneToLoad_SceneStateChanged;
Task.Factory.StartNew(
() =>
{
- _sceneToLoad.Initialize(_registry);
+ _sceneToLoad.Initialize(_registry!);
});
}
else if (_sceneToLoad.State == SceneState.StandBy)
{
- _sceneToLoad.SceneStateChanged += _sceneToLoad_SceneStateChanged;
+ _sceneToLoad.SceneStateChanged += SceneToLoad_SceneStateChanged;
Task.Factory.StartNew(
() =>
{
- _sceneToLoad.LoadContent(_registry);
+ _sceneToLoad.LoadContent(_registry!);
});
}
}
@@ -75,19 +75,19 @@ protected override void OnShow(SceneBase comingFrom, object[] payload)
/// The scene.
/// The current.
/// Thrown when an exception error condition occurs.
- private void _sceneToLoad_SceneStateChanged(IScene scene, SceneState current)
+ private void SceneToLoad_SceneStateChanged(IScene scene, SceneState current)
{
if (current == SceneState.StandBy)
{
Task.Factory.StartNew(
() =>
{
- _sceneToLoad.LoadContent(_registry);
+ _sceneToLoad.LoadContent(_registry!);
});
}
else if (current == SceneState.Ready)
{
- _sceneToLoad.SceneStateChanged -= _sceneToLoad_SceneStateChanged;
+ _sceneToLoad.SceneStateChanged -= SceneToLoad_SceneStateChanged;
if (SceneManager.ShowScene(_sceneToLoad) != ShowSceneResult.Success)
{
diff --git a/Exomia.Framework/Scene/IScene.cs b/src/Exomia.Framework/Scene/IScene.cs
similarity index 96%
rename from Exomia.Framework/Scene/IScene.cs
rename to src/Exomia.Framework/Scene/IScene.cs
index 8dcaf348..7043af1f 100644
--- a/Exomia.Framework/Scene/IScene.cs
+++ b/src/Exomia.Framework/Scene/IScene.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -39,7 +39,7 @@ interface IScene : IInitializable, IContentable, IInputHandler, IDisposable
///
/// The input handler.
///
- IInputHandler InputHandler { get; }
+ IRawInputHandler RawInputHandler { get; }
///
/// Gets or sets a value indicating whether this object is overlay scene.
@@ -119,7 +119,7 @@ interface IScene : IInitializable, IContentable, IInputHandler, IDisposable
///
/// coming from.
/// payload.
- void Show(SceneBase comingFrom, object[] payload);
+ void Show(SceneBase? comingFrom, object[] payload);
///
/// This method is called when this game component is updated.
diff --git a/Exomia.Framework/Scene/ISceneManager.cs b/src/Exomia.Framework/Scene/ISceneManager.cs
similarity index 98%
rename from Exomia.Framework/Scene/ISceneManager.cs
rename to src/Exomia.Framework/Scene/ISceneManager.cs
index 5efb67ef..30a722c6 100644
--- a/Exomia.Framework/Scene/ISceneManager.cs
+++ b/src/Exomia.Framework/Scene/ISceneManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Scene/SceneBase.cs b/src/Exomia.Framework/Scene/SceneBase.cs
similarity index 71%
rename from Exomia.Framework/Scene/SceneBase.cs
rename to src/Exomia.Framework/Scene/SceneBase.cs
index aa8c0262..701252ad 100644
--- a/Exomia.Framework/Scene/SceneBase.cs
+++ b/src/Exomia.Framework/Scene/SceneBase.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -8,11 +8,15 @@
#endregion
+#pragma warning disable IDE0069
+
using System;
using System.Collections.Generic;
+using System.Windows.Forms;
using Exomia.Framework.Game;
using Exomia.Framework.Input;
using SharpDX;
+using MouseButtons = Exomia.Framework.Input.MouseButtons;
namespace Exomia.Framework.Scene
{
@@ -29,7 +33,7 @@ public abstract class SceneBase : IScene
///
/// Occurs when Scene State Changed.
///
- public event EventHandler SceneStateChanged;
+ public event EventHandler? SceneStateChanged;
///
/// The contentable component.
@@ -72,24 +76,24 @@ public abstract class SceneBase : IScene
private readonly List _updateableComponent;
///
- /// The input handler.
+ /// The collector.
///
- private IInputHandler _inputHandler;
-
+ private readonly DisposeCollector _collector;
+
///
- /// Manager for scene.
+ /// The raw input handler.
///
- private ISceneManager _sceneManager;
+ private IRawInputHandler? _rawInputHandler;
///
- /// The registry.
+ /// Manager for scene.
///
- private IServiceRegistry _registry;
+ private ISceneManager? _sceneManager;
///
- /// The collector.
+ /// The registry.
///
- private DisposeCollector _collector;
+ private IServiceRegistry? _registry;
///
/// True if this object is initialized.
@@ -134,23 +138,31 @@ protected set
///
public bool Visible { get; set; } = false;
-
- ///
- protected IInputHandler InputHandler
+
+ ///
+ /// Sets the raw input handler.
+ ///
+ ///
+ /// The raw input handler.
+ ///
+ protected IRawInputHandler RawInputHandler
{
- set { _inputHandler = value; }
+ set
+ {
+ _rawInputHandler = value;
+ }
}
///
protected ISceneManager SceneManager
{
- get { return _sceneManager; }
+ get { return _sceneManager!; }
}
///
- IInputHandler IScene.InputHandler
+ IRawInputHandler IScene.RawInputHandler
{
- get { return _inputHandler; }
+ get { return _rawInputHandler!; }
}
///
@@ -159,7 +171,10 @@ ISceneManager IScene.SceneManager
set { _sceneManager = value; }
}
- ///
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The key.
protected SceneBase(string key)
{
Key = key;
@@ -303,7 +318,7 @@ void IScene.ReferenceScenesLoaded()
}
///
- void IScene.Show(SceneBase comingFrom, object[] payload)
+ void IScene.Show(SceneBase? comingFrom, object[] payload)
{
OnShow(comingFrom, payload);
}
@@ -311,7 +326,7 @@ void IScene.Show(SceneBase comingFrom, object[] payload)
///
/// Adds item.
///
- /// any.
+ /// Generic type parameter.
/// any.
///
/// the passed item.
@@ -331,7 +346,7 @@ public T Add(T item)
{
if (_isInitialized)
{
- initializable.Initialize(_registry);
+ initializable.Initialize(_registry!);
}
else
{
@@ -342,21 +357,20 @@ public T Add(T item)
}
}
- lock (_contentableComponent)
+ // ReSharper disable InconsistentlySynchronizedField
+ if (item is IContentable contentable && !_contentableComponent.Contains(contentable))
{
- if (item is IContentable contentable && !_contentableComponent.Contains(contentable))
+ lock (_contentableComponent)
{
- lock (_contentableComponent)
- {
- _contentableComponent.Add(contentable);
- }
- if (_isContentLoaded)
- {
- contentable.LoadContent(_registry);
- }
+ _contentableComponent.Add(contentable);
+ }
+ if (_isContentLoaded)
+ {
+ contentable.LoadContent(_registry!);
}
}
+ // ReSharper disable InconsistentlySynchronizedField
if (item is IUpdateable updateable && !_updateableComponent.Contains(updateable))
{
lock (_updateableComponent)
@@ -377,6 +391,7 @@ public T Add(T item)
updateable.UpdateOrderChanged += UpdateableComponent_UpdateOrderChanged;
}
+ // ReSharper disable InconsistentlySynchronizedField
if (item is IDrawable drawable && !_drawableComponent.Contains(drawable))
{
lock (_drawableComponent)
@@ -408,23 +423,20 @@ public T Add(T item)
///
/// Removes the given item.
///
- /// any.
+ /// Generic type parameter.
/// any.
///
/// the passed item.
///
public T Remove(T item)
{
- lock (_contentableComponent)
+ if (item is IContentable contentable && _contentableComponent.Contains(contentable))
{
- if (item is IContentable contentable && _contentableComponent.Contains(contentable))
+ lock (_contentableComponent)
{
- lock (_contentableComponent)
- {
- _contentableComponent.Remove(contentable);
- }
- contentable.UnloadContent(_registry);
+ _contentableComponent.Remove(contentable);
}
+ contentable.UnloadContent(_registry!);
}
if (item is IUpdateable updateable && _updateableComponent.Contains(updateable))
@@ -436,6 +448,7 @@ public T Remove(T item)
updateable.UpdateOrderChanged -= UpdateableComponent_UpdateOrderChanged;
}
+ // ReSharper disable once InconsistentlySynchronizedField
if (item is IDrawable drawable && _drawableComponent.Contains(drawable))
{
lock (_drawableComponent)
@@ -497,13 +510,13 @@ protected virtual void OnReferenceScenesLoaded() { }
///
/// coming from.
/// payload.
- protected virtual void OnShow(SceneBase comingFrom, object[] payload) { }
+ protected virtual void OnShow(SceneBase? comingFrom, object[] payload) { }
///
/// Converts an obj to a dispose.
///
- /// .
- /// .
+ /// Generic type parameter.
+ /// The object.
///
/// Obj as a T.
///
@@ -539,12 +552,12 @@ private void DrawableComponent_DrawOrderChanged()
///
/// Input mouse move.
///
- /// .
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_MouseMove(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ void IRawInputHandler.Input_MouseMove(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
OnMouseMove(x, y, buttons, clicks, wheelDelta);
}
@@ -552,22 +565,22 @@ void IInputHandler.Input_MouseMove(int x, int y, MouseButtons buttons, int click
///
/// Executes the mouse move action.
///
- /// .
- /// .
- /// .
- /// .
- /// .
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
protected virtual void OnMouseMove(int x, int y, MouseButtons buttons, int clicks, int wheelDelta) { }
///
/// Input mouse down.
///
- /// .
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_MouseDown(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ void IRawInputHandler.Input_MouseDown(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
OnMouseDown(x, y, buttons, clicks, wheelDelta);
}
@@ -575,22 +588,22 @@ void IInputHandler.Input_MouseDown(int x, int y, MouseButtons buttons, int click
///
/// Executes the mouse down action.
///
- /// .
- /// .
- /// .
- /// .
- /// .
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
protected virtual void OnMouseDown(int x, int y, MouseButtons buttons, int clicks, int wheelDelta) { }
///
/// Input mouse up.
///
- /// .
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_MouseUp(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ void IRawInputHandler.Input_MouseUp(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
OnMouseUp(x, y, buttons, clicks, wheelDelta);
}
@@ -598,22 +611,22 @@ void IInputHandler.Input_MouseUp(int x, int y, MouseButtons buttons, int clicks,
///
/// Executes the mouse up action.
///
- /// .
- /// .
- /// .
- /// .
- /// .
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
protected virtual void OnMouseUp(int x, int y, MouseButtons buttons, int clicks, int wheelDelta) { }
///
/// Input mouse click.
///
- /// .
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_MouseClick(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ void IRawInputHandler.Input_MouseClick(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
OnMouseClick(x, y, buttons, clicks, wheelDelta);
}
@@ -621,22 +634,22 @@ void IInputHandler.Input_MouseClick(int x, int y, MouseButtons buttons, int clic
///
/// Executes the mouse click action.
///
- /// .
- /// .
- /// .
- /// .
- /// .
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
protected virtual void OnMouseClick(int x, int y, MouseButtons buttons, int clicks, int wheelDelta) { }
///
/// Input mouse wheel.
///
- /// .
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_MouseWheel(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
+ void IRawInputHandler.Input_MouseWheel(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
OnMouseWheel(x, y, buttons, clicks, wheelDelta);
}
@@ -644,59 +657,66 @@ void IInputHandler.Input_MouseWheel(int x, int y, MouseButtons buttons, int clic
///
/// Executes the mouse wheel action.
///
- /// .
- /// .
- /// .
- /// .
- /// .
+ /// The x coordinate.
+ /// The y coordinate.
+ /// The buttons.
+ /// The clicks.
+ /// The wheel delta.
protected virtual void OnMouseWheel(int x, int y, MouseButtons buttons, int clicks, int wheelDelta) { }
///
/// Input key up.
///
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_KeyUp(int keyValue, bool shift, bool alt, bool ctrl)
+ /// The key value.
+ /// The key modifiers.
+ void IInputHandler.Input_KeyUp(int keyValue, KeyModifier modifiers)
{
- OnKeyUp(keyValue, shift, alt, ctrl);
+ OnKeyUp(keyValue, modifiers);
}
///
/// Executes the key up action.
///
- /// .
- /// .
- /// .
- /// .
- protected virtual void OnKeyUp(int keyValue, bool shift, bool alt, bool ctrl) { }
+ /// The key value.
+ /// The key modifiers.
+ protected virtual void OnKeyUp(int keyValue, KeyModifier modifiers) { }
///
/// Input key down.
///
- /// .
- /// .
- /// .
- /// .
- void IInputHandler.Input_KeyDown(int keyValue, bool shift, bool alt, bool ctrl)
+ /// The key value.
+ /// The key modifiers.
+ void IInputHandler.Input_KeyDown(int keyValue, KeyModifier modifiers)
{
- OnKeyDown(keyValue, shift, alt, ctrl);
+ OnKeyDown(keyValue, modifiers);
}
///
/// Executes the key down action.
///
- /// .
- /// .
- /// .
- /// .
- protected virtual void OnKeyDown(int keyValue, bool shift, bool alt, bool ctrl) { }
+ /// The key value.
+ /// The key modifiers.
+ protected virtual void OnKeyDown(int keyValue, KeyModifier modifiers) { }
+
+ ///
+ /// Input key event.
+ ///
+ /// [in,out] The message.
+ void IRawInputHandler.Input_KeyEvent(ref Message message)
+ {
+ OnKeyEvent(ref message);
+ }
+
+ ///
+ /// Executes the key event action.
+ ///
+ /// [in,out] The message.
+ protected virtual void OnKeyEvent(ref Message message) { }
///
/// Input key press.
///
- /// .
+ /// The key.
void IInputHandler.Input_KeyPress(char key)
{
OnKeyPress(key);
@@ -705,7 +725,7 @@ void IInputHandler.Input_KeyPress(char key)
///
/// Executes the key press action.
///
- /// .
+ /// The key.
protected virtual void OnKeyPress(char key) { }
#endregion
@@ -713,7 +733,7 @@ protected virtual void OnKeyPress(char key) { }
#region IDisposable Support
///
- /// true if the instance is allready disposed; false otherwise.
+ /// true if the instance is already disposed; false otherwise.
///
protected bool _disposed;
@@ -744,6 +764,7 @@ private void Dispose(bool disposing)
OnDispose(disposing);
if (disposing)
{
+ // ReSharper disable InconsistentlySynchronizedField
_drawableComponent.Clear();
_updateableComponent.Clear();
_contentableComponent.Clear();
@@ -755,10 +776,9 @@ private void Dispose(bool disposing)
_sceneComponents.Clear();
_pendingInitializables.Clear();
- /* USER CODE */
- _collector.DisposeAndClear();
- _collector = null;
+ // ReSharper enable InconsistentlySynchronizedField
}
+ _collector.DisposeAndClear(disposing);
State = SceneState.None;
_disposed = true;
}
diff --git a/Exomia.Framework/Scene/SceneManager.cs b/src/Exomia.Framework/Scene/SceneManager.cs
similarity index 68%
rename from Exomia.Framework/Scene/SceneManager.cs
rename to src/Exomia.Framework/Scene/SceneManager.cs
index 6d9a74cd..7efce82c 100644
--- a/Exomia.Framework/Scene/SceneManager.cs
+++ b/src/Exomia.Framework/Scene/SceneManager.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -11,8 +11,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using System.Windows.Forms;
using Exomia.Framework.Game;
using Exomia.Framework.Input;
+using MouseButtons = Exomia.Framework.Input.MouseButtons;
namespace Exomia.Framework.Scene
{
@@ -57,19 +59,24 @@ public sealed class SceneManager : DrawableComponent, ISceneManager
private readonly List _scenesToUnload;
///
- /// The input.
+ /// The raw input device.
///
- private IInputDevice _input;
+ private IRawInputDevice? _rawInputDevice;
///
/// The input handler.
///
- private IInputHandler _inputHandler;
+ private IRawInputHandler? _rawInputHandler;
///
/// The registry.
///
- private IServiceRegistry _registry;
+ private IServiceRegistry? _registry;
+
+ ///
+ /// The key modifier.
+ ///
+ private KeyModifier _keyModifier = 0;
///
///
@@ -111,7 +118,7 @@ public bool AddScene(SceneBase scene, bool initialize = true)
}
else
{
- scene.Initialize(_registry);
+ scene.Initialize(_registry!);
}
}
@@ -147,7 +154,7 @@ public bool RemoveScene(string key)
HideScene(scene);
_scenes.Remove(key);
- scene.UnloadContent(_registry);
+ scene.UnloadContent(_registry!);
scene.Dispose();
return true;
@@ -159,6 +166,7 @@ public ShowSceneResult ShowScene(SceneBase s, params object[] payload)
lock (this)
{
if (!(s is IScene scene)) { return ShowSceneResult.NoScene; }
+ // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (scene.State)
{
case SceneState.ContentLoading:
@@ -200,7 +208,7 @@ public ShowSceneResult ShowScene(SceneBase s, params object[] payload)
}
if (!isReferenced)
{
- uScene.UnloadContent(_registry);
+ uScene.UnloadContent(_registry!);
_scenesToUnload.RemoveAt(i);
}
}
@@ -219,13 +227,13 @@ public ShowSceneResult ShowScene(SceneBase s, params object[] payload)
}
if (rScene.State == SceneState.StandBy)
{
- rScene.LoadContent(_registry);
+ rScene.LoadContent(_registry!);
}
}
scene.ReferenceScenesLoaded();
});
- _inputHandler = scene?.InputHandler ?? scene;
+ _rawInputHandler = scene.RawInputHandler ?? scene;
lock (_currentScenes)
{
@@ -263,12 +271,12 @@ public bool HideScene(SceneBase scene)
if (_currentScenes.Count > 0)
{
- _inputHandler = (_currentScenes[_currentScenes.Count - 1] as IScene).InputHandler ??
- _currentScenes[_currentScenes.Count - 1];
+ _rawInputHandler = (_currentScenes[_currentScenes.Count - 1] as IScene).RawInputHandler ??
+ _currentScenes[_currentScenes.Count - 1];
}
else
{
- _inputHandler = null;
+ _rawInputHandler = null;
}
return true;
}
@@ -318,18 +326,15 @@ public override void Draw(GameTime gameTime)
protected override void OnInitialize(IServiceRegistry registry)
{
_registry = registry;
- _input = registry.GetService() ??
- throw new NullReferenceException("No IInputDevice found.");
+ _rawInputDevice = registry.GetService() ??
+ throw new NullReferenceException($"No {nameof(IRawInputDevice)} found.");
- _input.MouseMove += Input_MouseMove;
- _input.MouseDown += Input_MouseDown;
- _input.MouseUp += Input_MouseUp;
- _input.MouseClick += Input_MouseClick;
- _input.MouseWheel += Input_MouseWheel;
-
- _input.KeyDown += Input_KeyDown;
- _input.KeyUp += Input_KeyUp;
- _input.KeyPress += Input_KeyPress;
+ _rawInputDevice.RawKeyEvent += RawInputDeviceOnRawKeyEvent;
+ _rawInputDevice.RawMouseDown += RawInputDeviceOnRawMouseDown;
+ _rawInputDevice.RawMouseUp += RawInputDeviceOnRawMouseUp;
+ _rawInputDevice.RawMouseClick += RawInputDeviceOnRawMouseClick;
+ _rawInputDevice.RawMouseMove += RawInputDeviceOnRawMouseMove;
+ _rawInputDevice.RawMouseWheel += RawInputDeviceOnRawMouseWheel;
lock (_pendingInitializableScenes)
{
@@ -355,19 +360,15 @@ protected override void OnDispose(bool dispose)
_currentScenes.Clear();
}
- _input.MouseMove -= Input_MouseMove;
- _input.MouseDown -= Input_MouseDown;
- _input.MouseUp -= Input_MouseUp;
- _input.MouseClick -= Input_MouseClick;
- _input.MouseWheel -= Input_MouseWheel;
-
- _input.KeyDown -= Input_KeyDown;
- _input.KeyUp -= Input_KeyUp;
- _input.KeyPress -= Input_KeyPress;
+ _rawInputDevice!.RawKeyEvent -= RawInputDeviceOnRawKeyEvent;
+ _rawInputDevice.RawMouseDown -= RawInputDeviceOnRawMouseDown;
+ _rawInputDevice.RawMouseUp -= RawInputDeviceOnRawMouseUp;
+ _rawInputDevice.RawMouseMove -= RawInputDeviceOnRawMouseMove;
+ _rawInputDevice.RawMouseWheel -= RawInputDeviceOnRawMouseWheel;
foreach (IScene scene in _scenes.Values)
{
- scene.UnloadContent(_registry);
+ scene.UnloadContent(_registry!);
scene.Dispose();
}
@@ -375,106 +376,128 @@ protected override void OnDispose(bool dispose)
}
}
- #region Input Handler
-
///
- /// Input mouse move.
+ /// Raw input device on raw mouse wheel.
///
/// The x coordinate.
/// The y coordinate.
/// The buttons.
/// The clicks.
- /// The wheel delta.
- private void Input_MouseMove(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The wheelDelta.
+ private void RawInputDeviceOnRawMouseWheel(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
- _inputHandler?.Input_MouseMove(x, y, buttons, clicks, wheelDelta);
+ _rawInputHandler?.Input_MouseWheel(x, y, buttons, clicks, wheelDelta);
}
///
- /// Input mouse down.
+ /// Raw input device on raw mouse move.
///
/// The x coordinate.
/// The y coordinate.
/// The buttons.
/// The clicks.
- /// The wheel delta.
- private void Input_MouseDown(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The wheelDelta.
+ private void RawInputDeviceOnRawMouseMove(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
- _inputHandler?.Input_MouseDown(x, y, buttons, clicks, wheelDelta);
+ _rawInputHandler?.Input_MouseMove(x, y, buttons, clicks, wheelDelta);
}
///
- /// Input mouse up.
+ /// Raw input device on raw mouse up.
///
/// The x coordinate.
/// The y coordinate.
/// The buttons.
/// The clicks.
- /// The wheel delta.
- private void Input_MouseUp(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The wheelDelta.
+ private void RawInputDeviceOnRawMouseUp(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
- _inputHandler?.Input_MouseUp(x, y, buttons, clicks, wheelDelta);
+ _rawInputHandler?.Input_MouseUp(x, y, buttons, clicks, wheelDelta);
}
///
- /// Input mouse click.
+ /// Raw input device on raw mouse down.
///
/// The x coordinate.
/// The y coordinate.
/// The buttons.
/// The clicks.
- /// The wheel delta.
- private void Input_MouseClick(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The wheelDelta.
+ private void RawInputDeviceOnRawMouseDown(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
- _inputHandler?.Input_MouseClick(x, y, buttons, clicks, wheelDelta);
+ _rawInputHandler?.Input_MouseDown(x, y, buttons, clicks, wheelDelta);
}
///
- /// Input mouse wheel.
+ /// Raw input device on raw mouse click.
///
/// The x coordinate.
/// The y coordinate.
/// The buttons.
/// The clicks.
- /// The wheel delta.
- private void Input_MouseWheel(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
+ /// The wheelDelta.
+ private void RawInputDeviceOnRawMouseClick(int x, int y, MouseButtons buttons, int clicks, int wheelDelta)
{
- _inputHandler?.Input_MouseWheel(x, y, buttons, clicks, wheelDelta);
+ _rawInputHandler?.Input_MouseClick(x, y, buttons, clicks, wheelDelta);
}
///
- /// Input key press.
+ /// Raw input device on raw key event.
///
- /// The key.
- private void Input_KeyPress(char key)
+ /// [in,out] The ref Message to process.
+ private void RawInputDeviceOnRawKeyEvent(ref Message e)
{
- _inputHandler?.Input_KeyPress(key);
- }
-
- ///
- /// Input key up.
- ///
- /// The key value.
- /// True to shift.
- /// True to alternate.
- /// True to control.
- private void Input_KeyUp(int keyValue, bool shift, bool alt, bool ctrl)
- {
- _inputHandler?.Input_KeyUp(keyValue, shift, alt, ctrl);
- }
+ _rawInputHandler?.Input_KeyEvent(ref e);
+ if (_rawInputHandler is IInputHandler inputHandler)
+ {
+ int vKey = (int)e.WParam.ToInt64();
- ///
- /// Input key down.
- ///
- /// The key value.
- /// True to shift.
- /// True to alternate.
- /// True to control.
- private void Input_KeyDown(int keyValue, bool shift, bool alt, bool ctrl)
- {
- _inputHandler?.Input_KeyDown(keyValue, shift, alt, ctrl);
+ switch (e.Msg)
+ {
+ case Win32Message.WM_KEYDOWN:
+ switch (vKey)
+ {
+ case Key.ShiftKey:
+ _keyModifier |= KeyModifier.Shift;
+ break;
+ case Key.ControlKey:
+ _keyModifier |= KeyModifier.Control;
+ break;
+ }
+ inputHandler.Input_KeyDown(vKey, _keyModifier);
+ break;
+ case Win32Message.WM_KEYUP:
+ switch (vKey)
+ {
+ case Key.ShiftKey:
+ _keyModifier &= ~KeyModifier.Shift;
+ break;
+ case Key.ControlKey:
+ _keyModifier &= ~KeyModifier.Control;
+ break;
+ }
+ inputHandler.Input_KeyUp(vKey, _keyModifier);
+ break;
+ case Win32Message.WM_SYSKEYDOWN:
+ if (vKey == Key.Menu)
+ {
+ _keyModifier |= KeyModifier.Alt;
+ }
+ inputHandler.Input_KeyDown(vKey, _keyModifier);
+ break;
+ case Win32Message.WM_SYSKEYUP:
+ if (vKey == Key.Menu)
+ {
+ _keyModifier &= ~KeyModifier.Alt;
+ }
+ inputHandler.Input_KeyUp(vKey, _keyModifier);
+ break;
+ case Win32Message.WM_UNICHAR:
+ case Win32Message.WM_CHAR:
+ inputHandler.Input_KeyPress((char)vKey);
+ break;
+ }
+ }
}
-
- #endregion
}
}
\ No newline at end of file
diff --git a/Exomia.Framework/Scene/SceneState.cs b/src/Exomia.Framework/Scene/SceneState.cs
similarity index 98%
rename from Exomia.Framework/Scene/SceneState.cs
rename to src/Exomia.Framework/Scene/SceneState.cs
index 97f5a6ad..58341655 100644
--- a/Exomia.Framework/Scene/SceneState.cs
+++ b/src/Exomia.Framework/Scene/SceneState.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Scene/ShowSceneResult.cs b/src/Exomia.Framework/Scene/ShowSceneResult.cs
similarity index 98%
rename from Exomia.Framework/Scene/ShowSceneResult.cs
rename to src/Exomia.Framework/Scene/ShowSceneResult.cs
index 1adab984..4c269fe1 100644
--- a/Exomia.Framework/Scene/ShowSceneResult.cs
+++ b/src/Exomia.Framework/Scene/ShowSceneResult.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/ServiceRegistry.cs b/src/Exomia.Framework/ServiceRegistry.cs
similarity index 94%
rename from Exomia.Framework/ServiceRegistry.cs
rename to src/Exomia.Framework/ServiceRegistry.cs
index 3421422c..6db9c9f2 100644
--- a/Exomia.Framework/ServiceRegistry.cs
+++ b/src/Exomia.Framework/ServiceRegistry.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -34,7 +34,7 @@ public ServiceRegistry()
///
public void AddService(Type type, object provider)
{
- if (type == null) { throw new ArgumentNullException(nameof(type)); }
+ if (type == null) { throw new ArgumentNullException(nameof(type)); }
if (provider == null) { throw new ArgumentNullException(nameof(provider)); }
if (!type.IsInstanceOfType(provider))
@@ -56,7 +56,7 @@ public void AddService(Type type, object provider)
///
public void AddService(T provider)
{
- AddService(typeof(T), provider);
+ AddService(typeof(T), provider!);
}
///
diff --git a/Exomia.Framework/Tools/Easings.cs b/src/Exomia.Framework/Tools/Easings.cs
similarity index 95%
rename from Exomia.Framework/Tools/Easings.cs
rename to src/Exomia.Framework/Tools/Easings.cs
index 9e4eeb7a..3d8a977b 100644
--- a/Exomia.Framework/Tools/Easings.cs
+++ b/src/Exomia.Framework/Tools/Easings.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -156,7 +156,7 @@ public static float EaseIn(float t, float b, float c, float d)
public static float EaseInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1) { return ((-c / 2) * ((float)Math.Sqrt(1 - (t * t)) - 1)) + b; }
- return ((c / 2) * ((float)Math.Sqrt(1 - ((t -= 2) * t)) + 1)) + b;
+ return ((c / 2) * ((float)Math.Sqrt(1 - ((t -= 2) * t)) + 1)) + b;
}
///
@@ -208,7 +208,7 @@ public static float EaseIn(float t, float b, float c, float d)
public static float EaseInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1) { return ((c / 2) * t * t * t) + b; }
- return ((c / 2) * (((t -= 2) * t * t) + 2)) + b;
+ return ((c / 2) * (((t -= 2) * t * t) + 2)) + b;
}
///
@@ -259,10 +259,10 @@ public static float EaseIn(float t, float b, float c, float d)
///
public static float EaseInOut(float t, float b, float c, float d)
{
- if (t == 0) { return b; }
- if (t == d) { return b + c; }
+ if (t == 0) { return b; }
+ if (t == d) { return b + c; }
if ((t /= d / 2) < 1) { return ((c / 2) * (float)Math.Pow(2, 10 * (t - 1))) + b; }
- return ((c / 2) * (-(float)Math.Pow(2, -10 * --t) + 2)) + b;
+ return ((c / 2) * (-(float)Math.Pow(2, -10 * --t) + 2)) + b;
}
///
@@ -335,7 +335,7 @@ public static float EaseIn(float t, float b, float c, float d)
public static float EaseInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1) { return ((c / 2) * t * t) + b; }
- return ((-c / 2) * ((--t * (t - 2)) - 1)) + b;
+ return ((-c / 2) * ((--t * (t - 2)) - 1)) + b;
}
///
@@ -387,7 +387,7 @@ public static float EaseIn(float t, float b, float c, float d)
public static float EaseInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1) { return ((c / 2) * t * t * t * t) + b; }
- return ((-c / 2) * (((t -= 2) * t * t * t) - 2)) + b;
+ return ((-c / 2) * (((t -= 2) * t * t * t) - 2)) + b;
}
///
@@ -439,7 +439,7 @@ public static float EaseIn(float t, float b, float c, float d)
public static float EaseInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1) { return ((c / 2) * t * t * t * t * t) + b; }
- return ((c / 2) * (((t -= 2) * t * t * t * t) + 2)) + b;
+ return ((c / 2) * (((t -= 2) * t * t * t * t) + 2)) + b;
}
///
diff --git a/Exomia.Framework/Tools/Timer2.cs b/src/Exomia.Framework/Tools/Timer2.cs
similarity index 79%
rename from Exomia.Framework/Tools/Timer2.cs
rename to src/Exomia.Framework/Tools/Timer2.cs
index cb495aee..1f0f6439 100644
--- a/Exomia.Framework/Tools/Timer2.cs
+++ b/src/Exomia.Framework/Tools/Timer2.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -20,26 +20,26 @@ public sealed class Timer2 : IUpdateable
///
/// Occurs when Enabled Changed.
///
- ///
- /// ###
- public event EventHandler EnabledChanged;
+ /// ###
+ ///
+ public event EventHandler? EnabledChanged;
///
/// Occurs when Update Order Changed.
///
- ///
- /// ###
- public event EventHandler UpdateOrderChanged;
+ /// ###
+ ///
+ public event EventHandler? UpdateOrderChanged;
///
/// timer finished event.
///
- public event EventHandler TimerFinished;
+ public event EventHandler? TimerFinished;
///
/// timer ticked event.
///
- public event EventHandler TimerTicked;
+ public event EventHandler? TimerTicked;
///
/// The maximum iterations.
@@ -69,7 +69,7 @@ public sealed class Timer2 : IUpdateable
///
public uint CurrentIteration { get; private set; }
- ///
+ ///
public bool Enabled
{
get { return _enabled; }
@@ -91,7 +91,7 @@ public bool Enabled
///
public float TimerTick { get; set; }
- ///
+ ///
public int UpdateOrder
{
get { return _updateOrder; }
@@ -109,43 +109,51 @@ public int UpdateOrder
/// Initializes a new instance of the class.
///
/// time in ms after a timer Tick occurs.
- /// (Optional) set the max iteration count for this timer or 0 for
- /// unlimited.
+ ///
+ /// (Optional) set the max iteration count for this timer or 0 for
+ /// unlimited.
+ ///
public Timer2(float tick, uint maxIterations = 0)
{
TimerTick = tick;
_maxIterations = maxIterations;
}
-
+
///
/// Initializes a new instance of the class.
///
/// time in ms after a timer Tick occurs.
/// callback for each tick event.
- /// (Optional) set the max iteration count for this timer or 0 for
- /// unlimited.
+ ///
+ /// (Optional) set the max iteration count for this timer or 0 for
+ /// unlimited.
+ ///
public Timer2(float tick, EventHandler tickCallback, uint maxIterations = 0)
: this(tick, maxIterations)
{
TimerTicked += tickCallback;
}
-
+
///
/// Initializes a new instance of the class.
///
/// time in ms after a timer Tick occurs.
/// callback for each tick event.
/// callback for timer finished.
- /// set the max iteration count for this timer or 0 for
- /// unlimited.
- public Timer2(float tick, EventHandler tickCallback, EventHandler finishedCallback,
- uint maxIterations)
+ ///
+ /// set the max iteration count for this timer or 0 for
+ /// unlimited.
+ ///
+ public Timer2(float tick,
+ EventHandler tickCallback,
+ EventHandler finishedCallback,
+ uint maxIterations)
: this(tick, tickCallback, maxIterations)
{
TimerFinished += finishedCallback;
}
-
- ///
+
+ ///
public void Update(GameTime gameTime)
{
if (!_enabled) { return; }
diff --git a/Exomia.Framework/Tools/Tween.cs b/src/Exomia.Framework/Tools/Tween.cs
similarity index 89%
rename from Exomia.Framework/Tools/Tween.cs
rename to src/Exomia.Framework/Tools/Tween.cs
index 72c935f9..c72dff3a 100644
--- a/Exomia.Framework/Tools/Tween.cs
+++ b/src/Exomia.Framework/Tools/Tween.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -24,13 +24,13 @@ public sealed class Tween : IUpdateable
/// Occurs when Enabled Changed.
///
///
- public event EventHandler EnabledChanged;
+ public event EventHandler? EnabledChanged;
///
/// Occurs when Update Order Changed.
///
///
- public event EventHandler UpdateOrderChanged;
+ public event EventHandler? UpdateOrderChanged;
///
/// The callback.
@@ -105,7 +105,15 @@ public int UpdateOrder
}
}
- ///
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Target for the.
+ /// The values.
+ /// The duration.
+ /// The delay.
+ /// The callback.
+ /// Thrown when one or more required arguments are null.
public Tween(object target, object values, float duration, float delay, EasingFunction callback)
{
if (values == null) { throw new ArgumentNullException(nameof(values)); }
diff --git a/Exomia.Framework/UpdateableComparer.cs b/src/Exomia.Framework/UpdateableComparer.cs
similarity index 96%
rename from Exomia.Framework/UpdateableComparer.cs
rename to src/Exomia.Framework/UpdateableComparer.cs
index b2f53903..3a05025a 100644
--- a/Exomia.Framework/UpdateableComparer.cs
+++ b/src/Exomia.Framework/UpdateableComparer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
diff --git a/Exomia.Framework/Video/VideoPlayer.cs b/src/Exomia.Framework/Video/VideoPlayer.cs
similarity index 73%
rename from Exomia.Framework/Video/VideoPlayer.cs
rename to src/Exomia.Framework/Video/VideoPlayer.cs
index 6abc5780..2e6824a7 100644
--- a/Exomia.Framework/Video/VideoPlayer.cs
+++ b/src/Exomia.Framework/Video/VideoPlayer.cs
@@ -1,6 +1,6 @@
#region License
-// Copyright (c) 2018-2019, exomia
+// Copyright (c) 2018-2020, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
@@ -40,7 +40,7 @@ public sealed class VideoPlayer : DrawableComponent
///
/// Name of the asset.
///
- private string _assetName;
+ private string? _assetName;
///
/// The background color.
@@ -50,12 +50,12 @@ public sealed class VideoPlayer : DrawableComponent
///
/// The byte stream.
///
- private ByteStream _byteStream;
+ private ByteStream? _byteStream;
///
/// Manager for dxgi device.
///
- private DXGIDeviceManager _dxgiDeviceManager;
+ private DXGIDeviceManager? _dxgiDeviceManager;
///
/// True if this object is end of stream.
@@ -75,27 +75,27 @@ public sealed class VideoPlayer : DrawableComponent
///
/// The media engine.
///
- private MediaEngine _mediaEngine;
+ private MediaEngine? _mediaEngine;
///
/// The media engine ex.
///
- private MediaEngineEx _mediaEngineEx;
+ private MediaEngineEx? _mediaEngineEx;
///
/// The sprite batch.
///
- private SpriteBatch _spriteBatch;
+ private SpriteBatch? _spriteBatch;
///
/// The texture.
///
- private Texture _texture;
+ private Texture? _texture;
///
/// The graphics device.
///
- private IGraphicsDevice _graphicsDevice;
+ private IGraphicsDevice? _graphicsDevice;
///
/// Gets or sets the name of the asset.
@@ -103,16 +103,10 @@ public sealed class VideoPlayer : DrawableComponent
///
/// The name of the asset.
///
- public string AssetName
+ public string? AssetName
{
get { return _assetName; }
- set
- {
- if (_assetName != value)
- {
- _assetName = value;
- }
- }
+ set { _assetName = value; }
}
///
@@ -124,13 +118,7 @@ public string AssetName
public Color BackgroundColor
{
get { return _backgroundColor; }
- set
- {
- if (_backgroundColor != value)
- {
- _backgroundColor = value;
- }
- }
+ set { _backgroundColor = value; }
}
///
@@ -143,12 +131,12 @@ public double Duration
{
get
{
- double duration = 0.0;
- if (_mediaEngineEx != null)
+ if (_mediaEngineEx == null)
{
- duration = _mediaEngineEx.Duration;
- if (double.IsNaN(duration)) { duration = 0.0; }
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
}
+ double duration = _mediaEngineEx.Duration;
+ if (double.IsNaN(duration)) { duration = 0.0; }
return duration;
}
}
@@ -162,13 +150,8 @@ public double Duration
public bool IsPlaying
{
get { return _isPlaying; }
- set
- {
- if (_isPlaying != value)
- {
- _isPlaying = value;
- }
- }
+
+ set { _isPlaying = value; }
}
///
@@ -180,7 +163,15 @@ public bool IsPlaying
public bool Mute
{
get { return _mediaEngineEx?.Muted ?? false; }
- set { _mediaEngineEx.Muted = value; }
+
+ set
+ {
+ if (_mediaEngineEx == null)
+ {
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
+ }
+ _mediaEngineEx.Muted = value;
+ }
}
///
@@ -192,7 +183,15 @@ public bool Mute
public double PlaybackPosition
{
get { return _mediaEngineEx?.CurrentTime ?? 0.0; }
- set { _mediaEngineEx.CurrentTime = value; }
+
+ set
+ {
+ if (_mediaEngineEx == null)
+ {
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
+ }
+ _mediaEngineEx.CurrentTime = value;
+ }
}
///
@@ -204,7 +203,15 @@ public double PlaybackPosition
public double Volume
{
get { return _mediaEngineEx?.Volume ?? 0.0; }
- set { _mediaEngineEx.Volume = value; }
+
+ set
+ {
+ if (_mediaEngineEx == null)
+ {
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
+ }
+ _mediaEngineEx.Volume = value;
+ }
}
///
@@ -229,8 +236,8 @@ public override bool BeginDraw()
///
public override void Draw(GameTime gameTime)
{
- _spriteBatch.Begin();
- _spriteBatch.Draw(_texture, Vector2.Zero, Color.White);
+ _spriteBatch!.Begin();
+ _spriteBatch.Draw(_texture!, Vector2.Zero, Color.White);
_spriteBatch.End();
}
@@ -247,22 +254,26 @@ public void Pause()
///
public void Play()
{
- if (_mediaEngineEx != null)
+ if (_mediaEngineEx == null)
{
- if (_mediaEngineEx.HasVideo() && _isVideoStopped) { _isVideoStopped = false; }
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
+ }
- if (_isEndOfStream)
- {
- PlaybackPosition = 0;
- _isPlaying = true;
- }
- else
- {
- _mediaEngineEx.Play();
- }
+ if (_mediaEngineEx.HasVideo() && _isVideoStopped)
+ {
+ _isVideoStopped = false;
+ }
+ if (_isEndOfStream)
+ {
+ PlaybackPosition = 0;
+ _isPlaying = true;
+ }
- _isEndOfStream = false;
+ else
+ {
+ _mediaEngineEx.Play();
}
+ _isEndOfStream = false;
}
///
@@ -273,14 +284,16 @@ public void Play()
public void SetByteStream(Stream stream)
{
_byteStream = new ByteStream(stream);
- if (_mediaEngineEx != null)
+ if (_mediaEngineEx == null)
{
- Uri url = new Uri(_assetName, UriKind.RelativeOrAbsolute);
- _mediaEngineEx.SetSourceFromByteStream(_byteStream, url.AbsoluteUri);
- if (!_eventReadyToPlay.WaitOne(5000))
- {
- throw new Exception("Unexpected error: Unable to play this file");
- }
+ throw new NullReferenceException($"the {nameof(_mediaEngineEx)} is uninitialized!");
+ }
+
+ Uri url = new Uri(_assetName, UriKind.RelativeOrAbsolute);
+ _mediaEngineEx.SetSourceFromByteStream(_byteStream, url.AbsoluteUri);
+ if (!_eventReadyToPlay.WaitOne(5000))
+ {
+ throw new Exception("Unexpected error: Unable to play this file");
}
}
@@ -293,30 +306,29 @@ public void Shutdown()
{
Stop();
- _mediaEngineEx?.Shutdown();
+ _mediaEngineEx!.Shutdown();
}
}
///
public override void Update(GameTime gameTime)
{
- if (_isVideoStopped || !_isInitialized) { return; }
-
- if (_mediaEngineEx != null)
+ if (_isVideoStopped || !_isInitialized)
{
- if (_mediaEngineEx.OnVideoStreamTick(out _))
- {
- _mediaEngineEx.TransferVideoFrame(
- _outputTexture,
- null,
- new Rectangle(0, 0, _outputTexture.Description.Width, _outputTexture.Description.Height),
- (ColorBGRA)BackgroundColor);
-
- //TODO: draw the texture directly to the _texture's TexturePointer instead of creating every time new one
- _texture = new Texture(
- new ShaderResourceView1(_graphicsDevice.Device, _outputTexture),
- _outputTexture.Description.Width, _outputTexture.Description.Height);
- }
+ return;
+ }
+ if (_mediaEngineEx!.OnVideoStreamTick(out _))
+ {
+ _mediaEngineEx.TransferVideoFrame(
+ _outputTexture,
+ null,
+ new Rectangle(0, 0, _outputTexture.Description.Width, _outputTexture.Description.Height),
+ (ColorBGRA)BackgroundColor);
+
+ //TODO: draw the texture directly to the _texture's TexturePointer instead of creating every time new one
+ _texture = new Texture(
+ new ShaderResourceView1(_graphicsDevice!.Device, _outputTexture),
+ _outputTexture.Description.Width, _outputTexture.Description.Height);
}
}
@@ -325,13 +337,10 @@ protected override void OnInitialize(IServiceRegistry registry)
{
_graphicsDevice = registry.GetService() ??
throw new NullReferenceException(nameof(IGraphicsDevice));
-
_spriteBatch = ToDispose(new SpriteBatch(_graphicsDevice));
MediaManager.Startup();
-
DeviceMultithread multithread = _graphicsDevice.Device.QueryInterface();
multithread.SetMultithreadProtected(true);
-
_dxgiDeviceManager = ToDispose(new DXGIDeviceManager());
_dxgiDeviceManager.ResetDevice(_graphicsDevice.Device);
@@ -339,7 +348,6 @@ protected override void OnInitialize(IServiceRegistry registry)
{
DxgiManager = _dxgiDeviceManager, VideoOutputFormat = (int)Format.B8G8R8A8_UNorm
};
-
using (MediaEngineClassFactory factory = new MediaEngineClassFactory())
{
_mediaEngine = ToDispose(
@@ -375,7 +383,7 @@ private void OnMediaEngineEvent(MediaEngineEvent mediaEvent, long param1, int pa
_isPlaying = false;
break;
case MediaEngineEvent.Ended:
- if (_mediaEngineEx.HasVideo())
+ if (_mediaEngineEx!.HasVideo())
{
Stop();
}
diff --git a/Exomia.Framework/samples.info b/src/Exomia.Framework/samples.info
similarity index 100%
rename from Exomia.Framework/samples.info
rename to src/Exomia.Framework/samples.info