diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index dcc39ea66..062ceb83f 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -4245,11 +4245,16 @@ void CL_FTP_f(void) //fixme: make a cvar void CL_Fog_f(void) { - int ftype = Q_strcasecmp(Cmd_Argv(0), "fog"); + int ftype; + if (!Q_strcasecmp(Cmd_Argv(0), "waterfog")) + ftype = 1; + else //fog + ftype = 0; if ((cl.fog_locked && !Cmd_FromGamecode() && !cls.allow_cheats) || Cmd_Argc() <= 1) { + static const char *fognames[]={"fog","waterfog"}; if (Cmd_ExecLevel != RESTRICT_INSECURE) - Con_Printf("Current fog %f (r:%f g:%f b:%f, a:%f bias:%f)\n", cl.fog[ftype].density, cl.fog[ftype].colour[0], cl.fog[ftype].colour[1], cl.fog[ftype].colour[2], cl.fog[ftype].alpha, cl.fog[ftype].depthbias); + Con_Printf("Current %s %f (r:%f g:%f b:%f, a:%f bias:%f)\n", fognames[ftype], cl.fog[ftype].density, cl.fog[ftype].colour[0], cl.fog[ftype].colour[1], cl.fog[ftype].colour[2], cl.fog[ftype].alpha, cl.fog[ftype].depthbias); } else { @@ -4298,6 +4303,29 @@ void CL_Fog_f(void) } } +#ifdef _DEBUG +void CL_FreeSpace_f(void) +{ + quint64_t freespace; + const char *freepath = Cmd_Argv(1); + if (Sys_GetFreeDiskSpace(freepath, &freespace)) + { + if (freespace > 512.0*1024*1024*1024) + Con_Printf("%s: %g tb available\n", freepath, freespace/(1024.0*1024*1024*1024)); + else if (freespace > 512.0*1024*1024) + Con_Printf("%s: %g gb available\n", freepath, freespace/(1024.0*1024*1024)); + else if (freespace > 512.0*1024) + Con_Printf("%s: %g mb available\n", freepath, freespace/(1024.0*1024)); + else if (freespace > 512.0) + Con_Printf("%s: %g kb available\n", freepath, freespace/1024.0); + else + Con_Printf("%s: %"PRIu64" bytes available\n", freepath, freespace); + } + else + Con_Printf("%s: disk free not queryable\n", freepath); +} +#endif + void CL_CrashMeEndgame_f(void) { Host_EndGame("crashme! %s", Cmd_Args()); @@ -4663,6 +4691,9 @@ void CL_Init (void) Cmd_AddCommandD ("demo_jump", CL_DemoJump_f, "Jump to a specified time in a demo. Prefix with a + or - for a relative offset. Seeking backwards will restart the demo and the fast forward, which can take some time in long demos."); Cmd_AddCommandD ("demo_nudge", CL_DemoNudge_f, "Nudge the demo by one frame. Argument should be +1 or -1. Nudging backwards is limited."); Cmd_AddCommandAD ("timedemo", CL_TimeDemo_f, CL_DemoList_c, NULL); +#ifdef _DEBUG + Cmd_AddCommand ("freespace", CL_FreeSpace_f); +#endif Cmd_AddCommand ("crashme_endgame", CL_CrashMeEndgame_f); Cmd_AddCommand ("crashme_error", CL_CrashMeError_f); diff --git a/engine/client/m_mp3.c b/engine/client/m_mp3.c index 873d94aad..912ab7d5e 100644 --- a/engine/client/m_mp3.c +++ b/engine/client/m_mp3.c @@ -21,17 +21,6 @@ #define HAVE_API_VFW #endif -#ifdef HAVE_MEDIA_ENCODER - #if defined(__linux__) && !defined(ANDROID) - //should really include posix 2001 systems in general - #define HAVE_STATVFS - #endif - #ifdef HAVE_STATVFS - #include - #endif -#endif - - #ifdef _WIN32 #include "winquake.h" #endif @@ -2999,27 +2988,16 @@ static void QDECL capture_raw_video (void *vctx, int frame, void *data, int stri { char base[MAX_QPATH]; Q_strncpyz(base, ctx->videonameprefix, sizeof(base)); - *COM_SkipPath(base) = 0; if (FS_NativePath(base, ctx->fsroot, filename, sizeof(filename))) { - #ifdef HAVE_STATVFS - //posix 2001 - struct statvfs inf; - if(0==statvfs(filename, &inf)) - { - if (inf.f_frsize*(double)inf.f_blocks < (1024.*1024)*capturethrottlesize.value) - Sys_Sleep(1); - } - #elif defined(_WIN32) && !defined(FTE_SDL) - wchar_t ffs[MAX_OSPATH]; - ULARGE_INTEGER freebytes; - if (GetDiskFreeSpaceExW(widen(ffs, sizeof(ffs), filename), &freebytes, NULL, NULL)) - if (freebytes.QuadPart < (ULONGLONG)(1024*1024)*capturethrottlesize.value) - Sys_Sleep(1); - #else - Con_Printf("capturethrottlesize is unsupported in this build\n"); - capturethrottlesize.ival = 0; - #endif + quint64_t diskfree = 0; + if (Sys_GetFreeDiskSpace(filename, &diskfree) && diskfree < (quint64_t)1024*1024*capturethrottlesize.value) + Sys_Sleep(1); //throttle + else + { + Con_Printf("%s: unable to query free disk space. Disabling\n", capturethrottlesize.name); + capturethrottlesize.ival = capturethrottlesize.value = 0; + } } } } diff --git a/engine/client/sys_droid.c b/engine/client/sys_droid.c index 517da8633..4073b7807 100644 --- a/engine/client/sys_droid.c +++ b/engine/client/sys_droid.c @@ -860,6 +860,24 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname) { return !rename(oldfname, newfname); } + +#if _POSIX_C_SOURCE >= 200112L + #include +#endif +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ +#if _POSIX_C_SOURCE >= 200112L + //posix 2001 + struct statvfs inf; + if(0==statvfs(path, &inf)) + { + *freespace = inf.f_bsize*(quint64_t)inf.f_bavail; + return true; + } +#endif + return false; +} + void Sys_SendKeyEvents(void) { } diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index 857e8ef02..7574e91aa 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -480,6 +480,22 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname) { return !rename(oldfname, newfname); } +#if _POSIX_C_SOURCE >= 200112L + #include +#endif +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ +#if _POSIX_C_SOURCE >= 200112L + //posix 2001 + struct statvfs inf; + if(0==statvfs(path, &inf)) + { + *freespace = inf.f_bsize*(quint64_t)inf.f_bavail; //grab the quota-free value rather than the actual free space + return true; + } +#endif + return false; +} int Sys_DebugLog(char *file, char *fmt, ...) { diff --git a/engine/client/sys_sdl.c b/engine/client/sys_sdl.c index 160d220a5..8d7413981 100644 --- a/engine/client/sys_sdl.c +++ b/engine/client/sys_sdl.c @@ -287,6 +287,23 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname) return !rename(oldfname, newfname); } +#if _POSIX_C_SOURCE >= 200112L + #include +#endif +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ +#if _POSIX_C_SOURCE >= 200112L + //posix 2001 + struct statvfs inf; + if(0==statvfs(path, &inf)) + { + *freespace = inf.f_bsize*(quint64_t)inf.f_bavail; + return true; + } +#endif + return false; +} + //someone used the 'quit' command void Sys_Quit (void) { diff --git a/engine/common/fs_win32.c b/engine/common/fs_win32.c index 86dd017ba..34a2a42f0 100644 --- a/engine/common/fs_win32.c +++ b/engine/common/fs_win32.c @@ -682,3 +682,17 @@ searchpathfuncs_t *QDECL VFSW32_OpenPath(vfsfile_t *mustbenull, searchpathfuncs_ return &np->pub; } #endif + + + +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ //symlinks means the path needs to be fairly full. it may also be a file, and relative to the working directory. + wchar_t ffs[MAX_OSPATH]; + ULARGE_INTEGER freebytes; + if (GetDiskFreeSpaceExW(widen(ffs, sizeof(ffs), path), &freebytes, NULL, NULL)) + { + *freespace = freebytes.QuadPart; + return true; + } + return false; +} diff --git a/engine/common/sys.h b/engine/common/sys.h index b15b7f7c2..aabee87c3 100644 --- a/engine/common/sys.h +++ b/engine/common/sys.h @@ -28,6 +28,7 @@ void Sys_mkdir (const char *path); //not all pre-unix systems have directories ( qboolean Sys_rmdir (const char *path); qboolean Sys_remove (const char *path); qboolean Sys_Rename (const char *oldfname, const char *newfname); +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace); //false for not-implemented or other error. path will be a system path, but may be relative (if basedir isn't properly known). path MAY be a file, or may be a slash-terminated directory. qboolean Sys_FindGameData(const char *poshname, const char *gamename, char *basepath, int basepathlen, qboolean allowprompts); // diff --git a/engine/gl/gl_vidnt.c b/engine/gl/gl_vidnt.c index 713b46957..06035054f 100644 --- a/engine/gl/gl_vidnt.c +++ b/engine/gl/gl_vidnt.c @@ -1907,7 +1907,7 @@ qboolean VID_AttachGL (rendererstate_t *info) Con_SafePrintf("WGL_EXTENSIONS: %s\n", wgl_extensions?wgl_extensions:"NONE"); qwglCreateContextAttribsARB = getglfunc("wglCreateContextAttribsARB"); -#if 1//def _DEBUG + //attempt to promote that to opengl3. if (qwglCreateContextAttribsARB) { @@ -2020,7 +2020,6 @@ qboolean VID_AttachGL (rendererstate_t *info) } } } -#endif qwglChoosePixelFormatARB = getglfunc("wglChoosePixelFormatARB"); qwglGetPixelFormatAttribfvARB = getglfunc("wglGetPixelFormatAttribfvARB"); diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index eba999113..f539d1a56 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -111,6 +111,24 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname) return !rename(oldfname, newfname); } + +#if _POSIX_C_SOURCE >= 200112L + #include +#endif +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ +#if _POSIX_C_SOURCE >= 200112L + //posix 2001 + struct statvfs inf; + if(0==statvfs(path, &inf)) + { + *freespace = inf.f_bsize*(quint64_t)inf.f_bavail; + return true; + } +#endif + return false; +} + int Sys_DebugLog(char *file, char *fmt, ...) { va_list argptr; diff --git a/engine/web/sys_web.c b/engine/web/sys_web.c index a8d0722ba..f2705b64d 100644 --- a/engine/web/sys_web.c +++ b/engine/web/sys_web.c @@ -103,6 +103,9 @@ qboolean Sys_remove (const char *path) qboolean Sys_Rename (const char *oldfname, const char *newfname) { return emscriptenfte_buf_rename(oldfname, newfname); +} +qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace) +{ //not implemented. we could try querying local storage quotas, but our filesystem is otherwise purely ram so doesn't have much of a limit in 64bit browsers. hurrah for swap space. return false; }