From a83d5c36887a89249ae8dd9c38fd7b86d689ac06 Mon Sep 17 00:00:00 2001 From: exterlulz Date: Sat, 14 Aug 2010 19:29:12 +0200 Subject: [PATCH] cleaning --- src/Game.m | 22 +++++++++++------- src/GameController.m | 12 ++++------ src/Gem.h | 5 ++-- src/OpenGLSprite.h | 3 --- src/OpenGLSprite.m | 66 +++++++++++++++++++++++++++++----------------------- src/TimerView.h | 2 -- src/TimerView.m | 3 --- 7 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/Game.m b/src/Game.m index a8b3ef0..c4a17b6 100644 --- a/src/Game.m +++ b/src/Game.m @@ -35,17 +35,21 @@ @implementation Game -- (id) init +- (id)init { - int i,j; self = [super init]; - gemsFaded = 0; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - board[i][j] = [[Gem alloc] init]; - // MW - scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; - // + if (self != nil) { + gemsFaded = 0; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + board[i][j] = [[Gem alloc] init]; + } + } + + // MW + scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; + } + return self; } diff --git a/src/GameController.m b/src/GameController.m index 2f2d6aa..6bb285f 100644 --- a/src/GameController.m +++ b/src/GameController.m @@ -673,19 +673,17 @@ - (void)newBoard2 { Gem *gem; - int i,j,r; + int r; + //NSLog(@"newBoard2"); - for (i = 0; i < 8; i++) - { - for (j = 0; j < 8; j++) - { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { gem = [game gemAt:i:j]; - //NSLog(@"..gem..%@",gem); r = rand() % 7; [gem setGemType:r]; //[gem setImage:[[gameView imageArray] objectAtIndex:r]]; [gem setSprite:[[gameView spriteArray] objectAtIndex:r]]; - gem._positionOnBoard = NSMakePoint(i, j); + gem._positionOnBoard = NSMakePoint(i, j); gem._positionOnScreen = NSMakePoint(i * 48, (i + j + 8) * 48); [gem fall]; } diff --git a/src/Gem.h b/src/Gem.h index 9615558..f0229b0 100644 --- a/src/Gem.h +++ b/src/Gem.h @@ -26,8 +26,8 @@ // TODO: clean #import -#import +// TODO: move to .m? // TODO: replace with enum? #define GEMSTATE_RESTING 1 #define GEMSTATE_FADING 2 @@ -38,7 +38,6 @@ // MW... #define GEMSTATE_SHIVERING 7 -// #define FADE_STEPS 8.0 #define GRAVITY 1.46 @@ -47,7 +46,7 @@ // Open GL Z value for gems #define GEM_SPRITE_Z -0.25 -@class OpenGLSprite; +@class OpenGLSprite; @interface Gem : NSObject { diff --git a/src/OpenGLSprite.h b/src/OpenGLSprite.h index de2591a..8f3a3dd 100644 --- a/src/OpenGLSprite.h +++ b/src/OpenGLSprite.h @@ -16,9 +16,6 @@ #include -#define OPEN_GL_SPRITE_MIN_WIDTH 64.0 -#define OPEN_GL_SPRITE_MIN_HEIGHT 64.0 - @interface OpenGLSprite : NSObject { NSData* textureData; diff --git a/src/OpenGLSprite.m b/src/OpenGLSprite.m index 3929937..70f7780 100644 --- a/src/OpenGLSprite.m +++ b/src/OpenGLSprite.m @@ -15,6 +15,10 @@ @implementation OpenGLSprite +// TODO: replace with static onst +#define OPEN_GL_SPRITE_MIN_WIDTH 64.0 +#define OPEN_GL_SPRITE_MIN_HEIGHT 64.0 + /* ???: what's the point? - (id) init { @@ -51,20 +55,19 @@ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, texName); - glBegin(GL_QUADS); - - glTexCoord2f(0.0, 1.0-textureCropRect.size.height); - glVertex3f(x, y+size.height, z); - - glTexCoord2f(0.0, 1.0); - glVertex3f(x, y, z); - - glTexCoord2f(textureCropRect.size.width, 1.0); - glVertex3f(x+size.width, y, z); - - glTexCoord2f(textureCropRect.size.width, 1.0-textureCropRect.size.height); - glVertex3f(x+size.width, y+size.height, z); - + glBegin(GL_QUADS); { + glTexCoord2f(0.0, 1.0-textureCropRect.size.height); + glVertex3f(x, y+size.height, z); + + glTexCoord2f(0.0, 1.0); + glVertex3f(x, y, z); + + glTexCoord2f(textureCropRect.size.width, 1.0); + glVertex3f(x+size.width, y, z); + + glTexCoord2f(textureCropRect.size.width, 1.0-textureCropRect.size.height); + glVertex3f(x+size.width, y+size.height, z); + } glEnd(); glDisable(GL_TEXTURE_2D); @@ -77,25 +80,27 @@ if (a > 1.0) a = 1.0; // clamp the alpha value + glEnable(GL_TEXTURE_2D); glColor4f(1.0, 1.0, 1.0, a); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, texName); - glBegin(GL_QUADS); - - glTexCoord2f(0.0, 1.0-textureCropRect.size.height); - glVertex3f(x, y+size.height, z); - - glTexCoord2f(0.0, 1.0); - glVertex3f(x, y, z); - - glTexCoord2f(textureCropRect.size.width, 1.0); - glVertex3f(x+size.width, y, z); - - glTexCoord2f(textureCropRect.size.width, 1.0-textureCropRect.size.height); - glVertex3f(x+size.width, y+size.height, z); + glBegin(GL_QUADS); { + glTexCoord2f(0.0, 1.0-textureCropRect.size.height); + glVertex3f(x, y+size.height, z); + + glTexCoord2f(0.0, 1.0); + glVertex3f(x, y, z); + + glTexCoord2f(textureCropRect.size.width, 1.0); + glVertex3f(x+size.width, y, z); + + glTexCoord2f(textureCropRect.size.width, 1.0-textureCropRect.size.height); + glVertex3f(x+size.width, y+size.height, z); + } glEnd(); + glDisable(GL_TEXTURE_2D); } @@ -243,6 +248,7 @@ [image unlockFocus]; [image release]; + // normalise textureCropRect size to 0.0 -> 1.0 textureCropRect = NSMakeRect(0.0,0.0,1.0,1.0); @@ -251,8 +257,9 @@ if ([bitmapImageRep bitsPerPixel]==32) { - if (textureData) + if (textureData) { [textureData autorelease]; + } textureData = [[NSData dataWithBytes:[bitmapImageRep bitmapData] length:textureSize.width*textureSize.height*4] retain]; glBindTexture(GL_TEXTURE_2D, texName); @@ -261,8 +268,9 @@ } else if ([bitmapImageRep bitsPerPixel]==24) { - if (textureData) + if (textureData) { [textureData autorelease]; + } textureData = [[NSData dataWithBytes:[bitmapImageRep bitmapData] length:textureSize.width*textureSize.height*3] retain]; glBindTexture(GL_TEXTURE_2D, texName); diff --git a/src/TimerView.h b/src/TimerView.h index ee89e2f..926c29e 100644 --- a/src/TimerView.h +++ b/src/TimerView.h @@ -44,8 +44,6 @@ NSColor *_backColor; } -// ???: what's the point of this: @property float _meter; - - (id)initWithFrame:(NSRect)frame; - (void)dealloc; diff --git a/src/TimerView.m b/src/TimerView.m index d7b7bbd..01b86c2 100644 --- a/src/TimerView.m +++ b/src/TimerView.m @@ -29,8 +29,6 @@ @implementation TimerView -// ???: @synthesize _meter; - - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; @@ -143,7 +141,6 @@ if (_timer) { [_timer invalidate]; } - _timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(runTimer) -- 2.11.4.GIT