Changeset 86 for trunk/UEngine.pas
- Timestamp:
- Jun 21, 2022, 5:04:48 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r84 r86 1 1 unit UEngine; 2 2 3 {$mode delphi}4 3 {$IFDEF DARWIN}{$modeswitch Objectivec1}{$ENDIF} 5 4 … … 7 6 8 7 uses 9 {$IFDEF D arwin}MacOSAll, CocoaAll, CocoaUtils,{$ENDIF}8 {$IFDEF DARWIN}MacOSAll, CocoaAll, CocoaUtils,{$ENDIF} 10 9 Classes, SysUtils, Graphics, Controls, ExtCtrls, Math, DateUtils, 11 UMetaCanvas, fgl, UMenu, UControls;10 UMetaCanvas, Generics.Collections, Generics.Defaults, UMenu, UControls; 12 11 13 12 type … … 57 56 { TMapStations } 58 57 59 TMapStations = class(T FPGObjectList<TMapStation>)58 TMapStations = class(TObjectList<TMapStation>) 60 59 Engine: TEngine; 61 60 function GetRect: TRect; … … 71 70 { TLineStations } 72 71 73 TLineStations = class(T FPGObjectList<TLineStation>)72 TLineStations = class(TObjectList<TLineStation>) 74 73 Line: TMetroLine; 75 74 function SearchMapStation(Station: TMapStation): TLineStation; … … 105 104 { TTrackPoints } 106 105 107 TTrackPoints = class(T FPGObjectList<TTrackPoint>)106 TTrackPoints = class(TObjectList<TTrackPoint>) 108 107 Track: TTrack; 109 108 function AddNew: TTrackPoint; … … 122 121 { TTrackLinks } 123 122 124 TTrackLinks = class(T FPGObjectList<TTrackLink>)123 TTrackLinks = class(TObjectList<TTrackLink>) 125 124 Track: TTrack; 126 125 function SearchPoints(Point1, Point2: TTrackPoint): TTrackLink; … … 140 139 { TTracks } 141 140 142 TTracks = class(T FPGObjectList<TTrackLink>)141 TTracks = class(TObjectList<TTrackLink>) 143 142 function SearchPointUp(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; 144 143 function SearchPointDown(TrackPoint: TTrackPoint; Skip: TTrackLink): TTrackLink; … … 156 155 { TTrackPointsAngleGroup } 157 156 158 TTrackPointsAngleGroup = class(T FPGObjectList<TTrackPointsAngle>)157 TTrackPointsAngleGroup = class(TObjectList<TTrackPointsAngle>) 159 158 function SearchAngle(Angle: Double): TTrackPointsAngle; 160 159 end; … … 164 163 TMetroLine = class 165 164 private 165 procedure UpdateEndingLine(EndIndex, Direction: Integer); 166 166 procedure UpdateEndingLines; 167 167 public … … 182 182 { TMetroLines } 183 183 184 TMetroLines = class(T FPGObjectList<TMetroLine>)184 TMetroLines = class(TObjectList<TMetroLine>) 185 185 Engine: TEngine; 186 186 function AddNew: TMetroLine; … … 194 194 end; 195 195 196 TMetroCarriages = class(T FPGObjectList<TMetroCarriage>)196 TMetroCarriages = class(TObjectList<TMetroCarriage>) 197 197 end; 198 198 … … 224 224 { TMetroTrains } 225 225 226 TMetroTrains = class(T FPGObjectList<TMetroTrain>)226 TMetroTrains = class(TObjectList<TMetroTrain>) 227 227 function GetUnusedTrain: TMetroTrain; 228 228 function GetUnusedCount: Integer; … … 239 239 { TMetroPassengers } 240 240 241 TMetroPassengers = class(T FPGObjectList<TMetroPassenger>)241 TMetroPassengers = class(TObjectList<TMetroPassenger>) 242 242 Engine: TEngine; 243 243 function AddNew: TMetroPassenger; … … 251 251 end; 252 252 253 TRivers = class(T FPGObjectList<TRiver>)253 TRivers = class(TObjectList<TRiver>) 254 254 end; 255 255 … … 499 499 begin 500 500 Points := TTrackPoints.Create; 501 Points. FreeObjects := False;501 Points.OwnsObjects := False; 502 502 end; 503 503 … … 627 627 begin 628 628 TrackLinks := TTrackLinks.Create; 629 TrackLinks. FreeObjects := False;629 TrackLinks.OwnsObjects := False; 630 630 end; 631 631 … … 751 751 begin 752 752 NeighPoints := TTrackPoints.Create; 753 NeighPoints. FreeObjects := False;753 NeighPoints.OwnsObjects := False; 754 754 NeighLinks := TTrackLinks.Create; 755 NeighLinks. FreeObjects := False;755 NeighLinks.OwnsObjects := False; 756 756 end; 757 757 … … 888 888 { TMetroLine } 889 889 890 procedure TMetroLine.UpdateEndingLine s;890 procedure TMetroLine.UpdateEndingLine(EndIndex, Direction: Integer); 891 891 var 892 892 Index: Integer; … … 894 894 Angle: Double; 895 895 EndPoint: TPoint; 896 begin 897 { if Direction = 1 then Index := Track.Points.IndexOf(LineStations.Last.TrackPoint) 898 else if Direction = -1 then Index := Track.Points.IndexOf(LineStations.Last.TrackPoint); 899 if Index = EndIndex then begin 900 NewTrackPoint := Track.Points.AddNew; 901 if Direction = 1 then Track.Points.Insert(EndIndex, NewTrackPoint) 902 else if Direction = -1 then begin 903 Inc(EndIndex); 904 Track.Points.Insert(EndIndex, NewTrackPoint); 905 end; 906 end; 907 } 908 Angle := ArcTan2((Track.Points[EndIndex + 2 * Direction].PositionDesigned.Y - 909 Track.Points[EndIndex + Direction].PositionDesigned.Y), 910 (Track.Points[EndIndex + 2 * Direction].PositionDesigned.X - 911 Track.Points[EndIndex + Direction].PositionDesigned.X)); 912 EndPoint := Point(Round(Track.Points[EndIndex + Direction].PositionDesigned.X - EndStationLength * Cos(Angle)), 913 Round(Track.Points[EndIndex + Direction].PositionDesigned.Y - EndStationLength * Sin(Angle))); 914 Track.Points[EndIndex].PositionDesigned := EndPoint; 915 Track.Points[EndIndex].Position := EndPoint; 916 end; 917 918 procedure TMetroLine.UpdateEndingLines; 919 var 920 Index: Integer; 921 NewTrackPoint: TTrackPoint; 896 922 begin 897 923 if LineStations.Count >= 2 then begin … … 906 932 Track.Points.Insert(Track.Points.Count, NewTrackPoint); 907 933 end; 908 909 Angle := ArcTan2((Track.Points[2].PositionDesigned.Y - Track.Points[1].PositionDesigned.Y), 910 (Track.Points[2].PositionDesigned.X - Track.Points[1].PositionDesigned.X)); 911 EndPoint := Point(Round(Track.Points[1].PositionDesigned.X - EndStationLength * Cos(Angle)), 912 Round(Track.Points[1].PositionDesigned.Y - EndStationLength * Sin(Angle))); 913 Track.Points.First.PositionDesigned := EndPoint; 914 Track.Points.First.Position := EndPoint; 915 916 Angle := ArcTan2((Track.Points[Track.Points.Count - 2].PositionDesigned.Y - Track.Points[Track.Points.Count - 3].PositionDesigned.Y), 917 (Track.Points[Track.Points.Count - 2].PositionDesigned.X - Track.Points[Track.Points.Count - 3].PositionDesigned.X)); 918 EndPoint := Point(Round(Track.Points[Track.Points.Count - 2].PositionDesigned.X + EndStationLength * Cos(Angle)), 919 Round(Track.Points[Track.Points.Count - 2].PositionDesigned.Y + EndStationLength * Sin(Angle))); 920 Track.Points.Last.PositionDesigned := EndPoint; 921 Track.Points.Last.Position := EndPoint; 934 UpdateEndingLine(0, 1); 935 UpdateEndingLine(Track.Points.Count - 1, -1); 922 936 end; 923 937 end; … … 1100 1114 begin 1101 1115 LineStations := TLineStations.Create; 1102 LineStations. FreeObjects := True;1116 LineStations.OwnsObjects := True; 1103 1117 Trains := TMetroTrains.Create; 1104 Trains. FreeObjects := False;1118 Trains.OwnsObjects := False; 1105 1119 Track := TTrack.Create; 1106 1120 Track.Line := Self; … … 1197 1211 begin 1198 1212 Passengers := TMetroPassengers.Create; 1199 Passengers. FreeObjects := False;1213 Passengers.OwnsObjects := False; 1200 1214 Carriages := TMetroCarriages.Create; 1201 1215 Direction := 1; … … 1230 1244 begin 1231 1245 TrackLinks := TTrackLinks.Create; 1232 TrackLinks. FreeObjects := False;1246 TrackLinks.OwnsObjects := False; 1233 1247 1234 1248 // Collect all near track points as track links … … 1290 1304 with TrackLinks[J] do begin 1291 1305 // Get orthogonal angle 1292 HAngle := Angle + Pi / 2; 1293 if HAngle > Pi then HAngle := HAngle - Pi; 1306 HAngle := (Angle + Pi / 2) mod Pi; 1294 1307 NewShift.X := Trunc(MetroLineThickness * Cos(HAngle) * (J - (TrackLinks.Count - 1) / 2)); 1295 1308 NewShift.Y := Trunc(MetroLineThickness * Sin(HAngle) * (J - (TrackLinks.Count - 1) / 2)); … … 1302 1315 end; 1303 1316 1304 function MapStationCompareLine(const Item1, Item2: TMetroLine): Integer;1317 function MapStationCompareLine(constref Item1, Item2: TMetroLine): Integer; 1305 1318 begin 1306 1319 if Item1.Index > Item2.Index then Result := 1 … … 1311 1324 procedure TMapStation.SortLines; 1312 1325 begin 1313 Lines.Sort( MapStationCompareLine);1326 Lines.Sort(TComparer<TMetroLine>.Construct(MapStationCompareLine)); 1314 1327 end; 1315 1328 … … 1376 1389 begin 1377 1390 Passengers := TMetroPassengers.Create; 1378 Passengers. FreeObjects := False;1391 Passengers.OwnsObjects := False; 1379 1392 Lines := TMetroLines.Create; 1380 Lines. FreeObjects := False;1393 Lines.OwnsObjects := False; 1381 1394 end; 1382 1395 … … 1941 1954 Track.Points[I].PositionDesigned + Track.Points[I].LinkDown.Shift, 1942 1955 Track.Points[I].PositionDesigned + Track.Points[I].LinkUp.Shift, 1943 Track.Points[I + 1].PositionDesigned + Track.Points[I].LinkUp.Shift, NewPoint) then 1944 Track.Points[I].Position := NewPoint1945 e lse begin1956 Track.Points[I + 1].PositionDesigned + Track.Points[I].LinkUp.Shift, NewPoint) then begin 1957 Track.Points[I].Position := NewPoint; 1958 end else begin 1946 1959 // Parallel lines 1947 1960 NewPoint := Track.Points[I].PositionDesigned + Track.Points[I].LinkDown.Shift; … … 1949 1962 end; 1950 1963 // end; 1964 1965 // Update ending 1966 if Track.Points.Count > 1 then begin 1967 Track.Points[Track.Points.Count - 1].Position := Track.Points[Track.Points.Count - 1].PositionDesigned - 1968 Track.Points[Track.Points.Count - 1].LinkDown.Shift; 1969 end; 1951 1970 end; 1952 1971 … … 2333 2352 { if (S = TrackPoints.Count - 1) then begin 2334 2353 Canvas.Pen.EndCap := pecSquare; 2335 Angle := arctan2 (((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),2354 Angle := arctan2D(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2336 2355 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2337 2356 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
Note:
See TracChangeset
for help on using the changeset viewer.