Refactored the XInput FormatConverter and unknown keys are now ignored instead of throwing NotImplementedException
This commit is contained in:
parent
25006ab464
commit
2745521141
@ -11,35 +11,22 @@ namespace ANX.Framework.NonXNA
|
||||
public class AddIn : IComparable<AddIn>
|
||||
{
|
||||
#region Private
|
||||
private Assembly assembly;
|
||||
private Type creatorType;
|
||||
private ICreator instance;
|
||||
private ISupportedPlatforms supportedPlatforms;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
return assembly != null && creatorType != null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSupported
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid && supportedPlatforms != null)
|
||||
if (supportedPlatforms != null)
|
||||
{
|
||||
PlatformName platformName = OSInformation.GetName();
|
||||
foreach (var platform in supportedPlatforms.Names)
|
||||
{
|
||||
if (platformName == platform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -56,14 +43,16 @@ namespace ANX.Framework.NonXNA
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
return instance.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "*** no instance of AddIn *** (" + creatorType.FullName + ")";
|
||||
}
|
||||
try
|
||||
{
|
||||
if (Instance != null)
|
||||
return Instance.Name;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return "*** no instance of AddIn *** (" + creatorType.FullName + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,13 +61,9 @@ namespace ANX.Framework.NonXNA
|
||||
get
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
return instance.Priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
return int.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,10 +94,11 @@ namespace ANX.Framework.NonXNA
|
||||
#region Constructor
|
||||
public AddIn(Type creatorType, Type supportedPlatformsType)
|
||||
{
|
||||
this.assembly = TypeHelper.GetAssemblyFrom(creatorType);
|
||||
this.creatorType = creatorType;
|
||||
Type = AddInSystemFactory.GetAddInType(creatorType);
|
||||
this.supportedPlatforms = TypeHelper.Create<ISupportedPlatforms>(supportedPlatformsType);
|
||||
|
||||
var assembly = TypeHelper.GetAssemblyFrom(creatorType);
|
||||
Version = assembly.GetName().Version;
|
||||
}
|
||||
#endregion
|
||||
@ -131,11 +117,11 @@ namespace ANX.Framework.NonXNA
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = TypeHelper.Create<ICreator>(creatorType); ;
|
||||
instance = TypeHelper.Create<ICreator>(creatorType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("couldn't create instance of creator '" + creatorType.FullName + "'.", ex.InnerException);
|
||||
{
|
||||
HandleCreateException(ex);
|
||||
}
|
||||
|
||||
if (instance != null)
|
||||
@ -143,5 +129,28 @@ namespace ANX.Framework.NonXNA
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region HandleCreateException
|
||||
private void HandleCreateException(Exception ex)
|
||||
{
|
||||
if (ex.InnerException == null)
|
||||
{
|
||||
Logger.Error("couldn't create instance of creator '" + creatorType.FullName + "'.", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
string innerMessage = ex.InnerException.Message;
|
||||
if (innerMessage.Contains("openal32.dll"))
|
||||
{
|
||||
Logger.Error("Couldn't create instance of creator '" + creatorType.FullName +
|
||||
"' cause OpenAL is not installed and the dll's couldn't be found in the output path, too! " +
|
||||
"Make sure the OpenAL32.dll and the wrap_oal.dll files are in the output folder. You can " +
|
||||
"find them in the lib folder of the ANX.Framework or download and run the installer from " +
|
||||
"http://connect.creativelabs.com/openal/Downloads/oalinst.zip");
|
||||
}
|
||||
else
|
||||
Logger.Error("couldn't create instance of creator '" + creatorType.FullName + "'.", ex.InnerException);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace ANX.Framework.NonXNA
|
||||
matchingSupportedPlatformsType = FindSupportedPlatformsTypeByAssembly(creatorType);
|
||||
|
||||
AddIn addin = new AddIn(creatorType, matchingSupportedPlatformsType);
|
||||
if (addin.IsValid && addin.IsSupported)
|
||||
if (addin.IsSupported)
|
||||
{
|
||||
addinSystems[addin.Type].Add(addin);
|
||||
Logger.Info("[ANX] successfully loaded AddIn (" + addin.Type + ") " + creatorType.FullName + ".");
|
||||
|
@ -8,6 +8,32 @@ namespace ANX.Framework.NonXNA.Reflection
|
||||
{
|
||||
internal static class AssemblyLoader
|
||||
{
|
||||
#region Constants
|
||||
private static readonly string[] IgnoreAssemblies =
|
||||
{
|
||||
"OpenTK.dll",
|
||||
"OpenTK.GLControl.dll",
|
||||
"OpenTK.Compatibility.dll",
|
||||
"sharpdx_direct3d11_effects_x86.dll",
|
||||
"sharpdx_direct3d11_effects_x64.dll",
|
||||
"SharpDX.dll",
|
||||
"SharpDX.Direct3D11.dll",
|
||||
"SharpDX.Direct3D10.dll",
|
||||
"SharpDX.D3DCompiler.dll",
|
||||
"SharpDX.DXGI.dll",
|
||||
"SharpDX.XInput.dll",
|
||||
"SharpDX.DirectInput.dll",
|
||||
"WaveUtils.dll",
|
||||
"SharpDX.XAudio2.dll",
|
||||
"System.dll",
|
||||
"System.Core.dll",
|
||||
"System.Xml.dll",
|
||||
"System.Xml.Linq.dll",
|
||||
"mscorlib.dll",
|
||||
"Sce.PlayStation.Core.dll",
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
private static List<Assembly> allAssemblies;
|
||||
#endregion
|
||||
@ -64,22 +90,19 @@ namespace ANX.Framework.NonXNA.Reflection
|
||||
|
||||
foreach (string file in assembliesInPath)
|
||||
{
|
||||
if (file.EndsWith("OpenTK.dll") ||
|
||||
file.EndsWith("OpenTK.GLControl.dll") ||
|
||||
file.EndsWith("OpenTK.Compatibility.dll") ||
|
||||
file.EndsWith("SharpDX.dll") ||
|
||||
file.EndsWith("SharpDX.Direct3D11.dll") ||
|
||||
file.EndsWith("SharpDX.Direct3D10.dll") ||
|
||||
file.EndsWith("SharpDX.D3DCompiler.dll") ||
|
||||
file.EndsWith("SharpDX.DXGI.dll") ||
|
||||
file.EndsWith("SharpDX.XInput.dll") ||
|
||||
file.EndsWith("SharpDX.DirectInput.dll") ||
|
||||
file.EndsWith("WaveUtils.dll") ||
|
||||
file.EndsWith("SharpDX.XAudio2.dll"))
|
||||
bool ignore = false;
|
||||
foreach (string ignoreName in IgnoreAssemblies)
|
||||
{
|
||||
continue;
|
||||
if (file.EndsWith(ignoreName))
|
||||
{
|
||||
ignore = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ignore)
|
||||
continue;
|
||||
|
||||
Logger.Info("[ANX] trying to load '" + file + "'...");
|
||||
try
|
||||
{
|
||||
|
@ -1,9 +1,8 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ANX.Framework.Input;
|
||||
using SharpDX.XInput;
|
||||
|
||||
#endregion // Using Statements
|
||||
using Key = SharpDX.DirectInput.Key;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -11,351 +10,261 @@ using SharpDX.XInput;
|
||||
|
||||
namespace ANX.InputDevices.Windows.XInput
|
||||
{
|
||||
internal class FormatConverter
|
||||
{
|
||||
public static ANX.Framework.Input.Keys Translate(SharpDX.DirectInput.Key key)
|
||||
{
|
||||
//TODO: implement all keys
|
||||
//TODO: test if a array with the mapping which is constructed once is faster
|
||||
internal static class FormatConverter
|
||||
{
|
||||
private static Dictionary<GamepadButtonFlags, Buttons> gamePadButtonsMap;
|
||||
private static Dictionary<Key, Keys> keyboardKeyMap;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case SharpDX.DirectInput.Key.A:
|
||||
return Keys.A;
|
||||
case SharpDX.DirectInput.Key.AT:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.AX:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.AbntC1:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.AbntC2:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Add:
|
||||
return Keys.Add;
|
||||
case SharpDX.DirectInput.Key.Apostrophe:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Applications:
|
||||
//check
|
||||
return Keys.Apps;
|
||||
case SharpDX.DirectInput.Key.B:
|
||||
return Keys.B;
|
||||
case SharpDX.DirectInput.Key.Back:
|
||||
return Keys.Back;
|
||||
case SharpDX.DirectInput.Key.Backslash:
|
||||
return Keys.OemBackslash;
|
||||
case SharpDX.DirectInput.Key.C:
|
||||
return Keys.C;
|
||||
case SharpDX.DirectInput.Key.Calculator:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Capital:
|
||||
//check
|
||||
return Keys.CapsLock;
|
||||
case SharpDX.DirectInput.Key.Colon:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Comma:
|
||||
return Keys.OemComma;
|
||||
case SharpDX.DirectInput.Key.Convert:
|
||||
return Keys.ImeConvert;
|
||||
case SharpDX.DirectInput.Key.D:
|
||||
return Keys.D;
|
||||
case SharpDX.DirectInput.Key.D0:
|
||||
return Keys.D0;
|
||||
case SharpDX.DirectInput.Key.D1:
|
||||
return Keys.D1;
|
||||
case SharpDX.DirectInput.Key.D2:
|
||||
return Keys.D2;
|
||||
case SharpDX.DirectInput.Key.D3:
|
||||
return Keys.D3;
|
||||
case SharpDX.DirectInput.Key.D4:
|
||||
return Keys.D4;
|
||||
case SharpDX.DirectInput.Key.D5:
|
||||
return Keys.D5;
|
||||
case SharpDX.DirectInput.Key.D6:
|
||||
return Keys.D6;
|
||||
case SharpDX.DirectInput.Key.D7:
|
||||
return Keys.D7;
|
||||
case SharpDX.DirectInput.Key.D8:
|
||||
return Keys.D8;
|
||||
case SharpDX.DirectInput.Key.D9:
|
||||
return Keys.D9;
|
||||
case SharpDX.DirectInput.Key.Decimal:
|
||||
return Keys.Decimal;
|
||||
case SharpDX.DirectInput.Key.Delete:
|
||||
return Keys.Delete;
|
||||
case SharpDX.DirectInput.Key.Divide:
|
||||
return Keys.Divide;
|
||||
case SharpDX.DirectInput.Key.Down:
|
||||
return Keys.Down;
|
||||
case SharpDX.DirectInput.Key.E:
|
||||
return Keys.E;
|
||||
case SharpDX.DirectInput.Key.End:
|
||||
return Keys.End;
|
||||
case SharpDX.DirectInput.Key.Equals:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Escape:
|
||||
return Keys.Escape;
|
||||
case SharpDX.DirectInput.Key.F:
|
||||
return Keys.F;
|
||||
case SharpDX.DirectInput.Key.F1:
|
||||
return Keys.F1;
|
||||
case SharpDX.DirectInput.Key.F10:
|
||||
return Keys.F10;
|
||||
case SharpDX.DirectInput.Key.F11:
|
||||
return Keys.F11;
|
||||
case SharpDX.DirectInput.Key.F12:
|
||||
return Keys.F12;
|
||||
case SharpDX.DirectInput.Key.F13:
|
||||
return Keys.F13;
|
||||
case SharpDX.DirectInput.Key.F14:
|
||||
return Keys.F14;
|
||||
case SharpDX.DirectInput.Key.F15:
|
||||
return Keys.F15;
|
||||
case SharpDX.DirectInput.Key.F2:
|
||||
return Keys.F2;
|
||||
case SharpDX.DirectInput.Key.F3:
|
||||
return Keys.F3;
|
||||
case SharpDX.DirectInput.Key.F4:
|
||||
return Keys.F4;
|
||||
case SharpDX.DirectInput.Key.F5:
|
||||
return Keys.F5;
|
||||
case SharpDX.DirectInput.Key.F6:
|
||||
return Keys.F6;
|
||||
case SharpDX.DirectInput.Key.F7:
|
||||
return Keys.F7;
|
||||
case SharpDX.DirectInput.Key.F8:
|
||||
return Keys.F8;
|
||||
case SharpDX.DirectInput.Key.F9:
|
||||
return Keys.F9;
|
||||
case SharpDX.DirectInput.Key.G:
|
||||
return Keys.G;
|
||||
case SharpDX.DirectInput.Key.Grave:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.H:
|
||||
return Keys.H;
|
||||
case SharpDX.DirectInput.Key.Home:
|
||||
return Keys.Home;
|
||||
case SharpDX.DirectInput.Key.I:
|
||||
return Keys.I;
|
||||
case SharpDX.DirectInput.Key.Insert:
|
||||
return Keys.Insert;
|
||||
case SharpDX.DirectInput.Key.J:
|
||||
return Keys.J;
|
||||
case SharpDX.DirectInput.Key.K:
|
||||
return Keys.K;
|
||||
case SharpDX.DirectInput.Key.Kana:
|
||||
return Keys.Kana;
|
||||
case SharpDX.DirectInput.Key.Kanji:
|
||||
return Keys.Kanji;
|
||||
case SharpDX.DirectInput.Key.L:
|
||||
return Keys.L;
|
||||
case SharpDX.DirectInput.Key.Left:
|
||||
return Keys.Left;
|
||||
case SharpDX.DirectInput.Key.LeftAlt:
|
||||
return Keys.LeftAlt;
|
||||
case SharpDX.DirectInput.Key.LeftBracket:
|
||||
return Keys.OemOpenBrackets;
|
||||
case SharpDX.DirectInput.Key.LeftControl:
|
||||
return Keys.LeftControl;
|
||||
case SharpDX.DirectInput.Key.LeftShift:
|
||||
return Keys.LeftShift;
|
||||
case SharpDX.DirectInput.Key.LeftWindowsKey:
|
||||
return Keys.LeftWindows;
|
||||
case SharpDX.DirectInput.Key.M:
|
||||
return Keys.M;
|
||||
case SharpDX.DirectInput.Key.Mail:
|
||||
return Keys.LaunchMail;
|
||||
case SharpDX.DirectInput.Key.MediaSelect:
|
||||
return Keys.SelectMedia;
|
||||
case SharpDX.DirectInput.Key.MediaStop:
|
||||
return Keys.MediaStop;
|
||||
case SharpDX.DirectInput.Key.Minus:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Multiply:
|
||||
return Keys.Multiply;
|
||||
case SharpDX.DirectInput.Key.Mute:
|
||||
return Keys.VolumeMute;
|
||||
case SharpDX.DirectInput.Key.MyComputer:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.N:
|
||||
return Keys.N;
|
||||
case SharpDX.DirectInput.Key.NextTrack:
|
||||
return Keys.MediaNextTrack;
|
||||
case SharpDX.DirectInput.Key.NoConvert:
|
||||
return Keys.ImeNoConvert;
|
||||
case SharpDX.DirectInput.Key.NumberLock:
|
||||
return Keys.NumLock;
|
||||
case SharpDX.DirectInput.Key.NumberPad0:
|
||||
return Keys.NumPad0;
|
||||
case SharpDX.DirectInput.Key.NumberPad1:
|
||||
return Keys.NumPad1;
|
||||
case SharpDX.DirectInput.Key.NumberPad2:
|
||||
return Keys.NumPad2;
|
||||
case SharpDX.DirectInput.Key.NumberPad3:
|
||||
return Keys.NumPad3;
|
||||
case SharpDX.DirectInput.Key.NumberPad4:
|
||||
return Keys.NumPad4;
|
||||
case SharpDX.DirectInput.Key.NumberPad5:
|
||||
return Keys.NumPad5;
|
||||
case SharpDX.DirectInput.Key.NumberPad6:
|
||||
return Keys.NumPad6;;
|
||||
case SharpDX.DirectInput.Key.NumberPad7:
|
||||
return Keys.NumPad7;
|
||||
case SharpDX.DirectInput.Key.NumberPad8:
|
||||
return Keys.NumPad8;
|
||||
case SharpDX.DirectInput.Key.NumberPad9:
|
||||
return Keys.NumPad9;
|
||||
case SharpDX.DirectInput.Key.NumberPadComma:
|
||||
return Keys.OemComma;
|
||||
case SharpDX.DirectInput.Key.NumberPadEnter:
|
||||
return Keys.Enter;
|
||||
case SharpDX.DirectInput.Key.NumberPadEquals:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.O:
|
||||
return Keys.O;
|
||||
case SharpDX.DirectInput.Key.Oem102:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.P:
|
||||
return Keys.P;
|
||||
case SharpDX.DirectInput.Key.PageDown:
|
||||
return Keys.PageDown;
|
||||
case SharpDX.DirectInput.Key.PageUp:
|
||||
return Keys.PageUp;
|
||||
case SharpDX.DirectInput.Key.Pause:
|
||||
return Keys.Pause;
|
||||
case SharpDX.DirectInput.Key.Period:
|
||||
return Keys.OemPeriod;
|
||||
case SharpDX.DirectInput.Key.PlayPause:
|
||||
return Keys.MediaPlayPause;
|
||||
case SharpDX.DirectInput.Key.Power:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.PreviousTrack:
|
||||
return Keys.MediaPreviousTrack;
|
||||
case SharpDX.DirectInput.Key.PrintScreen:
|
||||
return Keys.PrintScreen;
|
||||
case SharpDX.DirectInput.Key.Q:
|
||||
return Keys.Q;
|
||||
case SharpDX.DirectInput.Key.R:
|
||||
return Keys.R;
|
||||
case SharpDX.DirectInput.Key.Return:
|
||||
//check
|
||||
return Keys.Enter;
|
||||
case SharpDX.DirectInput.Key.Right:
|
||||
return Keys.Right;
|
||||
case SharpDX.DirectInput.Key.RightAlt:
|
||||
return Keys.RightAlt;
|
||||
case SharpDX.DirectInput.Key.RightBracket:
|
||||
return Keys.OemCloseBrackets;
|
||||
case SharpDX.DirectInput.Key.RightControl:
|
||||
return Keys.RightControl;
|
||||
case SharpDX.DirectInput.Key.RightShift:
|
||||
return Keys.RightShift;
|
||||
case SharpDX.DirectInput.Key.RightWindowsKey:
|
||||
return Keys.RightWindows;
|
||||
case SharpDX.DirectInput.Key.S:
|
||||
return Keys.S;
|
||||
case SharpDX.DirectInput.Key.ScrollLock:
|
||||
//check
|
||||
return Keys.Scroll;
|
||||
case SharpDX.DirectInput.Key.Semicolon:
|
||||
return Keys.OemSemicolon;
|
||||
case SharpDX.DirectInput.Key.Slash:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Sleep:
|
||||
return Keys.Sleep;
|
||||
case SharpDX.DirectInput.Key.Space:
|
||||
return Keys.Space;
|
||||
case SharpDX.DirectInput.Key.Stop:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Subtract:
|
||||
return Keys.Subtract;
|
||||
case SharpDX.DirectInput.Key.T:
|
||||
return Keys.T;
|
||||
case SharpDX.DirectInput.Key.Tab:
|
||||
return Keys.Tab;
|
||||
case SharpDX.DirectInput.Key.U:
|
||||
return Keys.U;
|
||||
case SharpDX.DirectInput.Key.Underline:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Unknown:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Unlabeled:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.UpArrow:
|
||||
return Keys.Up;
|
||||
case SharpDX.DirectInput.Key.V:
|
||||
return Keys.V;
|
||||
case SharpDX.DirectInput.Key.VolumeDown:
|
||||
return Keys.VolumeDown;
|
||||
case SharpDX.DirectInput.Key.VolumeUp:
|
||||
return Keys.VolumeUp;
|
||||
case SharpDX.DirectInput.Key.W:
|
||||
return Keys.W;
|
||||
case SharpDX.DirectInput.Key.Wake:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.WebBack:
|
||||
return Keys.BrowserBack;
|
||||
case SharpDX.DirectInput.Key.WebFavorites:
|
||||
return Keys.BrowserFavorites;
|
||||
case SharpDX.DirectInput.Key.WebForward:
|
||||
return Keys.BrowserForward;
|
||||
case SharpDX.DirectInput.Key.WebHome:
|
||||
return Keys.BrowserHome;
|
||||
case SharpDX.DirectInput.Key.WebRefresh:
|
||||
return Keys.BrowserRefresh;
|
||||
case SharpDX.DirectInput.Key.WebSearch:
|
||||
return Keys.BrowserSearch;
|
||||
case SharpDX.DirectInput.Key.WebStop:
|
||||
return Keys.BrowserStop;
|
||||
case SharpDX.DirectInput.Key.X:
|
||||
return Keys.X;
|
||||
case SharpDX.DirectInput.Key.Y:
|
||||
return Keys.Y;
|
||||
case SharpDX.DirectInput.Key.Yen:
|
||||
break;
|
||||
case SharpDX.DirectInput.Key.Z:
|
||||
return Keys.Z;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
static FormatConverter()
|
||||
{
|
||||
CreateGamePadButtonMap();
|
||||
CreateKeyboardKeyMap();
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#region CreateGamePadButtonMap
|
||||
private static void CreateGamePadButtonMap()
|
||||
{
|
||||
gamePadButtonsMap = new Dictionary<GamepadButtonFlags, Buttons>();
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.A, Buttons.A);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.B, Buttons.B);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.X, Buttons.X);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.Y, Buttons.Y);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.Back, Buttons.Back);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.Start, Buttons.Start);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.DPadDown, Buttons.DPadDown);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.DPadLeft, Buttons.DPadLeft);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.DPadRight, Buttons.DPadRight);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.DPadUp, Buttons.DPadUp);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.LeftShoulder, Buttons.LeftShoulder);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.LeftThumb, Buttons.LeftStick);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.RightShoulder, Buttons.RightShoulder);
|
||||
gamePadButtonsMap.Add(GamepadButtonFlags.RightThumb, Buttons.RightStick);
|
||||
|
||||
public static KeyboardState Translate(SharpDX.DirectInput.KeyboardState keyboardState)
|
||||
{
|
||||
int keyCount = keyboardState.PressedKeys.Count;
|
||||
Keys[] keys = new Keys[keyCount];
|
||||
// TODO: xna supports more than sharpdx it seems. Missing: l/r trigger, big, l/r/u/d thumbsticks
|
||||
}
|
||||
#endregion
|
||||
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
{
|
||||
keys[i] = Translate(keyboardState.PressedKeys[i]);
|
||||
}
|
||||
#region CreateKeyboardKeyMap
|
||||
private static void CreateKeyboardKeyMap()
|
||||
{
|
||||
keyboardKeyMap = new Dictionary<Key, Keys>();
|
||||
keyboardKeyMap.Add(Key.Unknown, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Escape, Keys.Escape);
|
||||
keyboardKeyMap.Add(Key.D1, Keys.D1);
|
||||
keyboardKeyMap.Add(Key.D2, Keys.D2);
|
||||
keyboardKeyMap.Add(Key.D3, Keys.D3);
|
||||
keyboardKeyMap.Add(Key.D4, Keys.D4);
|
||||
keyboardKeyMap.Add(Key.D5, Keys.D5);
|
||||
keyboardKeyMap.Add(Key.D6, Keys.D6);
|
||||
keyboardKeyMap.Add(Key.D7, Keys.D7);
|
||||
keyboardKeyMap.Add(Key.D8, Keys.D8);
|
||||
keyboardKeyMap.Add(Key.D9, Keys.D9);
|
||||
keyboardKeyMap.Add(Key.D0, Keys.D0);
|
||||
keyboardKeyMap.Add(Key.Minus, Keys.OemMinus);
|
||||
keyboardKeyMap.Add(Key.Back, Keys.Back);
|
||||
keyboardKeyMap.Add(Key.Tab, Keys.Tab);
|
||||
keyboardKeyMap.Add(Key.Q, Keys.Q);
|
||||
keyboardKeyMap.Add(Key.W, Keys.W);
|
||||
keyboardKeyMap.Add(Key.E, Keys.E);
|
||||
keyboardKeyMap.Add(Key.R, Keys.R);
|
||||
keyboardKeyMap.Add(Key.T, Keys.T);
|
||||
keyboardKeyMap.Add(Key.Y, Keys.Y);
|
||||
keyboardKeyMap.Add(Key.U, Keys.U);
|
||||
keyboardKeyMap.Add(Key.I, Keys.I);
|
||||
keyboardKeyMap.Add(Key.O, Keys.O);
|
||||
keyboardKeyMap.Add(Key.P, Keys.P);
|
||||
keyboardKeyMap.Add(Key.LeftBracket, Keys.OemOpenBrackets);
|
||||
keyboardKeyMap.Add(Key.RightBracket, Keys.OemCloseBrackets);
|
||||
keyboardKeyMap.Add(Key.Return, Keys.Enter);
|
||||
keyboardKeyMap.Add(Key.LeftControl, Keys.LeftControl);
|
||||
keyboardKeyMap.Add(Key.A, Keys.A);
|
||||
keyboardKeyMap.Add(Key.S, Keys.S);
|
||||
keyboardKeyMap.Add(Key.D, Keys.D);
|
||||
keyboardKeyMap.Add(Key.F, Keys.F);
|
||||
keyboardKeyMap.Add(Key.G, Keys.G);
|
||||
keyboardKeyMap.Add(Key.H, Keys.H);
|
||||
keyboardKeyMap.Add(Key.J, Keys.J);
|
||||
keyboardKeyMap.Add(Key.K, Keys.K);
|
||||
keyboardKeyMap.Add(Key.L, Keys.L);
|
||||
keyboardKeyMap.Add(Key.Semicolon, Keys.OemSemicolon);
|
||||
keyboardKeyMap.Add(Key.LeftShift, Keys.LeftShift);
|
||||
keyboardKeyMap.Add(Key.Backslash, Keys.OemBackslash);
|
||||
keyboardKeyMap.Add(Key.Z, Keys.Z);
|
||||
keyboardKeyMap.Add(Key.X, Keys.X);
|
||||
keyboardKeyMap.Add(Key.C, Keys.C);
|
||||
keyboardKeyMap.Add(Key.V, Keys.V);
|
||||
keyboardKeyMap.Add(Key.B, Keys.B);
|
||||
keyboardKeyMap.Add(Key.N, Keys.N);
|
||||
keyboardKeyMap.Add(Key.M, Keys.M);
|
||||
keyboardKeyMap.Add(Key.Comma, Keys.OemComma);
|
||||
keyboardKeyMap.Add(Key.Period, Keys.OemPeriod);
|
||||
keyboardKeyMap.Add(Key.RightShift, Keys.RightShift);
|
||||
keyboardKeyMap.Add(Key.Multiply, Keys.Multiply);
|
||||
keyboardKeyMap.Add(Key.LeftAlt, Keys.LeftAlt);
|
||||
keyboardKeyMap.Add(Key.Space, Keys.Space);
|
||||
keyboardKeyMap.Add(Key.Capital, Keys.CapsLock);
|
||||
keyboardKeyMap.Add(Key.F1, Keys.F1);
|
||||
keyboardKeyMap.Add(Key.F2, Keys.F2);
|
||||
keyboardKeyMap.Add(Key.F3, Keys.F3);
|
||||
keyboardKeyMap.Add(Key.F4, Keys.F4);
|
||||
keyboardKeyMap.Add(Key.F5, Keys.F5);
|
||||
keyboardKeyMap.Add(Key.F6, Keys.F6);
|
||||
keyboardKeyMap.Add(Key.F7, Keys.F7);
|
||||
keyboardKeyMap.Add(Key.F8, Keys.F8);
|
||||
keyboardKeyMap.Add(Key.F9, Keys.F9);
|
||||
keyboardKeyMap.Add(Key.F10, Keys.F10);
|
||||
keyboardKeyMap.Add(Key.NumberLock, Keys.NumLock);
|
||||
keyboardKeyMap.Add(Key.ScrollLock, Keys.Scroll);
|
||||
keyboardKeyMap.Add(Key.NumberPad7, Keys.NumPad7);
|
||||
keyboardKeyMap.Add(Key.NumberPad8, Keys.NumPad8);
|
||||
keyboardKeyMap.Add(Key.NumberPad9, Keys.NumPad9);
|
||||
keyboardKeyMap.Add(Key.Subtract, Keys.Subtract);
|
||||
keyboardKeyMap.Add(Key.NumberPad4, Keys.NumPad4);
|
||||
keyboardKeyMap.Add(Key.NumberPad5, Keys.NumPad5);
|
||||
keyboardKeyMap.Add(Key.NumberPad6, Keys.NumPad6);
|
||||
keyboardKeyMap.Add(Key.Add, Keys.Add);
|
||||
keyboardKeyMap.Add(Key.NumberPad1, Keys.NumPad1);
|
||||
keyboardKeyMap.Add(Key.NumberPad2, Keys.NumPad2);
|
||||
keyboardKeyMap.Add(Key.NumberPad3, Keys.NumPad3);
|
||||
keyboardKeyMap.Add(Key.NumberPad0, Keys.NumPad0);
|
||||
keyboardKeyMap.Add(Key.Decimal, Keys.Decimal);
|
||||
keyboardKeyMap.Add(Key.F11, Keys.F11);
|
||||
keyboardKeyMap.Add(Key.F12, Keys.F12);
|
||||
keyboardKeyMap.Add(Key.F13, Keys.F13);
|
||||
keyboardKeyMap.Add(Key.F14, Keys.F14);
|
||||
keyboardKeyMap.Add(Key.F15, Keys.F15);
|
||||
keyboardKeyMap.Add(Key.Kana, Keys.Kana);
|
||||
keyboardKeyMap.Add(Key.Convert, Keys.ImeConvert);
|
||||
keyboardKeyMap.Add(Key.NoConvert, Keys.ImeNoConvert);
|
||||
keyboardKeyMap.Add(Key.PreviousTrack, Keys.MediaPreviousTrack);
|
||||
keyboardKeyMap.Add(Key.Kanji, Keys.Kanji);
|
||||
keyboardKeyMap.Add(Key.Stop, Keys.MediaStop);
|
||||
keyboardKeyMap.Add(Key.NextTrack, Keys.MediaNextTrack);
|
||||
keyboardKeyMap.Add(Key.NumberPadEnter, Keys.Enter);
|
||||
keyboardKeyMap.Add(Key.RightControl, Keys.RightControl);
|
||||
keyboardKeyMap.Add(Key.Mute, Keys.VolumeMute);
|
||||
keyboardKeyMap.Add(Key.PlayPause, Keys.MediaPlayPause);
|
||||
keyboardKeyMap.Add(Key.MediaStop, Keys.MediaStop);
|
||||
keyboardKeyMap.Add(Key.VolumeDown, Keys.VolumeDown);
|
||||
keyboardKeyMap.Add(Key.VolumeUp, Keys.VolumeUp);
|
||||
keyboardKeyMap.Add(Key.WebHome, Keys.BrowserHome);
|
||||
keyboardKeyMap.Add(Key.NumberPadComma, Keys.OemComma);
|
||||
keyboardKeyMap.Add(Key.Divide, Keys.Divide);
|
||||
keyboardKeyMap.Add(Key.PrintScreen, Keys.PrintScreen);
|
||||
keyboardKeyMap.Add(Key.RightAlt, Keys.RightAlt);
|
||||
keyboardKeyMap.Add(Key.Pause, Keys.Pause);
|
||||
keyboardKeyMap.Add(Key.Home, Keys.Home);
|
||||
keyboardKeyMap.Add(Key.UpArrow, Keys.Up);
|
||||
keyboardKeyMap.Add(Key.PageUp, Keys.PageUp);
|
||||
keyboardKeyMap.Add(Key.Left, Keys.Left);
|
||||
keyboardKeyMap.Add(Key.Right, Keys.Right);
|
||||
keyboardKeyMap.Add(Key.End, Keys.End);
|
||||
keyboardKeyMap.Add(Key.Down, Keys.Down);
|
||||
keyboardKeyMap.Add(Key.PageDown, Keys.PageDown);
|
||||
keyboardKeyMap.Add(Key.Insert, Keys.Insert);
|
||||
keyboardKeyMap.Add(Key.Delete, Keys.Delete);
|
||||
keyboardKeyMap.Add(Key.LeftWindowsKey, Keys.LeftWindows);
|
||||
keyboardKeyMap.Add(Key.RightWindowsKey, Keys.RightWindows);
|
||||
keyboardKeyMap.Add(Key.Applications, Keys.Apps);
|
||||
keyboardKeyMap.Add(Key.Sleep, Keys.Sleep);
|
||||
keyboardKeyMap.Add(Key.WebSearch, Keys.BrowserSearch);
|
||||
keyboardKeyMap.Add(Key.WebFavorites, Keys.BrowserFavorites);
|
||||
keyboardKeyMap.Add(Key.WebRefresh, Keys.BrowserRefresh);
|
||||
keyboardKeyMap.Add(Key.WebStop, Keys.BrowserStop);
|
||||
keyboardKeyMap.Add(Key.WebForward, Keys.BrowserForward);
|
||||
keyboardKeyMap.Add(Key.WebBack, Keys.BrowserBack);
|
||||
keyboardKeyMap.Add(Key.Mail, Keys.LaunchMail);
|
||||
keyboardKeyMap.Add(Key.MediaSelect, Keys.SelectMedia);
|
||||
keyboardKeyMap.Add(Key.Slash, Keys.OemMinus);
|
||||
|
||||
KeyboardState ks = new KeyboardState(keys);
|
||||
// TODO
|
||||
keyboardKeyMap.Add(Key.AbntC1, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Yen, Keys.None);
|
||||
keyboardKeyMap.Add(Key.AbntC2, Keys.None);
|
||||
keyboardKeyMap.Add(Key.NumberPadEquals, Keys.None);
|
||||
keyboardKeyMap.Add(Key.AT, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Colon, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Underline, Keys.None);
|
||||
keyboardKeyMap.Add(Key.AX, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Unlabeled, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Calculator, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Power, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Wake, Keys.None);
|
||||
keyboardKeyMap.Add(Key.MyComputer, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Equals, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Apostrophe, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Grave, Keys.None);
|
||||
keyboardKeyMap.Add(Key.Oem102, Keys.None);
|
||||
|
||||
return ks;
|
||||
}
|
||||
// Xna keys not mapped:
|
||||
// Select
|
||||
// Print
|
||||
// Execute
|
||||
// Help
|
||||
// Separator
|
||||
// F16
|
||||
// F17
|
||||
// F18
|
||||
// F19
|
||||
// F20
|
||||
// F21
|
||||
// F22
|
||||
// F23
|
||||
// F24
|
||||
// LaunchApplication1
|
||||
// LaunchApplication2
|
||||
// OemPlus
|
||||
// OemQuestion
|
||||
// OemTilde
|
||||
// ChatPadGreen
|
||||
// ChatPadOrange
|
||||
// OemPipe
|
||||
// OemQuotes
|
||||
// Oem8
|
||||
// ProcessKey
|
||||
// OemCopy
|
||||
// OemAuto
|
||||
// OemEnlW
|
||||
// Attn
|
||||
// Crsel
|
||||
// Exsel
|
||||
// EraseEof
|
||||
// Play
|
||||
// Zoom
|
||||
// Pa1
|
||||
// OemClear
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static Buttons Translate(SharpDX.XInput.GamepadButtonFlags buttons)
|
||||
{
|
||||
Buttons tb = 0;
|
||||
#region Translate (Key)
|
||||
public static Keys Translate(Key key)
|
||||
{
|
||||
return keyboardKeyMap.ContainsKey(key) ? keyboardKeyMap[key] : Keys.None;
|
||||
}
|
||||
#endregion
|
||||
|
||||
tb |= (buttons & GamepadButtonFlags.A) == GamepadButtonFlags.A ? Buttons.A : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.B) == GamepadButtonFlags.B ? Buttons.B : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.Back) == GamepadButtonFlags.Back ? Buttons.Back : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.DPadDown ? Buttons.DPadDown : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.DPadLeft ? Buttons.DPadLeft : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.DPadRight ? Buttons.DPadRight : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.DPadUp ? Buttons.DPadUp : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.LeftShoulder ? Buttons.LeftShoulder : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.LeftThumb) == GamepadButtonFlags.LeftThumb ? Buttons.LeftTrigger : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.RightShoulder ? Buttons.RightShoulder : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.RightThumb) == GamepadButtonFlags.RightThumb ? Buttons.RightTrigger : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.Start) == GamepadButtonFlags.Start ? Buttons.Start : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.X) == GamepadButtonFlags.X ? Buttons.X : 0;
|
||||
tb |= (buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.Y ? Buttons.Y : 0;
|
||||
#region Translate (KeyboardState)
|
||||
public static KeyboardState Translate(SharpDX.DirectInput.KeyboardState keyboardState)
|
||||
{
|
||||
int keyCount = keyboardState.PressedKeys.Count;
|
||||
Keys[] keys = new Keys[keyCount];
|
||||
|
||||
return tb;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
keys[i] = Translate(keyboardState.PressedKeys[i]);
|
||||
|
||||
return new KeyboardState(keys);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Translate (GamepadButtonFlags)
|
||||
public static Buttons Translate(SharpDX.XInput.GamepadButtonFlags buttons)
|
||||
{
|
||||
Buttons tb = 0;
|
||||
foreach(var key in gamePadButtonsMap.Keys)
|
||||
tb |= (buttons & key) == key ? gamePadButtonsMap[key] : 0;
|
||||
|
||||
return tb;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -120,13 +120,12 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
graphicsMode = new GraphicsMode(colorFormat, depth, stencil, presentationParameters.MultiSampleCount);
|
||||
|
||||
CreateWindowInfo(presentationParameters.DeviceWindowHandle, graphicsMode.Index.Value);
|
||||
|
||||
|
||||
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
|
||||
nativeContext.MakeCurrent(nativeWindowInfo);
|
||||
nativeContext.LoadAll();
|
||||
nativeContext.ErrorChecking = false;
|
||||
|
||||
GetOpenGLVersion();
|
||||
LogOpenGLInformation();
|
||||
|
||||
GL.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
|
||||
|
||||
@ -134,11 +133,15 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetOpenGLVersion
|
||||
private void GetOpenGLVersion()
|
||||
#region LogOpenGLInformation
|
||||
private void LogOpenGLInformation()
|
||||
{
|
||||
string version = GL.GetString(StringName.Version);
|
||||
Logger.Info("OpenGL version: " + version);
|
||||
string vendor = GL.GetString(StringName.Vendor);
|
||||
string renderer = GL.GetString(StringName.Renderer);
|
||||
string shadingLanguageVersion = GL.GetString(StringName.ShadingLanguageVersion);
|
||||
Logger.Info("OpenGL version: " + version + " (" + vendor + " - " + renderer + ")");
|
||||
Logger.Info("GLSL version: " + shadingLanguageVersion);
|
||||
string[] parts = version.Split(new char[] { '.', ' ' });
|
||||
cachedVersionMajor = int.Parse(parts[0]);
|
||||
cachedVersionMinor = int.Parse(parts[1]);
|
||||
@ -149,23 +152,13 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
private void CreateWindowInfo(IntPtr windowHandle, IntPtr graphicsModeHandle)
|
||||
{
|
||||
if (OpenTK.Configuration.RunningOnWindows)
|
||||
{
|
||||
nativeWindowInfo = Utilities.CreateWindowsWindowInfo(windowHandle);
|
||||
}
|
||||
else if (OpenTK.Configuration.RunningOnX11)
|
||||
{
|
||||
nativeWindowInfo = LinuxInterop.CreateX11WindowInfo(windowHandle,
|
||||
graphicsModeHandle);
|
||||
}
|
||||
nativeWindowInfo = LinuxInterop.CreateX11WindowInfo(windowHandle, graphicsModeHandle);
|
||||
else if (OpenTK.Configuration.RunningOnMacOS)
|
||||
{
|
||||
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(windowHandle,
|
||||
false, true);
|
||||
}
|
||||
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(windowHandle, false, true);
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
@ -8,6 +8,7 @@ using SharpDX.Direct3D11;
|
||||
using ANX.Framework.Graphics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ANX.Framework.NonXNA.RenderSystem;
|
||||
using System.IO;
|
||||
|
||||
#endregion // Using Statements
|
||||
|
||||
@ -68,38 +69,20 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
|
||||
//TODO: check offsetInBytes parameter for bounds etc.
|
||||
|
||||
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
IntPtr dataPointer = pinnedArray.AddrOfPinnedObject();
|
||||
SharpDX.DataStream stream;
|
||||
context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
|
||||
|
||||
int dataLength = Marshal.SizeOf(typeof(T)) * data.Length;
|
||||
if (offsetInBytes > 0)
|
||||
stream.Seek(offsetInBytes, SeekOrigin.Current);
|
||||
|
||||
unsafe
|
||||
{
|
||||
using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, true))
|
||||
{
|
||||
if (offsetInBytes > 0)
|
||||
{
|
||||
vData.Seek(offsetInBytes / (size == IndexElementSize.SixteenBits ? 2 : 4), System.IO.SeekOrigin.Begin);
|
||||
}
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
stream.Write<T>(data[i]);
|
||||
else
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
stream.Write<T>(data[i]);
|
||||
|
||||
SharpDX.DataStream stream;
|
||||
SharpDX.DataBox box = context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
{
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
{
|
||||
vData.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vData.CopyTo(stream);
|
||||
}
|
||||
context.UnmapSubresource(this.buffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
pinnedArray.Free();
|
||||
context.UnmapSubresource(this.buffer, 0);
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA.RenderSystem;
|
||||
using SharpDX.Direct3D11;
|
||||
@ -11,13 +12,21 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
public class VertexBuffer_DX11 : INativeVertexBuffer, IDisposable
|
||||
{
|
||||
SharpDX.Direct3D11.Buffer buffer;
|
||||
int vertexStride;
|
||||
|
||||
public SharpDX.Direct3D11.Buffer NativeBuffer
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
#region Constructor
|
||||
public VertexBuffer_DX11(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
{
|
||||
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
|
||||
SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null;
|
||||
SharpDX.Direct3D11.DeviceContext context = gd11 != null ?
|
||||
gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext :
|
||||
null;
|
||||
|
||||
InitializeBuffer(context.Device, vertexDeclaration, vertexCount, usage);
|
||||
}
|
||||
@ -27,7 +36,9 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
InitializeBuffer(device, vertexDeclaration, vertexCount, usage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region InitializeBuffer (TODO)
|
||||
private void InitializeBuffer(SharpDX.Direct3D11.Device device, VertexDeclaration vertexDeclaration, int vertexCount,
|
||||
BufferUsage usage)
|
||||
{
|
||||
@ -46,10 +57,12 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
OptionFlags = ResourceOptionFlags.None
|
||||
};
|
||||
|
||||
this.buffer = new SharpDX.Direct3D11.Buffer(device, description);
|
||||
NativeBuffer = new SharpDX.Direct3D11.Buffer(device, description);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetData (TODO)
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount)
|
||||
where T : struct
|
||||
{
|
||||
@ -59,23 +72,19 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
//TODO: check offsetInBytes parameter for bounds etc.
|
||||
|
||||
SharpDX.DataStream stream;
|
||||
context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
{
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
context.MapSubresource(NativeBuffer, MapMode.WriteDiscard, MapFlags.None, out stream);
|
||||
|
||||
context.UnmapSubresource(this.buffer, 0);
|
||||
if (offsetInBytes > 0)
|
||||
stream.Seek(offsetInBytes, SeekOrigin.Current);
|
||||
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
stream.Write<T>(data[i]);
|
||||
else
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
stream.Write<T>(data[i]);
|
||||
|
||||
context.UnmapSubresource(NativeBuffer, 0);
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
|
||||
@ -88,40 +97,30 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount);
|
||||
}
|
||||
|
||||
public SharpDX.Direct3D11.Buffer NativeBuffer
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount,
|
||||
int vertexStride) where T : struct
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.buffer != null)
|
||||
if (NativeBuffer != null)
|
||||
{
|
||||
buffer.Dispose();
|
||||
buffer = null;
|
||||
NativeBuffer.Dispose();
|
||||
NativeBuffer = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region INativeVertexBuffer Member
|
||||
|
||||
#region GetData (TODO)
|
||||
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region INativeBuffer Member
|
||||
|
||||
|
||||
public void GetData<T>(T[] data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@ -131,7 +130,6 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA.RenderSystem;
|
||||
using Dx11 = SharpDX.Direct3D11;
|
||||
using System.IO;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -81,20 +82,17 @@ namespace ANX.RenderSystem.Windows.Metro
|
||||
//TODO: check offsetInBytes parameter for bounds etc.
|
||||
|
||||
SharpDX.DataStream stream = device.MapSubresource(NativeBuffer);
|
||||
|
||||
if (offsetInBytes > 0)
|
||||
stream.Seek(offsetInBytes, SeekOrigin.Current);
|
||||
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
{
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
device.UnmapSubresource(NativeBuffer, 0);
|
||||
}
|
||||
#endregion
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA.RenderSystem;
|
||||
using Dx11 = SharpDX.Direct3D11;
|
||||
@ -89,20 +90,17 @@ namespace ANX.RenderSystem.Windows.Metro
|
||||
//TODO: check offsetInBytes parameter for bounds etc.
|
||||
|
||||
SharpDX.DataStream stream = device.MapSubresource(NativeBuffer);
|
||||
|
||||
if (offsetInBytes > 0)
|
||||
stream.Seek(offsetInBytes, SeekOrigin.Current);
|
||||
|
||||
if (startIndex > 0 || elementCount < data.Length)
|
||||
{
|
||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
stream.Write<T>(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
device.UnmapSubresource(NativeBuffer, 0);
|
||||
}
|
||||
#endregion
|
||||
|
@ -13,169 +13,168 @@ using ANX.Framework.Input;
|
||||
|
||||
namespace WindowsGame1
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Game1 : ANX.Framework.Game
|
||||
{
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Game1 : ANX.Framework.Game
|
||||
{
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
Texture2D texture;
|
||||
Texture2D alternateTexture;
|
||||
Texture2D texture;
|
||||
Texture2D alternateTexture;
|
||||
|
||||
Color[] color = new Color[] { Color.White, Color.Green, Color.Blue, Color.Black, Color.White, Color.DarkMagenta };
|
||||
float[] y = new float[] { 10f, 10f, 10f, 10f, 10f, 10f };
|
||||
Random r = new Random();
|
||||
Color[] color = new Color[] { Color.White, Color.Green, Color.Blue, Color.Black, Color.White, Color.DarkMagenta };
|
||||
float[] y = new float[] { 10f, 10f, 10f, 10f, 10f, 10f };
|
||||
Random r = new Random();
|
||||
|
||||
|
||||
private float elapsedLastSecond = 0f;
|
||||
private int fpsCount = 0;
|
||||
private int lastFps = 60;
|
||||
private float elapsedLastSecond = 0f;
|
||||
private int fpsCount = 0;
|
||||
private int lastFps = 60;
|
||||
|
||||
public Game1()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings;
|
||||
Content.RootDirectory = "SampleContent";
|
||||
}
|
||||
public Game1()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings;
|
||||
Content.RootDirectory = "SampleContent";
|
||||
}
|
||||
|
||||
void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
|
||||
{
|
||||
e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 800;
|
||||
e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = 600;
|
||||
}
|
||||
void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
|
||||
{
|
||||
e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 800;
|
||||
e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = 600;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
//this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotColor4x4");
|
||||
this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotWhiteTopLeft5x5");
|
||||
this.texture = Content.Load<Texture2D>(@"Textures/ANX.logo");
|
||||
|
||||
//this.alternateTexture = new Texture2D(GraphicsDevice, 64, 64);
|
||||
//Color[] color = new Color[this.alternateTexture.Width * this.alternateTexture.Height];
|
||||
//for (int i = 0; i < color.Length; i++)
|
||||
//{
|
||||
// color[i] = new Color(1.0f, 1.0f, 0, 0.5f);
|
||||
//}
|
||||
//this.alternateTexture.SetData<Color>(color);
|
||||
}
|
||||
//this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotColor4x4");
|
||||
this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotWhiteTopLeft5x5");
|
||||
this.texture = Content.Load<Texture2D>(@"Textures/ANX.logo");
|
||||
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
//this.alternateTexture = new Texture2D(GraphicsDevice, 64, 64);
|
||||
//Color[] color = new Color[this.alternateTexture.Width * this.alternateTexture.Height];
|
||||
//for (int i = 0; i < color.Length; i++)
|
||||
//{
|
||||
// color[i] = new Color(1.0f, 1.0f, 0, 0.5f);
|
||||
//}
|
||||
//this.alternateTexture.SetData<Color>(color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
elapsedLastSecond += (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
fpsCount++;
|
||||
if (elapsedLastSecond >= 1f)
|
||||
{
|
||||
elapsedLastSecond -= 1f;
|
||||
lastFps = fpsCount;
|
||||
fpsCount = 0;
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
|
||||
Window.Title = "FPS=" + lastFps;
|
||||
}
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
elapsedLastSecond += (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
fpsCount++;
|
||||
if (elapsedLastSecond >= 1f)
|
||||
{
|
||||
elapsedLastSecond -= 1f;
|
||||
lastFps = fpsCount;
|
||||
fpsCount = 0;
|
||||
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
Window.Title = "FPS=" + lastFps;
|
||||
}
|
||||
|
||||
for (int i = 0; i < y.Length; i++)
|
||||
{
|
||||
y[i] += this.r.Next(100) * (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
y[i] = MathHelper.Clamp(y[i], 0, 536);
|
||||
}
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
for (int i = 0; i < y.Length; i++)
|
||||
{
|
||||
y[i] += this.r.Next(100) * (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
y[i] = MathHelper.Clamp(y[i], 0, 536);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
|
||||
{ GraphicsDevice.Clear(Color.Green); }
|
||||
else
|
||||
{
|
||||
if (Mouse.GetState().XButton1 == ButtonState.Pressed)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Chocolate);
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mouse.GetState().XButton1 == ButtonState.Pressed)
|
||||
{
|
||||
GraphicsDevice.Clear(Color.Chocolate);
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.Space))
|
||||
{
|
||||
if (GraphicsDevice.PresentationParameters.BackBufferWidth != 420)
|
||||
{
|
||||
PresentationParameters newParams = GraphicsDevice.PresentationParameters.Clone();
|
||||
newParams.BackBufferWidth = 420;
|
||||
newParams.BackBufferHeight = 360;
|
||||
GraphicsDevice.Reset(newParams);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GraphicsDevice.PresentationParameters.BackBufferWidth != 800)
|
||||
{
|
||||
PresentationParameters newParams = GraphicsDevice.PresentationParameters.Clone();
|
||||
newParams.BackBufferWidth = 800;
|
||||
newParams.BackBufferHeight = 600;
|
||||
GraphicsDevice.Reset(newParams);
|
||||
}
|
||||
}
|
||||
|
||||
if (Keyboard.GetState().IsKeyDown(Keys.Space))
|
||||
{
|
||||
if (GraphicsDevice.PresentationParameters.BackBufferWidth != 420)
|
||||
{
|
||||
PresentationParameters newParams =
|
||||
GraphicsDevice.PresentationParameters.Clone();
|
||||
newParams.BackBufferWidth = 420;
|
||||
newParams.BackBufferHeight = 360;
|
||||
GraphicsDevice.Reset(newParams);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GraphicsDevice.PresentationParameters.BackBufferWidth != 800)
|
||||
{
|
||||
PresentationParameters newParams =
|
||||
GraphicsDevice.PresentationParameters.Clone();
|
||||
newParams.BackBufferWidth = 800;
|
||||
newParams.BackBufferHeight = 600;
|
||||
GraphicsDevice.Reset(newParams);
|
||||
}
|
||||
}
|
||||
spriteBatch.Begin();
|
||||
|
||||
spriteBatch.Begin();
|
||||
for (int x = 0; x < y.Length; x++)
|
||||
{
|
||||
spriteBatch.Draw(texture, new Vector2(x * texture.Width + 32, y[x]), new Rectangle(0, 0, 120, 60),
|
||||
color[x], 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
for (int x = 0; x < y.Length; x++)
|
||||
{
|
||||
spriteBatch.Draw(texture, new Vector2(x * texture.Width + 32, y[x]), new Rectangle(0, 0, 120, 60), color[x], 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
spriteBatch.Draw(alternateTexture, new Vector2(32, 32), Color.White);
|
||||
|
||||
spriteBatch.Draw(alternateTexture, new Vector2(32, 32), Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user