Here is my CLinked class (it's the class formerly known as CObject)
It provides LinkedList support for classes which inherit from it.
No more messy LinkedList coding.
This code is untested but I'll implement it immediately in my ParticleEngine Demo to keep track of those pesky Particles... after which it will provide support for my CFrame class, which will be used to provide full blown Scene Hierarchy support.
I know I am talking gamecoding in the wrong forum, but I assume these generic classes will be useful to others.
Posted on 2003-12-22 02:46:52 by Homer
I forgot one line in the Destructor class

CLinked_$CLinked proc
local me:DWORD
mov me,ecx
.while .CLinked.pFirstChild
icall me,CLinked,DetachChild, .CLinked.pFirstChild
.if .CLinked.pOwner ; // detaches this object from it's parent
icall .CLinked.pOwner,CLinked, DetachChild,me
CLinked_$CLinked endp
Posted on 2003-12-22 02:49:25 by Homer
Here's a SIMPLE version of CLinked class, with much less overhead but only support for one - dimensional bidirectional linkedlists (normal ones).
This is the one I'll be using for the Particles in my ParticleEngine Demo.
It's faster and cleaner for keeping basic linkedlists.

; The link tree class.
; This class provides a link mechanism to the classes derived from it.

;To attach an object to another, icall pExistingObject, CLinked, Attach, pNewObject
;To detach an object from its peers, icall pExistingObject, CLinked, Detach
;To delete ALL the peers of an object, icall pExistingObject, CLinked, Delete
;To delete a SINGLE object, Detach it and then use the delete macro.

class CLinked
virtual $CLinked
virtual Delete ;Delete all the child objects
virtual Attach ;The only function which requires a param
virtual Detach
long pPrev ;Pointer to the previous sibling
long pNext ;Pointer to the next sibling

CLinked_$CLinked proc
CLinked_$CLinked endp

CLinked_CLinked proc
CLinked_CLinked endp

; Removes the object from the tree by detaching it from its parent and detaching all
; the childs of this object.
CLinked_Detach proc
local me:DWORD
mov me,ecx
mov eax,.CLinked.pPrev
.if eax ;If I have a prev
.if .CLinked.pNext ;If I have a Prev AND ALSO a Next
m2m .CLinked.pNext,.CLinked.pNext ;Patch links either side of This
.else ;If I have a Prev but no Next
mov .CLinked.pNext, NULL ;Simply terminate the link from Prev to This
.elseif .CLinked.pNext ;If I have a Next but I have no Prev
mov eax,.CLinked.pNext
mov .CLinked.pPrev, NULL ;Terminate the link from Next back to This
return .CLinked.pNext
CLinked_Detach endp

CLinked_Attach proc uses ebx ecx pObject
local me:DWORD
mov me,ecx
mov ebx,pObject
.if .CLinked.pNext ;If theres a NEXT in the list, we are inserting after THIS and before NEXT
mov eax, .CLinked.pNext
mov .CLinked.pPrev, ebx ;(patch backwards from the other side, aka the previous NEXT)
mov .CLinked.pNext, ebx
CLinked_Attach endp

CLinked_Delete proc
local me:DWORD
local pobj:DWORD
mov me,ecx
mov pobj,ecx
.while pobj
.while .CLinked.pPrev ;Idiotproof, walk back up first
mov ecx,.CLinked.pPrev ;to find the youngest peer
icall ecx, CLinked, Detach ;returns pNext or NULL
mov pobj,eax
delete eax ;calls destructor
mov ecx,me ;restore ecx (safety)
CLinked_Delete endp
Posted on 2003-12-25 09:34:47 by Homer