From: Ketmar Dark Date: Wed, 23 Aug 2017 14:44:19 +0000 (+0300) Subject: more debug code in grid and holmes X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=71d6aff3ac19f4c810c1be46816f395447b76d87;p=d2df-sdl.git more debug code in grid and holmes --- diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas index c6fe095..27b553a 100644 --- a/src/game/g_grid.pas +++ b/src/game/g_grid.pas @@ -29,6 +29,8 @@ type type TGridRayQueryCB = function (obj: ITP; tag: Integer; x, y, prevx, prevy: Integer): Boolean is nested; // return `true` to stop type TGridAlongQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop + type TCellQueryCB = procedure (x, y: Integer) is nested; // top-left cell corner coords + const TagDisabled = $40000000; const TagFullMask = $3fffffff; @@ -142,6 +144,9 @@ type // trace line along the grid, calling `cb` for all objects in passed cells, in no particular order function forEachAlongLine (x0, y0, x1, y1: Integer; cb: TGridAlongQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP; + // debug + procedure forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB); + function forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP; procedure dumpStats (); //WARNING! no sanity checks! @@ -428,6 +433,57 @@ begin end; +procedure TBodyGridBase.forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB); +var + g, f, cidx: Integer; + cc: PGridCell; + //px: PBodyProxyRec; +begin + if (body < 0) or (body > High(mProxies)) or not assigned(cb) then exit; + for g := 0 to High(mGrid) do + begin + cidx := mGrid[g]; + while (cidx <> -1) do + begin + cc := @mCells[cidx]; + for f := 0 to High(TGridCell.bodies) do + begin + if (cc.bodies[f] = -1) then break; + if (cc.bodies[f] = body) then cb((g mod mWidth)*mTileSize+mMinX, (g div mWidth)*mTileSize+mMinY); + //px := @mProxies[cc.bodies[f]]; + end; + // next cell + cidx := cc.next; + end; + end; +end; + + +function TBodyGridBase.forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP; +var + f, cidx: Integer; + cc: PGridCell; +begin + result := Default(ITP); + if not assigned(cb) then exit; + Dec(x, mMinX); + Dec(y, mMinY); + if (x < 0) or (y < 0) or (x >= mWidth*mTileSize) or (y > mHeight*mTileSize) then exit; + cidx := mGrid[(y div mTileSize)*mWidth+(x div mTileSize)]; + while (cidx <> -1) do + begin + cc := @mCells[cidx]; + for f := 0 to High(TGridCell.bodies) do + begin + if (cc.bodies[f] = -1) then break; + if cb(mProxies[cc.bodies[f]].mObj, mProxies[cc.bodies[f]].mTag) then begin result := mProxies[cc.bodies[f]].mObj; exit; end; + end; + // next cell + cidx := cc.next; + end; +end; + + // ////////////////////////////////////////////////////////////////////////// // function TBodyGridBase.getGridWidthPx (): Integer; inline; begin result := mWidth*mTileSize; end; function TBodyGridBase.getGridHeightPx (): Integer; inline; begin result := mHeight*mTileSize; end; diff --git a/src/game/g_holmes.inc b/src/game/g_holmes.inc index e3dd380..d1265d0 100644 --- a/src/game/g_holmes.inc +++ b/src/game/g_holmes.inc @@ -501,7 +501,9 @@ begin glDisable(GL_TEXTURE_2D); glColor4f(r/255.0, g/255.0, b/255.0, a/255.0); + glLineWidth(1); + glPointSize(1); glBegin(GL_LINES); glVertex2i(x1, y1); @@ -513,6 +515,19 @@ begin end; +procedure drawRect (x, y, w, h: Integer; r, g, b: Integer; a: Integer=255); +begin + if (w < 0) or (h < 0) then exit; + if (w = 1) and (h = 1) then begin drawLine(x, y, x, y, r, g, b, a); exit; end; + Inc(w); + Inc(h); + drawLine(x, y, x+w-1, y, r, g, b, a); + drawLine(x+w-1, y+1, x+w-1, y+h-2, r, g, b, a); + drawLine(x+w-2, y+h-1, x, y+h-1, r, g, b, a); + drawLine(x, y+h-2, x, y+1, r, g, b, a); +end; + + // ////////////////////////////////////////////////////////////////////////// // procedure shadeRect (x, y, w, h: Integer; a: Integer); begin diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 75e03bb..d03d7b4 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -167,6 +167,12 @@ procedure plrDebugMouse (var ev: THMouseEvent); //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx); end; + function monsInCell (mon: TMonster; tag: Integer): Boolean; + begin + result := false; // don't stop + e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), MSG_NOTIFY); + end; + begin //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY); if (gPlayer1 = nil) then exit; @@ -174,7 +180,18 @@ begin if (ev.but = THMouseEvent.Left) then begin - mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor)); + if ((kbS and THKeyEvent.ModShift) <> 0) then + begin + // dump monsters in cell + e_WriteLog('===========================', MSG_NOTIFY); + monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell); + e_WriteLog('---------------------------', MSG_NOTIFY); + end + else + begin + // toggle wall + mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor)); + end; exit; end; @@ -191,6 +208,33 @@ end; procedure plrDebugDraw (); + procedure drawTileGrid (); + var + x, y: Integer; + begin + y := mapGrid.gridY0; + while (y < mapGrid.gridY0+mapGrid.gridHeight) do + begin + x := mapGrid.gridX0; + while (x < mapGrid.gridX0+mapGrid.gridWidth) do + begin + if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and + (x < vpx+vpw) and (y < vpy+vph) then + begin + //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96); + drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255); + end; + Inc(x, mapGrid.tileSize); + end; + Inc(y, mapGrid.tileSize); + end; + end; + + procedure hilightCell (cx, cy: Integer); + begin + fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64); + end; + function monsCollector (mon: TMonster; tag: Integer): Boolean; var ex, ey: Integer; @@ -216,26 +260,32 @@ procedure plrDebugDraw (); mon.getMapBox(mx, my, mw, mh); //mx += mw div 2; - //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250); - shadeRect(mx-4, my-7*8-6, 110, 7*8+6, 128); - my -= 8; - my -= 2; - - // type - drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8; - // beh - drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8; - // state - drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8; - // health - drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8; - // ammo - drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8; - // target - drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8; - drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8; + monsGrid.forEachBodyCell(mon.proxyId, hilightCell); + + if ((kbS and THKeyEvent.ModCtrl) <> 0) then + begin + //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250); + shadeRect(mx-4, my-7*8-6, 110, 7*8+6, 128); + my -= 8; + my -= 2; + + // type + drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8; + // beh + drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8; + // state + drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8; + // health + drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8; + // ammo + drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8; + // target + drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8; + drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8; + + mon.getMapBox(mx, my, mw, mh); + end; - mon.getMapBox(mx, my, mw, mh); if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then begin eplr := g_Player_Get(mon.MonsterTargetUID); @@ -274,6 +324,8 @@ begin glPushMatrix(); glTranslatef(-vpx, -vpy, 0); + drawTileGrid(); + g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true); if (monMarkedUID <> -1) then @@ -293,30 +345,6 @@ begin end; -{ - procedure drawTileGrid (); - var - x, y: Integer; - begin - y := mapGrid.gridY0; - while (y < mapGrid.gridY0+mapGrid.gridHeight) do - begin - x := mapGrid.gridX0; - while (x < mapGrid.gridX0+mapGrid.gridWidth) do - begin - if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and - (x < vpx+vpw) and (y < vpy+vph) then - begin - e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96); - end; - Inc(x, mapGrid.tileSize); - end; - Inc(y, mapGrid.tileSize); - end; - end; -} - - // ////////////////////////////////////////////////////////////////////////// // function g_Holmes_mouseEvent (var ev: THMouseEvent): Boolean; begin diff --git a/src/game/g_player.pas b/src/game/g_player.pas index e72a756..92aec40 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -2319,6 +2319,7 @@ end; procedure TPlayer.DrawAim(); procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer); + { procedure drawTileGrid (); var x, y: Integer; @@ -2339,6 +2340,7 @@ procedure TPlayer.DrawAim(); Inc(y, mapGrid.tileSize); end; end; + } var ex, ey: Integer; @@ -2359,7 +2361,7 @@ procedure TPlayer.DrawAim(); e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96); end; - drawTileGrid(); + //drawTileGrid(); end; var