From 25448f375cbeff5ab250f0440589a44c3400e9fe Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Fri, 11 Feb 2011 00:17:23 +0000 Subject: [PATCH] base size git-svn-id: http://svn.net-core.org/repos/t-engine4@2711 51575b47-30f0-44d4-a5cc-537603b46e54 --- src/particles.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/particles.c b/src/particles.c index 78daa9e289..2ee1610b46 100644 --- a/src/particles.c +++ b/src/particles.c @@ -541,6 +541,8 @@ void thread_particle_init(particle_thread *pt, plist *l) { lua_State *L = pt->L; particles_type *ps = l->ps; + int tile_w, tile_h; + int base_size = 0; // Load the particle definition // Returns: generator_fct:1, update_fct:2, max:3, gl:4, no_stop:5 @@ -574,10 +576,12 @@ void thread_particle_init(particle_thread *pt, plist *l) lua_pushstring(L, "tile_w"); lua_pushstring(L, "tile_w"); lua_gettable(L, -7); + tile_w = lua_tonumber(L, -1); lua_settable(L, -3); lua_pushstring(L, "tile_h"); lua_pushstring(L, "tile_h"); lua_gettable(L, -7); + tile_h = lua_tonumber(L, -1); lua_settable(L, -3); lua_settable(L, -3); @@ -593,10 +597,23 @@ void thread_particle_init(particle_thread *pt, plist *l) lua_setmetatable(L, -2); // Set the environment - lua_setfenv(L, -2); + lua_pushvalue(L, -1); + lua_setfenv(L, -3); + lua_insert(L, -2); // Call the method - docall(L, 0, 5); + if (lua_pcall(L, 0, 5, 0)) + { + printf("Particle run error %x (%s): %s\n", (int)l, ps->args, lua_tostring(L, -1)); + lua_pop(L, 1); + } + + // Check base size + lua_pushstring(L, "base_size"); + lua_gettable(L, -7); + base_size = lua_tonumber(L, -1); + lua_pop(L, 1); + lua_remove(L, -6); } else { lua_pop(L, 1); return; } @@ -606,6 +623,12 @@ void thread_particle_init(particle_thread *pt, plist *l) ps->nb = nb; ps->no_stop = lua_toboolean(L, 5); + ps->zoom = 1; + if (base_size) + { + ps->zoom = (((float)tile_w + (float)tile_h) / 2) / (float)base_size; + } + int batch = nb; ps->batch_nb = 0; ps->vertices = calloc(2*4*batch, sizeof(GLfloat)); // 2 coords, 4 vertices per particles -- GitLab