diff --git a/src/android/i_system.c b/src/android/i_system.c index ef10df5b5..c0f7cc11c 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -34,8 +34,8 @@ size_t I_GetFreeMem(size_t *total) /* return si.freeram; */ char buf[1024]; char *memTag; - UINT32 freeKBytes; - UINT32 totalKBytes; + size_t freeKBytes; + size_t totalKBytes; INT32 n; INT32 meminfo_fd = -1; @@ -46,7 +46,7 @@ size_t I_GetFreeMem(size_t *total) if (n < 0) { // Error - *total = 0L; + *total = 0; return 0; } @@ -54,7 +54,7 @@ size_t I_GetFreeMem(size_t *total) if (NULL == (memTag = strstr(buf, MEMTOTAL))) { // Error - *total = 0L; + *total = 0; return 0; } @@ -64,7 +64,7 @@ size_t I_GetFreeMem(size_t *total) if (NULL == (memTag = strstr(buf, MEMFREE))) { // Error - *total = 0L; + *total = 0; return 0; } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 9e591e78c..81ba79d5d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -114,6 +114,7 @@ void* PoolAllocator::allocate() FreeBlock* ret = head_; head_ = head_->next; + allocated_blocks_++; return ret; } @@ -125,6 +126,7 @@ void PoolAllocator::deallocate(void* p) FreeBlock* block = reinterpret_cast(p); block->next = head_; head_ = block; + allocated_blocks_--; } void PoolAllocator::release() @@ -144,6 +146,7 @@ void PoolAllocator::release() first_chunk_ = nullptr; head_ = nullptr; + allocated_blocks_ = 0; } static LinearMemory g_frame_memory {4 * 1024 * 1024}; diff --git a/src/core/memory.h b/src/core/memory.h index 77e7206b5..4aec917d7 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -37,6 +37,7 @@ class PoolAllocator final FreeBlock* head_; size_t block_size_; size_t blocks_; + size_t allocated_blocks_; int32_t tag_; ChunkFooter* allocate_chunk(); @@ -47,6 +48,7 @@ public: , head_(nullptr) , block_size_(block_size) , blocks_(blocks) + , allocated_blocks_(0) , tag_(tag) {} PoolAllocator(const PoolAllocator&) = delete; @@ -59,6 +61,8 @@ public: void* allocate(); void deallocate(void* p); constexpr size_t block_size() const noexcept { return block_size_; }; + constexpr size_t allocated_blocks() const noexcept { return allocated_blocks_; }; + constexpr size_t allocated_bytes() const noexcept { return allocated_blocks_ * block_size_; }; void release(); }; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8efc2a1cd..a19e916cb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -110,7 +110,7 @@ SINT8 joinnode = 0; // used for CL_VIEWSERVER boolean player_muted[MAXPLAYERS] = {}; // Server specific vars -UINT8 playernode[MAXPLAYERS] = {}; +UINT8 playernode[MAXPLAYERS] = {UINT8_MAX}; // Minimum timeout for sending the savegame // The actual timeout will be longer depending on the savegame length @@ -3767,6 +3767,10 @@ static void Command_Ban(void) if (pn == -1 || pn == 0) return; + // player does not exist + if (!playeringame[pn]) + return; + WRITEUINT8(p, pn); if (COM_Argc() == 2) @@ -3884,6 +3888,10 @@ static void Command_Kick(void) if (pn == -1 || pn == 0) return; + // player does not exist + if (!playeringame[pn]) + return; + // Special case if we are trying to kick a player who is downloading the game state: // trigger a timeout instead of kicking them, because a kick would only // take effect after they have finished downloading @@ -3933,6 +3941,13 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) pnum = READUINT8(*p); msg = READUINT8(*p); + if (pnum >= MAXPLAYERS) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal kick command received from %s for player %d\n"), player_names[playernum], pnum); + return; + } + + // FIXME: this does not work at all on dedi, servernode == 0 which is prevented from kick/ban command if (pnum == serverplayer && IsPlayerAdmin(playernum)) { CONS_Printf(M_GetText("Server is being shut down remotely. Goodbye!\n")); @@ -3987,6 +4002,16 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) msg = KICK_MSG_CON_FAIL; } + // without this the server will remove itself and thus self destruct on dedicated + if (server && (playernode[pnum] == UINT8_MAX || !playeringame[pnum])) + { + CONS_Alert(CONS_WARNING, M_GetText("Attempting to kick player %d which is not in game received from %s\n"), pnum, player_names[playernum]); + return; + } + + // make sure we dont read garbage anywhere + memset(reason, 0, sizeof(buf)); + if (msg == KICK_MSG_CUSTOM_BAN || msg == KICK_MSG_CUSTOM_KICK) { READSTRINGN(*p, reason, MAX_REASONLENGTH+1); diff --git a/src/d_main.c b/src/d_main.c index 2150b1e72..ed0e0199e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -275,20 +275,6 @@ static void D_Renderview(void) R_ApplyLevelInterpolators(R_GetTimeFrac(RTF_LEVEL)); - if (rendermode == render_soft && cv_homremoval.value) - { - if (cv_homremoval.value == 1) - { - // Clear the software screen buffer to remove HOM - memset(vid.screens[0], 31, vid.width * vid.height); - } - else if (cv_homremoval.value == 2) - { - //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. - memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); - } - } - for (i = 0; i <= splitscreen; i++) { if (!P_MobjWasRemoved(players[displayplayers[i]].mo) || players[displayplayers[i]].playerstate == PST_DEAD) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 66e4aad3a..452263b75 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1806,7 +1806,7 @@ INT32 D_LookupPlayer(const char *s) if ((playernum = atoi(s))) { - playernum = max(min(playernum, MAXPLAYERS-1), 0);/* not out of range */ + playernum = max(min(playernum, MAXPLAYERS-1), 0); /* not out of range */ return playernum; } @@ -5691,19 +5691,22 @@ static void Command_SkinSearch(void) size_t i; UINT16 s; UINT16 ic = 0; - //skin_t *skininput = &skins[s]; - for (i = 1; i < COM_Argc(); i++){ - for( s = 0 ; s < numallskins ; s++ ) + + for (i = 1; i < COM_Argc(); i++) + { + for (s = 0; s < numskins; s++) { skin_t *skininput = &skins[s]; - if (strcasestr(skininput->realname,COM_Argv(i))) + + if (strcasestr(skininput->realname, COM_Argv(i))) { ic++; - CONS_Printf("%d. %s%s:\x80 %s\n", ic,HU_SkinColorToConsoleColor(skininput->prefcolor),skininput->realname,skininput->name); + CONS_Printf("%d. %s%s:\x80 %s\n", ic, HU_SkinColorToConsoleColor(skininput->prefcolor), skininput->realname, skininput->name); } } } - CONS_Printf("Total %d skins.\n", ic); + + CONS_Printf("Total %d skins.\n", ic); } /** Sends a color change for the console player, unless that player is moving. diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index fb3cc2731..b6d50a712 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -68,6 +68,12 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #if defined (__linux__) #include +#elif defined(__APPLE__) +#include +#include +#include +#include +#include #else #include #include @@ -156,8 +162,7 @@ const char *wadSearchPaths[] = { /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.srb" -#define WADKEYWORD2 "srb2.wad" +#define WADKEYWORD "srb2.srb" /** \brief holds wad path */ static char returnWadPath[256]; @@ -520,16 +525,23 @@ void I_OutputMsg(const char *fmt, ...) { size_t len; char *txt; - va_list argptr; + va_list argptr; - va_start(argptr,fmt); + if (!fmt) + return; + + va_start(argptr, fmt); len = vsnprintf(NULL, 0, fmt, argptr); va_end(argptr); if (len == 0) return; - txt = malloc(len+1); - va_start(argptr,fmt); + txt = (char*)(malloc(len+1)); + + if (!txt) + I_Error("I_OutputMsg: Out of memory!\n"); + + va_start(argptr, fmt); vsprintf(txt, fmt, argptr); va_end(argptr); @@ -1413,6 +1425,12 @@ static void I_Fork(void) } #endif/*NEWSIGNALHANDLER*/ +int I_OpenURL(const char *url) +{ + (void)url; + return -1; +} + INT32 I_StartupSystem(void) { I_StartupConsole(); @@ -1802,20 +1820,12 @@ const char *I_ClipboardPaste(void) */ static boolean isWadPathOk(const char *path) { - char *wad3path = malloc(256); + char *wad3path = (char*)(malloc(256)); if (!wad3path) return false; - sprintf(wad3path, pandf, path, WADKEYWORD1); - - if (FIL_ReadFileOK(wad3path)) - { - free(wad3path); - return true; - } - - sprintf(wad3path, pandf, path, WADKEYWORD2); + sprintf(wad3path, pandf, path, WADKEYWORD); if (FIL_ReadFileOK(wad3path)) { @@ -1832,12 +1842,17 @@ static void pathonly(char *s) size_t j; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { - if (s[j] == ':') s[j+1] = 0; - else s[j] = 0; + if (s[j] == ':') + s[j+1] = 0; + else + s[j] = 0; + return; } + } } /** \brief search for srb2.srb in the given path @@ -1853,7 +1868,7 @@ static const char *searchWad(const char *searchDir) static char tempsw[256] = ""; filestatus_t fstemp; - strcpy(tempsw, WADKEYWORD1); + strcpy(tempsw, WADKEYWORD); fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { @@ -1974,17 +1989,22 @@ const char *I_LocateWad(void) static long get_entry(const char* name, const char* buf) { long val; - char* hit = strstr(buf, name); - if (hit == NULL) { + const char* hit = strstr(buf, name); + + if (hit == NULL) + { return -1; } errno = 0; val = strtol(hit + strlen(name), NULL, 10); - if (errno != 0) { + + if (errno != 0) + { CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); return -1; } + return val; } #endif @@ -2009,13 +2029,13 @@ size_t I_GetFreeMem(size_t *total) *total = 32 << 20; return 32 << 20; #elif defined (_WIN32) - MEMORYSTATUS info; + MEMORYSTATUSEX info; - info.dwLength = sizeof (MEMORYSTATUS); - GlobalMemoryStatus( &info ); + info.dwLength = sizeof (MEMORYSTATUSEX); + GlobalMemoryStatusEx( &info ); if (total) - *total = (size_t)info.dwTotalPhys; - return (size_t)info.dwAvailPhys; + *total = (size_t)info.ullTotalPhys; + return (size_t)info.ullAvailPhys; #elif defined (__OS2__) UINT32 pr_arena; @@ -2048,7 +2068,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } @@ -2057,12 +2077,12 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } memTag += sizeof (MEMTOTAL); - totalKBytes = (size_t)atoi(memTag); + totalKBytes = strtoul(memTag, NULL, 10); if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) { @@ -2076,7 +2096,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } freeKBytes = MemAvailable; @@ -2084,16 +2104,46 @@ size_t I_GetFreeMem(size_t *total) else { memTag += sizeof (MEMAVAILABLE); - freeKBytes = atoi(memTag); + freeKBytes = strtoul(memTag, NULL, 10); } if (total) *total = totalKBytes << 10; return freeKBytes << 10; +#elif defined(__APPLE__) + /* macOS */ + mach_port_t host = mach_host_self(); + kern_return_t kr; + mach_msg_type_number_t count; + vm_size_t v_page_size; + struct vm_statistics64 vm_stats; + uint64_t total_mem, free_mem; + size_t size; + + size = sizeof(total_mem); + if (sysctlbyname("hw.memsize", &total_mem, &size, NULL, 0) < 0) + total_mem = 0; + + kr = host_page_size(host, &v_page_size); + if (kr != KERN_SUCCESS) + v_page_size = 4096; + + count = HOST_VM_INFO64_COUNT; + kr = host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count); + if (kr == KERN_SUCCESS) + free_mem = (uint64_t)(vm_stats.free_count + vm_stats.inactive_count) * v_page_size; + else + free_mem = 0; + + if (total) + *total = (size_t)total_mem; + return (size_t)free_mem; #else // Guess 48 MB. if (total) + { *total = 48<<20; + } return 48<<20; #endif } diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 6a8649099..ed4bff5a2 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -96,7 +96,6 @@ typedef struct typedef struct { float x, y, z; - fixed_t x2, y2, z2; } polyvertex_t; // a convex 'plane' polygon, clockwise order diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index fbd9702ce..562be50bb 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3483,6 +3483,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) fixed_t v1x, v1y, v2x, v2y; INT32 shader = SHADER_NONE; + const boolean billboarding = (cv_glspritebillboarding.value && !cv_glshearing.value && !papersprite); + gpatch = spr->gpatch; // cache the patch in the graphics card memory @@ -3680,7 +3682,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) wallVerts[1].y = endbot; // The x and y only need to be adjusted in the case that it's not a papersprite - if (cv_glspritebillboarding.value && !cv_glshearing.value && !papersprite) + if (billboarding) { // Get the x and z of the vertices so billboarding draws correctly realheight = realbot - realtop; @@ -5451,6 +5453,8 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool { gl_portallist_t portallist; + const boolean wireframe = HWR_IsWireframeMode(); + player_t *viewplayer = &players[displayplayers[viewssnum]]; const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); @@ -5511,7 +5515,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool } } - if (HWR_IsWireframeMode()) + if (wireframe) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); // FIXME: perfstats does not account for portal rendering! @@ -5597,7 +5601,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool HWR_RenderDrawNodes(); - if (HWR_IsWireframeMode()) + if (wireframe) GL_SetSpecialState(HWD_SET_WIREFRAME, 0); HWR_FreePortalList(portallist); // always call this just in case diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index aff722773..0c04beb09 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1465,6 +1465,19 @@ void GL_ReadScreenTexture(int tex, UINT8 *restrict dest, INT32 scale) if (tex != HWD_SCREENTEXTURE_GENERIC2) GL_DrawScreenTexture(tex, NULL, 0); +#ifdef USE_FBO_OGL + // FIXME: this is incredibly stupid + // but the final screen texture will NOT be drawn in the downsample fbo + if (tex == HWD_SCREENTEXTURE_GENERIC2 && + UseScreenFBO() && HWR_ShouldUsePaletteRendering()) + { + GL_SetShader(HWR_GetShaderFromTarget(SHADER_PALETTE_POSTPROCESS)); + GL_EnableShader(); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); + GL_UnSetShader(); + } +#endif + image = malloc(screen_width*screen_height*3); pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(0, 0, screen_width, screen_height, GL_RGB, GL_UNSIGNED_BYTE, image); diff --git a/src/k_kart.c b/src/k_kart.c index 0196bb521..e77c0b5ee 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7055,6 +7055,28 @@ void K_MoveKartPlayer(player_t *player, boolean onground) // "Stair jank" visuals akin to RR if (cv_stairjank.value && player->stairjank > 0) { + // only spawn em once + if (player->stairjank > 8) + { + // 90 degrees to direction you're facing + fixed_t dirx = -FINESINE(player->mo->angle>>ANGLETOFINESHIFT); + fixed_t diry = FINECOSINE(player->mo->angle>>ANGLETOFINESHIFT); + fixed_t offset = player->mo->radius; + + dirx = K_AltFlip(-dirx, 4); + diry = K_AltFlip(-diry, 4); + + mobj_t * spark = P_SpawnMobj(player->mo->x + FixedMul(dirx, offset), player->mo->y + FixedMul(diry, offset), player->mo->z, MT_DRIFTDUST); + spark->momx = FixedMul(dirx, FRACUNIT) + (6 + ((int)leveltime % 5))*(player->mo->momx)/10; + spark->momy = FixedMul(diry, FRACUNIT) + (6 + ((int)leveltime % 5))*(player->mo->momy)/10; + spark->momz = 5*FRACUNIT; + spark->scale = mapobjectscale/5; + spark->destscale = mapobjectscale/2; + spark->islocal = true; + spark->color = SKINCOLOR_WHITE; + P_SetTarget(&spark->target, player->mo); + } + player->mo->temprollangle += K_StairJankFlip(ANGLE_11hh / 2 / (17 / player->stairjank)); // TODO: make strength adjustable? } diff --git a/src/p_map.c b/src/p_map.c index ce43c2235..4ebc9a124 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2610,36 +2610,10 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) // sound does not work out all that well for kart maps // best i can do... - if (cv_stairjanksfx.value) + if (cv_stairjank.value && cv_stairjanksfx.value) S_StartSoundAtVolume(thing, (thing->player->stairjank >= 8 ? sfx_s23b : sfx_s268), 192); // dont blast this at full volume lul - //if (!thing->player->stairjank) - { - // 90 degrees to direction you're facing - fixed_t dirx = -FINESINE(thing->angle>>ANGLETOFINESHIFT); - fixed_t diry = FINECOSINE(thing->angle>>ANGLETOFINESHIFT); - fixed_t offset = thing->radius; - - if (leveltime % 8 < 4) - { - dirx = -dirx; - diry = -diry; - } - - mobj_t * spark = P_SpawnMobj(thing->x + FixedMul(dirx, offset), thing->y + FixedMul(diry, offset), thing->z, MT_DRIFTDUST); - spark->momx = FixedMul(dirx, FRACUNIT) + (6 + ((int)leveltime % 5))*(thing->momx)/10; - spark->momy = FixedMul(diry, FRACUNIT) + (6 + ((int)leveltime % 5))*(thing->momy)/10; - spark->momz = 5*FRACUNIT; - spark->scale = mapobjectscale/5; - spark->destscale = mapobjectscale/2; - spark->islocal = true; - //spark->fuse = 9; - spark->color = SKINCOLOR_WHITE; - //spark->cusval = K_StairJankFlip(ANGLE_90); - P_SetTarget(&spark->target, thing); - //P_SetTarget(&spark->owner, thing); - //spark->renderflags |= RF_REDUCEVFX; - } + // Can't spawn things during P_TryMove, because global variables :) thing->player->stairjank = 9; //thing->player->stairjank = 17; diff --git a/src/r_main.cpp b/src/r_main.cpp index d2b6eed65..ad8f1aa0a 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1389,6 +1389,21 @@ void R_RenderPlayerView(player_t *player) maskcount_t* masks = static_cast(malloc(sizeof(maskcount_t))); const boolean skybox = (skyboxmo[0] && cv_skybox.value); + // Only do it if it's the first screen being rendered + if (cv_homremoval.value && viewssnum == 0) + { + if (cv_homremoval.value == 1) + { + // Clear the software screen buffer to remove HOM + memset(vid.screens[0], 31, vid.width * vid.height); + } + else if (cv_homremoval.value == 2) + { + //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. + memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); + } + } + // load previous saved value of skyVisible for the player skyVisible = skyVisiblePerPlayer[viewssnum]; @@ -1455,10 +1470,12 @@ void R_RenderPlayerView(player_t *player) NetUpdate(); R_SetColumnContext(COLUMNCONTEXT_FLUSH); + ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0; PS_START_TIMING(ps_bsptime); R_RenderViewpoint(&masks[nummasks - 1], true); PS_STOP_TIMING(ps_bsptime); + PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); @@ -1466,8 +1483,8 @@ void R_RenderPlayerView(player_t *player) ps_numsprites.value.i = numvisiblesprites; - PS_START_TIMING(ps_sw_portaltime); // Portal rendering. Hijacks the BSP traversal. + PS_START_TIMING(ps_sw_portaltime); if (portal_base) { portal_t *portal; @@ -1508,8 +1525,7 @@ void R_RenderPlayerView(player_t *player) R_SetColumnContext(COLUMNCONTEXT_DIRECT); PS_START_TIMING(ps_sw_planetime); - if (!skybox) - R_DrawSkyPlanes(); + R_DrawSkyPlanes(); R_DrawPlanes(); PS_STOP_TIMING(ps_sw_planetime); // draw mid texture and sprite @@ -1517,6 +1533,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_maskedtime); R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); + free(masks); // Check for new console commands. diff --git a/src/r_portal.c b/src/r_portal.c index d84a99be4..f403c17c7 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -272,7 +272,7 @@ static boolean TrimVisplaneBounds(const visplane_t* plane, INT16* start, INT16* * Applies the necessary offsets and rotation to give * a depth illusion to the skybox. */ -void Portal_AddSkybox(const visplane_t* plane) +static void Portal_AddSkybox(const visplane_t* plane) { INT16 start, end; mapheader_t *mh; @@ -333,10 +333,13 @@ void Portal_AddSkyboxPortals(void) INT32 i; UINT16 count = 0; - for (i = 0; i < MAXVISPLANES; i++, pl++) + for (i = 0; i < MAXVISPLANES; i++) { for (pl = visplanes[i]; pl; pl = pl->next) { + if (pl->minx >= pl->maxx) + continue; + if (pl->picnum == skyflatnum) { Portal_AddSkybox(pl); diff --git a/src/r_portal.h b/src/r_portal.h index 223dd83be..4c4583903 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -58,7 +58,6 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con void Portal_ClipApply (const portal_t* portal); -void Portal_AddSkybox(const visplane_t* plane); void Portal_AddSkyboxPortals(void); #ifdef __cplusplus diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8460d4679..8a2693c84 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -713,16 +713,11 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf rw_scalestep = drawseg->scalestep; spryscale = drawseg->scale1 + (x1 - drawseg->x1)*rw_scalestep; -#define CLAMPMAX INT32_MAX -#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out. auto overflow_clamp = [&](INT64 overflow_test) { - return (overflow_test > (INT64)CLAMPMAX) ? CLAMPMAX : - (overflow_test > (INT64)CLAMPMIN) ? (fixed_t)overflow_test : - CLAMPMIN; + // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out. + return (fixed_t)std::clamp(overflow_test, (-INT32_MAX), INT32_MAX); }; -#undef CLAMPMAX -#undef CLAMPMIN dc->numlights = 0; if (frontsector->numlights) @@ -2604,71 +2599,91 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (linedef->special == HORIZONSPECIAL) // HORIZON LINES { topstep = bottomstep = 0; - topfrac = bottomfrac = (centeryfrac>>4); + topfrac = bottomfrac = (centeryfrac >> 4); topfrac++; // Prevent 1px HOM } else { + topstep = -FixedMul(rw_scalestep, worldtop); + topfrac = (centeryfrac >> 4) - FixedMul(worldtop, rw_scale); + // for anyone that sees this // dont. // this is absolute shit-tier hacks // but i just cant determine this in any sane way // but this checks a shitton of things to make software handle skies better - auto set_topstep_normal = [&] - { - topstep = -FixedMul(rw_scalestep, worldtop); - topfrac = (centeryfrac>>4) - FixedMul(worldtop, rw_scale); - }; - // untextured seg - if (!segtextured && !curline->polyseg) + if (!segtextured && !curline->polyseg) // not for polyobjects..... { - const bool tophigh = (worldhigh <= worldtop && worldhighslope <= worldtopslope); + const boolean nofrontsky = (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum); + const boolean inskybox = (skyboxmo[0] && cv_skybox.value && newview->sky); // dont mess with skyVisible within skybox rendering! - // if we cant see the goddamn skyplane, well there wont be any skybox - // we could kill skyVisible instead, but i want to keep the performance improvements it yields - // so we do this absolute trash - if ((tophigh - && (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum)) // try to guess if its a "window" - && ((!backsector) // single sided - || ((backsector && (worldhigh != worldtop || worldhighslope != worldtopslope)) - && (backsector->floorheight >= frontsector->ceilingheight || backsector->ceilingheight <= frontsector->floorheight)))) // check if there is a "thok" sector behind it - skyVisible = true; - - // this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead - if (tophigh && !backsector && frontsector->ceilingpic == skyflatnum) + // single sided line + if (!backsector) { - // account for slopes to try and get rid of sharp edges from the black void - if (frontsector->f_slope || (backsector && backsector->f_slope)) + // this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead + + // there is a sky flat on the ceiling + // so we can assume this is supposed to draw the sky + if (frontsector->ceilingpic == skyflatnum) { - topstep = -FixedMul(rw_scalestep, worldbottomslope); - topfrac = (centeryfrac>>4) - FixedMul(worldbottomslope, rw_scale); + // just draw sky from top to bottom! + if (frontsector->f_slope) + { + topstep = -FixedMul(rw_scalestep, worldbottomslope); + topfrac = (centeryfrac >> 4) - FixedMul(worldbottomslope, rw_scale); + } + else + { + topstep = -FixedMul(rw_scalestep, worldbottom); + topfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale); + } } - else + else if (nofrontsky && !inskybox) { - topstep = -FixedMul(rw_scalestep, worldbottom); - topfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale); + // completely empty wall without sky flats, just assume skybox is visible then + skyVisible = true; } } - else - set_topstep_normal(); + else if (nofrontsky && !inskybox) // if there was a skyflat, drawplane would already set skyvisible + { + // "thok walls" are double sided + // so we need to check a few things here + // to be rather conservative + // as skyrendering is pretty costly! + + // ideally we´d just dont care and always draw the skytexture + // or skybox at any time, like gl does + // wonder if there would be a fast way to draw atleast just the texture? + + // gotta shift those here for proper comparisons + const INT32 whigh = worldhigh >> 4; + const INT32 whslope = worldhighslope >> 4; + + // check if there is a window to force skybox to draw + if ((whigh <= worldtop && whslope <= worldtopslope) && (backsector->ceilingpic == skyflatnum)) // backsector has a skyflat? + skyVisible = true; + // otherwise check for thokwalls + else if ((whigh != worldtop || whslope != worldtopslope) && // FIXME: i forgor what this was for lol + (backsector->floorheight >= frontsector->ceilingheight || // thok walls usually are set up like that... + frontsector->floorheight >= backsector->ceilingheight)) // floor higher than the other sides ceiling + skyVisible = true; + } } - else - set_topstep_normal(); bottomstep = -FixedMul(rw_scalestep, worldbottom); - bottomfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale); + bottomfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale); if (frontsector->c_slope) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldtopslope, ds_p->scale2); + fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldtopslope, ds_p->scale2); topstep = (topfracend-topfrac)/(range); } if (frontsector->f_slope) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldbottomslope, ds_p->scale2); + fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldbottomslope, ds_p->scale2); bottomstep = (bottomfracend-bottomfrac)/(range); } } @@ -2706,12 +2721,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (leftheight < worldbottom && rightheight < worldbottomslope) continue; - if (leftheight > worldtop && rightheight > worldtopslope && i+1 < dc.numlights && frontsector->lightlist[i+1].height > frontsector->ceilingheight) + if ((leftheight > worldtop) && (rightheight > worldtopslope) && + (i+1 < dc.numlights) && (frontsector->lightlist[i+1].height > frontsector->ceilingheight)) continue; } - rlight->height = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); - rlight->heightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); + rlight->height = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale); + rlight->heightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); rlight->flags = static_cast(light->flags); @@ -2730,10 +2746,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) leftheight >>= 4; rightheight >>= 4; - rlight->botheight = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); - rlight->botheightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); + rlight->botheight = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale); + rlight->botheightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); - } rlight->lightlevel = *light->lightlevel; @@ -2754,13 +2769,14 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (linedef->special == HORIZONSPECIAL) // Horizon lines extend FOFs in contact with them too. { visffloor[i].f_step = 0; - visffloor[i].f_frac = (centeryfrac>>4); + visffloor[i].f_frac = (centeryfrac >> 4); topfrac++; // Prevent 1px HOM } else { - visffloor[i].f_frac = (centeryfrac>>4) - FixedMul(visffloor[i].f_pos, rw_scale); - visffloor[i].f_step = ((centeryfrac>>4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2) - visffloor[i].f_frac)/(range); + visffloor[i].f_frac = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos, rw_scale); + visffloor[i].f_step = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2); + visffloor[i].f_step = (visffloor[i].f_step - visffloor[i].f_frac)/(range); } } } @@ -2774,9 +2790,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (toptexture) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldhighslope, ds_p->scale2); - - pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); + fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldhighslope, ds_p->scale2); + pixhigh = (centeryfrac >> 4) - FixedMul(worldhigh, rw_scale); pixhighstep = (topfracend-pixhigh)/(range); // If the lowest part of a ceiling stretching down covers the entire screen @@ -2786,9 +2801,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (bottomtexture) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldlowslope, ds_p->scale2); - - pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale); + fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldlowslope, ds_p->scale2); + pixlow = (centeryfrac >> 4) - FixedMul(worldlow, rw_scale); pixlowstep = (bottomfracend-pixlow)/(range); // If the highest part of a floor stretching up covers the entire screen diff --git a/src/r_state.h b/src/r_state.h index 0431525e7..5e226103b 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -90,7 +90,7 @@ extern side_t *sides; extern fixed_t viewx, viewy, viewz; extern angle_t viewangle, aimingangle, viewroll; extern UINT8 viewssnum; // splitscreen view number -extern boolean viewsky, skyVisible; +extern boolean skyVisible; extern boolean skyVisiblePerPlayer[MAXSPLITSCREENPLAYERS]; // saved values of skyVisible of each splitscreen player extern sector_t *viewsector; extern player_t *viewplayer; diff --git a/src/r_things.cpp b/src/r_things.cpp index ee517c11f..79c280ee5 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -87,6 +87,8 @@ static drawseg_xrange_item_t *drawsegs_xrange; static size_t drawsegs_xrange_size = 0; static INT32 drawsegs_xrange_count = 0; +#define CLIP_UNDEF -2 + // // Sprite rotation 0 is facing the viewer, // rotation 1 is one angle turn CLOCKWISE around the axis. @@ -2221,6 +2223,7 @@ static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 e best = ds; } } + if (best) { best->next->prev = best->prev; @@ -2629,7 +2632,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port for (x = x1; x <= x2; x++) { - spr->clipbot[x] = spr->cliptop[x] = -2; + spr->clipbot[x] = spr->cliptop[x] = CLIP_UNDEF; } // Scan drawsegs from end to start for obscuring segs. @@ -2658,29 +2661,26 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port ds = curr->user; - if (ds->portalpass != 66) // unused? + if (ds->portalpass > 0 && ds->portalpass <= portalrender) + continue; // is a portal + + if (ds->scale1 > ds->scale2) { - if (ds->portalpass > 0 && ds->portalpass <= portalrender) - continue; // is a portal + lowscale = ds->scale2; + scale = ds->scale1; + } + else + { + lowscale = ds->scale1; + scale = ds->scale2; + } - if (ds->scale1 > ds->scale2) - { - lowscale = ds->scale2; - scale = ds->scale1; - } - else - { - lowscale = ds->scale1; - scale = ds->scale2; - } - - if (scale < spr->sortscale || - (lowscale < spr->sortscale && - !R_PointOnSegSide(spr->gx, spr->gy, ds->curline))) - { - // seg is behind sprite - continue; - } + if (scale < spr->sortscale || + (lowscale < spr->sortscale && + !R_PointOnSegSide(spr->gx, spr->gy, ds->curline))) + { + // seg is behind sprite + continue; } r1 = ds->x1 < x1 ? x1 : ds->x1; @@ -2699,14 +2699,14 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { // bottom sil for (x = r1; x <= r2; x++) - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = ds->sprbottomclip[x]; } else if (silhouette == SIL_TOP) { // top sil for (x = r1; x <= r2; x++) - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = ds->sprtopclip[x]; } else if (silhouette == (SIL_TOP|SIL_BOTTOM)) @@ -2714,9 +2714,9 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port // both for (x = r1; x <= r2; x++) { - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = ds->sprbottomclip[x]; - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = ds->sprtopclip[x]; } } @@ -2735,13 +2735,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (mh <= 0 || (phs != -1 && viewz > sectors[phs].floorheight)) { // clip bottom for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || h < spr->clipbot[x]) spr->clipbot[x] = (INT16)h; } else // clip top { for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || h > spr->cliptop[x]) spr->cliptop[x] = (INT16)h; } } @@ -2753,13 +2753,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (phs != -1 && viewz >= sectors[phs].ceilingheight) { // clip bottom for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || h < spr->clipbot[x]) spr->clipbot[x] = (INT16)h; } else // clip top { for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || h > spr->cliptop[x]) spr->cliptop[x] = (INT16)h; } } @@ -2769,10 +2769,10 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->cliptop[x] == -2 || spr->szt > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || spr->szt > spr->cliptop[x]) spr->cliptop[x] = spr->szt; - if (spr->clipbot[x] == -2 || spr->sz < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || spr->sz < spr->clipbot[x]) spr->clipbot[x] = spr->sz; } } @@ -2780,7 +2780,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->cliptop[x] == -2 || spr->szt > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || spr->szt > spr->cliptop[x]) spr->cliptop[x] = spr->szt; } } @@ -2788,7 +2788,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->clipbot[x] == -2 || spr->sz < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || spr->sz < spr->clipbot[x]) spr->clipbot[x] = spr->sz; } } @@ -2798,21 +2798,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port // check for unclipped columns for (x = x1; x <= x2; x++) { - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = (INT16)viewheight; - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = -1; } - // Check if it'll be visible - // Not done for floorsprites. - if (cv_spriteclip.value) - { - if (!R_CheckSpriteVisible(spr, x1, x2)) - spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); - } - if (portal) { INT32 start_index = std::max(portal->start, x1); @@ -2823,6 +2815,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port spr->clipbot[x] = -1; spr->cliptop[x] = -1; } + for (x = start_index; x <= end_index; x++) { if (spr->clipbot[x] > portal->floorclip[x - portal->start]) @@ -2830,12 +2823,21 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (spr->cliptop[x] < portal->ceilingclip[x - portal->start]) spr->cliptop[x] = portal->ceilingclip[x - portal->start]; } + for (x = end_index + 1; x <= x2; x++) { spr->clipbot[x] = -1; spr->cliptop[x] = -1; } } + + // Check if it'll be visible + // Not done for floorsprites. + if (cv_spriteclip.value) + { + if (!R_CheckSpriteVisible(spr, x1, x2)) + spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); + } } void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) @@ -2908,8 +2910,9 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) { vissprite_t *spr = R_GetVisSprite(clippedvissprites); - if (cv_spriteclip.value - && (spr->szt > vid.height || spr->sz < 0)) + if (cv_spriteclip.value && + (spr->szt > vid.height || spr->sz < 0) && + !spr->scalestep) { spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); continue; diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4e9de24c2..dd3508efd 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -83,6 +83,12 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) #if defined (__linux__) #include +#elif defined(__APPLE__) +#include +#include +#include +#include +#include #else #include #include @@ -172,8 +178,7 @@ const char *wadSearchPaths[] = { /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.srb" -#define WADKEYWORD2 "srb2.wad" +#define WADKEYWORD "srb2.srb" /** \brief holds wad path */ static char returnWadPath[256]; @@ -555,12 +560,12 @@ void I_OutputMsg(const char *fmt, ...) { size_t len; char *txt; - va_list argptr; + va_list argptr; if (!fmt) return; - va_start(argptr,fmt); + va_start(argptr, fmt); len = vsnprintf(NULL, 0, fmt, argptr); va_end(argptr); if (len == 0) @@ -571,7 +576,7 @@ void I_OutputMsg(const char *fmt, ...) if (!txt) I_Error("I_OutputMsg: Out of memory!\n"); - va_start(argptr,fmt); + va_start(argptr, fmt); vsprintf(txt, fmt, argptr); va_end(argptr); @@ -2259,7 +2264,6 @@ void I_ShutdownSystem(void) logstream = NULL; } #endif - } void I_GetDiskFreeSpace(INT64 *freespace) @@ -2431,7 +2435,7 @@ static boolean isWadPathOk(const char *path) if (!wad3path) return false; - sprintf(wad3path, pandf, path, WADKEYWORD1); + sprintf(wad3path, pandf, path, WADKEYWORD); if (FIL_ReadFileOK(wad3path)) { @@ -2471,10 +2475,10 @@ static void pathonly(char *s) */ static const char *searchWad(const char *searchDir) { - static char tempsw[255] = ""; + static char tempsw[256] = ""; filestatus_t fstemp; - strcpy(tempsw, WADKEYWORD1); + strcpy(tempsw, WADKEYWORD); fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { @@ -2635,13 +2639,13 @@ size_t I_GetFreeMem(size_t *total) *total = 32 << 20; return 32 << 20; #elif defined (_WIN32) - MEMORYSTATUS info; + MEMORYSTATUSEX info; - info.dwLength = sizeof (MEMORYSTATUS); - GlobalMemoryStatus( &info ); + info.dwLength = sizeof (MEMORYSTATUSEX); + GlobalMemoryStatusEx( &info ); if (total) - *total = (size_t)info.dwTotalPhys; - return (size_t)info.dwAvailPhys; + *total = (size_t)info.ullTotalPhys; + return (size_t)info.ullAvailPhys; #elif defined (__OS2__) UINT32 pr_arena; @@ -2674,7 +2678,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } @@ -2683,12 +2687,12 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } memTag += sizeof (MEMTOTAL); - totalKBytes = (size_t)atoi(memTag); + totalKBytes = strtoul(memTag, NULL, 10); if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) { @@ -2702,7 +2706,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } freeKBytes = MemAvailable; @@ -2710,12 +2714,40 @@ size_t I_GetFreeMem(size_t *total) else { memTag += sizeof (MEMAVAILABLE); - freeKBytes = atoi(memTag); + freeKBytes = strtoul(memTag, NULL, 10); } if (total) *total = totalKBytes << 10; return freeKBytes << 10; +#elif defined(__APPLE__) + /* macOS */ + mach_port_t host = mach_host_self(); + kern_return_t kr; + mach_msg_type_number_t count; + vm_size_t v_page_size; + struct vm_statistics64 vm_stats; + uint64_t total_mem, free_mem; + size_t size; + + size = sizeof(total_mem); + if (sysctlbyname("hw.memsize", &total_mem, &size, NULL, 0) < 0) + total_mem = 0; + + kr = host_page_size(host, &v_page_size); + if (kr != KERN_SUCCESS) + v_page_size = 4096; + + count = HOST_VM_INFO64_COUNT; + kr = host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count); + if (kr == KERN_SUCCESS) + free_mem = (uint64_t)(vm_stats.free_count + vm_stats.inactive_count) * v_page_size; + else + free_mem = 0; + + if (total) + *total = (size_t)total_mem; + return (size_t)free_mem; #else // Guess 48 MB. if (total) diff --git a/src/sounds.c b/src/sounds.c index 3769bf65b..e17e79512 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -972,7 +972,7 @@ sfxinfo_t S_sfx[NUMSFX] = // initialized to NULL }; -char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7] = {}; +static char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][MAXSOUNDNAME] = {}; // Prepare free sfx slots to add sfx at run time void S_InitRuntimeSounds(void) @@ -985,16 +985,13 @@ void S_InitRuntimeSounds(void) { value = (i+1) - sfx_freeslot0; - if (value < 10) - sprintf(soundname, "fre00%d", value); - else if (value < 100) - sprintf(soundname, "fre0%d", value); - else if (value < 1000) - sprintf(soundname, "fre%d", value); - else - sprintf(soundname, "fr%d", value); + sprintf(soundname, "fr%04x", value); - strcpy(freeslotnames[value-1], soundname); + // this might happen when raising skinlimit + I_Assert(strlen(soundname) < MAXSOUNDNAME); + + strncpy(freeslotnames[value-1], soundname, MAXSOUNDNAME-1); + freeslotnames[value-1][MAXSOUNDNAME-1] = '\0'; S_sfx[i].name = freeslotnames[value-1]; S_sfx[i].singularity = false; @@ -1024,7 +1021,11 @@ sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean { if (!S_sfx[i].priority) { - strncpy(freeslotnames[i-sfx_freeslot0], name, 6); + I_Assert(strlen(name) < MAXSOUNDNAME); + + strncpy(freeslotnames[i - sfx_freeslot0], name, MAXSOUNDNAME-1); + freeslotnames[i - sfx_freeslot0][MAXSOUNDNAME-1] = '\0'; + S_sfx[i].singularity = singular; S_sfx[i].priority = 60; S_sfx[i].pitch = flags; diff --git a/src/sounds.h b/src/sounds.h index ea530da05..a8522f1c6 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -59,6 +59,8 @@ typedef enum #define NUMSFXFREESLOTS 1600 // Matches SOC Editor. #define NUMSKINSFXSLOTS (MAXSKINS*NUMSKINSOUNDS) +#define MAXSOUNDNAME 7 + // // SoundFX struct. // diff --git a/src/st_stuff.c b/src/st_stuff.c index 57a7c6e29..c8bdd5d51 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -14,6 +14,7 @@ /// Does palette indicators as well (red pain/berserk, bright pickup) #include "doomdef.h" +#include "d_main.h" #include "g_game.h" #include "g_input.h" #include "k_director.h" @@ -172,7 +173,8 @@ INT32 st_palette = 0; void ST_ResetPaletteStuff(void) { st_palette = 0; - V_SetPalette(0); + if (loaded_config) + V_SetPalette(0); } static void ST_doPaletteStuff(void) diff --git a/src/v_video.c b/src/v_video.c index fc84a0cdc..109eac171 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -676,6 +676,7 @@ static void CV_palette_OnChange(void) { if (!loaded_config) return; + // reload palette // recalculate Color Cube V_ReloadPalette(); diff --git a/src/z_zone.cpp b/src/z_zone.cpp index f25f99e43..f688dd831 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -114,6 +114,7 @@ void Z_Init(void) head.next = head.prev = &head; memfree = I_GetFreeMem(&total)>>20; + CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree)); // Note: This allocates memory. Watch out. @@ -745,6 +746,7 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("HUD graphics : %7s KB\n"), sizeu1(Z_TagUsage(PU_HUDGFX)>>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("Level (pooled) : %7s KB\n"), sizeu1(Z_LevelPoolUsage()>>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)); @@ -804,6 +806,14 @@ char *Z_StrDup(const char *s) return strcpy((char*)ZZ_Alloc(strlen(s) + 1), s); } +size_t Z_LevelPoolUsage(void) +{ + return g_level_large_pool.allocated_bytes() + + g_level_med_pool.allocated_bytes() + + g_level_small_pool.allocated_bytes() + + g_level_tiny_pool.allocated_bytes(); +} + void* Z_LevelPoolMalloc(size_t size) { void* p = nullptr; diff --git a/src/z_zone.h b/src/z_zone.h index 38f00c48c..847e47291 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -167,6 +167,7 @@ char *Z_StrDup(const char *in); // // Specialty allocation functions // +size_t Z_LevelPoolUsage(void); void *Z_LevelPoolMalloc(size_t size); void *Z_LevelPoolCalloc(size_t size); void Z_LevelPoolFree(void *p, size_t size);