Allegro.cc Forums » Programming Questions » Particle Panic!

 Particle Panic!
ngiacomelli
Member #5,114
October 2004

[EDIT: first question removed! (Stupid, stupid, stupid!)]

Now, my second question (particle panic!) involves linked-lists which I have had absolutely no experience with. My program has been freezing occasionally since I added the particle engine. Which seems to me like it's a memory leak. I just wanted to know if this looked alright before I dived into really hunting it down:

particle.h:

```typedef struct part_list{

double x, y, z;
double dx, dy, dz; // direction
double rx, ry, rz; // randomness
double tx, ty, tz; // last location

int visible, life, birth;

struct part_list *next;

}particle_list;
```

particle.c:

 Hrvoje Ban Member #4,537 April 2004 Use arc for drawing partial circles (arcs). Just increase angle every frame.
 amarillion Member #940 January 2001 Why do you use the x,y,z coordinates to identify a particle to delete? Why not the pointer itself? Like this you have to do a test for equality of doubles, which should always be avoided I think. And, although unlikely, you could have two particles at exactly the same spot. --Martijn van Iersel | My Blog | Sin & Cos | Tegel tilemap editor | TINS 2017
ngiacomelli
Member #5,114
October 2004

Good point! I changed my code. Is this what you mean?

 1 void clean_particle_tree() { 2 3 particle_list *tmp, *next; 4 for(tmp = p_head; tmp; tmp = next){ 5 6 next = tmp->next; 7 8 if(tmp->life <= 0) { 9 delete_particle_node(tmp); 10 } 11 12 } 13 14 } 15 16 void delete_particle_node(particle_list *tmp_t){ 17 18 particle_list *tmp, *next, *prev; 19 for(tmp = p_head, prev = p_head; tmp; prev = tmp, tmp = next){ 20 21 next = tmp->next; 22 23 if(tmp == tmp_t){ 24 25 free(tmp); 26 27 if(prev == tmp) { 28 p_head = next; 29 } else { 30 prev->next = next; 31 } 32 33 } 34 35 } 36 37 }

 Hrvoje Ban Member #4,537 April 2004 You shouldn't remove questions, even stupid ones since someone else might have same problem and get here through search.Also, in C if you write function like foo() it means that function take varying number of arguments, for no arguments use foo(void).
ngiacomelli
Member #5,114
October 2004

Problem with do_circle (arcs isn't what I wanted):

 1 int c_click; 2 3 void draw_spawn_point(BITMAP *bmp, int x, int y, int d) { 4 5 int i; 6 7 c_click++; 8 if(c_click == d) { 9 10 add_object_node(1, x, y, 0); 11 12 for(i = 0; i < 10; i++) { 13 14 add_particle_node(rand()%50, rand()%150, 15 (x - 5) + rand()%20, (y - 5) + rand()%20, rand()%10, 16 0, 0, 2, 17 0, 0, 0); 18 19 } 20 21 c_click = 0; 22 23 } 24 25 } 26 27 void create_spawn_point(int size, int s_size, int x_s, int y_s) { 28 29 c_click = 0; 30 31 add_object_node(1, x_s, y_s, 0); // add centre node 32 33 do_circle(buffer, x_s, y_s, size, s_size, draw_spawn_point); 34 35 }

Now. The code works but when I have it placing a sprite within do_circle I end up with a huge amount of sprites per circle. So I wanted to cut that down. I thought that if I passed s_size as 10(which become d in draw_spawn_point). It would only draw a sprite every 10 calls to draw_spawn_point. Sadly, this doesn't work. It seems like it only calls the function for some areas of the circle, but not for others?! This is confusing as, if I remove the c_click counter, the entire circle is drawn.

Do I not understand the callback functionality?

 nonnus29 Member #2,606 August 2002 ```void clean_particle_tree() { particle_list *tmp, *next; for(tmp = p_head; tmp; tmp = next){ //You're always skipping the head of the list: next = tmp->next; if(tmp->life <= 0) { delete_particle_node(tmp->x, tmp->y, tmp->z); } } } ``` The head of the list never gets deleted, or anything else.....Edit; oops, n/m I'm wrong.
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads