diff --git a/source/games/duke/CMakeLists.txt b/source/games/duke/CMakeLists.txt index 49f048b20..432e56efe 100644 --- a/source/games/duke/CMakeLists.txt +++ b/source/games/duke/CMakeLists.txt @@ -24,8 +24,6 @@ set( PCH_SOURCES src/zz_d_menu.cpp src/zz_demo.cpp src/zz_game.cpp - src/zz_gamedef.cpp - src/zz_gameexec.cpp src/zz_global.cpp src/zz_interpolate.cpp src/zz_namesdyn.cpp diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index c2091e202..0266fe16e 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -4689,7 +4689,7 @@ void getglobalz(int i) { if( s->statnum != 4 ) { - hittype[i].flags |= SFLAG_NOFLOORSHADOW; + hittype[i].aflags |= SFLAG_NOFLOORSHADOW; //hittype[i].dispicnum = -4; // No shadows on actors s->xvel = -256; ssp(i,CLIPMASK0); @@ -4697,7 +4697,7 @@ void getglobalz(int i) } else if(sprite[lz].picnum == TILE_APLAYER && badguy(s) ) { - hittype[i].flags |= SFLAG_NOFLOORSHADOW; + hittype[i].aflags |= SFLAG_NOFLOORSHADOW; //hittype[i].dispicnum = -4; // No shadows on actors s->xvel = -256; ssp(i,CLIPMASK0); diff --git a/source/games/duke/src/actors.h b/source/games/duke/src/actors.h index 456fbc2fe..73a6f1a49 100644 --- a/source/games/duke/src/actors.h +++ b/source/games/duke/src/actors.h @@ -137,7 +137,7 @@ typedef struct { int32_t t_data[10]; // 40b sometimes used to hold offsets to con code - int32_t flags; // 4b + int32_t aflags; // 4b union { vec3_t bpos; // 12b @@ -185,13 +185,12 @@ typedef struct } netactor_t; #pragma pack(pop) -typedef struct +// Todo - put more state in here +struct ActorInfo { - intptr_t *execPtr; // pointer to CON script for this tile, formerly actorscrptr - intptr_t *loadPtr; // pointer to load time CON script, formerly actorLoadEventScrPtr or something - uint32_t flags; // formerly SpriteFlags, ActorType - int32_t cacherange; // formerly SpriteCache -} tiledata_t; + uint32_t scriptaddress; + uint32_t flags; +}; // KEEPINSYNC lunatic/con_lang.lua @@ -262,7 +261,7 @@ enum pflags_t PROJECTILE_TYPE_MASK = PROJECTILE_HITSCAN | PROJECTILE_RPG | PROJECTILE_KNEE | PROJECTILE_BLOOD, }; -extern tiledata_t g_tile[MAXTILES]; +extern ActorInfo actorinfo[MAXTILES]; extern actor_t actor[MAXSPRITES]; extern actor_t* hittype; extern int32_t block_deletesprite; @@ -337,7 +336,7 @@ EXTERN_INLINE_HEADER int A_CheckEnemySprite(void const * s); ACTOR_INLINE int A_CheckEnemyTile(int const tileNum) { - return ((g_tile[tileNum].flags & (SFLAG_BADGUY_TILE | SFLAG_BADGUY)) != 0); + return ((actorinfo[tileNum].flags & (SFLAG_BADGUY_TILE | SFLAG_BADGUY)) != 0); } int ssp(short i, unsigned int cliptype); //The set sprite function diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index a1eec057b..5ea72b603 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -456,11 +456,7 @@ int movesprite_d(short spritenum, int xchange, int ychange, int zchange, unsigne { if (sprite[spritenum].picnum == LIZMAN) cd = 292; -#if 0 // TRANSITIONAL the needed infrastructure for this is too different for now - else if ((actortype[sprite[spritenum].picnum] & 3)) -#else - else if (A_CheckSpriteFlags(spritenum, SFLAG_BADGUY)) -#endif + else if (actorflag(spritenum, SFLAG_BADGUY)) cd = sprite[spritenum].clipdist << 2; else cd = 192; diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index ab09199c0..a4ef32df0 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -625,7 +625,7 @@ void movefta_r(void) default: #if 0 // TRANSITIONAL: RedNukem has this here. Needed? - if (A_CheckSpriteFlags(spriteNum, SFLAG_USEACTIVATOR) && sector[sprite[spriteNum].sectnum].lotag & 16384) break; + if (actorflag(spriteNum, SFLAG_USEACTIVATOR) && sector[sprite[spriteNum].sectnum].lotag & 16384) break; #endif hittype[i].timetosleep = 0; check_fta_sounds(i); diff --git a/source/games/duke/src/duke3d_ed.h b/source/games/duke/src/duke3d_ed.h index 5b52361c4..05ec40488 100644 --- a/source/games/duke/src/duke3d_ed.h +++ b/source/games/duke/src/duke3d_ed.h @@ -38,7 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_DUKE_NS #define VOLUMEALL (g_Shareware == 0) -#define PLUTOPAK (g_scriptVersion >= 14) +#define PLUTOPAK (true)//g_scriptVersion >= 14) #define VOLUMEONE (g_Shareware == 1) // increase by 3, because atomic GRP adds 1, and Shareware adds 2 @@ -196,17 +196,6 @@ enum GameFunction_t NUM_ACTIONS }; -static inline int32_t G_HaveActor(int spriteNum) -{ - return g_tile[spriteNum].execPtr!=NULL; -} - -static inline int32_t G_DefaultActorHealth(int spriteNum) // rename! -{ - return G_HaveActor(spriteNum) ? g_tile[spriteNum].execPtr[0] : 0; -} - - struct GameInterface : ::GameInterface { const char* Name() override { return "Redneck"; } diff --git a/source/games/duke/src/game.h b/source/games/duke/src/game.h index 9b7fc112f..15a178c87 100644 --- a/source/games/duke/src/game.h +++ b/source/games/duke/src/game.h @@ -310,14 +310,17 @@ inline int32_t G_GetTeamPalette(int32_t team) return pal[team]; } -#define A_CheckSpriteFlags(spriteNum, iType) (((g_tile[sprite[spriteNum].picnum].flags^actor[spriteNum].flags) & iType) != 0) +inline int actorflag(int spritenum, int mask) +{ + return (((actorinfo[sprite[spritenum].picnum].flags/* ^ actor[spritenum].flags*/) & mask) != 0); +} inline int actorfella(int spnum) { - return A_CheckSpriteFlags(spnum, SFLAG_KILLCOUNT); + return actorflag(spnum, SFLAG_KILLCOUNT); } // (unsigned)iPicnum check: AMC TC Rusty Nails, bayonet MG alt. fire, iPicnum == -1 (via aplWeaponShoots) -#define A_CheckSpriteTileFlags(iPicnum, iType) (((unsigned)iPicnum < MAXTILES) && (g_tile[iPicnum].flags & iType) != 0) +#define A_CheckSpriteTileFlags(iPicnum, iType) (((unsigned)iPicnum < MAXTILES) && (actorinfo[iPicnum].flags & iType) != 0) #define S_StopSound(num) S_StopEnvSound(num, -1) extern int G_StartRTS(int lumpNum, int localPlayer); diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index c45ba1ef1..c5f68c4bb 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -52,14 +52,14 @@ int line_number; int labelcnt; int errorcount, warningcount; // was named 'error' and 'warning' which is too generic for public variables and may clash with other code. int g_currentSourceFile; -intptr_t parsing_actor, parsing_event; +uint32_t parsing_actor, parsing_event; int parsing_state; int num_squigilly_brackets; int checking_ifelse; //G_EXTERN char tempbuf[MAXSECTORS << 1], buf[1024]; todo - move to compile state. tempbuf gets used nearly everywhere as scratchpad memory. extern char tempbuf[]; -extern intptr_t* scriptptr; +extern intptr_t* scriptaddress; extern int* labelcode; extern intptr_t* apScript; @@ -421,22 +421,22 @@ static void setscriptvalue(int offset, int value) static void appendscriptvalue(int value) { - *scriptptr++ = value; + *scriptaddress++ = value; } static int popscriptvalue() { - return *--scriptptr; + return *--scriptaddress; } int scriptpos() { - return int(scriptptr - apScript); + return int(scriptaddress - apScript); } void appendlabeladdress(int offset = 0) { - labelcode[labelcnt++] = int(scriptptr - apScript) + offset; + labelcode[labelcnt++] = int(scriptaddress - apScript) + offset; labelcnt++; } @@ -448,7 +448,7 @@ void appendlabelvalue(int value) void reservescriptspace(int space) { - scriptptr += space; + scriptaddress += space; } @@ -754,7 +754,7 @@ int parsecommand() { transnum(); popscriptvalue(); - j |= *scriptptr; + j |= *scriptaddress; } appendscriptvalue(j); } @@ -793,7 +793,7 @@ int parsecommand() transnum(); // Volume Number (0/4) popscriptvalue(); - k = *scriptptr - 1; + k = *scriptaddress - 1; if (k == -1) k = MAXVOLUMES; if (k >= 0) // if it's background music @@ -975,20 +975,16 @@ int parsecommand() transnum(); lnum = popscriptvalue(); -#if 1 - g_tile[lnum].execPtr = apScript + parsing_actor; // TRANSITIONAL should only store an index + + actorinfo[lnum].scriptaddress = parsing_actor; // TRANSITIONAL should only store an index if (tw == concmd_useractor) { if (j & 1) - g_tile[lnum].flags |= SFLAG_BADGUY; + actorinfo[lnum].flags |= SFLAG_BADGUY; if (j & 2) - g_tile[lnum].flags |= (SFLAG_BADGUY | SFLAG_BADGUYSTAYPUT); + actorinfo[lnum].flags |= (SFLAG_BADGUY | SFLAG_BADGUYSTAYPUT); } -#else - actorscrptr[lnum] = parsing_actor; - actortype[lnum] = j; -#endif for (j = 0; j < 4; j++) { @@ -1014,7 +1010,7 @@ int parsecommand() } transnum(); // This code was originally here but is a no-op, because both source and destination are the same here. - //*(parsing_actor + j) = *(scriptptr - 1); + //*(parsing_actor + j) = *(scriptaddress - 1); } } @@ -1042,7 +1038,7 @@ int parsecommand() transnum(); popscriptvalue(); - j = *scriptptr; // type of event + j = *scriptaddress; // type of event if (j< 0 || j> EVENT_MAXEVENT) { Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Invalid Event ID.\n", fn, line_number); @@ -1133,7 +1129,7 @@ int parsecommand() { checking_ifelse--; tempscrptr = scriptpos(); - scriptptr++; //Leave a spot for the fail location + scriptaddress++; //Leave a spot for the fail location parsecommand(); setscriptvalue(tempscrptr, scriptpos()); } @@ -1309,7 +1305,7 @@ int parsecommand() { transnum(); popscriptvalue(); - j |= *scriptptr; + j |= *scriptaddress; } while (keyword() == -1); appendscriptvalue(j); goto if_common; @@ -1410,7 +1406,7 @@ int parsecommand() popscriptvalue(); transnum(); popscriptvalue(); - j = *scriptptr; + j = *scriptaddress; while (*textptr == ' ' || *textptr == '\t') textptr++; i = 0; @@ -1428,7 +1424,7 @@ int parsecommand() popscriptvalue(); transnum(); popscriptvalue(); - j = *scriptptr; + j = *scriptaddress; while (*textptr == ' ') textptr++; i = 0; @@ -1447,10 +1443,10 @@ int parsecommand() popscriptvalue(); transnum(); popscriptvalue(); - j = *scriptptr; + j = *scriptaddress; transnum(); popscriptvalue(); - k = *scriptptr; + k = *scriptaddress; while (*textptr == ' ') textptr++; i = 0; @@ -1494,7 +1490,7 @@ int parsecommand() case concmd_definequote: popscriptvalue(); transnum(); - k = *(scriptptr - 1); + k = *(scriptaddress - 1); if (k >= MAXQUOTES) { Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Quote number exceeds limit of %d.\n", line_number, MAXQUOTES); @@ -1518,7 +1514,7 @@ int parsecommand() { popscriptvalue(); transnum(); - k = *(scriptptr - 1); + k = *(scriptaddress - 1); popscriptvalue(); i = 0; while (*textptr == ' ') @@ -1533,19 +1529,19 @@ int parsecommand() parsebuffer.Push(0); transnum(); - int ps = *(scriptptr - 1); + int ps = *(scriptaddress - 1); popscriptvalue(); transnum(); - int pe = *(scriptptr - 1); + int pe = *(scriptaddress - 1); popscriptvalue(); transnum(); - int pr = *(scriptptr - 1); + int pr = *(scriptaddress - 1); popscriptvalue(); transnum(); - int m = *(scriptptr - 1); + int m = *(scriptaddress - 1); popscriptvalue(); transnum(); - int vo = *(scriptptr - 1); + int vo = *(scriptaddress - 1); popscriptvalue(); S_DefineSound(k, parsebuffer.Data(), ps, pe, pr, m, vo, 1.f); return 0; @@ -1668,7 +1664,7 @@ int parsecommand() max_ammo_amount[14] = parseone(); max_ammo_amount[16] = parseone(); } - scriptptr++; + scriptaddress++; } return 0; } @@ -1713,24 +1709,24 @@ void compilecon(const char *filenam) void loadcons(const char* filenam) { + for (int i = 0; i < MAXTILES; i++) + { + memset(&actorinfo[i], 0, sizeof(actorinfo)); + } + + apScript = (intptr_t*)Xcalloc(1, g_scriptSize * sizeof(intptr_t)); + labelcnt = 0; SortCommands(); -#if 0 ClearGameEvents(); -#endif - ClearGameVars(); AddSystemVars(); - - //memset(actorscrptr, 0, MAXSPRITES); - //memset(actortype, 0, MAXSPRITES); - auto before = I_nsTime(); - scriptptr = apScript + 1; + scriptaddress = apScript + 1; compilecon(filenam); //Tokenize if (userConfig.AddCons) for (FString& m : *userConfig.AddCons.get()) @@ -1748,7 +1744,7 @@ void loadcons(const char* filenam) { auto after = I_nsTime(); Printf("Compilation time:%.2f ms, Code Size:%d bytes. %d labels. %d/%d Variables.\n", (after-before) / 1000000., - ((scriptptr - apScript) << 2) - 4, + ((scriptaddress - apScript) << 2) - 4, labelcnt, 0,//iGameVarCount, MAXGAMEVARS diff --git a/source/games/duke/src/gamedef.h b/source/games/duke/src/gamedef.h index c6e2deb00..4b5d1fc8e 100644 --- a/source/games/duke/src/gamedef.h +++ b/source/games/duke/src/gamedef.h @@ -54,7 +54,7 @@ extern int32_t g_totalLines; extern int warningcount; extern int32_t otherp; -extern intptr_t *scriptptr; +extern intptr_t *scriptaddress; int32_t C_AllocQuote(int32_t qnum); @@ -67,7 +67,7 @@ void C_DefineMusic(int volumeNum, int levelNum, const char *fileName); void C_DefineVolumeFlags(int32_t vol, int32_t flags); void ReportError(int32_t iError); -void C_Compile(const char *filenam); +void loadcons(const char *filenam); extern int32_t g_errorLineNum; extern int32_t g_tw; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 11b01928b..a2e197759 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1517,7 +1517,7 @@ int parse(void) default: Printf(TEXTCOLOR_RED "Unrecognized PCode of %ld in parse. Killing current sprite.\n",*insptr); - Printf(TEXTCOLOR_RED "Offset=%0lX\n",scriptptr-apScript); + Printf(TEXTCOLOR_RED "Offset=%0lX\n",scriptaddress-apScript); killit_flag = 1; break; } @@ -1536,13 +1536,8 @@ void execute(int i,int p,int x) g_sp = &sprite[g_i]; // Pointer to sprite structure g_t = &hittype[g_i].temp_data[0]; // Sprite's 'extra' data -#if 1 - if (!g_tile[g_sp->picnum].execPtr) return; - insptr = 4 + (g_tile[g_sp->picnum].execPtr); -#else - if( actorscrptr[g_sp->picnum] == 0 ) return; - insptr = 4 + (actorscrptr[g_sp->picnum]); -#endif + if (actorinfo[g_sp->picnum].scriptaddress == 0) return; + insptr = apScript + 4 + (actorinfo[g_sp->picnum].scriptaddress); killit_flag = 0; @@ -1612,4 +1607,64 @@ quit: } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void OnEvent(int iEventID, int p, int i, int x) +{ + int og_i, og_p; + int og_x; + int* og_t; + spritetype* og_sp; + uint8_t okillit_flag; + intptr_t* oinsptr; + + char done; + + if (iEventID >= MAXGAMEEVENTS) + { + Printf("Invalid Event ID\n"); + return; + } + if (apScriptGameEvent[iEventID] == 0) + { + return; + } + + // save current values... + og_i = g_i; + og_p = g_p; + og_x = g_x; + og_sp = g_sp; + og_t = g_t; + okillit_flag = killit_flag; + oinsptr = insptr; + + g_i = i; // current sprite ID + g_p = p; /// current player ID + g_x = x; // ? + g_sp = &sprite[g_i]; + g_t = &hittype[g_i].temp_data[0]; + + insptr = apScript + apScriptGameEvent[iEventID]; + + killit_flag = 0; + do + done = parse(); + while (done == 0); + + // restore old values... + g_i = og_i; + g_p = og_p; + g_x = og_x; + g_sp = og_sp; + g_t = og_t; + killit_flag = okillit_flag; + insptr = oinsptr; +} + + END_DUKE_NS diff --git a/source/games/duke/src/gameexec.h b/source/games/duke/src/gameexec.h index 7b60f68b1..401a6fb9e 100644 --- a/source/games/duke/src/gameexec.h +++ b/source/games/duke/src/gameexec.h @@ -28,67 +28,95 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gamedef.h" // vmstate_t BEGIN_DUKE_NS -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum, int const nDist, int32_t const nReturn); -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum, int const nDist); -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum); -int32_t VM_ExecuteEventWithValue(int const nEventID, int const spriteNum, int const playerNum, int32_t const nReturn); -static FORCE_INLINE int VM_HaveEvent(int const nEventID) +enum { - return !!apScriptGameEvent[nEventID]; -} + EVENT_INIT = 0, + EVENT_ENTERLEVEL, + EVENT_RESETWEAPONS, // for each player + EVENT_RESETINVENTORY, // for each player + EVENT_HOLSTER, // for each player + EVENT_LOOKLEFT, // for each player + EVENT_LOOKRIGHT, // for each player + EVENT_SOARUP, // for each player + EVENT_SOARDOWN, // for each player + EVENT_CROUCH, // for each player + EVENT_JUMP, // for each player + EVENT_RETURNTOCENTER, // for each player + EVENT_LOOKUP, // for each player + EVENT_LOOKDOWN, // for each player + EVENT_AIMUP, // for each player + EVENT_AIMDOWN, // for each player + EVENT_FIRE, // for each player + EVENT_CHANGEWEAPON, // for each player + EVENT_GETSHOTRANGE, // for each player + EVENT_GETAUTOAIMANGLE, // for each player + EVENT_GETLOADTILE, -static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum, int playerNum, int nDist, int32_t nReturn) -{ - return VM_HaveEvent(nEventID) ? VM_ExecuteEvent(nEventID, spriteNum, playerNum, nDist, nReturn) : nReturn; -} + EVENT_CHEATGETSTEROIDS, + EVENT_CHEATGETHEAT, + EVENT_CHEATGETBOOT, + EVENT_CHEATGETSHIELD, + EVENT_CHEATGETSCUBA, + EVENT_CHEATGETHOLODUKE, + EVENT_CHEATGETJETPACK, + EVENT_CHEATGETFIRSTAID, + EVENT_QUICKKICK, + EVENT_INVENTORY, + EVENT_USENIGHTVISION, + EVENT_USESTEROIDS, + EVENT_INVENTORYLEFT, + EVENT_INVENTORYRIGHT, + EVENT_HOLODUKEON, + EVENT_HOLODUKEOFF, + EVENT_USEMEDKIT, + EVENT_USEJETPACK, + EVENT_TURNAROUND, -static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum, int playerNum, int nDist) -{ - return VM_HaveEvent(nEventID) ? VM_ExecuteEvent(nEventID, spriteNum, playerNum, nDist) : 0; -} + EVENT_NUMEVENTS, + EVENT_MAXEVENT = EVENT_NUMEVENTS - 1 +}; -static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum = -1, int playerNum = -1) -{ - return VM_HaveEvent(nEventID) ? VM_ExecuteEvent(nEventID, spriteNum, playerNum) : 0; -} -inline int OnEvent(int id, int pnum, int snum, int what) + +void OnEvent(int id, int pnum = -1, int snum = -1, int dist = -1); + +static FORCE_INLINE int32_t VM_OnEvent(int nEventID, int spriteNum=-1, int playerNum=-1, int nDist=-1, int32_t nReturn=0) { - return VM_OnEvent(id, snum, pnum, what); + // set return + if (IsGameEvent(nEventID)) + { + SetGameVarID(g_iReturnVarID, nReturn, spriteNum, playerNum); + OnEvent(nEventID, spriteNum, playerNum, -1); + return GetGameVarID(g_iReturnVarID, spriteNum, playerNum); + } + return nReturn; } static FORCE_INLINE int32_t VM_OnEventWithReturn(int nEventID, int spriteNum, int playerNum, int32_t nReturn) { - return VM_HaveEvent(nEventID) ? VM_ExecuteEventWithValue(nEventID, spriteNum, playerNum, nReturn) : nReturn; + // set return + if (IsGameEvent(nEventID)) + { + SetGameVarID(g_iReturnVarID, nReturn, spriteNum, playerNum); + OnEvent(nEventID, spriteNum, playerNum, -1); + return GetGameVarID(g_iReturnVarID, spriteNum, playerNum); + } + return nReturn; } extern int32_t ticrandomseed; -extern int32_t g_tw; -extern int32_t g_currentEvent; -extern int32_t g_errorLineNum; - void execute(int s, int p, int d); + void makeitfall(int s); int furthestangle(int spriteNum, int angDiv); void getglobalz(int s); int getincangle(int c, int n); -//void G_RestoreMapState(); -//void G_SaveMapState(); - -#define CON_ERRPRINTF(Text, ...) do { \ - Printf("Line %d, %s: " Text, g_errorLineNum, VM_GetKeywordForID(g_tw), ## __VA_ARGS__); \ -} while (0) - -#define CON_CRITICALERRPRINTF(Text, ...) do { \ - I_Error("Line %d, %s: " Text, VM_DECODE_LINE_NUMBER(g_tw), VM_GetKeywordForID(VM_DECODE_INST(g_tw)), ## __VA_ARGS__); \ -} while (0) void G_GetTimeDate(int32_t * pValues); int G_StartTrack(int levelNum); -void VM_UpdateAnim(int spriteNum, int32_t *pData); END_DUKE_NS diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index 74355de0b..ae9923531 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -420,7 +420,6 @@ int *GetGameValuePtr(char *szGameLabel) } -#if 0 //--------------------------------------------------------------------------- // // Event stuff @@ -455,66 +454,6 @@ bool IsGameEvent(int i) // //--------------------------------------------------------------------------- -void OnEvent(int iEventID, short i,short p,long x) -{ - int og_i,og_p; - int og_x; - int *og_t; - spritetype *og_sp; - uint8_t okillit_flag; - intptr_t *oinsptr; - - char done; - - if( iEventID >= MAXGAMEEVENTS) - { - Printf("Invalid Event ID\n"); - return; - } - if( apScriptGameEvent[iEventID] == 0 ) - { - return; - } - - // save current values... - og_i=g_i; - og_p=g_p; - og_x=g_x; - og_sp=g_sp; - og_t=g_t; - okillit_flag=killit_flag; - oinsptr=insptr; - - g_i = i; // current sprite ID - g_p = p; /// current player ID - g_x = x; // ? - g_sp = &sprite[g_i]; - g_t = &hittype[g_i].temp_data[0]; - - insptr = (apScriptGameEvent[iEventID]); - - killit_flag = 0; - do - done = parse(); - while( done == 0 ); - - // restore old values... - g_i=og_i; - g_p=og_p; - g_x=og_x; - g_sp=og_sp; - g_t=og_t; - killit_flag=okillit_flag; - insptr=oinsptr; -} -#endif - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - int *aplWeaponClip[MAX_WEAPONS]; // number of items in clip int *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire) int *aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire diff --git a/source/games/duke/src/gamevar.h b/source/games/duke/src/gamevar.h index 0b9532db1..6ca2a6cbb 100644 --- a/source/games/duke/src/gamevar.h +++ b/source/games/duke/src/gamevar.h @@ -3,55 +3,6 @@ BEGIN_DUKE_NS // gamedef.c -//void OnEvent(int iEventID, int i,int p,int x); - -enum -{ - EVENT_INIT = 0, - EVENT_ENTERLEVEL, - EVENT_RESETWEAPONS, // for each player - EVENT_RESETINVENTORY, // for each player - EVENT_HOLSTER, // for each player - EVENT_LOOKLEFT, // for each player - EVENT_LOOKRIGHT, // for each player - EVENT_SOARUP, // for each player - EVENT_SOARDOWN, // for each player - EVENT_CROUCH, // for each player - EVENT_JUMP, // for each player - EVENT_RETURNTOCENTER, // for each player - EVENT_LOOKUP, // for each player - EVENT_LOOKDOWN, // for each player - EVENT_AIMUP, // for each player - EVENT_AIMDOWN, // for each player - EVENT_FIRE, // for each player - EVENT_CHANGEWEAPON, // for each player - EVENT_GETSHOTRANGE, // for each player - EVENT_GETAUTOAIMANGLE, // for each player - EVENT_GETLOADTILE, - - EVENT_CHEATGETSTEROIDS, - EVENT_CHEATGETHEAT, - EVENT_CHEATGETBOOT, - EVENT_CHEATGETSHIELD, - EVENT_CHEATGETSCUBA, - EVENT_CHEATGETHOLODUKE, - EVENT_CHEATGETJETPACK, - EVENT_CHEATGETFIRSTAID, - EVENT_QUICKKICK, - EVENT_INVENTORY, - EVENT_USENIGHTVISION, - EVENT_USESTEROIDS, - EVENT_INVENTORYLEFT, - EVENT_INVENTORYRIGHT, - EVENT_HOLODUKEON, - EVENT_HOLODUKEOFF, - EVENT_USEMEDKIT, - EVENT_USEJETPACK, - EVENT_TURNAROUND, - - EVENT_NUMEVENTS, - EVENT_MAXEVENT = EVENT_NUMEVENTS-1 -}; enum { diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 30cb303fb..ece5c61f6 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -61,8 +61,8 @@ enum DUKE3D_GLOBALFLAGS { }; G_EXTERN actor_t actor[MAXSPRITES]; -// g_tile: tile-specific data THAT DOES NOT CHANGE during the course of a game -G_EXTERN tiledata_t g_tile[MAXTILES]; +// actorinfo: tile-specific data THAT DOES NOT CHANGE during the course of a game +G_EXTERN ActorInfo actorinfo[MAXTILES]; G_EXTERN animwalltype animwall[MAXANIMWALLS]; extern char *label; G_EXTERN char g_loadFromGroupOnly; @@ -202,7 +202,20 @@ G_EXTERN int16_t ambienthitag[64]; G_EXTERN uint32_t g_ambientCnt; G_EXTERN intptr_t *apScript; -G_EXTERN intptr_t *scriptptr; +G_EXTERN intptr_t *scriptaddress; + +inline int32_t G_HaveActor(int spriteNum) +{ + return actorinfo[spriteNum].scriptaddress != NULL; +} + +inline int32_t G_DefaultActorHealth(int spriteNum) // rename! +{ + return G_HaveActor(spriteNum) ? apScript[actorinfo[spriteNum].scriptaddress] : 0; +} + + + G_EXTERN vec2_t g_origins[MAXANIMPOINTS]; struct msx_ diff --git a/source/games/duke/src/zz_actors.cpp b/source/games/duke/src/zz_actors.cpp index 332a8b84f..4556a3eff 100644 --- a/source/games/duke/src/zz_actors.cpp +++ b/source/games/duke/src/zz_actors.cpp @@ -294,8 +294,8 @@ static void G_DoEffectorLights(void) // STATNUM 14 { case SE_49_POINT_LIGHT: { - if (!A_CheckSpriteFlags(i, SFLAG_NOLIGHT) && videoGetRenderMode() == REND_POLYMER && - !(A_CheckSpriteFlags(i, SFLAG_USEACTIVATOR) && sector[sprite[i].sectnum].lotag & 16384)) + if (!actorflag(i, SFLAG_NOLIGHT) && videoGetRenderMode() == REND_POLYMER && + !(actorflag(i, SFLAG_USEACTIVATOR) && sector[sprite[i].sectnum].lotag & 16384)) { if (actor[i].lightptr == NULL) { @@ -360,8 +360,8 @@ static void G_DoEffectorLights(void) // STATNUM 14 } case SE_50_SPOT_LIGHT: { - if (!A_CheckSpriteFlags(i, SFLAG_NOLIGHT) && videoGetRenderMode() == REND_POLYMER && - !(A_CheckSpriteFlags(i, SFLAG_USEACTIVATOR) && sector[sprite[i].sectnum].lotag & 16384)) + if (!actorflag(i, SFLAG_NOLIGHT) && videoGetRenderMode() == REND_POLYMER && + !(actorflag(i, SFLAG_USEACTIVATOR) && sector[sprite[i].sectnum].lotag & 16384)) { if (actor[i].lightptr == NULL) { @@ -466,7 +466,7 @@ static void A_DoLight(int spriteNum) if (((sector[pSprite->sectnum].floorz - sector[pSprite->sectnum].ceilingz) < 16) || pSprite->z > sector[pSprite->sectnum].floorz || pSprite->z > actor[spriteNum].floorz || (pSprite->picnum != TILE_SECTOREFFECTOR && ((pSprite->cstat & 32768) || pSprite->yrepeat < 4)) || - A_CheckSpriteFlags(spriteNum, SFLAG_NOLIGHT) || (A_CheckSpriteFlags(spriteNum, SFLAG_USEACTIVATOR) && sector[pSprite->sectnum].lotag & 16384)) + actorflag(spriteNum, SFLAG_NOLIGHT) || (actorflag(spriteNum, SFLAG_USEACTIVATOR) && sector[pSprite->sectnum].lotag & 16384)) { if (actor[spriteNum].lightptr != NULL) A_DeleteLight(spriteNum); @@ -505,7 +505,7 @@ static void A_DoLight(int spriteNum) case ACCESSSWITCH__STATIC: case ACCESSSWITCH2__STATIC: { - if ((pSprite->cstat & 32768) || A_CheckSpriteFlags(spriteNum, SFLAG_NOLIGHT)) + if ((pSprite->cstat & 32768) || actorflag(spriteNum, SFLAG_NOLIGHT)) { if (actor[spriteNum].lightptr != NULL) A_DeleteLight(spriteNum); diff --git a/source/games/duke/src/zz_game.cpp b/source/games/duke/src/zz_game.cpp index 38a4e97ae..b3079328c 100644 --- a/source/games/duke/src/zz_game.cpp +++ b/source/games/duke/src/zz_game.cpp @@ -1319,14 +1319,15 @@ void G_DumpDebugInfo(void) // else only if it equals 0. static int32_t G_InitActor(int32_t i, int32_t tilenum, int32_t set_movflag_uncond) { - if (g_tile[tilenum].execPtr) + if (actorinfo[tilenum].scriptaddress) { - SH(i) = *(g_tile[tilenum].execPtr); - AC_ACTION_ID(actor[i].t_data) = *(g_tile[tilenum].execPtr+1); - AC_MOVE_ID(actor[i].t_data) = *(g_tile[tilenum].execPtr+2); + auto sa = &apScript[actorinfo[tilenum].scriptaddress]; + SH(i) = sa[0]; + AC_ACTION_ID(actor[i].t_data) = sa[1]; + AC_MOVE_ID(actor[i].t_data) = sa[2]; - if (set_movflag_uncond || (*(g_tile[tilenum].execPtr + 3) && SHT(i) == 0)) // AC_MOVFLAGS - SHT(i) = *(g_tile[tilenum].execPtr+3); + if (set_movflag_uncond || (sa[3] && SHT(i) == 0)) // AC_MOVFLAGS + SHT(i) = sa[3]; return 1; } @@ -1555,7 +1556,7 @@ default_case: if (pSprite->xrepeat == 0 || pSprite->yrepeat == 0) pSprite->xrepeat = pSprite->yrepeat = 1; - if (A_CheckSpriteFlags(newSprite, SFLAG_BADGUY)) + if (actorflag(newSprite, SFLAG_BADGUY)) { if (ud.monsters_off == 1) { @@ -1566,10 +1567,10 @@ default_case: makeitfall(newSprite); - if (A_CheckSpriteFlags(newSprite, SFLAG_BADGUYSTAYPUT)) + if (actorflag(newSprite, SFLAG_BADGUYSTAYPUT)) pActor->actorstayput = pSprite->sectnum; - if (!RR || A_CheckSpriteFlags(newSprite, SFLAG_KILLCOUNT)) + if (!RR || actorflag(newSprite, SFLAG_KILLCOUNT)) g_player[myconnectindex].ps->max_actors_killed++; pSprite->clipdist = 80; @@ -3154,7 +3155,7 @@ rr_badguy: pSprite->cstat |= 257; if (pSprite->picnum != TILE_SHARK) - if (!RR || A_CheckSpriteFlags(newSprite, SFLAG_KILLCOUNT)) + if (!RR || actorflag(newSprite, SFLAG_KILLCOUNT)) g_player[myconnectindex].ps->max_actors_killed++; } @@ -3270,7 +3271,7 @@ rr_badguy: changespritestat(newSprite, STAT_MISC); goto SPAWN_END; } - if (!RR || A_CheckSpriteFlags(newSprite, SFLAG_KILLCOUNT)) + if (!RR || actorflag(newSprite, SFLAG_KILLCOUNT)) g_player[myconnectindex].ps->max_actors_killed++; pActor->t_data[5] = 0; if (ud.monsters_off == 1) @@ -3616,8 +3617,10 @@ rr_badguy: /* XXX: fi.fall-through intended? */ fallthrough__; #endif + case SE_49_POINT_LIGHT: case SE_50_SPOT_LIGHT: +#ifdef POLYMER { int32_t j, nextj; @@ -3625,6 +3628,7 @@ rr_badguy: if (sprite[j].picnum == TILE_ACTIVATOR || sprite[j].picnum == TILE_ACTIVATORLOCKED) pActor->flags |= SFLAG_USEACTIVATOR; } +#endif changespritestat(newSprite, pSprite->lotag==46 ? STAT_EFFECTOR : STAT_LIGHT); goto SPAWN_END; break; @@ -4341,7 +4345,7 @@ static int G_MaybeTakeOnFloorPal(tspritetype *pSprite, int sectNum) { int const floorPal = sector[sectNum].floorpal; - if (floorPal && !lookups.noFloorPal(floorPal) && !A_CheckSpriteFlags(pSprite->owner, SFLAG_NOPAL)) + if (floorPal && !lookups.noFloorPal(floorPal) && !actorflag(pSprite->owner, SFLAG_NOPAL)) { pSprite->pal = floorPal; return 1; @@ -5061,7 +5065,7 @@ default_case1: { // Display TILE_APLAYER sprites with action PSTAND when viewed through // a camera. - const intptr_t *aplayer_scr = g_tile[TILE_APLAYER].execPtr; + auto aplayer_scr = apScript + actorinfo[TILE_APLAYER].scriptaddress; // [0]=strength, [1]=actionofs, [2]=moveofs scrofs_action = aplayer_scr[1]; @@ -5351,7 +5355,7 @@ skip: // player has nightvision on. We should pass stuff like "from which player is this view // supposed to be" as parameters ("drawing context") instead of relying on globals. if (!RR && g_player[screenpeek].ps->inv_amount[GET_HEATS] > 0 && g_player[screenpeek].ps->heat_on && - (A_CheckEnemySprite(pSprite) || A_CheckSpriteFlags(t->owner,SFLAG_NVG) || pSprite->picnum == TILE_APLAYER || pSprite->statnum == STAT_DUMMYPLAYER)) + (A_CheckEnemySprite(pSprite) || actorflag(t->owner,SFLAG_NVG) || pSprite->picnum == TILE_APLAYER || pSprite->statnum == STAT_DUMMYPLAYER)) { t->pal = 6; t->shade = 0; @@ -5361,7 +5365,7 @@ skip: t->shade = -127; // Fake floor shadow, implemented by inserting a new tsprite. - if (pSprite->statnum == STAT_DUMMYPLAYER || A_CheckEnemySprite(pSprite) || A_CheckSpriteFlags(t->owner,SFLAG_SHADOW) || (pSprite->picnum == TILE_APLAYER && pSprite->owner >= 0)) + if (pSprite->statnum == STAT_DUMMYPLAYER || A_CheckEnemySprite(pSprite) || actorflag(t->owner,SFLAG_SHADOW) || (pSprite->picnum == TILE_APLAYER && pSprite->owner >= 0)) if ((!RR || (pSprite->cstat&48) == 0) && t->statnum != TSPR_TEMP && pSprite->picnum != TILE_EXPLOSION2 && (RR || pSprite->picnum != TILE_HANGLIGHT) && pSprite->picnum != TILE_DOMELITE && (RR || pSprite->picnum != TILE_HOTMEAT) && (!RR || pSprite->picnum != TILE_TORNADO) && (!RR || pSprite->picnum != TILE_EXPLOSION3) && (!RR || RRRA || pSprite->picnum != TILE_SBMOVE)) { @@ -5376,7 +5380,7 @@ skip: continue; } - if (actor[i].flags & SFLAG_NOFLOORSHADOW) + if (actor[i].aflags & SFLAG_NOFLOORSHADOW) continue; if (r_shadows && spritesortcnt < (maxspritesonscreen-2) @@ -6531,7 +6535,7 @@ static void G_CompileScripts(void) labeltype = (int32_t *)&wall[0]; // V8: 16384*32/4 = 131072 V7: 8192*32/4 = 65536 #endif - C_Compile(G_ConFile()); + loadcons(G_ConFile()); if ((uint32_t)labelcnt > MAXSPRITES*sizeof(spritetype)/64) // see the arithmetic above for why G_GameExit("Error: too many labels defined!"); @@ -6573,7 +6577,7 @@ static inline void G_CheckGametype(void) ud.m_respawn_items = ud.m_respawn_inventory = 1; } -#define SETFLAG(Tilenum, Flag) g_tile[Tilenum].flags |= Flag +#define SETFLAG(Tilenum, Flag) actorinfo[Tilenum].flags |= Flag // Has to be after setting the dynamic names (e.g. TILE_SHARK). static void A_InitEnemyFlags(void) diff --git a/source/games/duke/src/zz_gamedef.cpp b/source/games/duke/src/zz_gamedef.cpp deleted file mode 100644 index f02c1404a..000000000 --- a/source/games/duke/src/zz_gamedef.cpp +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2016 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "ns.h" // Must come before everything else! - -#include "concmd.h" - -#include "duke3d_ed.h" -#include "namesdyn.h" -#include "gamedef.h" -#include "gameexec.h" -#include "savegame.h" -#include "common.h" -#include "common_game.h" -#include "cheats.h" -#include "m_argv.h" - -#include "osd.h" -#include "m_crc32.h" -#include "printf.h" -#include "menu/menu.h" -#include "stringtable.h" -#include "mapinfo.h" - -BEGIN_DUKE_NS - -#define LINE_NUMBER (line_number << 12) - -int32_t g_scriptVersion = 14; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files - -char g_scriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling - -int32_t g_totalLines; -char g_szBuf[1024]; - -char const * VM_GetKeywordForID(int32_t id) -{ - // do not really need this for now... - return ""; -} - -void loadcons(const char* filenam); - -void C_Compile(const char *fileName) -{ - for (int i=0; i= MAXSPRITES) - VM_DummySprite(); - - if ((unsigned)playerNum >= (unsigned)g_mostConcurrentPlayers) - vm.pPlayer = g_player[0].ps; - - while (1) if (parse()) break; - - if (killit_flag == 1) - { - // if player was set to squish, first stop that... - if (ps[g_p].actorsqu == g_i) - ps[g_p].actorsqu = -1; - deletesprite(g_i); - } - - // restoring these needs to happen after VM_DeleteSprite() due to event recursion - returnValue = globalReturn; - - vm = saved.vm; - globalReturn = saved.globalReturn; - g_currentEvent = saved.eventNum; - insptr = saved.insptr; - - return returnValue; -#endif - return 0; -} - -// the idea here is that the compiler inlines the call to VM_EventInlineInternal__() and gives us a set of -// functions which are optimized further based on distance/return having values known at compile time - -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum, int const nDist, int32_t const nReturn) -{ - return VM_EventInlineInternal__(nEventID, spriteNum, playerNum, nDist, nReturn); -} - -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum, int const nDist) -{ - return VM_EventInlineInternal__(nEventID, spriteNum, playerNum, nDist); -} - -int32_t VM_ExecuteEvent(int const nEventID, int const spriteNum, int const playerNum) -{ - return VM_EventInlineInternal__(nEventID, spriteNum, playerNum); -} - -int32_t VM_ExecuteEventWithValue(int const nEventID, int const spriteNum, int const playerNum, int32_t const nReturn) -{ - return VM_EventInlineInternal__(nEventID, spriteNum, playerNum, -1, nReturn); -} - -END_DUKE_NS diff --git a/source/games/duke/src/zz_premap.cpp b/source/games/duke/src/zz_premap.cpp index e06d34d24..95a96eb87 100644 --- a/source/games/duke/src/zz_premap.cpp +++ b/source/games/duke/src/zz_premap.cpp @@ -87,9 +87,6 @@ static void G_CacheSpriteNum(int32_t i) maxc = 1; - for (j = PN(i); j <= g_tile[PN(i)].cacherange; j++) - tloadtile(j,1); - switch (DYNAMICTILEMAP(PN(i))) { case HYDRENT__STATIC: @@ -386,15 +383,6 @@ static void G_PrecacheSprites(void) { int32_t i; - //for (i=0; i 1)) tloadtile(TILE_FRAGBAR,1); diff --git a/source/games/duke/src/zz_screens.cpp b/source/games/duke/src/zz_screens.cpp index c2c6abd3b..b8eb2de38 100644 --- a/source/games/duke/src/zz_screens.cpp +++ b/source/games/duke/src/zz_screens.cpp @@ -187,9 +187,6 @@ static int32_t gtextsc(int32_t sc) static void G_DrawCameraText(int16_t i) { - //if (VM_OnEvent(EVENT_DISPLAYCAMERAOSD, i, screenpeek) != 0) - // return; - if (!T1(i)) { rotatesprite_win(24<<16, 33<<16, 65536L, 0, TILE_CAMCORNER, 0, 0, 2); @@ -810,7 +807,6 @@ void G_DisplayRest(int32_t smoothratio) G_RestoreInterpolations(); - //int32_t const textret = VM_OnEvent(EVENT_DISPLAYOVERHEADMAPTEXT, g_player[screenpeek].ps->i, screenpeek); if (/*textret == 0 &&*/ ud.overhead_on == 2) { const int32_t a = RR ? 0 : ((ud.screen_size > 0) ? 147 : 179); @@ -823,7 +819,6 @@ void G_DisplayRest(int32_t smoothratio) } - //if (VM_OnEvent(EVENT_DISPLAYSBAR, g_player[screenpeek].ps->i, screenpeek) == 0) G_DrawStatusBar(screenpeek); G_PrintGameQuotes(screenpeek); @@ -874,7 +869,7 @@ void G_DisplayRest(int32_t smoothratio) mdpause = (ud.pause_on || (ud.recstat==2 && (g_demo_paused && g_demo_goalCnt==0)) || (g_player[myconnectindex].ps->gm&MODE_MENU && numplayers < 2)); // JBF 20040124: display level stats in screen corner - if (ud.overhead_on != 2 && hud_stats) // && VM_OnEvent(EVENT_DISPLAYLEVELSTATS, g_player[screenpeek].ps->i, screenpeek) == 0) + if (ud.overhead_on != 2 && hud_stats) { DukePlayer_t const * const myps = g_player[myconnectindex].ps; int const sbarshift = RR ? 15 : 16;