# HG changeset patch # User koda # Date 1287086493 -7200 # Node ID abaf741a4e2149d87ec3b47bb9261dc25ca24db9 # Parent 3f605cca92152a9720804e5b0a682d89807d9e1e less warning, no rotation glitch, more comments diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/GSHandlers.inc Thu Oct 14 22:01:33 2010 +0200 @@ -422,7 +422,7 @@ begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, EXPLAutoSound); for i:= 0 to 2 do - AddGear(hwRound(Gear^.X) - 30 + GetRandom(60), hwRound(Gear^.Y) - 20 + GetRandom(40), gtPoisonCloud, 0, _0, _0, 0); + AddGear(int64(hwRound(Gear^.X)) - 30 + GetRandom(60), int64(hwRound(Gear^.Y)) - 20 + GetRandom(40), gtPoisonCloud, 0, _0, _0, 0); end; end; DeleteGear(Gear); diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/VGSHandlers.inc --- a/hedgewars/VGSHandlers.inc Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/VGSHandlers.inc Thu Oct 14 22:01:33 2010 +0200 @@ -36,7 +36,7 @@ if (round(X) >= cLeftScreenBorder) and (round(X) <= cRightScreenBorder) and - (round(Y) <= (LAND_HEIGHT + 75)) and + (round(Y) <= (int64(LAND_HEIGHT) + 75)) and (Timer > 0) and (Timer-Steps > 0) then begin if tdX > 0 then sign := 1 @@ -54,7 +54,7 @@ if round(X) < cLeftScreenBorder then X:= X + cScreenSpace else if round(X) > cRightScreenBorder then X:= X - cScreenSpace; // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + float(25); // For if flag is set for flakes rising upwards? - if round(Y) > (LAND_HEIGHT + 75) then Y:= Y - float(1024 + 150); // TODO - configure in theme (jellies for example could use limited range) + if round(Y) > (int64(LAND_HEIGHT) + 75) then Y:= Y - float(1024 + 150); // TODO - configure in theme (jellies for example could use limited range) Timer:= 0; tdX:= 0; tdY:= 0 @@ -84,7 +84,7 @@ t := 8 * AngleSin(s mod 2048).QWordValue / 4294967296; if (s < 2048) then t := -t; -Gear^.Y := LAND_HEIGHT-1184 + Gear^.Timer mod 8 + t; +Gear^.Y := int64(LAND_HEIGHT) - 1184 + Gear^.Timer mod 8 + t; if round(Gear^.X) < cLeftScreenBorder then Gear^.X:= Gear^.X + cScreenSpace else if round(Gear^.X) > cRightScreenBorder then Gear^.X:= Gear^.X - cScreenSpace @@ -480,7 +480,7 @@ procedure doStepHealthTagWorkUnderWater(Gear: PVisualGear; Steps: Longword); begin -if round(Gear^.Y) < cWaterLine + 10 then +if round(Gear^.Y) < int64(cWaterLine) + 10 then DeleteVisualGear(Gear) else Gear^.Y:= Gear^.Y - 0.08 * Steps; diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/hwengine.pas Thu Oct 14 22:01:33 2010 +0200 @@ -175,7 +175,7 @@ if isTerminated = false then begin CurrTime:= SDL_GetTicks; - if PrevTime + cTimerInterval <= CurrTime then + if PrevTime + longword(cTimerInterval) <= CurrTime then begin DoTimer(CurrTime - PrevTime); PrevTime:= CurrTime diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/uGears.pas Thu Oct 14 22:01:33 2010 +0200 @@ -534,7 +534,7 @@ end; gtPoisonCloud: begin gear^.Timer:= 5000; - gear^.dY:= int2hwfloat((-4 + getRandom(8))) / 1000; + gear^.dY:= int2hwfloat(-4 + longint(getRandom(8))) / 1000; end; gtResurrector: begin gear^.Radius := 100; @@ -1034,8 +1034,8 @@ begin if not (((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0)) then exit; - DrawTexture(round(sx + 16), round(sy + 16), ropeIconTex); - DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, round(sx + 30), round(sy + 30), ord(CurAmmoType) - 1, 1, 32, 32); + DrawTexture(round(int64(sx) + 16), round(int64(sy) + 16), ropeIconTex); + DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, round(int64(sx) + 30), round(int64(sy) + 30), ord(CurAmmoType) - 1, 1, 32, 32); end; end; diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/uLandObjects.pas Thu Oct 14 22:01:33 2010 +0200 @@ -292,9 +292,9 @@ end end; inc(y, 3); - until y > LAND_HEIGHT - 1 - Height; + until y > int64(LAND_HEIGHT) - 1 - Height; inc(x, getrandom(6) + 3) - until x > LAND_WIDTH - 1 - Width; + until x > int64(LAND_WIDTH) - 1 - Width; bRes:= cnt <> 0; if bRes then begin @@ -341,9 +341,9 @@ end end; inc(y, 12); - until y > LAND_HEIGHT - 1 - Height - 8; + until y > int64(LAND_HEIGHT) - 1 - Height - 8; inc(x, getrandom(12) + 12) - until x > LAND_WIDTH - 1 - Width; + until x > int64(LAND_WIDTH) - 1 - Width; bRes:= cnt <> 0; if bRes then begin @@ -455,7 +455,7 @@ Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed); // adjust amount of flakes scaled by screen space -vobCount:= vobCount * cScreenSpace div LAND_WIDTH; +vobCount:= longint(vobCount) * cScreenSpace div LAND_WIDTH; if (cReducedQuality and rqKillFlakes) <> 0 then vobCount:= 0; diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/uVisualGears.pas --- a/hedgewars/uVisualGears.pas Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/uVisualGears.pas Thu Oct 14 22:01:33 2010 +0200 @@ -370,7 +370,7 @@ if Gear^.Kind = vgtFlake then begin // Damage calc from doMakeExplosion - dmg:= min(101,Radius + cHHRadius div 2 - (round(abs(Gear^.X - float(X))+abs(Gear^.Y - float(Y))) div 5)); + dmg:= min(101, int64(Radius) + cHHRadius div 2 - (round(abs(Gear^.X - float(X))+abs(Gear^.Y - float(Y))) div 5)); if dmg > 1 then begin Gear^.tdX:= 0.02 * dmg + 0.01; diff -r 3f605cca9215 -r abaf741a4e21 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Thu Oct 14 16:01:43 2010 +0200 +++ b/hedgewars/uWorld.pas Thu Oct 14 22:01:33 2010 +0200 @@ -615,8 +615,8 @@ tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do DrawSprite(sprPower, - hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + round(WorldDx + tdx * (24 + i * 2)) - 16, - hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + round(WorldDy + tdy * (24 + i * 2)) - 16, + int64(hwRound(Gear^.X)) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + round(WorldDx + tdx * (24 + i * 2)) - 16, + int64(hwRound(Gear^.Y)) + GetLaunchY(CurAmmoType, Gear^.Angle) + round(WorldDy + tdy * (24 + i * 2)) - 16, i) end end; diff -r 3f605cca9215 -r abaf741a4e21 project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Thu Oct 14 16:01:43 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Thu Oct 14 22:01:33 2010 +0200 @@ -122,7 +122,8 @@ button.layer.borderWidth = w; [button.layer setCornerRadius:radius]; [button.layer setMasksToBounds:YES]; - [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; + [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown]; + [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside]; [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; button.titleLabel.backgroundColor = [UIColor blackColor]; button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; @@ -182,7 +183,7 @@ } } else { button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; - [button setTitle:@"" forState:UIControlStateNormal]; + [button setTitle:nil forState:UIControlStateNormal]; if (button.currentBackgroundImage == nil || button.imageView.tag == 10000) { int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; int y_src = (i*32)%(int)self.weaponsImage.size.height; @@ -211,10 +212,19 @@ #pragma mark - #pragma mark user interaction --(void) buttonPressed:(id) sender { +-(void) buttonPressed:(id) sender { UIButton *theButton = (UIButton *)sender; - HW_setWeapon(theButton.tag); - playSound(@"clickSound"); + if (theButton.currentTitle != nil) { + DLog(@"eeee"); + } +} + +-(void) buttonReleased:(id) sender { + UIButton *theButton = (UIButton *)sender; + if (theButton.currentTitle == nil) { + HW_setWeapon(theButton.tag); + playSound(@"clickSound"); + } if (IS_DUALHEAD() == NO) [self disappear]; } diff -r 3f605cca9215 -r abaf741a4e21 project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Oct 14 16:01:43 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Oct 14 22:01:33 2010 +0200 @@ -461,7 +461,6 @@ rotation = @"-90"; else rotation = @"90"; - } NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width]; diff -r 3f605cca9215 -r abaf741a4e21 project_files/HedgewarsMobile/Classes/OverlayViewController.h --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Thu Oct 14 16:01:43 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Thu Oct 14 22:01:33 2010 +0200 @@ -40,6 +40,7 @@ // the objc ammomenu AmmoMenuViewController *amvc; + BOOL wasVisible; // ths touch section CGFloat initialDistanceForPinching; @@ -53,6 +54,7 @@ // dual head support NSInteger initialScreenCount; + NSInteger a, b; } @property (nonatomic,retain) id popoverController; diff -r 3f605cca9215 -r abaf741a4e21 project_files/HedgewarsMobile/Classes/OverlayViewController.m --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Oct 14 16:01:43 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Oct 14 22:01:33 2010 +0200 @@ -45,29 +45,56 @@ @implementation OverlayViewController @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu; +#pragma mark - +#pragma mark rotation -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { - return rotationManager(interfaceOrientation); + if (IS_DUALHEAD()) + return YES; ////// TEST MEEEEE + else + return rotationManager(interfaceOrientation); } +// pause the game and remove objc menus so that animation is smoother +-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{ + [self dismissPopover]; + if (HW_isPaused() == NO) + HW_pause(); + if (self.amvc.isVisible && IS_DUALHEAD() == NO) { + [self.amvc disappear]; + wasVisible = YES; + } else + wasVisible = NO; + + [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; +} + +// now restore previous state +-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation { + if (wasVisible || IS_DUALHEAD()) + [self.amvc appearInView:self.view]; + if (HW_isPaused() == YES) + HW_pause(); + + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; +} + +// rotate the sdl view according to the orientation -- the uiview is autorotated -(void) didRotate:(NSNotification *)notification { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; - CGRect rect = [[UIScreen mainScreen] bounds]; - CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; [UIView beginAnimations:@"rotation" context:NULL]; - [UIView setAnimationDuration:0.8f]; - [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; + [UIView setAnimationDuration:0.7]; switch (orientation) { case UIDeviceOrientationLandscapeLeft: if (IS_DUALHEAD() == NO) - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a)); + //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); break; case UIDeviceOrientationLandscapeRight: if (IS_DUALHEAD() == NO) - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b)); + //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); break; case UIDeviceOrientationPortrait: if (IS_DUALHEAD()) @@ -81,63 +108,55 @@ // a debug log would spam too much break; } - if (self.amvc.isVisible) - [self.amvc appearInView:self.view]; - self.view.frame = usefulRect; [UIView commitAnimations]; - + // for single screens only landscape mode is supported // for dual screen mode the sdlview is not modified, but you can rotate the pad in any direction } #pragma mark - #pragma mark View Management --(void) viewDidLoad { - isGameRunning = NO; - isReplay = NO; - cachedGrenadeTime = 2; - isAttacking = NO; - - // i called it a popover even on the iphone - isPopoverVisible = NO; - self.view.alpha = 0; - self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); - - initialScreenCount = [[UIScreen screens] count]; +-(id) initWithCoder:(NSCoder *)aDecoder { + if ((self = [super initWithCoder:aDecoder])) { + isGameRunning = NO; + isReplay = NO; + cachedGrenadeTime = 2; + isAttacking = NO; + wasVisible = NO; + isPopoverVisible = NO; // it is called "popover" even on the iphone + } + return self; +} - if (IS_DUALHEAD()) { - // set initial orientation wrt the controller orientation - switch (self.interfaceOrientation) { - case UIDeviceOrientationLandscapeLeft: - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); - break; - case UIDeviceOrientationLandscapeRight: - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); - break; - case UIDeviceOrientationPortrait: - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); - break; - case UIDeviceOrientationPortraitUpsideDown: - self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); - break; - default: - DLog(@"Nope"); - break; - } - } +-(void) viewDidLoad { CGRect screenRect = [[UIScreen mainScreen] bounds]; self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); + self.view.alpha = 0; + self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2); + // get the number of screens to know the previous state whan a display is connected or detached + initialScreenCount = [[UIScreen screens] count]; + + // detrmine the quanitiy and direction of the rotation + if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { + a = 180; + b = 0; + } else { + a = 0; + b = 180; + } + + // the timer used to dim the overlay dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] interval:1000 target:self selector:@selector(dimOverlay) userInfo:nil repeats:YES]; - // add timer to runloop, otherwise it doesn't work [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; + // become listener of some notifications [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) @@ -163,7 +182,8 @@ selector:@selector(numberOfScreensDecreased) name:UIScreenDidDisconnectNotification object:nil]; - + + // present the overlay [UIView beginAnimations:@"showing overlay" context:NULL]; [UIView setAnimationDuration:1]; self.view.alpha = 1; @@ -209,6 +229,12 @@ doNotDim(); } +-(void) cleanup { + [self dismissPopover]; + HW_terminate(NO); + [self.view removeFromSuperview]; +} + -(void) didReceiveMemoryWarning { if (self.popupMenu.view.superview == nil) self.popupMenu = nil; @@ -245,14 +271,8 @@ [super dealloc]; } --(void) cleanup { - [self dismissPopover]; - HW_terminate(NO); - [self.view removeFromSuperview]; -} - #pragma mark - -#pragma mark Overlay actions and members +#pragma mark overlay user interaction // nice transition for dimming, should be called only by the timer himself -(void) dimOverlay { if (isGameRunning) { @@ -381,6 +401,22 @@ HW_preciseSet(NO); } +-(void) sendHWClick { + HW_click(); + removeConfirmationInput(); + doDim(); +} + +-(void) setGrenadeTime:(id) sender { + UISegmentedControl *theSegment = (UISegmentedControl *)sender; + if (cachedGrenadeTime != theSegment.selectedSegmentIndex) { + HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); + cachedGrenadeTime = theSegment.selectedSegmentIndex; + } +} + +#pragma mark - +#pragma mark other menu // present a further check before closing game -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { if ([actionSheet cancelButtonIndex] != buttonIndex) @@ -475,8 +511,6 @@ } } - //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { - -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGRect screen = [[UIScreen mainScreen] bounds]; NSSet *allTouches = [event allTouches]; @@ -564,20 +598,6 @@ initialDistanceForPinching = 0; } --(void) sendHWClick { - HW_click(); - removeConfirmationInput(); - doDim(); -} - --(void) setGrenadeTime:(id) sender { - UISegmentedControl *theSegment = (UISegmentedControl *)sender; - if (cachedGrenadeTime != theSegment.selectedSegmentIndex) { - HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); - cachedGrenadeTime = theSegment.selectedSegmentIndex; - } -} - -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesEnded:touches withEvent:event]; } @@ -642,7 +662,7 @@ } #pragma mark - -#pragma mark Functions called by pascal +#pragma mark Functions called by pascal code void inline setGameRunning(BOOL value) { isGameRunning = value; } diff -r 3f605cca9215 -r abaf741a4e21 project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Oct 14 16:01:43 2010 +0200 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Oct 14 22:01:33 2010 +0200 @@ -1458,7 +1458,7 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 1D6058900D05DD3D006BFB54 /* Test Lua */ = { + 1D6058900D05DD3D006BFB54 /* Hedgewars */ = { isa = PBXNativeTarget; buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "Hedgewars" */; buildPhases = ( @@ -1542,7 +1542,7 @@ ); projectRoot = ""; targets = ( - 1D6058900D05DD3D006BFB54 /* Test Lua */, + 1D6058900D05DD3D006BFB54 /* Hedgewars */, 928301160F10CAFC00CC5A3C /* fpc */, 6179928B114AE0C800BA94A9 /* UpdateDataFolder */, ); @@ -2696,7 +2696,7 @@ FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1; FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas"; FPC_RTL_UNITS_BASE = /usr/local/lib/fpc; - FPC_SPECIFIC_OPTIONS = "-Ci- -Cr- -Co- -O-2 -Xs -Cfvfpv2"; + FPC_SPECIFIC_OPTIONS = "-Ci- -Cr- -Co- -O-2 -Xs -Cfvfpv2 -dDEBUGFILE"; FPC_UNITS_PATH = "-Fu\"$(PROJECT_DIR)\""; GCC_C_LANGUAGE_STANDARD = c99; GCC_DEBUGGING_SYMBOLS = default;