diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index ffa05200c4d91b6957a186a6142ab6abe5d0ab1e..a56c670270a42aeb38439164b4c3a1160b1cee43 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
-{$MODE DELPHI}
-{$modeswitch nestedprocvars}
+{$INCLUDE g_amodes.inc}
unit g_grid;
interface
TBodyGrid = class(TObject)
private
mTileSize: Integer;
+ mMinX, mMinY: Integer; // so grids can start at any origin
mWidth, mHeight: Integer; // in tiles
mGrid: array of Integer; // mWidth*mHeight, index in mCells
mCells: array of TGridCell; // cell pool
function forGridRect (x, y, w, h: Integer; cb: GridInternalCB): Boolean;
public
- constructor Create (aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
+ constructor Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
destructor Destroy (); override;
function insertBody (aObj: TObject; ax, ay, aWidth, aHeight: Integer; aTag: Integer=0): TBodyProxy;
// ////////////////////////////////////////////////////////////////////////// //
-constructor TBodyGrid.Create (aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
+constructor TBodyGrid.Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
var
idx: Integer;
begin
if aPixWidth < aTileSize then aPixWidth := aTileSize;
if aPixHeight < aTileSize then aPixHeight := aTileSize;
mTileSize := aTileSize;
+ mMinX := aMinPixX;
+ mMinY := aMinPixY;
mWidth := (aPixWidth+aTileSize-1) div aTileSize;
mHeight := (aPixHeight+aTileSize-1) div aTileSize;
SetLength(mGrid, mWidth*mHeight);
begin
result := false;
if (w < 1) or (h < 1) or not assigned(cb) then exit;
+ // fix coords
+ Dec(x, mMinX);
+ Dec(y, mMinY);
+ // go on
if (x+w <= 0) or (y+h <= 0) then exit;
if (x >= mWidth*mTileSize) or (y >= mHeight*mTileSize) then exit;
for gy := y div mTileSize to (y+h-1) div mTileSize do