summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c4a040)
raw | patch | inline | side by side (parent: 4c4a040)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 22 Aug 2017 15:03:00 +0000 (18:03 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 18:23:55 +0000 (21:23 +0300) |
diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas
index e3655bbac9678b575f1653b5d0ac535e26f8b6d0..2300b1380fcb892f99c50ba8100f9295daabfc9d 100644 (file)
--- a/src/game/g_basic.pas
+++ b/src/game/g_basic.pas
implementation
uses
- Math, g_map, g_gfx, g_player, SysUtils, MAPDEF,
- StrUtils, e_graphics, g_monsters, g_items;
+ Math, e_log, g_map, g_gfx, g_player, SysUtils, MAPDEF,
+ StrUtils, e_graphics, g_monsters, g_items, g_game;
function g_PatchLength(X1, Y1, X2, Y2: Integer): Word;
begin
Result := True;
*)
- result := false;
- if g_Map_traceToNearestWall(x1, y1, x2, y2, @wallHitX, @wallHitY) then
- begin
- // check distance
- //result := ((wallHitX-x1)*(wallHitX-x1)+(wallHitY-y1)*(wallHitY-y1) > (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
- result := false;
- end
- else
- begin
- result := true; // no obstacles
- end;
+ // `true` if no obstacles
+ if (g_profile_los) then g_Mons_LOS_Start();
+ result := not g_Map_traceToNearestWall(x1, y1, x2, y2, @wallHitX, @wallHitY);
+ if (g_profile_los) then g_Mons_LOS_End();
end;
diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index 7d563ae8868f4480cfbeb0afc6b561412c942854..a5652ce5c799f874c538018dc40d32746cf3c1f6 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
AddCommand('pf_draw_frame', ProfilerCommands, 'draw frame rendering profiles');
//AddCommand('pf_update_frame', ProfilerCommands);
AddCommand('pf_coldet', ProfilerCommands, 'draw collision detection profiles');
+ AddCommand('pf_los', ProfilerCommands, 'draw monster LOS profiles');
AddCommand('r_sq_draw', ProfilerCommands, 'accelerated spatial queries in rendering');
AddCommand('cd_sq_enabled', ProfilerCommands, 'accelerated spatial queries in map coldet');
AddCommand('mon_sq_enabled', ProfilerCommands, 'use accelerated spatial queries for monsters');
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 6cd9970a59315a03cf65315942ce166ce1c6eb63..c6ea4963f5a52f1bb5c080c11f5322dbeab820bc 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
g_profile_frame_update: Boolean = false;
g_profile_frame_draw: Boolean = false;
g_profile_collision: Boolean = false;
+ g_profile_los: Boolean = false;
g_profile_history_size: Integer = 1000;
procedure g_ResetDynlights ();
procedure drawProfilers ();
var
px: Integer = -1;
+ py: Integer = -1;
begin
- if g_profile_frame_draw then px := px-drawProfiles(px, -1, profileFrameDraw);
- if g_profile_collision then px := px-drawProfiles(px, -1, profMapCollision);
+ if g_profile_frame_draw then px := px-drawProfiles(px, py, profileFrameDraw);
+ if g_profile_collision then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
+ if g_profile_los then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
end;
procedure g_Game_Draw();
if (cmd = 'pf_draw_frame') then begin binaryFlag(g_profile_frame_draw, 'render profiles'); exit; end;
if (cmd = 'pf_update_frame') then begin binaryFlag(g_profile_frame_update, 'update profiles (not yet)'); exit; end;
if (cmd = 'pf_coldet') then begin binaryFlag(g_profile_collision, 'coldet profiles'); exit; end;
+ if (cmd = 'pf_los') then begin binaryFlag(g_profile_los, 'monster LOS profiles'); exit; end;
if (cmd = 'r_sq_draw') then begin binaryFlag(gdbg_map_use_accel_render, 'accelerated rendering'); exit; end;
if (cmd = 'cd_sq_enabled') then begin binaryFlag(gdbg_map_use_accel_coldet, 'accelerated map coldet'); exit; end;
if (cmd = 'mon_sq_enabled') then begin binaryFlag(gmon_debug_use_sqaccel, 'accelerated monster coldet'); exit; end;
begin
Parse_Params(pars);
- s := Find_Param_Value(pars, '--profile-render');
- if (s <> '') then g_profile_frame_draw := true;
-
- s := Find_Param_Value(pars, '--profile-coldet');
- if (s <> '') then g_profile_collision := true;
-
// Debug mode:
s := Find_Param_Value(pars, '--debug');
if (s <> '') then
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index 13c57c98500101653d346c82599259cb5fa1d120..70703afd363162b5438af2d84a0a432cacb8db6c 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
type TGridRayQueryCB = function (obj: ITP; tag: Integer; x, y, prevx, prevy: Integer): Boolean is nested; // return `true` to stop
const TagDisabled = $40000000;
+ const TagFullMask = $3fffffff;
private
const
mX, mY, mWidth, mHeight: Integer; // aabb
mQueryMark: LongWord; // was this object visited at this query?
mObj: ITP;
- mTag: Integer;
+ mTag: Integer; // `TagDisabled` set: disabled ;-)
nextLink: TBodyProxyId; // next free or nothing
private
next: Integer; // in this cell; index in mCells
end;
- TGridInternalCB = function (grida: Integer): Boolean of object; // return `true` to stop
+ TGridInternalCB = function (grida: Integer; bodyId: TBodyProxyId): Boolean of object; // return `true` to stop
private
mTileSize: Integer;
mProxyCount: Integer; // currently used
mProxyMaxCount: Integer;
- mUData: TBodyProxyId; // for inserter/remover
- mTagMask: Integer; // for iterator
- mItCB: TGridQueryCB; // for iterator
-
private
function allocCell: Integer;
procedure freeCell (idx: Integer); // `next` is simply overwritten
function allocProxy (aX, aY, aWidth, aHeight: Integer; aObj: ITP; aTag: Integer): TBodyProxyId;
procedure freeProxy (body: TBodyProxyId);
- procedure insert (body: TBodyProxyId);
- procedure remove (body: TBodyProxyId);
+ procedure insertInternal (body: TBodyProxyId);
+ procedure removeInternal (body: TBodyProxyId);
- function forGridRect (x, y, w, h: Integer; cb: TGridInternalCB): Boolean;
+ function forGridRect (x, y, w, h: Integer; cb: TGridInternalCB; bodyId: TBodyProxyId): Boolean;
- function inserter (grida: Integer): Boolean;
- function remover (grida: Integer): Boolean;
+ function inserter (grida: Integer; bodyId: TBodyProxyId): Boolean;
+ function remover (grida: Integer; bodyId: TBodyProxyId): Boolean;
function getProxyEnabled (pid: TBodyProxyId): Boolean; inline;
procedure setProxyEnabled (pid: TBodyProxyId; val: Boolean); inline;
constructor Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
destructor Destroy (); override;
- function insertBody (aObj: ITP; ax, ay, aWidth, aHeight: Integer; aTag: Integer=0): TBodyProxyId;
+ function insertBody (aObj: ITP; ax, ay, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
procedure removeBody (aObj: TBodyProxyId); // WARNING! this WILL destroy proxy!
procedure moveBody (body: TBodyProxyId; dx, dy: Integer);
function insideGrid (x, y: Integer): Boolean; inline;
- //WARNING: can't do recursive queries
+ //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)
// no callback: return `true` on the first hit
- function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
+ function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
- //WARNING: can't do recursive queries
+ //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)
// no callback: return `true` on the first hit
- function forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
+ function forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): ITP;
- //WARNING: can't do recursive queries
+ //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)
// cb with `(nil)` will be called before processing new tile
// no callback: return `true` on the nearest hit
- function traceRay (x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): Boolean; overload;
- function traceRay (out ex, ey: Integer; x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): Boolean;
+ function traceRay (x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP; overload;
+ function traceRay (out ex, ey: Integer; x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
procedure dumpStats ();
mProxyFree := 0;
mProxyCount := 0;
mProxyMaxCount := 0;
- mUData := 0;
- mTagMask := -1;
- mItCB := nil;
e_WriteLog(Format('created grid with size: %dx%d (tile size: %d); pix: %dx%d', [mWidth, mHeight, mTileSize, mWidth*mTileSize, mHeight*mTileSize]), MSG_NOTIFY);
end;
end
else
begin
- mProxies[pid].mTag := mProxies[pid].mTag or TagDisabled
+ mProxies[pid].mTag := mProxies[pid].mTag or TagDisabled;
end;
end;
end;
end;
-function TBodyGridBase.forGridRect (x, y, w, h: Integer; cb: TGridInternalCB): Boolean;
+function TBodyGridBase.forGridRect (x, y, w, h: Integer; cb: TGridInternalCB; bodyId: TBodyProxyId): Boolean;
var
gx, gy: Integer;
gw, gh, tsize: Integer;
begin
if (gx < 0) then continue;
if (gx >= gw) then break;
- result := cb(gy*gw+gx);
+ result := cb(gy*gw+gx, bodyId);
if result then exit;
end;
end;
end;
-function TBodyGridBase.inserter (grida: Integer): Boolean;
+function TBodyGridBase.inserter (grida: Integer; bodyId: TBodyProxyId): Boolean;
var
cidx: Integer;
pc: Integer;
if (pi.bodies[f] = -1) then
begin
// can add here
- pi.bodies[f] := mUData;
+ pi.bodies[f] := bodyId;
if (f+1 < Length(TGridCell.bodies)) then pi.bodies[f+1] := -1;
exit;
end;
end;
// either no room, or no cell at all
cidx := allocCell();
- mCells[cidx].bodies[0] := mUData;
+ mCells[cidx].bodies[0] := bodyId;
mCells[cidx].bodies[1] := -1;
mCells[cidx].next := pc;
mGrid[grida] := cidx;
end;
-
-procedure TBodyGridBase.insert (body: TBodyProxyId);
+procedure TBodyGridBase.insertInternal (body: TBodyProxyId);
var
px: PBodyProxyRec;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
px := @mProxies[body];
- mUData := body;
- forGridRect(px.mX, px.mY, px.mWidth, px.mHeight, inserter);
+ forGridRect(px.mX, px.mY, px.mWidth, px.mHeight, inserter, body);
end;
-function TBodyGridBase.remover (grida: Integer): Boolean;
+// absolutely not tested
+function TBodyGridBase.remover (grida: Integer; bodyId: TBodyProxyId): Boolean;
var
f: Integer;
pidx, idx, tmp: Integer;
f := 0;
while (f < High(TGridCell.bodies)) do
begin
- if (pc.bodies[f] = mUData) then
+ if (pc.bodies[f] = bodyId) then
begin
// i found her!
if (f = 0) and (pc.bodies[1] = -1) then
end;
end;
-
// absolutely not tested
-procedure TBodyGridBase.remove (body: TBodyProxyId);
+procedure TBodyGridBase.removeInternal (body: TBodyProxyId);
var
px: PBodyProxyRec;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
px := @mProxies[body];
- mUData := body;
- forGridRect(px.mX, px.mY, px.mWidth, px.mHeight, remover);
+ forGridRect(px.mX, px.mY, px.mWidth, px.mHeight, remover, body);
end;
-function TBodyGridBase.insertBody (aObj: ITP; aX, aY, aWidth, aHeight: Integer; aTag: Integer=0): TBodyProxyId;
+function TBodyGridBase.insertBody (aObj: ITP; aX, aY, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
begin
+ aTag := aTag and TagFullMask;
result := allocProxy(aX, aY, aWidth, aHeight, aObj, aTag);
- insert(result);
+ insertInternal(result);
end;
procedure TBodyGridBase.removeBody (aObj: TBodyProxyId);
begin
if (aObj < 0) or (aObj > High(mProxies)) then exit; // just in case
- remove(aObj);
+ removeInternal(aObj);
freeProxy(aObj);
end;
begin
if (body < 0) or (body > High(mProxies)) then exit; // just in case
if ((dx = 0) and (dy = 0) and (sx = 0) and (sy = 0)) then exit;
- remove(body);
+ removeInternal(body);
px := @mProxies[body];
Inc(px.mX, dx);
Inc(px.mY, dy);
Inc(px.mWidth, sx);
Inc(px.mHeight, sy);
- insert(body);
+ insertInternal(body);
end;
procedure TBodyGridBase.moveBody (body: TBodyProxyId; dx, dy: Integer);
// ////////////////////////////////////////////////////////////////////////// //
// no callback: return `true` on the first hit
-function TBodyGridBase.forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
+function TBodyGridBase.forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): ITP;
var
f: Integer;
idx, curci: Integer;
lq: LongWord;
ptag: Integer;
begin
- result := false;
+ result := Default(ITP);
+ tagmask := tagmask and TagFullMask;
if (tagmask = 0) then exit;
// make coords (0,0)-based
begin
if (cc.bodies[f] = -1) then break;
px := @mProxies[cc.bodies[f]];
- if (px.mQueryMark <> lq) then
+ ptag := px.mTag;
+ if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
begin
- ptag := px.mTag;
- if ((ptag and TagDisabled) = 0) and ((px.mTag and tagmask) <> 0) then
+ if (x >= px.mX) and (y >= px.mY) and (x < px.mX+px.mWidth) and (y < px.mY+px.mHeight) then
begin
- if (x >= px.mX) and (y >= px.mY) and (x < px.mX+px.mWidth) and (y < px.mY+px.mHeight) then
+ px.mQueryMark := lq;
+ if assigned(cb) then
begin
- px.mQueryMark := lq;
- if assigned(cb) then result := cb(px.mObj, px.mTag) else result := true;
- if result then exit;
+ if cb(px.mObj, ptag) then begin result := px.mObj; exit; end;
+ end
+ else
+ begin
+ result := px.mObj;
+ exit;
end;
end;
end;
// no callback: return `true` on the first hit
-function TBodyGridBase.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1): Boolean;
+function TBodyGridBase.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
var
idx: Integer;
gx, gy: Integer;
x0, y0: Integer;
ptag: Integer;
begin
- result := false;
+ result := Default(ITP);
if (w < 1) or (h < 1) then exit;
+ tagmask := tagmask and TagFullMask;
+ if (tagmask = 0) then exit;
x0 := x;
y0 := y;
begin
if (cc.bodies[f] = -1) then break;
px := @mProxies[cc.bodies[f]];
- if (px.mQueryMark <> lq) then
+ ptag := px.mTag;
+ if (not allowDisabled) and ((ptag and TagDisabled) <> 0) then continue;
+ if ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
+ //if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
+ //if ( ((ptag and TagDisabled) = 0) = ignoreDisabled) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
begin
- ptag := px.mTag;
- if ((ptag and TagDisabled) = 0) and ((px.mTag and tagmask) <> 0) then
+ if (x0 >= px.mX+px.mWidth) or (y0 >= px.mY+px.mHeight) then continue;
+ if (x0+w <= px.mX) or (y0+h <= px.mY) then continue;
+ px.mQueryMark := lq;
+ if assigned(cb) then
begin
- if (x0 >= px.mX+px.mWidth) or (y0 >= px.mY+px.mHeight) then continue;
- if (x0+w <= px.mX) or (y0+h <= px.mY) then continue;
- px.mQueryMark := lq;
- if assigned(cb) then result := cb(px.mObj, px.mTag) else result := true;
- if result then exit;
+ if cb(px.mObj, ptag) then begin result := px.mObj; exit; end;
+ end
+ else
+ begin
+ result := px.mObj;
+ exit;
end;
end;
end;
// ////////////////////////////////////////////////////////////////////////// //
// no callback: return `true` on the nearest hit
-function TBodyGridBase.traceRay (x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): Boolean;
+function TBodyGridBase.traceRay (x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
var
ex, ey: Integer;
begin
// no callback: return `true` on the nearest hit
-function TBodyGridBase.traceRay (out ex, ey: Integer; x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): Boolean;
+function TBodyGridBase.traceRay (out ex, ey: Integer; x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
var
i: Integer;
dx, dy: Integer;
ptag: Integer;
lastDistSq, distSq: Integer;
wasHit: Boolean = false;
+ lastObj: ITP;
+ lastWasInGrid: Boolean = false;
begin
- result := false;
-
+ result := Default(ITP);
+ lastObj := Default(ITP);
+ tagmask := tagmask and TagFullMask;
if (tagmask = 0) then begin ex := x0; ey := y0; exit; end;
// make coords (0,0)-based
minx := mMinX;
miny := mMinY;
- Dec(x0, minx);
- Dec(y0, miny);
- Dec(x1, minx);
- Dec(y1, miny);
+ //Dec(x0, minx);
+ //Dec(y0, miny);
+ //Dec(x1, minx);
+ //Dec(y1, miny);
dx := x1-x0;
dy := y1-y0;
if (dx > dy) then d := dx else d := dy;
- x := x0;
- y := y0;
+ // `x` and `y` will be in grid coords
+ x := x0-minx;
+ y := y0-miny;
// increase query counter
Inc(mLastQuery);
maxx := gw*tsize-1;
maxy := gh*tsize-1;
lastDistSq := (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+1;
+ lastWasInGrid := (x >= 0) and (y >= 0) and (x <= maxx) and (y <= maxy);
for i := 1 to d do
begin
+ // prevs are always in map coords
prevX := x+minx;
prevY := y+miny;
- Inc(xerr, dx); if (xerr >= d) then begin Dec(xerr, d); Inc(x, incx); end;
- Inc(yerr, dy); if (yerr >= d) then begin Dec(yerr, d); Inc(y, incy); end;
+ // do one step
+ xerr += dx; if (xerr >= d) then begin xerr -= d; x += incx; end;
+ yerr += dy; if (yerr >= d) then begin yerr -= d; y += incy; end;
+ // check for new tile
if (x >= 0) and (y >= 0) and (x <= maxx) and (y <= maxy) then
begin
ga := (y div tsize)*gw+(x div tsize);
if (lastGA <> ga) then
begin
// new cell
+ lastWasInGrid := true; // do it here, yeah
lastGA := ga;
+ // had something in the cell we're leaving?
+ if (ccidx <> -1) then
+ begin
+ // yes, signal cell completion
+ if assigned(cb) then
+ begin
+ if cb(nil, 0, x+minx, y+miny, prevX, prevY) then begin result := lastObj; exit; end;
+ end
+ else if wasHit then
+ begin
+ result := lastObj;
+ exit;
+ end;
+ end;
+ // have something in this cell?
ccidx := mGrid[lastGA];
end;
end
else
begin
+ // out of grid, had something in the cell we're last processed?
if (ccidx <> -1) then
begin
+ // yes, signal cell completion
ccidx := -1;
- if assigned(cb) then result := cb(nil, 0, x+minx, y+miny, prevX, prevY) else result := wasHit;
- if result then exit;
+ if assigned(cb) then
+ begin
+ if cb(nil, 0, x+minx, y+miny, prevX, prevY) then begin result := lastObj; exit; end;
+ end
+ else if wasHit then
+ begin
+ result := lastObj;
+ exit;
+ end;
end;
+ if lastWasInGrid then exit; // oops, stepped out of the grid -- there is no way to return
+ //lastWasInGrid := false;
end;
+ // has something to process in the current cell?
if (ccidx <> -1) then
begin
+ // process cell
curci := ccidx;
- hasUntried := false;
+ hasUntried := false; // this will be set to `true` if we have some panels we still want to process at the next step
+ // convert coords to map
Inc(x, minx);
Inc(y, miny);
while (curci <> -1) do
begin
if (cc.bodies[f] = -1) then break;
px := @mProxies[cc.bodies[f]];
- if (px.mQueryMark <> lq) then
+ ptag := px.mTag;
+ if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
begin
- ptag := px.mTag;
- if ((ptag and TagDisabled) = 0) and ((px.mTag and tagmask) <> 0) then
+ // can we process this wall?
+ if (x >= px.mX) and (y >= px.mY) and (x < px.mX+px.mWidth) and (y < px.mY+px.mHeight) then
begin
- if (x >= px.mX) and (y >= px.mY) and (x < px.mX+px.mWidth) and (y < px.mY+px.mHeight) then
+ px.mQueryMark := lq; // mark as processed
+ if assigned(cb) then
begin
- px.mQueryMark := lq;
- if assigned(cb) then
- begin
- result := cb(px.mObj, px.mTag, x, y, prevX, prevY);
- if result then begin ex := prevX; ey := prevY; exit; end;
- end
- else
+ if cb(px.mObj, ptag, x, y, prevX, prevY) then
begin
- distSq := (prevX-x)*(prevX-x)+(prevY-y)*(prevY-y);
- if (distSq < lastDistSq) then
- begin
- wasHit := true;
- lastDistSq := distSq;
- ex := prevx;
- ey := prevy;
- end;
+ result := lastObj;
+ ex := prevX;
+ ey := prevY;
+ exit;
end;
end
else
begin
- hasUntried := true;
+ // remember this hitpoint if it is nearer than an old one
+ distSq := (prevX-x0)*(prevX-x0)+(prevY-y0)*(prevY-y0);
+ if (distSq < lastDistSq) then
+ begin
+ wasHit := true;
+ lastDistSq := distSq;
+ ex := prevX;
+ ey := prevY;
+ lastObj := px.mObj;
+ end;
end;
+ end
+ else
+ begin
+ // this is possibly interesting wall, set "has more to check" flag
+ hasUntried := true;
end;
end;
end;
+ // next cell
curci := cc.next;
end;
+ // still has something interesting in this cell?
if not hasUntried then
begin
- // don't process this cell anymore
+ // nope, don't process this cell anymore; signal cell completion
ccidx := -1;
- if assigned(cb) then result := cb(nil, 0, x, y, prevX, prevY) else result := wasHit;
- if result then exit; // don't update lasthit: it is done in real checker
+ if assigned(cb) then
+ begin
+ if cb(nil, 0, x, y, prevX, prevY) then begin result := lastObj; exit; end;
+ end
+ else if wasHit then
+ begin
+ result := lastObj;
+ exit;
+ end;
end;
+ // convert coords to grid
Dec(x, minx);
Dec(y, miny);
end;
diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index d1d824a9396883a9f2a5e3f2038a6bd7cf5dff4c..7d6f3dddd37d8472a5340620de86bdea06d6cb2f 100644 (file)
--- a/src/game/g_map.pas
+++ b/src/game/g_map.pas
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
{$INCLUDE ../shared/a_modes.inc}
+{$DEFINE MAP_DEBUG_ENABLED_FLAG}
unit g_map;
interface
GridTagLift = 1 shl 8;
GridTagBlockMon = 1 shl 9;
+ GridDrawableMask = (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore);
+
var
gWalls: TPanelArray;
if (hitx <> nil) then hitx^ := lastX;
if (hity <> nil) then hity^ := lastY;
*)
- result := mapGrid.traceRay(ex, ey, x0, y0, x1, y1, nil, (GridTagWall or GridTagDoor));
+ result := (mapGrid.traceRay(ex, ey, x0, y0, x1, y1, nil, (GridTagWall or GridTagDoor)) <> nil);
end;
if ((tagmask and GridTagLift) <> 0) then
begin
// slow
- result := mapGrid.forEachAtPoint(x, y, checker, tagmask);
+ result := (mapGrid.forEachAtPoint(x, y, checker, tagmask) <> nil);
end
else
begin
// fast
- result := mapGrid.forEachAtPoint(x, y, nil, tagmask);
+ result := (mapGrid.forEachAtPoint(x, y, nil, tagmask) <> nil);
end;
end;
pan.tag := tag;
if not pan.visvalid then continue;
pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, tag);
+ // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
mapGrid.proxyEnabled[pan.proxyId] := pan.Enabled;
+ {$IFDEF MAP_DEBUG_ENABLED_FLAG}
+ if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
+ begin
+ e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
+ end;
+ {$ENDIF}
//mapTree.insertObject(pan, tag, true); // as static object
end;
end;
end
else}
begin
- mapGrid.forEachInAABB(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
+ mapGrid.forEachInAABB(x0, y0, wdt, hgt, checker, GridDrawableMask, true);
end;
// list will be rendered in `g_game.DrawPlayer()`
end;
end
else}
begin
- mapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
+ mapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor), true);
end;
end;
function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean;
+const
+ SlowMask = GridTagLift or GridTagBlockMon;
function checker (pan: TPanel; tag: Integer): Boolean;
begin
- result := false; // don't stop, ever
-
{
if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
begin
@@ -2356,7 +2366,7 @@ function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word;
// other shit
//result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
- result := true;
+ result := true; // i found her!
end;
var
begin
if (Width = 1) and (Height = 1) then
begin
- if ((tagmask and (GridTagLift or GridTagBlockMon)) <> 0) then
+ if ((tagmask and SlowMask) <> 0) then
begin
// slow
- result := mapGrid.forEachAtPoint(X, Y, checker, tagmask);
+ result := (mapGrid.forEachAtPoint(X, Y, checker, tagmask) <> nil);
end
else
begin
// fast
- result := mapGrid.forEachAtPoint(X, Y, nil, tagmask);
+ result := (mapGrid.forEachAtPoint(X, Y, nil, tagmask) <> nil);
end;
end
else
begin
- if ((tagmask and (GridTagLift or GridTagBlockMon)) <> 0) then
+ if ((tagmask and SlowMask) <> 0) then
begin
// slow
- result := mapGrid.forEachInAABB(X, Y, Width, Height, checker, tagmask);
+ result := (mapGrid.forEachInAABB(X, Y, Width, Height, checker, tagmask) <> nil);
end
else
begin
// fast
- result := mapGrid.forEachInAABB(X, Y, Width, Height, nil, tagmask);
+ result := (mapGrid.forEachInAABB(X, Y, Width, Height, nil, tagmask) <> nil);
end;
end;
end;
procedure g_Map_EnableWall(ID: DWORD);
+var
+ pan: TPanel;
begin
- with gWalls[ID] do
- begin
- Enabled := True;
- g_Mark(X, Y, Width, Height, MARK_DOOR, True);
- mapGrid.proxyEnabled[proxyId] := true;
+ pan := gWalls[ID];
+ pan.Enabled := True;
+ g_Mark(pan.X, pan.Y, pan.Width, pan.Height, MARK_DOOR, True);
- if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
- end;
+ mapGrid.proxyEnabled[pan.proxyId] := true;
+ //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
+ //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
+
+ if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(gWalls[ID].PanelType, ID);
+
+ {$IFDEF MAP_DEBUG_ENABLED_FLAG}
+ e_WriteLog(Format('wall #%d(%d) enabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
+ {$ENDIF}
end;
procedure g_Map_DisableWall(ID: DWORD);
+var
+ pan: TPanel;
begin
- with gWalls[ID] do
- begin
- Enabled := False;
- g_Mark(X, Y, Width, Height, MARK_DOOR, False);
- mapGrid.proxyEnabled[proxyId] := false;
+ pan := gWalls[ID];
+ pan.Enabled := False;
+ g_Mark(pan.X, pan.Y, pan.Width, pan.Height, MARK_DOOR, False);
- if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
- end;
+ mapGrid.proxyEnabled[pan.proxyId] := false;
+ //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
+
+ if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pan.PanelType, ID);
+
+ {$IFDEF MAP_DEBUG_ENABLED_FLAG}
+ e_WriteLog(Format('wall #%d(%d) disabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
+ {$ENDIF}
end;
procedure g_Map_SwitchTexture(PanelType: Word; ID: DWORD; AnimLoop: Byte = 0);
topx := x;
topy := y;
// started outside of the liquid?
- if not mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) then begin result := false; exit; end;
+ if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
if (dx = 0) and (dy = 0) then begin result := false; exit; end; // sanity check
result := true;
while true do
begin
Inc(x, dx);
Inc(y, dy);
- if not mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) then exit; // out of the water, just exit
+ if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
topx := x;
topy := y;
end;
index 229748d1e4b0a88165f9cb2319d6ed744b0b3f82..f94e8e8dc3160fb7e451647ce6513afb0db0d671 100644 (file)
--- a/src/game/g_monsters.pas
+++ b/src/game/g_monsters.pas
uses
g_basic, e_graphics, g_phys, g_textures,
- g_saveload, BinEditor, g_panel, z_aabbtree;
+ g_saveload, BinEditor, g_panel, z_aabbtree, xprofiler;
const
MONSTATE_SLEEP = 0;
gmon_debug_use_sqaccel: Boolean = true;
+//HACK!
+procedure g_Mons_ProfilersBegin ();
+procedure g_Mons_ProfilersEnd ();
+
+procedure g_Mons_LOS_Start (); inline;
+procedure g_Mons_LOS_End (); inline;
+
+var
+ profMonsLOS: TProfiler = nil; //WARNING: FOR DEBUGGING ONLY!
+
+
implementation
uses
g_language, g_netmsg;
+// ////////////////////////////////////////////////////////////////////////// //
+procedure g_Mons_ProfilersBegin ();
+begin
+ if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
+ profMonsLOS.mainBegin(g_profile_los);
+ if g_profile_los then
+ begin
+ profMonsLOS.sectionBegin('loscalc');
+ profMonsLOS.sectionEnd();
+ end;
+end;
+
+procedure g_Mons_ProfilersEnd ();
+begin
+ if (profMonsLOS <> nil) and (g_profile_los) then profMapCollision.mainEnd();
+end;
+
+procedure g_Mons_LOS_Start (); inline;
+begin
+ profMonsLOS.sectionBeginAccum('loscalc');
+end;
+
+procedure g_Mons_LOS_End (); inline;
+begin
+ profMonsLOS.sectionEnd();
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
var
monCheckTrapLastFrameId: DWord;
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index f7770bbb7511f0fcd3fb9d9b7a7637e856820689..c53cba0bb63cc4d259e4277edcfe6300d18efa84 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
SDL2, GL, GLExt, e_graphics, e_log, g_main,
g_console, SysUtils, e_input, g_options, g_game,
g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net,
- g_map, g_gfx;
+ g_map, g_gfx, g_monsters;
var
h_Wnd: PSDL_Window;
end;
g_Map_ProfilersBegin();
+ g_Mons_ProfilersBegin();
t := Time_Delta div 28{(27777 div 1000)};
if t > 0 then
end;
g_Map_ProfilersEnd();
+ g_Mons_ProfilersEnd();
if wLoadingQuit then
begin
if ParamStr(idx) = '--no-particles' then gpart_dbg_enabled := false;
if ParamStr(idx) = '--no-los' then gmon_dbg_los_enabled := false;
+ if ParamStr(idx) = '--profile-render' then g_profile_frame_draw := true;
+ if ParamStr(idx) = '--profile-coldet' then g_profile_collision := true;
+ if ParamStr(idx) = '--profile-los' then g_profile_los := true;
+
if ParamStr(idx) = '--no-part-phys' then gpart_dbg_phys_enabled := false;
if ParamStr(idx) = '--no-part-physics' then gpart_dbg_phys_enabled := false;
if ParamStr(idx) = '--no-particles-phys' then gpart_dbg_phys_enabled := false;