2e7105e7729190fbe6e1062c834034beaa43de47
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 // universal spatial grid
17 {$INCLUDE ../shared/a_modes.inc}
18 {$IF DEFINED(D2F_DEBUG)}
19 {.$DEFINE D2F_DEBUG_RAYTRACE}
20 {$ENDIF}
23 interface
26 type
30 public
31 type TGridQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop
32 type TGridRayQueryCB = function (obj: ITP; tag: Integer; x, y, prevx, prevy: Integer): Boolean is nested; // return `true` to stop
33 type TGridAlongQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop
40 private
41 const
45 private
46 type
49 private
56 private
66 TGridInternalCB = function (grida: Integer; bodyId: TBodyProxyId): Boolean of object; // return `true` to stop
68 private
69 //mTileSize: Integer;
72 public
75 private
88 public
90 {$IF DEFINED(D2F_DEBUG)}
92 {$ENDIF}
94 private
115 public
116 constructor Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer{; aTileSize: Integer=GridDefaultTileSize});
119 function insertBody (aObj: ITP; ax, ay, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
128 // `false` if `body` is surely invalid
131 //WARNING: don't modify grid while any query is in progress (no checks are made!)
132 // you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
133 // no callback: return `true` on the first hit
134 function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
136 //WARNING: don't modify grid while any query is in progress (no checks are made!)
137 // you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
138 // no callback: return `true` on the first hit
141 //WARNING: don't modify grid while any query is in progress (no checks are made!)
142 // you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
143 // cb with `(nil)` will be called before processing new tile
144 // no callback: return `true` on the nearest hit
145 function traceRay (const x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP; overload;
146 function traceRay (out ex, ey: Integer; const ax0, ay0, ax1, ay1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
148 //WARNING: don't modify grid while any query is in progress (no checks are made!)
149 // you can set enabled/disabled flag, tho (but iterator can still return objects disabled inside it)
150 // trace line along the grid, calling `cb` for all objects in passed cells, in no particular order
151 function forEachAlongLine (const x0, y0, x1, y1: Integer; cb: TGridAlongQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
153 // debug
158 //WARNING! no sanity checks!
168 // you are not supposed to understand this
169 // returns `true` if there is an intersection, and enter coords
170 // enter coords will be equal to (x0, y0) if starting point is inside the box
171 // if result is `false`, `inx` and `iny` are undefined
172 function lineAABBIntersects (x0, y0, x1, y1: Integer; bx, by, bw, bh: Integer; out inx, iny: Integer): Boolean;
181 implementation
183 uses
187 // ////////////////////////////////////////////////////////////////////////// //
188 procedure swapInt (var a: Integer; var b: Integer); inline; var t: Integer; begin t := a; a := b; b := t; end;
189 function minInt (a, b: Integer): Integer; inline; begin if (a < b) then result := a else result := b; end;
190 function maxInt (a, b: Integer): Integer; inline; begin if (a > b) then result := a else result := b; end;
192 function distanceSq (x0, y0, x1, y1: Integer): Integer; inline; begin result := (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0); end;
195 // ////////////////////////////////////////////////////////////////////////// //
196 // you are not supposed to understand this
197 // returns `true` if there is an intersection, and enter coords
198 // enter coords will be equal to (x0, y0) if starting point is inside the box
199 // if result is `false`, `inx` and `iny` are undefined
200 function lineAABBIntersects (x0, y0, x1, y1: Integer; bx, by, bw, bh: Integer; out inx, iny: Integer): Boolean;
201 var
209 //!term: Integer;
213 begin
215 // why not
221 begin
222 // check this point
224 exit;
227 // check if staring point is inside the box
228 if (x0 >= bx) and (y0 >= by) and (x0 < bx+bw) and (y0 < by+bh) then begin result := true; exit; end;
230 // clip rectange
236 // horizontal setup
238 begin
239 // from left to right
242 end
243 else
244 begin
245 // from right to left
255 // vertical setup
257 begin
258 // from top to bottom
261 end
262 else
263 begin
264 // from bottom to top
278 begin
287 end
288 else
289 begin
299 //!term := x1;
303 begin
304 // clip at top
310 begin
319 begin
320 // clip at left
330 (*
331 if (y1 > wy1) then
332 begin
333 // clip at bottom
334 temp := dx2*(wy1-y0)+dsx;
335 term := x0+temp div dy2;
336 rem := temp mod dy2;
337 if (rem = 0) then Dec(term);
338 end;
340 if (term > wx1) then term := wx1; // clip at right
342 Inc(term); // draw last point
343 //if (term = xd) then exit; // this is the only point, get out of here
344 *)
348 //!dx2 -= dy2;
356 // ////////////////////////////////////////////////////////////////////////// //
357 procedure TBodyGridBase.TBodyProxyRec.setup (aX, aY, aWidth, aHeight: Integer; aObj: ITP; aTag: Integer);
358 begin
370 // ////////////////////////////////////////////////////////////////////////// //
371 constructor TBodyGridBase.Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer{; aTileSize: Integer=GridDefaultTileSize});
372 var
374 begin
376 {$IF DEFINED(D2F_DEBUG)}
378 {$ENDIF}
379 {
380 if aTileSize < 1 then aTileSize := 1;
381 if aTileSize > 8192 then aTileSize := 8192; // arbitrary limit
382 mTileSize := aTileSize;
383 }
394 // init free list
396 begin
401 // init grid
403 // init proxies
411 e_WriteLog(Format('created grid with size: %dx%d (tile size: %d); pix: %dx%d', [mWidth, mHeight, mTileSize, mWidth*mTileSize, mHeight*mTileSize]), MSG_NOTIFY);
416 begin
424 // ////////////////////////////////////////////////////////////////////////// //
426 var
428 begin
431 begin
435 begin
441 e_WriteLog(Format('grid size: %dx%d (tile size: %d); pix: %dx%d; used cells: %d; max bodies in cell: %d; max proxies allocated: %d; proxies used: %d', [mWidth, mHeight, mTileSize, mWidth*mTileSize, mHeight*mTileSize, mUsedCells, mcb, mProxyMaxCount, mProxyCount]), MSG_NOTIFY);
446 var
449 //px: PBodyProxyRec;
450 begin
453 begin
456 begin
459 begin
461 if (cc.bodies[f] = body) then cb((g mod mWidth)*mTileSize+mMinX, (g div mWidth)*mTileSize+mMinY);
462 //px := @mProxies[cc.bodies[f]];
464 // next cell
472 var
475 begin
483 begin
486 begin
488 if cb(mProxies[cc.bodies[f]].mObj, mProxies[cc.bodies[f]].mTag) then begin result := mProxies[cc.bodies[f]].mObj; exit; end;
490 // next cell
496 // ////////////////////////////////////////////////////////////////////////// //
497 function TBodyGridBase.getGridWidthPx (): Integer; inline; begin result := mWidth*mTileSize; end;
498 function TBodyGridBase.getGridHeightPx (): Integer; inline; begin result := mHeight*mTileSize; end;
502 begin
503 // fix coords
511 begin
513 begin
516 end
517 else
518 begin
526 // ////////////////////////////////////////////////////////////////////////// //
528 begin
534 begin
536 begin
538 begin
540 end
541 else
542 begin
549 // ////////////////////////////////////////////////////////////////////////// //
551 var
554 begin
556 begin
557 // no free cells, want more
561 begin
572 //pc.bodies[0] := -1;
574 //e_WriteLog(Format('grid: allocated new cell #%d (total: %d)', [result, mUsedCells]), MSG_NOTIFY);
579 begin
581 begin
583 begin
594 // ////////////////////////////////////////////////////////////////////////// //
595 function TBodyGridBase.allocProxy (aX, aY, aWidth, aHeight: Integer; aObj: ITP; aTag: Integer): TBodyProxyId;
596 var
599 begin
601 begin
602 // no free proxies, resize list
609 // get one from list
614 // add to used list
616 // statistics
622 begin
624 if (mProxyCount = 0) then raise Exception.Create('wutafuuuuu in grid (no allocated proxies, what i should free now?)');
625 // add to free list
633 // ////////////////////////////////////////////////////////////////////////// //
634 function TBodyGridBase.forGridRect (x, y, w, h: Integer; cb: TGridInternalCB; bodyId: TBodyProxyId): Boolean;
635 const
637 var
640 begin
643 // fix coords
646 // go on
650 //tsize := mTileSize;
653 begin
657 begin
667 // ////////////////////////////////////////////////////////////////////////// //
669 var
674 begin
676 // add body to the given grid cell
679 begin
682 begin
683 // can add here
685 begin
687 begin
690 exit;
696 // either no room, or no cell at all
706 var
708 begin
715 // assume that we cannot have one object added to bucket twice
717 var
721 begin
723 // find and remove cell
727 begin
730 begin
732 begin
733 // i found her!
735 begin
736 // this cell contains no elements, remove it
739 exit;
741 // remove element from bucket
743 begin
748 exit;
756 // absolutely not tested
758 var
760 begin
767 // ////////////////////////////////////////////////////////////////////////// //
768 function TBodyGridBase.insertBody (aObj: ITP; aX, aY, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
769 begin
777 begin
784 // ////////////////////////////////////////////////////////////////////////// //
786 var
789 begin
797 // did any corner crossed tile boundary?
802 begin
809 end
810 else
811 begin
819 //TODO: optimize for horizontal/vertical moves
821 var
829 begin
831 // check if tile coords was changed
836 // map -> grid
841 // check for heavy work
853 begin
854 // crossed tile boundary, do heavy work
857 // cycle with old rect, remove body where it is necessary
858 // optimized for horizontal moves
859 //e_WriteLog(Format('og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
860 // remove stale marks
863 begin
868 //e_WriteLog(Format(' norm og:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1]), MSG_NOTIFY);
870 begin
872 begin
873 // this column is completely outside of new rect
875 begin
876 //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
879 end
880 else
881 begin
882 // heavy checks
884 begin
886 begin
887 //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
894 // cycle with new rect, add body where it is necessary
897 begin
902 //e_WriteLog(Format(' norm ng:(%d,%d)-(%d,%d)', [ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
904 begin
906 begin
907 // this column is completely outside of old rect
909 begin
910 //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
913 end
914 else
915 begin
916 // heavy checks
918 begin
920 begin
921 //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
928 // done
930 // update coordinates
936 var
939 begin
941 // check if tile coords was changed
949 begin
950 // crossed tile boundary, do heavy work
955 end
956 else
957 begin
958 // nothing to do with the grid, just fix size
965 // ////////////////////////////////////////////////////////////////////////// //
966 // no callback: return `true` on the first hit
967 function TBodyGridBase.forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): ITP;
968 var
975 begin
980 // make coords (0,0)-based
986 // restore coords
990 // increase query counter
993 begin
994 // just in case of overflow
1001 begin
1004 begin
1009 begin
1011 begin
1014 begin
1016 end
1017 else
1018 begin
1020 exit;
1030 // ////////////////////////////////////////////////////////////////////////// //
1031 // no callback: return `true` on the first hit
1032 function TBodyGridBase.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
1033 const
1035 var
1046 begin
1055 // fix coords
1060 //tsize := mTileSize;
1065 // increase query counter
1068 begin
1069 // just in case of overflow
1073 //e_WriteLog(Format('grid: query #%d: (%d,%d)-(%dx%d)', [mLastQuery, minx, miny, maxx, maxy]), MSG_NOTIFY);
1076 // go on
1078 begin
1082 begin
1085 // process cells
1088 begin
1091 begin
1097 //if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
1098 //if ( ((ptag and TagDisabled) = 0) = ignoreDisabled) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
1099 begin
1104 begin
1106 end
1107 else
1108 begin
1110 exit;
1121 // ////////////////////////////////////////////////////////////////////////// //
1122 // no callback: return `true` on the nearest hit
1123 function TBodyGridBase.traceRay (const x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
1124 var
1126 begin
1131 // no callback: return `true` on the nearest hit
1132 // you are not supposed to understand this
1133 function TBodyGridBase.traceRay (out ex, ey: Integer; const ax0, ay0, ax1, ay1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
1134 const
1136 var
1162 begin
1170 if (ax0 = ax1) and (ay0 = ay1) then exit; // as the first point is ignored, just get outta here
1181 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1182 if assigned(dbgRayTraceTileHitCB) then e_WriteLog(Format('TRACING: (%d,%d)-(%d,%d) [(%d,%d)-(%d,%d)]; maxdistsq=%d', [ax0, ay0, ax1, ay1, minx, miny, maxx, maxy, lastDistSq]), MSG_NOTIFY);
1183 {$ENDIF}
1190 // offset query coords to (0,0)-based
1196 // clip rectange
1202 // horizontal setup
1204 begin
1205 // from left to right
1208 end
1209 else
1210 begin
1211 // from right to left
1221 // vertical setup
1223 begin
1224 // from top to bottom
1227 end
1228 else
1229 begin
1230 // from bottom to top
1244 begin
1253 end
1254 else
1255 begin
1269 begin
1270 // clip at top
1276 begin
1285 begin
1286 // clip at left
1297 begin
1298 // clip at bottom
1308 //if (term = xd) then exit; // this is the only point, get out of here
1314 // first move, to skip starting point
1318 // move coords
1321 // done?
1324 {$IF DEFINED(D2F_DEBUG)}
1325 if (xptr^ < 0) or (yptr^ < 0) or (xptr^ >= gw*tsize) and (yptr^ >= gh*tsize) then raise Exception.Create('raycaster internal error (0)');
1326 {$ENDIF}
1330 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1331 //if assigned(dbgRayTraceTileHitCB) then e_WriteLog('1:TRACING!', MSG_NOTIFY);
1332 {$ENDIF}
1334 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1335 if assigned(dbgRayTraceTileHitCB) then dbgRayTraceTileHitCB((xptr^ div tsize*tsize)+minx, (yptr^ div tsize*tsize)+miny);
1336 {$ENDIF}
1338 //if (dbgShowTraceLog) then e_WriteLog(Format('raycast start: (%d,%d)-(%d,%d); xptr^=%d; yptr^=%d', [ax0, ay0, ax1, ay1, xptr^, yptr^]), MSG_NOTIFY);
1340 // increase query counter
1343 begin
1344 // just in case of overflow
1351 // draw it; can omit checks
1353 begin
1354 // check cell(s)
1355 {$IF DEFINED(D2F_DEBUG)}
1356 if (xptr^ < 0) or (yptr^ < 0) or (xptr^ >= gw*tsize) and (yptr^ >= gh*tsize) then raise Exception.Create('raycaster internal error (0)');
1357 {$ENDIF}
1358 // new tile?
1361 begin
1362 // yes
1363 {$IF DEFINED(D2F_DEBUG)}
1364 if assigned(dbgRayTraceTileHitCB) then dbgRayTraceTileHitCB((xptr^ div tsize*tsize)+minx, (yptr^ div tsize*tsize)+miny);
1365 {$ENDIF}
1367 begin
1368 // signal cell completion
1370 begin
1372 end
1374 begin
1376 exit;
1382 // has something to process in this tile?
1384 begin
1385 // process cell
1387 hasUntried := false; // this will be set to `true` if we have some proxies we still want to process at the next step
1388 // convert coords to map (to avoid ajdusting coords inside the loop)
1391 // process cell list
1393 begin
1396 begin
1401 begin
1402 // can we process this proxy?
1404 begin
1407 begin
1409 begin
1413 exit;
1415 (*
1416 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1417 distSq := distanceSq(ax0, ay0, prevx, prevy);
1418 if assigned(dbgRayTraceTileHitCB) then e_WriteLog(Format(' hit(%d): a=(%d,%d), h=(%d,%d), p=(%d,%d); distsq=%d; lastsq=%d', [cc.bodies[f], ax0, ay0, x, y, prevx, prevy, distSq, lastDistSq]), MSG_NOTIFY);
1419 if (distSq < lastDistSq) then
1420 begin
1421 wasHit := true;
1422 lastDistSq := distSq;
1423 ex := prevx;
1424 ey := prevy;
1425 lastObj := px.mObj;
1426 end;
1427 {$ENDIF}
1428 *)
1429 end
1430 else
1431 begin
1432 // remember this hitpoint if it is nearer than an old one
1434 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1435 if assigned(dbgRayTraceTileHitCB) then e_WriteLog(Format(' hit(%d): a=(%d,%d), h=(%d,%d), p=(%d,%d); distsq=%d; lastsq=%d', [cc.bodies[f], ax0, ay0, x, y, prevx, prevy, distSq, lastDistSq]), MSG_NOTIFY);
1436 {$ENDIF}
1438 begin
1446 end
1447 else
1448 begin
1449 // this is possibly interesting proxy, set "has more to check" flag
1454 // next cell
1457 // still has something interesting in this cell?
1459 begin
1460 // nope, don't process this cell anymore; signal cell completion
1463 begin
1465 end
1467 begin
1469 exit;
1473 //putPixel(xptr^, yptr^);
1474 // move coords
1483 // ////////////////////////////////////////////////////////////////////////// //
1484 //FIXME! optimize this with real tile walking
1485 function TBodyGridBase.forEachAlongLine (const x0, y0, x1, y1: Integer; cb: TGridAlongQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
1486 const
1488 var
1507 //tedist: Integer;
1508 begin
1530 // `x` and `y` will be in grid coords
1534 // increase query counter
1537 begin
1538 // just in case of overflow
1544 // cache various things
1545 //tsize := mTileSize;
1551 // setup distance and flags
1554 // setup starting tile ('cause we'll adjust tile vars only on tile edge crossing)
1557 // it is slightly faster this way
1561 if (log) then e_WriteLog(Format('tracing: (%d,%d)-(%d,%d)', [x, y, x1-minx, y1-miny]), MSG_NOTIFY);
1563 // now trace
1566 begin
1568 // do one step
1571 // invariant: one of those always changed
1572 {$IF DEFINED(D2F_DEBUG)}
1573 if (xerr < 0) and (yerr < 0) then raise Exception.Create('internal bug in grid raycaster (0)');
1574 {$ENDIF}
1577 // invariant: we always doing a step
1578 {$IF DEFINED(D2F_DEBUG)}
1580 {$ENDIF}
1581 begin
1582 // check for crossing tile/grid boundary
1584 begin
1585 // we're still in grid
1587 // check for tile edge crossing
1593 // crossed tile edge?
1595 begin
1596 // setup new cell index
1598 if (log) then e_WriteLog(Format(' stepped to new tile (%d,%d) -- (%d,%d)', [(x div tsize), (y div tsize), x, y]), MSG_NOTIFY);
1599 end
1600 else
1602 begin
1603 // we have nothing interesting here anymore, jump directly to tile edge
1604 (*
1605 if (incx = 0) then
1606 begin
1607 // vertical line
1608 if (incy < 0) then tedist := y-(y and (not tsize)) else tedist := (y or (tsize-1))-y;
1609 if (tedist > 1) then
1610 begin
1611 if (log) then e_WriteLog(Format(' doing vertical jump from tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1612 y += incy*tedist;
1613 Inc(i, tedist);
1614 if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1615 end;
1616 end
1617 else if (incy = 0) then
1618 begin
1619 // horizontal line
1620 if (incx < 0) then tedist := x-(x and (not tsize)) else tedist := (x or (tsize-1))-x;
1621 if (tedist > 1) then
1622 begin
1623 if (log) then e_WriteLog(Format(' doing horizontal jump from tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1624 x += incx*tedist;
1625 Inc(i, tedist);
1626 if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1627 end;
1628 end;
1629 *)
1630 (*
1631 else if (
1632 // get minimal distance to tile edges
1633 if (incx < 0) then tedist := x-(x and (not tsize)) else if (incx > 0) then tedist := (x or (tsize+1))-x else tedist := 0;
1634 {$IF DEFINED(D2F_DEBUG)}
1635 if (tedist < 0) then raise Exception.Create('internal bug in grid raycaster (2.x)');
1636 {$ENDIF}
1637 if (incy < 0) then f := y-(y and (not tsize)) else if (incy > 0) then f := (y or (tsize+1))-y else f := 0;
1638 {$IF DEFINED(D2F_DEBUG)}
1639 if (f < 0) then raise Exception.Create('internal bug in grid raycaster (2.y)');
1640 {$ENDIF}
1641 if (tedist = 0) then tedist := f else if (f <> 0) then tedist := minInt(tedist, f);
1642 // do jump
1643 if (tedist > 1) then
1644 begin
1645 if (log) then e_WriteLog(Format(' doing jump from tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1646 xerr += dx*tedist;
1647 yerr += dy*tedist;
1648 if (xerr >= 0) then begin x += incx*((xerr div d)+1); xerr := (xerr mod d)-d; end;
1649 if (yerr >= 0) then begin y += incy*((yerr div d)+1); yerr := (yerr mod d)-d; end;
1650 Inc(i, tedist);
1651 if (log) then e_WriteLog(Format(' jumped to tile (%d,%d) - (%d,%d) by %d steps', [(x div tsize), (y div tsize), x, y, tedist]), MSG_NOTIFY);
1652 end;
1653 *)
1655 end
1656 else
1657 begin
1658 // out of grid
1663 // has something to process in the current cell?
1665 begin
1666 // process cell
1668 // convert coords to map (to avoid ajdusting coords inside the loop)
1669 //Inc(x, minx);
1670 //Inc(y, miny);
1671 // process cell list
1673 begin
1676 begin
1681 begin
1686 // next cell
1690 // convert coords to grid
1691 //Dec(x, minx);
1692 //Dec(y, miny);