Changeset 286 for trunk


Ignore:
Timestamp:
Feb 23, 2021, 10:47:47 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Optimized TurnToYear function to eliminate unnecessary loop.
Location:
trunk/Packages/CevoComponents
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r256 r286  
    263263
    264264function TurnToYear(Turn: Integer): Integer;
    265 var
    266   I: Integer;
    267265begin
    268266  Result := -4000;
    269   for I := 1 to Turn do
    270     if Result < -1000 then Inc(Result, 50) // 0..60
    271     else if Result < 0 then Inc(Result, 25) // 60..100
    272     else if Result < 1500 then Inc(Result, 20) // 100..175
    273     else if Result < 1750 then Inc(Result, 10) // 175..200
    274     else if Result < 1850 then Inc(Result, 2) // 200..250
    275     else Inc(Result);
     267  if Turn <= 0 then Exit;
     268
     269  // Year -4000..-1000, Turn 0..60
     270  Inc(Result, Min(60, Turn) * 50);
     271  Dec(Turn, Min(60, Turn));
     272  if Turn = 0 then Exit;
     273
     274  // Year -1000..0, Turn 60..100
     275  Inc(Result, Min(40, Turn) * 25);
     276  Dec(Turn, Min(40, Turn));
     277  if Turn = 0 then Exit;
     278
     279  // Year 0..1500, Turn 100..175
     280  Inc(Result, Min(75, Turn) * 20);
     281  Dec(Turn, Min(75, Turn));
     282  if Turn = 0 then Exit;
     283
     284  // Year 1500..1750, Turn 175..200
     285  Inc(Result, Min(25, Turn) * 10);
     286  Dec(Turn, Min(25, Turn));
     287  if Turn = 0 then Exit;
     288
     289  // Year 1750..1850, Turn 200..250
     290  Inc(Result, Min(50, Turn) * 2);
     291  Dec(Turn, Min(50, Turn));
     292  if Turn = 0 then Exit;
     293
     294  // Year 1850.., Turn 250..
     295  Inc(Result, Turn);
    276296end;
    277297
  • trunk/Packages/CevoComponents/StringTables.pas

    r174 r286  
    1919    function GetHandle(const Item: string): integer;
    2020    function LookupByHandle(Handle: integer; Index: integer = -1): string;
    21     function Lookup(const Item: string; Index: integer = -1): string;
     21    function Lookup(const Item: string; Index: Integer = -1): string;
    2222    function Search(const Content: string; var Handle, Index: integer): boolean;
    2323  end;
     
    9999end;
    100100
    101 function TStringTable.Lookup(const Item: string; Index: integer): string;
     101function TStringTable.Lookup(const Item: string; Index: Integer): string;
    102102var
    103   Handle: integer;
     103  Handle: Integer;
    104104begin
    105105  Handle := GetHandle(Item);
    106106  if Handle >= 0 then
    107     result := LookupByHandle(Handle, Index)
     107    Result := LookupByHandle(Handle, Index)
    108108  else
    109     result := '';
    110   if result = '' then
     109    Result := '';
     110  if Result = '' then
    111111    if Index < 0 then
    112       result := Format('[%s]', [Item])
     112      Result := Format('[%s]', [Item])
    113113    else
    114       result := Format('[%s %d]', [Item, Index])
     114      Result := Format('[%s %d]', [Item, Index])
    115115end;
    116116
Note: See TracChangeset for help on using the changeset viewer.