Merge pull request #1112 from unknownbrackets/ios-ctrl

iOS: Fix button sticking (from @rock88)
This commit is contained in:
Henrik Rydgård committed 2013-03-30 17:24:56 -07:00
commit 8155657ea3
2 files changed
+42 -11

No files matched your search

+2 -2
View File
@@ -1019,11 +1019,11 @@ if(APPLE)
set(CMAKE_CXX_FLAGS_DEBUG "-g -D_DEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -D_NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -D_NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -D_NDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -D_NDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -D_NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -D_NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -D_NDEBUG")
# These can be fast even for debug.
set_target_properties(cityhash PROPERTIES COMPILE_FLAGS "-O3")
+40 -9
View File
@@ -28,6 +28,7 @@ float dp_yscale = 1.0f;
static uint32_t pad_buttons_async_set = 0;
static uint32_t pad_buttons_async_clear = 0;
static uint32_t pad_buttons_down = 0;
extern ScreenManager *screenManager;
InputState input_state;
@@ -60,6 +61,9 @@ ViewController* sharedViewController;
self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"];
memset(&input_state, 0, sizeof(input_state));
pad_buttons_async_clear = 0;
pad_buttons_async_set = 0;
pad_buttons_down = 0;
net::Init();
@@ -108,7 +112,7 @@ ViewController* sharedViewController;
dp_yscale = (float)dp_yres / (float)pixel_yres;
if (g_Config.bEnableSound)
self.audioEngine = [[[AudioEngine alloc] init] autorelease];
self.audioEngine = [[[AudioEngine alloc] init] autorelease];
/*
UISwipeGestureRecognizer* gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)] autorelease];
[self.view addGestureRecognizer:gesture];
@@ -134,7 +138,7 @@ ViewController* sharedViewController;
{
[self viewDidUnload];
self.audioEngine = nil;
self.audioEngine = nil;
self.touches = nil;
self.documentsPath = nil;
self.bundlePath = nil;
@@ -160,8 +164,9 @@ ViewController* sharedViewController;
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
lock_guard guard(input_state.lock);
input_state.pad_buttons |= pad_buttons_async_set;
input_state.pad_buttons &= ~pad_buttons_async_clear;
pad_buttons_down |= pad_buttons_async_set;
pad_buttons_down &= ~pad_buttons_async_clear;
input_state.pad_buttons = pad_buttons_down;
UpdateInputState(&input_state);
{
@@ -219,12 +224,36 @@ ViewController* sharedViewController;
input_state.mouse_valid = true;
}
- (NSDictionary*)touchDictBy:(UITouch*)touch
{
for (NSDictionary* dict in self.touches) {
if ([dict objectForKey:@"touch"] == touch)
return dict;
}
return nil;
}
- (int)freeTouchIndex
{
int index = 0;
for (NSDictionary* dict in self.touches)
{
int i = [[dict objectForKey:@"index"] intValue];
if (index == i)
index = i+1;
}
return index;
}
- (void)touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)event
{
for(UITouch* touch in _touches) {
[self.touches addObject:touch];
NSDictionary* dict = @{@"touch":touch,@"index":@([self freeTouchIndex])};
[self.touches addObject:dict];
CGPoint point = [touch locationInView:self.view];
[self touchX:point.x y:point.y code:1 pointerId:[self.touches indexOfObject:touch]];
[self touchX:point.x y:point.y code:1 pointerId:[[dict objectForKey:@"index"] intValue]];
}
}
@@ -232,7 +261,8 @@ ViewController* sharedViewController;
{
for(UITouch* touch in _touches) {
CGPoint point = [touch locationInView:self.view];
[self touchX:point.x y:point.y code:0 pointerId:[self.touches indexOfObject:touch]];
NSDictionary* dict = [self touchDictBy:touch];
[self touchX:point.x y:point.y code:0 pointerId:[[dict objectForKey:@"index"] intValue]];
}
}
@@ -240,8 +270,9 @@ ViewController* sharedViewController;
{
for(UITouch* touch in _touches) {
CGPoint point = [touch locationInView:self.view];
[self touchX:point.x y:point.y code:2 pointerId:[self.touches indexOfObject:touch]];
[self.touches removeObject:touch];
NSDictionary* dict = [self touchDictBy:touch];
[self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]];
[self.touches removeObject:dict];
}
}