Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 08:43:07 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)(Digital) Device Component question
Pages: [1]
Print
Author Topic: (Digital) Device Component question  (Read 978 times)
SephirXV
Enjoying the stay
*
Offline Offline

Posts: 53


View Profile
« on: 10. October 2008, 06:36:17 pm »

AnalogDeviceComponent has methods to access the (what I assume is current) value of the component it represents, and in the doc it says DigitalDeviceComponent is limited to a boolean, but when I look at the source, DigitalDeviceComponent doesn't seem to do anything but extend DeviceComponent. Not only do I not see the point, but I feel a little slighted; I was hoping to use DeviceComponent to abstract away from where I care what device a button is on, just whether it's pushed or not.

Currently I have to determine the device to poll from by DeviceComponent.getClass, equals Key use Keyboard, equals MouseButton use Mouse, else it should have it's own InputState. Then I use the device specific method to retrieve the value, using the DeviceComponent as an index. It makes for long, ugly one-liners that are fragile in the face of API change. If nothing else, it would be nice for Key/MouseButton to implement a method from DigitalDeviceComponent which polls the appropriate device using the appropriate method and index, allowing my code to
just call DigitalDeviceComponent.getValue() and not care about the rest.

I will submit code suggestions later.
« Last Edit: 10. October 2008, 09:10:53 pm by SephirXV » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 11. October 2008, 03:58:39 am »

Hi SephirXV. Welcome to Xith3D Smiley.

The reason, why some of the devices can't have a getMyCurrentState() method or something like that, is that some of them are singletons. A Keyboard doesn't have its own unique KEy instances, but shares them with any other Keyboard instance. The same for the MouseButtons.

I have added an abstract getState() method to InputDevice. You can use it to abstractly read out the state of the given DeviceComponent. I hope, this helps you.

Marvin
Logged
SephirXV
Enjoying the stay
*
Offline Offline

Posts: 53


View Profile
« Reply #2 on: 11. October 2008, 08:14:30 pm »

Hmm. First, I'd like to say I appreciate your effort and your quickness for this. Unfortunately, it only solves half my issue. I wish I could have gotten back with my code I dreamed up, but today was my daughter's birthday.

I'd have worked this all out myself, but I just started using SVN (or any version control) yesterday, so I'm not entirely sure how to get checkouts and submissions and such to work with Eclipse, nor do I know if I even have permission, it never asked for a password so far.

Anyway, basically I had two issues before, given any DeviceComponent (let's just stick with Digital ones for now), I need to determine it's instanceof (Keyboard, Mouse, etc), and then based on which one, call a lookup method from that device. The changes you made solved the second one for my by making Keyboard/Mouse/etc each have a common lookup function, and on the mouse it actually helped allot because of all the different Components, but I still have to determine which device to call using if...instanceofs very similar to the ones you used to make sure it was a DC that Device knew how to handle. I guess I could just call all three and ignore the exceptions, knowing it would work on one of them, but that seems very hacked to me.

I also understand what  you're saying about the Singletons, but I don't think it affects my solution. We get a Key or a MouseSomething and know it came from one of those devices, but not which, and it is really unlikely that someone has multiple keyboards/mice plugged in, they've only got so many hands. And you don't want to store a boolean when you have a class doing that already, we want to have a chain or responsibility.

What I had in mind was this, and let me know if I don't know what I'm talking about, because it's a strong possibility. I want to go from a list of DigitalDeviceComponents and get their value and not worry if it's a key or button or what, because as long as it's boolean it really doesn't affect the game. But I don't really have DDC's, they're all extensions there of, they're Keys or MouseButtons or what have you. And they each, by virtue of knowing what they are, all know which device they should call and which method they should use, and which index they should pass. So if we make them all implement the same method, then I can call it and it will delegate the correct method for me. Best of all, there is no need to for the device to check anything. Polymorphism in action.

I know I'm not describing this very well, but the code is in my head, and I think it will make it clear.
Code:
//org.jagatoo.input.devices.components.DigitalDeviceComponent
public abstract boolean getBooleanValue();
public abstract InputState getState();

//org.jagatoo.input.devices.components.Key
public boolean getBooleanValue() {
   return Keyboard.isKeyPressed(this);
}

public InputState getState() {
   return Keyboard.getState(this);
}

//org.jagatoo.input.devices.components.MouseButton
public boolean getBooleanValue() {
   return Mouse.isButtonPressed(this);
}

public InputState getState() {
   return Mouse.getState(this);
}

//org.jagatoo.input.devices.components.ControllerButton
//already implements getBooleanValue as getBooleanState, just a rename to fit the get{Boolean|Float|Int}Value naming scheme
//already implements getState
Logged
SephirXV
Enjoying the stay
*
Offline Offline

Posts: 53


View Profile
« Reply #3 on: 11. October 2008, 08:53:50 pm »

In doing a little more digging, I think I finally understand the true issue. The system can handle multiple Keyboards & Mice, and
as Key & MouseButton are singletons they can't carry the state they represent nor the device they are part of, so they really just act as indexes with convienence functions.
I don't think my idea can be made to work without a wrapper class that has the Device and the Component as fields and provides the functions to perform the same lookups from the proper devices, or at least if it did work it would have to make a compile time assumption about which Keyboard and which Mouse to use (maybe it would make sense to assume the first, but there would be some poeple who wouldn't notice, but then how many need more then one keyboard/mouse?)
Perhaps the wrappers could extend Key|MouseButton and be called Demultiplexed{Key|MouseButton}, and only override getBooleanState & getState? The names indicate to me that using the regular 'Multiplexed' version of Key/MouseButton work fine but can't differntiate between multiple keyboards?

The only part I can't figure out is how to generate/retrieve them, and when (automatically, or on demand). I would have to yield to your experience in this area, but I should think that it wouldn't be hard to produce them on demand, seeing as they are are just two fields and one is a singleton. They could even be singletons themselves, there's only one of each key on a keyboard.

I havent' yet had the bravery to delve into the implementation specific input code, but I don't think any of what I'm proposing would need to be made at that level, it seems to me that it could all be done at the 'interface' level.

If it helps any, I'm trying to get all this worked out because I have a (what I think is) very well done driver in Java for the wiimote, and I've been meaning to build it to support/integrate with your input system. Right now it just does buttons, acceleration, and the IR camera, and it only works in Linux (If any Windows coders think they can make something to get the raw reports from a 'mote, I'd be interested in talking with you). My first tech demo (works) is just a skull that looks at where the IR camera's mouse is, but my next trick is to make it determine the distance from the monitor and appear to look directly at the 'mote itself.

Anyway, I'm sorry you went to that trouble and didn't do me much good. If you would, I'd rather you tell me where (and how) I'm right and wrong before commiting any more time to coding, I won't have time to do but browse the code until Tuesday. After I get familiar with Subclipse, I'll do my own coding if it's all right with you.

BTW, I appreciate you greeting me as a newb, my academic work was focused on programming, but I don't do much of it at work, so I sort of decided that the only way to stay in practice and build any sort of resume would be to get in on an open source project, and you guys have done such amazing bounds beyond what Java3D was doing.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 12. October 2008, 01:23:50 am »

I'm not sure, if I completely got you, But it's become late and I'm tired. So this might be the reason Smiley.

For now I will try to just throw some pointers into the room, that may help you to give me some more hints about what you actually need.

The InputSystem (which can be used as a singleto through the getInstance() method, and usually is) has methods getMouse(), getKeyboard() and getController(), that will return the first registered (and still registered) instance of the type. So these are already the instances, that you need, aren't they?

You wrapper class could then simply check for the type of the DDC and query the appropriate device coming from these methods.

The support for multiple Keyboards and Mice exists for two reasons:
1. (less common) The computer actually has more than one device of that type plugged in and thay need to be supported. This anyway works only with JInput and can generally be ignored.

2. (more common, but not too common) There is more than one InputSourceWindow (Canvas3D with its CanvasPeer in Xith3D). Each InputSourceWindow will have its own Keyboard and Mouse instance working, since this is the level, where events are polled/processed.

As for SVN dev access: Subclipse will forst ask for a username and password when you first do a commit. Each checkout can be (and is) done anonymously. If you want dev access, I would need you sourceforge accout name, so that I can grant you dev access (send it by PM).

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 12. October 2008, 01:38:40 am »

Just another idea: Maybe what you want is already implemented. How about using an InputHandler with its attached InputBindingsManager and InputStatesManager and some InputActions. The you would bind certain DeviceComponents to InputActions and you would not need to know at all, which device component triggered the action. Please have a look at the testcases in xith-tk in org.xith3d.test.input (CustomInputActionTest and CustomInputHandlerTest). Actually I'm pretty sure, that this is what you want.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic