- Timestamp:
- Sep 20, 2018, 11:44:42 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormClient.pas
r234 r235 192 192 {$endif} 193 193 194 {if Game.CyclicMap then begin194 if Game.CyclicMap then begin 195 195 VS := View.CellToCanvasPos(Game.Map.Size); 196 196 TempView := TView.Create; 197 197 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); 200 201 StartP := TPoint.Create(Ceil(R.P1.X / R.Size.X) * R.Size.X, 201 202 Ceil(R.P1.Y / R.Size.Y) * R.Size.Y); … … 204 205 for Y := 0 to CountP.Y do begin 205 206 for X := 0 to CountP.X do begin 206 TempView.Zoom := View.Zoom; 207 TempView.SourceRect := View.SourceRect; 207 TempView.Assign(View); 208 208 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 ) 215 217 ); 216 218 Client.Paint(PaintBox1.Canvas, TempView); … … 219 221 TempView.Free; 220 222 end else 221 }Client.Paint(PaintBox1.Canvas, View);223 Client.Paint(PaintBox1.Canvas, View); 222 224 end; 223 225 end; -
trunk/UGeometry.pas
r234 r235 24 24 class operator Equal(const A, B: TGPoint<T>): Boolean; 25 25 class operator Multiply(const A, B: TGPoint<T>): TGPoint<T>; 26 //class operator Divide(const A, B: TGPoint<T>): TGPoint<T>; 26 27 function Min(const A, B: TGPoint<T>): TGPoint<T>; 27 28 function Max(const A, B: TGPoint<T>): TGPoint<T>; … … 119 120 TPolygonF = TGPolygon<TPointF>; 120 121 121 function Divide(Divident, Divisor: Integer): Integer; overload;122 function Divide(Divident, Divisor: Double): Double; overload;122 function TypedDivide(Divident, Divisor: Integer): Integer; overload; 123 function TypedDivide(Divident, Divisor: Single): Single; overload; 123 124 function TypedRound(Value: Double): Integer; overload; 124 125 function TypedRound(Value: Double): Double; overload; … … 129 130 implementation 130 131 131 function Divide(Divident, Divisor: Integer): Integer;132 function TypedDivide(Divident, Divisor: Integer): Integer; 132 133 begin 133 134 Result := Divident div Divisor; 134 135 end; 135 136 136 function Divide(Divident, Divisor: Double): Double;137 function TypedDivide(Divident, Divisor: Single): Single; 137 138 begin 138 139 Result := Divident / Divisor; … … 334 335 function TGLine<T>.GetMiddle: T; 335 336 begin 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)); 337 338 end; 338 339 … … 437 438 end; 438 439 440 {class operator TGPoint<T>.Divide(const A, B: TGPoint<T>): TGPoint<T>; 441 begin 442 Result.X := TypedDivide(A.X, B.X); 443 Result.Y := TypedDivide(A.Y, B.Y); 444 end; 445 } 446 439 447 class operator TGPoint<T>.GreaterThan(const A, B: TGPoint<T>): Boolean; 440 448 begin … … 508 516 function TGRect<T>.Center: T; 509 517 begin 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); 512 520 end; 513 521 -
trunk/UMapType.pas
r232 r235 7 7 uses 8 8 Classes, SysUtils, XMLRead, XMLWrite, DOM, UGeometry, fgl, UMap; 9 10 const11 SquareCellMulX = 1.05;12 SquareCellMulY = 1.05;13 TriangleCellMulX = 0.55;14 TriangleCellMulY = 1.05;15 9 16 10 type … … 32 26 function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon; 33 27 public 28 function CalculatePixelRect: TRect; override; 34 29 procedure LoadFromFile(FileName: string); override; 35 30 procedure SaveToFile(FileName: string); override; … … 41 36 TSquareMap = class(TMap) 42 37 private 38 const 39 CellMulX = 1.05; 40 CellMulY = 1.05; 43 41 function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon; 44 42 public 45 43 procedure Generate; override; 44 function CalculatePixelRect: TRect; override; 46 45 end; 47 46 … … 50 49 TTriangleMap = class(TMap) 51 50 private 51 const 52 CellMulX = 0.55; 53 CellMulY = 1.05; 52 54 function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon; 53 55 public 54 56 procedure Generate; override; 57 function CalculatePixelRect: TRect; override; 55 58 end; 56 59 … … 61 64 public 62 65 procedure Generate; override; 66 function CalculatePixelRect: TRect; override; 63 67 end; 64 68 … … 73 77 public 74 78 procedure Generate; override; 79 function CalculatePixelRect: TRect; override; 75 80 end; 76 81 … … 147 152 148 153 FPixelRect := CalculatePixelRect; 154 end; 155 156 function TIsometricMap.CalculatePixelRect: TRect; 157 begin 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 ); 149 163 end; 150 164 … … 165 179 Result.Points[4] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 166 180 Result.Points[5] := TPoint.Create(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 181 end; 182 183 function THexMap.CalculatePixelRect: TRect; 184 var 185 Shift: TPointF; 186 Angle: Double; 187 begin 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 ); 167 195 end; 168 196 … … 293 321 NewCell := TCell.Create; 294 322 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)); 297 325 NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize); 298 326 NewCell.Id := GetNewCellId; … … 330 358 331 359 FPixelRect := CalculatePixelRect; 360 end; 361 362 function TSquareMap.CalculatePixelRect: TRect; 363 begin 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 ); 332 369 end; 333 370 … … 413 450 end; 414 451 452 function TVoronoiMap.CalculatePixelRect: TRect; 453 begin 454 Result := inherited CalculatePixelRect; 455 Result.P2 := Result.P2 + TPoint.Create( 456 Trunc(0.02 * DefaultCellSize.X), 457 Trunc(0.02 * DefaultCellSize.Y) 458 ); 459 end; 460 415 461 { TTriangleMap } 416 462 … … 447 493 if Reverse then Rev := -1 448 494 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))); 451 497 NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse); 452 498 NewCell.Id := GetNewCellId; … … 483 529 end; 484 530 531 function TTriangleMap.CalculatePixelRect: TRect; 532 begin 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 ); 538 end; 539 485 540 486 541 end. -
trunk/UPlayer.pas
r233 r235 349 349 I: Integer; 350 350 begin 351 // TODO: Can it be optimized somehow? 351 352 Result := nil; 352 353 for I := 0 to Cells.Count - 1 do
Note:
See TracChangeset
for help on using the changeset viewer.