public int Waypoint; // Current waypoint in the path #endregion Fields #region Constructors public Entity( int index ) { Index = index; Transform = new InstanceTransformRef(); Type = EntityType.Civilian; HalfSize = 1f; AABB = new AABB(); NextPosition = Vector3.Zero; NextAngle = 0f; ListNode = null; Direction = Vector3.Zero; StateTime = 0; StateDuration = 0; Behavior = null; Collision = 0; Path = new List<Vector2>( 60 ); Waypoint = -1; MoveSpeed = 1f; Beacon = null; BeaconVersion = 0; }
public void Add( EntityListNode node ) { #if DEBUG if ( node.parent[cellType] != null ) throw new InvalidOperationException( "Node is already in a list." ); if ( node.prev[cellType] != null || node.next[cellType] != null ) throw new InvalidOperationException( "Node appears to belong to another list of the same type." ); #endif node.parent[cellType] = this; node.prev[cellType] = tail; if ( head == null ) { head = node; tail = node; } else { tail.next[cellType] = node; tail = node; } count++; }
public void AddEntity( ref Entity entity ) { Vector2 min = Vector2.Clamp( entity.AABB.Min, Min, Max ); Vector2 max = Vector2.Clamp( entity.AABB.Max, Min, Max ); // add the entity to all touching cells float cellWidth = ( Max.X - Min.X ) / Cols; int colMin = (int)( ( min.X - Min.X ) / cellWidth ); int colMax = (int)( ( max.X - Min.X ) / cellWidth ); float cellHeight = ( Max.Y - Min.Y ) / Rows; int rowMin = (int)( ( min.Y - Min.Y ) / cellHeight ); int rowMax = (int)( ( max.Y - Min.Y ) / cellHeight ); // make sure the maxs don't go out of bounds if ( colMax >= Cols ) colMax = colMin; if ( rowMax >= Rows ) rowMax = rowMin; EntityListNode node = new EntityListNode( entity.Index ); entity.ListNode = node; for ( int r = rowMin; r <= rowMax; ++r ) { for ( int c = colMin; c <= colMax; ++c ) { cells[Cols * r + c].Entities.Add( node ); } } // box verts boxLineVertCount += 8; while ( boxLineVerts.Length < boxLineVertCount ) { boxLineVerts = new VertexPositionColor[boxLineVerts.Length * 2]; for ( int i = 0; i < boxLineVerts.Length; ++i ) boxLineVerts[i].Color = boxLineColor; } }
internal void Remove( EntityListNode node ) { if ( node == head ) head = node.next[cellType]; if ( node == tail ) tail = node.prev[cellType]; if ( node.prev[cellType] != null ) node.prev[cellType].next[cellType] = node.next[cellType]; if ( node.next[cellType] != null ) node.next[cellType].prev[cellType] = node.prev[cellType]; node.prev[cellType] = null; node.next[cellType] = null; node.parent[cellType] = null; count--; }
public EntityListNode Next( EntityListNode node ) { return node.next[cellType]; }