libpsys
diff src/psys.c @ 1:874a942853ad
foobar
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sat, 24 Sep 2011 20:44:42 +0300 |
parents | 1c8eb90a6989 |
children | 6e5342a2529a |
line diff
1.1 --- a/src/psys.c Sat Sep 24 07:22:07 2011 +0300 1.2 +++ b/src/psys.c Sat Sep 24 20:44:42 2011 +0300 1.3 @@ -48,15 +48,23 @@ 1.4 memset(em, 0, sizeof *em); 1.5 1.6 if(anm_init_node(&em->prs) == -1) { 1.7 + psys_destroy(em); 1.8 return -1; 1.9 } 1.10 if(anm_init_track(&em->rate) == -1) { 1.11 - anm_destroy_node(&em->prs); 1.12 + psys_destroy(em); 1.13 + return -1; 1.14 + } 1.15 + if(anm_init_track(&em->life) == -1) { 1.16 + psys_destroy(em); 1.17 return -1; 1.18 } 1.19 if(init_v3track(&em->dir) == -1) { 1.20 - anm_destroy_node(&em->prs); 1.21 - anm_destroy_track(&em->rate); 1.22 + psys_destroy(em); 1.23 + return -1; 1.24 + } 1.25 + if(init_v3track(&em->grav) == -1) { 1.26 + psys_destroy(em); 1.27 return -1; 1.28 } 1.29 1.30 @@ -106,11 +114,21 @@ 1.31 anm_set_value(&em->rate, ANM_SEC2TM(tm), rate); 1.32 } 1.33 1.34 +void psys_set_life(struct psys_emitter *em, float life, float tm) 1.35 +{ 1.36 + anm_set_value(&em->life, ANM_SEC2TM(tm), life); 1.37 +} 1.38 + 1.39 void psys_set_dir(struct psys_emitter *em, vec3_t dir, float tm) 1.40 { 1.41 set_v3value(&em->dir, ANM_SEC2TM(tm), dir); 1.42 } 1.43 1.44 +void psys_set_grav(struct psys_emitter *em, vec3_t grav, float tm) 1.45 +{ 1.46 + set_v3value(&em->grav, ANM_SEC2TM(tm), grav); 1.47 +} 1.48 + 1.49 1.50 void psys_clear_collision_planes(struct psys_emitter *em) 1.51 { 1.52 @@ -120,7 +138,7 @@ 1.53 while(plane) { 1.54 struct col_plane *tmp = plane; 1.55 plane = plane->next; 1.56 - pfree(tmp); 1.57 + free(tmp); 1.58 } 1.59 } 1.60 1.61 @@ -191,6 +209,10 @@ 1.62 return em->cur_dir; 1.63 } 1.64 1.65 +vec3_t psys_get_grav(struct psys_emitter *em) 1.66 +{ 1.67 + return em->cur_grav; 1.68 +} 1.69 1.70 /* --- update and render --- */ 1.71 1.72 @@ -205,23 +227,24 @@ 1.73 1.74 atm = ANM_SEC2TM(tm); 1.75 1.76 - em->cur_rate = anm_get_value(&em->rate, atm) 1.77 + em->cur_rate = anm_get_value(&em->rate, atm); 1.78 dt = tm - em->last_update; 1.79 1.80 /* how many particles to spawn for this interval ? */ 1.81 spawn_count = em->cur_rate * dt; 1.82 1.83 #ifndef SUB_UPDATE_POS 1.84 - em->pos = anm_get_position(&em->prs, atm); 1.85 + em->cur_pos = anm_get_position(&em->prs, atm); 1.86 #endif 1.87 em->cur_dir = get_v3value(&em->dir, atm); 1.88 em->cur_life = anm_get_value(&em->life, atm); 1.89 + em->cur_grav = get_v3value(&em->grav, atm); 1.90 1.91 spawn_dt = dt / (float)spawn_count; 1.92 for(i=0; i<spawn_count; i++) { 1.93 #ifdef SUB_UPDATE_POS 1.94 /* update emitter position for this spawning */ 1.95 - em->pos = anm_get_position(&em->prs, ANM_SEC2TM(em->last_update + spawn_dt)); 1.96 + em->cur_pos = anm_get_position(&em->prs, ANM_SEC2TM(em->last_update + spawn_dt)); 1.97 #endif 1.98 1.99 if(!(p = palloc())) { 1.100 @@ -235,7 +258,7 @@ 1.101 /* update all particles */ 1.102 p = em->plist; 1.103 while(p) { 1.104 - em->update(em, p, tm, dt, upd_cls); 1.105 + em->update(em, p, tm, dt, em->upd_cls); 1.106 p = p->next; 1.107 } 1.108 1.109 @@ -259,17 +282,17 @@ 1.110 struct psys_particle *p; 1.111 1.112 if(em->draw_start) { 1.113 - em->draw_start(em, em->cls); 1.114 + em->draw_start(em, em->draw_cls); 1.115 } 1.116 1.117 p = em->plist; 1.118 while(p) { 1.119 - em->draw(em, p, em->cls); 1.120 + em->draw(em, p, em->draw_cls); 1.121 p = p->next; 1.122 } 1.123 1.124 if(em->draw_end) { 1.125 - em->draw_end(em, em->cls); 1.126 + em->draw_end(em, em->draw_cls); 1.127 } 1.128 } 1.129 1.130 @@ -286,17 +309,19 @@ 1.131 1.132 static void update_particle(struct psys_emitter *em, struct psys_particle *p, float tm, float dt, void *cls) 1.133 { 1.134 - vec3_t forces; 1.135 + vec3_t accel; 1.136 1.137 - forces.x = em->cur_grav.x * p->mass - p->vel.x * em->drag; 1.138 - forces.y = em->cur_grav.y * p->mass - p->vel.y * em->drag; 1.139 - forces.z = em->cur_grav.z * p->mass - p->vel.z * em->drag; 1.140 + accel.x = em->cur_grav.x - p->vel.x * em->drag; 1.141 + accel.y = em->cur_grav.y - p->vel.y * em->drag; 1.142 + accel.z = em->cur_grav.z - p->vel.z * em->drag; 1.143 + 1.144 + p->vel.x += accel.x * dt; 1.145 + p->vel.y += accel.y * dt; 1.146 + p->vel.z += accel.z * dt; 1.147 1.148 p->pos.x += p->vel.x * dt; 1.149 p->pos.y += p->vel.y * dt; 1.150 p->pos.z += p->vel.z * dt; 1.151 - 1.152 - 1.153 } 1.154 1.155 /* --- v3track helper --- */ 1.156 @@ -359,7 +384,7 @@ 1.157 1.158 if(p) { 1.159 memset(p, 0, sizeof *p); 1.160 - reset_pattr(&p->attr); 1.161 + /*reset_pattr(&p->attr);*/ 1.162 } 1.163 return p; 1.164 }