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

Method remove

Engine/source/gui/worldEditor/terrainEditor.cpp:171–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171bool Selection::remove(const GridInfo &info)
172{
173 PROFILE_SCOPE( TerrainEditor_Selection_Remove );
174
175 if(size() < 1)
176 return false;
177
178 //AssertFatal( validate(), "Selection hashLists corrupted before Selection.remove()");
179
180 U32 hashIndex = getHashIndex(info.mGridPoint.gridPos);
181 S32 listHead = mHashLists[hashIndex];
182 //AssertFatal(listHead < size(), "A Selection's hash table is corrupt.");
183
184 if(listHead == -1)
185 return(false);
186
187 const S32 victimEntry = lookup(info.mGridPoint.gridPos);
188 if( victimEntry == -1 )
189 return(false);
190
191 const GridInfo victim = (*this)[victimEntry];
192 const S32 vicPrev = victim.mPrev;
193 const S32 vicNext = victim.mNext;
194
195 // remove us from the linked list, if there is one.
196 if(vicPrev != -1)
197 (*this)[vicPrev].mNext = vicNext;
198 if(vicNext != -1)
199 (*this)[vicNext].mPrev = vicPrev;
200
201 // if we were the head of the list, make our next the new head in the hash table.
202 if(vicPrev == -1)
203 mHashLists[hashIndex] = vicNext;
204
205 // if we're not the last element in the vector, copy the last element to our position.
206 if(victimEntry != size() - 1)
207 {
208 // copy last into victim, and re-cache next & prev
209 const GridInfo lastEntry = last();
210 const S32 lastPrev = lastEntry.mPrev;
211 const S32 lastNext = lastEntry.mNext;
212 (*this)[victimEntry] = lastEntry;
213
214 // update the new element's next and prev, to reestablish it in it's linked list.
215 if(lastPrev != -1)
216 (*this)[lastPrev].mNext = victimEntry;
217 if(lastNext != -1)
218 (*this)[lastNext].mPrev = victimEntry;
219
220 // if it was the head of it's list, update the hash table with its new position.
221 if(lastPrev == -1)
222 {
223 const U32 lastHash = getHashIndex(lastEntry.mGridPoint.gridPos);
224 AssertFatal(mHashLists[lastHash] == size() - 1, "Selection hashLists corrupted during Selection.remove() (oldmsg)");
225 mHashLists[lastHash] = victimEntry;
226 }
227 }
228

Callers 14

removeEventDelegateMethod · 0.45
onSleepMethod · 0.45
_setBitmapMethod · 0.45
setObjectModelMethod · 0.45
processMethod · 0.45
~PopupMenuMethod · 0.45
_disconnectMonitorsMethod · 0.45
setItemHiddenMethod · 0.45
onRemoveMethod · 0.45

Calls 2

lookupFunction · 0.85
sizeFunction · 0.50

Tested by

no test coverage detected