From 9dc8149ee231682452a52a4ec4bdee3981da5492 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 9 Mar 2005 17:36:50 +0000 Subject: [PATCH 1/1] cl_capturevideo_raw* modes now use O_NONBLOCKING file access for more performance git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5074 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 6 +++--- cl_screen.c | 6 +++--- console.c | 8 ++++---- dpvsimpledecode.c | 2 +- fs.c | 19 +++++++++++-------- fs.h | 2 +- host.c | 2 +- host_cmd.c | 2 +- jpeg.c | 2 +- menu.c | 18 +++++++++--------- pr_cmds.c | 4 ++-- prvm_cmds.c | 4 ++-- wad.c | 2 +- 13 files changed, 40 insertions(+), 37 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index af701590..e9236ce8 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -286,7 +286,7 @@ void CL_Record_f (void) // open the demo file Con_Printf("recording to %s.\n", name); - cls.demofile = FS_Open (name, "wb", false); + cls.demofile = FS_Open (name, "wb", false, false); if (!cls.demofile) { Con_Print("ERROR: couldn't open.\n"); @@ -334,7 +334,7 @@ void CL_PlayDemo_f (void) FS_DefaultExtension (name, ".dem", sizeof (name)); Con_Printf("Playing demo from %s.\n", name); - cls.demofile = FS_Open (name, "rb", false); + cls.demofile = FS_Open (name, "rb", false, false); if (!cls.demofile) { Con_Print("ERROR: couldn't open.\n"); @@ -414,6 +414,6 @@ void CL_TimeDemo_f (void) cls.timedemo = true; // get first message this frame - cls.td_lastframe = -1; + cls.td_lastframe = -1; } diff --git a/cl_screen.c b/cl_screen.c index 00a2630a..dc0418a1 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -784,12 +784,12 @@ Cr = R * .500 + G * -.419 + B * -.0813 + 128.; if (cl_capturevideo_rawrgb.integer) { cl_capturevideo_format = CAPTUREVIDEOFORMAT_RAWRGB; - cl_capturevideo_videofile = FS_Open ("video/dpvideo.rgb", "wb", false); + cl_capturevideo_videofile = FS_Open ("video/dpvideo.rgb", "wb", false, true); } else if (cl_capturevideo_rawyv12.integer) { cl_capturevideo_format = CAPTUREVIDEOFORMAT_RAWYV12; - cl_capturevideo_videofile = FS_Open ("video/dpvideo.yv12", "wb", false); + cl_capturevideo_videofile = FS_Open ("video/dpvideo.yv12", "wb", false, true); } else if (scr_screenshot_jpeg.integer) { @@ -802,7 +802,7 @@ Cr = R * .500 + G * -.419 + B * -.0813 + 128.; cl_capturevideo_videofile = NULL; } - cl_capturevideo_soundfile = FS_Open ("video/dpvideo.wav", "wb", false); + cl_capturevideo_soundfile = FS_Open ("video/dpvideo.wav", "wb", false, true); // wave header will be filled out when video ends memset(out, 0, 44); diff --git a/console.c b/console.c index 72dfd9e0..f36ca203 100644 --- a/console.c +++ b/console.c @@ -138,7 +138,7 @@ void Log_Open (void) if (logfile != NULL || log_file.string[0] == '\0') return; - logfile = FS_Open (log_file.string, "ab", false); + logfile = FS_Open (log_file.string, "ab", false, false); if (logfile != NULL) { strlcpy (crt_log_file, log_file.string, sizeof (crt_log_file)); @@ -252,7 +252,7 @@ void Log_Printf (const char *logfilename, const char *fmt, ...) { qfile_t *file; - file = FS_Open (logfilename, "ab", true); + file = FS_Open (logfilename, "ab", true, false); if (file != NULL) { va_list argptr; @@ -752,7 +752,7 @@ static void _Con_DrawString( float x, float y, const char *text, int maxlen, flo color = _con_colors[index]; // we dont want to display the color tag and the color index first = last; - } + } } } @@ -907,7 +907,7 @@ void Con_DrawConsole (int lines) rows = (lines-16)>>3; // rows of text to draw y = lines - 16 - (rows<<3); // may start slightly negative - + for (i = con_current - rows + 1;i <= con_current;i++, y += 8) { j = max(i - con_backscroll, 0); diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index 9927a760..90b86dc5 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -37,7 +37,7 @@ hz_bitstream_read_t *hz_bitstream_read_open(char *filename) { qfile_t *file; hz_bitstream_read_t *stream; - if ((file = FS_Open (filename, "rb", false))) + if ((file = FS_Open (filename, "rb", false, false))) { stream = malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); diff --git a/fs.c b/fs.c index b47d6117..8e0708d1 100644 --- a/fs.c +++ b/fs.c @@ -1012,7 +1012,7 @@ FS_SysOpen Internal function used to create a qfile_t and open the relevant non-packed file on disk ==================== */ -static qfile_t* FS_SysOpen (const char* filepath, const char* mode) +static qfile_t* FS_SysOpen (const char* filepath, const char* mode, qboolean nonblocking) { qfile_t* file; int mod, opt; @@ -1053,6 +1053,9 @@ static qfile_t* FS_SysOpen (const char* filepath, const char* mode) } } + if (nonblocking) + opt |= O_NONBLOCK; + file = Mem_Alloc (fs_mempool, sizeof (*file)); memset (file, 0, sizeof (*file)); file->ungetc = EOF; @@ -1291,7 +1294,7 @@ Look for a file in the search paths and open it in read-only mode Sets fs_filesize =========== */ -qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet) +qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonblocking) { searchpath_t *search; int pack_ind; @@ -1310,7 +1313,7 @@ qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet) { char path [MAX_OSPATH]; dpsnprintf (path, sizeof (path), "%s/%s", search->filename, filename); - return FS_SysOpen (path, "rb"); + return FS_SysOpen (path, "rb", nonblocking); } // So, we found it in a package... @@ -1333,7 +1336,7 @@ FS_Open Open a file. The syntax is the same as fopen ==================== */ -qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet) +qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking) { qfile_t* file; @@ -1354,11 +1357,11 @@ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet) // Create directories up to the file FS_CreatePath (real_path); - return FS_SysOpen (real_path, mode); + return FS_SysOpen (real_path, mode, nonblocking); } // Else, we look at the various search paths and open the file in read-only mode - file = FS_OpenReadFile (filepath, quiet); + file = FS_OpenReadFile (filepath, quiet, nonblocking); if (file != NULL) fs_filesize = file->real_length; @@ -1794,7 +1797,7 @@ qbyte *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet) qfile_t *file; qbyte *buf; - file = FS_Open (path, "rb", quiet); + file = FS_Open (path, "rb", quiet, false); if (!file) return NULL; @@ -1819,7 +1822,7 @@ qboolean FS_WriteFile (const char *filename, void *data, int len) { qfile_t *file; - file = FS_Open (filename, "wb", false); + file = FS_Open (filename, "wb", false, false); if (!file) { Con_Printf("FS_WriteFile: failed on %s\n", filename); diff --git a/fs.h b/fs.h index 665de9dc..219adee0 100644 --- a/fs.h +++ b/fs.h @@ -44,7 +44,7 @@ extern int fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile // IMPORTANT: the file path is automatically prefixed by the current game directory for // each file created by FS_WriteFile, or opened in "write" or "append" mode by FS_Open -qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet); +qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking); int FS_Close (qfile_t* file); size_t FS_Write (qfile_t* file, const void* data, size_t datasize); size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize); diff --git a/host.c b/host.c index 7a49529f..3c698965 100644 --- a/host.c +++ b/host.c @@ -280,7 +280,7 @@ void Host_SaveConfig_f(void) // config.cfg cvars if (host_initialized && cls.state != ca_dedicated) { - f = FS_Open ("config.cfg", "wb", false); + f = FS_Open ("config.cfg", "wb", false, false); if (!f) { Con_Print("Couldn't write config.cfg.\n"); diff --git a/host_cmd.c b/host_cmd.c index 2efcdd05..86668a20 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -500,7 +500,7 @@ void Host_Savegame_f (void) FS_DefaultExtension (name, ".sav", sizeof (name)); Con_Printf("Saving game to %s...\n", name); - f = FS_Open (name, "wb", false); + f = FS_Open (name, "wb", false, false); if (!f) { Con_Print("ERROR: couldn't open.\n"); diff --git a/jpeg.c b/jpeg.c index 70bd13da..45a2c32b 100644 --- a/jpeg.c +++ b/jpeg.c @@ -671,7 +671,7 @@ qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height, } // Open the file - file = FS_Open (filename, "wb", true); + file = FS_Open (filename, "wb", true, false); if (!file) return false; diff --git a/menu.c b/menu.c index 452565ce..3fcc7dbd 100644 --- a/menu.c +++ b/menu.c @@ -607,11 +607,11 @@ void M_Main_Key (int key, char ascii) case 0: M_Menu_Transfusion_Episode_f (); break; - + case 1: M_Menu_MultiPlayer_f (); break; - + case 2: M_Menu_Options_f (); break; @@ -623,7 +623,7 @@ void M_Main_Key (int key, char ascii) case 4: M_Menu_Help_f (); break; - + case 5: M_Menu_Credits_f (); break; @@ -640,11 +640,11 @@ void M_Main_Key (int key, char ascii) case 0: M_Menu_Transfusion_Episode_f (); break; - + case 1: M_Menu_MultiPlayer_f (); break; - + case 2: M_Menu_Options_f (); break; @@ -656,7 +656,7 @@ void M_Main_Key (int key, char ascii) case 4: M_Menu_Load_f (); break; - + case 5: M_Menu_Help_f (); break; @@ -833,7 +833,7 @@ void M_ScanSaves (void) strcpy (m_filenames[i], "--- UNUSED SLOT ---"); loadable[i] = false; sprintf (name, "s%i.sav", i); - f = FS_Open (name, "rb", false); + f = FS_Open (name, "rb", false, false); if (!f) continue; // read enough to get the comment @@ -1010,13 +1010,13 @@ void M_Transfusion_Episode_Draw (void) int y; cachepic_t *p; M_Background(640, 480); - + p = Draw_CachePic ("gfx/tb-episodes"); M_DrawPic (640/2 - p->width/2, 40, "gfx/tb-episodes"); for (y = 0; y < EPISODE_ITEMS; y++){ M_DrawPic (0, 160 + y * 40, va("gfx/episode%i", y+1)); } - + M_DrawPic (0, 120 + (m_episode_cursor + 1) * 40, va("gfx/episode%iselected", m_episode_cursor + 1)); } diff --git a/pr_cmds.c b/pr_cmds.c index 500f57f6..e57ebe39 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -2840,10 +2840,10 @@ void PF_fopen(void) } filename = G_STRING(OFS_PARM0); // -4 failure (dangerous/non-portable filename) removed, FS_Open checks - pr_files[filenum] = FS_Open(va("data/%s", filename), modestring, false); + pr_files[filenum] = FS_Open(va("data/%s", filename), modestring, false, false); if (pr_files[filenum] == NULL && modestring == "rb") - pr_files[filenum] = FS_Open(filename, modestring, false); + pr_files[filenum] = FS_Open(filename, modestring, false, false); if (pr_files[filenum] == NULL) G_FLOAT(OFS_RETURN) = -1; diff --git a/prvm_cmds.c b/prvm_cmds.c index 1d0a3d4c..126d3a45 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1775,9 +1775,9 @@ void VM_fopen(void) PRVM_G_FLOAT(OFS_RETURN) = -4; return; } - VM_FILES[filenum] = FS_Open(va("data/%s", filename), modestring, false); + VM_FILES[filenum] = FS_Open(va("data/%s", filename), modestring, false, false); if (VM_FILES[filenum] == NULL && mode == 0) - VM_FILES[filenum] = FS_Open(va("%s", filename), modestring, false); + VM_FILES[filenum] = FS_Open(va("%s", filename), modestring, false, false); if (VM_FILES[filenum] == NULL) PRVM_G_FLOAT(OFS_RETURN) = -1; diff --git a/wad.c b/wad.c index 0f4459c8..2183b8e3 100644 --- a/wad.c +++ b/wad.c @@ -157,7 +157,7 @@ void W_LoadTextureWadFile (char *filename, int complain) qfile_t *file; int numlumps; - file = FS_Open (filename, "rb", false); + file = FS_Open (filename, "rb", false, false); if (!file) { if (complain) -- 2.39.2