Deleting RECT as a tracepoint for collision detection

20 Views Asked by At

Having SHAPES with RECTs around to detect collions between objects. RECTs and SHAPES are moving on a CANVAS simultaniosly. Only SHAPES are drawn - RECTs are invisible. Now... I'm using RECTs as a trace of a moving object (Shape) on a canvas. A LIFO class drops out the oldest RECT by position on the canvas where the newest 'pheromone' is pushed.first in the LIFO stack according to the movement of it's host. Collision detection is used by other objects (Shapes) to follow the trace. *How do I remove the fading RECTs from the Canvas in order to save memory and avoid unexpected collisions? *

Setting "dead" RECTS to a default position seems not to be a good idea... Looking for something like: g.DrawRectangle(pen, 100,100, 100, 200); g.dispose();

My SHAPE (BOB)

public Species(int _index, Genome _genome)
        {
            this.Alive = true;
            this.EmitSignal = false;
            this.Challange = false;
            this.Index = _index;
            this.Age = 0;
            this.Fitness = 0;
            this.Speed = P.SPEED;
            this.Loc = FindBirthLoc(_index);
            this.LastMove = MoveDir();
            this.Genepool = _genome;
            this.BobNet = MakeBobNet(Genepool);
            this.BobSig = new Species.LIFOBuffer<Rect>(P.SIGFADE);
            peeps.Add(this);
        }

My LIFO Stack:

public class LIFOBuffer<T> : LinkedList<T>
        {
            private int capacity;
            private LinkedListNode<T> node;
            public LIFOBuffer(int capacity)
            {
                this.capacity = capacity;
            }
            public T Add(T item)
            {
                if (Count == capacity)
                {
                    node = Last;
                    RemoveLast();
                    AddFirst(item);
                    return node.Value;
                }
                else
                {
                    AddFirst(item);
                    return default(T);
                }
            }
        }

BOB moved by Vector _p leaving a new trace:

public static Rect SetSignal(Species _Bob , Vector _p)
        {
            Rect _rsig = new Rect((Point)_p, P.SIGSIZE);
            Rect _deadsig = _Bob.BobSig.Add(_rsig);
            return _deadsig;
        }

This routine "produces" new RECTs but missing the deletion of the _deadsig.

0

There are 0 best solutions below