close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 48


Ignore:
Timestamp:
Aug 17, 2014, 11:58:58 AM (10 years ago)
Author:
chronos
Message:
  • Modified: Two dimenzional Size map parameter moved to TMap base class. It will be converted to pixel size to support different mesh types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r47 r48  
    8282  TMap = class
    8383  private
     84    FSize: TPoint;
    8485    function GetSize: TPoint; virtual;
    8586    procedure SetSize(AValue: TPoint); virtual;
     
    114115  THexMap = class(TMap)
    115116  private
    116     FSize: TPoint;
    117     function GetSize: TPoint; override;
    118     procedure SetSize(AValue: TPoint); override;
    119117    function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
    120118    function GetCellNeighbors2(Cell: TCell): TCellArray;
     
    140138  TSquareMap = class(TMap)
    141139  private
    142     FSize: TPoint;
    143     function GetSize: TPoint; override;
    144     procedure SetSize(AValue: TPoint); override;
    145140    function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
    146     function GetCellNeighbours2(Cell: TCell): TCellArray;
     141    function GetCellNeighbors2(Cell: TCell): TCellArray;
    147142  public
    148143    Cells: array of array of TCell;
     144    procedure Generate; override;
    149145    function IsValidIndex(Index: TPoint): Boolean; override;
    150146    function PosToCell(Pos: TPoint; View: TView): TCell; override;
     
    155151    constructor Create; override;
    156152    destructor Destroy; override;
    157     property Size: TPoint read FSize write SetSize;
    158153  end;
    159154
     
    333328{ TSquareMap }
    334329
    335 function TSquareMap.GetSize: TPoint;
    336 begin
    337   Result := FSize;
    338 end;
    339 
    340 procedure TSquareMap.SetSize(AValue: TPoint);
     330procedure TSquareMap.Generate;
    341331var
    342332  X, Y: Integer;
     333  I: Integer;
    343334  NewCell: TCell;
    344   C: Integer;
    345 begin
    346   if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin
    347     // Free previous
    348     for Y := 0 to FSize.Y - 1 do
    349     for X := 0 to FSize.X - 1 do begin
    350       TCell(Cells[Y, X]).Destroy;
    351     end;
    352     FSize := AValue;
    353     // Allocate and init new
    354     SetLength(Cells, FSize.Y, FSize.X);
    355     for Y := 0 to FSize.Y - 1 do
    356     for X := 0 to FSize.X - 1 do begin
    357       NewCell := TCell.Create;
    358       NewCell.Pos := Point(X, Y);
    359       Cells[Y, X] := NewCell;
    360     end;
     335  NeighCells: TCellArray;
     336begin
     337  inherited;
     338  // Free previous
     339  for Y := 0 to Length(Cells) - 1 do
     340  for X := 0 to Length(Cells[Y]) - 1 do begin
     341    TCell(Cells[Y, X]).Destroy;
     342  end;
     343  // Allocate and init new
     344  SetLength(Cells, FSize.Y, FSize.X);
     345  for Y := 0 to FSize.Y - 1 do
     346  for X := 0 to FSize.X - 1 do begin
     347    NewCell := TCell.Create;
     348    NewCell.Pos := Point(X, Y);
     349    Cells[Y, X] := NewCell;
     350  end;
     351  // Generate neightbours
     352  for Y := 0 to FSize.Y - 1 do
     353  for X := 0 to FSize.X - 1 do begin
     354    NeighCells := GetCellNeighbors2(Cells[Y, X]);
     355    for I := 0 to Length(NeighCells) - 1 do
     356      Cells[Y, X].Neighbors.Add(NeighCells[I]);
    361357  end;
    362358end;
     
    430426end;
    431427
    432 function TSquareMap.GetCellNeighbours2(Cell: TCell): TCellArray;
     428function TSquareMap.GetCellNeighbors2(Cell: TCell): TCellArray;
    433429var
    434430  X, Y: Integer;
     
    564560function TMap.GetSize: TPoint;
    565561begin
    566   Result:= Point(0, 0);
     562  Result:= FSize;
    567563end;
    568564
    569565procedure TMap.SetSize(AValue: TPoint);
    570566begin
    571 
     567  if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin
     568    FSize := AValue;
     569    Generate;
     570  end;
    572571end;
    573572
     
    14511450end;
    14521451
    1453 function THexMap.GetSize: TPoint;
    1454 begin
    1455   Result := FSize;
    1456 end;
    1457 
    1458 procedure THexMap.SetSize(AValue: TPoint);
    1459 begin
    1460   if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin
    1461     FSize := AValue;
    1462     Generate;
    1463   end;
    1464 end;
    1465 
    14661452function THexMap.IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
    14671453var
     
    16961682  NeighCells: TCellArray;
    16971683begin
     1684  inherited;
    16981685  // Free previous
    16991686  for Y := 0 to Length(Cells) - 1 do
     
    17211708begin
    17221709  inherited;
     1710  FSize := Point(0, 0);
    17231711end;
    17241712
Note: See TracChangeset for help on using the changeset viewer.