开发者

How can I fix 'sticky' touchesMoved in my openGLES app?

开发者 https://www.devze.com 2022-12-08 13:03 出处:网络
I have my openGL scene rendering using the detach thread method //This is at the end of my init method

I have my openGL scene rendering using the detach thread method

//This is at the end of my init method
 SEL selector = @selector(preMainLoop);
 NSThread *thread = [[NSThread alloc] initWithTarget:self selector:selector object:nil];
 [thread start];
 [thread release];
}

-(void) preMainLoop
{
 while (isRunning) {

  NSAutoreleasePool *loopPool = [NSAutoreleasePool new];

  [self performSelectorOnMainThread:@selector(mainLoop) withObject:nil waitUntilDone:YES];

  [loopPool release];
 }
}

When I start getting touch events, I want to update my scene accordingly. But it seems like the scene is updating much faster than the iPhone is registering the touch events. For testing I'm trying to just drag a box around the screen based on the current position of a UITouch (updating the position during touchesMoved). I also have another box that moves independently, unaffected by touches.

The indepent box moves around smoothly, at a nice 60 frames per开发者_如何转开发 second. The touch box has 'jerky' movement which leads me to believe that the render loop is shoving out touch events or something to that affect.

Any help appreciated!


This forum thread has a long discussion comparing and contrasting NSTimer vs. MainLoop. In particular, I think you are looking for the following:

    //Yield to system calls (touches, etc.) for one ms.
    while( CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002, FALSE) == kCFRunLoopRunHandledSource);

However since you are doing this on the same single thread as everything else, I personally doubt you will be seeing any performance improvement over a properly configured NSTimer, and you may even take a hit. Your mileage may vary, but it might be worth testing both ways and doing some metrics before you launch. It's an easy enough thing to test.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号