b1b157f8d3c685b3b65d457ed5620051d2bbb4dc
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
402 // init grid
404 // init proxies
412 e_WriteLog(Format('created grid with size: %dx%d (tile size: %d); pix: %dx%d', [mWidth, mHeight, mTileSize, mWidth*mTileSize, mHeight*mTileSize]), MSG_NOTIFY);
417 begin
425 // ////////////////////////////////////////////////////////////////////////// //
427 var
429 begin
432 begin
436 begin
442 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);
447 var
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);
463 // next cell
471 var
474 begin
482 begin
485 begin
487 if cb(mProxies[cc.bodies[f]].mObj, mProxies[cc.bodies[f]].mTag) then begin result := mProxies[cc.bodies[f]].mObj; exit; end;
489 // next cell
495 // ////////////////////////////////////////////////////////////////////////// //
496 function TBodyGridBase.getGridWidthPx (): Integer; inline; begin result := mWidth*mTileSize; end;
497 function TBodyGridBase.getGridHeightPx (): Integer; inline; begin result := mHeight*mTileSize; end;
501 begin
502 // fix coords
510 begin
512 begin
515 end
516 else
517 begin
525 // ////////////////////////////////////////////////////////////////////////// //
527 begin
533 begin
535 begin
537 begin
539 end
540 else
541 begin
548 // ////////////////////////////////////////////////////////////////////////// //
550 var
553 begin
555 begin
556 // no free cells, want more
560 begin
572 //e_WriteLog(Format('grid: allocated new cell #%d (total: %d)', [result, mUsedCells]), MSG_NOTIFY);
577 begin
579 begin
581 begin
592 // ////////////////////////////////////////////////////////////////////////// //
593 function TBodyGridBase.allocProxy (aX, aY, aWidth, aHeight: Integer; aObj: ITP; aTag: Integer): TBodyProxyId;
594 var
597 begin
599 begin
600 // no free proxies, resize list
607 // get one from list
612 // add to used list
614 // statistics
620 begin
622 if (mProxyCount = 0) then raise Exception.Create('wutafuuuuu in grid (no allocated proxies, what i should free now?)');
623 // add to free list
631 // ////////////////////////////////////////////////////////////////////////// //
632 function TBodyGridBase.forGridRect (x, y, w, h: Integer; cb: TGridInternalCB; bodyId: TBodyProxyId): Boolean;
633 const
635 var
638 begin
641 // fix coords
644 // go on
648 //tsize := mTileSize;
651 begin
655 begin
665 // ////////////////////////////////////////////////////////////////////////// //
667 var
672 begin
674 // add body to the given grid cell
677 begin
679 // check "has room" flag
681 begin
682 // can add here
684 begin
686 begin
689 exit;
695 // either no room, or no cell at all
705 var
707 begin
714 // assume that we cannot have one object added to bucket twice
716 var
720 begin
722 // find and remove cell
726 begin
729 begin
731 begin
732 // i found her!
734 begin
735 // this cell contains no elements, remove it
738 exit;
740 // remove element from bucket
742 begin
747 exit;
756 var
758 begin
765 // ////////////////////////////////////////////////////////////////////////// //
766 function TBodyGridBase.insertBody (aObj: ITP; aX, aY, aWidth, aHeight: Integer; aTag: Integer=-1): TBodyProxyId;
767 begin
775 begin
782 // ////////////////////////////////////////////////////////////////////////// //
784 var
787 begin
795 // did any corner crossed tile boundary?
800 begin
807 end
808 else
809 begin
817 //TODO: optimize for horizontal/vertical moves
819 var
827 begin
829 // check if tile coords was changed
834 // map -> grid
839 // check for heavy work
851 begin
852 // crossed tile boundary, do heavy work
855 // cycle with old rect, remove body where it is necessary
856 // optimized for horizontal moves
857 //e_WriteLog(Format('og:(%d,%d)-(%d,%d); ng:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1, ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
858 // remove stale marks
861 begin
866 //e_WriteLog(Format(' norm og:(%d,%d)-(%d,%d)', [ogx0, ogy0, ogx1, ogy1]), MSG_NOTIFY);
868 begin
870 begin
871 // this column is completely outside of new rect
873 begin
874 //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
877 end
878 else
879 begin
880 // heavy checks
882 begin
884 begin
885 //e_WriteLog(Format(' remove:(%d,%d)', [gx, gy]), MSG_NOTIFY);
892 // cycle with new rect, add body where it is necessary
895 begin
900 //e_WriteLog(Format(' norm ng:(%d,%d)-(%d,%d)', [ngx0, ngy0, ngx1, ngy1]), MSG_NOTIFY);
902 begin
904 begin
905 // this column is completely outside of old rect
907 begin
908 //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
911 end
912 else
913 begin
914 // heavy checks
916 begin
918 begin
919 //e_WriteLog(Format(' insert:(%d,%d)', [gx, gy]), MSG_NOTIFY);
926 // done
928 // update coordinates
934 var
937 begin
939 // check if tile coords was changed
947 begin
948 // crossed tile boundary, do heavy work
953 end
954 else
955 begin
956 // nothing to do with the grid, just fix size
963 // ////////////////////////////////////////////////////////////////////////// //
964 // no callback: return `true` on the first hit
965 function TBodyGridBase.forEachAtPoint (x, y: Integer; cb: TGridQueryCB; tagmask: Integer=-1): ITP;
966 var
973 begin
978 // make coords (0,0)-based
984 // restore coords
988 // increase query counter
991 begin
992 // just in case of overflow
999 begin
1002 begin
1007 begin
1009 begin
1012 begin
1014 end
1015 else
1016 begin
1018 exit;
1028 // ////////////////////////////////////////////////////////////////////////// //
1029 // no callback: return `true` on the first hit
1030 function TBodyGridBase.forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
1031 const
1033 var
1044 begin
1053 // fix coords
1058 //tsize := mTileSize;
1063 // increase query counter
1066 begin
1067 // just in case of overflow
1071 //e_WriteLog(Format('grid: query #%d: (%d,%d)-(%dx%d)', [mLastQuery, minx, miny, maxx, maxy]), MSG_NOTIFY);
1074 // go on
1076 begin
1080 begin
1083 // process cells
1086 begin
1089 begin
1095 //if ((ptag and TagDisabled) = 0) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
1096 //if ( ((ptag and TagDisabled) = 0) = ignoreDisabled) and ((ptag and tagmask) <> 0) and (px.mQueryMark <> lq) then
1097 begin
1102 begin
1104 end
1105 else
1106 begin
1108 exit;
1119 // ////////////////////////////////////////////////////////////////////////// //
1120 // no callback: return `true` on the nearest hit
1121 function TBodyGridBase.traceRay (const x0, y0, x1, y1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
1122 var
1124 begin
1129 // no callback: return `true` on the nearest hit
1130 // you are not supposed to understand this
1131 function TBodyGridBase.traceRay (out ex, ey: Integer; const ax0, ay0, ax1, ay1: Integer; cb: TGridRayQueryCB; tagmask: Integer=-1): ITP;
1132 const
1134 var
1160 begin
1168 if (ax0 = ax1) and (ay0 = ay1) then exit; // as the first point is ignored, just get outta here
1179 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1180 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);
1181 {$ENDIF}
1188 // offset query coords to (0,0)-based
1194 // clip rectange
1200 // horizontal setup
1202 begin
1203 // from left to right
1206 end
1207 else
1208 begin
1209 // from right to left
1219 // vertical setup
1221 begin
1222 // from top to bottom
1225 end
1226 else
1227 begin
1228 // from bottom to top
1242 begin
1251 end
1252 else
1253 begin
1267 begin
1268 // clip at top
1274 begin
1283 begin
1284 // clip at left
1295 begin
1296 // clip at bottom
1306 //if (term = xd) then exit; // this is the only point, get out of here
1312 // first move, to skip starting point
1316 // move coords
1319 // done?
1322 {$IF DEFINED(D2F_DEBUG)}
1323 if (xptr^ < 0) or (yptr^ < 0) or (xptr^ >= gw*tsize) and (yptr^ >= gh*tsize) then raise Exception.Create('raycaster internal error (0)');
1324 {$ENDIF}
1328 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1329 //if assigned(dbgRayTraceTileHitCB) then e_WriteLog('1:TRACING!', MSG_NOTIFY);
1330 {$ENDIF}
1332 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1333 if assigned(dbgRayTraceTileHitCB) then dbgRayTraceTileHitCB((xptr^ div tsize*tsize)+minx, (yptr^ div tsize*tsize)+miny);
1334 {$ENDIF}
1336 //if (dbgShowTraceLog) then e_WriteLog(Format('raycast start: (%d,%d)-(%d,%d); xptr^=%d; yptr^=%d', [ax0, ay0, ax1, ay1, xptr^, yptr^]), MSG_NOTIFY);
1338 // increase query counter
1341 begin
1342 // just in case of overflow
1349 // draw it; can omit checks
1351 begin
1352 // check cell(s)
1353 {$IF DEFINED(D2F_DEBUG)}
1354 if (xptr^ < 0) or (yptr^ < 0) or (xptr^ >= gw*tsize) and (yptr^ >= gh*tsize) then raise Exception.Create('raycaster internal error (0)');
1355 {$ENDIF}
1356 // new tile?
1359 begin
1360 // yes
1361 {$IF DEFINED(D2F_DEBUG)}
1362 if assigned(dbgRayTraceTileHitCB) then dbgRayTraceTileHitCB((xptr^ div tsize*tsize)+minx, (yptr^ div tsize*tsize)+miny);
1363 {$ENDIF}
1365 begin
1366 // signal cell completion
1368 begin
1370 end
1372 begin
1374 exit;
1380 // has something to process in this tile?
1382 begin
1383 // process cell
1385 hasUntried := false; // this will be set to `true` if we have some proxies we still want to process at the next step
1386 // convert coords to map (to avoid ajdusting coords inside the loop)
1389 // process cell list
1391 begin
1394 begin
1399 begin
1400 // can we process this proxy?
1402 begin
1405 begin
1407 begin
1411 exit;
1413 (*
1414 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1415 distSq := distanceSq(ax0, ay0, prevx, prevy);
1416 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);
1417 if (distSq < lastDistSq) then
1418 begin
1419 wasHit := true;
1420 lastDistSq := distSq;
1421 ex := prevx;
1422 ey := prevy;
1423 lastObj := px.mObj;
1424 end;
1425 {$ENDIF}
1426 *)
1427 end
1428 else
1429 begin
1430 // remember this hitpoint if it is nearer than an old one
1432 {$IF DEFINED(D2F_DEBUG_RAYTRACE)}
1433 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);
1434 {$ENDIF}
1436 begin
1444 end
1445 else
1446 begin
1447 // this is possibly interesting proxy, set "has more to check" flag
1452 // next cell
1455 // still has something interesting in this cell?
1457 begin
1458 // nope, don't process this cell anymore; signal cell completion
1461 begin
1463 end
1465 begin
1467 exit;
1471 //putPixel(xptr^, yptr^);
1472 // move coords
1481 // ////////////////////////////////////////////////////////////////////////// //
1482 //FIXME! optimize this with real tile walking
1483 function TBodyGridBase.forEachAlongLine (const x0, y0, x1, y1: Integer; cb: TGridAlongQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
1484 const
1486 var
1505 //tedist: Integer;
1506 begin
1528 // `x` and `y` will be in grid coords
1532 // increase query counter
1535 begin
1536 // just in case of overflow
1542 // cache various things
1543 //tsize := mTileSize;
1549 // setup distance and flags
1552 // setup starting tile ('cause we'll adjust tile vars only on tile edge crossing)
1555 // it is slightly faster this way
1559 if (log) then e_WriteLog(Format('tracing: (%d,%d)-(%d,%d)', [x, y, x1-minx, y1-miny]), MSG_NOTIFY);
1561 // now trace
1564 begin
1566 // do one step
1569 // invariant: one of those always changed
1570 {$IF DEFINED(D2F_DEBUG)}
1571 if (xerr < 0) and (yerr < 0) then raise Exception.Create('internal bug in grid raycaster (0)');
1572 {$ENDIF}
1575 // invariant: we always doing a step
1576 {$IF DEFINED(D2F_DEBUG)}
1578 {$ENDIF}
1579 begin
1580 // check for crossing tile/grid boundary
1582 begin
1583 // we're still in grid
1585 // check for tile edge crossing
1591 // crossed tile edge?
1593 begin
1594 // setup new cell index
1596 if (log) then e_WriteLog(Format(' stepped to new tile (%d,%d) -- (%d,%d)', [(x div tsize), (y div tsize), x, y]), MSG_NOTIFY);
1597 end
1598 else
1600 begin
1601 // we have nothing interesting here anymore, jump directly to tile edge
1602 (*
1603 if (incx = 0) then
1604 begin
1605 // vertical line
1606 if (incy < 0) then tedist := y-(y and (not tsize)) else tedist := (y or (tsize-1))-y;
1607 if (tedist > 1) then
1608 begin
1609 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);
1610 y += incy*tedist;
1611 Inc(i, tedist);
1612 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);
1613 end;
1614 end
1615 else if (incy = 0) then
1616 begin
1617 // horizontal line
1618 if (incx < 0) then tedist := x-(x and (not tsize)) else tedist := (x or (tsize-1))-x;
1619 if (tedist > 1) then
1620 begin
1621 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);
1622 x += incx*tedist;
1623 Inc(i, tedist);
1624 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);
1625 end;
1626 end;
1627 *)
1628 (*
1629 else if (
1630 // get minimal distance to tile edges
1631 if (incx < 0) then tedist := x-(x and (not tsize)) else if (incx > 0) then tedist := (x or (tsize+1))-x else tedist := 0;
1632 {$IF DEFINED(D2F_DEBUG)}
1633 if (tedist < 0) then raise Exception.Create('internal bug in grid raycaster (2.x)');
1634 {$ENDIF}
1635 if (incy < 0) then f := y-(y and (not tsize)) else if (incy > 0) then f := (y or (tsize+1))-y else f := 0;
1636 {$IF DEFINED(D2F_DEBUG)}
1637 if (f < 0) then raise Exception.Create('internal bug in grid raycaster (2.y)');
1638 {$ENDIF}
1639 if (tedist = 0) then tedist := f else if (f <> 0) then tedist := minInt(tedist, f);
1640 // do jump
1641 if (tedist > 1) then
1642 begin
1643 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);
1644 xerr += dx*tedist;
1645 yerr += dy*tedist;
1646 if (xerr >= 0) then begin x += incx*((xerr div d)+1); xerr := (xerr mod d)-d; end;
1647 if (yerr >= 0) then begin y += incy*((yerr div d)+1); yerr := (yerr mod d)-d; end;
1648 Inc(i, tedist);
1649 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);
1650 end;
1651 *)
1653 end
1654 else
1655 begin
1656 // out of grid
1661 // has something to process in the current cell?
1663 begin
1664 // process cell
1666 // convert coords to map (to avoid ajdusting coords inside the loop)
1667 //Inc(x, minx);
1668 //Inc(y, miny);
1669 // process cell list
1671 begin
1674 begin
1679 begin
1684 // next cell
1688 // convert coords to grid
1689 //Dec(x, minx);
1690 //Dec(y, miny);