Added many getters of questionable utility to ParticleSystems.

Storing your own values is blasphemy, clearly.
This commit is contained in:
Alex Szpakowski
2013-04-18 04:54:53 -03:00
parent bf6d1c258b
commit b6247f9ae1
4 changed files with 641 additions and 242 deletions
+181 -75
View File
@@ -63,12 +63,12 @@ StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_M
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries));
ParticleSystem::ParticleSystem(Image *sprite, unsigned int buffer)
ParticleSystem::ParticleSystem(Image *image, unsigned int buffer)
: pStart(0)
, pLast(0)
, pEnd(0)
, particleVerts(0)
, sprite(sprite)
, image(image)
, active(true)
, emissionRate(0)
, emitCounter(0)
@@ -94,13 +94,13 @@ ParticleSystem::ParticleSystem(Image *sprite, unsigned int buffer)
, spinStart(0)
, spinEnd(0)
, spinVariation(0)
, offsetX(sprite->getWidth()*0.5f)
, offsetY(sprite->getHeight()*0.5f)
, offsetX(image->getWidth()*0.5f)
, offsetY(image->getHeight()*0.5f)
{
sizes.push_back(1.0f);
colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
setBufferSize(buffer);
sprite->retain();
image->retain();
}
ParticleSystem::~ParticleSystem()
@@ -108,8 +108,8 @@ ParticleSystem::~ParticleSystem()
for (size_t i = 0; i < quads.size(); i++)
quads[i]->release();
if (this->sprite != 0)
this->sprite->release();
if (this->image != 0)
this->image->release();
if (pStart != 0)
delete [] pStart;
@@ -137,17 +137,17 @@ void ParticleSystem::add()
switch (areaSpreadDistribution)
{
case DISTRIBUTION_UNIFORM:
pLast->position[0] += rng.random(-areaSpread.getX(), areaSpread.getX());
pLast->position[1] += rng.random(-areaSpread.getY(), areaSpread.getY());
break;
case DISTRIBUTION_NORMAL:
pLast->position[0] += rng.randomnormal(areaSpread.getX());
pLast->position[1] += rng.randomnormal(areaSpread.getY());
break;
case DISTRIBUTION_NONE:
default:
break;
case DISTRIBUTION_UNIFORM:
pLast->position[0] += rng.random(-areaSpread.getX(), areaSpread.getX());
pLast->position[1] += rng.random(-areaSpread.getY(), areaSpread.getY());
break;
case DISTRIBUTION_NORMAL:
pLast->position[0] += rng.randomnormal(areaSpread.getX());
pLast->position[1] += rng.randomnormal(areaSpread.getY());
break;
case DISTRIBUTION_NONE:
default:
break;
}
min = direction - spread/2.0f;
@@ -197,13 +197,18 @@ void ParticleSystem::remove(particle *p)
}
}
void ParticleSystem::setSprite(Image *image)
void ParticleSystem::setImage(Image *image)
{
if (sprite != 0)
sprite->release();
if (this->image != 0)
this->image->release();
sprite = image;
sprite->retain();
this->image = image;
this->image->retain();
}
Image *ParticleSystem::getImage() const
{
return image;
}
void ParticleSystem::setBufferSize(unsigned int size)
@@ -223,16 +228,31 @@ void ParticleSystem::setBufferSize(unsigned int size)
particleVerts = new vertex[size*4];
}
int ParticleSystem::getBufferSize() const
{
return pEnd - pStart;
}
void ParticleSystem::setEmissionRate(int rate)
{
emissionRate = rate;
}
int ParticleSystem::getEmissionRate() const
{
return emissionRate;
}
void ParticleSystem::setLifetime(float life)
{
this->life = lifetime = life;
}
float ParticleSystem::getLifetime() const
{
return lifetime;
}
void ParticleSystem::setParticleLife(float min, float max)
{
particleLifeMin = min;
@@ -242,11 +262,33 @@ void ParticleSystem::setParticleLife(float min, float max)
particleLifeMax = max;
}
void ParticleSystem::getParticleLife(float *min, float *max) const
{
if (min)
*min = particleLifeMin;
if (max)
*max = particleLifeMax;
}
void ParticleSystem::setPosition(float x, float y)
{
position = love::Vector(x, y);
}
const love::Vector &ParticleSystem::getPosition() const
{
return position;
}
float ParticleSystem::getX() const
{
return position.getX();
}
float ParticleSystem::getY() const
{
return position.getY();
}
void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y)
{
@@ -254,21 +296,46 @@ void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x,
areaSpreadDistribution = distribution;
}
ParticleSystem::AreaSpreadDistribution ParticleSystem::getAreaSpreadDistribution() const
{
return areaSpreadDistribution;
}
const love::Vector &ParticleSystem::getAreaSpreadParameters() const
{
return areaSpread;
}
void ParticleSystem::setDirection(float direction)
{
this->direction = direction;
}
float ParticleSystem::getDirection() const
{
return direction;
}
void ParticleSystem::setSpread(float spread)
{
this->spread = spread;
}
float ParticleSystem::getSpread() const
{
return spread;
}
void ParticleSystem::setRelativeDirection(bool relative)
{
this->relative = relative;
}
bool ParticleSystem::isRelativeDirection() const
{
return relative;
}
void ParticleSystem::setSpeed(float speed)
{
speedMin = speedMax = speed;
@@ -280,6 +347,14 @@ void ParticleSystem::setSpeed(float min, float max)
speedMax = max;
}
void ParticleSystem::getSpeed(float *min, float *max) const
{
if (min)
*min = speedMin;
if (max)
*max = speedMax;
}
void ParticleSystem::setGravity(float gravity)
{
gravityMin = gravityMax = gravity;
@@ -291,6 +366,14 @@ void ParticleSystem::setGravity(float min, float max)
gravityMax = max;
}
void ParticleSystem::getGravity(float *min, float *max) const
{
if (min)
*min = gravityMin;
if (max)
*max = gravityMax;
}
void ParticleSystem::setRadialAcceleration(float acceleration)
{
radialAccelerationMin = radialAccelerationMax = acceleration;
@@ -302,6 +385,14 @@ void ParticleSystem::setRadialAcceleration(float min, float max)
radialAccelerationMax = max;
}
void ParticleSystem::getRadialAcceleration(float *min, float *max) const
{
if (min)
*min = radialAccelerationMin;
if (max)
*max = radialAccelerationMax;
}
void ParticleSystem::setTangentialAcceleration(float acceleration)
{
tangentialAccelerationMin = tangentialAccelerationMax = acceleration;
@@ -313,6 +404,14 @@ void ParticleSystem::setTangentialAcceleration(float min, float max)
tangentialAccelerationMax = max;
}
void ParticleSystem::getTangentialAcceleration(float *min, float *max) const
{
if (min)
*min = tangentialAccelerationMin;
if (max)
*max = tangentialAccelerationMax;
}
void ParticleSystem::setSize(float size)
{
sizes.resize(1);
@@ -325,11 +424,21 @@ void ParticleSystem::setSize(const std::vector<float> &newSizes, float variation
sizeVariation = variation;
}
const std::vector<float> &ParticleSystem::getSize() const
{
return sizes;
}
void ParticleSystem::setSizeVariation(float variation)
{
sizeVariation = variation;
}
float ParticleSystem::getSizeVariation() const
{
return sizeVariation;
}
void ParticleSystem::setRotation(float rotation)
{
rotationMin = rotationMax = rotation;
@@ -341,6 +450,14 @@ void ParticleSystem::setRotation(float min, float max)
rotationMax = max;
}
void ParticleSystem::getRotation(float *min, float *max) const
{
if (min)
*min = rotationMin;
if (max)
*max = rotationMax;
}
void ParticleSystem::setSpin(float spin)
{
spinStart = spin;
@@ -360,11 +477,35 @@ void ParticleSystem::setSpin(float start, float end, float variation)
spinVariation = variation;
}
void ParticleSystem::getSpin(float *start, float *end) const
{
if (start)
*start = spinStart;
if (end)
*end = spinEnd;
}
void ParticleSystem::setSpinVariation(float variation)
{
spinVariation = variation;
}
float ParticleSystem::getSpinVariation() const
{
return spinVariation;
}
void ParticleSystem::setOffset(float x, float y)
{
offsetX = x;
offsetY = y;
}
love::Vector ParticleSystem::getOffset() const
{
return love::Vector(offsetX, offsetY);
}
void ParticleSystem::setColor(const Color &color)
{
colors.resize(1);
@@ -378,6 +519,17 @@ void ParticleSystem::setColor(const std::vector<Color> &newColors)
colors[i] = colorToFloat(newColors[i]);
}
std::vector<Color> ParticleSystem::getColor() const
{
// We store colors as floats...
std::vector<Color> ncolors(colors.size());
for (size_t i = 0; i < colors.size(); ++i)
ncolors[i] = Color(colors[i].r, colors[i].g, colors[i].b, colors[i].a);
return ncolors;
}
void ParticleSystem::setQuads(const std::vector<Quad *> &newQuads)
{
for (size_t i = 0; i < quads.size(); i++)
@@ -400,55 +552,9 @@ void ParticleSystem::setQuads()
quads.resize(0);
}
void ParticleSystem::setOffset(float x, float y)
const std::vector<Quad *> &ParticleSystem::getQuads() const
{
offsetX = x;
offsetY = y;
}
float ParticleSystem::getX() const
{
return position.getX();
}
float ParticleSystem::getY() const
{
return position.getY();
}
const love::Vector &ParticleSystem::getPosition() const
{
return position;
}
ParticleSystem::AreaSpreadDistribution ParticleSystem::getAreaSpreadDistribution() const
{
return areaSpreadDistribution;
}
const love::Vector &ParticleSystem::getAreaSpreadParameters() const
{
return areaSpread;
}
float ParticleSystem::getDirection() const
{
return direction;
}
float ParticleSystem::getSpread() const
{
return spread;
}
float ParticleSystem::getOffsetX() const
{
return offsetX;
}
float ParticleSystem::getOffsetY() const
{
return offsetY;
return quads;
}
int ParticleSystem::count() const
@@ -511,7 +617,7 @@ bool ParticleSystem::isFull() const
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
if (sprite == 0) return; // just in case of failure
if (image == 0) return; // just in case of failure
int numParticles = count();
if (numParticles == 0) return; // don't bother if there's nothing to do
@@ -524,7 +630,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
glMultMatrixf((const GLfloat *)t.getElements());
const vertex *imageVerts = sprite->getVertices();
const vertex *imageVerts = image->getVertices();
const vertex *tVerts;
size_t numQuads = quads.size();
@@ -543,7 +649,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
else
tVerts = imageVerts;
// particle vertices are sprite vertices transformed by particle information
// particle vertices are image vertices transformed by particle information
t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
t.transform(&particleVerts[i*4], &tVerts[0], 4);
@@ -563,7 +669,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
}
}
sprite->bind();
image->bind();
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
+153 -57
View File
@@ -87,9 +87,9 @@ public:
};
/**
* Creates a particle system with the specified buffersize and sprite.
* Creates a particle system with the specified buffersize and image.
**/
ParticleSystem(Image *sprite, unsigned int buffer);
ParticleSystem(Image *image, unsigned int buffer);
/**
* Deletes any allocated memory.
@@ -97,10 +97,15 @@ public:
virtual ~ParticleSystem();
/**
* Sets the sprite used in the particle system.
* @param sprite The new sprite.
* Sets the image used in the particle system.
* @param image The new image.
**/
void setSprite(Image *image);
void setImage(Image *image);
/**
* Returns the image used when drawing the particle system.
**/
Image *getImage() const;
/**
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
@@ -108,18 +113,34 @@ public:
**/
void setBufferSize(unsigned int size);
/**
* Returns the total amount of particles this ParticleSystem can have active
* at any given point in time.
**/
int getBufferSize() const;
/**
* Sets the emission rate.
* @param rate The amount of particles per second.
**/
void setEmissionRate(int rate);
/**
* Returns the number of particles created per second.
**/
int getEmissionRate() const;
/**
* Sets the lifetime of the particle emitter (-1 means eternal)
* @param life The lifetime (in seconds).
**/
void setLifetime(float life);
/**
* Returns the lifetime of the particle emitter.
**/
float getLifetime() const;
/**
* Sets the life range of the particles.
* @param lifeMin The minimum life.
@@ -127,6 +148,13 @@ public:
**/
void setParticleLife(float min, float max = 0);
/**
* Gets the lifetime of a particle.
* @param[out] min
* @param[out] max
**/
void getParticleLife(float *min, float *max) const;
/**
* Sets the position of the center of the emitter and the direction (if set to relative).
* Used to move the emitter without changing the position of already existing particles.
@@ -135,6 +163,21 @@ public:
**/
void setPosition(float x, float y);
/**
* Returns the position of the emitter.
**/
const love::Vector &getPosition() const;
/**
* Returns the x-coordinate of the emitter's position.
**/
float getX() const;
/**
* Returns the y-coordinate of the emitter's position.
**/
float getY() const;
/**
* Sets the emission area spread parameters and distribution type. The interpretation of
* the parameters depends on the distribution type:
@@ -145,27 +188,53 @@ public:
* @param x First parameter. Interpretation depends on distribution type.
* @param y Second parameter. Interpretation depends on distribution type.
* @param distribution Distribution type
* */
**/
void setAreaSpread(AreaSpreadDistribution distribution, float x, float y);
/**
* Sets the direction and the spread of the particle emitter.
* Returns area spread distribution type.
**/
AreaSpreadDistribution getAreaSpreadDistribution() const;
/**
* Returns area spread parameters.
**/
const love::Vector &getAreaSpreadParameters() const;
/**
* Sets the direction of the particle emitter.
* @param direction The direction (in degrees).
**/
void setDirection(float direction);
/**
* Returns the direction of the particle emitter (in radians).
**/
float getDirection() const;
/**
* Sets the spread of the particle emitter.
* @param spread The spread (in degrees).
* @param spread The spread (in radians).
**/
void setSpread(float spread);
/**
* Sets whether the direction should be relative to the particle emitters movement. Used in conjunction with setPosition.
* Returns the directional spread of the emitter (in radians).
**/
float getSpread() const;
/**
* Sets whether the direction should be relative to the particle emitter's movement. Used in conjunction with setPosition.
* @param relative Whether to have relative direction.
**/
void setRelativeDirection(bool relative);
/**
* Returns whether the direction is relative to the particle emitter's
* movement.
**/
bool isRelativeDirection() const;
/**
* Sets the speed of the particles.
* @param speed The speed.
@@ -179,6 +248,13 @@ public:
**/
void setSpeed(float min, float max);
/**
* Gets the speed of the particles.
* @param[out] min
* @param[out] max
**/
void getSpeed(float *min, float *max) const;
/**
* Sets the gravity of the particles (the acceleration along the y-axis).
* @param gravity The amount of gravity.
@@ -192,6 +268,13 @@ public:
**/
void setGravity(float min, float max);
/**
* Gets the gravity (y-axis acceleration) of the particles.
* @param[out] min
* @param[out] max
**/
void getGravity(float *min, float *max) const;
/**
* Sets the radial acceleration (the acceleration towards the particle emitter).
* @param acceleration The amount of acceleration.
@@ -205,6 +288,13 @@ public:
**/
void setRadialAcceleration(float min, float max);
/**
* Gets the radial acceleration.
* @param[out] min
* @param[out] max
**/
void getRadialAcceleration(float *min, float *max) const;
/**
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
* @param acceleration The amount of acceleration.
@@ -218,6 +308,13 @@ public:
**/
void setTangentialAcceleration(float min, float max);
/**
* Gets the tangential acceleration.
* @param[out] min
* @param[out] max
**/
void getTangentialAcceleration(float *min, float *max) const;
/**
* Sets the size of the sprite (1.0 being the default size).
* @param size The size of the sprite.
@@ -231,12 +328,22 @@ public:
**/
void setSize(const std::vector<float> &newSizes, float variation = 0.0f);
/**
* Returns the size of the particle sprites.
**/
const std::vector<float> &getSize() const;
/**
* Sets the amount of variation to the sprite's beginning size (0 being no variation and 1.0 a random size between start and end).
* @param variation The amount of variation.
**/
void setSizeVariation(float variation);
/**
* Returns the amount of initial size variation between particles.
**/
float getSizeVariation() const;
/**
* Sets the amount of rotation a sprite starts out with.
* @param rotation The amount of rotation.
@@ -250,6 +357,13 @@ public:
**/
void setRotation(float min, float max);
/**
* Gets the initial amount of rotation of a particle.
* @param[out] min
* @param[out] max
**/
void getRotation(float *min, float *max) const;
/**
* Sets the spin of the sprite.
* @param spin The spin of the sprite (in degrees).
@@ -272,16 +386,22 @@ public:
void setSpin(float start, float end, float variation);
/**
* Sets the variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
* Gets the amount of spin of a particle during its lifetime.
* @param[out] start
* @param[out] end
**/
void getSpin(float *start, float *end) const;
/**
* Sets the variation of the start spin (0 being no variation and 1 being a random spin between start and end).
* @param variation The variation in degrees.
**/
void setSpinVariation(float variation);
/**
* Sets the color of the particles.
* @param color The color.
* Returns the amount of variation of the start spin of a particle.
**/
void setColor(const Color &color);
float getSpinVariation() const;
/**
* Sets the particles' offsets for rotation.
@@ -290,12 +410,28 @@ public:
**/
void setOffset(float x, float y);
/**
* Returns of the particle offset.
**/
love::Vector getOffset() const;
/**
* Sets the color of the particles.
* @param color The color.
**/
void setColor(const Color &color);
/**
* Sets the color of the particles.
* @param newColors Array of colors
**/
void setColor(const std::vector<Color> &newColors);
/**
* Returns the color of the particles.
**/
std::vector<Color> getColor() const;
/**
* Sets the quads used when drawing the particles.
* @param newQuads Array of quads.
@@ -308,49 +444,9 @@ public:
void setQuads();
/**
* Returns the x-coordinate of the emitter's position.
* Returns the list of quads used when drawing the particles.
**/
float getX() const;
/**
* Returns the y-coordinate of the emitter's position.
**/
float getY() const;
/**
* Returns the position of the emitter.
**/
const love::Vector &getPosition() const;
/**
* Returns area spread distribution type.
*/
AreaSpreadDistribution getAreaSpreadDistribution() const;
/**
* Returns area spread parameters.
*/
const love::Vector &getAreaSpreadParameters() const;
/**
* Returns the direction of the emitter (in degrees).
**/
float getDirection() const;
/**
* Returns the directional spread of the emitter (in degrees).
**/
float getSpread() const;
/**
* Returns the X offset of the particles.
**/
float getOffsetX() const;
/**
* Returns the Y offset of the particles.
**/
float getOffsetY() const;
const std::vector<Quad *> &getQuads() const;
/**
* Returns the amount of particles that are currently active in the system.
@@ -430,8 +526,8 @@ protected:
// array of transformed vertex data for all particles, for drawing
vertex * particleVerts;
// The sprite to be drawn.
Image *sprite;
// The image to be drawn.
Image *image;
// Whether the particle emitter is active.
bool active;
@@ -37,14 +37,23 @@ ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
}
int w_ParticleSystem_setSprite(lua_State *L)
int w_ParticleSystem_setImage(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
Image *i = luax_checkimage(L, 2);
t->setSprite(i);
t->setImage(i);
return 0;
}
int w_ParticleSystem_getImage(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
Image *i = t->getImage();
i->retain();
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *) i);
return 1;
}
int w_ParticleSystem_setBufferSize(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -53,6 +62,13 @@ int w_ParticleSystem_setBufferSize(lua_State *L)
return 0;
}
int w_ParticleSystem_getBufferSize(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushinteger(L, t->getBufferSize());
return 1;
}
int w_ParticleSystem_setEmissionRate(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -61,6 +77,13 @@ int w_ParticleSystem_setEmissionRate(lua_State *L)
return 0;
}
int w_ParticleSystem_getEmissionRate(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushinteger(L, t->getEmissionRate());
return 1;
}
int w_ParticleSystem_setLifetime(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -69,6 +92,13 @@ int w_ParticleSystem_setLifetime(lua_State *L)
return 0;
}
int w_ParticleSystem_getLifetime(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getLifetime());
return 1;
}
int w_ParticleSystem_setParticleLife(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -78,6 +108,16 @@ int w_ParticleSystem_setParticleLife(lua_State *L)
return 0;
}
int w_ParticleSystem_getParticleLife(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getParticleLife(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setPosition(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -87,6 +127,29 @@ int w_ParticleSystem_setPosition(lua_State *L)
return 0;
}
int w_ParticleSystem_getPosition(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
love::Vector pos = t->getPosition();
lua_pushnumber(L, pos.getX());
lua_pushnumber(L, pos.getY());
return 2;
}
int w_ParticleSystem_getX(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getX());
return 1;
}
int w_ParticleSystem_getY(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getY());
return 1;
}
int w_ParticleSystem_setAreaSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -105,6 +168,21 @@ int w_ParticleSystem_setAreaSpread(lua_State *L)
return 0;
}
int w_ParticleSystem_getAreaSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
ParticleSystem::AreaSpreadDistribution distribution = t-> getAreaSpreadDistribution();
const char *str;
ParticleSystem::getConstant(distribution, str);
const love::Vector &p = t->getAreaSpreadParameters();
lua_pushstring(L, str);
lua_pushnumber(L, p.x);
lua_pushnumber(L, p.y);
return 3;
}
int w_ParticleSystem_setDirection(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -113,6 +191,13 @@ int w_ParticleSystem_setDirection(lua_State *L)
return 0;
}
int w_ParticleSystem_getDirection(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getDirection());
return 1;
}
int w_ParticleSystem_setSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -121,6 +206,13 @@ int w_ParticleSystem_setSpread(lua_State *L)
return 0;
}
int w_ParticleSystem_getSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getSpread());
return 1;
}
int w_ParticleSystem_setRelativeDirection(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -129,6 +221,13 @@ int w_ParticleSystem_setRelativeDirection(lua_State *L)
return 0;
}
int w_ParticleSystem_isRelativeDirection(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
luax_pushboolean(L, t->isRelativeDirection());
return 1;
}
int w_ParticleSystem_setSpeed(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -138,6 +237,16 @@ int w_ParticleSystem_setSpeed(lua_State *L)
return 0;
}
int w_ParticleSystem_getSpeed(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getSpeed(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setGravity(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -147,6 +256,16 @@ int w_ParticleSystem_setGravity(lua_State *L)
return 0;
}
int w_ParticleSystem_getGravity(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getGravity(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setRadialAcceleration(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -156,6 +275,16 @@ int w_ParticleSystem_setRadialAcceleration(lua_State *L)
return 0;
}
int w_ParticleSystem_getRadialAcceleration(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getRadialAcceleration(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setTangentialAcceleration(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -165,6 +294,16 @@ int w_ParticleSystem_setTangentialAcceleration(lua_State *L)
return 0;
}
int w_ParticleSystem_getTangentialAcceleration(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getTangentialAcceleration(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setSizes(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -189,6 +328,17 @@ int w_ParticleSystem_setSizes(lua_State *L)
return 0;
}
int w_ParticleSystem_getSizes(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
const std::vector<float> &sizes = t->getSize();
for (size_t i = 0; i < sizes.size(); i++)
lua_pushnumber(L, sizes[i]);
return sizes.size();
}
int w_ParticleSystem_setSizeVariation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -200,6 +350,13 @@ int w_ParticleSystem_setSizeVariation(lua_State *L)
return 0;
}
int w_ParticleSystem_getSizeVariation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getSizeVariation());
return 1;
}
int w_ParticleSystem_setRotation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -209,6 +366,16 @@ int w_ParticleSystem_setRotation(lua_State *L)
return 0;
}
int w_ParticleSystem_getRotation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float min, max;
t->getRotation(&min, &max);
lua_pushnumber(L, min);
lua_pushnumber(L, max);
return 2;
}
int w_ParticleSystem_setSpin(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -219,6 +386,16 @@ int w_ParticleSystem_setSpin(lua_State *L)
return 0;
}
int w_ParticleSystem_getSpin(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float start, end;
t->getSpin(&start, &end);
lua_pushnumber(L, start);
lua_pushnumber(L, end);
return 2;
}
int w_ParticleSystem_setSpinVariation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -227,6 +404,31 @@ int w_ParticleSystem_setSpinVariation(lua_State *L)
return 0;
}
int w_ParticleSystem_getSpinVariation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getSpinVariation());
return 1;
}
int w_ParticleSystem_setOffset(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setOffset(x, y);
return 0;
}
int w_ParticleSystem_getOffset(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
love::Vector offset = t->getOffset();
lua_pushnumber(L, offset.getX());
lua_pushnumber(L, offset.getY());
return 2;
}
int w_ParticleSystem_setColors(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -301,6 +503,29 @@ int w_ParticleSystem_setColors(lua_State *L)
return 0;
}
int w_ParticleSystem_getColors(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
const std::vector<Color> &colors =t->getColor();
for (size_t i = 0; i < colors.size(); i++)
{
lua_createtable(L, 4, 0);
lua_pushinteger(L, colors[i].r);
lua_rawseti(L, -2, 1);
lua_pushinteger(L, colors[i].g);
lua_rawseti(L, -2, 2);
lua_pushinteger(L, colors[i].b);
lua_rawseti(L, -2, 3);
lua_pushinteger(L, colors[i].a);
lua_rawseti(L, -2, 4);
}
return colors.size();
}
int w_ParticleSystem_setQuads(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -338,79 +563,19 @@ int w_ParticleSystem_setQuads(lua_State *L)
return 0;
}
int w_ParticleSystem_setOffset(lua_State *L)
int w_ParticleSystem_getQuads(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setOffset(x, y);
return 0;
}
int w_ParticleSystem_getX(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getX());
return 1;
}
const std::vector<Quad *> &quads = t->getQuads();
int w_ParticleSystem_getY(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getY());
return 1;
}
for (size_t i = 0; i < quads.size(); i++)
{
quads[i]->retain();
luax_newtype(L, "Quad", GRAPHICS_QUAD_T, (void *) quads[i]);
}
int w_ParticleSystem_getPosition(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
const love::Vector &p = t->getPosition();
lua_pushnumber(L, p.x);
lua_pushnumber(L, p.y);
return 2;
}
int w_ParticleSystem_getAreaSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
ParticleSystem::AreaSpreadDistribution distribution = t-> getAreaSpreadDistribution();
const char *str;
ParticleSystem::getConstant(distribution, str);
const love::Vector &p = t->getAreaSpreadParameters();
lua_pushstring(L, str);
lua_pushnumber(L, p.x);
lua_pushnumber(L, p.y);
return 3;
}
int w_ParticleSystem_getDirection(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getDirection());
return 1;
}
int w_ParticleSystem_getSpread(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getSpread());
return 1;
}
int w_ParticleSystem_getOffsetX(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getOffsetX());
return 1;
}
int w_ParticleSystem_getOffsetY(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getOffsetY());
return 1;
return quads.size();
}
int w_ParticleSystem_count(lua_State *L)
@@ -487,36 +652,52 @@ int w_ParticleSystem_update(lua_State *L)
static const luaL_Reg functions[] =
{
{ "setSprite", w_ParticleSystem_setSprite },
{ "setImage", w_ParticleSystem_setImage },
{ "getImage", w_ParticleSystem_getImage },
{ "setBufferSize", w_ParticleSystem_setBufferSize },
{ "getBufferSize", w_ParticleSystem_getBufferSize },
{ "setEmissionRate", w_ParticleSystem_setEmissionRate },
{ "getEmissionRate", w_ParticleSystem_getEmissionRate },
{ "setLifetime", w_ParticleSystem_setLifetime },
{ "getLifetime", w_ParticleSystem_getLifetime },
{ "setParticleLife", w_ParticleSystem_setParticleLife },
{ "getParticleLife", w_ParticleSystem_getParticleLife },
{ "setPosition", w_ParticleSystem_setPosition },
{ "setAreaSpread", w_ParticleSystem_setAreaSpread },
{ "setDirection", w_ParticleSystem_setDirection },
{ "setSpread", w_ParticleSystem_setSpread },
{ "setRelativeDirection", w_ParticleSystem_setRelativeDirection },
{ "setSpeed", w_ParticleSystem_setSpeed },
{ "setGravity", w_ParticleSystem_setGravity },
{ "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
{ "setSizes", w_ParticleSystem_setSizes },
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
{ "setRotation", w_ParticleSystem_setRotation },
{ "setSpin", w_ParticleSystem_setSpin },
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
{ "setColors", w_ParticleSystem_setColors },
{ "setQuads", w_ParticleSystem_setQuads },
{ "setOffset", w_ParticleSystem_setOffset },
{ "getPosition", w_ParticleSystem_getPosition },
{ "getX", w_ParticleSystem_getX },
{ "getY", w_ParticleSystem_getY },
{ "getPosition", w_ParticleSystem_getPosition },
{ "setAreaSpread", w_ParticleSystem_setAreaSpread },
{ "getAreaSpread", w_ParticleSystem_getAreaSpread },
{ "setDirection", w_ParticleSystem_setDirection },
{ "getDirection", w_ParticleSystem_getDirection },
{ "setSpread", w_ParticleSystem_setSpread },
{ "getSpread", w_ParticleSystem_getSpread },
{ "getOffsetX", w_ParticleSystem_getOffsetX },
{ "getOffsetY", w_ParticleSystem_getOffsetY },
{ "setRelativeDirection", w_ParticleSystem_setRelativeDirection },
{ "isRelativeDirection", w_ParticleSystem_isRelativeDirection },
{ "setSpeed", w_ParticleSystem_setSpeed },
{ "getSpeed", w_ParticleSystem_getSpeed },
{ "setGravity", w_ParticleSystem_setGravity },
{ "getGravity", w_ParticleSystem_getGravity },
{ "setRadialAcceleration", w_ParticleSystem_setRadialAcceleration },
{ "getRadialAcceleration", w_ParticleSystem_getRadialAcceleration },
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
{ "getTangentialAcceleration", w_ParticleSystem_getTangentialAcceleration },
{ "setSizes", w_ParticleSystem_setSizes },
{ "getSizes", w_ParticleSystem_getSizes },
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
{ "getSizeVariation", w_ParticleSystem_getSizeVariation },
{ "setRotation", w_ParticleSystem_setRotation },
{ "getRotation", w_ParticleSystem_getRotation },
{ "setSpin", w_ParticleSystem_setSpin },
{ "getSpin", w_ParticleSystem_getSpin },
{ "setSpinVariation", w_ParticleSystem_setSpinVariation },
{ "getSpinVariation", w_ParticleSystem_getSpinVariation },
{ "setColors", w_ParticleSystem_setColors },
{ "getColors", w_ParticleSystem_getColors },
{ "setQuads", w_ParticleSystem_setQuads },
{ "getQuads", w_ParticleSystem_getQuads },
{ "setOffset", w_ParticleSystem_setOffset },
{ "getOffset", w_ParticleSystem_getOffset },
{ "count", w_ParticleSystem_count },
{ "start", w_ParticleSystem_start },
{ "stop", w_ParticleSystem_stop },
@@ -34,36 +34,52 @@ namespace opengl
{
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx);
int w_ParticleSystem_setSprite(lua_State *L);
int w_ParticleSystem_setImage(lua_State *L);
int w_ParticleSystem_getImage(lua_State *L);
int w_ParticleSystem_setBufferSize(lua_State *L);
int w_ParticleSystem_getBufferSize(lua_State *L);
int w_ParticleSystem_setEmissionRate(lua_State *L);
int w_ParticleSystem_getEmissionRate(lua_State *L);
int w_ParticleSystem_setLifetime(lua_State *L);
int w_ParticleSystem_getLifetime(lua_State *L);
int w_ParticleSystem_setParticleLife(lua_State *L);
int w_ParticleSystem_getParticleLife(lua_State *L);
int w_ParticleSystem_setPosition(lua_State *L);
int w_ParticleSystem_setAreaSpread(lua_State *L);
int w_ParticleSystem_setDirection(lua_State *L);
int w_ParticleSystem_setSpread(lua_State *L);
int w_ParticleSystem_setRelativeDirection(lua_State *L);
int w_ParticleSystem_setSpeed(lua_State *L);
int w_ParticleSystem_setGravity(lua_State *L);
int w_ParticleSystem_setRadialAcceleration(lua_State *L);
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
int w_ParticleSystem_setSizes(lua_State *L);
int w_ParticleSystem_setSizeVariation(lua_State *L);
int w_ParticleSystem_setRotation(lua_State *L);
int w_ParticleSystem_setSpin(lua_State *L);
int w_ParticleSystem_setSpinVariation(lua_State *L);
int w_ParticleSystem_setColors(lua_State *L);
int w_ParticleSystem_setQuads(lua_State *L);
int w_ParticleSystem_setOffset(lua_State *L);
int w_ParticleSystem_getPosition(lua_State *L);
int w_ParticleSystem_getX(lua_State *L);
int w_ParticleSystem_getY(lua_State *L);
int w_ParticleSystem_getPosition(lua_State *L);
int w_ParticleSystem_setAreaSpread(lua_State *L);
int w_ParticleSystem_getAreaSpread(lua_State *L);
int w_ParticleSystem_setDirection(lua_State *L);
int w_ParticleSystem_getDirection(lua_State *L);
int w_ParticleSystem_setSpread(lua_State *L);
int w_ParticleSystem_getSpread(lua_State *L);
int w_ParticleSystem_getOffsetX(lua_State *L);
int w_ParticleSystem_getOffsetY(lua_State *L);
int w_ParticleSystem_setRelativeDirection(lua_State *L);
int w_ParticleSystem_isRelativeDirection(lua_State *L);
int w_ParticleSystem_setSpeed(lua_State *L);
int w_ParticleSystem_getSpeed(lua_State *L);
int w_ParticleSystem_setGravity(lua_State *L);
int w_ParticleSystem_getGravity(lua_State *L);
int w_ParticleSystem_setRadialAcceleration(lua_State *L);
int w_ParticleSystem_getRadialAcceleration(lua_State *L);
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
int w_ParticleSystem_getTangentialAcceleration(lua_State *L);
int w_ParticleSystem_setSizes(lua_State *L);
int w_ParticleSystem_getSizes(lua_State *L);
int w_ParticleSystem_setSizeVariation(lua_State *L);
int w_ParticleSystem_getSizeVariation(lua_State *L);
int w_ParticleSystem_setRotation(lua_State *L);
int w_ParticleSystem_getRotation(lua_State *L);
int w_ParticleSystem_setSpin(lua_State *L);
int w_ParticleSystem_getSpin(lua_State *L);
int w_ParticleSystem_setSpinVariation(lua_State *L);
int w_ParticleSystem_getSpinVariation(lua_State *L);
int w_ParticleSystem_setColors(lua_State *L);
int w_ParticleSystem_getColors(lua_State *L);
int w_ParticleSystem_setQuads(lua_State *L);
int w_ParticleSystem_getQuads(lua_State *L);
int w_ParticleSystem_setOffset(lua_State *L);
int w_ParticleSystem_getOffset(lua_State *L);
int w_ParticleSystem_count(lua_State *L);
int w_ParticleSystem_start(lua_State *L);
int w_ParticleSystem_stop(lua_State *L);