「利用者:Phonybone/Archive/Modular particle system/Particle properties」の版間の差分

提供: wiki
移動先: 案内検索
 
(1版 をインポートしました)
 
(相違点なし)

2018年6月29日 (金) 04:37時点における最新版

Particle Properties

The data making up each particle should only be allocated when necessary. Some properties like location and velocity are used in almost all modules, but for things like color, temperature, boids information, etc. a custom data registration mechanism must be implemented.

The base ParticleData struct only contains a few variables needed by the generic particle system's "business logic":

typedef struct ParticleData {
    float birthtime;
    ...                  /* TODO what data does the system always need? */
} ParticleData;

The particle settings store a list of descriptions of the currently available particle properties:

typedef struct ParticleProperty {
    char name[32];       /* name of the property used as ID */
    int size;            /* size in bytes to correctly allocate the buffers */
    int offset;          /* offset of this property in the buffer */
} ParticleProperty;

typedef struct ParticleSettings {
    ...
    ParticleProperty *properties; /* Array of registered properties */
    int num_properties;           /* Number of registered properties */
    int totpropsize;              /* Accumulated size of all properties */
    ...
} ParticleSettings;
to do

 How can the RNA for particle properties be created? Should they include some runtime type information? Would it be feasible to use a StructRNA at registration to determine the property size, etc. and do checks on this if it already exists?

to do

 In its raw form, this kind of type-less buffer would force the module writers to do pointer arithmetic and explicit casts from void* to the actual data type of the property all the time, which would easily lead to bugs and corrupt particle buffers. To avoid this, a convenient way of assigning particle data to typed pointers can be implemented. The module would simply store a couple of typed pointer pointers in a list and hand it over to a particle system function, which then assigns the correct address. Make an example!


The particle buffer is allocated using the accumulated size of ParticleData + the registered properties:

Chunks
For simplicity the following example does not use the chunk principle yet.


typedef struct ParticleSystem {
    ...
    ParticleSettings *part;  /* Settings pointer */
    ParticleData *particles; /* Main particle buffer */
    ...
} ParticleSystem;
...
void psys_allocate_particles(ParticleSystem *psys, int totpart)
{
    ...
    MEM_callocN(psys->particles, (sizeof(ParticleData) + part->totpropsize) * totpart);
    ...
}