summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f98d086)
raw | patch | inline | side by side (parent: f98d086)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 4 Sep 2017 19:25:34 +0000 (22:25 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 4 Sep 2017 19:25:51 +0000 (22:25 +0300) |
src/game/g_grid.pas | patch | blob | history | |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_panel.pas | patch | blob | history |
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index fae595dc6c0844388402cfaa738905a28eaacf54..092f13ee201a53a54939da7ceced246ef4e39c24 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
function lineAABBIntersects (x0, y0, x1, y1: Integer; bx, by, bw, bh: Integer; out inx, iny: Integer): Boolean;
// sweep two AABB's to see if and when they are overlapping
-// returns `true` if collision was detected (or boxes overlaps)
+// returns `true` if collision was detected (but boxes doesn't overlap)
+// u1 and u1 has no sense if no collision was detected
// u0 = normalized time of first collision (i.e. collision starts at myMove*u0)
// u1 = normalized time of second collision (i.e. collision stops after myMove*u1)
-// if no collision was detected:
-// u1 < 0: no collision at all
-// u1 >= 0: boxes are overlapping at the start; u0 has no meaning, u1 is exit time, hitedge is undefined
// hitedge for `it`: 0: top; 1: right; 2: bottom; 3: left
// enter/exit coords will form non-intersecting configuration (i.e. will be before/after the actual collision)
function sweepAABB (mex0, mey0, mew, meh: Integer; medx, medy: Integer; itx0, ity0, itw, ith: Integer;
lq: LongWord;
f, ptag: Integer;
minu0: Single = 100000.0;
- u0: Single;
+ u0, u1: Single;
hedge: Integer;
cx0, cy0, cx1, cy1: Integer;
begin
end;
lq := mLastQuery;
- gy := cy0;
- while (gy <= cy1) do
+ for gy := cy0 div mTileSize to cy1 div mTileSize do
begin
- gx := cx0;
- while (gx <= cx1) do
+ for gx := cx0 div mTileSize to cx1 div mTileSize do
begin
- cidx := mGrid[(gy div mTileSize)*mWidth+(gx div mTileSize)];
+ cidx := mGrid[gy*mWidth+gx];
while (cidx <> -1) do
begin
cc := @mCells[cidx];
begin
if not cb(px.mObj, ptag) then continue;
end;
- if not sweepAABB(cx0+mMinX, cy0+mMinY, aw, ah, dx, dy, px.mX, px.mY, px.mWidth, px.mHeight, @u0, @hedge) then
+ if not sweepAABB(ax0, ay0, aw, ah, dx, dy, px.mX, px.mY, px.mWidth, px.mHeight, @u0, @hedge, @u1) then
begin
+ {
+ if (u1 >= 0) then
+ begin
+ // overlapping
+ ex := ax0;
+ ey := ay0;
+ result := px.mObj;
+ mInQuery := false;
+ exit;
+ end;
+ }
continue;
end;
if (minu0 > u0) then
minu0 := u0;
if (u0 = 0.0) then
begin
- ex := cx0+mMinX;
- ey := cy0+mMinY;
+ ex := ax0;
+ ey := ay0;
mInQuery := false;
exit;
end;
// next cell
cidx := cc.next;
end;
- Inc(gx, mTileSize);
end;
- Inc(gy, mTileSize);
end;
if (minu0 <= 1.0) then
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index 1f548e4c2058b560b06054513333e175df7ee7bc..47d34812cea47f6dd0f13797b9f144292a95f1c7 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
showLayersWindow: Boolean = false;
showOutlineWindow: Boolean = false;
showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
+ showTraceBox: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
// ////////////////////////////////////////////////////////////////////////// //
end;
end;
+ procedure drawTraceBox ();
+ var
+ plr: TPlayer;
+ px, py, pw, ph: Integer;
+ pdx, pdy: Integer;
+ ex, ey: Integer;
+ pan: TPanel;
+ begin
+ if (Length(gPlayers) < 1) then exit;
+ plr := gPlayers[0];
+ if (plr = nil) then exit;
+ plr.getMapBox(px, py, pw, ph);
+ drawRect(px, py, pw, ph, 255, 0, 255, 200);
+ pdx := pmsCurMapX-(px+pw div 2);
+ pdy := pmsCurMapY-(py+ph div 2);
+ drawLine(px+pw div 2, py+ph div 2, px+pw div 2+pdx, py+ph div 2+pdy, 255, 0, 255, 200);
+ pan := mapGrid.traceBox(ex, ey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
+ if (pan = nil) then
+ begin
+ drawRect(px+pdx, py+pdy, pw, ph, 255, 255, 255, 180);
+ end
+ else
+ begin
+ drawRect(px+pdx, py+pdy, pw, ph, 255, 255, 0, 180);
+ end;
+ drawRect(ex, ey, pw, ph, 255, 127, 0, 180);
+ end;
+
procedure hilightCell (cx, cy: Integer);
begin
fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
if showTriggers then drawTriggers();
if showGrid then drawSelectedPlatformCells();
- drawAwakeCells();
+ //drawAwakeCells();
+
+ if showTraceBox then drawTraceBox();
//drawGibsBoxes();
end;
end;
+procedure dbgToggleTraceBox (arg: Integer=-1); begin if (arg < 0) then showTraceBox := not showTraceBox else showTraceBox := (arg > 0); end;
+
procedure cbAtcurSelectMonster ();
function monsAtDump (mon: TMonster; tag: Integer): Boolean;
begin
begin
result := false; // don't stop
if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
- e_LogWritefln('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]);
+ e_LogWritefln('wall ''%s'' #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.mapId, pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]);
dumpPublishedProperties(pan);
end;
var
cmdAdd('mon_info', bcToggleMonsterInfo, 'toggle monster info', 'monster control');
cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr, 'toggle monster LOS to player', 'monster control');
cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
- cmdAdd('mon_wakeup', bcMonsterWakeup, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
+ cmdAdd('mon_wakeup', bcMonsterWakeup, 'wake up selected monster', 'monster control');
cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters, 'dump monsters in cell', 'monster control');
cmdAdd('atcur_dump_walls', cbAtcurDumpWalls, 'dump walls in cell', 'wall control');
cmdAdd('atcur_disable_walls', cbAtcurToggleWalls, 'disable walls', 'wall control');
+
+ cmdAdd('dbg_tracebox', dbgToggleTraceBox, 'disable walls', 'wall control');
end;
keybindAdd('M-O', 'mplat_toggle');
keybindAdd('C-T', 'plr_teleport');
+ keybindAdd('M-T', 'dbg_tracebox');
keybindAdd('C-P', 'dbg_curpos');
keybindAdd('C-G', 'dbg_grid');
diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas
index 5197654726df8a94a0f2d905f5e9a4cffaa493d3..6160929b5f214697fc8170fba949589246f319a9 100644 (file)
--- a/src/game/g_panel.pas
+++ b/src/game/g_panel.pas
TPanelArray = Array of TPanel;
var
- g_dbgpan_mplat_active: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}true{$ENDIF};
+ g_dbgpan_mplat_active: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}true{$ENDIF};
g_dbgpan_mplat_step: Boolean = false; // one step, and stop
u0, u1: Single;
tex, tey: Integer;
pdx, pdy: Integer;
+ pan: TPanel;
begin
squash := false;
- dx := 0;
- dy := 0;
+ tex := px;
+ tey := py;
pdx := mMovingSpeed.X;
pdy := mMovingSpeed.Y;
// standing on the platform?
begin
if (ontop <> nil) then ontop^ := true;
// yes, move with it
- mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
- //e_LogWritefln('entity on the platform; tracing=(%s,%s); endpoint=(%s,%s); mustbe=(%s,%s)', [px, py, tex, tey, px+pdx, py+pdy]);
- // still in platform?
- squash := g_Collide(tex, tey, pw, ph, nx, ny, mpw, mph);
- dx := tex-px;
- dy := tey-py;
+ pan := mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
+ if (pan <> nil) then
+ begin
+ //e_LogWritefln('entity on the platform; tracing=(%s,%s); endpoint=(%s,%s); mustbe=(%s,%s)', [px, py, tex, tey, px+pdx, py+pdy]);
+ if (tex = px) and (tey = py) then squash := true;
+ end;
end
else
begin
if (pdx <> 0) or (pdy <> 0) then
begin
// has some path to go, trace the entity
- mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
+ pan := mapGrid.traceBox(tex, tey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
//e_LogWritefln(' tracebox: te=(%s,%s)', [tex, tey]);
- end
- else
- begin
- // no movement
- tex := px;
- tey := py;
+ if (pan <> nil) and (tex = px) and (tey = py) then squash := true;
end;
- // free to push along the whole path, or path was corrected
- // still in platform?
- squash := g_Collide(tex, tey, pw, ph, nx, ny, mpw, mph);
- dx := tex-px;
- dy := tey-py;
end
else
begin
squash := (u1 >= 0.0);
end;
end;
+ dx := tex-px;
+ dy := tey-py;
result := (dx <> 0) or (dy <> 0);
+ if result and (not squash) then
+ begin
+ squash := g_Collide(tex, tey, pw, ph, nx, ny, mpw, mph); // still in platform?
+ if not squash then squash := g_Map_CollidePanel(tex, tey, pw, ph, (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR));
+ end;
end;
function monCollect (mon: TMonster): Boolean;