summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Bosveld <joel@joel-desktop.(none)>2008-01-21 20:03:35 +0900
committerJoel Bosveld <joel@joel-desktop.(none)>2008-01-21 20:03:35 +0900
commit91e86743ed315e00a007239d4646beb56de06a59 (patch)
tree4dbea5dceb7ec0e3cc42bfc951c431fbec09053c
parente027fbc8611de9b57983579012e484f4423f41cd (diff)
downloadcubedbus-91e86743ed315e00a007239d4646beb56de06a59.tar.gz
cubedbus-91e86743ed315e00a007239d4646beb56de06a59.tar.bz2
Some work on emitters, to properly create particles
-rw-r--r--particleFx/emitter.c.in55
-rw-r--r--particleFx/particleFxPrework52
2 files changed, 104 insertions, 3 deletions
diff --git a/particleFx/emitter.c.in b/particleFx/emitter.c.in
index 444739e..3eb096b 100644
--- a/particleFx/emitter.c.in
+++ b/particleFx/emitter.c.in
@@ -26,6 +26,61 @@ static CompFxParticle
return emitter->tail;
}
+static void
+compFxParticleInitiate (CompFxParticle *particle, CompFxParticleEmitterParticleDataInfo *data)
+{
+ int i,i2;
+
+ particle->compFxParticleDrawProc=data->compFxParticleDrawProc;
+ particle->compFxParticleMoveProc=data->compFxParticleMoveProc;
+ particle->compFxParticleDeathProc=data->compFxParticleDeathProc;
+
+ particle->nDataSets=data->nDataSets;
+ particle->dataSets = malloc (sizeof (CompFxParticleDataSet) * particle->nDataSets);
+ if(particle->dataSets == NULL) /* XXX error XXX */
+
+ for(i=0; i < particle->nDataSets;i++)
+ {
+ particle->dataSets[i].name=data->dataSets[i].name;
+ particle->dataSets[i].data= malloc (sizeof (CompFxParticleData) * data->dataSets[i].nData);
+ if(particle->dataSets[i].data == NULL) /* XXX error XXX */
+
+ for(i2=0; i2 < data->dataSets[i].nData;i2++)
+ {
+ (data->dataSets[i].data[i2].compFxParticleEmitterAddDataProc) ( &(particle->dataSets[i].data[i2]), &(data->dataSets[i].data[i2]));
+ }
+ }
+}
+
+/* the data pointer under emitterData should point to a typedef'd union of type CompFxParticleData */
+
+static void
+compFxParticleEmitterAddDataStandard (CompFxParticleData *particleData, CompFxParticleEmitterParticleData *emitterData)
+{
+ memcpy(particleData, emitterData->data, sizeof( CompFxParticleData));
+}
+
+/* Softcoded step function to create particles for an emitter - also for testing */
+
+static void
+compFxParticleCreateEmitterSoft (CompFxParticleEmitter *emitter)
+{
+ CompFxParticle *particle = NULL;
+
+ if(emitter->nParticles >= 1000) /* XXX should be a variable in emitter */
+ {
+ }
+ else if( (particle = compFxParticleCreate (emitter)) == NULL) /* this function sets up the emitter, next, and prev fields */
+ {
+ compLogMessage (NULL, "particleFX", CompLogLevelWarn, "Creating particle failed - memory error");
+ }
+ else
+ {
+ emitter->nParticles++;
+ compFxParticleInitiate (particle, &(emitter->particleInfo[0]));
+ }
+}
+
/* Hardcoded emitter - XXX - for testing only */
static void
compFxParticleCreateEmitterColour (CompFxParticleEmitter *emitter)
diff --git a/particleFx/particleFxPrework b/particleFx/particleFxPrework
index 6b23f98..3392385 100644
--- a/particleFx/particleFxPrework
+++ b/particleFx/particleFxPrework
@@ -4,10 +4,14 @@ typedef struct _CompFxParticle CompFxParticle;
typedef struct _CompFxParticleEmitter CompFxParticleEmitter;
typedef struct _CompFxParticleDataSet CompFxParticleDataSet;
typedef union _CompFxParticleData CompFxParticleData;
+typedef struct _CompFxParticleEmitterParticleDataSet CompFxParticleEmitterParticleDataSet;
+typedef struct _CompFxParticleEmitterParticleData CompFxParticleEmitterParticleData;
+typedef struct _CompFxParticleEmitterParticleDataInfo CompFxParticleEmitterParticleDataInfo;
+typedef enum _CompFxParticleDataType CompFxParticleDataType;
static CompFxParticleDataSet *compFxParticleFindDataSet (char *name, CompFxParticle *particle, int start);
-/* Structs for particle system */
+/* Structs for particles */
union _CompFxParticleData
{
@@ -16,7 +20,7 @@ union _CompFxParticleData
long l;
float f;
double d;
- void *p; /* if you use pointers in here do not expect it to be freed, you must create and destroy data using the emitter (and it should be per emitter not particle)*/
+ void *p; /*if you use pointers in here do not expect it to be freed, you must create and destroy data using the emitter (and it should be per emitter not particle)*/
};
struct _CompFxParticleDataSet
@@ -31,7 +35,7 @@ struct _CompFxParticle
CompFxParticle *next;
CompFxParticle *prev;
-
+
void (*compFxParticleDrawProc) (CompFxParticle *particle);
void (*compFxParticleMoveProc) (CompFxParticle *particle);
void (*compFxParticleDeathProc) (CompFxParticle *particle);
@@ -40,6 +44,44 @@ struct _CompFxParticle
int nDataSets;
};
+/* structs for emitters */
+
+enum _CompFxParticleDataType
+{
+ CompFxParticleDataTypeInt,
+ CompFxParticleDataTypeFloat,
+ CompFxParticleDataTypeUnsigned,
+ CompFxParticleDataTypePointer,
+ CompFxParticleDataTypeLong,
+ CompFxParticleDataTypeDouble
+};
+
+struct _CompFxParticleEmitterParticleData
+{
+ CompFxParticleDataType type;
+ void (*compFxParticleEmitterAddDataProc) (CompFxParticleData *particleData, CompFxParticleEmitterParticleData *emitterData);
+ void *data;
+};
+
+struct _CompFxParticleEmitterParticleDataSet
+{
+ char *name;
+ CompFxParticleEmitterParticleData *data; /* array containing data union */
+ int nData;
+};
+
+struct _CompFxParticleEmitterParticleDataInfo
+{
+ char *name;
+
+ void (*compFxParticleDrawProc) (CompFxParticle *particle);
+ void (*compFxParticleMoveProc) (CompFxParticle *particle);
+ void (*compFxParticleDeathProc) (CompFxParticle *particle);
+
+ CompFxParticleEmitterParticleDataSet *dataSets; /* array of datasets */
+ int nDataSets;
+};
+
struct _CompFxParticleEmitter
{
CompFxParticleEmitter *next;
@@ -50,7 +92,11 @@ struct _CompFxParticleEmitter
int nParticles;
+ CompFxParticleEmitterParticleDataInfo *particleInfo; /* array of info needed to create particles */
+ int nParticleInfo;
+
void (*compFxParticleEmitterStepProc) (CompFxParticleEmitter *emitter); /* This is where we create particles */
+ void *stepData; /* pointer for extra data to be used by step function if necessary */
};
/***********************************************************/