# HG changeset patch # User nemo # Date 1417980988 18000 # Node ID 2f062fac5791b2750167068218176808f9865bb1 # Parent 5ae7ba0b2849aa0813eea783ac07cf44e949d16e Add that "make screenshots of Land/LandPixels" thing for map creators diff -r 5ae7ba0b2849 -r 2f062fac5791 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sat Dec 06 10:41:33 2014 -0500 +++ b/hedgewars/hwengine.pas Sun Dec 07 14:36:28 2014 -0500 @@ -123,10 +123,13 @@ if flagMakeCapture then begin flagMakeCapture:= false; + if flagDumpLand then + s:= '/Screenshots/mapdump_' + else s:= '/Screenshots/hw_'; {$IFDEF PAS2C} - s:= '/Screenshots/hw_' + inttostr(GameTicks); + s:= s + inttostr(GameTicks); {$ELSE} - s:= '/Screenshots/hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); + s:= s + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); {$ENDIF} // flash @@ -134,8 +137,8 @@ ScreenFade:= sfFromWhite; ScreenFadeValue:= sfMax; ScreenFadeSpeed:= 5; - - if MakeScreenshot(s, 1) then + + if (not flagDumpLand and MakeScreenshot(s, 1, 0)) or (flagDumpLand and MakeScreenshot(s, 1, 1) and MakeScreenshot(s, 1, 2)) then WriteLnToConsole('Screenshot saved: ' + s) else begin diff -r 5ae7ba0b2849 -r 2f062fac5791 hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Sat Dec 06 10:41:33 2014 -0500 +++ b/hedgewars/uCommandHandlers.pas Sun Dec 07 14:36:28 2014 -0500 @@ -487,7 +487,8 @@ procedure chCapture(var s: shortstring); begin s:= s; // avoid compiler hint -flagMakeCapture:= true +flagMakeCapture:= true; +flagDumpLand:= LocalMessage and gmPrecise <> 0; end; procedure chRecord(var s: shortstring); diff -r 5ae7ba0b2849 -r 2f062fac5791 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Sat Dec 06 10:41:33 2014 -0500 +++ b/hedgewars/uMisc.pas Sun Dec 07 14:36:28 2014 -0500 @@ -28,7 +28,7 @@ procedure movecursor(dx, dy: LongInt); function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; -function MakeScreenshot(filename: shortstring; k: LongInt): boolean; +function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; function GetTeamStatString(p: PTeam): shortstring; {$IFDEF SDL2} function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline; @@ -221,12 +221,13 @@ // captures and saves the screen. returns true on success. // saved image will be k times smaller than original (useful for saving thumbnails). -function MakeScreenshot(filename: shortstring; k: LongInt): Boolean; +function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): boolean; var p: Pointer; size: QWord; image: PScreenshot; format: GLenum; ext: string[4]; + x,y: LongWord; begin {$IFDEF PNG_SCREENSHOTS} format:= GL_RGBA; @@ -236,7 +237,9 @@ ext:= '.bmp'; {$ENDIF} -size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4; +if dump > 0 then + size:= LAND_WIDTH*LAND_HEIGHT*4 +else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4; p:= GetMem(size); // will be freed in SaveScreenshot() // memory could not be allocated @@ -248,17 +251,54 @@ end; // read pixels from the front buffer -glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p); - +if dump > 0 then + begin + for y:= 0 to LAND_HEIGHT-1 do + for x:= 0 to LAND_WIDTH-1 do + if dump = 2 then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= LandPixels[LAND_HEIGHT-1-y, x] + else + begin + if Land[LAND_HEIGHT-1-y, x] and lfIndestructible = lfIndestructible then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or RMask) + else if Land[LAND_HEIGHT-1-y, x] and lfIce = lfIce then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or BMask) + else if Land[LAND_HEIGHT-1-y, x] and lfBouncy = lfBouncy then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= (AMask or GMask) + else if Land[LAND_HEIGHT-1-y, x] and lfObject = lfObject then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= $FFFFFFFF + else if Land[LAND_HEIGHT-1-y, x] and lfBasic = lfBasic then + PLongWordArray(p)^[y*LAND_WIDTH+x]:= AMask + else + PLongWordArray(p)^[y*LAND_WIDTH+x]:= 0 + end + end +else + begin + glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p); {$IFDEF USE_VIDEO_RECORDING} -ReduceImage(p, cScreenWidth, cScreenHeight, k); + ReduceImage(p, cScreenWidth, cScreenHeight, k) {$ENDIF} + end; // allocate and fill structure that will be passed to new thread New(image); // will be disposed in SaveScreenshot() -image^.filename:= shortstring(UserPathPrefix) + filename + ext; -image^.width:= cScreenWidth div k; -image^.height:= cScreenHeight div k; +if dump = 2 then + image^.filename:= shortstring(UserPathPrefix) + filename + '_landpixels' + ext +else if dump = 1 then + image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext +else image^.filename:= shortstring(UserPathPrefix) + filename + '_land' + ext; + +if dump <> 0 then + begin + image^.width:= LAND_WIDTH; + image^.height:= LAND_HEIGHT + end +else + begin + image^.width:= cScreenWidth div k; + image^.height:= cScreenHeight div k + end; image^.size:= size; image^.buffer:= p; diff -r 5ae7ba0b2849 -r 2f062fac5791 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Sat Dec 06 10:41:33 2014 -0500 +++ b/hedgewars/uVariables.pas Sun Dec 07 14:36:28 2014 -0500 @@ -189,6 +189,7 @@ flagMakeCapture : boolean; + flagDumpLand : boolean; InitStepsFlags : Longword; RealTicks : Longword; @@ -2589,6 +2590,7 @@ cVampiric := false; cArtillery := false; flagMakeCapture := false; + flagDumpLand := false; bBetweenTurns := false; bWaterRising := false; isCursorVisible := false; diff -r 5ae7ba0b2849 -r 2f062fac5791 hedgewars/uVideoRec.pas --- a/hedgewars/uVideoRec.pas Sat Dec 06 10:41:33 2014 -0500 +++ b/hedgewars/uVideoRec.pas Sun Dec 07 14:36:28 2014 -0500 @@ -239,7 +239,7 @@ thumbpath:= '/VideoTemp/' + RecPrefix; AddFileLog('Saving thumbnail ' + thumbpath); k:= max(max(cScreenWidth, cScreenHeight) div 400, 1); // here 400 is minimum size of thumbnail - MakeScreenshot(thumbpath, k); + MakeScreenshot(thumbpath, k, 0); thumbnailSaved:= true; end;