Changeset 235


Ignore:
Timestamp:
Sep 20, 2018, 11:44:42 AM (6 years ago)
Author:
chronos
Message:
  • Added: Show map multiple times side by side in cyclic mode.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r234 r235  
    192192      {$endif}
    193193
    194     {  if Game.CyclicMap then begin
     194      if Game.CyclicMap then begin
    195195        VS := View.CellToCanvasPos(Game.Map.Size);
    196196        TempView := TView.Create;
    197197        TempView.Game := Game;
    198         R := TRect.Create(View.CellToCanvasPos(Game.Map.Cells.First.PosPx),
    199           View.CellToCanvasPos(Game.Map.Cells.Last.PosPx));
     198        //R := View.CellToCanvasRect(TRect.Create(Game.Map.Cells.First.PosPx,
     199        //  Game.Map.Cells.Last.PosPx));
     200        R := View.CellToCanvasRect(Game.Map.PixelRect);
    200201        StartP := TPoint.Create(Ceil(R.P1.X / R.Size.X) * R.Size.X,
    201202          Ceil(R.P1.Y / R.Size.Y) * R.Size.Y);
     
    204205        for Y := 0 to CountP.Y do begin
    205206          for X := 0 to CountP.X do begin
    206             TempView.Zoom := View.Zoom;
    207             TempView.SourceRect := View.SourceRect;
     207            TempView.Assign(View);
    208208            TempView.DestRect := TRect.Create(
    209             TPoint.Create(
    210               -StartP.X + R.Size.X * X,
    211               -StartP.Y + R.Size.Y * Y),
    212             TPoint.Create(
    213               -StartP.X + R.Size.X * X + View.DestRect.Size.X,
    214               -StartP.Y + R.Size.Y * Y + View.DestRect.Size.Y)
     209              TPoint.Create(
     210                -StartP.X + R.Size.X * X,
     211                -StartP.Y + R.Size.Y * Y
     212              ),
     213              TPoint.Create(
     214                -StartP.X + R.Size.X * X + View.DestRect.Size.X,
     215                -StartP.Y + R.Size.Y * Y + View.DestRect.Size.Y
     216              )
    215217            );
    216218            Client.Paint(PaintBox1.Canvas, TempView);
     
    219221        TempView.Free;
    220222      end else
    221       }Client.Paint(PaintBox1.Canvas, View);
     223      Client.Paint(PaintBox1.Canvas, View);
    222224    end;
    223225  end;
  • trunk/UGeometry.pas

    r234 r235  
    2424    class operator Equal(const A, B: TGPoint<T>): Boolean;
    2525    class operator Multiply(const A, B: TGPoint<T>): TGPoint<T>;
     26    //class operator Divide(const A, B: TGPoint<T>): TGPoint<T>;
    2627    function Min(const A, B: TGPoint<T>): TGPoint<T>;
    2728    function Max(const A, B: TGPoint<T>): TGPoint<T>;
     
    119120  TPolygonF = TGPolygon<TPointF>;
    120121
    121 function Divide(Divident, Divisor: Integer): Integer; overload;
    122 function Divide(Divident, Divisor: Double): Double; overload;
     122function TypedDivide(Divident, Divisor: Integer): Integer; overload;
     123function TypedDivide(Divident, Divisor: Single): Single; overload;
    123124function TypedRound(Value: Double): Integer; overload;
    124125function TypedRound(Value: Double): Double; overload;
     
    129130implementation
    130131
    131 function Divide(Divident, Divisor: Integer): Integer;
     132function TypedDivide(Divident, Divisor: Integer): Integer;
    132133begin
    133134  Result := Divident div Divisor;
    134135end;
    135136
    136 function Divide(Divident, Divisor: Double): Double;
     137function TypedDivide(Divident, Divisor: Single): Single;
    137138begin
    138139  Result := Divident / Divisor;
     
    334335function TGLine<T>.GetMiddle: T;
    335336begin
    336   Result := T.Create(P1.X + Divide((P2.X - P1.X), 2), P1.Y + Divide((P2.Y - P1.Y), 2));
     337  Result := T.Create(P1.X + TypedDivide((P2.X - P1.X), 2), P1.Y + TypedDivide((P2.Y - P1.Y), 2));
    337338end;
    338339
     
    437438end;
    438439
     440{class operator TGPoint<T>.Divide(const A, B: TGPoint<T>): TGPoint<T>;
     441begin
     442  Result.X := TypedDivide(A.X, B.X);
     443  Result.Y := TypedDivide(A.Y, B.Y);
     444end;
     445}
     446
    439447class operator TGPoint<T>.GreaterThan(const A, B: TGPoint<T>): Boolean;
    440448begin
     
    508516function TGRect<T>.Center: T;
    509517begin
    510   Result.X := Divide(P2.X - P1.X, 2);
    511   Result.Y := Divide(P2.Y - P1.Y, 2);
     518  Result.X := TypedDivide(P2.X - P1.X, 2);
     519  Result.Y := TypedDivide(P2.Y - P1.Y, 2);
    512520end;
    513521
  • trunk/UMapType.pas

    r232 r235  
    77uses
    88  Classes, SysUtils, XMLRead, XMLWrite, DOM, UGeometry, fgl, UMap;
    9 
    10 const
    11   SquareCellMulX = 1.05;
    12   SquareCellMulY = 1.05;
    13   TriangleCellMulX = 0.55;
    14   TriangleCellMulY = 1.05;
    159
    1610type
     
    3226    function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon;
    3327  public
     28    function CalculatePixelRect: TRect; override;
    3429    procedure LoadFromFile(FileName: string); override;
    3530    procedure SaveToFile(FileName: string); override;
     
    4136  TSquareMap = class(TMap)
    4237  private
     38    const
     39      CellMulX = 1.05;
     40      CellMulY = 1.05;
    4341    function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    4442  public
    4543    procedure Generate; override;
     44    function CalculatePixelRect: TRect; override;
    4645  end;
    4746
     
    5049  TTriangleMap = class(TMap)
    5150  private
     51    const
     52      CellMulX = 0.55;
     53      CellMulY = 1.05;
    5254    function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon;
    5355  public
    5456    procedure Generate; override;
     57    function CalculatePixelRect: TRect; override;
    5558  end;
    5659
     
    6164  public
    6265    procedure Generate; override;
     66    function CalculatePixelRect: TRect; override;
    6367  end;
    6468
     
    7377  public
    7478    procedure Generate; override;
     79    function CalculatePixelRect: TRect; override;
    7580  end;
    7681
     
    147152
    148153  FPixelRect := CalculatePixelRect;
     154end;
     155
     156function TIsometricMap.CalculatePixelRect: TRect;
     157begin
     158  Result := inherited CalculatePixelRect;
     159  Result.P2 := Result.P2 - TPoint.Create(
     160    Trunc(0.45 * DefaultCellSize.X / CellMulX),
     161    Trunc(0.90 * DefaultCellSize.Y / CellMulY)
     162  );
    149163end;
    150164
     
    165179  Result.Points[4] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));
    166180  Result.Points[5] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));
     181end;
     182
     183function THexMap.CalculatePixelRect: TRect;
     184var
     185  Shift: TPointF;
     186  Angle: Double;
     187begin
     188  Result := inherited CalculatePixelRect;
     189  Angle := 30 / 180 * Pi;
     190  Shift := TPointF.Create(0.5, 0.5) * TPointF.Create(Cos(Angle), Sin(Angle));
     191  Result.P2 := Result.P2 - TPoint.Create(
     192    Trunc(0.47 * DefaultCellSize.X / CellMulX),
     193    Trunc(1.2 * Shift.Y * DefaultCellSize.Y / CellMulY)
     194  );
    167195end;
    168196
     
    293321    NewCell := TCell.Create;
    294322    NewCell.Map := Self;
    295     NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * SquareCellMulX),
    296       Trunc(Y * DefaultCellSize.Y * SquareCellMulY));
     323    NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * CellMulX),
     324      Trunc(Y * DefaultCellSize.Y * CellMulY));
    297325    NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize);
    298326    NewCell.Id := GetNewCellId;
     
    330358
    331359  FPixelRect := CalculatePixelRect;
     360end;
     361
     362function TSquareMap.CalculatePixelRect: TRect;
     363begin
     364  Result := inherited CalculatePixelRect;
     365  Result.P2 := Result.P2 + TPoint.Create(
     366    Trunc(0.05 * DefaultCellSize.X / CellMulX),
     367    Trunc(0.05 * DefaultCellSize.Y / CellMulY)
     368  );
    332369end;
    333370
     
    413450end;
    414451
     452function TVoronoiMap.CalculatePixelRect: TRect;
     453begin
     454  Result := inherited CalculatePixelRect;
     455  Result.P2 := Result.P2 + TPoint.Create(
     456    Trunc(0.02 * DefaultCellSize.X),
     457    Trunc(0.02 * DefaultCellSize.Y)
     458  );
     459end;
     460
    415461{ TTriangleMap }
    416462
     
    447493    if Reverse then Rev := -1
    448494      else Rev := 1;
    449     NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * TriangleCellMulX),
    450       Trunc((Y * DefaultCellSize.Y * TriangleCellMulY) - (0.1 * Rev * DefaultCellSize.Y)));
     495    NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * CellMulX),
     496      Trunc((Y * DefaultCellSize.Y * CellMulY) - (0.1 * Rev * DefaultCellSize.Y)));
    451497    NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse);
    452498    NewCell.Id := GetNewCellId;
     
    483529end;
    484530
     531function TTriangleMap.CalculatePixelRect: TRect;
     532begin
     533  Result := inherited CalculatePixelRect;
     534  Result.P2 := Result.P2 + TPoint.Create(
     535    Trunc(0.05 * DefaultCellSize.X / CellMulX - 0.30 * DefaultCellSize.X / CellMulX),
     536    Trunc(0.05 * DefaultCellSize.Y / CellMulY)
     537  );
     538end;
     539
    485540
    486541end.
  • trunk/UPlayer.pas

    r233 r235  
    349349  I: Integer;
    350350begin
     351  // TODO: Can it be optimized somehow?
    351352  Result := nil;
    352353  for I := 0 to Cells.Count - 1 do
Note: See TracChangeset for help on using the changeset viewer.