GameControls Feature?

I've been working on a feature for my game that I've mentioned a couple times already, but I'm to the point in development where I need to decide if it's going into jME or straight into my game development utilities API.  The feature works like this:



1.) There is a GameControl object that can be instantiated and contains a String representing the name of the binding (ex. "Jump") and a Binding object.

2.) The Binding object represents a KeyboardKey, MouseButton, MouseAxis, JoystickButton, or JoystickAxis.

3.) There is a createConfigurationPanel() static method on GameControl that takes a list of GameControls and returns a JPanel that can be displayed in a JMESwing JInternalFrame that shows current key assignments as well as being able to click the current binding and it will popup a window asking for you to press the key/button/axis that you want to assign that named binding to.



I'm still doing a lot of work on it to make it fully customizable, but wasn't sure if this is something that would benefit jME directly or if it should be an extra released apart from jME?

I guess we can decide that when we see it? We already got a bunch of swing panels, though those are more focused on game tool design than the actual game. Maybe we could have something like this for game settings too.

That's going to actually be in the works as soon as this aspect is done. :stuck_out_tongue:

darkfrog said:

3.) There is a createConfigurationPanel() static method on GameControl that takes a list of GameControls and returns a JPanel that can be displayed in a JMESwing JInternalFrame that shows current key assignments as well as being able to click the current binding and it will popup a window asking for you to press the key/button/axis that you want to assign that named binding to.

Creating dependencies between control code and Swing (graphics code) doesn't sound like a good idea too me. How about using the MVC pattern and creating object hierarchies for the model (different storage engines, eg.g. ini files, relational databases) and the view (different GUI types, e.g. BUI, NUI, Swing, home-cooked). The GameControl would of course be the controller.

Gaheris,



That's simply a utility method, entirely optional.  However, I have been considering putting it in another class entirely anyway as I will likely need a similar method for use with the GameSettings as well.



GameControl can be used entirely without this as it's just another method of storing control settings for your game.

I would really like to have something like this at least in the tests, to show people how it could be done. Maybe not everyone will use a swing dialog for it. But I'm also fine with putting it in some package below the awt package.



And I would favour instantiating a dialog/manager class instead of calling a static method…

Well, I got a lot of work done on this last night, but didn't have enough time to get it completed.  I'll try to get it finished tonight.  I may have gone overboard on this a bit though.  I made it so a binding has a getValue() that returns a float that is a positive value from 0.0f to 1.0f (or potentially higher if it's a mouse axis).  However, I designed it so an axis that has positive and negative values actually is two bindings.  This allows you to do cool things like set throttle up to acceleration and throttle back to brakes, or something crazy like firing. :-p



Anyway, I'll get it checked in hopefully tonight and you can see what I've come up with.  I think I'm going to add a setting in GameSettings for mouse sensitivity, anyone have any thoughts about that?

@darkfrog

Sounds promising and exactly like the thing I will eventually need for my current game.

This seems useful. Out of curiosity, can one control be accessed several ways? In my game, I'd like for the same actions to be accomplished several different ways based on control. For instance, moving forward should happen both upon pressing the up arrow and using the joystick. Can I create a single forward control and give it several ways of being accessed?

Ugh…no, I didn't.  Sounds like I have some refactoring to do. :o



Okay, so I currently have a GameControl that has a getBinding() that returns an implementation of the Binding interface.  I'll change it List<Binding> getBindings() and have addBinding instead of setBinding.  Also, I'll change GameControl to have getValue() that will cycle through all the bindings and returning the highest value from their getValue() methods.



Does that sound sufficient?  Now that you've changed my requirements is there anything else?  :stuck_out_tongue:

Yes, while you're at it, can it make me coffee? Maybe a binding that interfaces with my coffee maker? :slight_smile:



In all seriousness, thanks a bunch. I'm not terribly familiar with the bindings API, and am using a simple input handler with hard-coded commands. Just seemed to me like such a facility could support multiple input methods rather easily, so I suggested it, especially as it's something I'd likely need when I add gamepad support later. :slight_smile:

I'm just giving you a hard time.  Now is a much easier time to add the functionality than later.  It was a good idea that I overlooked.  Thanks for the insight.

Okay guys, just made a massive update to the jME repository.  I started out too timid with my checkins but perhaps I've gotten too bold, but here it is anyway.  Here is a copy of my CVS commit entry:


  • Updated BasicGameState with getRootNode()
  • Renamed TestGameState to DebugGameState
  • Renamed TestTestGameState to TestDebugGameState
  • Created JMEDesktopState for a convenient way of utilizing a JMEDesktop within a scene and providing a simple way of removing it.
  • JMEDesktop takes the entire screen width and height and is ortho mode
  • Provides its own input and getDesktop() and getInputHandler()
  • Added contructor StandardGame(String name) that defaults to GRAPHICAL
  • New Controls Features
  • The controls feature is not completed, but this is a first phase implementation that may be usable but still lacks a great deal of functionality.
  • Binding interface representing a single key binding (keyboard, mouse, or joystick)
  • Binding implementations:
  • JoystickAxisBinding
  • JoystickButtonBinding
  • KeyboardBinding
  • MouseAxisBinding
  • MouseButtonBinding
  • GameControl represents a named "control" that can have multiple Bindings associated with it
  • Created TestSwingControlEditor as an example using the GameControl JPanel creator method
  • Created TestJMEDesktopState to show a working usage of JMEDesktopState



    Quite a bit of stuff there and there will probably be a lot more coming throughout the weekend as I find time to tweak all of this and get the functionality to where I want it.



    I don't know where I should separate out a graphical class for representing the bindings, any ideas anyone?  I'm not sure what package it would fit in.  For now I just left it as a static method in the GameControl class, but I want to split it out and put it somewhere that will also contain a similar feature for GameSettings.  I hope to be able to use this functionality to be able to modify settings and controls inside the game as well as outside the game via a startup JFrame if necessary.



    Let me know if you find any bugs in this - apart from the lacking features which I am still working on, but since I'm going to bed soon I wanted to check it in so I could get some feedback.

Okay, I believe I've got all the bugs resolved and even split out the graphical panel into its own class in its own package:

com.jmex.editors.swing.ControlConfigurationPanel



It can be added just like any Swing component.  It has support now for multiple bindings for a single GameControl, it now prompts you if you have a duplicate binding and if you say okay it will remove it from its current place and put it in the new location, better binding organization, and a very pretty little test:



jmetest.input.controls.TestSwingControlEditor



It displays two fields for some example controls and when you hit the close button a list is printed to the console of the configuration you set and then exits.



Let me know how you like this, if you find any bugs, and if you have any feature requests for it.  I will hopefully find the time to get a similar editor for GameSettings done as well today, but that should be significantly easier than this.

With me jmetest.input.controls.TestSwingControlEditor is almost unuseable because even the slightest movement of the mouse acts as a binding.

Yeah, I was thinking of creating a threshold, but hadn't decided.  Perhaps I should also allow an option to be specified on the panel whether mouse movement should be allowed?

Okay, I modified it so it has a threshold now and I also fixed a minor bug in it with re-assigning a key.

Ok, I do have another feature request. Hopefully this one isn't as drastic as my last. :stuck_out_tongue: Can this support keyboard modifiers?



Thanks.

I think it should support using keys as a modifier (but this is supported in the input system of jME, so I assume you can use it like that).



Not setting keys with modifiers… which… well… I've never seen that before. How would it be useful? I think it'd be confusing…

It'd be useful for, say, assigning shift-left arrow to a strafe left action, ctrl-right arrow to an action that turns to the nearest right angle compass direction, etc.