Changeset 414


Ignore:
Timestamp:
Jan 10, 2025, 4:24:19 PM (3 hours ago)
Author:
chronos
Message:
  • Modified: Lowered idle CPU consumption.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r408 r414  
    213213  ThemeManager1.Theme := ThemeManager1.Themes.FindByName(String(XmlConfig1.GetValue('Theme', 'System')));
    214214  LastOpenedList1.LoadFromXMLConfig(XMLConfig1, 'RecentFiles');
    215   DevelMode := XMLConfig1.GetValue('DevelMode', false);
     215  DevelMode := XMLConfig1.GetValue('DevelMode', False);
    216216  AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50);
    217217  Translator1.Language := Translator1.Languages.SearchByCode(String(XMLConfig1.GetValue('Language', '')));
  • trunk/Forms/FormClient.pas

    r404 r414  
    320320  if RedrawPending and not Drawing then begin
    321321    Drawing := True;
    322     if not Core.Core.DevelMode then RedrawPending := False;
     322    RedrawPending := False;
     323    Timer1.Enabled := False;
    323324    TimerPeriod := (9 * TimerPeriod + (Now - LastTimerTime)) / 10;
    324325    LastTimerTime := Now;
     
    358359begin
    359360  Redraw;
     361  Core.Core.FormMain.UpdateInterface;
    360362end;
    361363
     
    421423begin
    422424  RedrawPending := True;
     425  Timer1.Enabled := True;
    423426end;
    424427
  • trunk/Forms/FormMain.lfm

    r364 r414  
    11object FormMain: TFormMain
    22  Left = 534
    3   Height = 959
     3  Height = 925
    44  Top = 223
    55  Width = 1491
    66  Caption = 'xTactics'
    7   ClientHeight = 959
     7  ClientHeight = 925
    88  ClientWidth = 1491
    99  DesignTimePPI = 144
     
    9797  object PanelMain: TPanel
    9898    Left = 0
    99     Height = 919
     99    Height = 885
    100100    Top = 40
    101101    Width = 1491
     
    107107  object MainMenu1: TMainMenu
    108108    Images = Core.ImageListSmall
    109     Left = 224
    110     Top = 48
     109    Left = 88
     110    Top = 112
    111111    object MenuItem1: TMenuItem
    112112      Caption = 'Game'
     
    233233    end
    234234  end
    235   object Timer1: TTimer
    236     Interval = 20
    237     OnTimer = Timer1Timer
    238     Left = 128
    239     Top = 263
    240   end
    241235  object ActionList1: TActionList
    242236    Images = Core.ImageListSmall
    243     Left = 280
    244     Top = 152
     237    Left = 88
     238    Top = 184
    245239    object AToolBarBigIcons: TAction
    246240      Caption = 'Toolbar big icons'
     
    265259  end
    266260  object PopupMenuToolbar: TPopupMenu
    267     Left = 452
    268     Top = 98
     261    Left = 432
     262    Top = 112
    269263    object MenuItem18: TMenuItem
    270264      Action = AToolBarBigIcons
     
    272266  end
    273267  object PopupMenuOpenRecent: TPopupMenu
    274     Left = 448
    275     Top = 251
     268    Left = 432
     269    Top = 184
    276270  end
    277271end
  • trunk/Forms/FormMain.pas

    r364 r414  
    6767    PopupMenuToolbar: TPopupMenu;
    6868    Separator1: TMenuItem;
    69     Timer1: TTimer;
    7069    ToolBar1: TToolBar;
    7170    ToolButton1: TToolButton;
     
    9493    procedure FormDestroy(Sender: TObject);
    9594    procedure EraseBackground(DC: HDC); override;
    96     procedure Timer1Timer(Sender: TObject);
    9795  private
    9896    FormActivated: Boolean;
     
    106104    FormUnitMoves: TFormUnitMoves;
    107105    FormCharts: TFormCharts;
     106    procedure UpdateInterface;
    108107    procedure LoadConfig(Config: TXmlConfig; Path: string);
    109108    procedure SaveConfig(Config: TXmlConfig; Path: string);
     
    128127begin
    129128  // Do nothing, all background space covered by controls
    130 end;
    131 
    132 procedure TFormMain.Timer1Timer(Sender: TObject);
    133 var
    134   NewCaption: string;
    135 begin
    136   NewCaption := 'xTactics';
    137   if Assigned(Core.Core.Game.CurrentPlayer) then
    138     NewCaption := Core.Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' +
    139     IntToStr(Core.Core.Game.TurnCounter) + ' - ' + NewCaption;
    140   Caption := NewCaption;
    141129end;
    142130
     
    311299end;
    312300
     301procedure TFormMain.UpdateInterface;
     302var
     303  NewCaption: string;
     304begin
     305  NewCaption := 'xTactics';
     306  if Assigned(Core.Core.Game.CurrentPlayer) then
     307    NewCaption := Core.Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' +
     308    IntToStr(Core.Core.Game.TurnCounter) + ' - ' + NewCaption;
     309  Caption := NewCaption;
     310end;
     311
    313312procedure TFormMain.FormShow(Sender: TObject);
    314313begin
  • trunk/Game.pas

    r407 r414  
    5959    procedure WinObjectiveMapPrepare;
    6060    procedure BuildCity(Cell: TCell);
     61    procedure DoChange;
    6162  public
    6263    GameSystem: TGameSystem;
     
    510511end;
    511512
     513procedure TGame.DoChange;
     514begin
     515  if Assigned(FOnChange) then
     516    FOnChange(Self);
     517end;
     518
    512519procedure TGame.Assign(Source: TGame);
    513520begin
     
    678685    FreeAndNil(Doc);
    679686  end;
     687  DoChange;
    680688end;
    681689
     
    851859  CurrentPlayer.RemoveInvalidMoves;
    852860  CurrentPlayer.InitUnitMoves;
    853   if Assigned(FOnChange) then
    854     FOnChange(Self);
     861  DoChange;
    855862end;
    856863
     
    10091016
    10101017  ComputePlayerStats;
     1018  DoChange;
    10111019end;
    10121020
     
    10151023  Running := False;
    10161024  if Assigned(OnWin) then OnWin(Winner);
     1025  DoChange;
    10171026end;
    10181027
  • trunk/Packages/PinConnection/CommThread.pas

    r340 r414  
    1212  TReceiveDataEvent = procedure(Stream: TMemoryStream) of object;
    1313
    14   { TCommThreadReceiveThread }
    15 
    16   TCommThreadReceiveThread = class(TTermThread)
     14  { TCommThreadReceiveDataThread }
     15
     16  TCommThreadReceiveDataThread = class(TTermThread)
    1717  public
    1818    Parent: TCommThread;
     
    2424  end;
    2525
     26  { TCommThreadReceiveStatusThread }
     27
     28  TCommThreadReceiveStatusThread = class(TTermThread)
     29  public
     30    Parent: TCommThread;
     31    Stream: TBinarySerializer;
     32    procedure Execute; override;
     33    constructor Create(CreateSuspended: Boolean;
     34      const StackSize: SizeUInt = DefaultStackSize);
     35    destructor Destroy; override;
     36  end;
     37
    2638  { TCommThread }
    2739
     
    2941  private
    3042    //FOnReceiveData: TReceiveDataEvent;
    31     FReceiveThread: TCommThreadReceiveThread;
     43    FReceiveDataThread: TCommThreadReceiveDataThread;
     44    FReceiveStatusThread: TCommThreadReceiveStatusThread;
    3245    FInputBuffer: TBinarySerializer;
    3346    FInputBufferLock: TCriticalSection;
     
    91104
    92105  if AValue then begin
    93     FReceiveThread := TCommThreadReceiveThread.Create(True);
    94     FReceiveThread.FreeOnTerminate := False;
    95     FReceiveThread.Parent := Self;
    96     FReceiveThread.Name := 'CommThread';
    97     FReceiveThread.Start;
     106    FReceiveDataThread := TCommThreadReceiveDataThread.Create(True);
     107    FReceiveDataThread.FreeOnTerminate := False;
     108    FReceiveDataThread.Parent := Self;
     109    FReceiveDataThread.Name := 'CommThreadData';
     110    FReceiveDataThread.Start;
     111
     112    FReceiveStatusThread := TCommThreadReceiveStatusThread.Create(True);
     113    FReceiveStatusThread.FreeOnTerminate := False;
     114    FReceiveStatusThread.Parent := Self;
     115    FReceiveStatusThread.Name := 'CommThreadStatus';
     116    FReceiveStatusThread.Start;
    98117  end else begin
    99     FreeAndNil(FReceiveThread);
     118    FreeAndNil(FReceiveDataThread);
     119    FreeAndNil(FReceiveStatusThread);
    100120  end;
    101121  inherited;
     
    134154end;
    135155
    136 { TCommThreadReceiveThread }
    137 
    138 procedure TCommThreadReceiveThread.Execute;
    139 var
    140   TempStatus: Integer;
    141   DoSleep: Boolean;
     156{ TCommThreadReceiveDataThread }
     157
     158procedure TCommThreadReceiveDataThread.Execute;
    142159begin
    143160  with Parent do
    144161  repeat
    145     DoSleep := True;
    146162    // Check if new data arrived
    147     if FDataAvailable.WaitFor(0) = wrSignaled then begin
    148       DoSleep := False;
     163    if FDataAvailable.WaitFor(100) = wrSignaled then begin
    149164      try
    150165        FInputBufferLock.Acquire;
     
    157172      Pin.Send(Stream.List);
    158173    end;
    159 
     174  until Terminated;
     175end;
     176
     177constructor TCommThreadReceiveDataThread.Create(CreateSuspended: Boolean;
     178  const StackSize: SizeUInt);
     179begin
     180  inherited;
     181  Stream := TBinarySerializer.Create;
     182  Stream.List := TListByte.Create;
     183  Stream.OwnsList := True;
     184end;
     185
     186destructor TCommThreadReceiveDataThread.Destroy;
     187begin
     188  FreeAndNil(Stream);
     189  inherited;
     190end;
     191
     192{ TCommThreadReceiveStatusThread }
     193
     194procedure TCommThreadReceiveStatusThread.Execute;
     195var
     196  TempStatus: Integer;
     197begin
     198  with Parent do
     199  repeat
    160200    // Check if state changed
    161     if FStatusEvent.WaitFor(0) = wrSignaled then begin
    162       DoSleep := False;
     201    if FStatusEvent.WaitFor(100) = wrSignaled then begin
    163202      try
    164203        FInputBufferLock.Acquire;
     
    170209      Pin.Status := TempStatus;
    171210    end;
    172     if not Terminated and DoSleep then begin
    173       Sleep(1);
    174     end;
    175211  until Terminated;
    176212end;
    177213
    178 constructor TCommThreadReceiveThread.Create(CreateSuspended: Boolean;
     214constructor TCommThreadReceiveStatusThread.Create(CreateSuspended: Boolean;
    179215  const StackSize: SizeUInt);
    180216begin
     
    185221end;
    186222
    187 destructor TCommThreadReceiveThread.Destroy;
     223destructor TCommThreadReceiveStatusThread.Destroy;
    188224begin
    189225  FreeAndNil(Stream);
Note: See TracChangeset for help on using the changeset viewer.