From cf2b9ec940e2ba6d7d87cb7e98540e787d64b4d7 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 18 Mar 2012 08:50:41 +0000 Subject: [PATCH] New "-clipmap" command-line switch to specify sector collision clip maps. This switch works in an additive fashion like -mx and -mh. _clipshape0.map through _clipshape9.map remain loaded by default. Also, a very minor change in the con/def module code. (int --> int32_t) git-svn-id: https://svn.eduke32.com/eduke32@2495 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 11 ++- polymer/eduke32/build/include/compat.h | 4 + polymer/eduke32/build/src/build.c | 9 +- polymer/eduke32/build/src/engine.c | 123 +++++++++++++++++-------- polymer/eduke32/source/astub.c | 33 ++++++- polymer/eduke32/source/game.c | 42 ++++++++- polymer/eduke32/source/game.h | 2 +- 7 files changed, 176 insertions(+), 48 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 11d5a6847..f658ba3fa 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -552,8 +552,8 @@ void initspritelists(void); int32_t loadboard(char *filename, char flags, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum); int32_t loadmaphack(const char *filename); void delete_maphack_lights(); -#if !defined DEBUG_MAIN_ARRAYS -int32_t clipmapinfo_load(const char *filename); +#ifdef HAVE_CLIPSHAPE_FEATURE +int32_t clipmapinfo_load(void); #endif int32_t saveboard(const char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum); int32_t loadpics(const char *filename, int32_t askedsize); @@ -783,7 +783,12 @@ extern char defsfilename[BMAX_PATH]; extern char *g_defNamePtr; extern char **g_defModules; -extern int g_defModulesNum; +extern int32_t g_defModulesNum; + +#ifdef HAVE_CLIPSHAPE_FEATURE +extern char **g_clipMapFiles; +extern int32_t g_clipMapFilesNum; +#endif #ifdef USE_OPENGL typedef struct diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 2e8b52798..83498f56c 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -128,6 +128,10 @@ static inline float nearbyintf(float x) # define DEBUG_MAIN_ARRAYS #endif +#if !defined DEBUG_MAIN_ARRAYS +# define HAVE_CLIPSHAPE_FEATURE +#endif + // redefined for apple/ppc, which chokes on stderr when linking... #define ERRprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 7b5020e63..a2ece50a4 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -627,10 +627,15 @@ int32_t app_main(int32_t argc, const char **argv) // Here used to be the 'whitecol' calculation -#if !defined DEBUG_MAIN_ARRAYS - k = clipmapinfo_load("_clipshape0.map"); +#ifdef HAVE_CLIPSHAPE_FEATURE + k = clipmapinfo_load(); if (k>0) initprintf("There was an error loading the sprite clipping map (status %d).\n", k); + + for (i=0; i < g_clipMapFilesNum; ++i) + Bfree (g_clipMapFiles[i]); + Bfree (g_clipMapFiles); + g_clipMapFiles = NULL; #endif taglab_init(); diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 263a57a64..f0b6b82db 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -49,7 +49,6 @@ #define CACHEAGETIME 16 #if !defined DEBUG_MAIN_ARRAYS -# define HAVE_CLIPSHAPE_FEATURE const int32_t engine_main_arrays_are_static = 0; // for Lunatic #else const int32_t engine_main_arrays_are_static = 1; @@ -1258,15 +1257,19 @@ static void clipmapinfo_init() numwalls = 0; } -// loads the clip maps 0 through 9. +// loads the clip maps. // this should be called before any real map is loaded. -int32_t clipmapinfo_load(const char *filename) +int32_t clipmapinfo_load(void) { int32_t i,k,w, px,py,pz; int16_t ang,cs; - char fn[BMAX_PATH], loadedwhich[32]={0}, *lwcp=loadedwhich; - int32_t slen, fi, fisec[10], fispr[10]; + int32_t lwcp = 0; + int32_t fi; + + int32_t *fisec = NULL; + int32_t *fispr = NULL; + int32_t ournumsectors=0, ournumwalls=0, ournumsprites=0; clipmapinfo_init(); @@ -1281,29 +1284,29 @@ int32_t clipmapinfo_load(const char *filename) return 1; } - Bmemset(fisec, 0, sizeof(fisec)); - Bmemset(fispr, 0, sizeof(fispr)); - - Bstrcpy(fn, filename); - slen = Bstrlen(fn); + fisec = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); + assert(fisec); + fispr = (int32_t *) Bcalloc(g_clipMapFilesNum, sizeof (int32_t)); + assert(fispr); quickloadboard = 1; - for (fi='0'; fi<='9'; fi++) + for (fi = 0; fi < g_clipMapFilesNum; ++fi) { - fisec[fi-'0'] = ournumsectors; - fispr[fi-'0'] = ournumsprites; + fisec[fi] = ournumsectors; + fispr[fi] = ournumsprites; - fn[slen-5] = fi; - i = loadboard(fn, 0, &px,&py,&pz, &ang,&cs); + i = loadboard(g_clipMapFiles[fi], 0, &px,&py,&pz, &ang,&cs); if (i<0) continue; // Numsprites will now be set! + initprintf("Loading clip map: %s\n", g_clipMapFiles[fi]); + if (ournumsectors+numsectors>MAXSECTORS || ournumwalls+numwalls>MAXWALLS || ournumsprites+Numsprites>MAXSPRITES) { - initprintf("clip map: warning: exceeded limits when loading %s, aborting.\n", fn); + initprintf("clip map: warning: exceeded limits when loading %s, aborting.\n", g_clipMapFiles[fi]); break; } @@ -1329,19 +1332,19 @@ int32_t clipmapinfo_load(const char *filename) ournumwalls += numwalls; ournumsprites += Numsprites; - if (lwcp != loadedwhich) - { - *lwcp++ = ','; - *lwcp++ = ' '; - } - *lwcp++ = fi; - *lwcp = 0; + ++lwcp; } quickloadboard = 0; if (ournumsectors==0 || ournumwalls==0 || ournumsprites==0) // nothing loaded { clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return -1; } @@ -1361,6 +1364,12 @@ int32_t clipmapinfo_load(const char *filename) if (!sectoidx || !sector || !wall) { clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 1; } for (i=0; i=fisec[fi]) break; - initprintf("clip map %d: error: tried to chain picnum %d (sprite %d) in sector %d which" - " already belongs to picnum %d.\n", fi, pn, i-fispr[fi], k-fisec[fi], + initprintf("clip map \"%s\": error: tried to chain picnum %d (sprite %d) in sector %d which" + " already belongs to picnum %d.\n", g_clipMapFiles[fi], pn, i-fispr[fi], k-fisec[fi], clipinfo[sectoidx[k]].picnum); clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 2; } @@ -1449,11 +1470,11 @@ int32_t clipmapinfo_load(const char *filename) { if (sprite[i].ang!=1536 && sprite[i].ang!=512) { - for (fi=0; fi<9; fi++) + for (fi = 0; fi < g_clipMapFilesNum; ++fi) if (i>=fispr[fi]) break; - initprintf("clip map %d: warning: sprite %d pointing neither northward nor southward. %s will be wrong.\n", - fi, i-fispr[fi], (sprite[i].cstat&48)==32 ? "Scaling and flipping" : "X-flipping"); + initprintf("clip map \"%s\": warning: sprite %d pointing neither northward nor southward. %s will be wrong.\n", + g_clipMapFiles[fi], i-fispr[fi], (sprite[i].cstat&48)==32 ? "Scaling and flipping" : "X-flipping"); } } @@ -1486,12 +1507,18 @@ int32_t clipmapinfo_load(const char *filename) { if (outersect>=0 && ns!=outersect) { - for (fi=0; fi<9; fi++) + for (fi = 0; fi < g_clipMapFilesNum; ++fi) if (ns>=fisec[fi]) break; - initprintf("clip map %d: error: encountered more than one outer sector (%d and %d)" - " for sprite %d.\n", fi, outersect-fisec[fi], ns-fisec[fi], i-fispr[fi]); + initprintf("clip map \"%s\": error: encountered more than one outer sector (%d and %d)" + " for sprite %d.\n", g_clipMapFiles[fi], outersect-fisec[fi], ns-fisec[fi], i-fispr[fi]); clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 3; } @@ -1500,13 +1527,19 @@ int32_t clipmapinfo_load(const char *filename) } else if (sectoidx[ns]!=numclipmaps) { - for (fi=0; fi<9; fi++) + for (fi = 0; fi < g_clipMapFilesNum; ++fi) if (ns>=fisec[fi]) break; - initprintf("clip map %d: error: encountered sector %d belonging to index %d" + initprintf("clip map \"%s\": error: encountered sector %d belonging to index %d" " while collecting sectors for sprite %d (index %d).\n", - fi, ns-fisec[fi], sectoidx[ns], i-fispr[fi], numclipmaps); + g_clipMapFiles[fi], ns-fisec[fi], sectoidx[ns], i-fispr[fi], numclipmaps); clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 4; } } @@ -1518,6 +1551,12 @@ int32_t clipmapinfo_load(const char *filename) { initprintf("clip map: INTERNAL ERROR: outersect==-1!\n"); clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 5; } @@ -1619,6 +1658,12 @@ int32_t clipmapinfo_load(const char *filename) if (!loadwallinv) { clipmapinfo_init(); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; + return 1; } @@ -1683,7 +1728,13 @@ int32_t clipmapinfo_load(const char *filename) numwalls = 0; initspritelists(); - initprintf("Loaded clip map%s %s.\n", lwcp==loadedwhich+1?"":"s", loadedwhich); + if (lwcp > 0) + initprintf("Loaded clip map%s.\n", lwcp==1?"":"s"); + + free(fisec); + fisec = NULL; + free(fispr); + fispr = NULL; return 0; } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index a0436fd36..0d8ea3ead 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -98,9 +98,14 @@ static int32_t g_skipDefaultCons = 0; static int32_t g_skipDefaultDefs = 0; // primarily for NAM/WWII GI appeasement char **g_scriptModules = NULL; -int g_scriptModulesNum = 0; +int32_t g_scriptModulesNum = 0; char **g_defModules = NULL; -int g_defModulesNum = 0; +int32_t g_defModulesNum = 0; + +#ifdef HAVE_CLIPSHAPE_FEATURE +char **g_clipMapFiles = NULL; +int32_t g_clipMapFilesNum = 0; +#endif #pragma pack(push,1) sound_t g_sounds[MAXSOUNDS]; @@ -8432,6 +8437,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { int32_t i = 1, j, maxlen=0, *lengths; char *c, *k; + char clipshape[16] = "_clipshape0.map"; mapster32_fullpath = argv[0]; @@ -8448,6 +8454,16 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) testplay_addparam = Bmalloc(maxlen+argc); testplay_addparam[0] = 0; + // pre-form the default 10 clipmaps + for (j = '0'; j<='9'; ++j) + { + clipshape[10] = j; + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen(clipshape) + 1); + Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], clipshape); + ++g_clipMapFilesNum; + } + j = 0; while (i < argc) @@ -8582,6 +8598,19 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) i++; continue; } + if (!Bstrcasecmp(c+1,"clipmap")) + { + if (argc > i+1) + { + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen((char *)argv[i+1]) + 1); + Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], (char *)argv[i+1]); + ++g_clipMapFilesNum; + i++; + } + i++; + continue; + } if (!Bstrcasecmp(c+1,"nm") || !Bstrcasecmp(c+1,"ns")) { COPYARG(i); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 18ef6c311..c7f362bd5 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -130,9 +130,14 @@ char *g_gameNamePtr = NULL; char *g_rtsNamePtr = NULL; char **g_scriptModules = NULL; -int g_scriptModulesNum = 0; +int32_t g_scriptModulesNum = 0; char **g_defModules = NULL; -int g_defModulesNum = 0; +int32_t g_defModulesNum = 0; + +#ifdef HAVE_CLIPSHAPE_FEATURE +char **g_clipMapFiles = NULL; +int32_t g_clipMapFilesNum = 0; +#endif #ifdef LUNATIC_ENABLE El_State g_ElState; @@ -8583,6 +8588,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { int16_t i = 1, j; char *c, *k; + char clipshape[16] = "_clipshape0.map"; ud.fta_on = 1; ud.god = 0; @@ -8603,6 +8609,16 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) g_player[0].wchoice[8] = 9; g_player[0].wchoice[9] = 1; + // pre-form the default 10 clipmaps + for (j = '0'; j<='9'; ++j) + { + clipshape[10] = j; + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen(clipshape) + 1); + Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], clipshape); + ++g_clipMapFilesNum; + } + if (argc > 1) { initprintf("Application parameters: "); @@ -8832,6 +8848,19 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) i++; continue; } + if (!Bstrcasecmp(c+1,"clipmap")) + { + if (argc > i+1) + { + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bmalloc(Bstrlen((char *)argv[i+1]) + 1); + Bstrcpy(g_clipMapFiles[g_clipMapFilesNum], (char *)argv[i+1]); + ++g_clipMapFilesNum; + i++; + } + i++; + continue; + } if (!Bstrcasecmp(c+1,"condebug")) { g_scriptDebug = 1; @@ -10374,9 +10403,14 @@ CLEAN_DIRECTORY: Bfree(ptr); } -#if !defined DEBUG_MAIN_ARRAYS - if ((i = clipmapinfo_load("_clipshape0.map")) > 0) +#ifdef HAVE_CLIPSHAPE_FEATURE + if ((i = clipmapinfo_load()) > 0) initprintf("There was an error loading the sprite clipping map (status %d).\n", i); + + for (i=0; i < g_clipMapFilesNum; ++i) + Bfree (g_clipMapFiles[i]); + Bfree (g_clipMapFiles); + g_clipMapFiles = NULL; #endif OSD_Exec("autoexec.cfg"); diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 6d12b79ba..e7841db52 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -184,7 +184,7 @@ extern char *g_scriptNamePtr; extern char *g_gameNamePtr; extern char *g_rtsNamePtr; extern char **g_scriptModules; -extern int g_scriptModulesNum; +extern int32_t g_scriptModulesNum; extern char CheatStrings[][MAXCHEATLEN]; extern char boardfilename[BMAX_PATH], currentboardfilename[BMAX_PATH]; extern char boardfilename[BMAX_PATH];