Fire intensity from Lua

This commit is contained in:
Simon Robertshaw 2011-08-11 13:02:00 +01:00
parent 806e1933a2
commit 9e634b95cc
4 changed files with 15 additions and 4 deletions

View File

@ -142,7 +142,7 @@ void render_signs(pixel *vid_buf);
void render_fire(pixel *dst); void render_fire(pixel *dst);
void prepare_alpha(void); void prepare_alpha(int size, float intensity);
void draw_image(pixel *vid, pixel *img, int x, int y, int w, int h, int a); void draw_image(pixel *vid, pixel *img, int x, int y, int w, int h, int a);

View File

@ -64,4 +64,5 @@ int luatpt_decorations_enable(lua_State* l);
int luatpt_cmode_set(lua_State* l); int luatpt_cmode_set(lua_State* l);
int luatpt_error(lua_State* l); int luatpt_error(lua_State* l);
int luatpt_heat(lua_State* l); int luatpt_heat(lua_State* l);
int luatpt_setfire(lua_State* l);
#endif #endif

View File

@ -3869,9 +3869,11 @@ void render_fire(pixel *vid)
} }
} }
void prepare_alpha(void) void prepare_alpha(int size, float intensity)
{ {
//TODO: implement size
int x,y,i,j; int x,y,i,j;
float multiplier = 255.0f*intensity;
float temp[CELL*3][CELL*3]; float temp[CELL*3][CELL*3];
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
for (x=0; x<CELL; x++) for (x=0; x<CELL; x++)
@ -3881,7 +3883,7 @@ void prepare_alpha(void)
temp[y+CELL+j][x+CELL+i] += expf(-0.1f*(i*i+j*j)); temp[y+CELL+j][x+CELL+i] += expf(-0.1f*(i*i+j*j));
for (x=0; x<CELL*3; x++) for (x=0; x<CELL*3; x++)
for (y=0; y<CELL*3; y++) for (y=0; y<CELL*3; y++)
fire_alpha[y][x] = (int)(255.0f*temp[y][x]/(CELL*CELL)); fire_alpha[y][x] = (int)(multiplier*temp[y][x]/(CELL*CELL));
} }
pixel *render_packed_rgb(void *image, int width, int height, int cmp_size) pixel *render_packed_rgb(void *image, int width, int height, int cmp_size)

View File

@ -53,6 +53,7 @@ void luacon_open(){
{"display_mode", &luatpt_cmode_set}, {"display_mode", &luatpt_cmode_set},
{"throw_error", &luatpt_error}, {"throw_error", &luatpt_error},
{"heat", &luatpt_heat}, {"heat", &luatpt_heat},
{"setfire", &luatpt_setfire},
{NULL,NULL} {NULL,NULL}
}; };
@ -1036,8 +1037,15 @@ int luatpt_heat(lua_State* l)
int luatpt_cmode_set(lua_State* l) int luatpt_cmode_set(lua_State* l)
{ {
int aheatstate; int aheatstate;
aheatstate = luaL_optint(l, 1, CM_COUNT); aheatstate = luaL_optint(l, 1, CM_FIRE);
cmode = aheatstate; cmode = aheatstate;
return 0; return 0;
} }
int luatpt_setfire(lua_State* l)
{
int firesize = luaL_optint(l, 2, 4);
float fireintensity = (float)luaL_optnumber(l, 1, 1.0d);
prepare_alpha(firesize, fireintensity);
return 0;
}
#endif #endif