258 |
258 |
259 procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
259 procedure LandSurface2LandPixels(Surface: PSDL_Surface); |
260 var x, y: LongInt; |
260 var x, y: LongInt; |
261 p: PLongwordArray; |
261 p: PLongwordArray; |
262 begin |
262 begin |
263 TryDo(Surface <> nil, 'Assert (LandSurface <> nil) failed', true); |
263 if checkFails(Surface <> nil, 'Assert (LandSurface <> nil) failed', true) then exit; |
264 |
264 |
265 if SDL_MustLock(Surface) then |
265 if SDL_MustLock(Surface) then |
266 if SDLCheck(SDL_LockSurface(Surface) >= 0, 'SDL_LockSurface', true) then exit; |
266 if SDLCheck(SDL_LockSurface(Surface) >= 0, 'SDL_LockSurface', true) then exit; |
267 |
267 |
268 p:= Surface^.pixels; |
268 p:= Surface^.pixels; |
289 begin |
289 begin |
290 AddProgress(); |
290 AddProgress(); |
291 |
291 |
292 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask); |
292 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask); |
293 |
293 |
294 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true); |
294 if checkFails(tmpsurf <> nil, 'Error creating pre-land surface', true) then exit; |
295 ColorizeLand(tmpsurf); |
295 ColorizeLand(tmpsurf); |
296 if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
296 if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
297 AddOnLandObjects(tmpsurf); |
297 AddOnLandObjects(tmpsurf); |
298 |
298 |
299 LandSurface2LandPixels(tmpsurf); |
299 LandSurface2LandPixels(tmpsurf); |
488 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps); |
488 tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifTransparent or ifIgnoreCaps); |
489 if tmpsurf = nil then |
489 if tmpsurf = nil then |
490 begin |
490 begin |
491 mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
491 mapName:= ExtractFileName(cPathz[ptMapCurrent]); |
492 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
492 tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); |
|
493 if not allOK then exit; |
493 end; |
494 end; |
494 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
495 // (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take |
495 TryDo((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true); |
496 if checkFails((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true) |
|
497 then exit; |
496 |
498 |
497 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
499 ResizeLand(tmpsurf^.w, tmpsurf^.h); |
498 LoadMapConfig; |
500 LoadMapConfig; |
499 |
501 |
500 playHeight:= tmpsurf^.h; |
502 playHeight:= tmpsurf^.h; |
501 playWidth:= tmpsurf^.w; |
503 playWidth:= tmpsurf^.w; |
502 leftX:= (LAND_WIDTH - playWidth) div 2; |
504 leftX:= (LAND_WIDTH - playWidth) div 2; |
503 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
505 rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
504 topY:= LAND_HEIGHT - playHeight; |
506 topY:= LAND_HEIGHT - playHeight; |
505 |
507 |
506 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true); |
508 if not checkFails(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true) then |
507 |
509 BlitImageAndGenerateCollisionInfo( |
508 BlitImageAndGenerateCollisionInfo( |
510 (LAND_WIDTH - tmpsurf^.w) div 2, |
509 (LAND_WIDTH - tmpsurf^.w) div 2, |
511 LAND_HEIGHT - tmpsurf^.h, |
510 LAND_HEIGHT - tmpsurf^.h, |
512 tmpsurf^.w, |
511 tmpsurf^.w, |
513 tmpsurf); |
512 tmpsurf); |
514 |
513 SDL_FreeSurface(tmpsurf); |
515 SDL_FreeSurface(tmpsurf); |
514 |
516 |
515 LoadMask; |
517 if allOK then LoadMask; |
516 end; |
518 end; |
517 |
519 |
518 procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
520 procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD |
519 var x, w, c: Longword; |
521 var x, w, c: Longword; |
520 begin |
522 begin |
795 begin |
797 begin |
796 AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); |
798 AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); |
797 if digest = '' then |
799 if digest = '' then |
798 digest:= s |
800 digest:= s |
799 else |
801 else |
800 TryDo(s = digest, 'Different maps generated, sorry', true); |
802 checkFails(s = digest, 'Different maps generated, sorry', true); |
801 end; |
803 end; |
802 |
804 |
803 procedure chSendLandDigest(var s: shortstring); |
805 procedure chSendLandDigest(var s: shortstring); |
804 var adler, i: LongInt; |
806 var adler, i: LongInt; |
805 begin |
807 begin |
809 s:= 'M' + IntToStr(adler) + cScriptName; |
811 s:= 'M' + IntToStr(adler) + cScriptName; |
810 |
812 |
811 ScriptSetString('LandDigest', s); |
813 ScriptSetString('LandDigest', s); |
812 |
814 |
813 chLandCheck(s); |
815 chLandCheck(s); |
814 SendIPCRaw(@s[0], Length(s) + 1) |
816 if allOK then SendIPCRaw(@s[0], Length(s) + 1) |
815 end; |
817 end; |
816 |
818 |
817 procedure initModule; |
819 procedure initModule; |
818 begin |
820 begin |
819 RegisterVariable('landcheck', @chLandCheck, false); |
821 RegisterVariable('landcheck', @chLandCheck, false); |