Optimized and cleaned-up 'smoke.c' (smoke effect).

This commit is contained in:
stainless
2001-11-14 09:55:15 +00:00
parent 1ef0eba904
commit c446309ddc
2 changed files with 49 additions and 18 deletions

View File

@@ -59,7 +59,9 @@ MAINOBJ=cfgload.o endmem.o fixsin.o init.o ui.o vcache.o water.o smoke.o
OBJS=${CHIPSOBJ} ${CPUOBJ} ${DOSOBJ} ${GUIOBJ} ${VIDEOBJ} ${PREOBJ} ${MAINOBJ} ${ZIPOBJ} OBJS=${CHIPSOBJ} ${CPUOBJ} ${DOSOBJ} ${GUIOBJ} ${VIDEOBJ} ${PREOBJ} ${MAINOBJ} ${ZIPOBJ}
LIBS=-lz -lm -lpng LIBS=-lz -lm -lpng
CFLAGS=-O2 -Wall -Wno-unused -D__MSDOS__ #CFLAGS=-O2 -Wall -Wno-unused -D__MSDOS__
CFLAGS=-O3 -march=i486 -mpentium -fno-rtti -fno-exceptions -ffast-math\
-fomit-frame-pointer -fno-unroll-loops -Wall -Wno-unused -D__MSDOS__
ASM=nasm ASM=nasm
ASMFLAGS=-f coff -D__MSDOS__ ASMFLAGS=-f coff -D__MSDOS__
CC=gcc CC=gcc

View File

@@ -5,13 +5,20 @@
#else #else
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>
# include <time.h>
#endif #endif
// Ripped from an Allegro example (exflame.c). :P /*
// Should be fire, but looks more like smoke in ZSNES.
#define MIN(x,y) \ Ripped from an Allegro example (exflame.c). :)
Should be fire, but looks more like smoke in ZSNES.
*/
#define MIN(x, y) \
(((x) < (y)) ? (x) : (y)) (((x) < (y)) ? (x) : (y))
#define ABS(x) \ #define ABS(x) \
@@ -39,11 +46,13 @@ static unsigned char fire_buffer [SCRW * SCRH];
static int fire_init_flag; static int fire_init_flag;
static void draw_bottom_line_of_fire (void) static __inline__ void draw_bottom_line_of_fire (void)
{ {
int count, count2; int count, count2;
memset (&fire_line, 0, SCRW);
memset ((& fire_line), 0, SCRW);
for (count = 0; count < FIRE_HOTSPOTS; count ++) for (count = 0; count < FIRE_HOTSPOTS; count ++)
{ {
@@ -53,13 +62,15 @@ static void draw_bottom_line_of_fire (void)
if ((count2 >= 0) && (count2 < SCRW)) if ((count2 >= 0) && (count2 < SCRW))
{ {
fire_line [count2] = fire_line [count2] =
MIN((fire_line [count2] + 20) - MIN ((fire_line [count2] + 20) -
ABS(fire_hotspot [count] - count2), 256); ABS (fire_hotspot [count] - count2), 256);
} }
} }
fire_hotspot [count] += ((rand () & 7) - 3); fire_hotspot [count] += ((rand () & 7) - 3);
if (fire_hotspot [count] < 0) if (fire_hotspot [count] < 0)
{ {
fire_hotspot [count] += SCRW; fire_hotspot [count] += SCRW;
@@ -70,6 +81,7 @@ static void draw_bottom_line_of_fire (void)
} }
} }
for (count = 0; count < SCRW; count ++) for (count = 0; count < SCRW; count ++)
{ {
fire_buffer [((SCRH - 1) * fire_buffer [((SCRH - 1) *
@@ -78,66 +90,82 @@ static void draw_bottom_line_of_fire (void)
} }
static void InitFire (void) static __inline__ void init_fire (void)
{ {
int x, y, pixel, count; int x, y, pixel, count;
srand (time (0));
for (count = 0; count < FIRE_HOTSPOTS; count ++) for (count = 0; count < FIRE_HOTSPOTS; count ++)
{ {
fire_hotspot [count] = (rand () % SCRW); fire_hotspot [count] = (rand () % SCRW);
} }
for (count = 0; count < SCRH; count ++) for (count = 0; count < SCRH; count ++)
{ {
draw_bottom_line_of_fire (); draw_bottom_line_of_fire ();
for (y = 0; y < (SCRH - 1); y ++) for (y = 0; y < (SCRH - 1); y ++)
{ {
for (x = 0; x < SCRW; x ++) for (x = 0; x < SCRW; x ++)
{ {
pixel = fire_buffer [((y + 1) * SCRW) + x]; pixel = fire_buffer [((y + 1) * SCRW) + x];
if (pixel > 0) if (pixel > 0)
{ {
pixel --; pixel --;
} }
fire_buffer [(y * SCRW) + x] = pixel; fire_buffer [(y * SCRW) + x] = pixel;
} }
} }
} }
fire_init_flag = 1; fire_init_flag = 1;
} }
// void DrawFire (void) /* void DrawFire (void) */
void DrawSmoke (void) void DrawSmoke (void)
{ {
int x, y, pixel, pixel2; int x, y, pixel, pixel2;
if (fire_init_flag != 1)
if (! fire_init_flag)
{ {
InitFire (); init_fire ();
} }
draw_bottom_line_of_fire (); draw_bottom_line_of_fire ();
for (y = 0; y < (SCRH - 1); y ++) for (y = 0; y < (SCRH - 1); y ++)
{ {
for (x = 0; x < SCRW; x ++) for (x = 0; x < SCRW; x ++)
{ {
pixel = fire_buffer [((y + 1) * SCRW) + x]; pixel = fire_buffer [((y + 1) * SCRW) + x];
if (pixel > 0) if (pixel > 0)
{ {
pixel --; pixel --;
} }
fire_buffer [(y * SCRW) + x] = pixel; fire_buffer [(y * SCRW) + x] = pixel;
} }
} }
for (y = 0; y < SCRH; y ++) for (y = 0; y < SCRH; y ++)
{ {
for (x = 0; x < SCRW; x ++) for (x = 0; x < SCRW; x ++)
@@ -146,6 +174,7 @@ void DrawSmoke (void)
pixel2 = (fire_buffer [(y * SCRW) + x] / 8); pixel2 = (fire_buffer [(y * SCRW) + x] / 8);
if (pixel2 > pixel) if (pixel2 > pixel)
{ {
vidbuffer [(y * SCRW) + x] = pixel2; vidbuffer [(y * SCRW) + x] = pixel2;