1
0
Fork 0

(svn r328) -Fix: remove some unlogical alloca()s (Tron)

release/0.4.5
darkvater 2004-09-27 12:36:59 +00:00
parent 0dbe38fba7
commit edf841fb6f
3 changed files with 32 additions and 34 deletions

View File

@ -339,40 +339,40 @@ void TPFMode1(TrackPathFinder *tpf, uint tile, int direction)
void FollowTrack(uint tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) void FollowTrack(uint tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
{ {
TrackPathFinder *tpf = alloca(sizeof(TrackPathFinder)); TrackPathFinder tpf;
assert(direction < 4); assert(direction < 4);
/* initialize path finder variables */ /* initialize path finder variables */
tpf->userdata = data; tpf.userdata = data;
tpf->enum_proc = enum_proc; tpf.enum_proc = enum_proc;
tpf->new_link = tpf->links; tpf.new_link = tpf.links;
tpf->num_links_left = 0x400; tpf.num_links_left = lengthof(tpf.links);
tpf->rd.cur_length = 0; tpf.rd.cur_length = 0;
tpf->rd.depth = 0; tpf.rd.depth = 0;
tpf->rd.pft_var6 = 0; tpf.rd.pft_var6 = 0;
tpf->var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */ tpf.var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */
tpf->disable_tile_hash = HASBIT(flags, 12) != 0; /* 0x1000 */ tpf.disable_tile_hash = HASBIT(flags, 12) != 0; /* 0x1000 */
tpf->hasbit_13 = HASBIT(flags, 13) != 0; /* 0x2000 */ tpf.hasbit_13 = HASBIT(flags, 13) != 0; /* 0x2000 */
tpf->tracktype = (byte)flags; tpf.tracktype = (byte)flags;
if (HASBIT(flags, 11)) { if (HASBIT(flags, 11)) {
tpf->rd.pft_var6 = 0xFF; tpf.rd.pft_var6 = 0xFF;
tpf->enum_proc(tile, data, 0, 0, 0); tpf.enum_proc(tile, data, 0, 0, 0);
TPFMode2(tpf, tile, direction); TPFMode2(&tpf, tile, direction);
} else { } else {
/* clear the hash_heads */ /* clear the hash_heads */
memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); memset(tpf.hash_head, 0, sizeof(tpf.hash_head));
TPFMode1(tpf, tile, direction); TPFMode1(&tpf, tile, direction);
} }
if (after_proc != NULL) if (after_proc != NULL)
after_proc(tpf); after_proc(&tpf);
} }
typedef struct { typedef struct {
@ -713,19 +713,17 @@ void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *d
if (!_patches.new_pathfinding) { if (!_patches.new_pathfinding) {
FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data); FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data);
} else { } else {
NewTrackPathFinder *tpf; NewTrackPathFinder tpf;
tpf.userdata = data;
tpf.enum_proc = enum_proc;
tpf.tracktype = 0;
tpf.maxlength = _patches.pf_maxlength;
tpf.nstack = 0;
tpf.new_link = tpf.links;
tpf.num_links_left = lengthof(tpf.links);
memset(tpf.hash_head, 0, sizeof(tpf.hash_head));
tpf = alloca(sizeof(NewTrackPathFinder)); NTPEnum(&tpf, tile, direction);
tpf->userdata = data;
tpf->enum_proc = enum_proc;
tpf->tracktype = 0;
tpf->maxlength = _patches.pf_maxlength;
tpf->nstack = 0;
tpf->new_link = tpf->links;
tpf->num_links_left = 0x400;
memset(tpf->hash_head, 0, sizeof(tpf->hash_head));
NTPEnum(tpf, tile, direction);
} }
} }

View File

@ -53,7 +53,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
{ {
BitmapFileHeader bfh; BitmapFileHeader bfh;
BitmapInfoHeader bih; BitmapInfoHeader bih;
RgbQuad *rq = alloca(sizeof(RgbQuad) * 256); RgbQuad rq[256];
byte *buff; byte *buff;
FILE *f; FILE *f;
uint i, padw; uint i, padw;
@ -99,7 +99,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
// write file header and info header and palette // write file header and info header and palette
fwrite(&bfh, 1, sizeof(bfh), f); fwrite(&bfh, 1, sizeof(bfh), f);
fwrite(&bih, 1, sizeof(bih), f); fwrite(&bih, 1, sizeof(bih), f);
fwrite(rq, 1, sizeof(RgbQuad) * 256, f); fwrite(rq, 1, sizeof(rq), f);
// use by default 64k temp memory // use by default 64k temp memory
maxlines = clamp(65536 / padw, 16, 128); maxlines = clamp(65536 / padw, 16, 128);
@ -146,7 +146,7 @@ static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette) static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette)
{ {
png_colorp rq = alloca(sizeof(png_color) * 256); png_color rq[256];
byte *buff; byte *buff;
FILE *f; FILE *f;
uint i, y, n; uint i, y, n;

View File

@ -1072,7 +1072,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const char *filename)
static char *PrintModuleInfo(char *output, HMODULE mod) static char *PrintModuleInfo(char *output, HMODULE mod)
{ {
char *buffer = alloca(MAX_PATH); char buffer[MAX_PATH];
DebugFileInfo dfi; DebugFileInfo dfi;
GetModuleFileName(mod, buffer, MAX_PATH); GetModuleFileName(mod, buffer, MAX_PATH);
GetFileInfo(&dfi, buffer); GetFileInfo(&dfi, buffer);