Cleaned up entity tracking. Scene.Camera. Matrix struct.

This commit is contained in:
Matt Thorson
2020-05-22 23:39:46 -07:00
parent 292213dae5
commit fe3672f30c
5 changed files with 582 additions and 72 deletions

View File

@ -4,10 +4,12 @@ namespace Strawberry
{
static public class Draw
{
static public Point Camera => Game.Scene != null ? Game.Scene.Camera.Round() : Point.Zero;
static public void Rect(int x, int y, int w, int h, Color color)
{
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)x, (int32)y, (int32)w, (int32)h));
SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
}
static public void Rect(Rect rect, Color color)
@ -18,7 +20,7 @@ namespace Strawberry
static public void HollowRect(int x, int y, int w, int h, Color color)
{
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)x, (int32)y, (int32)w, (int32)h));
SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
}
static public void HollowRect(Rect rect, Color color)
@ -28,8 +30,11 @@ namespace Strawberry
static public void Line(Point from, Point to, Color color)
{
let fromn = (Point)(from - Camera);
let ton = (Point)(to - Camera);
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderDrawLine(Game.Renderer, (int32)from.X, (int32)from.Y, (int32)to.X, (int32)to.Y);
SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y);
}
}
}

View File

@ -1,61 +0,0 @@
using System.Collections;
using System;
namespace Strawberry
{
static public class TypeTree
{
static private Dictionary<Type, List<Type>> EntityAssignableLists;
static private Dictionary<Type, List<Type>> ComponentAssignableLists;
static private void Build()
{
/*
For each Type that extends Entity, we build a list of all the other Entity Types that it is assignable to.
We cache these lists, and use them later to bucket Entities as they are added to the Scene.
This allows us to retrieve Entities by type very easily.
*/
EntityAssignableLists = new Dictionary<Type, List<Type>>();
for (let type in Type.Enumerator())
{
if (type != typeof(Entity) && type.IsSubtypeOf(typeof(Entity)))
{
let list = new List<Type>();
for (let check in Type.Enumerator())
if (check != typeof(Entity) && check.IsSubtypeOf(typeof(Entity)) && type.IsSubtypeOf(check))
list.Add(check);
EntityAssignableLists.Add(type, list);
}
}
/*
And then we also do this for components
*/
ComponentAssignableLists = new Dictionary<Type, List<Type>>();
for (let type in Type.Enumerator())
{
if (type != typeof(Component) && type.IsSubtypeOf(typeof(Component)))
{
let list = new List<Type>();
for (let check in Type.Enumerator())
if (check != typeof(Component) && check.IsSubtypeOf(typeof(Component)) && type.IsSubtypeOf(check))
list.Add(check);
ComponentAssignableLists.Add(type, list);
}
}
}
static private void Dispose()
{
for (let list in EntityAssignableLists.Values)
delete list;
delete EntityAssignableLists;
for (let list in ComponentAssignableLists.Values)
delete list;
delete ComponentAssignableLists;
}
}
}