//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#include "neonz.h"

template<typename T>
struct devector
{
	vector<T> vec;
	int start_spot;
	const int pre_buf_size;

	devector() :
	pre_buf_size(10)
	{
		set_up();
	};

	devector(int pre_size) :
	pre_buf_size(pre_size)
	{
		set_up();
	};

	void set_up()
	{
		vec.clear();
		//pre_buf_size = pre_size;
		start_spot = pre_buf_size;
		vec.assign(pre_buf_size, T());
	}
	void push_back(T& entry)
	{
		vec.push_back(entry);
	};
	void push_front(T& entry)
	{
		if(start_spot == 0)
		{
			vec.insert(vec.begin(), pre_buf_size, T());
			start_spot = pre_buf_size;
		}
		start_spot--;
		vec[start_spot] = entry;
	};

	void pop_back()
	{
		vec.pop_back();
	};

	T& operator[](int pos)
	{
		return vec.at(pos + start_spot);
	};

	int size()
	{
		return vec.size() - start_spot;
	};

	T& back()
	{
		return (*this)[size() - 1];
	}
	T& front()
	{
		return (*this)[0];
	}
};

//note how the things are arranged
//the two points are equally spaced in memory
struct STrailEntry
{

	float tcoords1[2];
	int32_t color1;
	float verts1[3];

	float factor;
	int32_t orig_color;

	float tcoords2[2];
	int32_t color2;
	float verts2[3];

	vector2d position;

	STrailEntry& operator =(const STrailEntry& other)
	{
		memcpy(this, &other, sizeof(STrailEntry));
		return *this;
	};
};

struct STrail : SObject
{
	devector<STrailEntry> entries;

	float dec_rate;

	int32_t color;

	SBitmap* bmp;

	STrail()
	: entries(10)
	{
		type = trail_type;
	}

	virtual int Handle();
	virtual void Draw();
};

STrail* CreateTrail(SObject* parent, SBitmap* bmp, int32_t color, float dec_rate);
