Changeset 33


Ignore:
Timestamp:
Apr 19, 2015, 12:42:58 AM (10 years ago)
Author:
chronos
Message:
  • Added: Attempt to reduce scene redraw be introducing Redraw method and RedrawPending flag. But clock need to be redrawn as fast as possible so different approach need to be taken.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r32 r33  
    304304    ServedPassengerCount: Integer;
    305305    State: TGameState;
    306     procedure Tick;
     306    RedrawPending: Boolean;
    307307    procedure MouseMove(Position: TPoint);
    308308    procedure MouseUp(Button: TMouseButton; Position: TPoint);
    309309    procedure MouseDown(Button: TMouseButton; Position: TPoint);
    310310    procedure Reset;
     311    procedure Redraw;
    311312    constructor Create;
    312313    destructor Destroy; override;
     314    procedure Tick;
    313315    procedure Paint(TargetCanvas: TCanvas);
    314316    property Time: TDateTime read FTime;
     
    341343  //TimePerSecond = (60 * OneMinute);
    342344  TimePerSecond = (60 * OneMinute);
    343   NewStationPeriod = 0.01;
     345  NewStationPeriod = 1;
    344346  NewShapePeriod = 10;
    345347  NewTrainPeriod = 7; // Each week
     
    16071609        RelPos := RelPos + PosChange;
    16081610        LastTrainMoveTime := Time;
     1611        Redraw;
    16091612        if Assigned(BaseTrackPoint) then
    16101613        while (Direction = -1) and (RelPos < 0) do begin
     
    16511654          InStation := True;
    16521655          StationStopTime := Time;
     1656          Redraw;
    16531657        end;
    16541658        LastPosDelta := PosDelta;
     
    17911795  if State = gsRunning then begin
    17921796    FTime := FTime + (Now - LastTickTime) / OneSecond * TimePerSecond;
     1797    Redraw; // Redraw on every because engine time is changed so clock should be redrawn
    17931798
    17941799  // Add new trains
     
    17971802    Trains.AddNew;
    17981803    // TODO: Show notification screen with confirmation
     1804    Redraw;
    17991805  end;
    18001806
     
    18031809    LastNewShapeTime := Time;
    18041810    if ShapeCount <= Integer(High(TStationShape)) then Inc(ShapeCount);
     1811    Redraw;
    18051812  end;
    18061813
     
    18101817    Stations.AddNew;
    18111818    ResizeView;
     1819    Redraw;
    18121820  end;
    18131821
     
    18251833      while (Passenger.Shape = Passenger.Station.Shape) or not (Passenger.Shape in GetExistStationShapes) do
    18261834        Passenger.Shape := TStationShape((Integer(Passenger.Shape) + 1) mod Integer(ShapeCount));
    1827     end;
    1828   end;
    1829 
     1835      Redraw;
     1836    end;
     1837  end;
     1838
     1839  // Check station passenger overload state
    18301840  for I := 0 to Stations.Count - 1 do
    18311841  with TMapStation(Stations[I]) do begin
     
    18341844      if OverloadDuration > MaxPassengersOveloadTime then
    18351845        OverloadDuration := MaxPassengersOveloadTime;
     1846      if OverloadDuration < MaxPassengersOveloadTime then Redraw;
    18361847    end;
    18371848    if Passengers.Count <= MaxWaitingPassengers then begin
     1849      if OverloadDuration > 0 then Redraw;
    18381850      OverloadDuration := OverloadDuration - (FTime - FLastTime);
    18391851      if OverloadDuration < 0 then begin
     
    18481860  for I := 0 to Stations.Count - 1 do
    18491861  with TMapStation(Stations[I]) do begin
    1850     if OverloadDuration >= MaxPassengersOveloadTime then State := gsGameOver;
     1862    if OverloadDuration >= MaxPassengersOveloadTime then begin
     1863      State := gsGameOver;
     1864      Redraw;
     1865    end;
    18511866  end;
    18521867
     
    18681883      FocusedStation := GetStationOnPos(View.PointDestToSrc(Position));
    18691884      Line := nil;
    1870       if Assigned(TrackStationDown) then Line := TrackStationDown.Track.Line;
    1871       if Assigned(TrackStationUp) then Line := TrackStationUp.Track.Line;
     1885      if Assigned(TrackStationDown) then begin
     1886        Line := TrackStationDown.Track.Line;
     1887        Redraw;
     1888      end;
     1889      if Assigned(TrackStationUp) then begin
     1890        Line := TrackStationUp.Track.Line;
     1891        Redraw;
     1892      end;
    18721893      if Assigned(Line) and not Assigned(LastFocusedStation) and Assigned(FocusedStation) then begin
    18731894        if Assigned(TrackStationDown) and (TrackStationDown.LineStation.MapStation = FocusedStation) then begin
     
    20642085  LastTickTime := Now;
    20652086  State := gsRunning;
     2087  Redraw;
     2088end;
     2089
     2090procedure TEngine.Redraw;
     2091begin
     2092  RedrawPending := True;
    20662093end;
    20672094
     
    23152342    TargetCanvas.TextOut((TargetCanvas.Width - TargetCanvas.TextWidth(Text)) div 2, 180, Text);
    23162343  end;
     2344  RedrawPending := False;
    23172345end;
    23182346
  • trunk/UFormMain.pas

    r30 r33  
    3737  public
    3838    Engine: TEngine;
    39     procedure Repaint;
    4039  end;
    4140
     
    114113procedure TFormMain.PaintBox1Resize(Sender: TObject);
    115114begin
     115  Engine.Redraw;
    116116end;
    117117
     
    119119begin
    120120  Engine.Tick;
    121   PaintBox1.Repaint;
     121  if Engine.RedrawPending then
     122    PaintBox1.Repaint;
    122123end;
    123124
     
    127128end;
    128129
    129 procedure TFormMain.Repaint;
    130 begin
    131 
    132 end;
    133 
    134130end.
    135131
Note: See TracChangeset for help on using the changeset viewer.