# HG changeset patch # User koda # Date 1272246926 0 # Node ID c7289e42f0ee688b80024f1529c1a84e98497d3f # Parent 791fa466420960ff342f1011f9836dbf60a70974 add other controls for map preview, also fix a bug in digest diff -r 791fa4664209 -r c7289e42f0ee cocoaTouch/GameConfigViewController.m --- a/cocoaTouch/GameConfigViewController.m Sun Apr 25 18:38:08 2010 +0000 +++ b/cocoaTouch/GameConfigViewController.m Mon Apr 26 01:55:26 2010 +0000 @@ -38,7 +38,7 @@ -(IBAction) segmentPressed:(id) sender { UISegmentedControl *theSegment = (UISegmentedControl *)sender; - NSLog(@"%d", theSegment.selectedSegmentIndex); + switch (theSegment.selectedSegmentIndex) { case 0: // this init here is just aestetic as this controller was already set up in viewDidLoad @@ -91,8 +91,11 @@ [alert show]; [alert release]; return; - } + } NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command", + mapConfigViewController.templateFilterCommand,@"templatefilter_command", + mapConfigViewController.mapGenCommand,@"mapgen_command", + mapConfigViewController.mazeSizeCommand,@"mazesize_command", teamConfigViewController.listOfSelectedTeams,@"teams_list",nil]; [dict writeToFile:GAMECONFIG_FILE() atomically:YES]; [dict release]; @@ -104,7 +107,7 @@ mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; activeController = mapConfigViewController; - [self.view insertSubview:mapConfigViewController.view atIndex:0]; + [self.view addSubview:mapConfigViewController.view]; [super viewDidLoad]; } diff -r 791fa4664209 -r c7289e42f0ee cocoaTouch/GameSetup.m --- a/cocoaTouch/GameSetup.m Sun Apr 25 18:38:08 2010 +0000 +++ b/cocoaTouch/GameSetup.m Mon Apr 26 01:55:26 2010 +0000 @@ -198,7 +198,9 @@ [self sendToEngine:@"e$casefreq 5"]; // dimension of the map - [self sendToEngine:@"e$template_filter 1"]; + [self sendToEngine:[self.gameConfig objectForKey:@"templatefilter_command"]]; + [self sendToEngine:[self.gameConfig objectForKey:@"mapgen_command"]]; + [self sendToEngine:[self.gameConfig objectForKey:@"mazesize_command"]]; // theme info [self sendToEngine:@"etheme Compost"]; @@ -290,6 +292,8 @@ SDLNet_TCP_Close(sd); SDLNet_Quit(); + [[NSFileManager defaultManager] removeItemAtPath:GAMECONFIG_FILE() error:NULL]; + [pool release]; [NSThread exit]; } @@ -302,7 +306,7 @@ CGRect screenBounds = [[UIScreen mainScreen] bounds]; NSString *wSize = [[NSString alloc] initWithFormat:@"%d", (int) screenBounds.size.width]; NSString *hSize = [[NSString alloc] initWithFormat:@"%d", (int) screenBounds.size.height]; - const char **gameArgs = (const char**) malloc(sizeof(char*) * 8); + const char **gameArgs = (const char**) malloc(sizeof(char *) * 8); /* size_t size; @@ -333,14 +337,14 @@ username = [[NSString alloc] initWithString:originalUsername]; } - gameArgs[0] = [username UTF8String]; //UserNick - gameArgs[1] = [ipcString UTF8String]; //ipcPort - gameArgs[2] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled - gameArgs[3] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled - gameArgs[4] = [localeString UTF8String]; //cLocaleFName + gameArgs[0] = [username UTF8String]; //UserNick + gameArgs[1] = [ipcString UTF8String]; //ipcPort + gameArgs[2] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled + gameArgs[3] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled + gameArgs[4] = [localeString UTF8String]; //cLocaleFName gameArgs[5] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage - gameArgs[6] = [wSize UTF8String]; //cScreenHeight - gameArgs[7] = [hSize UTF8String]; //cScreenWidth + gameArgs[6] = [wSize UTF8String]; //cScreenHeight + gameArgs[7] = [hSize UTF8String]; //cScreenWidth [wSize release]; [hSize release]; diff -r 791fa4664209 -r c7289e42f0ee cocoaTouch/MapConfigViewController.h --- a/cocoaTouch/MapConfigViewController.h Sun Apr 25 18:38:08 2010 +0000 +++ b/cocoaTouch/MapConfigViewController.h Mon Apr 26 01:55:26 2010 +0000 @@ -9,20 +9,43 @@ #import #import "SDL_net.h" -@interface MapConfigViewController : UIViewController { +@interface MapConfigViewController : UIViewController { TCPsocket sd, csd; - NSInteger maxHogs; unsigned char map[128*32]; + // objects read (mostly) by parent view + NSInteger maxHogs; + NSString *seedCommand; + NSString *templateFilterCommand; + NSString *mapGenCommand; + NSString *mazeSizeCommand; + + // various widgets in the view UIButton *previewButton; - NSString *seedCommand; + UITableView *tableView; + UILabel *maxLabel; + UILabel *sizeLabel; + UISegmentedControl *segmentedControl; + UISlider *slider; } @property (nonatomic) NSInteger maxHogs; -@property (nonatomic,retain) UIButton *previewButton; @property (nonatomic,retain) NSString *seedCommand; +@property (nonatomic,retain) NSString *templateFilterCommand; +@property (nonatomic,retain) NSString *mapGenCommand; +@property (nonatomic,retain) NSString *mazeSizeCommand; +@property (nonatomic,retain) IBOutlet UIButton *previewButton; +@property (nonatomic,retain) IBOutlet UITableView *tableView; +@property (nonatomic,retain) IBOutlet UILabel *maxLabel; +@property (nonatomic,retain) IBOutlet UILabel *sizeLabel; +@property (nonatomic,retain) IBOutlet UISegmentedControl *segmentedControl; +@property (nonatomic,retain) IBOutlet UISlider *slider; -(IBAction) updatePreview; +-(IBAction) sliderChanged:(id) sender; +-(IBAction) sliderEndedChanging:(id) sender; +-(IBAction) segmentedControlChanged:(id) sender; + -(void) engineProtocol:(NSInteger) port; @end diff -r 791fa4664209 -r c7289e42f0ee cocoaTouch/MapConfigViewController.m --- a/cocoaTouch/MapConfigViewController.m Sun Apr 25 18:38:08 2010 +0000 +++ b/cocoaTouch/MapConfigViewController.m Mon Apr 26 01:55:26 2010 +0000 @@ -13,8 +13,11 @@ #import "SDL_net.h" #import +#define INDICATOR_TAG 7654 +#define RANDOMSTR_LEN 36 @implementation MapConfigViewController -@synthesize previewButton, maxHogs, seedCommand; +@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, + tableView, maxLabel, sizeLabel, segmentedControl, slider; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { @@ -62,9 +65,9 @@ NSLog(@"engineProtocol - Client found"); [self sendToEngine:self.seedCommand]; - [self sendToEngine:@"e$template_filter 1"]; - [self sendToEngine:@"e$mapgen 0"]; - [self sendToEngine:@"e$maze_size 1"]; + [self sendToEngine:self.templateFilterCommand]; + [self sendToEngine:self.mapGenCommand]; + [self sendToEngine:self.mazeSizeCommand]; [self sendToEngine:@"!"]; memset(map, 0, 128*32); @@ -80,21 +83,12 @@ SDLNet_Quit(); } - --(void) updatePreview { - pthread_t thread_id; +-(void) drawingThread { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - // generate a seed - char randomStr[36]; - for (int i = 0; i<36; i++) { - randomStr[i] = random()%255; - } - NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%s}", randomStr]; - self.seedCommand = seedCmd; - [seedCmd release]; - - // select the port for IPC + // select the port for IPC and launch the preview generation int port = randomPort(); + pthread_t thread_id; pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port); [self engineProtocol:port]; @@ -104,9 +98,9 @@ UIGraphicsBeginImageContext(CGSizeMake(256,128)); CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(context); - for (int x = 0; x < 32*128; x++) { - unsigned char byte = map[x]; - for (int z = 0; z < 8; z++) { + for (int i = 0; i < 32*128; i++) { + unsigned char byte = map[i]; + for (int j = 0; j < 8; j++) { // select the color based on the rightmost bit if ((byte & 0x00000001) != 0) CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0); @@ -116,7 +110,7 @@ // draw pixel CGContextFillRect(context,CGRectMake(xc,yc,1,1)); // move coordinates - xc = (xc+1)%256; + xc = (xc + 1) % 256; if (xc == 0) yc++; // shift to next bit @@ -124,12 +118,23 @@ } } UIGraphicsPopContext(); - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); - // set the image in the button - [self.previewButton setImage:image forState:UIControlStateNormal]; + + // set the preview image (autoreleased) in the button and the maxhog label + [self.previewButton setBackgroundImage:previewImage forState:UIControlStateNormal]; + self.maxLabel.text = [NSString stringWithFormat:@"%d", maxHogs]; + // restore functionality of button and remove the spinning wheel + [self turnOnWidgets]; + UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.previewButton viewWithTag:INDICATOR_TAG]; + [indicator stopAnimating]; + [indicator removeFromSuperview]; + + [pool release]; + [NSThread exit]; + /* // http://developer.apple.com/mac/library/qa/qa2001/qa1037.html CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray(); @@ -142,6 +147,180 @@ */ } +-(void) turnOffWidgets { + self.previewButton.alpha = 0.5f; + self.previewButton.enabled = NO; + self.maxLabel.text = @"..."; + self.segmentedControl.enabled = NO; + self.tableView.allowsSelection = NO; + self.slider.enabled = NO; +} + +-(void) turnOnWidgets { + self.previewButton.alpha = 1.0f; + self.previewButton.enabled = YES; + self.segmentedControl.enabled = YES; + self.tableView.allowsSelection = YES; + self.slider.enabled = YES; +} + +-(IBAction) updatePreview { + // prevent other events and add an activity while the preview is beign generated + [self turnOffWidgets]; + + // remove the current preview + [self.previewButton setImage:nil forState:UIControlStateNormal]; + + // add a very nice spinning wheel + UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] + initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; + indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2); + indicator.tag = INDICATOR_TAG; + [indicator startAnimating]; + [self.previewButton addSubview:indicator]; + [indicator release]; + + // generate a seed + char randomStr[RANDOMSTR_LEN+1]; + for (int i = 0; i < RANDOMSTR_LEN; ) { + randomStr[i] = random() % 255; + if (randomStr[i] >= '0' && randomStr[i] <= '9' || randomStr[i] >= 'a' && randomStr[i] <= 'z') + i++; + } + randomStr[ 8] = '-'; + randomStr[13] = '-'; + randomStr[18] = '-'; + randomStr[23] = '-'; + randomStr[RANDOMSTR_LEN] = '\0'; + NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%s}", randomStr]; + self.seedCommand = seedCmd; + [seedCmd release]; + + // let's draw in a separate thread so the gui can work; also it restores the preview button + [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil]; +} + +#pragma mark - +#pragma mark Table view data source +-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 1; +} + +-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier = @"Cell"; + + UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + + return cell; +} + +#pragma mark - +#pragma mark slider & segmentedControl +-(IBAction) sliderChanged:(id) sender { + NSString *labelText; + NSString *templateCommand; + NSString *mazeCommand; + + switch ((int)(slider.value*100)) { + case 0: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"Wacky",@""); + } else { + labelText = NSLocalizedString(@"Large Floating Islands",@""); + } + templateCommand = @"e$template_filter 5"; + mazeCommand = @"e$maze_size 5"; + break; + case 1: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"Cavern",@""); + } else { + labelText = NSLocalizedString(@"Medium Floating Islands",@""); + } + templateCommand = @"e$template_filter 4"; + mazeCommand = @"e$maze_size 4"; + break; + case 2: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"Small",@""); + } else { + labelText = NSLocalizedString(@"Small Floating Islands",@""); + } + templateCommand = @"e$template_filter 1"; + mazeCommand = @"e$maze_size 3"; + break; + case 3: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"Medium",@""); + } else { + labelText = NSLocalizedString(@"Large Tunnels",@""); + } + templateCommand = @"e$template_filter 2"; + mazeCommand = @"e$maze_size 2"; + break; + case 4: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"Large",@""); + } else { + labelText = NSLocalizedString(@"Medium Tunnels",@""); + } + templateCommand = @"e$template_filter 3"; + mazeCommand = @"e$maze_size 1"; + break; + case 5: + if (self.segmentedControl.selectedSegmentIndex == 0) { + labelText = NSLocalizedString(@"All",@""); + } else { + labelText = NSLocalizedString(@"Small Tunnels",@""); + } + templateCommand = @"e$template_filter 0"; + mazeCommand = @"e$maze_size 0"; + break; + default: + break; + } + self.sizeLabel.text = labelText; + self.templateFilterCommand = templateCommand; + self.mazeSizeCommand = mazeCommand; +} + +// update preview as soon as the user lifts its finger +-(IBAction) sliderEndedChanging:(id) sender { + if (self.previewButton.enabled == YES) + [self updatePreview]; +} + +-(IBAction) segmentedControlChanged:(id) sender { + NSString *mapgen; + + switch (segmentedControl.selectedSegmentIndex) { + case 0: // Random + mapgen = @"e$mapgen 0"; + [self sliderChanged:nil]; + if (self.previewButton.enabled == YES) + [self updatePreview]; + break; + case 1: // Map + mapgen = @"e$mapgen 0"; + // other stuff + break; + case 2: // Maze + mapgen = @"e$mapgen 1"; + [self sliderChanged:nil]; + if (self.previewButton.enabled == YES) + [self updatePreview]; + + break; + } + self.mapGenCommand = mapgen; +} + #pragma mark - #pragma mark view management -(void) viewDidLoad { @@ -150,13 +329,12 @@ CGSize screenSize = [[UIScreen mainScreen] bounds].size; self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); - - UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - button.frame = CGRectMake(32, 32, 256, 128); - [button addTarget:self action:@selector(updatePreview) forControlEvents:UIControlEventTouchUpInside]; - self.previewButton = button; - [button release]; - [self.view addSubview:self.previewButton]; + + self.sizeLabel.text = NSLocalizedString(@"All",@""); + self.templateFilterCommand = @"e$template_filter 0"; + self.segmentedControl.selectedSegmentIndex == 0; + self.mazeSizeCommand = @"e$maze_size 0"; + self.mapGenCommand = @"e$mapgen 0"; } -(void) viewWillAppear:(BOOL)animated { @@ -175,14 +353,30 @@ -(void) viewDidUnload { self.previewButton = nil; self.seedCommand = nil; + self.seedCommand = nil; + self.templateFilterCommand = nil; + self.mapGenCommand = nil; + self.mazeSizeCommand = nil; + self.previewButton = nil; + self.tableView = nil; + self.maxLabel = nil; + self.sizeLabel = nil; + self.segmentedControl = nil; + self.slider = nil; [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; } -(void) dealloc { + [seedCommand release]; + [templateFilterCommand release]; + [mapGenCommand release]; + [mazeSizeCommand release]; [previewButton release]; - [seedCommand release]; + [tableView release]; + [maxLabel release]; + [sizeLabel release]; + [segmentedControl release]; + [slider release]; [super dealloc]; } diff -r 791fa4664209 -r c7289e42f0ee cocoaTouch/xib/MapConfigViewController-iPhone.xib --- a/cocoaTouch/xib/MapConfigViewController-iPhone.xib Sun Apr 25 18:38:08 2010 +0000 +++ b/cocoaTouch/xib/MapConfigViewController-iPhone.xib Mon Apr 26 01:55:26 2010 +0000 @@ -12,7 +12,7 @@ YES - + YES @@ -42,27 +42,20 @@ 274 YES - - - 290 - {{240, 60}, {240, 216}} - - IBCocoaTouchFramework - YES - 292 - {{240, 9}, {240, 44}} + {{28, 166}, {240, 30}} NO IBCocoaTouchFramework + 2 3 0 YES + Random Map - Random Maze @@ -93,7 +86,7 @@ 292 - {{18.5, 234}, {150, 23}} + {{121, 209}, {149, 23}} NO IBCocoaTouchFramework @@ -102,13 +95,96 @@ 0.05000000074505806 0.05000000074505806 + + + 292 + {{20, 20}, {256, 128}} + + NO + IBCocoaTouchFramework + 0 + 0 + + Helvetica-Bold + 15 + 16 + + 1 + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + + + 274 + {{295, 0}, {185, 276}} + + + YES + IBCocoaTouchFramework + NO + 1 + 0 + YES + 44 + 22 + 22 + + + + 292 + {{54, 234}, {42, 21}} + + NO + YES + 7 + NO + IBCocoaTouchFramework + ... + + 1 + MCAwIDAAA + + + 1 + 10 + 1 + + + + 292 + {{123, 239}, {145, 29}} + + NO + YES + 7 + NO + IBCocoaTouchFramework + Label + + Helvetica + 24 + 16 + + + + 1 + 10 + 1 + {480, 276} - - 3 - MQA - + 3 @@ -127,6 +203,98 @@ 3 + + + updatePreview + + + 7 + + 12 + + + + previewButton + + + + 13 + + + + dataSource + + + + 14 + + + + delegate + + + + 15 + + + + maxLabel + + + + 16 + + + + sizeLabel + + + + 18 + + + + sliderChanged: + + + 13 + + 19 + + + + sliderEndedChanging: + + + 7 + + 20 + + + + segmentedControl + + + + 21 + + + + segmentedControlChanged: + + + 13 + + 22 + + + + slider + + + + 23 + @@ -142,9 +310,12 @@ YES + + + - + @@ -160,11 +331,6 @@ - 6 - - - - 7 @@ -174,6 +340,26 @@ + + 9 + + + + + 10 + + + + + 11 + + + + + 17 + + + @@ -184,15 +370,21 @@ -2.CustomClassName 1.IBEditorWindowLastContentRect 1.IBPluginDependency - 6.IBPluginDependency + 10.IBPluginDependency + 11.IBPluginDependency + 17.IBPluginDependency 7.IBPluginDependency 8.IBPluginDependency + 9.IBPluginDependency YES MapConfigViewController UIResponder - {{556, 572}, {480, 320}} + {{744, 568}, {480, 320}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -215,7 +407,7 @@ - 8 + 23 @@ -223,6 +415,44 @@ MapConfigViewController UIViewController + + YES + + YES + segmentedControlChanged: + sliderChanged: + sliderEndedChanging: + updatePreview + + + YES + id + id + id + id + + + + YES + + YES + maxLabel + previewButton + segmentedControl + sizeLabel + slider + tableView + + + YES + UILabel + UIButton + UISegmentedControl + UILabel + UISlider + UITableView + + IBProjectSource ../../cocoaTouch/MapConfigViewController.h @@ -365,6 +595,14 @@ + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + UIControl UIView @@ -373,11 +611,11 @@ - UIPickerView + UILabel UIView IBFrameworkSource - UIKit.framework/Headers/UIPickerView.h + UIKit.framework/Headers/UILabel.h @@ -386,6 +624,14 @@ + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + UISearchBar UIView @@ -418,6 +664,14 @@ + UITableView + UIScrollView + + IBFrameworkSource + UIKit.framework/Headers/UITableView.h + + + UIView IBFrameworkSource @@ -481,7 +735,7 @@ YES - ../project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj + ../../project_files/HedgewarsMobile/Hedgewars.xcodeproj 3 87 diff -r 791fa4664209 -r c7289e42f0ee hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sun Apr 25 18:38:08 2010 +0000 +++ b/hedgewars/hwengine.pas Mon Apr 26 01:55:26 2010 +0000 @@ -349,7 +349,7 @@ //uLandTexture does not need initialization //uLocale does not need initialization uRandom.initModule; - //uSHA does not need initialization + //uSHA is initialized internally uSound.initModule; uStats.initModule; uStore.initModule; @@ -391,7 +391,7 @@ uConsole.freeModule; uConsts.freeModule; //stub uScript.freeModule; -// uMisc closes the debug log. + // uMisc closes the debug log. uMisc.freeModule; end; diff -r 791fa4664209 -r c7289e42f0ee hedgewars/uLand.pas --- a/hedgewars/uLand.pas Sun Apr 25 18:38:08 2010 +0000 +++ b/hedgewars/uLand.pas Mon Apr 26 01:55:26 2010 +0000 @@ -35,6 +35,7 @@ isMap: boolean; playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword; // idea is that a template can specify height/width. Or, a map, a height/width by the dimensions of the image. If the map has pixels near top of image, it triggers border. LandBackSurface: PSDL_Surface; + digest: shortstring; type direction = record x, y: LongInt; end; const DIR_N: direction = (x: 0; y: -1); @@ -80,15 +81,14 @@ end; procedure CheckLandDigest(s: shortstring); -const digest: shortstring = ''; begin {$IFDEF DEBUGFILE} -AddFileLog('CheckLandDigest: ' + s); + AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); {$ENDIF} -if digest = '' then - digest:= s -else - TryDo(s = digest, 'Different maps generated, sorry', true) + if digest = '' then + digest:= s + else + TryDo(s = digest, 'Different maps generated, sorry', true); end; procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword); @@ -1311,6 +1311,7 @@ procedure initModule; begin LandBackSurface:= nil; + digest:= ''; FillChar(LandPixels, sizeof(TLandArray), 0); end; diff -r 791fa4664209 -r c7289e42f0ee hedgewars/uRandom.pas --- a/hedgewars/uRandom.pas Sun Apr 25 18:38:08 2010 +0000 +++ b/hedgewars/uRandom.pas Mon Apr 26 01:55:26 2010 +0000 @@ -99,6 +99,7 @@ procedure initModule; begin n:= 54; + FillChar(cirbuf, 64*sizeof(Longword), 0); end; procedure freeModule; diff -r 791fa4664209 -r c7289e42f0ee hedgewars/uSHA.pas --- a/hedgewars/uSHA.pas Sun Apr 25 18:38:08 2010 +0000 +++ b/hedgewars/uSHA.pas Mon Apr 26 01:55:26 2010 +0000 @@ -122,41 +122,43 @@ procedure SHA1UpdateLongwords(var Context: TSHA1Context; Buf: PLongwordArray; Length: LongWord); var i: Longword; begin -for i:= 0 to Pred(Length div 4) do + for i:= 0 to Pred(Length div 4) do begin - SDLNet_Write32(Buf^[i], @Context.Buf[Context.CurrLength]); - inc(Context.CurrLength, 4); - if Context.CurrLength = 64 then - begin - SHA1Hash(Context); - inc(Context.Length, 512); - Context.CurrLength:= 0 - end + SDLNet_Write32(Buf^[i], @Context.Buf[Context.CurrLength]); + inc(Context.CurrLength, 4); + if Context.CurrLength = 64 then + begin + SHA1Hash(Context); + inc(Context.Length, 512); + Context.CurrLength:= 0 + end end end; function SHA1Final(Context: TSHA1Context): TSHA1Digest; var i: LongWord; begin -Context.Length:= Context.Length + Context.CurrLength shl 3; -Context.Buf[Context.CurrLength]:= $80; -inc(Context.CurrLength); + Context.Length:= Context.Length + Context.CurrLength shl 3; + Context.Buf[Context.CurrLength]:= $80; + inc(Context.CurrLength); -if Context.CurrLength > 56 then - begin - FillChar(Context.Buf[Context.CurrLength], 64 - Context.CurrLength, 0); - Context.CurrLength:= 64; - SHA1Hash(Context); - Context.CurrLength:=0 - end; + if Context.CurrLength > 56 then + begin + FillChar(Context.Buf[Context.CurrLength], 64 - Context.CurrLength, 0); + Context.CurrLength:= 64; + SHA1Hash(Context); + Context.CurrLength:=0 + end; -FillChar(Context.Buf[Context.CurrLength], 56 - Context.CurrLength, 0); + FillChar(Context.Buf[Context.CurrLength], 56 - Context.CurrLength, 0); -for i:= 56 to 63 do - Context.Buf[i] := (Context.Length shr ((63 - i) * 8)) and $FF; -SHA1Hash(Context); -for i:= 0 to 4 do SHA1Final[i]:= Context.H[i]; -FillChar(Context, sizeof(Context), 0) + for i:= 56 to 63 do + Context.Buf[i] := (Context.Length shr ((63 - i) * 8)) and $FF; + SHA1Hash(Context); + for i:= 0 to 4 do + SHA1Final[i]:= Context.H[i]; + + FillChar(Context, sizeof(Context), 0) end; end.