void update(Particles *uemitter, Particle* part, int partNumber) { Particles uemit = *uemitter; Uint32 timeElapsed; Uint32 curr = getMilliCount(); timeElapsed = curr - uemit.m_lastRender; //printf("get -elapsed %d emitter last render %d\n", timeElapsed, emitter->m_lastRender); uemit.particles[partNumber].m_age += timeElapsed; if (!isAlive(&(uemit.particles[partNumber]))) { printf("Dead\n"); //printf( "age %u timedie %u\n", part->m_age, part->m_timeDie); // smoke eventually dies /*if (r01() > emitter.m_dieRate) { part->m_canRegen = FALSE; } if (!part->m_canRegen) { return; }*/ // regenerate uemit.particles[partNumber].m_age = 1; startRand(&uemit, &(uemit.particles[partNumber]), partNumber); *uemitter = uemit; return; } // At start the particle fades in and expands rapidly (like in real life) double fadeIn = uemit.particles[partNumber].m_timeDie * 0.01; double startScale; double maxStartScale = 0.4; if (uemit.particles[partNumber].m_age < fadeIn) { uemit.particles[partNumber].m_alpha = ((uemit.particles[partNumber].m_age / fadeIn)); //printf("fade calc = %f \n", (part->m_age/fadeIn)*10 ); startScale = uemit.particles[partNumber].m_alpha * maxStartScale; // y increases quicker because particle is expanding quicker uemit.particles[partNumber].m_y += uemit.particles[partNumber].m_yVector * timeElapsed; } else { uemit.particles[partNumber].m_alpha = 1.0 - (uemit.particles[partNumber].m_age - fadeIn) / (uemit.particles[partNumber].m_timeDie - fadeIn); startScale = maxStartScale; uemit.particles[partNumber].m_y += uemit.particles[partNumber].m_yVector * timeElapsed; } // the x direction is influenced by wind velocity uemit.particles[partNumber].m_x += (uemit.particles[partNumber].m_xVector + uemit.m_windVelocity) * timeElapsed; uemit.particles[partNumber].m_scale = 0.001 + startScale + uemit.particles[partNumber].m_age / 4000.0; //printf( "x = %f y =%f\n", uemit.particles[partNumber].m_x, uemit.particles[partNumber].m_y); /*printf("update m_speed: %f\n", emitter->m_speed);*/ *uemitter = uemit; }
void initParticles(Particles *em, int x, int y) { em->m_speed = 0.02; em->m_alpha = 1.0; em->m_windVelocity = 0.025; em->m_dieRate = 0.95; em->m_x = x; em->m_y = y; em->m_lastRender = getMilliCount(); for (int i = 0; i < PART_COUNT; i++) { em->particles[i].m_x = 0; em->particles[i].m_canRegen = 1; em->particles[i].m_age = i * 50000 * em->m_speed; //Particle *cparticle = &emitter->particles[i]; startRand(&*em, &((*em).particles[i]), i); //printf( "part = %d x = %f y =%f age = %u die = %u\n",i, em.particles[i].m_x, em.particles[i].m_y, em.particles[i].m_age, em.particles[i].m_timeDie); } }
char* createTag() { int i; char *tag = malloc(sizeof(char)*GENERATOR_TAG_SIZE); if (tag != NULL) { startRand(); for( i=0; i<GENERATOR_TAG_LENGTH; i++) { tag[i] = nextRand(2)==0?'0':'1'; } tag[GENERATOR_TAG_LENGTH] = '\0'; } else { #ifdef DEBUG fprintf(stderr, "@Generator: Failed tag malloc\n"); #endif } return tag; }