- Timestamp:
- Nov 23, 2017, 9:57:48 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormNew.pas
r166 r167 103 103 104 104 uses 105 UFormPlayer , UCore;105 UFormPlayer; 106 106 107 107 resourcestring -
trunk/Packages/Common/UGeometry.pas
r166 r167 20 20 P1: TPoint; 21 21 P2: TPoint; 22 function Create( P1, P2: TPoint): TLine;22 function Create(const P1, P2: TPoint): TLine; 23 23 function GetMiddle: TPoint; 24 24 function GetAngle: Double; … … 26 26 function ToRect: TRect; 27 27 function DotProduct: Double; 28 procedure Rotate( Angle: Double);29 class operator Equal( A, B: TLine): Boolean;28 procedure Rotate(const Angle: Double); 29 class operator Equal(const A, B: TLine): Boolean; 30 30 property Distance: Double read GetDistance write SetDistance; 31 31 end; … … 35 35 TPolygon = record 36 36 Points: TPointArray; 37 function IsPointInside( P: TPoint): Boolean;38 function Create( Points: TPointArray): TPolygon; overload;39 function Create( Rect: TRect): TPolygon; overload;40 procedure AddPoint( P: TPoint);37 function IsPointInside(const P: TPoint): Boolean; 38 function Create(const Points: TPointArray): TPolygon; overload; 39 function Create(const Rect: TRect): TPolygon; overload; 40 procedure AddPoint(const P: TPoint); 41 41 procedure Clear; 42 procedure CutLine( Vector: TLine;PointInside: TPoint);43 end; 44 45 function Distance( P1, P2: TPoint): Integer;42 procedure CutLine(const Vector: TLine; const PointInside: TPoint); 43 end; 44 45 function Distance(const P1, P2: TPoint): Integer; 46 46 function Dot(const P1, P2: TPoint): Double; 47 47 function AddPoint(const P1, P2: TPoint): TPoint; 48 48 function SubPoint(const P1, P2: TPoint): TPoint; 49 49 function PointToLineDistance(const P, V, W: TPoint): Integer; 50 function ComparePoint( P1, P2: TPoint): Boolean;51 function RotatePoint( Center, P: TPoint; Angle: Double): TPoint;52 function RotatePoints( Center: TPoint; P: TPointArray; Angle: Double): TPointArray;53 function LineIntersect( LineA, LineB: TLine; out Intersection: TPoint): Boolean;54 function ArcTan2Point( Point: TPoint): Float;55 function ArcTanPoint( Point: TPoint): Float;56 function RectEquals( A, B: TRect): Boolean;57 function RectEnlarge( Rect: TRect; Value: Integer): TRect;58 function ShiftRect( ARect: TRect; Delta: TPoint): TRect;59 function PointsToRect( P1, P2: TPoint): TRect;60 function PointInRect( P: TPoint; aRect: TRect): Boolean;61 function HalfDistancePoint( P1, P2: TPoint): TPoint;62 function NormalizeAngle( Angle: Double): Double;50 function ComparePoint(const P1, P2: TPoint): Boolean; 51 function RotatePoint(const Center, P: TPoint; Angle: Double): TPoint; 52 function RotatePoints(const Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 53 function LineIntersect(const LineA, LineB: TLine; out Intersection: TPoint): Boolean; 54 function ArcTan2Point(const Point: TPoint): Float; 55 function ArcTanPoint(const Point: TPoint): Float; 56 function RectEquals(const A, B: TRect): Boolean; 57 function RectEnlarge(const Rect: TRect; Value: Integer): TRect; 58 function ShiftRect(const ARect: TRect; Delta: TPoint): TRect; 59 function PointsToRect(const P1, P2: TPoint): TRect; 60 function PointInRect(const P: TPoint; aRect: TRect): Boolean; 61 function HalfDistancePoint(const P1, P2: TPoint): TPoint; 62 function NormalizeAngle(const Angle: Double): Double; 63 63 function SubAngle(A1, A2: Double): Double; 64 64 65 65 implementation 66 66 67 function Distance( P1, P2: TPoint): Integer;67 function Distance(const P1, P2: TPoint): Integer; 68 68 begin 69 69 Result := Trunc(Sqrt(Sqr(P2.X - P1.X) + Sqr(P2.Y - P1.Y))); … … 116 116 end; 117 117 118 function ComparePoint( P1, P2: TPoint): Boolean;118 function ComparePoint(const P1, P2: TPoint): Boolean; 119 119 begin 120 120 Result := (P1.X = P2.X) and (P1.Y = P2.Y); 121 121 end; 122 122 123 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; 124 begin 125 P := Point(P.X - Center.X, P.Y - Center.Y); 126 Result := Point(Center.X + Round(P.X * Cos(Angle) - P.Y * Sin(Angle)), 127 Center.Y + Round(P.X * Sin(Angle) + P.Y * Cos(Angle))); 128 end; 129 130 function RotatePoints(Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 123 function RotatePoint(const Center, P: TPoint; Angle: Double): TPoint; 124 var 125 D: TPoint; 126 begin 127 D := Point(P.X - Center.X, P.Y - Center.Y); 128 Result := Point(Center.X + Round(D.X * Cos(Angle) - D.Y * Sin(Angle)), 129 Center.Y + Round(D.X * Sin(Angle) + D.Y * Cos(Angle))); 130 end; 131 132 function RotatePoints(const Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 131 133 var 132 134 I: Integer; … … 137 139 end; 138 140 139 function LineIntersect( LineA, LineB: TLine; out Intersection: TPoint): Boolean;141 function LineIntersect(const LineA, LineB: TLine; out Intersection: TPoint): Boolean; 140 142 Var 141 143 LDetLineA, LDetLineB, LDetDivInv: Double; … … 143 145 D: Integer; 144 146 begin 145 if (LineA.P1 = LineA.P2) or (LineB.P1 =LineB.P2) then begin147 if ComparePoint(LineA.P1, LineA.P2) or ComparePoint(LineB.P1, LineB.P2) then begin 146 148 Result := False; 147 149 Exit; … … 166 168 end; 167 169 168 function ArcTan2Point( Point: TPoint): Float;170 function ArcTan2Point(const Point: TPoint): Float; 169 171 begin 170 172 Result := ArcTan2(Point.Y, Point.X); 171 173 end; 172 174 173 function ArcTanPoint( Point: TPoint): Float;175 function ArcTanPoint(const Point: TPoint): Float; 174 176 begin 175 177 if Point.Y = 0 then Result := Infinity … … 177 179 end; 178 180 179 function RectEquals( A, B: TRect): Boolean;181 function RectEquals(const A, B: TRect): Boolean; 180 182 begin 181 183 Result := (A.Left = B.Left) and (A.Top = B.Top) and … … 183 185 end; 184 186 185 function RectEnlarge( Rect: TRect; Value: Integer): TRect;187 function RectEnlarge(const Rect: TRect; Value: Integer): TRect; 186 188 begin 187 189 Result.Left := Rect.Left - Value; … … 191 193 end; 192 194 193 function ShiftRect( ARect: TRect; Delta: TPoint): TRect;195 function ShiftRect(const ARect: TRect; Delta: TPoint): TRect; 194 196 begin 195 197 Result := Rect(ARect.Left + Delta.X, ARect.Top + Delta.Y, … … 197 199 end; 198 200 199 function PointsToRect( P1, P2: TPoint): TRect;201 function PointsToRect(const P1, P2: TPoint): TRect; 200 202 begin 201 203 if P1.X < P2.X then Result.Left := P1.X else Result.Left := P2.X; … … 205 207 end; 206 208 207 function PointInRect( P: TPoint; aRect: TRect): Boolean;209 function PointInRect(const P: TPoint; aRect: TRect): Boolean; 208 210 begin 209 211 Result := (P.X >= aRect.Left) and (P.X <= aRect.Right) and … … 211 213 end; 212 214 213 function HalfDistancePoint( P1, P2: TPoint): TPoint;215 function HalfDistancePoint(const P1, P2: TPoint): TPoint; 214 216 begin 215 217 Result := Point(P1.X + (P2.X - P1.X) div 2, P1.Y + (P2.Y - P1.Y) div 2) 216 218 end; 217 219 218 function NormalizeAngle( Angle: Double): Double;220 function NormalizeAngle(const Angle: Double): Double; 219 221 begin 220 222 if Angle < 0 then Result := Angle + (Trunc(Angle / (2 * Pi)) + 1) * (2 * Pi) … … 233 235 { TPolygon } 234 236 235 function TPolygon.IsPointInside( P: TPoint): Boolean;237 function TPolygon.IsPointInside(const P: TPoint): Boolean; 236 238 var 237 239 I, J: Integer; … … 273 275 274 276 275 function TPolygon.Create( Points: TPointArray): TPolygon;277 function TPolygon.Create(const Points: TPointArray): TPolygon; 276 278 var 277 279 I: Integer; … … 282 284 end; 283 285 284 function TPolygon.Create( Rect: TRect): TPolygon;286 function TPolygon.Create(const Rect: TRect): TPolygon; 285 287 begin 286 288 SetLength(Result.Points, 4); … … 291 293 end; 292 294 293 procedure TPolygon.AddPoint( P: TPoint);295 procedure TPolygon.AddPoint(const P: TPoint); 294 296 begin 295 297 SetLength(Points, Length(Points) + 1); … … 302 304 end; 303 305 304 procedure TPolygon.CutLine( Vector: TLine;PointInside: TPoint);306 procedure TPolygon.CutLine(const Vector: TLine; const PointInside: TPoint); 305 307 var 306 308 I: Integer; … … 367 369 end; 368 370 369 function TLine.Create( P1, P2: TPoint): TLine;371 function TLine.Create(const P1, P2: TPoint): TLine; 370 372 begin 371 373 Result.P1 := P1; … … 401 403 end; 402 404 403 procedure TLine.Rotate( Angle: Double);405 procedure TLine.Rotate(const Angle: Double); 404 406 begin 405 407 P2 := RotatePoint(P1, P2, Angle); 406 408 end; 407 409 408 class operator TLine.Equal(A, B: TLine): Boolean; 409 begin 410 Result := (A.P1 = B.P1) and (A.P2 = B.P2); 411 end; 412 410 class operator TLine.Equal(const A, B: TLine): Boolean; 411 begin 412 Result := ComparePoint(A.P1, B.P1) and ComparePoint(A.P2, B.P2); 413 end; 413 414 414 415 end. -
trunk/UGame.pas
r166 r167 188 188 private 189 189 FSize: TPoint; 190 FUpdateCount: Integer;191 190 function GetSize: TPoint; virtual; 192 191 procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView; … … 229 228 procedure CreateLinks; 230 229 procedure Clear; 231 procedure BeginUpdate;232 procedure EndUpdate;233 230 constructor Create; virtual; 234 231 destructor Destroy; override; … … 1388 1385 if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin 1389 1386 FSize := AValue; 1390 if FUpdateCount = 0 then Generate;1391 1387 end; 1392 1388 end; … … 1504 1500 // I: Integer; 1505 1501 begin 1506 FUpdateCount := Source.FUpdateCount;1507 1502 MaxPower := Source.MaxPower; 1508 1503 Game := Source.Game; … … 1784 1779 Cells.Clear; 1785 1780 FNewCellId := 1; 1786 end;1787 1788 procedure TMap.BeginUpdate;1789 begin1790 Inc(FUpdateCount);1791 end;1792 1793 procedure TMap.EndUpdate;1794 begin1795 if FUpdateCount > 0 then Dec(FUpdateCount);1796 if FUpdateCount = 0 then Generate;1797 1781 end; 1798 1782 … … 3317 3301 begin 3318 3302 with Config do begin 3319 try 3320 Map.BeginUpdate; 3321 MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon))); 3322 Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10), 3323 GetValue(DOMString(Path + '/MapSizeY'), 10)); 3324 finally 3325 Map.EndUpdate; 3326 end; 3303 MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon))); 3304 Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10), 3305 GetValue(DOMString(Path + '/MapSizeY'), 10)); 3327 3306 MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName))); 3328 3307 SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), False); -
trunk/UMap.pas
r166 r167 296 296 LeftCellCommon: TCell; 297 297 RightCellCommon: TCell; 298 LeftText: string;299 RightText: string;298 //LeftText: string; 299 //RightText: string; 300 300 NeighborCell: TCell; 301 301 begin 302 302 Clear; 303 RandSeed := 1234;303 //RandSeed := 1234; 304 304 305 305 // Allocate and init new cells
Note:
See TracChangeset
for help on using the changeset viewer.