made faster

This commit is contained in:
Philip 2010-11-08 19:59:03 -05:00
parent b8ed9035f7
commit 16265e3736
7 changed files with 60 additions and 46 deletions

View File

@ -1,7 +1,7 @@
#ifndef DEFINE_H #ifndef DEFINE_H
#define DEFINE_H #define DEFINE_H
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
#define PATH_SEP "\\" #define PATH_SEP "\\"
#else #else
#define PATH_SEP "/" #define PATH_SEP "/"

View File

@ -63,13 +63,13 @@ int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc);
void draw_menu(pixel *vid_buf, int i, int hover); void draw_menu(pixel *vid_buf, int i, int hover);
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a); _inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a);
#else #else
extern inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a); extern inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a); _inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a);
#else #else
extern inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a); extern inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a);
@ -97,7 +97,7 @@ int textnheight(char *s, int n, int w);
int textwidthx(char *s, int w); int textwidthx(char *s, int w);
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a); _inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a);
#else #else
void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a); void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a);

View File

@ -21,19 +21,19 @@ __asm__ __volatile ("cpuid":\
static char hex[] = "0123456789ABCDEF"; static char hex[] = "0123456789ABCDEF";
//Signum function //Signum function
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline int isign(float i); extern _inline int isign(float i);
#else #else
extern inline int isign(float i); extern inline int isign(float i);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline unsigned clamp_flt(float f, float min, float max); extern _inline unsigned clamp_flt(float f, float min, float max);
#else #else
extern inline unsigned clamp_flt(float f, float min, float max); extern inline unsigned clamp_flt(float f, float min, float max);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline float restrict_flt(float f, float min, float max); extern _inline float restrict_flt(float f, float min, float max);
#else #else
extern inline float restrict_flt(float f, float min, float max); extern inline float restrict_flt(float f, float min, float max);
@ -69,4 +69,4 @@ void *file_load(char *fn, int *size);
int cpu_check(void); int cpu_check(void);
#endif #endif

View File

@ -299,7 +299,7 @@ static const part_type ptypes[PT_NUM] =
{"2x2", PIXPACK(0xFFFF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "2x2! (125/36)", TYPE_SOLID}, {"2x2", PIXPACK(0xFFFF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "2x2! (125/36)", TYPE_SOLID},
{"DANI", PIXPACK(0x00FFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Day and Night! (34678/3678)", TYPE_SOLID}, {"DANI", PIXPACK(0x00FFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Day and Night! (34678/3678)", TYPE_SOLID},
{"AMOE", PIXPACK(0xFF00FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Amoeba! (1358/357)", TYPE_SOLID}, {"AMOE", PIXPACK(0xFF00FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Amoeba! (1358/357)", TYPE_SOLID},
{"MOVE", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Move particles! (245/368)", TYPE_SOLID}, {"MOVE", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "'Move' particles! Does not move things.. it is a life type(245/368)", TYPE_SOLID},
{"PGOL", PIXPACK(0xE05010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Pseudo Life! (238/357)", TYPE_SOLID}, {"PGOL", PIXPACK(0xE05010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Pseudo Life! (238/357)", TYPE_SOLID},
{"DMOE", PIXPACK(0x500000), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Diamoeba! (5678/35678)", TYPE_SOLID}, {"DMOE", PIXPACK(0x500000), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Diamoeba! (5678/35678)", TYPE_SOLID},
//Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Weights Section H Ins(real world, by triclops200) Description //Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Weights Section H Ins(real world, by triclops200) Description
@ -421,25 +421,25 @@ int try_move(int i, int x, int y, int nx, int ny);
void kill_part(int i); void kill_part(int i);
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline int create_part(int p, int x, int y, int t); extern _inline int create_part(int p, int x, int y, int t);
#else #else
extern inline int create_part(int p, int x, int y, int t); extern inline int create_part(int p, int x, int y, int t);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline void delete_part(int x, int y); extern _inline void delete_part(int x, int y);
#else #else
extern inline void delete_part(int x, int y); extern inline void delete_part(int x, int y);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline int is_wire(int x, int y); extern _inline int is_wire(int x, int y);
#else #else
extern inline int is_wire(int x, int y); extern inline int is_wire(int x, int y);
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
extern _inline int is_wire_off(int x, int y); extern _inline int is_wire_off(int x, int y);
#else #else
extern inline int is_wire_off(int x, int y); extern inline int is_wire_off(int x, int y);
@ -447,7 +447,7 @@ extern inline int is_wire_off(int x, int y);
void set_emap(int x, int y); void set_emap(int x, int y);
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int parts_avg(int ci, int ni); _inline int parts_avg(int ci, int ni);
#else #else
int parts_avg(int ci, int ni); int parts_avg(int ci, int ni);

View File

@ -757,7 +757,7 @@ void draw_menu(pixel *vid_buf, int i, int hover)
} }
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a) _inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
#else #else
inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a) inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
@ -776,7 +776,7 @@ inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) _inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
#else #else
inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
@ -1030,7 +1030,7 @@ int textwidthx(char *s, int w)
return n; return n;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) _inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
#else #else
inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)

View File

@ -7,7 +7,7 @@
#include "graphics.h" #include "graphics.h"
//Signum function //Signum function
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int isign(float i) _inline int isign(float i)
#else #else
inline int isign(float i) inline int isign(float i)
@ -20,7 +20,7 @@ inline int isign(float i)
return 0; return 0;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline unsigned clamp_flt(float f, float min, float max) _inline unsigned clamp_flt(float f, float min, float max)
#else #else
inline unsigned clamp_flt(float f, float min, float max) inline unsigned clamp_flt(float f, float min, float max)
@ -33,7 +33,7 @@ inline unsigned clamp_flt(float f, float min, float max)
return (int)(255.0f*(f-min)/(max-min)); return (int)(255.0f*(f-min)/(max-min));
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline float restrict_flt(float f, float min, float max) _inline float restrict_flt(float f, float min, float max)
#else #else
inline float restrict_flt(float f, float min, float max) inline float restrict_flt(float f, float min, float max)
@ -280,4 +280,4 @@ int cpu_check(void)
#endif #endif
#endif #endif
return 0; return 0;
} }

View File

@ -354,7 +354,7 @@ void kill_part(int i)
pfree = i; pfree = i;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int create_part(int p, int x, int y, int t) _inline int create_part(int p, int x, int y, int t)
#else #else
inline int create_part(int p, int x, int y, int t) inline int create_part(int p, int x, int y, int t)
@ -650,7 +650,7 @@ static void create_cherenkov_photon(int pp)
parts[i].vy *= r; parts[i].vy *= r;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline void delete_part(int x, int y) _inline void delete_part(int x, int y)
#else #else
inline void delete_part(int x, int y) inline void delete_part(int x, int y)
@ -672,7 +672,7 @@ inline void delete_part(int x, int y)
return; return;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int is_wire(int x, int y) _inline int is_wire(int x, int y)
#else #else
inline int is_wire(int x, int y) inline int is_wire(int x, int y)
@ -681,7 +681,7 @@ inline int is_wire(int x, int y)
return bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8 || bmap[y][x]==11 || bmap[y][x]==12; return bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8 || bmap[y][x]==11 || bmap[y][x]==12;
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int is_wire_off(int x, int y) _inline int is_wire_off(int x, int y)
#else #else
inline int is_wire_off(int x, int y) inline int is_wire_off(int x, int y)
@ -772,7 +772,7 @@ void set_emap(int x, int y)
} }
} }
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
_inline int parts_avg(int ci, int ni) _inline int parts_avg(int ci, int ni)
#else #else
inline int parts_avg(int ci, int ni) inline int parts_avg(int ci, int ni)
@ -845,24 +845,42 @@ void update_particles_i(pixel *vid, int start, int inc)
for(int nnx=-1;nnx<2;nnx++) for(int nnx=-1;nnx<2;nnx++)
for(int nny=-1;nny<2;nny++) for(int nny=-1;nny<2;nny++)
{ {
if(ny+nny<4&&nx+nnx<4)//any way to make wrapping code smaller? if(ny+nny<4&&nx+nnx<4){//any way to make wrapping code smaller?
gol2[XRES-5][YRES-5][golnum] ++; gol2[XRES-5][YRES-5][golnum] ++;
else if(ny+nny<4&&nx+nnx>=XRES-4) gol2[XRES-5][YRES-5][0] ++;
}
else if(ny+nny<4&&nx+nnx>=XRES-4){
gol2[4][YRES-5][golnum] ++; gol2[4][YRES-5][golnum] ++;
else if(ny+nny>=YRES-4&&nx+nnx<4) gol2[4][YRES-5][0] ++;
}
else if(ny+nny>=YRES-4&&nx+nnx<4){
gol2[XRES-5][4][golnum] ++; gol2[XRES-5][4][golnum] ++;
else if(nx+nnx<4) gol2[XRES-5][4][0] ++;
}
else if(nx+nnx<4){
gol2[XRES-5][ny+nny][golnum] ++; gol2[XRES-5][ny+nny][golnum] ++;
else if(ny+nny<4) gol2[XRES-5][ny+nny][0] ++;
}
else if(ny+nny<4){
gol2[nx+nnx][YRES-5][golnum] ++; gol2[nx+nnx][YRES-5][golnum] ++;
else if(ny+nny>=YRES-4&&nx+nnx>=XRES-4) gol2[nx+nnx][YRES-5][0] ++;
}
else if(ny+nny>=YRES-4&&nx+nnx>=XRES-4){
gol2[4][4][golnum] ++; gol2[4][4][golnum] ++;
else if(ny+nny>=YRES-4) gol2[4][4][0] ++;
}
else if(ny+nny>=YRES-4){
gol2[nx+nnx][4][golnum] ++; gol2[nx+nnx][4][golnum] ++;
else if(nx+nnx>=XRES-4) gol2[nx+nnx][4][0] ++;
}
else if(nx+nnx>=XRES-4){
gol2[4][ny+nny][golnum] ++; gol2[4][ny+nny][golnum] ++;
else gol2[4][ny+nny][0] ++;
}
else{
gol2[nx+nnx][ny+nny][golnum] ++; gol2[nx+nnx][ny+nny][golnum] ++;
gol2[nx+nnx][ny+nny][0] ++;
}
} }
@ -872,15 +890,11 @@ void update_particles_i(pixel *vid, int start, int inc)
for(nx=4;nx<XRES-4;nx++) for(nx=4;nx<XRES-4;nx++)
for(ny=4;ny<YRES-4;ny++) for(ny=4;ny<YRES-4;ny++)
{ {
int neighbors = 0; int neighbors = gol2[nx][ny][0];
if(neighbors==0)
continue;
for(int golnum = 1;golnum<NGOL;golnum++) for(int golnum = 1;golnum<NGOL;golnum++)
{ for(int goldelete = 1;goldelete<10;goldelete++)
neighbors += gol2[nx][ny][golnum];
}
if(neighbors!=0)
{
for(int golnum = 1;golnum<NGOL;golnum++)
for(int goldelete = 1;goldelete<10;goldelete++)
{ {
if(neighbors==goldelete&&gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2) if(neighbors==goldelete&&gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
{ {
@ -889,9 +903,9 @@ void update_particles_i(pixel *vid, int start, int inc)
else if(neighbors==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2)) else if(neighbors==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))
parts[pmap[ny][nx]>>8].type = PT_NONE; parts[pmap[ny][nx]>>8].type = PT_NONE;
} }
for(int z = 1;z<NGOL;z++) gol2[nx][ny][0] = 0;
for(int z = 1;z<NGOL;z++)
gol2[nx][ny][z] = 0; gol2[nx][ny][z] = 0;
}
} }
} }
if(CGOL==0) if(CGOL==0)
@ -1019,7 +1033,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
// interpolator // interpolator
#ifdef WIN32 #if defined(WIN32) && !defined(__GNUC__)
mv = max(fabsf(parts[i].vx), fabsf(parts[i].vy)); mv = max(fabsf(parts[i].vx), fabsf(parts[i].vy));
#else #else
mv = fmaxf(fabsf(parts[i].vx), fabsf(parts[i].vy)); mv = fmaxf(fabsf(parts[i].vx), fabsf(parts[i].vy));