Changeset 164 for trunk/UGame.pas


Ignore:
Timestamp:
Nov 21, 2017, 6:39:06 PM (7 years ago)
Author:
chronos
Message:
  • Modified: More work on voronoi type map generation.
  • Fixed: Do not generate map twice on map config load.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r162 r164  
    174174  private
    175175    FSize: TPoint;
     176    FUpdateCount: Integer;
    176177    function GetSize: TPoint; virtual;
    177178    procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
     
    213214    procedure CreateLinks;
    214215    procedure Clear;
     216    procedure BeginUpdate;
     217    procedure EndUpdate;
    215218    constructor Create; virtual;
    216219    destructor Destroy; override;
     
    982985  CellText: string;
    983986  CellLink: TCellLink;
     987  NeighCell: TCell;
    984988begin
    985989  with Canvas, View do
     
    10281032        Player.Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, '', View, Cell.MapCell);
    10291033      end;
     1034
     1035      {// Draw links to neighbors
     1036      for NeighCell in Cell.MapCell.Neighbors do begin
     1037        Pen.Color := clYellow;
     1038        MoveTo(View.CellToCanvasPos(Cell.MapCell.PosPx));
     1039        LineTo(View.CellToCanvasPos(NeighCell.PosPx));
     1040      end;
     1041      }
    10301042    end;
    10311043
     
    13401352  if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin
    13411353    FSize := AValue;
    1342     Generate;
     1354    if FUpdateCount = 0 then Generate;
    13431355  end;
    13441356end;
     
    14341446//  I: Integer;
    14351447begin
     1448  FUpdateCount := Source.FUpdateCount;
    14361449  MaxPower := Source.MaxPower;
    14371450  Game := Source.Game;
     
    17131726  Cells.Clear;
    17141727  FNewCellId := 1;
     1728end;
     1729
     1730procedure TMap.BeginUpdate;
     1731begin
     1732  Inc(FUpdateCount);
     1733end;
     1734
     1735procedure TMap.EndUpdate;
     1736begin
     1737  if FUpdateCount > 0 then Dec(FUpdateCount);
     1738  if FUpdateCount = 0 then Generate;
    17151739end;
    17161740
     
    32173241begin
    32183242  with Config do begin
    3219     MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon)));
     3243    try
     3244      Map.BeginUpdate;
     3245      MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon)));
     3246      Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10),
     3247        GetValue(DOMString(Path + '/MapSizeY'), 10));
     3248    finally
     3249      Map.EndUpdate;
     3250    end;
    32203251    MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName)));
    32213252    SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), False);
     
    32233254    VoidEnabled := GetValue(DOMString(Path + '/VoidEnabled'), True);
    32243255    VoidPercentage := GetValue(DOMString(Path + '/VoidPercentage'), 20);
    3225     Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10),
    3226       GetValue(DOMString(Path + '/MapSizeY'), 10));
    32273256    Value := GetValue(DOMString(Path + '/MapShape'), 0);
    32283257    if (Value >= Integer(Low(TMapShape))) and (Value <= Integer(High(TMapShape))) then
Note: See TracChangeset for help on using the changeset viewer.