Okay, I just posted the new code on the wiki. I still need to add some comments...
The original purpose of the snippet was to take advantage of the Cocoa <UIKit> framework as a means to get multi-touch input into your C++ code ... which it did, but only just. I've had a lot more experience in iOS since posting it. For one, I discovered gesture recognizers. The gesture recognizers (GRs) do a lot of the heavy lifting for you. No need to track touches to figure out where a touch started, where it's moved, how fast it's moving, and in which direction. The pan GR is especially good for that. It works much like a MouseDrag event. As the touch slides across the screen, the pan GR sends a translation and a velocity vector (as well as the starting point). The tap and pinch GRs are equally friendly as well as long-press. The first three cover the needs of most games.
So, how does it work?
First, notice that there is a singleton named iOS_UIManager. It's purpose is to provide an interface for manipulating UIKit UI stuff. Here, it has only one view controller to manage, iOS_InputVC. iOS_InputVC is a UIViewController responsible for setting up the gesture recognizers and dispatching GRs actions to the C++ side. This happens by way of the InputVCDelegate protocol. The input view controller is provided with weak reference to an iOS_InputImpl object (which conforms to the protocol). iOS_InputVC handles any GR actions (ObjC for event) by grabbing whatever info it can from the GR before passing it through the respective protocol (here, always an instance of iOS_InputImpl). From there, it finally passes over the C++ in a call to one of the _notify***WasRecognized methods. The last class in the wiki snippet is a concrete State (from the Advanced Ogre Framework tutorial) which also
privately implements InputPimpl. MyStateWithGestureSupport can then do whatever it wants with the data it received ... including passing something back through to the iOS side (perhaps to change which gesture should be detected).
... and how do I implement it?
Well, if your project is based of the Advanced Ogre Framework, you can pretty much copy/paste everything over. However, it may be better to create a "Listener" class that implement InputImpl (rather than having the state implement it). Then make the listener a member of the state ... or of whichever class needs the input data.
Oh, and you have to add two lines to AppDelegate.h.
Code: Select all
// Near the top; after #import <UIKit/UIKit.h>
#import "iOS_UIManager.h"
// ...
- (void) go
{
// Make this the first line in this method.
[iOS_UIManager getInstance];
// ...
}
Hope that helps,
~aleroy~
{PS: sorry it took so long to get this up... I had to ween myself off Skyrim (glad I was finally able to play it).}