NUGET-Changes:
+ Materials now have a method to draw. That should allow more freedom on how materials can have a effect on the resulting shader.

~ PostProcessEffect.Draw now needs a source ColorAttachment.
~ Added some missing summaries

GIT-/SOLUTION-Changes:
Remade the folder structure, to something more senseable.
This commit is contained in:
Michel Fedde 2021-05-14 21:38:50 +02:00
parent db7f01dca1
commit 89de4258e1
181 changed files with 584 additions and 698 deletions

View file

@ -0,0 +1,25 @@
<configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<!-- XQuartz compatibility (X11 on Mac) -->
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SM.Intergrations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SM.Intergrations")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4cb351f4-b3f2-4f77-acc2-02f21dbf5ec2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SM.Intergrations</RootNamespace>
<AssemblyName>SM.Intergrations</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.3.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="ShaderToolParser, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\ShaderToolParser.1.0.0-pre3\lib\net450\ShaderToolParser.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShaderTool\STMaterial.cs" />
<Compile Include="ShaderTool\STMaterialShader.cs" />
<Compile Include="ShaderTool\STPostProcessEffect.cs" />
<Compile Include="ShaderTool\STPostProcessShader.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\renderer\SM.Base\SM.Base.csproj">
<Project>{8e733844-4204-43e7-b3dc-3913cddabb0d}</Project>
<Name>SM.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\renderer\SM.OGL\SM.OGL.csproj">
<Project>{f604d684-bc1d-4819-88b5-8b5d03a17be0}</Project>
<Name>SM.OGL</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using OpenTK;
using OpenTK.Graphics;
using ShaderToolParser.Nodes;
using ShaderToolParser.Nodes.Textures;
using ShaderToolParser.Variables;
using SM.Base.Drawing;
using SM.Base.Textures;
using SM.Base.Window;
namespace SM.Intergrations.ShaderTool
{
public class STMaterial : Material
{
private Vector4 _tintVector = Vector4.One;
public override Color4 Tint
{
get => Color4.FromXyz(_tintVector);
set => _tintVector = Color4.ToXyz(value);
}
public STMaterial(STPDrawNode node)
{
if (node.OGLEffect == null)
throw new Exception("[ERROR AT IMPORTING MATERIAL] DrawNode didn't contain a OpenGL-shader.");
CustomShader = new STMaterialShader(node);
foreach (KeyValuePair<string, STPVariable> pair in node.Variables)
{
if (pair.Value.Type == STPBasisType.Texture)
ShaderArguments[pair.Key] = new Texture(((STPTextureNode) pair.Value.Texture).Bitmap);
}
}
public override void Draw(DrawContext context)
{
ShaderArguments["MVP"] = context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World;
ShaderArguments["MasterTextureMatrix"] = context.Instances[0].TextureMatrix * context.TextureMatrix;
ShaderArguments["HasVColor"] = context.Mesh.Attributes.Has("color");
ShaderArguments["_MATColor"] = _tintVector;
base.Draw(context);
}
}
}

View file

@ -0,0 +1,70 @@

using System;
using System.Collections.Generic;
using OpenTK;
using ShaderToolParser.Nodes;
using ShaderToolParser.Variables;
using SM.Base.Shaders;
using SM.Base.Textures;
using SM.Base.Window;
using SM.OGL.Shaders;
using SM.OGL.Texture;
namespace SM.Intergrations.ShaderTool
{
public class STMaterialShader : MaterialShader
{
private event Action<DrawContext> _uniforms;
public STMaterialShader(STPDrawNode drawNode) : base(new ShaderFileCollection())
{
if (drawNode.OGLEffect == null)
throw new Exception("[ERROR AT IMPORTING SHADER] DrawNode didn't contain a OpenGL-shader.");
STPCompositeNode composeNode = drawNode.OGLEffect;
ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
ShaderFileFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)};
if (composeNode.Geometry != null)
ShaderFileFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)};
foreach (KeyValuePair<string, STPVariable> pair in drawNode.Variables)
{
switch (pair.Value.Type)
{
case STPBasisType.Bool:
_uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, false));
break;
case STPBasisType.Float:
_uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, 0.0f));
break;
case STPBasisType.Vector2:
_uniforms += context => Uniforms[pair.Key].SetUniform2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero));
break;
case STPBasisType.Vector3:
_uniforms += context => Uniforms[pair.Key].SetUniform3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero));
break;
case STPBasisType.Vector4:
_uniforms += context =>
Uniforms[pair.Key].SetUniform4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero));
break;
case STPBasisType.Matrix:
_uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Material.ShaderArguments.Get(pair.Key, Matrix4.Identity));
break;
case STPBasisType.Texture:
_uniforms += context => Uniforms[pair.Key].SetTexture(context.Material.ShaderArguments.Get<TextureBase>(pair.Key, null));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
protected override void DrawProcess(DrawContext context)
{
_uniforms.Invoke(context);
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
}
}
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
using ShaderToolParser.Nodes;
using ShaderToolParser.Nodes.Textures;
using ShaderToolParser.Variables;
using SM.Base.Drawing;
using SM.Base.PostProcess;
using SM.Base.Textures;
using SM.Base.Window;
using SM.OGL.Framebuffer;
using SM.OGL.Texture;
namespace SM.Intergrations.ShaderTool
{
public class STPostProcessEffect : PostProcessEffect
{
private STPostProcessShader _shader;
public ShaderArguments Arguments;
public STPostProcessEffect(STPDrawNode postEffectNode)
{
Arguments = Arguments ?? new ShaderArguments();
if (postEffectNode.OGLEffect == null)
throw new Exception("[ERROR AT IMPORTING EFFECT] DrawNode didn't contain a OpenGL-shader.");
_shader = new STPostProcessShader(postEffectNode);
foreach (KeyValuePair<string, STPVariable> pair in postEffectNode.Variables)
{
if (pair.Value.Type == STPBasisType.Texture)
{
if (pair.Value.Texture == null) continue;
Arguments[pair.Key] = new Texture(((STPTextureNode)pair.Value.Texture).Bitmap);
}
}
}
public override void Draw(ColorAttachment source, DrawContext context)
{
Arguments["_Scene"] = (TextureBase)source;
Arguments["_MVP"] = Mvp;
Arguments["_ViewportSize"] = context.Window.WindowSize;
_shader.Draw(Arguments);
}
}
}

View file

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using ShaderToolParser.Nodes;
using ShaderToolParser.Variables;
using SM.Base.Drawing;
using SM.Base.Objects.Static;
using SM.Base.Textures;
using SM.OGL.Shaders;
using SM.OGL.Texture;
namespace SM.Intergrations.ShaderTool
{
public class STPostProcessShader : GenericShader
{
private event Action<ShaderArguments> _uniforms;
public STPostProcessShader(STPDrawNode postProcessNode) : base(new ShaderFileCollection())
{
if (postProcessNode.OGLEffect == null)
throw new Exception("[ERROR AT IMPORTING SHADER] DrawNode didn't contain a OpenGL-shader.");
STPCompositeNode composeNode = postProcessNode.OGLEffect;
ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
ShaderFileFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) };
if (composeNode.Geometry != null)
ShaderFileFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) };
foreach (KeyValuePair<string, STPVariable> pair in postProcessNode.Variables)
{
switch (pair.Value.Type)
{
case STPBasisType.Bool:
_uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, false));
break;
case STPBasisType.Float:
_uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, 0.0f));
break;
case STPBasisType.Vector2:
_uniforms += context => Uniforms[pair.Key].SetUniform2(context.Get(pair.Key, Vector2.Zero));
break;
case STPBasisType.Vector3:
_uniforms += context => Uniforms[pair.Key].SetUniform3(context.Get(pair.Key, Vector3.Zero));
break;
case STPBasisType.Vector4:
_uniforms += context =>
Uniforms[pair.Key].SetUniform4(context.Get(pair.Key, Vector4.Zero));
break;
case STPBasisType.Matrix:
_uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Get(pair.Key, Matrix4.Identity));
break;
case STPBasisType.Texture:
_uniforms += context => Uniforms[pair.Key].SetTexture(context.Get<TextureBase>(pair.Key, null));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
public void Draw(ShaderArguments arguments)
{
Activate();
Plate.Object.Activate();
_uniforms.Invoke(arguments);
GL.DrawArrays(PrimitiveType.Quads, 0, 4);
CleanUp();
}
}
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
<package id="ShaderToolParser" version="1.0.0-pre3" targetFramework="net452" />
</packages>

View file

@ -0,0 +1,39 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
{
public struct GameController
{
public static float GlobalDeadband = 2500;
private Controller _controller;
public float Deadband { get; set; }
public bool IsConnected => _controller.IsConnected;
public UserIndex Index { get; private set; }
public GameController(int id) : this((UserIndex)id)
{}
public GameController(UserIndex index = UserIndex.Any)
{
_controller = new Controller(index);
Index = index;
Deadband = GlobalDeadband;
}
public GameControllerState GetState()
{
if (!IsConnected)
{
return new GameControllerState(true);
}
Gamepad state = _controller.GetState().Gamepad;
return new GameControllerState(state, ref this);
}
}
}

View file

@ -0,0 +1,57 @@
using System;
using OpenTK;
using SharpDX.XInput;
namespace SM.Optionals.Controls
{
public struct GameControllerState
{
public GameControllerStateThumbs Thumbs;
public GameControllerStateTriggers Triggers;
public GameControllerStateDPad DPad;
public GameControllerStateButtons Buttons;
public bool FromConnected { get; }
internal GameControllerState(bool empty)
{
FromConnected = false;
Thumbs = GameControllerStateThumbs.Default;
Triggers = GameControllerStateTriggers.Default;
DPad = GameControllerStateDPad.Default;
Buttons = GameControllerStateButtons.Default;
}
internal GameControllerState(Gamepad state, ref GameController controller)
{
FromConnected = true;
Thumbs = new GameControllerStateThumbs
{
Left = new Vector2(
Math.Abs((float)state.LeftThumbX) < controller.Deadband ? 0 : (float)state.LeftThumbX / short.MaxValue,
Math.Abs((float)state.LeftThumbY) < controller.Deadband ? 0 : (float)state.LeftThumbY / short.MaxValue),
Right = new Vector2(
Math.Abs((float)state.RightThumbX) < controller.Deadband ? 0 : (float)state.RightThumbX / short.MaxValue,
Math.Abs((float)state.RightThumbY) < controller.Deadband ? 0 : (float)state.RightThumbY / short.MaxValue),
PressedLeft = state.Buttons.HasFlag(GamepadButtonFlags.LeftThumb),
PressedRight = state.Buttons.HasFlag(GamepadButtonFlags.RightThumb)
};
Triggers = new GameControllerStateTriggers()
{
Left = (float)state.LeftTrigger / byte.MaxValue,
Right = (float)state.RightTrigger / byte.MaxValue
};
DPad = new GameControllerStateDPad(state.Buttons);
Buttons = new GameControllerStateButtons(state.Buttons);
}
public override string ToString()
{
return !FromConnected ? "[From a disconnected controller]" : $"Thumbs: [{Thumbs}]; Trigger: [{Triggers}]; DPad: [{DPad}]; Buttons: [{Buttons}]";
}
}
}

View file

@ -0,0 +1,45 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
{
public struct GameControllerStateButtons
{
public static GameControllerStateButtons Default = new GameControllerStateButtons(GamepadButtonFlags.None);
private GamepadButtonFlags _buttonFlags;
public bool X;
public bool Y;
public bool A;
public bool B;
public bool LB;
public bool RB;
public bool LeftThumb;
public bool RightThumb;
public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags);
internal GameControllerStateButtons(GamepadButtonFlags flags)
{
_buttonFlags = flags;
X = flags.HasFlag(GamepadButtonFlags.X);
Y = flags.HasFlag(GamepadButtonFlags.Y);
A = flags.HasFlag(GamepadButtonFlags.A);
B = flags.HasFlag(GamepadButtonFlags.B);
LB = flags.HasFlag(GamepadButtonFlags.LeftShoulder);
RB = flags.HasFlag(GamepadButtonFlags.RightShoulder);
LeftThumb = flags.HasFlag(GamepadButtonFlags.LeftThumb);
RightThumb = flags.HasFlag(GamepadButtonFlags.RightThumb);
}
public override string ToString()
{
return $"X: {(X ? "1" : "0")}; Y: {(Y ? "1" : "0")}; A: {(A ? "1" : "0")}; B: {(B ? "1" : "0")}; LB: {(LB ? "1" : "0")}; RB: {(RB ? "1" : "0")}; LT: {(LeftThumb ? "1" : "0")}; RT: {(RightThumb ? "1" : "0")}";
}
}
}

View file

@ -0,0 +1,28 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
{
public struct GameControllerStateDPad
{
public static GameControllerStateDPad Default = new GameControllerStateDPad(GamepadButtonFlags.None);
public bool Up;
public bool Down;
public bool Left;
public bool Right;
internal GameControllerStateDPad(GamepadButtonFlags flags)
{
Up = flags.HasFlag(GamepadButtonFlags.DPadUp);
Down = flags.HasFlag(GamepadButtonFlags.DPadDown);
Left = flags.HasFlag(GamepadButtonFlags.DPadLeft);
Right = flags.HasFlag(GamepadButtonFlags.DPadRight);
}
public override string ToString()
{
return
$"Up: {(Up ? "1" : "0")}; Down: {(Down ? "1" : "0")}; Left: {(Left ? "1" : "0")}; Right: {(Right ? "1" : "0")};";
}
}
}

View file

@ -0,0 +1,21 @@
using OpenTK;
namespace SM.Optionals.Controls
{
public struct GameControllerStateThumbs
{
public static GameControllerStateThumbs Default = new GameControllerStateThumbs()
{Left = Vector2.Zero, Right = Vector2.Zero};
public Vector2 Left;
public Vector2 Right;
public bool PressedLeft;
public bool PressedRight;
public override string ToString()
{
return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}";
}
}
}

View file

@ -0,0 +1,14 @@
namespace SM.Optionals.Controls
{
public struct GameControllerStateTriggers
{
public static GameControllerStateTriggers Default = new GameControllerStateTriggers {Left = 0f, Right = 0f};
public float Left;
public float Right;
public override string ToString()
{
return $"Left: {Left}; Right: {Right}";
}
}
}

View file

@ -0,0 +1,29 @@
using System;
namespace SM.Optionals.Controls
{
public class GameKeybind
{
public Func<GameKeybindContext, object> Keyboard;
public Func<GameKeybindContext, object> Controller;
public Func<GameKeybindContext, object> AI;
public Func<GameKeybindContext, object> this[GameKeybindActorType type]
{
get
{
switch (type)
{
case GameKeybindActorType.AI:
return AI;
case GameKeybindActorType.Keyboard:
return Keyboard;
case GameKeybindActorType.Controller:
return Controller;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
}
}
}

View file

@ -0,0 +1,88 @@
using OpenTK.Input;
namespace SM.Optionals.Controls
{
public enum GameKeybindActorType
{
AI,
Keyboard,
Controller
}
public struct GameKeybindActor
{
private GameKeybindActorType _type;
private GameController? _controller;
private GameKeybindHost _keybindHost;
public GameKeybindActorType Type => _type;
public GameController? Controller => _controller;
public object[] Parameter;
private GameKeybindActor(GameKeybindActorType type, GameController? controller)
{
_type = type;
_controller = controller;
_keybindHost = null;
Parameter = new object[0];
}
public void ConnectHost(GameKeybindHost host)
{
_keybindHost = host;
}
public ReturnType Get<ReturnType>(string name, params object[] param)
{
return (ReturnType) Get(name, param);
}
public object Get(string name, params object[] objects)
{
if (_keybindHost == null) return null;
if (!_keybindHost._actions.ContainsKey(name)) return null;
GameKeybind keybind = _keybindHost._actions[name];
GameKeybindContext context = new GameKeybindContext()
{
Actor = this,
Host = _keybindHost,
ActorParameter = Parameter,
InstanceParameter = objects,
KeyboardState = Keyboard.GetState(),
MouseState = Mouse.GetState(),
ControllerState = Controller?.GetState(),
};
return keybind[Type].Invoke(context);
}
public static GameKeybindActor CreateAIActor()
{
return new GameKeybindActor(GameKeybindActorType.AI, null);
}
public static GameKeybindActor CreateKeyboardActor()
{
return new GameKeybindActor(GameKeybindActorType.Keyboard, null);
}
public static GameKeybindActor CreateControllerActor(int id)
{
return CreateControllerActor(new GameController(id));
}
public static GameKeybindActor CreateControllerActor(GameController controller)
{
return new GameKeybindActor(GameKeybindActorType.Controller, controller);
}
}
}

View file

@ -0,0 +1,17 @@
using OpenTK.Input;
namespace SM.Optionals.Controls
{
public struct GameKeybindContext
{
public KeyboardState KeyboardState;
public MouseState MouseState;
public GameControllerState? ControllerState;
public GameKeybindActor Actor;
public GameKeybindHost Host;
public object[] InstanceParameter;
public object[] ActorParameter;
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
namespace SM.Optionals.Controls
{
public class GameKeybindHost
{
internal Dictionary<string, GameKeybind> _actions = new Dictionary<string, GameKeybind>();
public GameKeybindHost()
{ }
public GameKeybindHost(GameKeybindList setup)
{
for (int i = 0; i < setup.Count; i++)
{
_actions[setup[i].Key] = setup[i].Value;
}
}
public void Setup(string name, Func<GameKeybindContext, object> keyboard = null, Func<GameKeybindContext, object> gameController = null, Func<GameKeybindContext, object> ai = null)
{
GameKeybind bind;
if (_actions.ContainsKey(name))
{
bind = _actions[name];
}
else
{
bind = new GameKeybind();
_actions.Add(name, bind);
}
bind.Keyboard = keyboard;
bind.Controller = gameController;
bind.AI = ai;
}
}
}

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
namespace SM.Optionals.Controls
{
public class GameKeybindList : List<KeyValuePair<string, GameKeybind>>
{
public void Add(string name, GameKeybind keybind)
{
Add(new KeyValuePair<string, GameKeybind>(name, keybind));
}
public void Add(string name, Func<GameKeybindContext, object> keyboard = null,
Func<GameKeybindContext, object> controller = null)
{
Add(new KeyValuePair<string, GameKeybind>(name, new GameKeybind()
{
AI = null,
Controller = controller,
Keyboard = keyboard
}));
}
}
}

View file

@ -0,0 +1,25 @@
<configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<!-- XQuartz compatibility (X11 on Mac) -->
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>

View file

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SM.Game")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SM.Game")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("079bab31-3dc4-40da-90c7-efaa8517c647")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{079BAB31-3DC4-40DA-90C7-EFAA8517C647}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SM.Utils</RootNamespace>
<AssemblyName>SM.Utils</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.3.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.XInput, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\GameController.cs" />
<Compile Include="Controls\GameControllerState.cs" />
<Compile Include="Controls\GameControllerStateButtons.cs" />
<Compile Include="Controls\GameControllerStateDPad.cs" />
<Compile Include="Controls\GameControllerStateThumbs.cs" />
<Compile Include="Controls\GameControllerStateTriggers.cs" />
<Compile Include="Controls\GameKeybind.cs" />
<Compile Include="Controls\GameKeybindActor.cs" />
<Compile Include="Controls\GameKeybindContext.cs" />
<Compile Include="Controls\GameKeybindHost.cs" />
<Compile Include="Controls\GameKeybindList.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
</packages>