Changeset 479 for trunk


Ignore:
Timestamp:
Dec 6, 2023, 5:28:20 PM (5 months ago)
Author:
chronos
Message:
  • Fixed: Do not draw minimap outside of bitmap memory.
  • Modified: Code cleanup.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MiniMap.pas

    r471 r479  
    167167  MiniPixel: TPixelPointer;
    168168  Map: ^TTileList;
     169  xx, yy: Integer;
    169170begin
    170171  Map := PreviewMap(StartLandMass);
     
    175176  Bitmap.BeginUpdate;
    176177  MiniPixel := TPixelPointer.Create(Bitmap);
    177   for y := 0 to ScaleToNative(Size.Y) - 1 do begin
    178     for x := 0 to ScaleToNative(Size.X) - 1 do begin
     178  xx := ScaleToNative(Size.X);
     179  yy := ScaleToNative(Size.Y);
     180  for y := 0 to yy - 1 do begin
     181    for x := 0 to xx - 1 do begin
    179182      for i := 0 to 1 do begin
    180         xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);
     183        xm := (x * 2 + i + y and 1) mod (xx * 2);
    181184        MiniPixel.SetX(xm);
    182185        cm := Colors[Map[ScaleFromNative(x) * lxmax div Size.X + lxmax *
    183186          ((ScaleFromNative(y) * (lymax - 1) + Size.Y div 2) div (Size.Y - 1))] and
    184           fTerrain, i];
    185         MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
    186         MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
    187         MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
     187          fTerrain, I];
     188        if (PByte(MiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     189        (PByte(MiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * MiniPixel.BytesPerLine)) then begin
     190          MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
     191          MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
     192          MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
     193        end;
    188194      end;
    189195    end;
     
    198204  MiniPixel: TPixelPointer;
    199205  PrevMiniPixel: TPixelPointer;
     206  xx, yy: Integer;
    200207begin
    201208  OwnColor := HGrSystem.Data.Canvas.Pixels[95, 67];
     
    207214    MiniPixel := TPixelPointer.Create(Bitmap);
    208215    PrevMiniPixel := TPixelPointer.Create(Bitmap, 0, -1);
    209     for y := 0 to ScaleToNative(Size.Y) - 1 do begin
    210       for x := 0 to ScaleToNative(Size.X) - 1 do begin
     216    xx := ScaleToNative(Size.X);
     217    yy := ScaleToNative(Size.Y);
     218    for y := 0 to yy - 1 do begin
     219      for x := 0 to xx - 1 do begin
    211220        for i := 0 to 1 do begin
    212           xm := (x * 2 + i + y and 1) mod (ScaleToNative(Size.X) * 2);
     221          xm := (x * 2 + i + y and 1) mod (xx * 2);
    213222          MiniPixel.SetX(xm);
    214223          Tile := SaveMap[ScaleFromNative(x) + Size.X * ScaleFromNative(y)];
     
    221230              // 2x2 city dot covers two lines
    222231              PrevMiniPixel.SetX(xm);
    223               PrevMiniPixel.Pixel^.B := cm shr 16;
    224               PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
    225               PrevMiniPixel.Pixel^.R := cm and $FF;
     232              if (PByte(PrevMiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     233              (PByte(PrevMiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * PrevMiniPixel.BytesPerLine)) then begin
     234                PrevMiniPixel.Pixel^.B := cm shr 16;
     235                PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
     236                PrevMiniPixel.Pixel^.R := cm and $FF;
     237              end;
    226238            end;
    227239          end
     
    231243          end else
    232244            cm := Colors[Tile and fTerrain, i];
    233           MiniPixel.Pixel^.B := (cm shr 16) and $ff;
    234           MiniPixel.Pixel^.G := (cm shr 8) and $ff;
    235           MiniPixel.Pixel^.R := (cm shr 0) and $ff;
     245          if (PByte(MiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     246          (PByte(MiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * MiniPixel.BytesPerLine)) then begin
     247            MiniPixel.Pixel^.B := (cm shr 16) and $ff;
     248            MiniPixel.Pixel^.G := (cm shr 8) and $ff;
     249            MiniPixel.Pixel^.R := (cm shr 0) and $ff;
     250          end;
    236251        end;
    237252      end;
     
    254269  MyUnit: PUn;
    255270  EnemyUnit: PUnitInfo;
     271  xx, yy: Integer;
    256272begin
    257273  if not Assigned(MyMap) then Exit;
     
    268284  MiniPixel := TPixelPointer.Create(Bitmap);
    269285  PrevMiniPixel := TPixelPointer.Create(Bitmap, 0, -1);
    270   for y := 0 to ScaleToNative(Size.Y) - 1 do begin
    271     for x := 0 to ScaleToNative(Size.X) - 1 do begin
     286
     287  xx := ScaleToNative(Size.X);
     288  yy := ScaleToNative(Size.Y);
     289  for y := 0 to yy - 1 do begin
     290    for x := 0 to xx - 1 do begin
    272291      Loc := ScaleFromNative(x) + Size.X * ScaleFromNative(y);
    273292      if (MyMap[Loc] and fTerrain) <> fUNKNOWN then begin
    274293        for i := 0 to 1 do begin
    275294          xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
    276             ScaleToNative(Size.X) * 5) mod (ScaleToNative(Size.X) * 2);
     295            xx * 5) mod (xx * 2);
    277296          MiniPixel.SetX(xm);
    278297          TerrainTile := MyMap[Loc] and fTerrain;
     
    296315              // 2x2 city dot covers two lines
    297316              PrevMiniPixel.SetX(xm);
    298               PrevMiniPixel.Pixel^.B := (cm shr 16) and $ff;
    299               PrevMiniPixel.Pixel^.G := (cm shr 8) and $ff;
    300               PrevMiniPixel.Pixel^.R := (cm shr 0) and $ff;
     317              if (PByte(PrevMiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     318              (PByte(PrevMiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * PrevMiniPixel.BytesPerLine)) then begin
     319                PrevMiniPixel.Pixel^.B := (cm shr 16) and $ff;
     320                PrevMiniPixel.Pixel^.G := (cm shr 8) and $ff;
     321                PrevMiniPixel.Pixel^.R := (cm shr 0) and $ff;
     322              end;
    301323            end;
    302324          end
     
    318340            else cm := Tribe[MyRO.Territory[Loc]].Color;
    319341          end;
    320           MiniPixel.Pixel^.B := (cm shr 16) and $ff;
    321           MiniPixel.Pixel^.G := (cm shr 8) and $ff;
    322           MiniPixel.Pixel^.R := (cm shr 0) and $ff;
     342          if (PByte(MiniPixel.Pixel) >= Bitmap.RawImage.Data) and
     343          (PByte(MiniPixel.Pixel) < (Bitmap.RawImage.Data + yy * MiniPixel.BytesPerLine)) then begin
     344            MiniPixel.Pixel^.B := (cm shr 16) and $ff;
     345            MiniPixel.Pixel^.G := (cm shr 8) and $ff;
     346            MiniPixel.Pixel^.R := (cm shr 0) and $ff;
     347          end;
    323348        end;
    324349      end;
  • trunk/Start.pas

    r474 r479  
    160160const
    161161  // predefined world size
    162   // attention: lx*ly+1 must be prime!
    163   { MaxWorldSize=8;
    164     lxpre: array[0..nWorldSize-1] of Integer =(30,40,50,60,70,90,110,130);
    165     lypre: array[0..nWorldSize-1] of Integer =(46,52,60,70,84,94,110,130);
    166     DefaultWorldTiles=4200; }
     162  // attention: lx * ly + 1 must be prime!
     163  { MaxWorldSize = 8;
     164    lxpre: array[0..nWorldSize - 1] of Integer = (30, 40, 50, 60, 70, 90, 110, 130);
     165    lypre: array[0..nWorldSize - 1] of Integer = (46, 52, 60, 70, 84, 94, 110, 130);
     166    DefaultWorldTiles = 4200; }
    167167  MaxWorldSize = 6;
    168168  WorldSizes: array [0 .. MaxWorldSize - 1] of TPoint = ((X: 30; Y: 46),
     
    558558  MainAction: TMainAction;
    559559begin
    560   PaintBackground(self, 3, 3, TabOffset + 4 * TabSize - 4, TabHeight - 3);
    561   PaintBackground(self, 3, TabHeight + 3, ClientWidth - 6,
     560  PaintBackground(Self, 3, 3, TabOffset + 4 * TabSize - 4, TabHeight - 3);
     561  PaintBackground(Self, 3, TabHeight + 3, ClientWidth - 6,
    562562    ClientHeight - TabHeight - 6);
    563563  with Canvas do
     
    570570  if Page in [pgStartRandom, pgStartMap] then
    571571  begin
    572     Frame(Canvas, 328, yMain + 112 - 15, ClientWidth, Up2Btn.top + 38,
     572    Frame(Canvas, 328, yMain + 112 - 15, ClientWidth, Up2Btn.Top + 38,
    573573      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    574574    if AutoDiff > 0 then
    575575    begin
    576       Frame(Canvas, -1 { x0Brain-dxBrain } ,
    577         yMain + 112 - 15 { Up1Btn.Top-12 }{ y0Brain-dyBrain } ,
    578         x0Brain + dxBrain + 64, Up2Btn.top + 38 { y0Brain+dyBrain+64 } ,
     576      Frame(Canvas, -1 { x0Brain - dxBrain } ,
     577        yMain + 112 - 15 { Up1Btn.Top - 12 }{ y0Brain - dyBrain } ,
     578        x0Brain + dxBrain + 64, Up2Btn.Top + 38 { y0Brain + dyBrain + 64 } ,
    579579        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    580580    end;
    581581  end
    582   else if Page <> pgMain then
    583     Frame(Canvas, 328, Up1Btn.top - 15, ClientWidth, Up2Btn.top + 38,
     582  else if Page <> pgMain then begin
     583    Frame(Canvas, 328, Up1Btn.Top - 15, ClientWidth, Up2Btn.Top + 38,
    584584      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
     585  end;
    585586  Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
    586587
     
    10911092    end;
    10921093    pgLoad: begin
    1093         MiniMap.LoadFromLogFile(GetSavedDir + DirectorySeparator +
    1094           List.Items[List.ItemIndex] + CevoExt, LastTurn, WorldSizes[DefaultWorldSize]);
    1095         // BookDate:=DateToStr(FileDateToDateTime(FileAge(FileName)));
    1096         if not TurnValid then begin
    1097           LoadTurn := LastTurn;
    1098           SmartInvalidate(xTurnSlider - 2, y0Mini + 61,
    1099             xTurnSlider + wTurnSlider + 2, yTurnSlider + 9);
    1100         end;
    1101         TurnValid := True;
    1102       end;
     1094      MiniMap.LoadFromLogFile(GetSavedDir + DirectorySeparator +
     1095        List.Items[List.ItemIndex] + CevoExt, LastTurn, WorldSizes[DefaultWorldSize]);
     1096        // BookDate := DateToStr(FileDateToDateTime(FileAge(FileName)));
     1097      if not TurnValid then begin
     1098        LoadTurn := LastTurn;
     1099        SmartInvalidate(xTurnSlider - 2, y0Mini + 61,
     1100          xTurnSlider + wTurnSlider + 2, yTurnSlider + 9);
     1101      end;
     1102      TurnValid := True;
     1103    end;
    11031104    pgEditRandom: begin
    11041105      MapFileName := '';
     
    13901391            PlayerSlots[I].MultiBtn.Tag := 768;
    13911392            PlayerSlots[I].MultiBtn.ButtonIndex := 2 + (MultiControl shr I) and 1;
    1392             PlayerSlots[I].MultiBtn.Enabled := Page = pgStartRandom
     1393            PlayerSlots[I].MultiBtn.Enabled := Page = pgStartRandom;
    13931394          end
    13941395          else
Note: See TracChangeset for help on using the changeset viewer.