mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
Add ability to introspect the Particle struct
This commit is contained in:
@@ -25,6 +25,22 @@ class Renderer;
|
|||||||
class Gravity;
|
class Gravity;
|
||||||
class Air;
|
class Air;
|
||||||
|
|
||||||
|
//Describes fields in structures such as Particle or Element
|
||||||
|
struct StructProperty
|
||||||
|
{
|
||||||
|
enum PropertyType { ParticleType, Colour, Integer, UInteger, Float, String };
|
||||||
|
std::string Name;
|
||||||
|
PropertyType Type;
|
||||||
|
intptr_t Offset;
|
||||||
|
StructProperty(std::string name, PropertyType type, intptr_t offset):
|
||||||
|
Name(name),
|
||||||
|
Type(type),
|
||||||
|
Offset(offset)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Particle
|
struct Particle
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
@@ -36,6 +52,25 @@ struct Particle
|
|||||||
int tmp;
|
int tmp;
|
||||||
int tmp2;
|
int tmp2;
|
||||||
unsigned int dcolour;
|
unsigned int dcolour;
|
||||||
|
/** Returns a list of properties, their type and offset within the structure that can be changed
|
||||||
|
by higher-level processes refering to them by name such as Lua or the property tool **/
|
||||||
|
std::vector<StructProperty> GetProperties()
|
||||||
|
{
|
||||||
|
std::vector<StructProperty> properties;
|
||||||
|
properties.push_back(StructProperty("type", StructProperty::ParticleType, offsetof(Particle, type)));
|
||||||
|
properties.push_back(StructProperty("life", StructProperty::ParticleType, offsetof(Particle, life)));
|
||||||
|
properties.push_back(StructProperty("ctype", StructProperty::ParticleType, offsetof(Particle, ctype)));
|
||||||
|
properties.push_back(StructProperty("x", StructProperty::Float, offsetof(Particle, x)));
|
||||||
|
properties.push_back(StructProperty("y", StructProperty::Float, offsetof(Particle, y)));
|
||||||
|
properties.push_back(StructProperty("vx", StructProperty::Float, offsetof(Particle, vx)));
|
||||||
|
properties.push_back(StructProperty("vy", StructProperty::Float, offsetof(Particle, vy)));
|
||||||
|
properties.push_back(StructProperty("temp", StructProperty::Float, offsetof(Particle, temp)));
|
||||||
|
properties.push_back(StructProperty("flags", StructProperty::UInteger, offsetof(Particle, flags)));
|
||||||
|
properties.push_back(StructProperty("tmp", StructProperty::Integer, offsetof(Particle, tmp)));
|
||||||
|
properties.push_back(StructProperty("tmp2", StructProperty::Integer, offsetof(Particle, tmp2)));
|
||||||
|
properties.push_back(StructProperty("dcolour", StructProperty::UInteger, offsetof(Particle, dcolour)));
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
typedef struct Particle Particle;
|
typedef struct Particle Particle;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user