summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1f2ea3a)
raw | patch | inline | side by side (parent: 1f2ea3a)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 22:07:18 +0000 (01:07 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 22:07:44 +0000 (01:07 +0300) |
src/game/g_grid.pas | patch | blob | history | |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_monsters.pas | patch | blob | history |
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index 647a45d8329519461cb257e423a8176de017d077..34cfbef88086e837be79b5c718da17e523bc0130 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
{$IF DEFINED(D2F_DEBUG)}
{.$DEFINE D2F_DEBUG_RAYTRACE}
{.$DEFINE D2F_DEBUG_XXQ}
+ {.$DEFINE D2F_DEBUG_MOVER}
{$ENDIF}
unit g_grid;
// `false` if `body` is surely invalid
function getBodyXY (body: TBodyProxyId; out rx, ry: Integer): Boolean; inline;
+ function getBodyWH (body: TBodyProxyId; out rw, rh: Integer): Boolean; inline;
+ function getBodyDims (body: TBodyProxyId; out rx, ry, rw, rh: Integer): Boolean; inline;
//WARNING: don't modify grid while any query is in progress (no checks are made!)
// you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
end;
+function TBodyGridBase.getBodyWH (body: TBodyProxyId; out rw, rh: Integer): Boolean; inline;
+begin
+ if (body >= 0) and (body < Length(mProxies)) then
+ begin
+ with mProxies[body] do begin rw := mWidth; rh := mHeight; end;
+ result := true;
+ end
+ else
+ begin
+ rw := 0;
+ rh := 0;
+ result := false;
+ end;
+end;
+
+
+function TBodyGridBase.getBodyDims (body: TBodyProxyId; out rx, ry, rw, rh: Integer): Boolean; inline;
+begin
+ if (body >= 0) and (body < Length(mProxies)) then
+ begin
+ with mProxies[body] do begin rx := mX; ry := mY; rw := mWidth; rh := mHeight; end;
+ result := true;
+ end
+ else
+ begin
+ rx := 0;
+ ry := 0;
+ rw := 0;
+ rh := 0;
+ result := false;
+ end;
+end;
+
+
+
// ////////////////////////////////////////////////////////////////////////// //
function TBodyGridBase.getProxyEnabled (pid: TBodyProxyId): Boolean; inline;
begin
y0 := px.mY;
w := px.mWidth;
h := px.mHeight;
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format('proxy #%d: MOVERESIZE: xg=%d;yg=%d;w=%d;h=%d;nx=%d;ny=%d;nw=%d;nh=%d', [body, x0-mMinX, y0-mMinY, w, h, nx-mMinX, ny-mMinY, nw, nh]), MSG_NOTIFY);
+ {$ENDIF}
if (nx = x0) and (ny = y0) and (nw = w) and (nh = h) then exit;
+ // map -> grid
+ Dec(x0, mMinX);
+ Dec(y0, mMinY);
+ Dec(nx, mMinX);
+ Dec(ny, mMinY);
// did any corner crossed tile boundary?
if (x0 div mTileSize <> nx div mTileSize) or
(y0 div mTileSize <> ny div mTileSize) or
((y0+h) div mTileSize <> (ny+nh) div mTileSize) then
begin
removeInternal(body);
- px.mX := nx;
- px.mY := ny;
+ px.mX := nx+mMinX;
+ px.mY := ny+mMinY;
px.mWidth := nw;
px.mHeight := nh;
insertInternal(body);
end
else
begin
- px.mX := nx;
- px.mY := ny;
+ px.mX := nx+mMinX;
+ px.mY := ny+mMinY;
px.mWidth := nw;
px.mHeight := nh;
end;
if (nx = x0) and (ny = y0) then exit;
// map -> grid
Dec(x0, mMinX);
- Dec(y0, mMinX);
+ Dec(y0, mMinY);
Dec(nx, mMinX);
- Dec(ny, mMinX);
+ Dec(ny, mMinY);
// check for heavy work
pw := px.mWidth;
ph := px.mHeight;
ogy1 := (y0+ph-1) div mTileSize;
ngx1 := (nx+pw-1) div mTileSize;
ngy1 := (ny+ph-1) div mTileSize;
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format('proxy #%d: checkmove: xg=%d;yg=%d;w=%d;h=%d;nx=%d;ny=%d og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [body, x0, y0, pw, ph, nx, ny, ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$ENDIF}
if (ogx0 <> ngx0) or (ogy0 <> ngy0) or (ogx1 <> ngx1) or (ogy1 <> ngy1) then
begin
// crossed tile boundary, do heavy work
gh := mHeight;
// cycle with old rect, remove body where it is necessary
// optimized for horizontal moves
- //e_WriteLog(Format('og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format('proxy #%d: xg=%d;yg=%d;w=%d;h=%d;nx=%d;ny=%d og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [body, x0, y0, pw, ph, nx, ny, ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$ENDIF}
// remove stale marks
if not ((ogy0 >= gh) or (ogy1 < 0)) and
not ((ogx0 >= gw) or (ogx1 < 0)) then
if (ogy0 < 0) then ogy0 := 0;
if (ogx1 > gw-1) then ogx1 := gw-1;
if (ogy1 > gh-1) then ogy1 := gh-1;
- //e_WriteLog(Format(' norm og:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' norm og:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1]), MSG_NOTIFY);
+ {$ENDIF}
for gx := ogx0 to ogx1 do
begin
if (gx < ngx0) or (gx > ngx1) then
// this column is completely outside of new rect
for gy := ogy0 to ogy1 do
begin
- //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' remove0:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$ENDIF}
remover(gy*gw+gx, body);
end;
end
begin
if (gy < ngy0) or (gy > ngy1) then
begin
- //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' remove1:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$ENDIF}
remover(gy*gw+gx, body);
end;
end;
if (ngy0 < 0) then ngy0 := 0;
if (ngx1 > gw-1) then ngx1 := gw-1;
if (ngy1 > gh-1) then ngy1 := gh-1;
- //e_WriteLog(Format(' norm ng:(%d,%d)-(%d,%d)', [ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' norm ng:(%d,%d)-(%d,%d)', [ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$ENDIF}
for gx := ngx0 to ngx1 do
begin
if (gx < ogx0) or (gx > ogx1) then
// this column is completely outside of old rect
for gy := ngy0 to ngy1 do
begin
- //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' insert0:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$ENDIF}
inserter(gy*gw+gx, body);
end;
end
begin
if (gy < ogy0) or (gy > ogy1) then
begin
- //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format(' insert1:(%d,%d)', [gx, gy]), MSG_NOTIFY);
+ {$ENDIF}
inserter(gy*gw+gx, body);
end;
end;
end;
end;
// done
+ end
+ else
+ begin
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format('proxy #%d: GRID OK: xg=%d;yg=%d;w=%d;h=%d;nx=%d;ny=%d og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [body, x0, y0, pw, ph, nx, ny, ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
+ {$ENDIF}
end;
// update coordinates
px.mX := nx+mMinX;
if (body < 0) or (body > High(mProxies)) then exit; // just in case
// check if tile coords was changed
px := @mProxies[body];
- x0 := px.mX;
- y0 := px.mY;
+ x0 := px.mX-mMinX;
+ y0 := px.mY-mMinY;
w := px.mWidth;
h := px.mHeight;
+ {$IF DEFINED(D2F_DEBUG_MOVER)}
+ e_WriteLog(Format('proxy #%d: RESIZE: xg=%d;yg=%d;w=%d;h=%d;nw=%d;nh=%d', [body, x0, y0, w, h, nw, nh]), MSG_NOTIFY);
+ {$ENDIF}
if ((x0+w) div mTileSize <> (x0+nw) div mTileSize) or
((y0+h) div mTileSize <> (y0+nh) div mTileSize) then
begin
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index d7ab6bfec15ac5484115a67a40a23b0f22d30b24..7d4259c061c6e3a2a0408460e77d51ed426791b7 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
var
mon: TMonster;
+ x, y, w, h: Integer;
begin
result := false;
msB := ev.bstate;
end;
exit;
end;
+ // C-T: teleport player
+ if (ev.scan = SDL_SCANCODE_T) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
+ begin
+ result := true;
+ //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
+ if (gPlayers[0] <> nil) then
+ begin
+ gPlayers[0].getMapBox(x, y, w, h);
+ gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
+ end;
+ exit;
+ end;
end;
end;
index 7b22e56dfcc3cffee624d01a965ac6dfa208e31f..5d529e2593fbfc01b3c8762197ef35b9eac7d575 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
{$INCLUDE ../shared/a_modes.inc}
+{.$DEFINE D2F_DEBUG_MONS_MOVE}
unit g_monsters;
interface
//WARNING! call this after monster position was changed, or coldet will not work right!
procedure TMonster.positionChanged ();
var
- x, y: Integer;
+ x, y, w, h: Integer;
+ nx, ny, nw, nh: Integer;
begin
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
//e_WriteLog(Format('monster #%d(%u): pos=(%d,%d); rpos=(%d,%d)', [mArrIdx, UID, FObj.X, FObj.Y, FObj.Rect.X, FObj.Rect.Y]), MSG_NOTIFY);
mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
monsGrid.getBodyXY(mProxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): inserted into the grid; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): inserted into the grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
{$ENDIF}
end
else
begin
- monsGrid.getBodyXY(mProxyId, x, y);
- if (FObj.X+FObj.Rect.X = x) and (FObj.Y+FObj.Rect.Y = y) then exit; // nothing to do
- {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}e_WriteLog(Format('monster #%d(%u): updating tree; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);{$ENDIF}
-
- {$IF TRUE}
- monsGrid.moveBody(mProxyId, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y);
- {$ELSE}
- monsGrid.removeBody(mProxyId);
- mProxyId := monsGrid.insertBody(self, FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
- {$ENDIF}
+ monsGrid.getBodyDims(mProxyId, x, y, w, h);
+ getMapBox(nx, ny, nw, nh);
+ if (w <> nw) or (h <> nh) then
+ begin
+ {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
+ e_WriteLog(Format('monster #%d:(%u): resized; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ monsGrid.moveResizeBody(mProxyId, nx, ny, nw, nh);
+ end
+ else if (x <> nx) or (y <> ny) then
+ begin
+ {$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
+ e_WriteLog(Format('monster #%d:(%u): updating grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
+ {$ENDIF}
+ monsGrid.moveBody(mProxyId, nx, ny);
+ end
+ else
+ begin
+ exit; // nothing to do
+ end;
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
monsGrid.getBodyXY(mProxyId, x, y);
- e_WriteLog(Format('monster #%d(%u): updated tree; mProxyid=%d; x=%d; y=%d', [mArrIdx, UID, mProxyId, x, y]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): updated grid; mProxyid=%d; gx=%d; gy=%d', [mArrIdx, UID, mProxyId, x-monsGrid.gridX0, y-monsGrid.gridY0]), MSG_NOTIFY);
{$ENDIF}
end;
end;
begin
monsGrid.removeBody(mProxyId);
{$IF DEFINED(D2F_DEBUG_MONS_MOVE)}
- e_WriteLog(Format('monster #%d(%u): removed from tree; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
+ e_WriteLog(Format('monster #%d:(%u): removed from tree; mProxyid=%d', [mArrIdx, UID, mProxyId]), MSG_NOTIFY);
{$ENDIF}
end;
mProxyId := -1;