Ignore:
Timestamp:
May 21, 2020, 8:17:38 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Update from trunk rev 245.
  • Modified: Vcl prefix/suffix changed to Native.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/LocalPlayer/Term.pas

    r244 r246  
    287287    Offscreen: TDpiBitmap;
    288288    OffscreenUser: TDpiForm;
    289     procedure CreateParams(var p: TCreateParams); override;
    290289    procedure Client(Command, NewPlayer: integer; var Data);
    291290    procedure SetAIName(p: integer; Name: string);
     
    532531  SmallScreen, GameOK, MapValid, skipped, idle: boolean;
    533532
    534   SaveOption: array [0..nSaveOption - 1] of integer;
    535   MiniColors: array [0..fTerrain, 0..1] of TColor;
     533  SaveOption: array [0 .. nSaveOption - 1] of integer;
     534  MiniColors: array [0 .. 11, 0 .. 1] of TColor;
    536535  MainMap: TIsoMap;
    537536  CurrentMoveInfo: record AfterMovePaintRadius, AfterAttackExpeller: integer;
     
    555554  Sharpen = 80;
    556555type
    557   TBuffer = array [0 .. 99999, 0 .. 2] of integer;
     556  TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    558557var
    559   sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch, xdivider,
    560     ydivider: integer;
    561   resampled: ^TBuffer;
     558  Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;
     559  xdivider, ydivider: Integer;
     560  Resampled: ^TBuffer;
    562561  PixelPtr: TPixelPointer;
    563562begin
    564   nx := BigImp.width div xSizeBig * xSizeSmall;
    565   ny := BigImp.height div ySizeBig * ySizeSmall;
     563  nx := BigImp.Width div xSizeBig * xSizeSmall;
     564  ny := BigImp.Height div ySizeBig * ySizeSmall;
    566565
    567566  // resample icons
    568   GetMem(resampled, nx * ny * 12);
    569   FillChar(resampled^, nx * ny * 12, 0);
     567  GetMem(Resampled, nx * ny * 12);
     568  FillChar(Resampled^, nx * ny * 12, 0);
    570569  BigImp.BeginUpdate;
    571   for ix := 0 to BigImp.width div xSizeBig - 1 do
    572     for iy := 0 to BigImp.height div ySizeBig - 1 do
    573       for y := 0 to ySizeBig - 2 * cut - 1 do
    574       begin
    575         ydivider := (y * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
    576           (ySizeBig - 2 * cut) - y * ySizeSmall;
     570  for ix := 0 to BigImp.Width div xSizeBig - 1 do
     571    for iy := 0 to BigImp.Height div ySizeBig - 1 do begin
     572      PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig),
     573        ScaleToNative(cut + iy * ySizeBig));
     574      for y := 0 to ScaleToNative(ySizeBig - 2 * cut) - 1 do begin
     575        ydivider := (ScaleFromNative(y) * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
     576          (ySizeBig - 2 * cut) - ScaleFromNative(y) * ySizeSmall;
    577577        if ydivider > ySizeSmall then
    578578          ydivider := ySizeSmall;
    579         PixelPtr := PixelPointer(BigImp, 0, cut + iy * ySizeBig + y);
    580         for x := 0 to xSizeBig - 1 do
    581         begin
    582           ir := ix * xSizeSmall + iy * nx * ySizeSmall + x *
    583             xSizeSmall div xSizeBig + y *
     579        for x := 0 to ScaleToNative(xSizeBig) - 1 do begin
     580          ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(x) *
     581            xSizeSmall div xSizeBig + ScaleFromNative(y) *
    584582            ySizeSmall div (ySizeBig - 2 * cut) * nx;
    585           xdivider := (x * xSizeSmall div xSizeBig + 1) * xSizeBig - x *
    586             xSizeSmall;
     583          xdivider := (ScaleFromNative(x) * xSizeSmall div xSizeBig + 1) *
     584            xSizeBig - ScaleFromNative(x) * xSizeSmall;
    587585          if xdivider > xSizeSmall then
    588586            xdivider := xSizeSmall;
    589           for ch := 0 to 2 do
    590           begin
    591             PixelPtr.SetX(ix * xSizeBig + x);
     587          for ch := 0 to 2 do begin
    592588            c := PixelPtr.Pixel^.Planes[ch];
    593             inc(resampled[ir, ch], c * xdivider * ydivider);
     589            Inc(Resampled[ir, ch], c * xdivider * ydivider);
    594590            if xdivider < xSizeSmall then
    595               inc(resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
     591              Inc(Resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
    596592                ydivider);
    597593            if ydivider < ySizeSmall then
    598               inc(resampled[ir + nx, ch],
     594              Inc(Resampled[ir + nx, ch],
    599595                c * xdivider * (ySizeSmall - ydivider));
    600596            if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    601               inc(resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
     597              Inc(Resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
    602598                (ySizeSmall - ydivider));
    603599          end;
     600          PixelPtr.NextPixel;
    604601        end;
     602        PixelPtr.NextLine;
    605603      end;
     604    end;
    606605  BigImp.EndUpdate;
    607606
    608   // sharpen resampled icons
     607  // Sharpen Resampled icons
    609608  SmallImp.SetSize(nx, ny);
    610609  SmallImp.BeginUpdate;
    611   for y := 0 to ny - 1 do begin
    612     PixelPtr := PixelPointer(SmallImp, 0, y);
    613     for x := 0 to nx - 1 do
     610  PixelPtr := PixelPointer(SmallImp);
     611  for y := 0 to ScaleToNative(ny) - 1 do begin
     612    for x := 0 to ScaleToNative(nx) - 1 do begin
    614613      for ch := 0 to 2 do begin
    615         sum := 0;
     614        Sum := 0;
    616615        Cnt := 0;
    617616        for dy := -1 to 1 do
    618           if ((dy >= 0) or (y mod ySizeSmall > 0)) and
    619             ((dy <= 0) or (y mod ySizeSmall < ySizeSmall - 1)) then
     617          if ((dy >= 0) or (ScaleFromNative(y) mod ySizeSmall > 0)) and
     618            ((dy <= 0) or (ScaleFromNative(y) mod ySizeSmall < ySizeSmall - 1)) then
    620619            for dx := -1 to 1 do
    621               if ((dx >= 0) or (x mod xSizeSmall > 0)) and
    622                 ((dx <= 0) or (x mod xSizeSmall < xSizeSmall - 1)) then
     620              if ((dx >= 0) or (ScaleFromNative(x) mod xSizeSmall > 0)) and
     621                ((dx <= 0) or (ScaleFromNative(x) mod xSizeSmall < xSizeSmall - 1)) then
    623622              begin
    624                 inc(sum, resampled[x + dx + nx * (y + dy), ch]);
    625                 inc(Cnt);
     623                Inc(Sum, Resampled[ScaleFromNative(x) + dx + nx * (ScaleFromNative(y) + dy), ch]);
     624                Inc(Cnt);
    626625              end;
    627         sum := ((Cnt * Sharpen + 800) * resampled[x + nx * y, ch] - sum *
     626        Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(x) + nx * ScaleFromNative(y), ch] - Sum *
    628627          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * cut));
    629         if sum < 0 then sum := 0;
    630         if sum > 255 then sum := 255;
    631         PixelPtr.SetX(x);
    632         PixelPtr.Pixel^.Planes[ch] := sum;
     628        if Sum < 0 then Sum := 0;
     629        if Sum > 255 then Sum := 255;
     630        PixelPtr.Pixel^.Planes[ch] := Sum;
    633631      end;
     632      PixelPtr.NextPixel;
     633    end;
     634    PixelPtr.NextLine;
    634635  end;
    635636  SmallImp.EndUpdate;
    636   FreeMem(resampled);
     637  FreeMem(Resampled);
    637638end;
    638639
     
    33993400{ *** main part *** }
    34003401
    3401 procedure TMainScreen.CreateParams(var p: TCreateParams);
    3402 begin
    3403   inherited;
    3404   if FullScreen then begin
    3405     p.Style := $87000000;
    3406     BorderStyle := bsNone;
    3407     BorderIcons := [];
    3408   end;
    3409 end;
    3410 
    34113402procedure TMainScreen.FormCreate(Sender: TObject);
    34123403var
     
    40774068  MiniPixel := PixelPointer(Mini);
    40784069  PrevMiniPixel := PixelPointer(Mini);
    4079   for y := 0 to ScaleToVcl(G.ly) - 1 do
    4080   begin
    4081     for x := 0 to ScaleToVcl(G.lx) - 1 do
    4082       if MyMap[ScaleFromVcl(x) + G.lx * ScaleFromVcl(y)] and fTerrain <> fUNKNOWN then
    4083       begin
    4084         Loc := ScaleFromVcl(x) + G.lx * ScaleFromVcl(y);
     4070  for y := 0 to ScaleToNative(G.ly) - 1 do
     4071  begin
     4072    for x := 0 to ScaleToNative(G.lx) - 1 do
     4073      if MyMap[ScaleFromNative(x) + G.lx * ScaleFromNative(y)] and fTerrain <> fUNKNOWN then
     4074      begin
     4075        Loc := ScaleFromNative(x) + G.lx * ScaleFromNative(y);
    40854076        for i := 0 to 1 do
    40864077        begin
    4087           xm := ((x - ScaleToVcl(xwMini)) * 2 + i + y and 1 - ScaleToVcl(hw) +
    4088             ScaleToVcl(G.lx) * 5) mod (ScaleToVcl(G.lx) * 2);
     4078          xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
     4079            ScaleToNative(G.lx) * 5) mod (ScaleToNative(G.lx) * 2);
    40894080          MiniPixel.SetXY(xm, y);
    40904081          cm := MiniColors[MyMap[Loc] and fTerrain, i];
     
    60926083      NoMap.PaintUnit(xMoving - xMin, yMoving - yMin, UnitInfo, 0);
    60936084      PaintBufferToScreen(xMin, yMin, xRange, yRange);
     6085      {$IFDEF LINUX}
     6086      // TODO: Force animation under linux
     6087      DpiApplication.ProcessMessages;
     6088      {$ENDIF}
    60946089
    60956090      SliceCount := 0;
     
    60976092      repeat
    60986093        if (SliceCount = 0) or
    6099           (MillisecondOf(Ticks - Ticks0) * 12 * (SliceCount + 1) div SliceCount
     6094          (Round(((Ticks - Ticks0) * 12) / OneMillisecond) * (SliceCount + 1) div SliceCount
    61006095          < MoveTime) then
    61016096        begin
    61026097          if not idle or (GameMode = cMovie) then
    61036098            DpiApplication.ProcessMessages;
    6104           {$IFDEF LINUX}
    6105           // TODO: Force animation under linux
    6106           DpiApplication.ProcessMessages;
    6107           {$ENDIF}
    61086099          Sleep(1);
    61096100          inc(SliceCount)
    61106101        end;
    61116102        Ticks := NowPrecise;
    6112       until (Ticks - Ticks0) / OneMillisecond * 12 >= MoveTime;
     6103      until (((Ticks - Ticks0) * 12) / OneMillisecond) >= MoveTime;
    61136104      Ticks0 := Ticks
    61146105    end;
     
    65516542          time1 := NowPrecise;
    65526543          SimpleMessage(Format('Map repaint time: %.3f ms',
    6553             [MillisecondOf(time1 - time0)]));
     6544            [(time1 - time0) / OneMillisecond]));
    65546545        end
    65556546    end
     
    76287619        InitPopup(GamePopup);
    76297620        if FullScreen then
    7630           // GamePopup.FItems.Count
    76317621          GamePopup.Popup(Left, Top + TopBarHeight - 1)
    76327622        else
     
    78077797procedure TMainScreen.FormShow(Sender: TObject);
    78087798begin
    7809   Timer1.Enabled := true;
    7810   Left := 0;
    7811   Top := 0;
     7799  if FullScreen then begin
     7800    WindowState := wsFullScreen;
     7801    BorderStyle := bsNone;
     7802    BorderIcons := [];
     7803  end else begin
     7804    WindowState := wsMaximized;
     7805    BorderStyle := bsSizeable;
     7806    BorderIcons := [biSystemMenu, biMinimize, biMaximize];
     7807  end;
     7808  Timer1.Enabled := True;
    78127809end;
    78137810
Note: See TracChangeset for help on using the changeset viewer.