Collision-with-condition checkers. Entity/Component Awake timing fixes. Batcher.Pixel()

This commit is contained in:
Maddy Thorson
2021-02-06 16:37:38 -08:00
parent 3d5130b45b
commit 86b05c648b
7 changed files with 241 additions and 35 deletions

View File

@ -97,17 +97,13 @@ namespace Strawberry
entities.Add(e);
e.[Friend]Added(this);
}
toAdd.Clear();
}
for (let e in entities)
e.[Friend]UpdateLists();
if (toAdd.Count > 0)
{
for (let e in toAdd)
e.Started();
toAdd.Clear();
}
for (let e in entities)
e.[Friend]AwakeCheck();
}
// Tracking
@ -148,6 +144,24 @@ namespace Strawberry
return componentTracker[typeof(T)].Count;
}
public int Count<T>(delegate bool(T) condition) where T : Component
{
int count = 0;
for (T c in componentTracker[typeof(T)])
if (condition(c))
count++;
return count;
}
public bool Check<T>(delegate bool(T) condition) where T : Component
{
for (T c in componentTracker[typeof(T)])
if (condition(c))
return true;
return false;
}
public bool Check<T>(Point point) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
@ -164,13 +178,21 @@ namespace Strawberry
return false;
}
public T First<T>() where T : Component, IHasHitbox
public T First<T>() where T : Component
{
for (T c in componentTracker[typeof(T)])
return c;
return null;
}
public T First<T>(delegate bool(T) condition) where T : Component
{
for (T c in componentTracker[typeof(T)])
if (condition(c))
return c;
return null;
}
public T First<T>(Point point) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
@ -179,6 +201,14 @@ namespace Strawberry
return null;
}
public T First<T>(Point point, delegate bool(T) condition) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
if (condition(c) && c.Hitbox.Check(point))
return c as T;
return null;
}
public T First<T>(Rect rect) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
@ -187,13 +217,29 @@ namespace Strawberry
return null;
}
public List<T> All<T>(List<T> into) where T : Component, IHasHitbox
public T First<T>(Rect rect, delegate bool(T) condition) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
if (condition(c) && c.Hitbox.Check(rect))
return c as T;
return null;
}
public List<T> All<T>(List<T> into) where T : Component
{
for (T c in componentTracker[typeof(T)])
into.Add(c as T);
return into;
}
public List<T> All<T>(List<T> into, delegate bool(T) condition) where T : Component
{
for (T c in componentTracker[typeof(T)])
if (condition(c))
into.Add(c as T);
return into;
}
public List<T> All<T>(Point point, List<T> into) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
@ -202,10 +248,18 @@ namespace Strawberry
return into;
}
public List<T> All<T>(Rect rect, List<T> into) where T : Component, IHasHitbox
public List<T> All<T>(Point point, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
if (c.Hitbox.Check(rect))
if (condition(c) && c.Hitbox.Check(point))
into.Add(c as T);
return into;
}
public List<T> All<T>(Rect rect, List<T> into, delegate bool(T) condition) where T : Component, IHasHitbox
{
for (T c in componentTracker[typeof(T)])
if (condition(c) && c.Hitbox.Check(rect))
into.Add(c as T);
return into;
}