Code: Select all
public static void Clear(this Space s)
{
while(s.Entities.Count > 0)
foreach(Entity e in s.Entities)
s.Remove(e);
}
Code: Select all
public static void Clear(this Space s)
{
while(s.Entities.Count > 0)
foreach(Entity e in s.Entities)
s.Remove(e);
}
Because it's a fairly rare requirement as there exist alternatives like re-creation or controlled removals. Extraneous features are avoided when possible.Why doesn't Space already have a function to clear everything out of it?
It seems like that would be used more than rarely. Either way, I just added a couple of extension methods that added things to a list, and then Clear() removed everything in that list from the space. I guess that could be useful if I needed something to be ignored by Clear(), cause I could just add it with the normal space.Add(), and it would be ignored by Clear(). It took, like... Four lines of code. No, six. Exactly six lines of code. One to declare the list, one to get a new list (the word I'm looking for is escaping me), one to add things to the list when they're added to the space, one to remove them from the list when they're removed from the space, and two to iterate and remove things from the list. Took an extra three to convert it to a dictionary, since it's a static list.Norbo wrote:Because it's a fairly rare requirement as there exist alternatives like re-creation or controlled removals. Extraneous features are avoided when possible.Why doesn't Space already have a function to clear everything out of it?
How so?Norbo wrote:It can also be slower.