Input Mapping

May 1, 2011 at 5:07 AM

Hi Guys (and Girls)

I wasn't liking it how at present the Engine makes assumptions about which keys / mouse clicks etc are used for specific actions (use left tool is Left Mouse Button etc).

Soo..  If the following sounds like something of use to you, then I would love to contribute it to the project.

Basically, I have created InputMapping functionaltiy within the Engine, so that rather than getting the Mouse, Keyboard, Gamepad state, and explicitly trying to detect if a particular button / key mouse button is pressed or is down, (like you do at the moment for tool usage or debug keys or whatever) Instead you would go through a new InputMapper class to ask if a particular action (An Enumerated Value) is Down or Pressed.

This does mean the enums have to be created to represent the actions, i.e:-

 

public enum ToolAction: byte
{
UseLeft,
UseRight
} 

 

And also the initial mapping has to be explicitly set, however in future I would like to add persistence methods to check for a default mapping on disk and load it if it exists.

            inputState = new InputState<DebugActions>();
            //TODO: Add peristence methods to Load() existing mappings
            // Just creating a default Map to use. Need to add Persistence methods, to be able to Save / Load maps.
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.Exit, Keys.Escape);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.FreeCam, Keys.F1);
            inputState.Mapping.SetMappedValue<MouseButtons>(DebugActions.ToggleFullScreen, MouseButtons.MiddleButton);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.FixedTimeStepPlusVSync, Keys.F3);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.DayMode, Keys.F9);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.NightMode, Keys.F10);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.ToggleRasterMode, Keys.F4);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.DiagnosticMode, Keys.F8);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.ReleaseMouse, Keys.F);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.ShowMinimap, Keys.M);
            inputState.Mapping.SetMappedValue<Keys>(DebugActions.StealthMode, Keys.S);

I would also like to look at putting together a UI for the user to Create / Edit / Load / Save Mappings - so the benefits of having a mapping can actually be realised.

Is this of interest to you?

May 1, 2011 at 5:12 AM
Edited May 1, 2011 at 5:14 AM

Oh, and if you are interested, it may be easier if I can send you the source some how as I don't have source control set up with Codeproject :(

May 1, 2011 at 3:12 PM

Interesting.

My 2 cents :

- dont bother with a UI , just use a .ini file

- try making it text based, the string "MouseButons.MiddleButton" being able to infer the MouseButtons type ( with reflection).

You can always send patches or samples at enomi dot enomi at g mail dot com.

PS : there are inputstate management frameworks and libraries , its on my todo  to check them, like the one in nuclex framework.

May 1, 2011 at 4:11 PM

Thanks Enomi,

Dagnammit! I thought there must be some frameworks out there for Input / Input mapping somewhere! My first googling session didn't give me any results though, so I thought how hard can it be right?

I will take a look at the Nuclex stuff, see how they have done it, and I won't bother with a UI (thanks for that advice).

What would the reasons be for making it text based though - i.e "MouseButons.MiddleButton" -  I did consider this, but I don't want to let intellisense (and compile time checking) go if I can help it so that's why I made strong use of generics. 

Thank you :)

 

 

 

May 1, 2011 at 5:21 PM

Because you will need to parse it from the ini file as text anyways. To have the possibility to use a muse btn or keyboard indifferently

On 2011-05-01 11:11 AM, "darrelltunnell" <notifications@codeplex.com> wrote:
>
> From: darrelltunnell
>
> Thanks Enomi,
>
> Dagnammit! I thought there must be some frameworks out there for Input / Input mapping somewhere! My first googling session didn't give me any results though, so I thought how hard can it be right?
>
> I will take a look at the Nuclex stuff, see how they have done it, and I won't bother with a UI (thanks for that advice).
>
> What would the reasons be for making it text based though - i.e "MouseButons.MiddleButton" - I did consider this, but I don't want to let intellisense (and compile time checking) go if I can help it so that's why I made strong use of generics.
>
> Thank you :)
>
>
>
>
>
>
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email (TechCraft@discussions.codeplex.com)
>
> To start a new discussion for this project, email TechCraft@discussions.codeplex.com
>
> You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

May 1, 2011 at 7:18 PM

Ah true. I have a few ideas there though.

Once it's done I'll email you a sample project and then maybe you can review it along side the other frameworks when you reach that stage of your to-do list! :)

Kind Regards

Darrell

May 1, 2011 at 7:29 PM

Ok SCRAP THAT the nuclex stuff looks way more advanced. Think I'll wait to see what you guys implement and then just go with that.

:'(