Using SharpInputSystem with Axiom
From Axiom
Contents |
Step 1 - Introduction
This tutorial will show you how to set up Axiom to run with an alternate input system called SharpInputSystem. This tutorial will start from a blank Axiom setup. To be able to successfully complete this tutorial, you will need to be able to complete Basic Tutorial 1.
You should start this tutorial with the following files:
- Application.cs - The base of your Axiom engine
- ExampleGame.cs - The overriden class for your Axiom engine
- Program.cs - The main entry point to your game
I will be using Visual Studio C# Express 2005 for this tutorial, however you can copy the operations in any C# IDE. Refer to your IDE's help for more instructions.
Step 2 - Getting the SharpInputSystem (SIS)
The official site for the SIS is http://www.codeplex.com/SharpInputSystem. This tutorial deals with the Alpha 0.3 version of SIS and cannot guarantee to be correct for any other version.
The Alpha 0.3 version comes in two groups:
- SharpInputSystem-0.3-src.zip
- SharpInputSystem-0.3-bin.zip
You want to download the SharpInputSystem-0.3-bin.zip file and extract its contents. Copy the following files from the "<extracted folder>\bin\Release\DirectX" folder into your "<blank Axiom setup>\bin\Debug" folder:
- SharpInputSystem.dll
- log4net.dll
Updating Dependencies
On the Project menu, select "Add Reference..." As shown in the screenshot below, you need to add the two selected DLL: 'log4net.dll' and 'SharpInputSystem.dll'
Once you have have added these to your project, you can proceed to Step 3.
Step 3 - Integrating SIS with Axiom
This step integrates the SIS with Axiom through some easy additions of code. This is not a hard task, but keep attentive and don't miss steps.
The first thing we need to do is add another form to the project. To do this, select the Project menu and click the Add New Item. Make sure you have selected the "Windows Form" option. Name your form FormInput.cs and click Ok. We will not be using this form any more as it is just there for the SIS to be able to read the inputs.
Now, open up your Application.cs file. We will edit this file first.
Add the following line into the Namespace Declarations region:
using SIS = SharpInputSystem;
Add the following lines at the end of the Protected Fields region:
//SIS Variables protected SIS.InputManager inputManager; protected SIS.Keyboard inputKeyboard; protected SIS.Mouse inputMouse; protected EventHandler eventHandler = new EventHandler();
Add the following lines just before the line "ShowDebugOverlay(showDebugOverlay);" in the Setup() method
FormInput form = new FormInput(); inputManager = SIS.InputManager.CreateInputSystem(System.Windows.Forms.Control.FromHandle((IntPtr)window["WINDOW"])); inputKeyboard = inputManager.CreateInputObject<SIS.Keyboard>(true, ""); inputKeyboard.EventListener = eventHandler; inputMouse = inputManager.CreateInputObject<SIS.Mouse>(true, ""); inputMouse.EventListener = eventHandler; inputMouse.MouseState.Width = window.Width; inputMouse.MouseState.Height = window.Height;
Now, open your ExampleGame.cs file. We will be editing this file now.
In the method updateGUI() add the following:
inputKeyboard.Capture();
inputMouse.Capture();
int mousex = inputMouse.MouseState.X.Absolute;
int mousey = inputMouse.MouseState.Y.Absolute;
currentFPSLabel = OverlayElementManager.Instance.GetElement("Core/CurrentFPS");
if (currentFPSLabel != null)
{
currentFPSLabel.Text = string.Format("Current FPS: {0:#0} (mX={1},mY={2})", engine.CurrentFPS, mousex, mousey);
currentFPSLabel.Color = ColorEx.Goldenrod;
}
Step 4 - Extending SIS
Add a new Class to the project that is called "EventHandler.cs". This class will handle events raised by the SIS such as mouse, keyboard or joystick inputs.
Add the following code, making your final EventHandler.cs file look just like it:
using System;
using System.Collections.Generic;
using System.Text;
using SharpInputSystem;
using log4net;
namespace Axiom.Example
{
public class EventHandler : IKeyboardListener, IMouseListener, IJoystickListener
{
private bool appRunning = true;
public bool AppRunning
{
get { return appRunning; }
set { appRunning = value; }
}
#region IKeyboardListener Members
public bool KeyPressed(KeyEventArgs e)
{
// TODO: Whatever you want to do on a KeyPress
return true;
}
public bool KeyReleased(KeyEventArgs e)
{
// TODO: Whatever you want to do on a KeyRelease
return true;
}
#endregion
#region IMouseListener Members
public bool MouseMoved(MouseEventArgs arg)
{
// TODO: Whatever you want to do on a MouseMove
return true;
}
public bool MousePressed(MouseEventArgs arg, MouseButtonID id)
{
// TODO: Whatever you want to do on a MousePress
return true;
}
public bool MouseReleased(MouseEventArgs arg, MouseButtonID id)
{
// TODO: Whatever you want to do on a MouseRelease
return true;
}
#endregion
#region IJoystickListener Members
public bool ButtonPressed(JoystickEventArgs arg, int button)
{
// TODO: Whatever you want to do on a JoyPress
return true;
}
public bool ButtonReleased(JoystickEventArgs arg, int button)
{
// TODO: Whatever you want to do on a JoyRelease
return true;
}
public bool AxisMoved(JoystickEventArgs arg, int axis)
{
// TODO: Whatever you want to do on a JoyAxisMoved
return true;
}
public bool SliderMoved(JoystickEventArgs arg, int slider)
{
// TODO: Whatever you want to do on a SliderMove
return true;
}
public bool PovMoved(JoystickEventArgs arg, int pov)
{
// TODO: Whatever you want to do on a PovMove
return true;
}
#endregion IJoystickListener Members
}
}
Conclusion
Welcome to the conclusion! At this point you will have a compilable implementation of the SIS system for Axiom. If you have any questions regarding this, please visit the Axiom forums: http://axiomengine.sourceforge.net/forum


