diff --git a/README.md b/README.md index 9d73520a3..2f1f60f22 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,38 @@ - Sprites player rotation on slopes; going on hills, levitate, going down, and so on alters your sprites (configurable) - You can alter all the base kart HUD element offsets on the fly in the Saturn Options settings menu -- "addfilelocal" Command, for those who want to use things like their custom hud in netgames (Same as addfile but completely client sided) -- OpenMPT for Tracker module playback (Complete with filters) fixed looping issues while even sounding better than the old GME playback +- `addfilelocal` Command, for those who want to use things like their custom hud in netgames (Same as addfile but completely client sided) +- OpenMPT for Tracker module playback instead of GME + - Fixes looping and sounds better + - Allows filter configuration - The minimal brightness with Shaders can be configured, now you can seeeee in dark areas (0-255 , uses Sector brightness values) -- Lua hooks for Intermission (ex: You can make hostmod votes still visible during intermission!) -- Visual Portals from Haya´s HEP Client -- Toggable lowercase menu´s also from Haya´s HEP client +- Lua HUD hooks for Intermission (ex: You can make hostmod votes still visible during intermission!) +- Lua HUD hooks for Vote Screen (ex: You can make hostmod votes still visible during map vote screen!) +- Saltyhop! do a funny hop +- Smaller Speedometer (optional / requieres extra.kart file) +- Record Attack input display can now be used everywhere +- Smaller minimap icons and also show player names on the minimap (toggable) +- `showmusiccredit` command, shows you the current music track again +- `listskins` show a list of all skins currently loaded +- Visual Portals from Haya's HEP Client +- Toggable lowercase menu's also from Haya's HEP client - Everything that Galaxy has ## Improvements / Bug fixes -- Replay size has been increased to 10MiB minimum, to make replay overflows very unlikely to happen (can be set to 100MiB max with "maxdemosize" command in console) -- Music changes now properly show the music credits (ex: Kart maps with easter eggs that alter the music) *The mapper still has to provide a MusicDEF for this to work. +- Replay size has been increased to 10MiB minimum, to make replay overflows very unlikely to happen + - can be set to 100MiB max with `maxdemosize` command in console +- Music changes now properly show the music credits (ex: Kart maps with easter eggs that alter the music) + - The mapper still has to provide a MusicDEF for this to work. - Configurable chatlog length (yay can read those messages from 30 mins ago without opening log.txt) - Configurable timeout for waiting to join a full server (in vanilla this is capped to 5 minutes before it boots you out) - Characters now spin in skin selection menu (configurable) -- HTTP Addon download speed has been raised dramatically (configurable with "downloadspeed" command) -- Zone memory allocations have been rewritten, speeds up some map loading, and may improve performance on busy maps +- HTTP Addon download speed has been raised dramatically + - configurable with `downloadspeed` command - HWR Drawnodes have been refactored, this should fix a few rare crashes esp in regards to OpenGL Visportals +- The Position Number in the corner is alot smaller now (half the size!) +- Toggable Lap animation +- Main menu shows the current renderer being used - MSAA and A2C Antialiasing support (Configurable in renderer.txt file) ## Performance / Debugging @@ -31,17 +45,18 @@ - Access for `mobj_t` and `player_t` fields from Lua has been completely rewritten, for much better performance with many Lua scripts - Lua shows Tracebacks whenever an error occurs - The Lua Perfstats page now has multiple pages and is more organized (ps_thinkframe_page X in console) -- People with lower end hardware can disable "screen textures" with "gr_screentextures" command, huge performance gain with minimal visual loss (Note intermission screen background is broken with this) -- Software mode has gotten "ffloorclip", which boosts performance on maps with many Floor over Floor roads +- People with lower end hardware can disable "screen textures" with "gr_screentextures" command, huge performance gain with minimal visual loss + - Intermission backgrounds, heat wave effects and etc are broken with this +- `ffloorclip`, exclusive to Software, which boosts performance on maps with many Floor over Floor sectors ## Technical fixes - ZFigthing Textures in Opengl mode have been fixed in engine (well almost all of it) -- Fof's intersecting with slopes have less issues and now render correctly in Opengl +- FOFs intersecting with slopes have less issues and now render correctly in Opengl - Midtextures on slopes in Opengl are fixed, many weird guardrails and fences, aswell as some of those sticking out textures from the ground on some maps should be gone -- The annoying depraction messages for "P_TeleportMove" and "P_AproxDistance" have been silenced +- The annoying depraction messages for `P_TeleportMove` and `P_AproxDistance` have been silenced - Silenced the annoying "cant find next map..." messages as theyre super useless and annoying anyways -- Added a small cooldown on "map" command due to spamming causing a SIGSEGV +- Added a small cooldown on `map` command due to spamming causing a SIGSEGV ## MISC - Bird's Camara Tilting feature is no longer turned on by default diff --git a/src/console.c b/src/console.c index f3e56aae8..99d032b7f 100644 --- a/src/console.c +++ b/src/console.c @@ -153,25 +153,25 @@ consvar_t cons_backcolor = {"con_backcolor", "Black", CV_CALL|CV_SAVE, backcolor static CV_PossibleValue_t menuhighlight_cons_t[] = { - {0, "Game type"}, - {V_YELLOWMAP, "Always yellow"}, - {V_PURPLEMAP, "Always purple"}, - {V_GREENMAP, "Always green"}, - {V_BLUEMAP, "Always blue"}, - {V_REDMAP, "Always red"}, - {V_GRAYMAP, "Always gray"}, - {V_ORANGEMAP, "Always orange"}, - {V_SKYMAP, "Always sky-blue"}, - {V_GOLDMAP, "Always gold"}, - {V_LAVENDERMAP, "Always lavender"}, - {V_TEAMAP, "Always tea-green"}, - {V_STEELMAP, "Always steel-blue"}, - {V_PINKMAP, "Always pink"}, - {V_BROWNMAP, "Always brown"}, - {V_PEACHMAP, "Always peach"}, + {0, "Gametype Default"}, + {V_YELLOWMAP, "Always Yellow"}, + {V_PURPLEMAP, "Always Purple"}, + {V_GREENMAP, "Always Green"}, + {V_BLUEMAP, "Always Blue"}, + {V_REDMAP, "Always Red"}, + {V_GRAYMAP, "Always Gray"}, + {V_ORANGEMAP, "Always Orange"}, + {V_SKYMAP, "Always Sky-Blue"}, + {V_GOLDMAP, "Always Gold"}, + {V_LAVENDERMAP, "Always Lavender"}, + {V_TEAMAP, "Always Tea-Green"}, + {V_STEELMAP, "Always Steel-Blue"}, + {V_PINKMAP, "Always Pink"}, + {V_BROWNMAP, "Always Brown"}, + {V_PEACHMAP, "Always Peach"}, {0, NULL} }; -consvar_t cons_menuhighlight = {"menuhighlight", "Game type", CV_SAVE, menuhighlight_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cons_menuhighlight = {"menuhighlight", "Gametype Default", CV_SAVE, menuhighlight_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static void CON_Print(char *msg); diff --git a/src/d_main.c b/src/d_main.c index 66ad22211..5467ba655 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -957,9 +957,12 @@ static boolean AddIWAD(void) } } +boolean found_extra_kart; + static void IdentifyVersion(void) { const char *srb2waddir = NULL; + found_extra_kart = false; #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) // change to the directory where 'srb2.srb' is found @@ -1012,6 +1015,11 @@ static void IdentifyVersion(void) #ifdef USE_PATCH_KART D_AddFile(va(pandf,srb2waddir,"patch.kart"), startupwadfiles); #endif + // completely optional + if (FIL_ReadFileOK(va(pandf,srb2waddir,"extra.kart"))) { + D_AddFile(va(pandf,srb2waddir,"extra.kart"), startupwadfiles); + found_extra_kart = true; + } #if !defined (HAVE_SDL) || defined (HAVE_MIXER) #define MUSICTEST(str) \ @@ -1337,6 +1345,9 @@ void D_SRB2Main(void) #endif //ifndef DEVELOP + if (found_extra_kart) // found the funny, add it in! + mainwads++; + // // search for maps // diff --git a/src/d_main.h b/src/d_main.h index af74e7a69..b64d672de 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -25,6 +25,8 @@ extern boolean usehome; //Alam: which path? extern const char *pandf; //Alam: how to path? extern char srb2path[256]; //Alam: SRB2's Home +extern boolean found_extra_kart; // for use in k_kart.c + // the infinite loop of D_SRB2Loop() called from win_main for windows version void D_SRB2Loop(void) FUNCNORETURN; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 859e396b7..35e6857b1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -469,6 +469,12 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showminimapnames = {"showminimapnames", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; // Intermission time Tails 04-19-2002 @@ -703,6 +709,8 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_powerstones); CV_RegisterVar(&cv_competitionboxes); CV_RegisterVar(&cv_matchboxes); + + CV_RegisterVar(&cv_slamsound); /*CV_RegisterVar(&cv_recycler); CV_RegisterVar(&cv_teleporters); @@ -768,6 +776,11 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_pingtimeout); CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); + + CV_RegisterVar(&cv_minihead); + CV_RegisterVar(&cv_showminimapnames); + + CV_RegisterVar(&cv_showlapemblem); CV_RegisterVar(&cv_showtrackaddon); @@ -957,6 +970,15 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_mini_yoffset); CV_RegisterVar(&cv_want_xoffset); CV_RegisterVar(&cv_want_yoffset); + CV_RegisterVar(&cv_showinput); + CV_RegisterVar(&cv_newspeedometer); + + CV_RegisterVar(&cv_saltyhop); + CV_RegisterVar(&cv_saltyhopsfx); + CV_RegisterVar(&cv_saltysquish); + + CV_RegisterVar(&cv_growmusic); + CV_RegisterVar(&cv_supermusic); //CV_RegisterVar(&cv_crosshair); //CV_RegisterVar(&cv_crosshair2); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index e92289397..e999a202e 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -150,6 +150,12 @@ extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; extern consvar_t cv_pingmeasurement; +//extern consvar_t cv_smallpos; +extern consvar_t cv_showminimapnames; +extern consvar_t cv_minihead; + +extern consvar_t cv_showlapemblem; + extern consvar_t cv_showviewpointtext; extern consvar_t cv_skipmapcheck; diff --git a/src/d_netfil.c b/src/d_netfil.c index 49c12ce25..0436f05d3 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -562,7 +562,7 @@ INT32 CL_CheckFiles(void) CONS_Debug(DBG_NETPLAY, "searching for '%s' ", fileneeded[i].filename); // Check in already loaded files - for (j = mainwads+1; j < numwadfiles; j++) + for (j = mainwads+1; wadfiles[j]; j++) { nameonly(strcpy(wadfilename, wadfiles[j]->filename)); if (!stricmp(wadfilename, fileneeded[i].filename) && diff --git a/src/dehacked.c b/src/dehacked.c index 52b2785c3..925d69042 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8735,6 +8735,7 @@ struct { // Custom client features exposed to lua {"FEATURE_INTERMISSIONHUD",1}, + {"FEATURE_VOTEHUD",1}, #endif {NULL,0} diff --git a/src/doomdef.h b/src/doomdef.h index 9d2a3a2c9..5a914f218 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -149,8 +149,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v1.1 " -#define VERSIONSTRINGW L"Saturn v1.1" +#define VERSIONSTRING "Saturn v2.1 " +#define VERSIONSTRINGW L"Saturn v2.1" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! diff --git a/src/g_game.c b/src/g_game.c index 93c502d06..01037f3c6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -468,6 +468,10 @@ consvar_t cv_songcredits = {"songcredits", "On", CV_SAVE, CV_OnOff, NULL, 0, NUL // Show "FREE PLAY" when you're alone. :( consvar_t cv_showfreeplay = { "showfreeplay", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +// We can disable special tunes! +consvar_t cv_growmusic = {"growmusic", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_supermusic = {"supermusic", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + /*consvar_t cv_crosshair = {"crosshair", "Off", CV_SAVE, crosshair_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_crosshair2 = {"crosshair2", "Off", CV_SAVE, crosshair_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_crosshair3 = {"crosshair3", "Off", CV_SAVE, crosshair_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -545,8 +549,12 @@ static CV_PossibleValue_t stretchfactor_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0 consvar_t cv_gravstretch = {"gravstretch", "0", CV_FLOAT | CV_SAVE, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_sloperoll = {"sloperoll", "Off", CV_SAVE|CV_CALL, CV_OnOff, PDistort_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_sliptideroll = {"sliptideroll", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t slamsound_t[] = {{0, "Off"}, {1, "On"}, {0, NULL}}; +consvar_t cv_slamsound = {"slamsound", "1", CV_SAVE, slamsound_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t sloperolldist_cons_t[] = { /*{256, "256"},*/ {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, @@ -5699,6 +5707,9 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) void G_WriteAllGhostTics(void) { + UINT8 *save_demo_p = demo_p; +#define CHECKSPACE(num) if (demo_p+(num) > demoend) { demo_p = save_demo_p; G_CheckDemoStatus(); return; } + INT32 i, counter = leveltime; for (i = 0; i < MAXPLAYERS; i++) { @@ -5713,10 +5724,16 @@ void G_WriteAllGhostTics(void) if (counter % cv_netdemosyncquality.value != 0) // Only write 1 in this many ghost datas per tic to cut down on multiplayer replay size. continue; + CHECKSPACE(1); + WRITEUINT8(demo_p, i); G_WriteGhostTic(players[i].mo, i); } + + CHECKSPACE(1); WRITEUINT8(demo_p, 0xFF); + +#undef CHECKSPACE } void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) @@ -5727,6 +5744,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) UINT8 sprite; UINT8 frame; + UINT8 *save_demo_p = demo_p; +#define CHECKSPACE(num) if (demo_p+(num) > demoend) { demo_p = save_demo_p; G_CheckDemoStatus(); return; } + if (!demo_p) return; if (!(demoflags & DF_GHOST)) @@ -5753,6 +5773,8 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) oldghost[playernum].y = ghost->y; oldghost[playernum].z = ghost->z; ziptic |= GZT_XYZ; + + CHECKSPACE(sizeof(fixed_t)*3); WRITEFIXED(demo_p,oldghost[playernum].x); WRITEFIXED(demo_p,oldghost[playernum].y); WRITEFIXED(demo_p,oldghost[playernum].z); @@ -5769,6 +5791,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) oldghost[playernum].momx = momx; oldghost[playernum].momy = momy; ziptic |= GZT_MOMXY; + + CHECKSPACE(4); + WRITEINT16(demo_p,momx); WRITEINT16(demo_p,momy); } @@ -5777,6 +5802,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) { oldghost[playernum].momz = momx; ziptic |= GZT_MOMZ; + + CHECKSPACE(2); + WRITEINT16(demo_p,momx); } @@ -5797,6 +5825,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) { oldghost[playernum].angle = ghost->angle>>24; ziptic |= GZT_ANGLE; + + CHECKSPACE(1); + WRITEUINT8(demo_p,oldghost[playernum].angle); } @@ -5806,6 +5837,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) { oldghost[playernum].frame = frame; ziptic |= GZT_SPRITE; + + CHECKSPACE(1); + WRITEUINT8(demo_p,oldghost[playernum].frame); } @@ -5845,20 +5879,26 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) if (ghostext[playernum].flags & EZT_COLOR) { + CHECKSPACE(1); WRITEUINT8(demo_p,ghostext[playernum].color); ghostext[playernum].lastcolor = ghostext[playernum].color; } if (ghostext[playernum].flags & EZT_SCALE) { + CHECKSPACE(sizeof(fixed_t)); WRITEFIXED(demo_p,ghostext[playernum].scale); ghostext[playernum].lastscale = ghostext[playernum].scale; } if (ghostext[playernum].flags & EZT_HIT) { + CHECKSPACE(2); WRITEUINT16(demo_p,ghostext[playernum].hits); for (i = 0; i < ghostext[playernum].hits; i++) { mobj_t *mo = ghostext[playernum].hitlist[i]; + + CHECKSPACE(4+4+2+sizeof(fixed_t)*3+sizeof(angle_t)); + WRITEUINT32(demo_p,UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) WRITEUINT32(demo_p,mo->type); WRITEUINT16(demo_p,(UINT16)mo->health); @@ -5872,9 +5912,14 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) ghostext[playernum].hitlist = NULL; } if (ghostext[playernum].flags & EZT_SPRITE) + { + CHECKSPACE(1); WRITEUINT8(demo_p,sprite); + } if (ghostext[playernum].flags & EZT_KART) { + CHECKSPACE(12); + WRITEINT32(demo_p, ghostext[playernum].kartitem); WRITEINT32(demo_p, ghostext[playernum].kartamount); WRITEINT32(demo_p, ghostext[playernum].kartbumpers); @@ -5891,6 +5936,7 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum) G_CheckDemoStatus(); // no more space return; } +#undef CHECKSPACE } void G_ConsAllGhostTics(void) @@ -6743,22 +6789,30 @@ void G_RecordDemo(const char *name) { INT32 maxsize; - CONS_Printf("Recording demo %s.lmp\n", name); - - strcpy(demoname, name); - strcat(demoname, ".lmp"); - maxsize = cv_maxdemosize.value*1024*1024; - if (demobuffer) - free(demobuffer); demo_p = NULL; demo.recording = false; - demobuffer = malloc(maxsize); - demoend = demobuffer + maxsize; - if (demobuffer) - demo.recording = true; - else - CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + free(demobuffer); + demobuffer = NULL; + demoend = NULL; + + if (cv_recordmultiplayerdemos.value) + { + CONS_Printf("Recording demo %s.lmp\n", name); + + strcpy(demoname, name); + strcat(demoname, ".lmp"); + + maxsize = cv_maxdemosize.value*1024*1024; + + demobuffer = malloc(maxsize); + demoend = demobuffer + maxsize; + + if (demobuffer) + demo.recording = true; + else + CONS_Alert(CONS_ERROR, "Failed to allocate demo buffer\n"); + } } void G_RecordMetal(void) diff --git a/src/g_game.h b/src/g_game.h index c99404a35..ceb8e1f9f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -113,6 +113,7 @@ extern INT16 rw_maximums[NUM_WEAPONS]; extern consvar_t cv_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection/*, cv_compactscoreboard*/; extern consvar_t cv_songcredits; extern consvar_t cv_showfreeplay; +extern consvar_t cv_growmusic, cv_supermusic; extern consvar_t cv_pauseifunfocused; //extern consvar_t cv_crosshair, cv_crosshair2, cv_crosshair3, cv_crosshair4; extern consvar_t cv_invertmouse/*, cv_alwaysfreelook, cv_chasefreelook, cv_mousemove*/; @@ -145,11 +146,18 @@ extern consvar_t cv_mini_xoffset; extern consvar_t cv_mini_yoffset; extern consvar_t cv_want_xoffset; extern consvar_t cv_want_yoffset; +extern consvar_t cv_showinput; +extern consvar_t cv_newspeedometer; + +extern consvar_t cv_saltyhop; +extern consvar_t cv_saltyhopsfx; +extern consvar_t cv_saltysquish; extern consvar_t cv_driftsparkpulse; extern consvar_t cv_gravstretch; extern consvar_t cv_sloperoll; extern consvar_t cv_sliptideroll; +extern consvar_t cv_slamsound; extern consvar_t cv_sloperolldist; extern consvar_t cv_invincmusicfade; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 13b6b7911..834f617bf 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3755,7 +3755,7 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t } // This is expecting a pointer to an array containing 4 wallVerts for a sprite -static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts) +static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts, const boolean precip) { if (cv_grspritebillboarding.value && spr && spr->mobj && !(spr->mobj->frame & FF_PAPERSPRITE) && wallVerts) { @@ -3907,7 +3907,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) } // Let dispoffset work first since this adjust each vertex - HWR_RotateSpritePolyToAim(spr, baseWallVerts); + HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); // push it toward the camera to mitigate floor-clipping sprites { @@ -4254,7 +4254,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) // Let dispoffset work first since this adjust each vertex // ...nah - HWR_RotateSpritePolyToAim(spr, wallVerts); + HWR_RotateSpritePolyToAim(spr, wallVerts, false); // push it toward the camera to mitigate floor-clipping sprites { @@ -4348,7 +4348,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) wallVerts[1].z = wallVerts[2].z = spr->z2; // Let dispoffset work first since this adjust each vertex - HWR_RotateSpritePolyToAim(spr, wallVerts); + HWR_RotateSpritePolyToAim(spr, wallVerts, true); wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = gpatch->max_s; @@ -5253,11 +5253,11 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) unsigned rot = 0; UINT8 flip; - // uncapped/interpolation - interpmobjstate_t interp = {0}; - if (!thing) return; + + // uncapped/interpolation + interpmobjstate_t interp = {0}; // do interpolation if (R_UsingFrameInterpolation() && !paused) @@ -5326,16 +5326,6 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) x1 = tr_x + x1 * rightcos; x2 = tr_x - x2 * rightcos; - // okay, we can't return now... this is a hack, but weather isn't networked, so it should be ok - if (!(thing->precipflags & PCF_THUNK)) - { - if (thing->precipflags & PCF_RAIN) - P_RainThinker(thing); - else - P_SnowThinker(thing); - thing->precipflags |= PCF_THUNK; - } - // // store information in a vissprite // @@ -5364,6 +5354,16 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); vis->precip = true; + + // okay... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } } static boolean drewsky = false; @@ -5815,6 +5815,8 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) if (skybox) drewsky = true; + current_bsp_culling_distance = 0; + if (!skybox && cv_grrenderdistance.value) { HWD.pfnGClipRect((INT32)gr_viewwindowx, diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 737956671..51a362c9e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -98,6 +98,9 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap); // Let's see if FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); +// Get amount of memory used by gpu textures in bytes +INT32 HWR_GetTextureUsed(void); + // hw_main.c: Post-rendering void HWR_DoPostProcessor(player_t *player); void HWR_StartScreenWipe(void); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 3d5017961..dc52dfe7f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -81,6 +81,8 @@ patch_t *pingnum[10]; patch_t *pinggfx[5]; // small ping graphic patch_t *pingmeasure[2]; // ping measurement graphic +patch_t *ranknum[10]; // rank numbers + patch_t *framecounter; patch_t *frameslash; // framerate stuff. Used in screen.c @@ -281,6 +283,8 @@ void HU_LoadGraphics(void) nightsnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); sprintf(buffer, "PINGN%d", i); pingnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + sprintf(buffer, "OPPRNK0%d", i); + ranknum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); } // minus for negative tallnums diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 9979427cf..eb2461146 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -83,6 +83,7 @@ extern patch_t *hu_font[HU_FONTSIZE], *kart_font[KART_FONTSIZE], *tny_font[HU_FO extern patch_t *tallnum[10]; extern patch_t *pingnum[10]; extern patch_t *pinggfx[5]; +extern patch_t *ranknum[10]; extern patch_t *nightsnum[10]; extern patch_t *framecounter; extern patch_t *frameslash; diff --git a/src/k_kart.c b/src/k_kart.c index 1f62f7c72..fd3a46afe 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -22,6 +22,7 @@ #include "f_finale.h" #include "lua_hud.h" // For Lua hud checks #include "lua_hook.h" // For MobjDamage and ShouldDamage +#include "d_main.h" // found_extra_kart // Hud offset cvars consvar_t cv_item_xoffset = {"hud_item_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -53,6 +54,13 @@ consvar_t cv_mini_yoffset = {"hud_minimap_yoffset", "0", CV_SAVE, NULL, NULL, 0, consvar_t cv_want_xoffset = {"hud_wanted_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_want_yoffset = {"hud_wanted_yoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_newspeedometer = {"newspeedometer", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_saltyhop = {"hardcodehop", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_saltyhopsfx = {"hardcodehopsfx", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_saltysquish = {"hardcodehopsquish", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) // franticitems is Frantic Mode items, bool @@ -3000,6 +3008,15 @@ static void K_StretchPlayerGravity(player_t *p) I_Assert(p != NULL); I_Assert(p->mo != NULL); I_Assert(!P_MobjWasRemoved(p->mo)); + + if (p->mo->slamsoundtimer) + p->mo->slamsoundtimer--; + + if (cv_slamsound.value == 1 && (p->mo->eflags & MFE_JUSTHITFLOOR) && p->mo->stretchslam > 4*mos && !p->mo->slamsoundtimer) + { + S_StartSound(p->mo, sfx_s3k4c); + p->mo->slamsoundtimer = TICRATE; + } if (!P_IsObjectOnGround(p->mo)) { @@ -3037,6 +3054,67 @@ static void K_StretchPlayerGravity(player_t *p) } } +static void K_QuiteSaltyHop(player_t *p) +{ + // what the fuck is this haya + fixed_t mos = FRACUNIT; // doesnt work correctly if it isnt :/ + + // ready? + if (!p->kartstuff[k_jmp]) { + p->mo->salty_ready = true; + p->mo->salty_tapping = false; + } else if (p->mo->salty_ready) { + p->mo->salty_ready = false; + p->mo->salty_tapping = true; + } else { + p->mo->salty_tapping = false; + } + + // GO! + if (!p->mo->init_salty) { + p->mo->salty_jump = false; + p->mo->salty_zoffset = 0; + p->mo->salty_momz = 0; + p->mo->init_salty = true; + } + else if ((p->mo->salty_jump)) { + if (p->mo->eflags & MFE_JUSTHITFLOOR) { + p->mo->salty_zoffset = 0; + } else if (P_IsObjectOnGround(p->mo)) { + p->mo->salty_zoffset += p->mo->salty_momz; + p->mo->salty_momz -= (mos*3/2); + } else { + p->mo->salty_zoffset *= (49/50)*mos; + p->mo->salty_momz = 0; + } + if (p->mo->salty_zoffset <= 0) { + if (!(p->mo->eflags & MFE_JUSTHITFLOOR) && P_IsObjectOnGround(p->mo) && cv_saltyhopsfx.value) + S_StartSound(p->mo, sfx_s268); + p->mo->salty_jump = false; + p->mo->salty_zoffset = 0; + p->mo->salty_momz = 0; + // shlamma damma + p->mo->stretchslam += cv_saltysquish.value ? (8*mos) : 0; + } else if (p->mo->salty_zoffset >= 0 && cv_saltysquish.value) { + // goofy ahh hack + p->mo->spriteyscale += (mos/8); + p->mo->spritexscale -= (mos/8); + } + p->mo->spriteyoffset = p->mo->salty_zoffset*P_MobjFlip(p->mo); + if (S_SoundPlaying(p->mo, sfx_screec)) + S_StopSoundByID(p->mo, sfx_screec); + if (S_SoundPlaying(p->mo, sfx_drift)) + S_StopSoundByID(p->mo, sfx_drift); + } + else if (p->mo->salty_tapping && P_IsObjectOnGround(p->mo) && !p->kartstuff[k_spinouttimer] && !p->kartstuff[k_squishedtimer]) { + p->mo->salty_jump = true; + p->mo->salty_zoffset = 0; + p->mo->salty_momz = 6*mos; + if (cv_saltyhopsfx.value) + S_StartSound(p->mo, sfx_s25a); + } +} + static INT32 K_FindPlayerNum(player_t *plyr) { INT32 i; @@ -6392,6 +6470,16 @@ void K_MoveKartPlayer(player_t *player, boolean onground) player->kartstuff[k_boostcharge] = 0; } + + // salty hop! i wanna die + if (cv_saltyhop.value) + K_QuiteSaltyHop(player); + else { + player->mo->spriteyoffset = 0; + player->mo->salty_jump = false; + player->mo->salty_zoffset = 0; + player->mo->salty_momz = 0; + } } void K_CalculateBattleWanted(void) @@ -6817,6 +6905,9 @@ static patch_t *kp_lapanim_hand[3]; static patch_t *kp_yougotem; +static patch_t *skp_smallsticker; +static patch_t *skp_speedpatches[5]; + void K_LoadKartHUDGraphics(void) { INT32 i, j; @@ -7063,6 +7154,16 @@ void K_LoadKartHUDGraphics(void) } kp_yougotem = (patch_t *) W_CachePatchName("YOUGOTEM", PU_HUDGFX); + + if (found_extra_kart) // snowy speedometer + { + skp_smallsticker = W_CachePatchName("SP_SMSTC", PU_HUDGFX); + skp_speedpatches[0] = W_CachePatchName("K_TRNULL", PU_HUDGFX); // lolxd + skp_speedpatches[1] = W_CachePatchName("SP_MKMH", PU_HUDGFX); + skp_speedpatches[2] = W_CachePatchName("SP_MMPH", PU_HUDGFX); + skp_speedpatches[3] = W_CachePatchName("SP_MFRAC", PU_HUDGFX); + skp_speedpatches[4] = W_CachePatchName("SP_MPERC", PU_HUDGFX); + } } // For the item toggle menu @@ -7775,6 +7876,7 @@ static void K_DrawKartPositionNum(INT32 num) patch_t *localpatch = kp_positionnum[0][0]; //INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTORIGHT); INT32 fx = 0, fy = 0, fflags = 0; + INT32 xoffs = (cv_showinput.value) ? -48 : 0; boolean flipdraw = false; // flip the order we draw it in for MORE splitscreen bs. fun. boolean flipvdraw = false; // used only for 2p splitscreen so overtaking doesn't make 1P's position fly off the screen. boolean overtake = false; @@ -7786,13 +7888,15 @@ static void K_DrawKartPositionNum(INT32 num) } if (splitscreen) scale /= 2; + if (cv_showinput.value && !splitscreen) // anuther one. + scale /= 2; W = FixedMul(W<>FRACBITS; // pain and suffering defined below if (!splitscreen) { - fx = POSI_X; + fx = POSI_X + xoffs; fy = BASEVIDHEIGHT - 8; fflags = V_SNAPTOBOTTOM|V_SNAPTORIGHT; } @@ -8202,35 +8306,62 @@ static void K_drawKartLaps(void) static void K_drawKartSpeedometer(void) { - fixed_t convSpeed; + // why? + if (cv_kartspeedometer.value == 0) + return; + + fixed_t convSpeed = 0; + INT32 speedtype = 0; INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); - if (cv_kartspeedometer.value == 1) // Kilometers + switch (cv_kartspeedometer.value) { - convSpeed = FixedDiv(FixedMul(stplyr->speed, 142371), mapobjectscale)/FRACUNIT; // 2.172409058 - V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d km/h", convSpeed)); + case 1: + convSpeed = FixedDiv(FixedMul(stplyr->speed, 142371), mapobjectscale)/FRACUNIT; // 2.172409058 + speedtype = 1; + break; + case 2: + convSpeed = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale)/FRACUNIT; // 1.349868774 + speedtype = 2; + break; + case 3: + convSpeed = FixedDiv(stplyr->speed, mapobjectscale)/FRACUNIT; + speedtype = 3; + break; + case 4: + if (stplyr->mo) + convSpeed = (FixedDiv(stplyr->speed, FixedMul(K_GetKartSpeed(stplyr, false), ORIG_FRICTION))*100)>>FRACBITS; + speedtype = 4; + break; + default: + break; } - else if (cv_kartspeedometer.value == 2) // Miles + + // man. + if ((!cv_newspeedometer.value) || (cv_newspeedometer.value && !found_extra_kart)) { - convSpeed = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale)/FRACUNIT; // 1.349868774 - V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d mph", convSpeed)); - } - else if (cv_kartspeedometer.value == 3) // Fracunits - { - convSpeed = FixedDiv(stplyr->speed, mapobjectscale)/FRACUNIT; - V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d fu/t", convSpeed)); - } - else if (cv_kartspeedometer.value == 4) // Percent - { - // so code breaks if someone attempts to join from spectator since it sets - // their mo to NULL - // so can we just check if their mo is NULL???? - if (stplyr->mo) - { - convSpeed = (FixedDiv(stplyr->speed, FixedMul(K_GetKartSpeed(stplyr, false), ORIG_FRICTION))*100)>>FRACBITS; - V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d P", convSpeed)); + switch (speedtype) { + case 1: + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d km/h", convSpeed)); + break; + case 2: + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d mph", convSpeed)); + break; + case 3: + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%3d fu/t", convSpeed)); + break; + case 4: // if extra.kart is found, use its included % symbol + if (!found_extra_kart) + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d P", convSpeed)); + else + V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d %%", convSpeed)); } } + else if (cv_newspeedometer.value && found_extra_kart) { // why bother if we dont? + V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_smallsticker); + V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed, 3, NULL); + V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatches[cv_kartspeedometer.value]); + } } static void K_drawKartBumpersOrKarma(void) @@ -8518,27 +8649,29 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat amxpos = amnumxpos + ((x + AutomapPic->width/2 - (facemmapprefix[skin]->width/2))<height/2 - (facemmapprefix[skin]->height/2))<width/2 + (facemmapprefix[skin]->width/2))<color) // 'default' color V_DrawSciencePatch(amxpos, amypos, flags, facemmapprefix[skin], FRACUNIT); else { - UINT8 *colormap; - if (mo->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, mo->color, GTC_CACHE); - else - colormap = R_GetTranslationColormap(skin, mo->color, GTC_CACHE); - V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, facemmapprefix[skin], colormap); + UINT8 *colormap = R_GetTranslationColormap((mo->colorized) ? TC_RAINBOW : skin, mo->color, GTC_CACHE); + + if (cv_minihead.value == 1) + V_DrawFixedPatch(amxpos + (2 * FRACUNIT), amypos + (2 * FRACUNIT), FRACUNIT/2, flags, facemmapprefix[skin], colormap); + else if (cv_minihead.value == 0) + V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, facemmapprefix[skin], colormap); + + if (cv_showminimapnames.value && !(modeattacking || gamestate == GS_TIMEATTACK)) + { + const char *player_name = va("%c%s", V_GetSkincolorChar(mo->color), player_names[mo->player - players]); + V_DrawCenteredSmallStringAtFixed(amxpos + (4 * FRACUNIT), amypos - (3 * FRACUNIT), V_ALLOWLOWERCASE|flags, player_name); + } if (mo->player && ((G_RaceGametype() && mo->player->kartstuff[k_position] == spbplace) || (G_BattleGametype() && K_IsPlayerWanted(mo->player)))) { + if (cv_minihead.value == 1) + V_DrawFixedPatch(amxpos, amypos, FRACUNIT / 2, flags, kp_wantedreticle, NULL); + else if (cv_minihead.value == 0) V_DrawFixedPatch(amxpos - (4<skincolor][5]; const INT32 accent2 = splitflags|colortranslations[stplyr->skincolor][9]; ticcmd_t *cmd = &stplyr->cmd; @@ -9112,6 +9248,9 @@ static void K_drawChallengerScreen(void) static void K_drawLapStartAnim(void) { + if (! cv_showlapemblem.value) + return; + // This is an EVEN MORE insanely complicated animation. const UINT8 progress = 80-stplyr->kartstuff[k_lapanimation]; UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, stplyr->skincolor, GTC_CACHE); @@ -9388,6 +9527,12 @@ void K_drawKartHUD(void) if (!stplyr->spectator && !demo.freecam) // Bottom of the screen elements, don't need in spectate mode { + if (!(splitscreen || demo.title)) +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_position)) +#endif + K_drawInput(); + if (demo.title) // Draw title logo instead in demo.titles { INT32 x = BASEVIDWIDTH - 32, y = 128, offs; diff --git a/src/lua_hud.h b/src/lua_hud.h index 06ba0169b..26b8cf0b0 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -44,5 +44,6 @@ boolean LUA_HudEnabled(enum hud option); void LUAh_GameHUD(player_t *stplyr, huddrawlist_h list); void LUAh_ScoresHUD(huddrawlist_h list); void LUAh_IntermissionHUD(huddrawlist_h list); +void LUAh_VoteHUD(huddrawlist_h list); #endif // __LUA_HUD_H__ diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index f2eeae4c9..470fad9b7 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -86,11 +86,13 @@ enum hudhook { hudhook_game = 0, hudhook_scores = 1, hudhook_intermission = 2, + hudhook_vote = 3, }; static const char *const hudhook_opt[] = { "game", "scores", "intermission", + "vote", NULL}; // alignment types for v.drawString @@ -993,6 +995,9 @@ int LUA_HudLib(lua_State *L) lua_newtable(L); lua_rawseti(L, -2, 4); // HUD[4] = intermission rendering functions array + + lua_newtable(L); + lua_rawseti(L, -2, 5); // HUD[5] = vote rendering functions array lua_setfield(L, LUA_REGISTRYINDEX, "HUD"); luaL_newmetatable(L, META_HUDINFO); @@ -1061,7 +1066,7 @@ void LUAh_GameHUD(player_t *stplayr, huddrawlist_h list) lua_getfield(gL, LUA_REGISTRYINDEX, "HUD"); I_Assert(lua_istable(gL, -1)); - lua_rawgeti(gL, -1, 2); // HUD[2] = rendering funcs + lua_rawgeti(gL, -1, hudhook_game+2); // HUD[2] = rendering funcs I_Assert(lua_istable(gL, -1)); lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw @@ -1119,7 +1124,7 @@ void LUAh_ScoresHUD(huddrawlist_h list) lua_getfield(gL, LUA_REGISTRYINDEX, "HUD"); I_Assert(lua_istable(gL, -1)); - lua_rawgeti(gL, -1, 3); // HUD[3] = rendering funcs + lua_rawgeti(gL, -1, hudhook_scores+2); // HUD[3] = rendering funcs I_Assert(lua_istable(gL, -1)); lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw @@ -1152,7 +1157,40 @@ void LUAh_IntermissionHUD(huddrawlist_h list) lua_getfield(gL, LUA_REGISTRYINDEX, "HUD"); I_Assert(lua_istable(gL, -1)); - lua_rawgeti(gL, -1, 4); // HUD[4] = rendering funcs + lua_rawgeti(gL, -1, hudhook_intermission+2); // HUD[4] = rendering funcs + I_Assert(lua_istable(gL, -1)); + + lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw + I_Assert(lua_istable(gL, -1)); + lua_remove(gL, -3); // pop HUD + lua_pushnil(gL); + while (lua_next(gL, -3) != 0) { + lua_pushvalue(gL, -3); // graphics library (HUD[1]) + LUA_Call(gL, 1, 0, 1); + } + lua_settop(gL, 0); + hud_running = false; + + lua_pushlightuserdata(gL, NULL); + lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); +} + +void LUAh_VoteHUD(huddrawlist_h list) +{ + if (!gL || !(hudAvailable & (1<items = NULL; drawlist->items_capacity = 0; drawlist->items_len = 0; @@ -145,7 +145,7 @@ static size_t AllocateDrawItem(huddrawlist_h list) { if (list->items_capacity == 0) list->items_capacity = 128; else list->items_capacity *= 2; - list->items = (drawitem_t *) Z_Realloc(list->items, sizeof(struct drawitem_s) * list->items_capacity, PU_STATIC, NULL); + list->items = (drawitem_t *) Z_ReallocAlign(list->items, sizeof(struct drawitem_s) * list->items_capacity, PU_STATIC, NULL, 64); } return list->items_len++; @@ -164,7 +164,7 @@ static size_t CopyString(huddrawlist_h list, const char* str) { if (list->strbuf_capacity == 0) list->strbuf_capacity = 256; else list->strbuf_capacity *= 2; - list->strbuf = (char*) Z_Realloc(list->strbuf, sizeof(char) * list->strbuf_capacity, PU_STATIC, NULL); + list->strbuf = (char*) Z_ReallocAlign(list->strbuf, sizeof(char) * list->strbuf_capacity, PU_STATIC, NULL, 8); } { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 9788e9a83..91c2158e8 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -36,8 +36,8 @@ int mobj_snext_noset(lua_State *L); int mobj_z_setter(lua_State *L); int mobj_sprev_unimplemented(lua_State *L); int mobj_angle_setter(lua_State *L); -//int mobj_sloperoll_noset(lua_State *L); -//int mobj_spritescale_setter(lua_State *L); +int mobj_sloperoll_noop(lua_State *L); +int mobj_spritescale_setter(lua_State *L); int mobj_touching_sectorlist_unimplemented(lua_State *L); int mobj_radius_setter(lua_State *L); int mobj_height_setter(lua_State *L); @@ -76,15 +76,15 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, snext, udatalib_getter_mobj, mobj_snext_noset), FIELD(mobj_t, sprev, mobj_sprev_unimplemented, mobj_sprev_unimplemented), FIELD(mobj_t, angle, udatalib_getter_angle, mobj_angle_setter), - //FIELD(mobj_t, rollangle, udatalib_getter_angle, udatalib_setter_angle), - //FIELD(mobj_t, sloperoll, udatalib_getter_angle, mobj_sloperoll_noset), + FIELD(mobj_t, rollangle, udatalib_getter_angle, udatalib_setter_angle), + FIELD(mobj_t, sloperoll, udatalib_getter_angle, mobj_sloperoll_noop), FIELD(mobj_t, sprite, udatalib_getter_spritenum, udatalib_setter_spritenum), FIELD(mobj_t, frame, udatalib_getter_uint32, udatalib_setter_uint32), FIELD(mobj_t, anim_duration, udatalib_getter_uint16, udatalib_setter_uint16), - //FIELD(mobj_t, spritexscale, udatalib_getter_fixed, mobj_spritescale_setter), - //FIELD(mobj_t, spriteyscale, udatalib_getter_fixed, mobj_spritescale_setter), - //FIELD(mobj_t, spritexoffset, udatalib_getter_fixed, udatalib_setter_fixed), - //FIELD(mobj_t, spriteyoffset, udatalib_getter_fixed, udatalib_setter_fixed), + FIELD(mobj_t, spritexscale, udatalib_getter_fixed, mobj_spritescale_setter), + FIELD(mobj_t, spriteyscale, udatalib_getter_fixed, mobj_spritescale_setter), + FIELD(mobj_t, spritexoffset, udatalib_getter_fixed, udatalib_setter_fixed), + FIELD(mobj_t, spriteyoffset, udatalib_getter_fixed, udatalib_setter_fixed), FIELD(mobj_t, touching_sectorlist, mobj_touching_sectorlist_unimplemented, mobj_touching_sectorlist_unimplemented), FIELD(mobj_t, subsector, udatalib_getter_subsector, mobj_nosetpos_subsector), FIELD(mobj_t, floorz, udatalib_getter_fixed, mobj_nosetpos_floorz), @@ -133,7 +133,7 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, cvmem, udatalib_getter_int32, udatalib_setter_int32), FIELD(mobj_t, standingslope, udatalib_getter_slope, mobj_standingslope_noset), FIELD(mobj_t, colorized, udatalib_getter_boolean, udatalib_setter_boolean), - //FIELD(mobj_t, rollmodel, udatalib_getter_boolean, udatalib_setter_boolean), + FIELD(mobj_t, rollmodel, udatalib_getter_boolean, udatalib_setter_boolean), { NULL }, }; #undef FIELD @@ -174,7 +174,6 @@ int mobj_ ## field ## _noset(lua_State *L) \ return luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " should not be set directly.", #field); \ } -//NOSET(sloperoll) NOSET(snext) NOSET(bnext) NOSET(info) @@ -198,6 +197,10 @@ UNIMPLEMENTED(mobjnum) #undef UNIMPLEMENTED +// For some dumb reason it is valid to set sloperoll, even though it is read +// only +int mobj_sloperoll_noop(lua_State *L) { return 0; } + // Now other getters/setters with arbitary logic // Getters get light userdata, which in this case is just mobj_t pointer @@ -233,7 +236,7 @@ int mobj_angle_setter(lua_State *L) return 0; } -/*int mobj_spritescale_setter(lua_State *L) +int mobj_spritescale_setter(lua_State *L) { mobj_t *mo = GETMO(); @@ -251,7 +254,7 @@ int mobj_angle_setter(lua_State *L) mo->realyscale = luaL_checkfixed(L, 2); } return 0; -}*/ +} int mobj_radius_setter(lua_State *L) { diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 91f094b81..c687921ec 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -516,7 +516,9 @@ static int player_get(lua_State *L) } lua_getfield(L, -1, field); if (lua_isnil(L, -1)) // no value for this field + { CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "player_t", field); + } return 1; } diff --git a/src/lua_udatalib.c b/src/lua_udatalib.c index 239e56e13..d7cd68278 100644 --- a/src/lua_udatalib.c +++ b/src/lua_udatalib.c @@ -87,7 +87,7 @@ int udatalib_setter_boolean_nocheck(lua_State *L) UDATALIB_SIMPLE_SETTER(boolean, lua_toboolean) int udatalib_setter_spritenum(lua_State *L) -UDATALIB_SIMPLE_SETTER(spritenum_t, (spritenum_t)luaL_checkinteger) +UDATALIB_SIMPLE_SETTER(spritenum_t, luaL_checkinteger) int udatalib_setter_tic(lua_State *L) UDATALIB_SIMPLE_SETTER(tic_t, (tic_t)luaL_checkinteger) diff --git a/src/lua_udatalib.h b/src/lua_udatalib.h index 30fb0d3a9..36d1ef5ff 100644 --- a/src/lua_udatalib.h +++ b/src/lua_udatalib.h @@ -1,8 +1,6 @@ #ifndef __LUA_UDATALIB_H__ #define __LUA_UDATALIB_H__ -#include - #ifdef HAVE_BLUA #include "doomdef.h" @@ -16,7 +14,7 @@ typedef struct udata_field_s { const char *name; - intptr_t offset; + size_t offset; lua_CFunction getter; lua_CFunction setter; } udata_field_t; @@ -82,8 +80,8 @@ void udatalib_addfields(lua_State *L, int mt, const udata_field_t fields[]); // Get pointer to field value within getter or setter #define UDATALIB_GETFIELD(type, field) \ { \ - intptr_t offset = lua_tointeger(L, lua_upvalueindex(1)); \ - field = (type*)((intptr_t)lua_touserdata(L, 1) + offset); \ + size_t offset = lua_tointeger(L, lua_upvalueindex(1)); \ + field = (type*)((uint8_t*)lua_touserdata(L, 1) + offset); \ } // Creates implementation for simple getter and setter. Super lazy, yes. diff --git a/src/m_menu.c b/src/m_menu.c index a68d11b52..980a4c694 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1404,24 +1404,28 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, -#ifdef HAVE_OPENMPT {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 155} -#endif }; -#ifdef HAVE_OPENMPT + static menuitem_t OP_SoundAdvancedMenu[] = { +#ifdef HAVE_OPENMPT {IT_HEADER, NULL, "Tracker Module Options", NULL, 10}, - {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 42}, - {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 62}, + {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 22}, + {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 42}, #if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR > 4 - {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 82}, + {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 62}, #endif - {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 102}, + {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 82}, +#endif + {IT_HEADER, NULL, "Misc", NULL, 105}, + + {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, + {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 137}, }; -#endif + static menuitem_t OP_DataOptionsMenu[] = { @@ -1694,14 +1698,34 @@ static menuitem_t OP_MonitorToggleMenu[] = static menuitem_t OP_SaturnMenu[] = { {IT_HEADER, NULL, "Saturn Options", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Serverqueue waittime", &cv_connectawaittime, 30}, - //{IT_STRING | IT_CVAR, NULL, "Addon Download Speed", &cv_downloadspeed, 55}, //no idea why you would wanna change it anyways - {IT_STRING | IT_CVAR, NULL, "Skin Select Spinning Speed", &cv_skinselectspin, 50}, - {IT_STRING | IT_CVAR, NULL, "No Midnight Channel Flicker", &cv_lessflicker, 75}, - {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 100}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 115}, + {IT_STRING | IT_CVAR, NULL, "Serverqueue waittime", &cv_connectawaittime, 20}, + {IT_STRING | IT_CVAR, NULL, "Skin Select Spinning Speed", &cv_skinselectspin, 40}, + {IT_STRING | IT_CVAR, NULL, "Input Display outside of RA", &cv_showinput, 50}, + {IT_STRING | IT_CVAR, NULL, "Small Speedometer", &cv_newspeedometer, 60}, + {IT_STRING | IT_CVAR, NULL, "Show Lap Emblem", &cv_showlapemblem, 70}, + {IT_STRING | IT_CVAR, NULL, "Show Minimap Names", &cv_showminimapnames, 80}, + {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 90}, + {IT_STRING | IT_CVAR, NULL, "Less Midnight Channel Flicker", &cv_lessflicker, 110}, + {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 130}, + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 145}, - {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 155}, // uwu + {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 170}, // uwu +}; + +enum +{ + sm_header, + sm_waittime, + sm_skinselspeed, + sm_input, + sm_speedometer, + sm_lapemblem, + sm_mapnames, + sm_smallmap, + sm_pisschannel, + sm_distortionmenu, + sm_hudoffsets, + sm_credits, }; static menuitem_t OP_PlayerDistortMenu[] = @@ -1712,6 +1736,10 @@ static menuitem_t OP_PlayerDistortMenu[] = {IT_STRING | IT_CVAR, NULL, "Slope rotation distance", &cv_sloperolldist, 35}, {IT_STRING | IT_CVAR, NULL, "Rotate players when sliptiding", &cv_sliptideroll, 50}, {IT_STRING | IT_CVAR, NULL, "Player stretch factor", &cv_gravstretch, 65}, + {IT_STRING | IT_CVAR, NULL, "Squish Sound Effect", &cv_slamsound, 80}, + {IT_STRING | IT_CVAR, NULL, "Saltyhop", &cv_saltyhop, 110}, + {IT_STRING | IT_CVAR, NULL, "Saltyhop Sound Effect", &cv_saltyhopsfx, 125}, + {IT_STRING | IT_CVAR, NULL, "Saltyhop Squish", &cv_saltysquish, 140}, }; enum @@ -1745,25 +1773,27 @@ static menuitem_t OP_SaturnCreditsMenu[] = {IT_HEADER, NULL, "Main Devs <3", NULL, 20}, - {IT_STRING, NULL, "alufolie91 aka Alug", NULL, 30}, - {IT_STRING, NULL, "Indev", NULL, 40}, + {IT_STRING2+IT_SPACE, NULL, "alufolie91 aka Alug", NULL, 30}, + {IT_STRING2+IT_SPACE, NULL, "Indev", NULL, 40}, {IT_HEADER, NULL, "Testers <3", NULL, 60}, - {IT_STRING, NULL, "Sunflower aka AnimeSonic", NULL, 70}, - {IT_STRING, NULL, "Yuz aka Yuzler", NULL, 80}, - {IT_STRING, NULL, "Democrab", NULL, 90}, - {IT_STRING, NULL, "EXpand aka Maver", NULL, 100}, + {IT_STRING2+IT_SPACE, NULL, "Sunflower aka AnimeSonic", NULL, 70}, + {IT_STRING2+IT_SPACE, NULL, "Yuz aka Yuzler", NULL, 80}, + {IT_STRING2+IT_SPACE, NULL, "Democrab", NULL, 90}, + {IT_STRING2+IT_SPACE, NULL, "EXpand aka Maver", NULL, 100}, {IT_HEADER, NULL, "Special Thanks <3", NULL, 120}, - {IT_STRING, NULL, "xyzzy", NULL, 130}, - {IT_STRING, NULL, "Haya", NULL, 140}, - {IT_STRING, NULL, "Galactice", NULL, 150}, - {IT_STRING, NULL, "Himie and", NULL, 160}, - {IT_STRING, NULL, "The Moe Mansion / Birdhouse Team", NULL, 170}, - {IT_STRING, NULL, "All of Sunflower's Garden", NULL, 180}, + {IT_STRING2+IT_SPACE, NULL, "xyzzy", NULL, 130}, + {IT_STRING2+IT_SPACE, NULL, "Haya", NULL, 140}, + {IT_STRING2+IT_SPACE, NULL, "Galactice", NULL, 150}, + {IT_STRING2+IT_SPACE, NULL, "Himie and", NULL, 160}, + {IT_STRING2+IT_SPACE, NULL, "The Moe Mansion / Birdhouse Team", NULL, 170}, + {IT_STRING2+IT_SPACE, NULL, "All of Sunflower's Garden", NULL, 180}, + {IT_STRING+IT_SPACE, NULL, "", NULL, 190}, // dummy text + {IT_STRING, NULL, "", NULL, 200}, // dummy text II }; static menuitem_t OP_BirdMenu[] = @@ -2340,8 +2370,8 @@ menu_t OP_DiscordOptionsDef = DEFAULTMENUSTYLE(NULL, OP_DiscordOptionsMenu, &OP_ #endif menu_t OP_EraseDataDef = DEFAULTMENUSTYLE("M_DATA", OP_EraseDataMenu, &OP_DataOptionsDef, 30, 30); -menu_t OP_SaturnDef = DEFAULTMENUSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 30); -menu_t OP_PlayerDistortDef = DEFAULTMENUSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 60); +menu_t OP_SaturnDef = DEFAULTMENUSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 15); +menu_t OP_PlayerDistortDef = DEFAULTMENUSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 30); menu_t OP_HudOffsetDef = DEFAULTMENUSTYLE(NULL, OP_HudOffsetMenu, &OP_SaturnDef, 30, 20); menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 10); @@ -3437,6 +3467,18 @@ void M_Drawer(void) #else // Regular build V_DrawThinString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, va("%s", VERSIONSTRING)); #endif + +#ifdef HWRENDER + if (rendermode == render_opengl) + { + V_DrawThinString(0, 0, V_GREENMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Opengl")); + } +#endif + if (rendermode == render_soft) + { + V_DrawThinString(0, 0, V_REDMAP|V_SNAPTOTOP|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("Software")); + } + } } } @@ -3826,6 +3868,9 @@ void M_Init(void) OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; #endif + if (!found_extra_kart) // why bother? + OP_SaturnMenu[sm_speedometer].status = IT_GRAYEDOUT; + #ifndef NONET CV_RegisterVar(&cv_serversort); #endif @@ -11050,7 +11095,7 @@ static void M_DrawJoystick(void) compareval4 = cv_usejoystick4.value; compareval3 = cv_usejoystick3.value; compareval2 = cv_usejoystick2.value; - compareval = cv_usejoystick.value + compareval = cv_usejoystick.value; #endif if ((setupcontrolplayer == 4 && (i == compareval4)) diff --git a/src/p_mobj.c b/src/p_mobj.c index f29a63f43..8aa726870 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3792,12 +3792,11 @@ void P_NullPrecipThinker(precipmobj_t *mobj) { //(void)mobj; mobj->precipflags &= ~PCF_THUNK; + R_ResetPrecipitationMobjInterpolationState(mobj); } void P_SnowThinker(precipmobj_t *mobj) { - R_ResetPrecipitationMobjInterpolationState(mobj); - P_CycleStateAnimation((mobj_t *)mobj); // adjust height @@ -3810,8 +3809,6 @@ void P_SnowThinker(precipmobj_t *mobj) void P_RainThinker(precipmobj_t *mobj) { - R_ResetPrecipitationMobjInterpolationState(mobj); - P_CycleStateAnimation((mobj_t *)mobj); if (mobj->state != &states[S_RAIN1]) @@ -3838,17 +3835,18 @@ void P_RainThinker(precipmobj_t *mobj) } // adjust height - if ((mobj->z += mobj->momz) <= mobj->floorz) + if ((mobj->z += mobj->momz) > mobj->floorz) + return; + + // no splashes on sky or bottomless pits + if (mobj->precipflags & PCF_PIT) { - // no splashes on sky or bottomless pits - if (mobj->precipflags & PCF_PIT) - mobj->z = mobj->ceilingz; - else - { - mobj->z = mobj->floorz; - P_SetPrecipMobjState(mobj, S_SPLASH1); - } + mobj->z = mobj->ceilingz; + return; } + + mobj->z = mobj->floorz; + P_SetPrecipMobjState(mobj, S_SPLASH1); } static void P_RingThinker(mobj_t *mobj) @@ -9564,6 +9562,9 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->spriteyscale = mobj->realyscale; mobj->spritexoffset = mobj->spriteyoffset = 0; + // Funni slam sound when landing + mobj->slamsoundtimer = 0; + // set subsector and/or block links P_SetThingPosition(mobj); I_Assert(mobj->subsector != NULL); diff --git a/src/p_mobj.h b/src/p_mobj.h index 872c9dd5e..004a437c4 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -23,6 +23,7 @@ // We need the WAD data structure for Map things, from the THINGS lump. #include "doomdata.h" +#include "doomtype.h" // States are tied to finite states are tied to animation frames. // Needs precompiled tables/data structures. @@ -394,6 +395,16 @@ typedef struct mobj_s boolean colorized; // Whether the mobj uses the rainbow colormap boolean rollmodel; // OpenGL: Should this model rotate? + tic_t slamsoundtimer; + + // saltyhop! hardcode edition + boolean salty_ready; + boolean salty_tapping; + fixed_t salty_zoffset; + fixed_t salty_momz; + boolean salty_jump; + boolean init_salty; + // WARNING: New fields must be added separately to savegame and Lua. } mobj_t; diff --git a/src/p_saveg.c b/src/p_saveg.c index 673f1cb40..bc836b6e5 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1984,6 +1984,7 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->spritexscale = mobj->spriteyscale = mobj->old_spritexscale = mobj->old_spriteyscale = FRACUNIT; mobj->realxscale = mobj->realyscale = FRACUNIT; mobj->stretchslam = 0; + mobj->slamsoundtimer = 0; mobj->sloperoll = mobj->reservezangle = mobj->reservexydir = 0; diff --git a/src/p_user.c b/src/p_user.c index 700671ef6..feed77bd7 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1278,13 +1278,13 @@ void P_RestoreMusic(player_t *player) } // Item - Grow - if (wantedmus == 2) + if (wantedmus == 2 && cv_growmusic.value) { S_ChangeMusicInternal("kgrow", true); S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); } // Item - Invincibility - else if (wantedmus == 1) + else if (wantedmus == 1 && cv_supermusic.value) { S_ChangeMusicInternal("kinvnc", true); S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); diff --git a/src/r_fps.c b/src/r_fps.c index ce7d08a7a..ac315c6a7 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -293,13 +293,13 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->scale = mobj->resetinterp ? mobj->scale : R_LerpFixed(mobj->old_scale, mobj->scale, frac); out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); - //out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - //out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); + out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); + out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); // Sprite offsets are not interpolated until we have a way to interpolate them explicitly in Lua. // It seems existing mods visually break more often than not if it is interpolated. - out->spritexoffset = mobj->spritexoffset; - out->spriteyoffset = mobj->spriteyoffset; + //out->spritexoffset = mobj->spritexoffset; + //out->spriteyoffset = mobj->spriteyoffset; out->subsector = R_PointInSubsector(out->x, out->y); @@ -357,11 +357,12 @@ static void AddInterpolator(levelinterpolator_t* interpolator) levelinterpolators_size *= 2; } - levelinterpolators = Z_Realloc( + levelinterpolators = Z_ReallocAlign( (void*) levelinterpolators, sizeof(levelinterpolator_t*) * levelinterpolators_size, PU_LEVEL, - NULL + NULL, + sizeof(levelinterpolator_t*) * 8 ); } @@ -371,8 +372,11 @@ static void AddInterpolator(levelinterpolator_t* interpolator) static levelinterpolator_t *CreateInterpolator(levelinterpolator_type_e type, thinker_t *thinker) { - levelinterpolator_t *ret = (levelinterpolator_t*) Z_Calloc( - sizeof(levelinterpolator_t), PU_LEVEL, NULL + levelinterpolator_t *ret = (levelinterpolator_t*) Z_CallocAlign( + sizeof(levelinterpolator_t), + PU_LEVEL, + NULL, + sizeof(levelinterpolator_t) * 8 ); ret->type = type; @@ -687,11 +691,12 @@ void R_AddMobjInterpolator(mobj_t *mobj) interpolated_mobjs_capacity *= 2; } - interpolated_mobjs = Z_Realloc( + interpolated_mobjs = Z_ReallocAlign( interpolated_mobjs, sizeof(mobj_t *) * interpolated_mobjs_capacity, PU_LEVEL, - NULL + NULL, + 64 ); } diff --git a/src/r_main.c b/src/r_main.c index cd4c99b69..dc914e79a 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -160,6 +160,7 @@ static CV_PossibleValue_t drawdist_cons_t[] = { static CV_PossibleValue_t drawdist_precip_cons_t[] = { {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, + {3072, "3072"}, {4096, "4096"}, {0, "None"}, {0, NULL}}; static CV_PossibleValue_t fov_cons_t[] = {{5*FRACUNIT, "MIN"}, {178*FRACUNIT, "MAX"}, {0, NULL}}; diff --git a/src/r_things.c b/src/r_things.c index a33f908dc..26dad2f0b 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1796,17 +1796,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; } - // okay, we can't return now except for vertical clipping... this is a hack, but weather isn't networked, so it should be ok - if (!(thing->precipflags & PCF_THUNK)) - { - if (thing->precipflags & PCF_RAIN) - P_RainThinker(thing); - else - P_SnowThinker(thing); - thing->precipflags |= PCF_THUNK; - } - - //SoM: 3/17/2000: Disregard sprites that are out of view.. gzt = interp.z + spritecachedinfo[lump].topoffset; gz = gzt - spritecachedinfo[lump].height; @@ -1814,7 +1803,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) if (thing->subsector->sector->cullheight) { if (R_DoCulling(thing->subsector->sector->cullheight, viewsector->cullheight, viewz, gz, gzt)) - return; + goto weatherthink; } // store information in a vissprite @@ -1878,6 +1867,18 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->precip = true; vis->vflip = false; vis->isScaled = false; + +weatherthink: + // okay... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } + } // R_AddSprites diff --git a/src/r_things.h b/src/r_things.h index 22c975daa..ab4688f91 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -138,11 +138,6 @@ typedef struct vissprite_s angle_t centerangle; // for paper sprites - struct { - fixed_t tan; // The amount to shear the sprite vertically per row - INT32 offset; // The center of the shearing location offset from x1 - } shear; - fixed_t texturemid; patch_t *patch; diff --git a/src/s_sound.c b/src/s_sound.c index 4f746c6f0..977d3be55 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -54,6 +54,7 @@ static void SetChannelsNum(void); static void Command_Tunes_f(void); static void Command_RestartAudio_f(void); static void Command_RestartMusic_f(void); //mhhhm amiga type filters here i come uwu +static void Command_ShowMusicCredit_f(void); // Sound system toggles #ifndef NO_MIDI @@ -322,6 +323,7 @@ void S_RegisterSoundStuff(void) COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); COM_AddCommand("restartmusic", Command_RestartMusic_f); + COM_AddCommand("showmusiccredit", Command_ShowMusicCredit_f); #if defined (macintosh) && !defined (HAVE_SDL) // mp3 playlist stuff @@ -1514,6 +1516,32 @@ void S_InitMusicDefs(void) S_LoadMusicDefs(i); } + +// +// S_FindMusicCredit +// +// Returns musicdef of specified song, or null if musicdef for it doesn't exist +// +musicdef_t *S_FindMusicCredit(const char *musname) +{ + musicdef_t *def = musicdefstart; + + if (!def) // No definitions + return NULL; + + while (def) + { + if (!stricmp(def->name, musname)) + { + return def; + } + else + def = def->next; + } + + return NULL; +} + // // S_ShowSpecifiedMusicCredit // @@ -1521,26 +1549,21 @@ void S_InitMusicDefs(void) // void S_ShowSpecifiedMusicCredit(const char *musname) { - musicdef_t *def = musicdefstart; + musicdef_t *def; + + if (digital_disabled) return; if (!cv_songcredits.value || demo.rewinding) return; - if (!def) // No definitions - return; + def = S_FindMusicCredit(musname); - while (def) + if (def) { - if (!stricmp(def->name, musname)) - { - cursongcredit.def = def; - cursongcredit.anim = 5*TICRATE; - cursongcredit.x = 0; - cursongcredit.trans = NUMTRANSMAPS; - return; - } - else - def = def->next; + cursongcredit.def = def; + cursongcredit.anim = 5*TICRATE; + cursongcredit.x = 0; + cursongcredit.trans = NUMTRANSMAPS; } } @@ -2175,6 +2198,26 @@ static void Command_RestartMusic_f(void) //same as RestartAudio but only music g S_RestartMusic(); } +static void Command_ShowMusicCredit_f(void) +{ + const char *musname = music_name; + + if (COM_Argc() > 1) + { + musname = COM_Argv(1); + } + else + { + S_ShowMusicCredit(); + } + + musicdef_t *def = S_FindMusicCredit(musname); + + if (def) { + CONS_Printf("%.6s - %.255s\n", musname, def->source); + } +} + void GameSounds_OnChange(void) { if (M_CheckParm("-nosound") || M_CheckParm("-noaudio")) diff --git a/src/s_sound.h b/src/s_sound.h index 2dd39f6f4..f19361714 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -172,6 +172,7 @@ extern musicdef_t *musicdefstart; void S_LoadMusicDefs(UINT16 wadnum); void S_InitMusicDefs(void); +musicdef_t *S_FindMusicCredit(const char *musname); void S_ShowSpecifiedMusicCredit(const char *musname); void S_ShowMusicCredit(void); diff --git a/src/screen.c b/src/screen.c index 95fd62658..e4a1f3136 100644 --- a/src/screen.c +++ b/src/screen.c @@ -137,10 +137,12 @@ void SCR_SetMode(void) { if (R_MMX) { - colfunc = basecolfunc = R_DrawColumn_8_MMX; + //colfunc = basecolfunc = R_DrawColumn_8_MMX; Can we please not use this function it seems to break sometimes???? + colfunc = basecolfunc = R_DrawColumn_8_ASM; //shadecolfunc = R_DrawShadeColumn_8_ASM; //fuzzcolfunc = R_DrawTranslucentColumn_8_ASM; - walldrawerfunc = R_DrawWallColumn_8_MMX; + //walldrawerfunc = R_DrawWallColumn_8_MMX; This is just an alias to R_DrawColumn_8_MMX + walldrawerfunc = R_DrawWallColumn_8_ASM; twosmultipatchfunc = R_Draw2sMultiPatchColumn_8_MMX; spanfunc = basespanfunc = R_DrawSpan_8_MMX; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 30eab8711..3fd96819c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2059,8 +2059,13 @@ void I_StartupGraphics(void) #endif if (rendermode == render_none) { +#ifdef HWRENDER + rendermode = render_opengl; + CONS_Printf("Defaulting to OpenGL renderer.\n"); +#else rendermode = render_soft; CONS_Printf("Using default software renderer.\n"); +#endif } } diff --git a/src/v_video.c b/src/v_video.c index 0b5231c02..602e89248 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -73,7 +73,7 @@ consvar_t cv_grgammablue = {"gr_gammablue", "127", CV_SAVE|CV_CALL, grgamma_cons //static CV_PossibleValue_t CV_MD2[] = {{0, "Off"}, {1, "On"}, {2, "Old"}, {0, NULL}}; // console variables in development -consvar_t cv_grmdls = {"gr_mdls", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grshearing = {"gr_shearing", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1770,6 +1770,12 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) } } +void V_DrawCenteredSmallString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x -= V_SmallStringWidth(string, option)/2; + V_DrawSmallString(x, y, option, string); +} + void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *string) { x -= V_SmallStringWidth(string, option); @@ -1983,6 +1989,102 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) } } +// Jaden: awesome! +void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + fixed_t cx = x, cy = y; + INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + const char *ch = string; + INT32 charflags = 0; + const UINT8 *colormap = NULL; + INT32 spacewidth = 2, charwidth = 0; + INT32 lowercase = (option & V_ALLOWLOWERCASE); + option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... + if (option & V_NOSCALESTART) + { + dupx = vid.dupx; + dupy = vid.dupy; + scrwidth = vid.width; + } + else + { + dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } + if (option & V_NOSCALEPATCH) + scrwidth *= vid.dupx; + charflags = (option & V_CHARCOLORMASK); + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 4; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 4; + break; + case V_6WIDTHSPACE: + spacewidth = 3; + default: + break; + } + for (;;ch++) + { + if (!*ch) + break; + if (*ch & 0x80) //color parsing -x 2.16.09 + { + // manually set flags override color codes + if (!(option & V_CHARCOLORMASK)) + charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; + continue; + } + if (*ch == '\n') + { + cx = x; + if (option & V_RETURN8) + cy += (4*dupy)<= HU_FONTSIZE || !hu_font[c]) + { + cx += (spacewidth * dupx)<width*(dupx/4); + } + else + w = hu_font[c]->width * dupx / 2; + if ((cx>>FRACBITS) > scrwidth) + break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check + { + cx += w<width) - 1; + + if (flags & V_NOSCALESTART) + w *= vid.dupx; + + if (num < 0) + num = -num; + + // draw the number + do + { + x -= (w - 1); + + V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, flags, ranknum[num % 10], colormap); + num /= 10; + } while (--digits); +} + // Write a string using the credit font // NOTE: the text is centered for screens larger than the base width // @@ -2347,6 +2471,167 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) return w; } +char V_GetSkincolorChar(INT32 color) +{ + char cstart = 0x80; + + switch (color) + { + case SKINCOLOR_WHITE: + case SKINCOLOR_SILVER: + case SKINCOLOR_SLATE: + cstart = 0x80; // White + break; + + case SKINCOLOR_GREY: + case SKINCOLOR_NICKEL: + case SKINCOLOR_BLACK: + case SKINCOLOR_SKUNK: + case SKINCOLOR_JET: + cstart = 0x86; // V_GRAYMAP + break; + + case SKINCOLOR_SEPIA: + case SKINCOLOR_BEIGE: + case SKINCOLOR_WALNUT: + case SKINCOLOR_BROWN: + case SKINCOLOR_LEATHER: + case SKINCOLOR_RUST: + case SKINCOLOR_WRISTWATCH: + cstart = 0x8e; // V_BROWNMAP + break; + + case SKINCOLOR_FAIRY: + case SKINCOLOR_SALMON: + case SKINCOLOR_PINK: + case SKINCOLOR_ROSE: + case SKINCOLOR_BRICK: + case SKINCOLOR_LEMONADE: + case SKINCOLOR_BUBBLEGUM: + case SKINCOLOR_LILAC: + cstart = 0x8d; // V_PINKMAP + break; + + case SKINCOLOR_CINNAMON: + case SKINCOLOR_RUBY: + case SKINCOLOR_RASPBERRY: + case SKINCOLOR_CHERRY: + case SKINCOLOR_RED: + case SKINCOLOR_CRIMSON: + case SKINCOLOR_MAROON: + case SKINCOLOR_FLAME: + case SKINCOLOR_SCARLET: + case SKINCOLOR_KETCHUP: + cstart = 0x85; // V_REDMAP + break; + + case SKINCOLOR_DAWN: + case SKINCOLOR_SUNSET: + case SKINCOLOR_CREAMSICLE: + case SKINCOLOR_ORANGE: + case SKINCOLOR_PUMPKIN: + case SKINCOLOR_ROSEWOOD: + case SKINCOLOR_BURGUNDY: + case SKINCOLOR_TANGERINE: + cstart = 0x87; // V_ORANGEMAP + break; + + case SKINCOLOR_PEACH: + case SKINCOLOR_CARAMEL: + case SKINCOLOR_CREAM: + cstart = 0x8f; // V_PEACHMAP + break; + + case SKINCOLOR_GOLD: + case SKINCOLOR_ROYAL: + case SKINCOLOR_BRONZE: + case SKINCOLOR_COPPER: + case SKINCOLOR_THUNDER: + cstart = 0x8a; // V_GOLDMAP + break; + + case SKINCOLOR_POPCORN: + case SKINCOLOR_QUARRY: + case SKINCOLOR_YELLOW: + case SKINCOLOR_MUSTARD: + case SKINCOLOR_CROCODILE: + case SKINCOLOR_OLIVE: + cstart = 0x82; // V_YELLOWMAP + break; + + case SKINCOLOR_ARTICHOKE: + case SKINCOLOR_VOMIT: + case SKINCOLOR_GARDEN: + case SKINCOLOR_TEA: + case SKINCOLOR_PISTACHIO: + cstart = 0x8b; // V_TEAMAP + break; + + case SKINCOLOR_LIME: + case SKINCOLOR_HANDHELD: + case SKINCOLOR_MOSS: + case SKINCOLOR_CAMOUFLAGE: + case SKINCOLOR_ROBOHOOD: + case SKINCOLOR_MINT: + case SKINCOLOR_GREEN: + case SKINCOLOR_PINETREE: + case SKINCOLOR_EMERALD: + case SKINCOLOR_SWAMP: + case SKINCOLOR_DREAM: + case SKINCOLOR_PLAGUE: + case SKINCOLOR_ALGAE: + cstart = 0x83; // V_GREENMAP + break; + + case SKINCOLOR_CARIBBEAN: + case SKINCOLOR_AZURE: + case SKINCOLOR_AQUA: + case SKINCOLOR_TEAL: + case SKINCOLOR_CYAN: + case SKINCOLOR_JAWZ: + case SKINCOLOR_CERULEAN: + case SKINCOLOR_NAVY: + case SKINCOLOR_SAPPHIRE: + cstart = 0x88; // V_SKYMAP + break; + + case SKINCOLOR_PIGEON: + case SKINCOLOR_PLATINUM: + case SKINCOLOR_STEEL: + cstart = 0x8c; // V_STEELMAP + break; + + case SKINCOLOR_PERIWINKLE: + case SKINCOLOR_BLUE: + case SKINCOLOR_BLUEBERRY: + case SKINCOLOR_NOVA: + cstart = 0x84; // V_BLUEMAP + break; + + case SKINCOLOR_ULTRAVIOLET: + case SKINCOLOR_PURPLE: + case SKINCOLOR_FUCHSIA: + cstart = 0x81; // V_PURPLEMAP + break; + + case SKINCOLOR_PASTEL: + case SKINCOLOR_MOONSLAM: + case SKINCOLOR_DUSK: + case SKINCOLOR_TOXIC: + case SKINCOLOR_MAUVE: + case SKINCOLOR_LAVENDER: + case SKINCOLOR_BYZANTIUM: + case SKINCOLOR_POMEGRANATE: + cstart = 0x89; // V_LAVENDERMAP + break; + + default: + break; + } + + return cstart; +} + boolean *heatshifter = NULL; INT32 lastheight = 0; INT32 heatindex[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; diff --git a/src/v_video.h b/src/v_video.h index f8024c8a2..7a9471deb 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -191,6 +191,7 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // draw a string using the hu_font, 0.5x scale void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string); +void V_DrawCenteredSmallString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *string); // draw a string using the tny_font @@ -200,6 +201,9 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawCenteredSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); + // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits); @@ -212,6 +216,9 @@ INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *color INT32 V_LevelNameWidth(const char *string); INT32 V_LevelNameHeight(const char *string); +// Rank numbers. +void V_DrawRankNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap); + void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string); INT32 V_CreditStringWidth(const char *string); @@ -222,6 +229,8 @@ INT32 V_SmallStringWidth(const char *string, INT32 option); // Find string width from tny_font chars INT32 V_ThinStringWidth(const char *string, INT32 option); +char V_GetSkincolorChar(INT32 color); + void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); void V_DrawPatchFill(patch_t *pat); diff --git a/src/y_inter.c b/src/y_inter.c index 9892571b4..3fb2d3aa3 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -121,6 +121,7 @@ intertype_t intertype = int_none; #ifdef HAVE_BLUA static huddrawlist_h luahuddrawlist_intermission = NULL; +static huddrawlist_h luahuddrawlist_vote = NULL; #endif static void Y_FollowIntermission(void); @@ -366,15 +367,6 @@ void Y_IntermissionDrawer(void) if (usebuffer) // Fade everything out V_DrawFadeScreen(0xFF00, 22); -#ifdef HAVE_BLUA - if (renderisnewtic) - { - LUA_HUD_ClearDrawList(luahuddrawlist_intermission); - LUAh_IntermissionHUD(luahuddrawlist_intermission); - } - LUA_HUD_DrawList(luahuddrawlist_intermission); -#endif - if (!splitscreen) whiteplayer = demo.playback ? displayplayers[0] : consoleplayer; @@ -609,6 +601,15 @@ dotimer: // Make it obvious that scrambling is happening next round. if (cv_scrambleonchange.value && cv_teamscramble.value && (intertic/TICRATE % 2 == 0)) V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, hilicol, M_GetText("Teams will be scrambled next round!")); + +#ifdef HAVE_BLUA + if (renderisnewtic) + { + LUA_HUD_ClearDrawList(luahuddrawlist_intermission); + LUAh_IntermissionHUD(luahuddrawlist_intermission); + } + LUA_HUD_DrawList(luahuddrawlist_intermission); +#endif } // @@ -1230,6 +1231,15 @@ void Y_VoteDrawer(void) V_DrawCenteredString(BASEVIDWIDTH/2, 188, hilicol, va("Vote ends in %d", tickdown)); } + +#ifdef HAVE_BLUA + if (renderisnewtic) + { + LUA_HUD_ClearDrawList(luahuddrawlist_vote); + LUAh_VoteHUD(luahuddrawlist_vote); + } + LUA_HUD_DrawList(luahuddrawlist_vote); +#endif } // @@ -1559,6 +1569,11 @@ void Y_StartVote(void) } voteclient.loaded = true; + +#ifdef HAVE_BLUA + LUA_HUD_DestroyDrawList(luahuddrawlist_vote); + luahuddrawlist_vote = LUA_HUD_CreateDrawList(); +#endif } // diff --git a/src/z_zone.c b/src/z_zone.c index 0109d21c6..b92707ef4 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -1,7 +1,7 @@ // SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2006 by Graue. -// Copyright (C) 2006-2023 by Sonic Team Junior. +// Copyright (C) 2006-2018 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. @@ -27,7 +27,6 @@ #include "doomdef.h" #include "doomstat.h" -#include "r_patch.h" #include "i_system.h" // I_GetFreeMem #include "i_video.h" // rendermode #include "z_zone.h" @@ -50,11 +49,27 @@ static boolean Z_calloc = false; //#define ZDEBUG2 #endif +struct memblock_s; + +typedef struct +{ + struct memblock_s *block; // Describing this memory + UINT32 id; // Should be ZONEID +} ATTRPACK memhdr_t; + +// Some code might want aligned memory. Assume it wants memory n bytes +// aligned -- then we allocate n-1 extra bytes and return a pointer to +// the first byte aligned as requested. +// Thus, "real" is the pointer we get from malloc() and will free() +// later, but "hdr" is where the memhdr_t starts. +// For non-aligned allocations they will be the same. typedef struct memblock_s { + void *real; + memhdr_t *hdr; + void **user; INT32 tag; // purgelevel - UINT32 id; // Should be ZONEID size_t size; // including the header and blocks size_t realsize; // size of real data only @@ -65,41 +80,74 @@ typedef struct memblock_s #endif struct memblock_s *next, *prev; -} memblock_t; +} ATTRPACK memblock_t; -#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t)) -#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - sizeof(memblock_t)) +#ifdef ZDEBUG +#define Ptr2Memblock(s, f) Ptr2Memblock2(s, f, __FILE__, __LINE__) +static memblock_t *Ptr2Memblock2(void *ptr, const char* func, const char *file, INT32 line) +#else +static memblock_t *Ptr2Memblock(void *ptr, const char* func) +#endif +{ + memhdr_t *hdr; + memblock_t *block; + + if (ptr == NULL) + return NULL; + +#ifdef ZDEBUG2 + CONS_Printf("%s %s:%d\n", func, file, line); +#endif + + hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); + +#ifdef VALGRIND_MAKE_MEM_DEFINED + VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); +#endif + +#ifdef VALGRIND_MEMPOOL_EXISTS + if (!VALGRIND_MEMPOOL_EXISTS(hdr->block)) + { +#ifdef ZDEBUG + I_Error("%s: bad memblock from %s:%d", func, file, line); +#else + I_Error("%s: bad memblock", func); +#endif + } +#endif + if (hdr->id != ZONEID) + { +#ifdef ZDEBUG + I_Error("%s: wrong id from %s:%d", func, file, line); +#else + I_Error("%s: wrong id", func); +#endif + } + block = hdr->block; +#ifdef VALGRIND_MAKE_MEM_NOACCESS + VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); +#endif + return block; + +} -// both the head and tail of the zone memory block list static memblock_t head; -// -// Function prototypes -// static void Command_Memfree_f(void); #ifdef ZDEBUG static void Command_Memdump_f(void); #endif -// -------------------------- -// Zone memory initialisation -// -------------------------- - -/** Initialises zone memory. - * Used at game startup. - * - * \sa I_GetFreeMem, Command_Memfree_f, Command_Memdump_f - */ void Z_Init(void) { - size_t total, memfree; + UINT32 total, memfree; memset(&head, 0x00, sizeof(head)); head.next = head.prev = &head; memfree = I_GetFreeMem(&total)>>20; - CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree)); + CONS_Printf("System memory: %uMB - Free: %uMB\n", total>>20, memfree); // Note: This allocates memory. Watch out. COM_AddCommand("memfree", Command_Memfree_f); @@ -109,17 +157,6 @@ void Z_Init(void) #endif } - -// ---------------------- -// Zone memory allocation -// ---------------------- - -/** Frees allocated memory. - * - * \param ptr A pointer to allocated memory, - * assumed to have been allocated with Z_Malloc/Z_Calloc. - * \sa Z_FreeTags - */ #ifdef ZDEBUG void Z_Free2(void *ptr, const char *file, INT32 line) #else @@ -135,14 +172,10 @@ void Z_Free(void *ptr) CONS_Debug(DBG_MEMORY, "Z_Free %s:%d\n", file, line); #endif - block = MEMBLOCK(ptr); -#ifdef PARANOIA - if (block->id != ZONEID) #ifdef ZDEBUG - I_Error("Z_Free at %s:%d: wrong id", file, line); + block = Ptr2Memblock2(ptr, "Z_Free", file, line); #else - I_Error("Z_Free: wrong id"); -#endif + block = Ptr2Memblock(ptr, "Z_Free"); #endif #ifdef ZDEBUG @@ -150,9 +183,11 @@ void Z_Free(void *ptr) CONS_Debug(DBG_MEMORY, "Z_Free at %s:%d\n", file, line); #endif +#ifdef HAVE_BLUA // anything that isn't by lua gets passed to lua just in case. if (block->tag != PU_LUA) LUA_InvalidateUserdata(ptr); +#endif // TODO: if zdebugging, make sure no other block has a user // that is about to be freed. @@ -161,27 +196,21 @@ void Z_Free(void *ptr) if (block->user != NULL) *block->user = NULL; -#ifdef VALGRIND_DESTROY_MEMPOOL - VALGRIND_DESTROY_MEMPOOL(block); -#endif + // Free the memory and get rid of the block. + free(block->real); block->prev->next = block->next; block->next->prev = block->prev; free(block); +#ifdef VALGRIND_DESTROY_MEMPOOL + VALGRIND_DESTROY_MEMPOOL(block); +#endif } -/** malloc() that doesn't accept failure. - * - * \param size Amount of memory to be allocated, in bytes. - * \return A pointer to the allocated memory. - */ +// malloc() that doesn't accept failure. static void *xm(size_t size) { const size_t padedsize = size+sizeof (size_t); - void *p; - - if (padedsize < size)/* overflow check */ - I_Error("You are allocating memory too large!"); - p = malloc(padedsize); + void *p = malloc(padedsize); if (p == NULL) { @@ -191,6 +220,10 @@ static void *xm(size_t size) if (p == NULL) { +#if defined (_NDS) | defined (_PSP) + // Temporary-ish debugging measure + Command_Memfree_f(); +#endif I_Error("Out of memory allocating %s bytes", sizeu1(size)); } } @@ -198,18 +231,10 @@ static void *xm(size_t size) return p; } -/** The Z_MallocAlign function. - * Allocates a block of memory, adds it to a linked list so we can keep track of it. - * - * \param size Amount of memory to be allocated, in bytes. - * \param tag Purge tag. - * \param user The address of a pointer to the memory to be allocated. - * When the memory is freed by Z_Free later, - * the pointer at this address will then be automatically set to NULL. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. - * \note You can pass Z_Malloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_CallocAlign, Z_ReallocAlign - */ +// Z_Malloc +// You can pass Z_Malloc() a NULL user if the tag is less than +// PU_PURGELEVEL. + #ifdef ZDEBUG void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) @@ -217,67 +242,75 @@ void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) #endif { + size_t extrabytes = (1<next = head.next; block->prev = &head; head.next = block; block->next->prev = block; + block->real = ptr; + block->hdr = hdr; block->tag = tag; block->user = NULL; #ifdef ZDEBUG block->ownerline = line; block->ownerfile = file; #endif - block->size = sizeof (memblock_t) + size; + block->size = blocksize; block->realsize = size; -#ifdef VALGRIND_CREATE_MEMPOOL - VALGRIND_CREATE_MEMPOOL(block, size, Z_calloc); -#endif + hdr->id = ZONEID; + hdr->block = block; - block->id = ZONEID; +#ifdef VALGRIND_MAKE_MEM_NOACCESS + VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); +#endif if (user != NULL) { block->user = user; - *(void **)user = ptr; + *(void **)user = given; } else if (tag >= PU_PURGELEVEL) I_Error("Z_Malloc: attempted to allocate purgable block " "(size %s) with no user", sizeu1(size)); - return ptr; + return given; } -/** The Z_CallocAlign function. - * Allocates a block of memory, adds it to a linked list so we can keep track of it. - * Unlike Z_MallocAlign, this also initialises the bytes to zero. - * - * \param size Amount of memory to be allocated, in bytes. - * \param tag Purge tag. - * \param user The address of a pointer to the memory to be allocated. - * When the memory is freed by Z_Free later, - * the pointer at this address will then be automatically set to NULL. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. - * \note You can pass Z_Calloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_MallocAlign, Z_ReallocAlign - */ #ifdef ZDEBUG void *Z_Calloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) #else @@ -294,26 +327,10 @@ void *Z_CallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) #endif } -/** The Z_ReallocAlign function. - * Reallocates a block of memory with a new size. - * - * \param ptr A pointer to allocated memory, - * assumed to have been allocated with Z_Malloc/Z_Calloc. - * If NULL, this function instead acts as a wrapper for Z_CallocAlign. - * \param size New size of memory block, in bytes. - * If zero, then the memory is freed and NULL is returned. - * \param tag New purge tag. - * \param user The address of a pointer to the memory to be reallocated. - * This can be a different user to the one originally assigned to the memory block. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. - * \return A pointer to the reallocated memory. Can be NULL if memory was freed. - * \note You can pass Z_Realloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_MallocAlign, Z_CallocAlign - */ #ifdef ZDEBUG void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) #else -void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) +void *Z_ReallocAlign(void *ptr, size_t size,INT32 tag, void *user, INT32 alignbits) #endif { void *rez; @@ -339,14 +356,10 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb #endif } - block = MEMBLOCK(ptr); -#ifdef PARANOIA - if (block->id != ZONEID) #ifdef ZDEBUG - I_Error("Z_ReallocAlign at %s:%d: wrong id", file, line); + block = Ptr2Memblock2(ptr, "Z_Realloc", file, line); #else - I_Error("Z_ReallocAlign: wrong id"); -#endif + block = Ptr2Memblock(ptr, "Z_Realloc"); #endif if (block == NULL) @@ -384,11 +397,6 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb return rez; } -/** Frees all memory for a given set of tags. - * - * \param lowtag The lowest tag to consider. - * \param hightag The highest tag to consider. - */ void Z_FreeTags(INT32 lowtag, INT32 hightag) { memblock_t *block, *next; @@ -397,57 +405,28 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag) for (block = head.next; block != &head; block = next) { next = block->next; // get link before freeing + if (block->tag >= lowtag && block->tag <= hightag) - Z_Free(MEMORY(block)); + Z_Free((UINT8 *)block->hdr + sizeof *block->hdr); } } -/** Iterates through all memory for a given set of tags. - * - * \param lowtag The lowest tag to consider. - * \param hightag The highest tag to consider. - * \param iterfunc The iterator function. - */ -void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)) -{ - memblock_t *block, *next; +// +// Z_CheckMemCleanup +// +// TODO: Currently blocks >= PU_PURGELEVEL are freed every +// CLEANUPCOUNT. It might be better to keep track of +// the total size of all purgable memory and free it when the +// size exceeds some value. +// +// This was in Z_Malloc, but was freeing data at +// unsafe times. Now it is only called when it is safe +// to cleanup memory. - if (!iterfunc) - I_Error("Z_IterateTags: no iterator function was given"); - - for (block = head.next; block != &head; block = next) - { - next = block->next; // get link before possibly freeing - - if (block->tag >= lowtag && block->tag <= hightag) - { - void *mem = MEMORY(block); - boolean free = iterfunc(mem); - if (free) - Z_Free(mem); - } - } -} - -// ----------------- -// Utility functions -// ----------------- - -// starting value of nextcleanup #define CLEANUPCOUNT 2000 -// number of function calls left before next cleanup static INT32 nextcleanup = CLEANUPCOUNT; -/** This was in Z_Malloc, but was freeing data at - * unsafe times. Now it is only called when it is safe - * to cleanup memory. - * - * \todo Currently blocks >= PU_PURGELEVEL are freed every - * CLEANUPCOUNT. It might be better to keep track of - * the total size of all purgable memory and free it when the - * size exceeds some value. - */ void Z_CheckMemCleanup(void) { if (nextcleanup-- == 0) @@ -466,13 +445,15 @@ void Z_CheckMemCleanup(void) void Z_CheckHeap(INT32 i) { memblock_t *block; + memhdr_t *hdr; UINT32 blocknumon = 0; void *given; for (block = head.next; block != &head; block = block->next) { blocknumon++; - given = MEMORY(block); + hdr = block->hdr; + given = (UINT8 *)hdr + sizeof *hdr; #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "block %u owned by %s:%d\n", blocknumon, block->ownerfile, block->ownerline); @@ -488,7 +469,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } #endif if (block->user != NULL && *(block->user) != given) @@ -501,7 +482,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } if (block->next->prev != block) { @@ -513,7 +494,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } if (block->prev->next != block) { @@ -525,9 +506,25 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } - if (block->id != ZONEID) +#ifdef VALGRIND_MAKE_MEM_DEFINED + VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); +#endif + if (hdr->block != block) + { + I_Error("Z_CheckHeap %d: block %u" +#ifdef ZDEBUG + "(owned by %s:%d)" +#endif + " doesn't have linkback from allocated memory", + i, blocknumon +#ifdef ZDEBUG + , block->ownerfile, block->ownerline +#endif + ); + } + if (hdr->id != ZONEID) { I_Error("Z_CheckHeap %d: block %u" #ifdef ZDEBUG @@ -537,37 +534,50 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } +#ifdef VALGRIND_MAKE_MEM_NOACCESS + VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); +#endif } } -// ------------------------ -// Zone memory modification -// ------------------------ - -/** Changes a memory block's purge tag. - * - * \param ptr A pointer to allocated memory, - * assumed to have been allocated with Z_Malloc/Z_Calloc. - * \param tag The new tag. - * \sa Z_SetUser - */ #ifdef PARANOIA void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line) #else -void Z_ChangeTag(void *ptr, INT32 tag) +void Z_ChangeTag2(void *ptr, INT32 tag) #endif { memblock_t *block; + memhdr_t *hdr; if (ptr == NULL) return; - block = MEMBLOCK(ptr); + hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); +#ifdef VALGRIND_MAKE_MEM_DEFINED + VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); +#endif + +#ifdef VALGRIND_MEMPOOL_EXISTS + if (!VALGRIND_MEMPOOL_EXISTS(hdr->block)) + { #ifdef PARANOIA - if (block->id != ZONEID) I_Error("Z_ChangeTag at %s:%d: wrong id", file, line); + I_Error("Z_CT at %s:%d: bad memblock", file, line); +#else + I_Error("Z_CT: bad memblock"); +#endif + } +#endif +#ifdef PARANOIA + if (hdr->id != ZONEID) I_Error("Z_CT at %s:%d: wrong id", file, line); +#endif + + block = hdr->block; + +#ifdef VALGRIND_MAKE_MEM_NOACCESS + VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); #endif if (tag >= PU_PURGELEVEL && block->user == NULL) @@ -577,48 +587,12 @@ void Z_ChangeTag(void *ptr, INT32 tag) block->tag = tag; } -/** Changes a memory block's user. - * - * \param ptr A pointer to allocated memory, - * assumed to have been allocated with Z_Malloc/Z_Calloc. - * \param newuser The new user for the memory block. - * \sa Z_ChangeTag - */ -#ifdef PARANOIA -void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line) -#else -void Z_SetUser(void *ptr, void **newuser) -#endif -{ - memblock_t *block; - - if (ptr == NULL) - return; - - block = MEMBLOCK(ptr); - -#ifdef PARANOIA - if (block->id != ZONEID) I_Error("Z_SetUser at %s:%d: wrong id", file, line); -#endif - - if (block->tag >= PU_PURGELEVEL && newuser == NULL) - I_Error("Internal memory management error: " - "tried to make block purgable but it has no owner"); - - block->user = (void*)newuser; - *newuser = ptr; -} - -// ----------------- -// Zone memory usage -// ----------------- - /** Calculates memory usage for a given set of tags. - * * \param lowtag The lowest tag to consider. * \param hightag The highest tag to consider. * \return Number of bytes currently allocated in the heap for the * given tags. + * \sa Z_TagUsage */ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) { @@ -635,54 +609,45 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) return cnt; } -// ----------------------- -// Miscellaneous functions -// ----------------------- - -/** The function called by the "memfree" console command. - * Prints the memory being used by each part of the game to the console. - */ -static void Command_Memfree_f(void) +size_t Z_TagUsage(INT32 tagnum) { - size_t freebytes, totalbytes; + return Z_TagsUsage(tagnum, tagnum); +} + +void Command_Memfree_f(void) +{ + UINT32 freebytes, totalbytes; Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10)); - CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); - CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); - CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); - CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); - CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); - CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); - CONS_Printf(M_GetText("All purgable : %7s KB\n"), + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); + CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); + CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); + CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); + CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); + CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); + CONS_Printf(M_GetText("All purgable : %7s KB\n"), sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { - CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); - CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); - CONS_Printf(M_GetText("Texture colormaps : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); - CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); - CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10); + CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); + CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); + CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); + CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); + CONS_Printf(M_GetText("All GPU textures : %7s KB\n"), sizeu1(HWR_GetTextureUsed()>>10)); } #endif CONS_Printf("\x82%s", M_GetText("System Memory Info\n")); freebytes = I_GetFreeMem(&totalbytes); - CONS_Printf(M_GetText(" Total physical memory: %s KB\n"), sizeu1(totalbytes>>10)); - CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10)); + CONS_Printf(M_GetText(" Total physical memory: %7u KB\n"), totalbytes>>10); + CONS_Printf(M_GetText("Available physical memory: %7u KB\n"), freebytes>>10); } - - #ifdef ZDEBUG -/** The function called by the "memdump" console command. - * Prints zone memory debugging information (i.e. tag, size, location in code allocated). - * Can be all memory allocated in game, or between a set of tags (if -min/-max args used). - * This command is available only if ZDEBUG is enabled. - */ static void Command_Memdump_f(void) { memblock_t *block; @@ -704,12 +669,45 @@ static void Command_Memdump_f(void) } #endif -/** Creates a copy of a string. - * - * \param s The string to be copied. - * \return A copy of the string, allocated in zone memory. - */ +// Creates a copy of a string. char *Z_StrDup(const char *s) { return strcpy(ZZ_Alloc(strlen(s) + 1), s); } + + +#ifdef PARANOIA +void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line) +#else +void Z_SetUser2(void *ptr, void **newuser) +#endif +{ + memblock_t *block; + memhdr_t *hdr; + + if (ptr == NULL) + return; + + hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); + +#ifdef VALGRIND_MAKE_MEM_DEFINED + VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); +#endif + +#ifdef PARANOIA + if (hdr->id != ZONEID) I_Error("Z_CT at %s:%d: wrong id", file, line); +#endif + + block = hdr->block; + +#ifdef VALGRIND_MAKE_MEM_NOACCESS + VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); +#endif + + if (block->tag >= PU_PURGELEVEL && newuser == NULL) + I_Error("Internal memory management error: " + "tried to make block purgable but it has no owner"); + + block->user = (void*)newuser; + *newuser = ptr; +} diff --git a/src/z_zone.h b/src/z_zone.h index 91743cfae..638d5f4b6 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -2,7 +2,7 @@ //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2023 by Sonic Team Junior. +// Copyright (C) 1999-2018 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. @@ -15,7 +15,6 @@ #define __Z_ZONE__ #include -#include "doomdef.h" #include "doomtype.h" #ifdef __GNUC__ // __attribute__ ((X)) @@ -31,120 +30,97 @@ //#define ZDEBUG // -// Purge tags -// -// Now they are an enum! -- Monster Iestyn 15/02/18 -// -enum -{ - // Tags < PU_LEVEL are not purged until freed explicitly. - PU_STATIC = 1, // static entire execution time - PU_LUA = 2, // static entire execution time -- used by lua so it doesn't get caught in loops forever - PU_PERFSTATS = 3, // static between changes to ps_samplesize cvar +// ZONE MEMORY +// PU - purge tags. +// Tags < PU_LEVEL are not purged until freed explicitly. +#define PU_STATIC 1 // static entire execution time +#define PU_LUA 2 // static entire execution time -- used by lua so it doesn't get caught in loops forever +#define PU_PERFSTATS 3 // static between changes to ps_samplesize cvar - PU_SOUND = 11, // static while playing - PU_MUSIC = 12, // static while playing - PU_HUDGFX = 13, // static until WAD added +#define PU_SOUND 11 // static while playing +#define PU_MUSIC 12 // static while playing +#define PU_HUDGFX 13 // static until WAD added - PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache - PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch +#define PU_HWRPATCHINFO 21 // Hardware GLPatch_t struct for OpenGL texture cache +#define PU_HWRPATCHCOLMIPMAP 22 // Hardware GLMipmap_t struct colromap variation of patch - PU_HWRCACHE = 48, // static until unlocked - PU_CACHE = 49, // static until unlocked +#define PU_HWRCACHE 48 // static until unlocked +#define PU_CACHE 49 // static until unlocked - // Tags s.t. PU_LEVEL <= tag < PU_PURGELEVEL are purged at level start - PU_LEVEL = 50, // static until level exited - PU_LEVSPEC = 51, // a special thinker in a level - PU_HWRPLANE = 52, // if ZPLANALLOC is enabled in hw_bsp.c, this is used to alloc polygons for OpenGL +// Tags s.t. PU_LEVEL <= tag < PU_PURGELEVEL are purged at level start +#define PU_LEVEL 50 // static until level exited +#define PU_LEVSPEC 51 // a special thinker in a level +#define PU_HWRPLANE 52 - // Tags >= PU_PURGELEVEL are purgable whenever needed - PU_PURGELEVEL = 100, // Note: this is never actually used as a tag - PU_CACHE_UNLOCKED = 101, // Note: unused - PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: - // 'second-level' cache for graphics - // stored in hardware format and downloaded as needed - PU_HWRPATCHINFO_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory -}; +// Tags >= PU_PURGELEVEL are purgable whenever needed +#define PU_PURGELEVEL 100 +#define PU_CACHE_UNLOCKED 101 +#define PU_HWRCACHE_UNLOCKED 102 // 'second-level' cache for graphics + // stored in hardware format and downloaded as needed +#define PU_HWRPATCHINFO_UNLOCKED 103 -// -// Zone memory initialisation -// void Z_Init(void); +void Z_FreeTags(INT32 lowtag, INT32 hightag); +void Z_CheckMemCleanup(void); +void Z_CheckHeap(INT32 i); +#ifdef PARANOIA +void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line); +#else +void Z_ChangeTag2(void *ptr, INT32 tag); +#endif -// -// Zone memory allocation -// -// enable ZDEBUG to get the file + line the functions were called from -// for ZZ_Alloc, see doomdef.h -// +#ifdef PARANOIA +void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line); +#else +void Z_SetUser2(void *ptr, void **newuser); +#endif -// Z_Free and alloc with alignment #ifdef ZDEBUG -#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) -#define Z_MallocAlign(s,t,u,a) Z_Malloc2(s, t, u, a, __FILE__, __LINE__) -#define Z_CallocAlign(s,t,u,a) Z_Calloc2(s, t, u, a, __FILE__, __LINE__) -#define Z_ReallocAlign(p,s,t,u,a) Z_Realloc2(p,s, t, u, a, __FILE__, __LINE__) +#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) void Z_Free2(void *ptr, const char *file, INT32 line); +#define Z_Malloc(s,t,u) Z_Malloc2(s, t, u, 0, __FILE__, __LINE__) +#define Z_MallocAlign(s,t,u,a) Z_Malloc2(s, t, u, a, __FILE__, __LINE__) void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(1); +#define Z_Calloc(s,t,u) Z_Calloc2(s, t, u, 0, __FILE__, __LINE__) +#define Z_CallocAlign(s,t,u,a) Z_Calloc2(s, t, u, a, __FILE__, __LINE__) void *Z_Calloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(1); +#define Z_Realloc(p,s,t,u) Z_Realloc2(p, s, t, u, 0, __FILE__, __LINE__) +#define Z_ReallocAlign(p,s,t,u,a) Z_Realloc2(p,s, t, u, a, __FILE__, __LINE__) void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(2); #else void Z_Free(void *ptr); void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(1); +#define Z_Malloc(s,t,u) Z_MallocAlign(s, t, u, 0) void *Z_CallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(1); -void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(2); +#define Z_Calloc(s,t,u) Z_CallocAlign(s, t, u, 0) +void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(2) ; +#define Z_Realloc(p, s,t,u) Z_ReallocAlign(p, s, t, u, 0) #endif -// Alloc with standard alignment -#define Z_Malloc(s,t,u) Z_MallocAlign(s, t, u, sizeof(void *)) -#define Z_Calloc(s,t,u) Z_CallocAlign(s, t, u, sizeof(void *)) -#define Z_Realloc(p,s,t,u) Z_ReallocAlign(p, s, t, u, sizeof(void *)) +size_t Z_TagUsage(INT32 tagnum); +size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); -// Free all memory by tag -// these don't give line numbers for ZDEBUG currently though -// (perhaps this should be changed in future?) -#define Z_FreeTag(tagnum) Z_FreeTags(tagnum, tagnum) -void Z_FreeTags(INT32 lowtag, INT32 hightag); +char *Z_StrDup(const char *in); -// Iterate memory by tag -#define Z_IterateTag(tagnum, func) Z_IterateTags(tagnum, tagnum, func) -void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)); - -// -// Utility functions -// -void Z_CheckMemCleanup(void); -void Z_CheckHeap(INT32 i); - -// -// Zone memory modification -// -// enable PARANOIA to get the file + line the functions were called from +// This is used to get the local FILE : LINE info from CPP +// prior to really call the function in question. // #ifdef PARANOIA #define Z_ChangeTag(p,t) Z_ChangeTag2(p, t, __FILE__, __LINE__) -#define Z_SetUser(p,u) Z_SetUser2(p, u, __FILE__, __LINE__) -void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line); -void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line); #else -void Z_ChangeTag(void *ptr, INT32 tag); -void Z_SetUser(void *ptr, void **newuser); +#define Z_ChangeTag(p,t) Z_ChangeTag2(p, t) #endif -// -// Zone memory usage -// -// Note: These give the memory used in bytes, -// shift down by 10 to convert to KB -// -#define Z_TagUsage(tagnum) Z_TagsUsage(tagnum, tagnum) -size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); -#define Z_TotalUsage() Z_TagsUsage(0, INT32_MAX) +#ifdef PARANOIA +#define Z_SetUser(p,u) Z_SetUser2(p, u, __FILE__, __LINE__) +#else +#define Z_SetUser(p,u) Z_SetUser2(p, u) +#endif -// -// Miscellaneous functions -// -char *Z_StrDup(const char *in); -#define Z_Unlock(p) (void)p // TODO: remove this now that NDS code has been removed +#ifdef _NDS ///TODO: need a lock reference system +#define Z_Unlock(p) Z_ChangeTag(p, PU_CACHE_UNLOCKED) +#else +#define Z_Unlock(p) (void)p +#endif #endif