From: Ketmar Dark Date: Sun, 21 Jan 2018 10:09:02 +0000 (+0200) Subject: generalized pool iterator (it is not tied to `framePool` anymore) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d63f1f5982f999a8946b02843de44bb2d63974d2;p=d2df-sdl.git generalized pool iterator (it is not tied to `framePool` anymore) --- diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas index ce31c63..79b87ca 100644 --- a/src/game/g_grid.pas +++ b/src/game/g_grid.pas @@ -704,7 +704,7 @@ var cc: PGridCell; presobj: PGridCellCoord; begin - result := CellCoordIter.Create(true); + result := CellCoordIter.Create(framePool); if (body < 0) or (body > High(mProxies)) then begin result.finishIt(); exit; end; for g := 0 to High(mGrid) do begin @@ -737,7 +737,7 @@ var cc: PGridCell; presobj: PITP; begin - result := Iter.Create(true); + result := Iter.Create(framePool); Dec(x, mMinX); Dec(y, mMinY); if (x < 0) or (y < 0) or (x >= mWidth*mTileSize) or (y > mHeight*mTileSize) then begin result.finishIt(); exit; end; @@ -1346,7 +1346,7 @@ var ptag: Integer; presobj: PITP; begin - result := Iter.Create(true); + result := Iter.Create(framePool); tagmask := tagmask and TagFullMask; if (tagmask = 0) then begin result.finishIt(); exit; end; @@ -1438,7 +1438,7 @@ begin exit; end; - result := Iter.Create(true); + result := Iter.Create(framePool); if (w < 1) or (h < 1) then begin result.finishIt(); exit; end; tagmask := tagmask and TagFullMask; @@ -1533,7 +1533,7 @@ var presobj: PITP; begin log := false; - result := Iter.Create(true); + result := Iter.Create(framePool); tagmask := tagmask and TagFullMask; if (tagmask = 0) then begin result.finishIt(); exit; end; diff --git a/src/shared/mempool.pas b/src/shared/mempool.pas index ae67f03..ff1e656 100644 --- a/src/shared/mempool.pas +++ b/src/shared/mempool.pas @@ -63,6 +63,7 @@ type type PoolMark = Integer; + PPoolMarkRelease = ^TPoolMarkRelease; TPoolMarkRelease = record private mMemory: Pointer; @@ -101,14 +102,14 @@ type type MyType = specialize PoolIter; private + mPool: PPoolMarkRelease; mMark: PoolMark; mCount: Integer; mCurrent: Integer; mFinished: Boolean; public - constructor Create (dummy: Boolean); // idiotic FPC doesn't support arg-less ctors for rectord - procedure startIt (); inline; // automatically called by ctor; does NO checks! + constructor Create (var apool: TPoolMarkRelease); // idiotic FPC doesn't support arg-less ctors for rectord procedure finishIt (); inline; // sets count procedure rewind (); inline; @@ -234,15 +235,10 @@ end; // ////////////////////////////////////////////////////////////////////////// // -constructor PoolIter.Create (dummy: Boolean); +constructor PoolIter.Create (var apool: TPoolMarkRelease); begin - startIt(); -end; - - -procedure PoolIter.startIt (); inline; // automatically called by ctor; does NO checks! -begin - mMark := framePool.mark(); + mPool := @apool; + mMark := mPool^.mark(); mCount := 0; mCurrent := -1; mFinished := false; @@ -252,16 +248,16 @@ end; procedure PoolIter.finishIt (); inline; // sets count begin if (mFinished) then raise Exception.Create('double fatality'); - if (mMark = -1) then raise Exception.Create('void fatality'); + if (mPool = nil) then raise Exception.Create('void fatality'); mFinished := true; - mCount := Integer(PtrUInt(framePool.curPtr)-PtrUInt(framePool.getPtr(mMark))) div Integer(sizeof(T)); + mCount := Integer(PtrUInt(mPool^.curPtr)-PtrUInt(mPool^.getPtr(mMark))) div Integer(sizeof(T)); if (mCount < 0) then raise Exception.Create('wutafu?'); end; procedure PoolIter.rewind (); inline; begin - if (mMark = -1) then raise Exception.Create('void rewind'); + if (mPool = nil) then raise Exception.Create('void rewind'); mCurrent := -1; end; @@ -275,9 +271,9 @@ end; procedure PoolIter.release (); inline; // reset pool begin - if (mMark = -1) then raise Exception.Create('double release'); - framePool.release(mMark); - mMark := -1; + if (mPool = nil) then raise Exception.Create('double release'); + mPool^.release(mMark); + mPool := nil; mCount := 0; mCurrent := -1; mFinished := false; @@ -286,7 +282,7 @@ end; function PoolIter.moveNext (): Boolean; inline; begin - if (mMark = -1) then raise Exception.Create('void moveNext()'); + if (mPool = nil) then raise Exception.Create('void moveNext()'); if (not mFinished) then raise Exception.Create('moveNext() on unfinished'); Inc(mCurrent); result := (mCurrent < mCount); @@ -295,8 +291,9 @@ end; function PoolIter.getCurrent (): Ptr; inline; begin + if (mPool = nil) then raise Exception.Create('getCurrent() on nothing'); if (mCurrent < 0) or (mCurrent >= mCount) then raise Exception.Create('getCurrent() range error'); - result := Ptr(framePool.getPtr(mMark+mCurrent*Integer(sizeof(T)))); + result := Ptr(mPool^.getPtr(mMark+mCurrent*Integer(sizeof(T)))); end; @@ -308,9 +305,9 @@ end; function PoolIter.first (): Ptr; inline; begin - if (mMark = -1) then raise Exception.Create('void moveNext()'); + if (mPool = nil) then raise Exception.Create('void moveNext()'); if (not mFinished) then raise Exception.Create('moveNext() on unfinished'); - result := Ptr(framePool.getPtr(mMark)); + result := Ptr(mPool^.getPtr(mMark)); end;