That's just what the engines I know use (Build, Action Arcade Adventure Set). And this is the way I'll use in my engine.
Like this:
Since the pointer itself is stored inside the list, there are very little CPU-cache collisions, so traverse the linked list should be quite fast.Code:TYPE TSpritePtr = ^TSPrite; TSprite = RECORD x, y: INTEGER; Bmp: ImageRef; NextSpr: TSpritePtr; END; VAR SpriteList: ARRAY OF TSprite; { Or a class containing the list, or a spezialized GENERIC or...} PlayerSpr: TSpritePtr; FirstEnemy: TSpritePtr; FirstBullet: TSpritePtr;
[edit]
Fun fact: Actually this may be faster in the old times (i.e. 8086, 80286, 80386), when memory were divided in pages (do you remember the FAR and NEAR pointers?). If the whole list is in one single memory page, no page change is needed, and memory access may be faster specially if the related code is also in the same memory page. The AAAkit book talks about it too.
Thanks pal. It confirms the hypothesis "Objects/CLASSes are the slowest".
[I must test it on FPC though, but I think it will be the same ]
Bookmarks