From 14d015cfbb4b466ce1662d4e88ce2b33a348bf5d Mon Sep 17 00:00:00 2001 From: Matej Jan Date: Mon, 15 Nov 2010 17:23:13 +0000 Subject: [PATCH] Enabled multitouch and corrected fixed timestep reporting. git-svn-id: http://xni.googlecode.com/svn/XNI@40 ac433895-eea3-a490-d80a-17149a75e588 --- .../Xni/Framework/Content/ContentManager.m | 2 ++ Classes/Retronator/Xni/Framework/Game.m | 26 ++++++++++--------- .../Xni/Framework/GameServiceContainer.m | 2 +- Classes/Retronator/Xni/Framework/GameView.m | 2 ++ .../Xni/Framework/GameViewController.m | 15 ++++++----- .../Xni/Framework/Graphics/SpriteBatch.h | 2 -- .../Xni/Framework/Graphics/SpriteBatch.m | 4 +-- .../Xni/Framework/Input/Touch/TouchPanel.h | 7 +++-- .../Xni/Framework/Input/Touch/TouchPanel.m | 19 ++++++++++---- 9 files changed, 48 insertions(+), 31 deletions(-) diff --git a/Classes/Retronator/Xni/Framework/Content/ContentManager.m b/Classes/Retronator/Xni/Framework/Content/ContentManager.m index b7a5450..2794cda 100644 --- a/Classes/Retronator/Xni/Framework/Content/ContentManager.m +++ b/Classes/Retronator/Xni/Framework/Content/ContentManager.m @@ -88,6 +88,8 @@ // Save the loaded asset for quick retreival. [loadedAssets setObject:result forKey:assetName]; + [input release]; + return result; } diff --git a/Classes/Retronator/Xni/Framework/Game.m b/Classes/Retronator/Xni/Framework/Game.m index 1a80a12..45a87d1 100644 --- a/Classes/Retronator/Xni/Framework/Game.m +++ b/Classes/Retronator/Xni/Framework/Game.m @@ -116,17 +116,19 @@ NSArray *drawOrderSort; NSTimeInterval elapsedRealTime = [currentFrameTime timeIntervalSinceDate:lastFrameTime]; // Sleep if we're ahead of the target elapsed time. - if (isFixedTimeStep && elapsedRealTime < targetElapsedTime) { - NSTimeInterval sleepTime = targetElapsedTime - elapsedRealTime; - CFRunLoopRunInMode(kCFRunLoopDefaultMode, sleepTime, NO); - - // Recalculate elapsed times. - [currentFrameTime release]; - currentFrameTime = [[NSDate alloc] init]; - elapsedRealTime = [currentFrameTime timeIntervalSinceDate:lastFrameTime]; - gameTime.isRunningSlowly = NO; - } else { - gameTime.isRunningSlowly = YES; + if (isFixedTimeStep) { + if (elapsedRealTime < targetElapsedTime) { + NSTimeInterval sleepTime = targetElapsedTime - elapsedRealTime; + CFRunLoopRunInMode(kCFRunLoopDefaultMode, sleepTime, NO); + + // Recalculate elapsed times. + [currentFrameTime release]; + currentFrameTime = [[NSDate alloc] init]; + elapsedRealTime = [currentFrameTime timeIntervalSinceDate:lastFrameTime]; + gameTime.isRunningSlowly = NO; + } else { + gameTime.isRunningSlowly = YES; + } } // Store current time for next frame. @@ -140,7 +142,7 @@ NSArray *drawOrderSort; gameTime.totalGameTime += elapsedGameTime; // Update input. - [[TouchPanel instance] update]; + [[TouchPanel getInstance] update]; // Update the game. [self updateWithGameTime:gameTime]; diff --git a/Classes/Retronator/Xni/Framework/GameServiceContainer.m b/Classes/Retronator/Xni/Framework/GameServiceContainer.m index 80beff2..f75b528 100644 --- a/Classes/Retronator/Xni/Framework/GameServiceContainer.m +++ b/Classes/Retronator/Xni/Framework/GameServiceContainer.m @@ -13,7 +13,7 @@ - (id) init { if (self = [super init]) { - services = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + services = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks); } return self; } diff --git a/Classes/Retronator/Xni/Framework/GameView.m b/Classes/Retronator/Xni/Framework/GameView.m index 3c08d8a..a857af8 100644 --- a/Classes/Retronator/Xni/Framework/GameView.m +++ b/Classes/Retronator/Xni/Framework/GameView.m @@ -23,6 +23,8 @@ eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; + + self.multipleTouchEnabled = YES; } return self; } diff --git a/Classes/Retronator/Xni/Framework/GameViewController.m b/Classes/Retronator/Xni/Framework/GameViewController.m index 2fd8a2a..ebe2065 100644 --- a/Classes/Retronator/Xni/Framework/GameViewController.m +++ b/Classes/Retronator/Xni/Framework/GameViewController.m @@ -78,9 +78,10 @@ GameView *gameView = [[GameView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; self.view = gameView; - [TouchPanel instance].displayWidth = self.view.bounds.size.width; - [TouchPanel instance].displayHeight = self.view.bounds.size.height; - [TouchPanel instance].displayOrientation = [GameViewController getDisplayOrientationForInterfaceOrientation:self.interfaceOrientation]; + TouchPanel *touchPanel = [TouchPanel getInstance]; + touchPanel.displayWidth = self.view.bounds.size.width; + touchPanel.displayHeight = self.view.bounds.size.height; + touchPanel.displayOrientation = [GameViewController getDisplayOrientationForInterfaceOrientation:self.interfaceOrientation]; [gameView release]; } @@ -110,19 +111,19 @@ // Touches - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - [[TouchPanel instance] touchesBegan:touches withEvent:event]; + [[TouchPanel getInstance] touchesBegan:touches withEvent:event]; } - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - [[TouchPanel instance] touchesMoved:touches withEvent:event]; + [[TouchPanel getInstance] touchesMoved:touches withEvent:event]; } - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - [[TouchPanel instance] touchesEnded:touches withEvent:event]; + [[TouchPanel getInstance] touchesEnded:touches withEvent:event]; } - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { - [[TouchPanel instance] touchesCancelled:touches withEvent:event]; + [[TouchPanel getInstance] touchesCancelled:touches withEvent:event]; } - (void)dealloc { diff --git a/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.h b/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.h index ef0144b..873b6f1 100644 --- a/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.h +++ b/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.h @@ -23,8 +23,6 @@ BOOL beginCalled; - int drawCalls; - NSMutableArray *sprites; VertexPositionColorTextureArray *vertexArray; } diff --git a/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.m b/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.m index e2611e9..9586ad6 100644 --- a/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.m +++ b/Classes/Retronator/Xni/Framework/Graphics/SpriteBatch.m @@ -6,10 +6,9 @@ // Copyright 2010 Retronator. All rights reserved. // -#import "SpriteBatch.h" - #import "Retronator.Xni.Framework.h" #import "Retronator.Xni.Framework.Graphics.h" +#import "SpriteBatch.h" typedef struct { float x; @@ -312,6 +311,7 @@ static VertexPositionColorTextureStruct vertices[4]; switch (sortMode) { case SpriteSortModeImmediate: // We've already done all the work. + beginCalled = NO; return; case SpriteSortModeTexture: [sprites sortUsingDescriptors:textureSort]; diff --git a/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.h b/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.h index 3f1e1b3..58811f9 100644 --- a/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.h +++ b/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.h @@ -24,14 +24,17 @@ NSMutableDictionary *touchLocations; } -+ (TouchPanel*) instance; - @property (nonatomic) int displayWidth; @property (nonatomic) int displayHeight; @property (nonatomic) DisplayOrientation displayOrientation; @property (nonatomic) GestureType enabledGestures; @property (nonatomic, readonly) BOOL isGestureAvailable; ++ (TouchCollection*) getState; ++ (GestureSample*) readGesture; + ++ (TouchPanel*) getInstance; + - (TouchCollection*) getState; - (GestureSample*) readGesture; diff --git a/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.m b/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.m index 49a10de..a04bbeb 100644 --- a/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.m +++ b/Classes/Retronator/Xni/Framework/Input/Touch/TouchPanel.m @@ -95,20 +95,29 @@ static TouchPanel *instance; return self; } - + (void) initialize { instance = [[TouchPanel alloc] init]; } -+ (TouchPanel*) instance { - return instance; -} - @synthesize displayWidth; @synthesize displayHeight; @synthesize displayOrientation; @synthesize enabledGestures; ++ (TouchCollection*) getState { + return [instance getState]; +} + ++ (GestureSample*) readGesture { + return [instance readGesture]; +} + + ++ (TouchPanel*) getInstance { + return instance; +} + + - (BOOL) isGestureAvailable{ return NO; }