Iphone engine loop

Started by
2 comments, last by SuperRad 14 years, 7 months ago
Hello we are trying to make an iphone/pc compatible game engine, but we got a problem. We need to look for event in our game loop and the game loop stall the normal event messaging system (touchesBegan function). We know that we can in c++ look at the event queue at each loop iteration but i don't know how and it's worse, cause i need to find it for multi touch event. We were thinking at first that apple messaging system wont get stall by a loop but it seem that it does... I know that we could use a timer too, like many iphone app seem to do but for technical reason here (optimization and compatibility between iphone and PC ) some other guys on the project tell me that we can't do it this way. So my question, is it possible to look in the event queue for iphone multi touch event, if yes i would appreciate a pointer on how, if not ...... any clue ??? I can't release source now, cause it's still at planning phase(the code phase isn't even started), but it's an open source project so we will.....someday....
Advertisement
You really should be doing the minimum amount of work in the touchesBegan, touchesMoved and touchesEnd functions.
That is if you really want to do any significant processing on any touch events you should record them (to a list/structure/etc) when you receive them in any of the touches functions and then process them when you reach your input handling code in your main loop.

To handle multitouch its a case of querying the NSSet (usually called touches) that is passed in to each touches function.
eg
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    int touchcount = [touches count];    // single touch    if( touchcount == 1){      // store the single touchpoint      touchOnePoints.push([touches anyObject]);    } else if (touchcount > 1) {      // store more than one touch      touchOnePoints.push([[touches allObjects] objectAtIndex:0]);      touchOnePoints.push([[touches allObjects] objectAtIndex:1]);    }}


Of course you'll probably want to store that touches have began as well as where they began (and probably clear out the touch lists when a new touch begins)

I hope that helps
thanks but still got stuck in a way.... (maybe i cant see an easy solution because it's 6 in the morning here and i REALLY should get to sleep.....i will think about it tomorrow), but now, i can't see how the touchesBegan (or other touches function ) could get called if the program is stall in my game loop. But you lighten on a possible solution: am now trying to query the NSSet (or touches) IN my game loop. (Without using the touches began function).

Alternatively, am looking for a way not to stall the "automatically called" function when my game loop is running.

Don't know where to head, i have been used to timer game loop(calling a function) but the other members of the project wan't to avoid this method in the project. So am stuck with a WHILE game loop type wich stall the touches function >_<
Quote:Original post by twistedjoe
i can't see how the touchesBegan (or other touches function ) could get called if the program is stall in my game loop.

Its actually a callback and I believe it runs in its own thread (not so sure about the thread part).
You have to define the method as a part of the current UIView you are running in not as a part of your game class or any other class.

Quote:am now trying to query the NSSet (or touches) IN my game loop. (Without using the touches began function).

I don't think you can do that, as the touches variable doesn't exist outside of the touches functions as its only passed in when a touches event occurs.
The idea would be to create a list or object as a member of the current UIView and then when a touches function is called you will be able store the info contained in the touches parameter.

This topic is closed to new replies.

Advertisement