I'm a little busy atm and thus cannot give you a full reply...I'm familiar with sdl and recalling having handeled input in a number of different manners. I'll share some when I get some time, haha.
Anyway, what jumped out was this:
And I could put that anywhere. Anyone know how this is done? How I could call something like getControllerClassPointer() and have it return the pointer to the initiated class?
It seems alot like you're describing a *dun dun dun* singleton! xD
I'm not exactly sure what you're asking here--I can interpret it two different ways. One way would imply that you're trying to pass objects to a controller class, in which case you'd probably want some kind of overloaded function that takes objects pointers as a parameter, then create an accessor in all of said objects that looks so:
Code: Select all
class Hector {
[ . . . ]
public:
Hector *get(void) { return this; }
[ . . . ]
}
Then, when you're browsing through all of your hectors via list or whatever, you can just call movementClass.shoudMove(hector_object.get());
Honestly, that looks like it'd get messy as hell, as you'd then have to force the controller to act upon every object that input should effect...So chances are good you meant this:
Create an object to represent a keyboard class. Keep an array of booleans to represent the keyboard within that class or poll events, whichever method you prefer...And have it where you can retrieve a pointer to this one said class anywhere else in your application. This, I'd think, would be the easiest method, as you can do:
Code: Select all
InputClass *input =InputClass::getInstance();
if(input->key[A] ) {
x++
}
Also, as marauder brought to my attention, you could rewrite the above code as
Code: Select all
if((InputClass::getInstance())->key[A] ) {
x++
}
As you can see, you can globally access a singleton, though it's not actually global. Incase you haven't used them before, it's simply an object that you can only have one instance of at a time, and have a static accessor method "getInstance" that you can access anywhere by using the scope operator(::) like other static members.
There's a huge, bitchy debate over weather the use of these are evil or not, so if you don't want to use because of 'bad OO design'...Your loss. ;p
Alternatively, I guess you could make the input class friends with everything else, but that'd be pretty gay...o.o;
Hope I helped, haha. Spend more time here than I planned, I gotta head out. I'll check back later. xD