GridCellBucketSize = 8; // WARNING! can't be less than 2!
type
- GridQueryCB = function (obj: TObject; var proxy: PBodyProxyRec; tag: Integer): Boolean is nested; // return `true` to stop
+ TGridQueryCB = function (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean is nested; // return `true` to stop
type
TBodyGrid = class;
procedure resizeBody (body: TBodyProxy; sx, sy: Integer);
procedure moveResizeBody (body: TBodyProxy; dx, dy, sx, sy: Integer);
- function forEachInAABB (x, y, w, h: Integer; cb: GridQueryCB; tagmask: Integer=-1): Boolean;
+ function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
//function getProxyForBody (aObj: TObject; x, y, w, h: Integer): TBodyProxy;
end;
-function TBodyGrid.forEachInAABB (x, y, w, h: Integer; cb: GridQueryCB; tagmask: Integer=-1): Boolean;
+function TBodyGrid.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
function iterator (grida: Integer): Boolean;
var
idx: Integer;
begin
//e_WriteLog(Format(' query #%d body hit: (%d,%d)-(%dx%d) tag:%d', [mLastQuery, mCells[idx].body.mX, mCells[idx].body.mY, mCells[idx].body.mWidth, mCells[idx].body.mHeight, mCells[idx].body.mTag]), MSG_NOTIFY);
px.mQueryMark := mLastQuery;
- if (cb(px.mObj, px.mTag)) then begin result := true; exit; end;
+ if (cb(px.mObj, px.mX, px.mY, px.mWidth, px.mHeight, px.mTag)) then begin result := true; exit; end;
end;
end;
idx := pi.next;
begin
//e_WriteLog(Format(' query #%d body hit: (%d,%d)-(%dx%d) tag:%d', [mLastQuery, mCells[idx].body.mX, mCells[idx].body.mY, mCells[idx].body.mWidth, mCells[idx].body.mHeight, mCells[idx].body.mTag]), MSG_NOTIFY);
px.mQueryMark := mLastQuery;
- if (cb(px.mObj, px.mTag)) then begin result := true; exit; end;
+ if (cb(px.mObj, px.mX, px.mY, px.mWidth, px.mHeight, px.mTag)) then begin result := true; exit; end;
end;
end;
idx := mCells[idx].next;
// new algo
procedure g_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer);
- function checker (obj: TObject; ; var proxy: PBodyProxyRectag: Integer): Boolean;
+ function checker (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean;
var
pan: TPanel;
begin
procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
- function checker (obj: TObject; ; var proxy: PBodyProxyRectag: Integer): Boolean;
+ function checker (obj: TObject; objx, objy, objw, objh: Integer; tag: Integer): Boolean;
var
pan: TPanel;
begin
function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean;
- function checker (obj: TObject; ; var proxy: PBodyProxyRectag: Integer): Boolean;
+ function checker (obj: TObject; objx, objy, objwidth, objheight: Integer; tag: Integer): Boolean;
var
pan: TPanel;
begin
(WordBool(PanelType and (PANEL_LIFTDOWN)) and (pan.LiftType = 1)) or
(WordBool(PanelType and (PANEL_LIFTLEFT)) and (pan.LiftType = 2)) or
(WordBool(PanelType and (PANEL_LIFTRIGHT)) and (pan.LiftType = 3))) and
- g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then
+ g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then
begin
result := true;
exit;
end;
end;
- if ((pan.tag and GridTagBlockMon) <> 0) then
+ if ((tag and GridTagBlockMon) <> 0) then
begin
- if ((not b1x3) or (pan.Width+pan.Height >= 64)) and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then
+ if ((not b1x3) or (objwidth+objheight >= 64)) and g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then
begin
result := True;
exit;
end;
// other shit
- result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
+ result := g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight);
end;
var
texid: DWORD;
// slightly different from the old code, but meh...
- function checker (obj: TObject; tag: Integer): Boolean;
- var
- pan: TPanel;
+ function checker (obj: TObject; objx, objy, objwidth, objheight: Integer; tag: Integer): Boolean;
+ //var pan: TPanel;
begin
result := false; // don't stop, ever
if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
- //pan := (obj as TPanel);
- pan := TPanel(obj);
// check priorities
case cctype of
0: if ((tag and GridTagWater) = 0) then exit; // only water
//2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // water, acid1, acid2
end;
// collision?
- if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
+ if not g_Collide(X, Y, Width, Height, objx, objy, objwidth, objheight) then exit;
// yeah
- texid := pan.GetTextureID();
+ //pan := (obj as TPanel);
+ texid := TPanel(obj).GetTextureID();
// water? water has the highest priority, so stop right here
if ((tag and GridTagWater) <> 0) then begin cctype := 0; result := true; exit; end;
// acid2
interface
-uses e_log;
+uses
+ e_log, g_grid;
// ////////////////////////////////////////////////////////////////////////// //
public
// called when a overlapping node has been found during the call to forEachAABBOverlap()
// return `true` to stop
- type TQueryOverlapCB = function (abody: TTreeFlesh; atag: Integer): Boolean is nested;
+ type TQueryOverlapCB = function (abody: TTreeFlesh; objx, objy, objw, objh: Integer; atag: Integer): Boolean is nested;
type TSegQueryCallback = function (abody: TTreeFlesh; ax, ay, bx, by: Single): Single is nested; // return dist from (ax,ay) to abody
TSegmentQueryResult = record
{$IFDEF aabbtree_query_count}Inc(mNodesDeepVisited);{$ENDIF}
if ((node.tag and tagmask) <> 0) then
begin
- if (visitor(node.flesh, node.tag)) then begin result := nodeId; bigstack := nil; exit; end;
+ if (visitor(node.flesh, node.aabb.minX, node.aabb.minY, node.aabb.maxX, node.aabb.maxY, node.tag)) then begin result := nodeId; bigstack := nil; exit; end;
end;
end
else
begin
result := node.aabb.contains(ax, ay);
end;
- function dummycb (abody: TTreeFlesh; atag: Integer): Boolean; begin result := false; end;
+ function dummycb (abody: TTreeFlesh; objx, objy, objw, objh: Integer; atag: Integer): Boolean; begin result := false; end;
var
nid: Integer;
caabb: AABB2D;
result := node.aabb.intersects(curax, curay, curbx, curby);
end;
- function visitor (flesh: TTreeFlesh; tag: Integer): Boolean;
+ function visitor (flesh: TTreeFlesh; objx, objy, objw, objh: Integer; tag: Integer): Boolean;
var
hitFraction: Single;
begin