MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / orderList

Method orderList

Engine/source/T3D/gameBase/processList.cpp:131–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129//----------------------------------------------------------------------------
130
131void ProcessList::orderList()
132{
133 // ProcessObject tags are initialized to 0, so current tag should never be 0.
134 if (++mCurrentTag == 0)
135 mCurrentTag++;
136
137 // Install a temporary head node
138 ProcessObject list;
139 list.plLinkBefore(mHead.mProcessLink.next);
140 mHead.plUnlink();
141
142 // start out by (bubble) sorting list by GUID
143 for (ProcessObject * cur = list.mProcessLink.next; cur != &list; cur = cur->mProcessLink.next)
144 {
145 if (cur->mOrderGUID == 0)
146 // special case -- can be no lower, so accept as lowest (this is also
147 // a common value since it is what non ordered objects have)
148 continue;
149
150 for (ProcessObject * walk = cur->mProcessLink.next; walk != &list; walk = walk->mProcessLink.next)
151 {
152 if (walk->mOrderGUID < cur->mOrderGUID)
153 {
154 // swap walk and cur -- need to be careful because walk might be just after cur
155 // so insert after item before cur and before item after walk
156 ProcessObject * before = cur->mProcessLink.prev;
157 ProcessObject * after = walk->mProcessLink.next;
158 cur->plUnlink();
159 walk->plUnlink();
160 cur->plLinkBefore(after);
161 walk->plLinkAfter(before);
162 ProcessObject * swap = walk;
163 walk = cur;
164 cur = swap;
165 }
166 }
167 }
168
169 // Reverse topological sort into the original head node
170 while (list.mProcessLink.next != &list)
171 {
172 ProcessObject * ptr = list.mProcessLink.next;
173 ProcessObject * afterObject = ptr->getAfterObject();
174 ptr->mProcessTag = mCurrentTag;
175 ptr->plUnlink();
176 if (afterObject)
177 {
178 // Build chain "stack" of dependent objects and patch
179 // it to the end of the current list.
180 while (afterObject && afterObject->mProcessTag != mCurrentTag)
181 {
182 afterObject->mProcessTag = mCurrentTag;
183 afterObject->plUnlink();
184 afterObject->plLinkBefore(ptr);
185 ptr = afterObject;
186 afterObject = ptr->getAfterObject();
187 }
188 ptr->plJoin(&mHead);

Callers

nothing calls this directly

Calls 5

plLinkBeforeMethod · 0.80
plUnlinkMethod · 0.80
plLinkAfterMethod · 0.80
plJoinMethod · 0.80
getAfterObjectMethod · 0.45

Tested by

no test coverage detected