summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4437053)
raw | patch | inline | side by side (parent: 4437053)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 18 Jan 2018 13:33:11 +0000 (15:33 +0200) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Thu, 18 Jan 2018 13:33:34 +0000 (15:33 +0200) |
src/game/g_grid.pas | patch | blob | history | |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_monsters.pas | patch | blob | history | |
src/game/g_weapons.pas | patch | blob | history |
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index 30ed8ee0ae9dc062de5a3897a238de1a2e1c6d48..a41349315a469391e90a1c268d56c01b81f9f294 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
const
GridTileSize = 32; // must be power of two!
+type
+ PGridCellCoord = ^TGridCellCoord;
+ TGridCellCoord = record
+ x, y: Integer;
+ end;
+
type
TBodyProxyId = Integer;
public
type PITP = ^ITP;
- type TGridQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop
+ //type TGridQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop
//type TGridRayQueryCB = function (obj: ITP; tag: Integer; x, y, prevx, prevy: Integer): Boolean is nested; // return `true` to stop
type TCellQueryCB = procedure (x, y: Integer) is nested; // top-left cell corner coords
// you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
// trace line along the grid, calling `cb` for all objects in passed cells, in no particular order
//WARNING: don't change tags in callbacks here!
- function forEachAlongLine (ax0, ay0, ax1, ay1: Integer; cb: TGridQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
+ //function forEachAlongLine (ax0, ay0, ax1, ay1: Integer; cb: TGridQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
+ function forEachAlongLine (ax0, ay0, ax1, ay1: Integer; tagmask: Integer=-1; log: Boolean=false): Integer;
// trace box with the given velocity; return object hit (if any)
// `cb` is used unconvetionally here: if it returns `false`, tracer will ignore the object
function traceBox (out ex, ey: Integer; const ax0, ay0, aw, ah: Integer; const dx, dy: Integer; tagmask: Integer=-1): ITP;
// debug
- procedure forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB);
- function forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP;
+ function forEachBodyCell (body: TBodyProxyId): Integer; // this puts `TGridCellCoord` into frame pool for each cell
+ function forEachInCell (x, y: Integer): Integer;
procedure dumpStats ();
public
end;
-procedure TBodyGridBase.forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB);
+function TBodyGridBase.forEachBodyCell (body: TBodyProxyId): Integer;
var
g, f, ccidx: Integer;
cc: PGridCell;
+ presobj: PGridCellCoord;
begin
- if (body < 0) or (body > High(mProxies)) or not assigned(cb) then exit;
+ result := 0;
+ if (body < 0) or (body > High(mProxies)) then exit;
for g := 0 to High(mGrid) do
begin
ccidx := mGrid[g];
for f := 0 to GridCellBucketSize-1 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);
+ if (cc.bodies[f] = body) then
+ begin
+ presobj := PGridCellCoord(framePool.alloc(sizeof(TGridCellCoord)));
+ presobj^.x := (g mod mWidth)*mTileSize+mMinX;
+ presobj^.y := (g div mWidth)*mTileSize+mMinY;
+ Inc(result);
+ //cb((g mod mWidth)*mTileSize+mMinX, (g div mWidth)*mTileSize+mMinY);
+ end;
end;
// next cell
ccidx := cc.next;
end;
-function TBodyGridBase.forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP;
+function TBodyGridBase.forEachInCell (x, y: Integer): Integer;
var
f, ccidx: Integer;
cc: PGridCell;
+ presobj: PITP;
begin
- result := Default(ITP);
- if not assigned(cb) then exit;
+ result := 0;
Dec(x, mMinX);
Dec(y, mMinY);
if (x < 0) or (y < 0) or (x >= mWidth*mTileSize) or (y > mHeight*mTileSize) then exit;
for f := 0 to GridCellBucketSize-1 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;
+ //if cb(mProxies[cc.bodies[f]].mObj, mProxies[cc.bodies[f]].mTag) then begin result := mProxies[cc.bodies[f]].mObj; exit; end;
+ presobj := PITP(framePool.alloc(sizeof(ITP)));
+ //presobj^ := mProxies[cc.bodies[f]].mObj;
+ Move(mProxies[cc.bodies[f]].mObj, presobj^, sizeof(ITP));
+ Inc(result);
end;
// next cell
ccidx := cc.next;
// ////////////////////////////////////////////////////////////////////////// //
-function TBodyGridBase.forEachAlongLine (ax0, ay0, ax1, ay1: Integer; cb: TGridQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
+function TBodyGridBase.forEachAlongLine (ax0, ay0, ax1, ay1: Integer; tagmask: Integer=-1; log: Boolean=false): Integer;
var
lw: TLineWalker;
ccidx: Integer;
x1, y1: Integer;
cx, cy: Integer;
//px0, py0, px1, py1: Integer;
+ presobj: PITP;
begin
log := false;
- result := Default(ITP);
+ result := 0;
tagmask := tagmask and TagFullMask;
- if (tagmask = 0) or not assigned(cb) then exit;
+ if (tagmask = 0) then exit;
gw := mWidth;
gh := mHeight;
if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
begin
px.mQueryMark := lq; // mark as processed
+ presobj := PITP(framePool.alloc(sizeof(ITP)));
+ Move(px.mObj, presobj^, sizeof(ITP));
+ Inc(result);
+ {
if cb(px.mObj, ptag) then
begin
result := px.mObj;
//mInQuery := false;
exit;
end;
+ }
end;
end;
// next cell
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index c4eba8b2ee4e718b58e16d8d78ab13c719ca11ee..f4fe415cbf97a6f499b01b65e342e0ae1b12136e 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
hlmContext.fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize);
end;
+ procedure hilightBodyCells (proxyId: Integer);
+ var
+ pmark: PoolMark;
+ hitcount: Integer;
+ pcellxy: PGridCellCoord;
+ begin
+ //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+ pmark := framePool.mark();
+ hitcount := monsGrid.forEachBodyCell(proxyId);
+ pcellxy := PGridCellCoord(framePool.getPtr(pmark));
+ while (hitcount > 0) do
+ begin
+ hilightCell(pcellxy^.x, pcellxy^.y);
+ Inc(pcellxy);
+ Dec(hitcount);
+ end;
+ framePool.release(pmark);
+ end;
+
procedure hilightCell1 (cx, cy: Integer);
begin
//e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
hlmContext.fillRect(pan.X, pan.Y, pan.Width, pan.Height);
end;
- function monsCollector (mon: TMonster; tag: Integer): Boolean;
+ procedure monsCollector (mon: TMonster);
var
ex, ey: Integer;
mx, my, mw, mh: Integer;
begin
- result := false;
mon.getMapBox(mx, my, mw, mh);
hlmContext.color := TGxRGBA.Create(255, 255, 0, 160);
hlmContext.rect(mx, my, mw, mh);
mon.getMapBox(mx, my, mw, mh);
//mx += mw div 2;
- monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+ //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+ hilightBodyCells(mon.proxyId);
if showMonsInfo then
begin
function highlightAllMonsterCells (mon: TMonster): Boolean;
begin
result := false; // don't stop
- monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+ //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+ hilightBodyCells(mon.proxyId);
end;
procedure drawSelectedPlatformCells ();
if not showGrid then exit;
pan := g_Map_PanelByGUID(platMarkedGUID);
if (pan = nil) then exit;
- mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
+ //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
+ hilightBodyCells(pan.proxyId);
hlmContext.color := TGxRGBA.Create(0, 200, 0, 200);
hlmContext.rect(pan.x, pan.y, pan.width, pan.height);
end;
mx, my, mw, mh: Integer;
//pan: TPanel;
//ex, ey: Integer;
+ pmark: PoolMark;
+ hitcount: Integer;
+ pmon: PMonster;
begin
if (gPlayer1 = nil) then exit;
if (showGrid) then drawTileGrid();
drawOutlines();
- if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
+ if (laserSet) then
+ begin
+ //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
+ pmark := framePool.mark();
+ hitcount := monsGrid.forEachAlongLine(laserX0, laserY0, laserX1, laserY1, -1, true);
+ pmon := PMonster(framePool.getPtr(pmark));
+ while (hitcount > 0) do
+ begin
+ monsCollector(pmon^);
+ Inc(pmon);
+ Dec(hitcount);
+ end;
+ framePool.release(pmark);
+ end;
if (monMarkedUID <> -1) then
begin
index e2f04a636d7408c7dfaca723cc15f02608451930..018a69359a90fa4598097ea48ad3fc4193454653 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
function g_Mons_getNewMPlatFrameId (): LongWord; inline;
+{
type
TMonsAlongLineCB = function (mon: TMonster; tag: Integer): Boolean is nested;
function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
+}
var
// ////////////////////////////////////////////////////////////////////////// //
+{
function g_Mons_AlongLine (x0, y0, x1, y1: Integer; cb: TMonsAlongLineCB; log: Boolean=false): TMonster;
begin
if not assigned(cb) then begin result := nil; exit; end;
result := monsGrid.forEachAlongLine(x0, y0, x1, y1, cb, -1, log);
end;
+}
//WARNING! call this after monster position was changed, or coldet will not work right!
diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index 97d127a46519fbf1a9c9589247cd468047e43b8b..725ab6d701a05634adb9baffe2e256e6b94d41ee 100644 (file)
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
interface
uses
- SysUtils, Classes,
+ SysUtils, Classes, mempool,
g_textures, g_basic, e_graphics, g_phys, xprofiler;
end;
end;
- function sqchecker (mon: TMonster; tag: Integer): Boolean;
+ procedure sqchecker (mon: TMonster);
var
mx, my, mw, mh: Integer;
inx, iny: Integer;
distSq: Integer;
begin
- result := false; // don't stop
mon.getMapBox(mx, my, mw, mh);
if lineAABBIntersects(x0, y0, x2, y2, mx, my, mw, mh, inx, iny) then
begin
{$IF DEFINED(D2F_DEBUG)}
stt: UInt64;
{$ENDIF}
+ pmark: PoolMark;
+ hitcount: Integer;
+ pmon: PMonster;
begin
(*
if not gwep_debug_fast_trace then
if playerPossibleHit() then exit; // instant hit
// collect monsters
- g_Mons_AlongLine(x, y, x2, y2, sqchecker);
+ //g_Mons_AlongLine(x, y, x2, y2, sqchecker);
+
+ pmark := framePool.mark();
+ hitcount := monsGrid.forEachAlongLine(x, y, x2, y2, -1);
+ pmon := PMonster(framePool.getPtr(pmark));
+ while (hitcount > 0) do
+ begin
+ sqchecker(pmon^);
+ Inc(pmon);
+ Dec(hitcount);
+ end;
+ framePool.release(pmark);
// here, we collected all monsters and players in `wgunHitHeap` and `wgunHitTime`
// also, if `wallWasHit` is `true`, then `wallHitX` and `wallHitY` contains spark coords