From 9254540b095ab585490118adadf9b28e9b50f45c Mon Sep 17 00:00:00 2001 From: Petr Sykora Date: Sun, 19 Oct 2008 22:44:15 +0200 Subject: [PATCH] Linked list->static array, it works :-) --- ebulanci.c | 4 ++-- particle.c | 49 ++++++++++++++++--------------------------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/ebulanci.c b/ebulanci.c index c0ea6ad..d4fcc83 100644 --- a/ebulanci.c +++ b/ebulanci.c @@ -545,7 +545,7 @@ void ShootParticles(Game *g, double dtime, int lid) double v; Particle *p; - for(i = 1; i < 200; i ++){ + for(i = 1; i < 20; i ++){ p = malloc(sizeof(Particle)); memset(p, 0, sizeof(Particle)); a = RandD(0.0, 2*M_PI); @@ -568,7 +568,6 @@ void Shoot(Game *g, double dtime, int lid){ for(i=0; iWeaponTemplate[g->Lilanek[lid].ActiveWeapon].Burst; i++){ if(g->Lilanek[lid].Ammo[g->Lilanek[lid].ActiveWeapon] == 0) return; - ShootParticles(g, dtime, lid); for(bid=0; bidnoBullets; bid++){ if(g->Bullet[bid].Exists) continue; @@ -578,6 +577,7 @@ void Shoot(Game *g, double dtime, int lid){ break; } } + ShootParticles(g, dtime, lid); switch(g->Lilanek[lid].ActiveWeapon){ case 0: PlaySound(s_shoot); break; case 1: PlaySound(s_mine); break; diff --git a/particle.c b/particle.c index 63a5196..13fd50d 100644 --- a/particle.c +++ b/particle.c @@ -1,30 +1,23 @@ #include "particle.h" typedef struct plistitem_s{ - struct plistitem_s *next; Particle *p; }plistitem_t; -plistitem_t *firstpart = 0; +#define NO_PARTS 100 +plistitem_t parts[NO_PARTS]; void AddParticle(Particle *p) { - plistitem_t *l; + int i; - l = firstpart; - if (l == NULL) { - firstpart = calloc(1, sizeof(plistitem_t)); - firstpart->next = 0; - firstpart->p = p; - return; - }; - - while (l->next != 0) { - l = l->next; + for (i = 0; i < NO_PARTS; i++) { + if (parts[i].p == 0) { + parts[i].p = p; + return; + }; }; - l->next = calloc(1, sizeof(plistitem_t)); - l->next->next = 0; - l->next->p = p; + free(p); } void UpdateParticle(Particle *p, double dt) @@ -55,40 +48,30 @@ void QueueDrawPart(Particle *p) QueueDrawSpriteColorize(p->s, p->x, p->y, p->z, color); } -void RemoveParticle(plistitem_t *l, plistitem_t *a) +void RemoveParticle(plistitem_t *a) { - if (l != 0) l->next = a->next; if (a == 0) return; if (a->p)free(a->p); - free(a); + a->p = 0; } void UpdateAndQueueDrawParticles(double dt) { - plistitem_t *n,*a, *l; - l = firstpart; - a = l; - while (a) { + plistitem_t *a; + int i; + for (i=0; ip == 0){ - n = a->next; - RemoveParticle(l, a); - if (a == firstpart) firstpart = n; - a = n; continue; }; UpdateParticle(a->p, dt); if (a->p->t <= 0.0) { - n = a->next; - RemoveParticle(l, a); - if (a == firstpart) firstpart = n; - a = n; + RemoveParticle(a); continue; }; QueueDrawPart(a->p); - l = a; - a = l->next; }; } -- 2.11.4.GIT