summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 487e049)
raw | patch | inline | side by side (parent: 487e049)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 22 Aug 2017 19:21:55 +0000 (22:21 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 18:23:55 +0000 (21:23 +0300) |
src/game/g_grid.pas | patch | blob | history |
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index c1a5f0777cd25a2416e92da03da53834e744a571..6ff288c5de2d2549fc98e0dd4a8be0e7e67bd2cf 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
function insertBody (aObj: ITP; ax, ay, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
procedure removeBody (body: TBodyProxyId); // WARNING! this WILL destroy proxy!
- procedure moveBody (body: TBodyProxyId; dx, dy: Integer);
- procedure resizeBody (body: TBodyProxyId; sx, sy: Integer);
- procedure moveResizeBody (body: TBodyProxyId; dx, dy, sx, sy: Integer);
+ procedure moveBody (body: TBodyProxyId; nx, ny: Integer);
+ procedure resizeBody (body: TBodyProxyId; nw, nh: Integer);
+ procedure moveResizeBody (body: TBodyProxyId; nx, ny, nw, nh: Integer);
function insideGrid (x, y: Integer): Boolean; inline;
// ////////////////////////////////////////////////////////////////////////// //
-procedure TBodyGridBase.moveResizeBody (body: TBodyProxyId; dx, dy, sx, sy: Integer);
+procedure TBodyGridBase.moveResizeBody (body: TBodyProxyId; nx, ny, nw, nh: Integer);
var
px: PBodyProxyRec;
x0, y0, w, h: Integer;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
- if (dx = 0) and (dy = 0) and (sx = 0) and (sy = 0) then exit;
px := @mProxies[body];
x0 := px.mX;
y0 := px.mY;
w := px.mWidth;
h := px.mHeight;
+ if (nx = x0) and (ny = y0) and (nw = w) and (nh = h) then exit;
// did any corner crossed tile boundary?
- if (x0 div mTileSize <> (x0+dx) div mTileSize) or
- (y0 div mTileSize <> (y0+dx) div mTileSize) or
- ((x0+w) div mTileSize <> (x0+w+sx) div mTileSize) or
- ((y0+h) div mTileSize <> (y0+h+sy) div mTileSize) then
+ if (x0 div mTileSize <> nx div mTileSize) or
+ (y0 div mTileSize <> ny div mTileSize) or
+ ((x0+w) div mTileSize <> (nx+nw) div mTileSize) or
+ ((y0+h) div mTileSize <> (ny+nh) div mTileSize) then
begin
removeInternal(body);
- Inc(px.mX, dx);
- Inc(px.mY, dy);
- Inc(px.mWidth, sx);
- Inc(px.mHeight, sy);
+ px.mX := nx;
+ px.mY := ny;
+ px.mWidth := nw;
+ px.mHeight := nh;
insertInternal(body);
end
else
begin
- Inc(px.mX, dx);
- Inc(px.mY, dy);
- Inc(px.mWidth, sx);
- Inc(px.mHeight, sy);
+ px.mX := nx;
+ px.mY := ny;
+ px.mWidth := nw;
+ px.mHeight := nh;
end;
end;
-procedure TBodyGridBase.moveBody (body: TBodyProxyId; dx, dy: Integer);
+procedure TBodyGridBase.moveBody (body: TBodyProxyId; nx, ny: Integer);
var
px: PBodyProxyRec;
- nx, ny: Integer;
+ x0, y0: Integer;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
- if (dx = 0) and (dy = 0) then exit;
// check if tile coords was changed
px := @mProxies[body];
- nx := px.mX+dx;
- ny := px.mY+dy;
- if (nx div mTileSize <> px.mX div mTileSize) or (ny div mTileSize <> px.mY div mTileSize) then
+ x0 := px.mX;
+ y0 := px.mY;
+ if (nx = x0) and (ny = y0) then exit;
+ if (nx div mTileSize <> x0 div mTileSize) or (ny div mTileSize <> y0 div mTileSize) then
begin
// crossed tile boundary, do heavy work
- moveResizeBody(body, dx, dy, 0, 0);
+ removeInternal(body);
+ px.mX := nx;
+ px.mY := ny;
+ insertInternal(body);
end
else
begin
end;
end;
-procedure TBodyGridBase.resizeBody (body: TBodyProxyId; sx, sy: Integer);
+procedure TBodyGridBase.resizeBody (body: TBodyProxyId; nw, nh: Integer);
var
px: PBodyProxyRec;
- x0, y0: Integer;
- nw, nh: Integer;
+ x0, y0, w, h: Integer;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
- if (sx = 0) and (sy = 0) then exit;
// check if tile coords was changed
px := @mProxies[body];
x0 := px.mX;
y0 := px.mY;
- nw := px.mWidth+sx;
- nh := px.mHeight+sy;
- if ((x0+px.mWidth) div mTileSize <> (x0+nw) div mTileSize) or
- ((y0+px.mHeight) div mTileSize <> (y0+nh) div mTileSize) then
+ w := px.mWidth;
+ h := px.mHeight;
+ if ((x0+w) div mTileSize <> (x0+nw) div mTileSize) or
+ ((y0+h) div mTileSize <> (y0+nh) div mTileSize) then
begin
// crossed tile boundary, do heavy work
- moveResizeBody(body, 0, 0, sx, sy);
+ removeInternal(body);
+ px.mWidth := nw;
+ px.mHeight := nh;
+ insertInternal(body);
end
else
begin