Skip to content

Commit

Permalink
Scaling fixes, performance improvements, zooming fixes, and fixes.
Browse files Browse the repository at this point in the history
[UPDATED]   More modern iTunesArtwork version.
[FIXED]     Some issues with too many windows as a result of floating
            point math rounding errors.
[IMPROVED]  Background buildings render speed.
[IMPROVED]  Don't render background windows when video effects are off.
[IMPROVED]  Longer dance and wait for dance to complete.
[FIXED]     Collision debugging code.
[FIXED]     Some issues with bobber & aim bar location, especially when
            zooming or on a non-default building scale.
[FIXED]     Game zooming gesture recognition.
  • Loading branch information
lhunath committed Aug 15, 2011
1 parent 37ac352 commit 2d347ad
Show file tree
Hide file tree
Showing 28 changed files with 201 additions and 154 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,5 @@

# Gorillas Stuff
/promocodes
/sendipa/*
!/sendipa/sendipa.conf
33 changes: 6 additions & 27 deletions Gorillas.xcodeproj/project.pbxproj
Expand Up @@ -88,10 +88,8 @@
DA0AA58F13B29C85005759F8 /* menu-main-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA58113B29C85005759F8 /* menu-main-hd.png */; };
DA0AA59113B29C9E005759F8 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59013B29C9E005759F8 /* Icon.png */; };
DA0AA59213B29C9E005759F8 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59013B29C9E005759F8 /* Icon.png */; };
DA0AA59513B29CF9005759F8 /* iTunesArtwork-lite.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59313B29CF9005759F8 /* iTunesArtwork-lite.png */; };
DA0AA59613B29CF9005759F8 /* iTunesArtwork-lite.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59313B29CF9005759F8 /* iTunesArtwork-lite.png */; };
DA0AA59713B29CF9005759F8 /* iTunesArtwork.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59413B29CF9005759F8 /* iTunesArtwork.png */; };
DA0AA59813B29CF9005759F8 /* iTunesArtwork.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59413B29CF9005759F8 /* iTunesArtwork.png */; };
DA0AA59713B29CF9005759F8 /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59413B29CF9005759F8 /* iTunesArtwork */; };
DA0AA59813B29CF9005759F8 /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = DA0AA59413B29CF9005759F8 /* iTunesArtwork */; };
DA0DA09413CCF1FD00B1D188 /* libPlayHaven.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0EA01113CCF06900BB7666 /* libPlayHaven.a */; };
DA0DA09513CCF20200B1D188 /* libPlayHaven.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0EA01113CCF06900BB7666 /* libPlayHaven.a */; };
DA0DD66A0F95368600E5607E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0DD6610F95368600E5607E /* UIKit.framework */; };
Expand Down Expand Up @@ -748,8 +746,7 @@
DA0AA58013B29C85005759F8 /* menu-back-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "menu-back-hd.png"; path = "png/menu-back-hd.png"; sourceTree = "<group>"; };
DA0AA58113B29C85005759F8 /* menu-main-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "menu-main-hd.png"; path = "png/menu-main-hd.png"; sourceTree = "<group>"; };
DA0AA59013B29C9E005759F8 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = png/Icon.png; sourceTree = "<group>"; };
DA0AA59313B29CF9005759F8 /* iTunesArtwork-lite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "iTunesArtwork-lite.png"; path = "png/iTunesArtwork-lite.png"; sourceTree = "<group>"; };
DA0AA59413B29CF9005759F8 /* iTunesArtwork.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = iTunesArtwork.png; path = png/iTunesArtwork.png; sourceTree = "<group>"; };
DA0AA59413B29CF9005759F8 /* iTunesArtwork */ = {isa = PBXFileReference; lastKnownFileType = text; name = iTunesArtwork; path = png/iTunesArtwork; sourceTree = "<group>"; };
DA0DD6610F95368600E5607E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
DA0DD6620F95368600E5607E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
DA0DD6630F95368600E5607E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -2615,8 +2612,7 @@
DA5F1BD30EE74CE80041691E /* Images */ = {
isa = PBXGroup;
children = (
DA0AA59313B29CF9005759F8 /* iTunesArtwork-lite.png */,
DA0AA59413B29CF9005759F8 /* iTunesArtwork.png */,
DA0AA59413B29CF9005759F8 /* iTunesArtwork */,
DA0AA59013B29C9E005759F8 /* Icon.png */,
DA0AA57B13B29C84005759F8 /* Icon-72.png */,
DA0AA57C13B29C84005759F8 /* Icon-Small-50.png */,
Expand Down Expand Up @@ -4586,7 +4582,6 @@
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
DAE38A881004D33B0023D941 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -4828,8 +4823,7 @@
DA0AA58C13B29C85005759F8 /* menu-back-hd.png in Resources */,
DA0AA58E13B29C85005759F8 /* menu-main-hd.png in Resources */,
DA0AA59113B29C9E005759F8 /* Icon.png in Resources */,
DA0AA59513B29CF9005759F8 /* iTunesArtwork-lite.png in Resources */,
DA0AA59713B29CF9005759F8 /* iTunesArtwork.png in Resources */,
DA0AA59713B29CF9005759F8 /* iTunesArtwork in Resources */,
DA03B67813CA3D04009DF176 /* score.png in Resources */,
DA03B67A13CA3D0A009DF176 /* menu.png in Resources */,
DA03B67C13CA3D2A009DF176 /* aim.body.0.png in Resources */,
Expand Down Expand Up @@ -4947,8 +4941,7 @@
DA0AA58D13B29C85005759F8 /* menu-back-hd.png in Resources */,
DA0AA58F13B29C85005759F8 /* menu-main-hd.png in Resources */,
DA0AA59213B29C9E005759F8 /* Icon.png in Resources */,
DA0AA59613B29CF9005759F8 /* iTunesArtwork-lite.png in Resources */,
DA0AA59813B29CF9005759F8 /* iTunesArtwork.png in Resources */,
DA0AA59813B29CF9005759F8 /* iTunesArtwork in Resources */,
DA03B67913CA3D05009DF176 /* score.png in Resources */,
DA03B67B13CA3D0A009DF176 /* menu.png in Resources */,
DA03B68E13CA3D2B009DF176 /* aim.body.0.png in Resources */,
Expand Down Expand Up @@ -5007,19 +5000,6 @@
shellScript = "cd \"$TARGET_BUILD_DIR\"\nif [[ \"$CONFIGURATION\" = Distribution ]]; then\n if [[ \"$TARGET_NAME\" = *\"Lite\"* ]]; then\n mv \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork-lite.png\" \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"\n else\n mv \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork.png\" \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"\n fi\nfi\nrm \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"*.png\n";
showEnvVarsInLog = 0;
};
DAE38A881004D33B0023D941 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
shellScript = "cd \"$TARGET_BUILD_DIR\"\nif [[ \"$CONFIGURATION\" = Distribution ]]; then\n if [[ \"$TARGET_NAME\" = *\"Lite\"* ]]; then\n mv \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork-lite.png\" \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"\n else\n mv \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork.png\" \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"\n fi\nfi\nrm \"$UNLOCALIZED_RESOURCES_FOLDER_PATH/iTunesArtwork\"*.png\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -5634,7 +5614,6 @@
armv6,
"$(ARCHS_STANDARD_32_BIT)",
);
CODE_SIGN_ENTITLEMENTS = Resources/Entitlements.plist;
DEPLOYMENT_POSTPROCESSING = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = YES;
Expand Down
101 changes: 49 additions & 52 deletions Gorillas/BuildingsLayer.m
Expand Up @@ -30,7 +30,7 @@ @implementation BuildingsLayer


- (id) init {

if (!(self = [self initWithWidthRatio:1 heightRatio:1 lightRatio:0]))
return nil;

Expand All @@ -42,7 +42,7 @@ - (id) initWithWidthRatio:(CGFloat)w heightRatio:(float)h lightRatio:(float)l {

if (!(self = [super init]))
return self;

buildingWidthRatio = w;
buildingHeightRatio = h;
lightRatio = l;
Expand All @@ -51,7 +51,7 @@ - (id) initWithWidthRatio:(CGFloat)w heightRatio:(float)h lightRatio:(float)l {
buildingsIndicesBuffer = 0;
windowsVertexBuffer = 0;
windowsIndicesBuffer = 0;

// Must reset before onEnter. Others' onEnter depends on us being done.
[self reset];

Expand All @@ -73,9 +73,9 @@ -(BOOL) hitsBuilding:(CGPoint)pos {
-(void) reset {

dbg(@"BuildingsLayer reset start");
GorillasConfig *config = [GorillasConfig get];
BOOL visualFx = [config.visualFx boolValue];

const GorillasConfig *config = [GorillasConfig get];
const BOOL visualFx = [config.visualFx boolValue];
const ccColor4B skyColor = ccc4l([config.skyColor longValue]);
const ccColor4B wColor0 = ccc4shade(ccc4lighten(ccc4l([config.windowColorOff longValue]), lightRatio), skyColor, MAX(0, -lightRatio / 2));
const ccColor4B wColor1 = ccc4shade(ccc4lighten(ccc4l([config.windowColorOn longValue]), lightRatio), skyColor, MAX(0, -lightRatio / 2));
Expand All @@ -84,16 +84,16 @@ -(void) reset {
wColor10.g = (wColor0.g + wColor1.g) / 2;
wColor10.b = (wColor0.b + wColor1.b) / 2;
wColor10.a = (wColor0.a + wColor1.a) / 2;

const NSUInteger fixedFloors = [config.fixedFloors unsignedIntValue];
const NSInteger varFloors = [config.varFloors unsignedIntValue];
const CGSize winSize = [CCDirector sharedDirector].winSize;
const CGFloat buildingWidth = buildingWidthRatio * (winSize.width / [config.buildingAmount unsignedIntValue]);
CGFloat wWidth = buildingWidth / ([config.windowAmount unsignedIntValue] * 2 + 1);
CGFloat wPad = wWidth;
CGFloat wHeight = wWidth * 2;
const CGFloat floorHeight = wHeight + wPad;

const CGFloat wWidthPt = buildingWidth / ([config.windowAmount unsignedIntValue] * 2 + 1);
const CGFloat wPadPt = wWidthPt;
const CGFloat wHeightPt = wWidthPt * 2;
const CGFloat floorHeightPt = wHeightPt + wPadPt;
// Calculcate buildings.
windowCount = 0;
buildingCount = [config.buildingAmount unsignedIntValue] * 3;
Expand All @@ -107,23 +107,20 @@ -(void) reset {
NSInteger addFloors = 0;
if (varFloors)
addFloors = buildingHeightRatio * (gameRandom() % varFloors);
buildings[b].size = CGSizeMake(buildingWidth - 1, (fixedFloors + addFloors) * floorHeight + wPad);

buildings[b].size = CGSizeMake(buildingWidth - 1, (fixedFloors + addFloors) * floorHeightPt + wPadPt);
// Building's windows.
buildings[b].windowCount = (1 + (int) (buildings[b].size.height - wHeight - (int)wPad) / (int) (wPad + wHeight))
* (1 + (int) (buildings[b].size.width - wWidth - (int)wPad) / (int) (wPad + wWidth));
buildings[b].windowCount = (fixedFloors + addFloors) * [config.windowAmount unsignedIntValue];
windowCount += buildings[b].windowCount;

// Building's color.
buildings[b].frontColor = ccc4shade(ccc4lighten([config buildingColor], lightRatio), skyColor, MAX(0, -lightRatio / 2));
buildings[b].backColor.r = (GLubyte)(buildings[b].frontColor.r * 0.2f);
buildings[b].backColor.g = (GLubyte)(buildings[b].frontColor.g * 0.2f);
buildings[b].backColor.b = (GLubyte)(buildings[b].frontColor.b * 0.2f);
buildings[b].backColor.a = (GLubyte)(buildings[b].frontColor.a * 1.0f);

dbg(@"building(%d/%d, varFloors(%d) => addFloors(%d))", b, buildingCount, varFloors, addFloors);
}

// Build vertex arrays.
BuildingVertex *buildingVertices = malloc(sizeof(BuildingVertex) /* size of a vertex */
* 4 /* amount of vertices per building */
Expand All @@ -137,18 +134,18 @@ -(void) reset {
GLushort *windowIndices = malloc(sizeof(GLushort) /* size of an index */
* 6 /* amount of indexes per window */
* windowCount /* amount of windows in all buildings */);
wPad *= CC_CONTENT_SCALE_FACTOR();
wWidth *= CC_CONTENT_SCALE_FACTOR();
wHeight *= CC_CONTENT_SCALE_FACTOR();
NSUInteger w = 0;
for (NSUInteger b = 0; b < buildingCount; ++b) {
const CGFloat wPadPx = wPadPt * CC_CONTENT_SCALE_FACTOR();
const CGFloat wWidthPx = wWidthPt * CC_CONTENT_SCALE_FACTOR();
const CGFloat wHeightPx = wHeightPt * CC_CONTENT_SCALE_FACTOR();
const CGFloat floorHeightPx = floorHeightPt * CC_CONTENT_SCALE_FACTOR();
for (NSUInteger w = 0, b = 0; b < buildingCount; ++b) {

CGFloat bx = buildings[b].x * CC_CONTENT_SCALE_FACTOR();
CGSize bs = CGSizeMake(buildings[b].size.width * CC_CONTENT_SCALE_FACTOR(),
const CGFloat bx = buildings[b].x * CC_CONTENT_SCALE_FACTOR();
const CGSize bs = CGSizeMake(buildings[b].size.width * CC_CONTENT_SCALE_FACTOR(),
buildings[b].size.height * CC_CONTENT_SCALE_FACTOR());
NSUInteger bv = b * 4;
NSUInteger bi = b * 6;

const NSUInteger bv = b * 4;
const NSUInteger bi = b * 6;
buildingVertices[bv + 0].front.c = buildingVertices[bv + 1].front.c = buildings[b].backColor;
buildingVertices[bv + 2].front.c = buildingVertices[bv + 3].front.c = buildings[b].frontColor;
buildingVertices[bv + 0].backColor = buildingVertices[bv + 1].backColor = buildings[b].backColor;
Expand All @@ -166,28 +163,27 @@ -(void) reset {
buildingIndices[bi + 4] = bv + 3;
buildingIndices[bi + 5] = bv + 1;

NSUInteger bw = 0;
for (NSInteger y = wPad;
bw < buildings[b].windowCount;
y += wPad + wHeight) {
NSUInteger bw = 0, floor = 0;
while (bw < buildings[b].windowCount) {
const CGFloat y = wPadPx + floor * floorHeightPx;

for (NSInteger wx = wPad;
wx < bs.width - wWidth && bw < buildings[b].windowCount;
wx += wPad + wWidth) {
for (NSInteger wx = wPadPx;
wx < bs.width - wWidthPx && bw < buildings[b].windowCount;
wx += wPadPx + wWidthPx) {

// Reason we don't use gameRandom for windows:
// Window count across multiple resolution devices is unpredictable due to rounding errors.
BOOL isOff = random() % 100 < 20;
NSUInteger wv = (w + bw) * 4;
NSUInteger wi = (w + bw) * 6;
const BOOL isOff = random() % 100 < 20;
const NSUInteger wv = (w + bw) * 4;
const NSUInteger wi = (w + bw) * 6;

windowVertices[wv + 0].c = windowVertices[wv + 1].c = isOff? wColor0: visualFx? wColor10: wColor1;
windowVertices[wv + 2].c = windowVertices[wv + 3].c = isOff? wColor0: wColor1;

windowVertices[wv + 0].p = ccp(bx + wx , y);
windowVertices[wv + 1].p = ccp(bx + wx + wWidth, y);
windowVertices[wv + 2].p = ccp(bx + wx , y + wHeight);
windowVertices[wv + 3].p = ccp(bx + wx + wWidth, y + wHeight);
windowVertices[wv + 0].p = ccp(bx + wx , y);
windowVertices[wv + 1].p = ccp(bx + wx + wWidthPx, y);
windowVertices[wv + 2].p = ccp(bx + wx , y + wHeightPx);
windowVertices[wv + 3].p = ccp(bx + wx + wWidthPx, y + wHeightPx);

windowIndices[wi + 0] = wv + 0;
windowIndices[wi + 1] = wv + 1;
Expand All @@ -198,6 +194,8 @@ -(void) reset {

++bw;
}

++floor;
}
if(bw != buildings[b].windowCount)
err(@"Windows vertex count not the same as window amount.");
Expand Down Expand Up @@ -229,7 +227,6 @@ -(void) reset {
free(buildingVertices);
free(windowVertices);
free(windowIndices);
dbg(@"BuildingsLayer reset done");
}


Expand All @@ -240,17 +237,17 @@ -(void) draw {
//glEnableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);

// Drawing Front Side.
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);

// == DRAW BUILDING ==
// Blend with DST_ALPHA (DST_ALPHA of 1 means draw SRC, hide DST; DST_ALPHA of 0 means hide SRC, leave DST).
glBindBuffer(GL_ARRAY_BUFFER, buildingsVertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buildingsIndicesBuffer);
glVertexPointer(2, GL_FLOAT, sizeof(BuildingVertex), 0);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(BuildingVertex), (GLvoid *) sizeof(CGPoint));

glDrawElements(GL_TRIANGLES, buildingCount * 6, GL_UNSIGNED_SHORT, 0);
//drawBoxFrom(CGPointZero, ccp(contentSize.width, contentSize.height), buildingColor, buildingColor);

Expand All @@ -264,9 +261,9 @@ -(void) draw {
// = DRAW FRONT WINDOWS =
// Blend with DST_ALPHA (DST_ALPHA of 1 means draw SRC, hide DST; DST_ALPHA of 0 means hide SRC, leave DST).
glDrawElements(GL_TRIANGLES, windowCount * 6, GL_UNSIGNED_SHORT, 0);

// Drawing Rear Side.
if ([[GorillasConfig get].visualFx boolValue]) {
if ([[GorillasConfig get].visualFx boolValue] && buildingHeightRatio == 1) {
glBlendFunc(GL_ONE, GL_ZERO);

// = DRAW REAR WINDOWS =
Expand Down Expand Up @@ -294,7 +291,7 @@ -(void) draw {
//glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);

}


Expand All @@ -308,7 +305,7 @@ -(void) dealloc {
buildingsIndicesBuffer = 0;
windowsVertexBuffer = 0;
windowsIndicesBuffer = 0;

[super dealloc];
}

Expand Down
7 changes: 6 additions & 1 deletion Gorillas/CityLayer.h
Expand Up @@ -31,12 +31,16 @@
#import "BarSprite.h"
#import "BuildingsLayer.h"

#define DEBUG_COLLISION 0

@interface CityLayer : CCParallaxNode <Resettable> {

@private
CCLabelTTF *msgLabel;

BuildingsLayer **buildings;
NSUInteger buildingsCount;

HolesLayer *holes;
ExplosionsLayer *explosions;
CCLayer *nonParallaxLayer;
Expand All @@ -47,7 +51,7 @@
CGPoint *throwHistory;
NSMutableArray *throwHints;

#ifdef _DEBUG_
#if DEBUG_COLLISION
NSUInteger dbgTraceStep;
NSUInteger dbgPathMaxInd;
NSUInteger dbgPathCurInd;
Expand All @@ -59,6 +63,7 @@
#endif
}

@property (nonatomic, readonly) BuildingsLayer *buildingLayer;
@property (nonatomic, readonly) BananaLayer *bananaLayer;
@property (nonatomic, readonly) GorillaLayer *hitGorilla;

Expand Down

0 comments on commit 2d347ad

Please sign in to comment.