]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Added qc fs search functions, so the qcs can easily verify directories contents,...
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Dec 2003 18:55:56 +0000 (18:55 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Dec 2003 18:55:56 +0000 (18:55 +0000)
Changed some 'bool's into read-only cvars to make them accessible for the menu qc.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3705 d7cf8633-e32d-0410-b094-e92efae38249

cd_linux.c
cd_win.c
fs.c
gl_backend.c
menu.c
pr_cmds.c
prvm_cmds.c
snd_dma.c
sound.h

index c502e0ace8d21d0135be85242c2d614fc524387e..24ebeb82a35d341df9895a90da9ac35c2047ae63 100644 (file)
@@ -387,7 +387,8 @@ int CDAudio_Init(void)
 
        for (i = 0; i < 100; i++)
                remap[i] = i;
-       cdaudioinitialized = true;
+       Cvar_RegisterVariable(&cdaudioinitialized);
+       Cvar_SetValueQuick(&cdaudioinitialized, true);
        enabled = true;
 
        return 0;
index e3359487ff4365be89808dde7d0da11ee3d4e802..69c1fc6ae6b85eeb516f1b18bb0a90ff5706b2ad 100644 (file)
--- a/cd_win.c
+++ b/cd_win.c
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 extern HWND    mainwindow;
 
-qboolean cdaudioinitialized = false;
+cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"};
 static qboolean cdValid = false;
 static qboolean playing = false;
 static qboolean wasPlaying = false;
@@ -428,7 +428,9 @@ int CDAudio_Init(void)
 
        for (n = 0; n < 100; n++)
                remap[n] = n;
-       cdaudioinitialized = true;
+
+       Cvar_RegisterVariable(&cdaudioinitialized);
+       Cvar_SetValueQuick(&cdaudioinitialized, true);
        enabled = true;
 
        Cmd_AddCommand("cd", CD_f);
diff --git a/fs.c b/fs.c
index 6ad2201d83b5a61e91418f8e57924509f170dd08..cd5f402a21f11698693dc55744844e788a772f32 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -2066,7 +2066,7 @@ void FS_Ls_f(void)
        char pattern[MAX_OSPATH];
        if (Cmd_Argc() > 3)
        {
-               Con_Printf("usage:\ndir [path/pattern]\n");
+               Con_Printf("usage:\nls [path/pattern]\n");
                return;
        }
        if (Cmd_Argc() == 2)
index a4fd9fcb1f4f0439f9e42a4d2bcf694f69036435..730ce44b3afc676af660e1ee58767442b3fcfd21 100644 (file)
@@ -939,7 +939,7 @@ void R_Mesh_State_Texture(const rmeshstate_t *m)
                {
                        GL_ActiveTexture(i);
                        unit->combinergb = combinergb;
-                       if (gl_combine.integer)
+                       if (gl_combine.integer) 
                        {
                                qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
                        }
diff --git a/menu.c b/menu.c
index 6b7e46f329ec381a5f48fdb939da2762728db457..a719a2d2d3b46fe9bd7f2f92623bf9cf6679d7b5 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1283,9 +1283,9 @@ void M_Options_Draw (void)
        M_Options_PrintCheckbox("Delay gfx (faster)", true, gl_delayfinish.integer);
        M_Options_PrintSlider(  "Anisotropic Filter", gl_support_anisotropy, gl_texture_anisotropy.value, 0, 8);
        M_Options_PrintSlider(  "        Game Speed", sv.active, slowmo.value, 0, 5);
-       M_Options_PrintSlider(  "   CD Music Volume", cdaudioinitialized, bgmvolume.value, 0, 1);
-       M_Options_PrintSlider(  "      Sound Volume", snd_initialized, volume.value, 0, 1);
-       M_Options_PrintSlider(gamemode == GAME_GOODVSBAD2 ? "      Music Volume" : "    Ambient Volume", snd_initialized, snd_staticvolume.value, 0, 1);
+       M_Options_PrintSlider(  "   CD Music Volume", cdaudioinitialized.integer, bgmvolume.value, 0, 1);
+       M_Options_PrintSlider(  "      Sound Volume", snd_initialized.integer, volume.value, 0, 1);
+       M_Options_PrintSlider(gamemode == GAME_GOODVSBAD2 ? "      Music Volume" : "    Ambient Volume", snd_initialized.integer, snd_staticvolume.value, 0, 1);
        M_Options_PrintSlider(  "         Crosshair", true, crosshair.value, 0, 5);
        M_Options_PrintSlider(  "    Crosshair Size", true, crosshair_size.value, 1, 5);
        M_Options_PrintCheckbox("  Static Crosshair", true, crosshair_static.integer);
index 360573426eed54d4495dbd1c6eb69b512a2ba5e3..d3d608abdfda69ec03ee14bb04b83df34395b901 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -142,6 +142,7 @@ char *ENGINE_EXTENSIONS =
 "NEH_CMD_PLAY2 "
 "NEH_RESTOREGAME "
 "TW_SV_STEPCONTROL "
+"DP_QC_FS_SEARCH " // Black: same as in the menu qc
 ;
 
 qboolean checkextension(char *name)
@@ -3042,6 +3043,159 @@ void PF_setattachment (void)
 }
 
 
+/////////////////////////////////////////
+// DP_QC_FS_SEARCH extension
+
+// qc fs search handling
+#define MAX_SEARCHES 128
+
+fssearch_t *pr_fssearchlist[MAX_SEARCHES];
+
+void PR_Search_Init(void)
+{
+       memset(pr_fssearchlist,0,sizeof(pr_fssearchlist));
+}
+
+void PR_Search_Reset(void)
+{
+       int i;
+       // reset the fssearch list
+       for(i = 0; i < MAX_SEARCHES; i++)
+               if(pr_fssearchlist[i])
+                       FS_FreeSearch(pr_fssearchlist[i]);
+       memset(pr_fssearchlist,0,sizeof(pr_fssearchlist));
+}
+
+/*
+=========
+PF_search_begin
+
+float search_begin(string pattern, float caseinsensitive, float quiet)
+=========
+*/
+void PF_search_begin(void)
+{
+       int handle;
+       char *pattern;
+       int caseinsens, quiet;
+
+       pattern = G_STRING(OFS_PARM0);
+
+       PR_CheckEmptyString(pattern);
+
+       caseinsens = G_FLOAT(OFS_PARM1);
+       quiet = G_FLOAT(OFS_PARM2);
+       
+       for(handle = 0; handle < MAX_SEARCHES; handle++)
+               if(!pr_fssearchlist[handle])
+                       break;
+
+       if(handle >= MAX_SEARCHES)
+       {
+               Con_Printf("PR_search_begin: ran out of search handles (%i)\n", MAX_SEARCHES);
+               G_FLOAT(OFS_RETURN) = -2;
+               return;
+       }
+
+       if(!(pr_fssearchlist[handle] = FS_Search(pattern,caseinsens, quiet)))
+               G_FLOAT(OFS_RETURN) = -1;
+       else
+               G_FLOAT(OFS_RETURN) = handle;
+}
+
+/*
+=========
+VM_search_end
+
+void   search_end(float handle)
+=========
+*/
+void PF_search_end(void)
+{
+       int handle;
+
+       handle = G_FLOAT(OFS_PARM0);
+       
+       if(handle < 0 || handle >= MAX_SEARCHES)
+       {
+               Con_Printf("PF_search_end: invalid handle %i\n", handle);
+               return;
+       }
+       if(pr_fssearchlist[handle] == NULL)
+       {
+               Con_Printf("PF_search_end: no such handle %i\n", handle);
+               return;
+       }
+
+       FS_FreeSearch(pr_fssearchlist[handle]);
+       pr_fssearchlist[handle] = NULL;
+}
+
+/*
+=========
+VM_search_getsize
+
+float  search_getsize(float handle)
+=========
+*/
+void PF_search_getsize(void)
+{
+       int handle;
+
+       handle = G_FLOAT(OFS_PARM0);
+
+       if(handle < 0 || handle >= MAX_SEARCHES)
+       {
+               Con_Printf("PF_search_getsize: invalid handle %i\n", handle);
+               return;
+       }
+       if(pr_fssearchlist[handle] == NULL)
+       {
+               Con_Printf("PF_search_getsize: no such handle %i\n", handle);
+               return;
+       }
+       
+       G_FLOAT(OFS_RETURN) = pr_fssearchlist[handle]->numfilenames;
+}
+
+/*
+=========
+VM_search_getfilename
+
+string search_getfilename(float handle, float num)
+=========
+*/
+void PF_search_getfilename(void)
+{
+       int handle, filenum;
+       char *tmp;
+
+       handle = G_FLOAT(OFS_PARM0);
+       filenum = G_FLOAT(OFS_PARM1);
+
+       if(handle < 0 || handle >= MAX_SEARCHES)
+       {
+               Con_Printf("PF_search_getfilename: invalid handle %i\n", handle);
+               return;
+       }
+       if(pr_fssearchlist[handle] == NULL)
+       {
+               Con_Printf("PF_search_getfilename: no such handle %i\n", handle);
+               return;
+       }
+       if(filenum < 0 || filenum >= pr_fssearchlist[handle]->numfilenames)
+       {
+               Con_Printf("PF_search_getfilename: invalid filenum %i\n", filenum);
+               return;
+       }
+       
+       tmp = PR_GetTempString();
+       strcpy(tmp, pr_fssearchlist[handle]->filenames[filenum]);
+
+       G_INT(OFS_RETURN) = PR_SetString(tmp);
+}
+
+
 builtin_t pr_builtin[] =
 {
 NULL,                                          // #0
@@ -3212,10 +3366,10 @@ PF_clientcommand,                       // #440 void(entity e, string s) clientcommand (KRIMZON_SV_P
 PF_tokenize,                           // #441 float(string s) tokenize (KRIMZON_SV_PARSECLIENTCOMMAND)
 PF_argv,                                       // #442 string(float n) argv (KRIMZON_SV_PARSECLIENTCOMMAND)
 PF_setattachment,                      // #443 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS)
-NULL,                                          // #444
-NULL,                                          // #445
-NULL,                                          // #446
-NULL,                                          // #447
+PF_search_begin,                       // #444
+PF_search_end,                         // #445
+PF_search_getsize,                     // #446
+PF_search_getfilename,         // #447
 NULL,                                          // #448
 NULL,                                          // #449
 a a a a a                                      // #450-499 (LordHavoc)
@@ -3228,11 +3382,13 @@ void PR_Cmd_Init(void)
 {
        pr_strings_mempool = Mem_AllocPool("pr_stringszone");
        PR_Files_Init();
+       PR_Search_Init();
 }
 
 void PR_Cmd_Reset(void)
 {
        Mem_EmptyPool(pr_strings_mempool);
+       PR_Search_Reset();
        PR_Files_CloseAll();
 }
 
index fc0396a0eda7cb706940c6cd107b21fb53fffcfb..fb68eea4cfd7ee1e1dff36590f3f0f2d3984ed41 100644 (file)
@@ -1,7 +1,7 @@
 // AK
 // Basically every vm builtin cmd should be in here.
-// All 3 builtin list and extension lists can be found here
-// cause large (I think they will) are from pr_cmds the same copyright like in pr_cms
+// All 3 builtin and extension lists can be found here
+// cause large (I think they will) parts are from pr_cmds the same copyright like in pr_cmds
 // also applies here
 
 
@@ -90,6 +90,11 @@ const string str_cvar (string)
                crash()
                stackdump()
                
+float  search_begin(string pattern, float caseinsensitive, float quiet)
+void   search_end(float handle)
+float  search_getsize(float handle)
+string search_getfilename(float handle, float num)
+               
 perhaps only : Menu : WriteMsg 
 ===============================
 
@@ -130,6 +135,8 @@ float       getmousetarget(void)
                writetofile(float fhandle, entity ent)
 float  isfunction(string function_name)
 vector getresolution(float number)
+string keynumtostring(float keynum)
+
 */
 
 #include "quakedef.h"
@@ -179,6 +186,13 @@ int vm_currentqc_cvar;
 
 qfile_t *vm_files[MAX_PRVMFILES];
 
+// qc fs search handling
+#define MAX_VMSEARCHES 128
+#define TOTAL_VMSEARCHES MAX_VMSEARCHES * PRVM_MAXPROGS
+#define VM_SEARCHLIST ((fssearch_t**)(vm_fssearchlist + PRVM_GetProgNr() * MAX_VMSEARCHES))
+
+fssearch_t *vm_fssearchlist[TOTAL_VMSEARCHES];
+
 static char *VM_GetTempString(void)
 {
        char *s;
@@ -2268,6 +2282,155 @@ void VM_modulo(void)
        PRVM_G_FLOAT(OFS_RETURN) = (float) (val % m);
 }
 
+void VM_Search_Init(void)
+{
+       memset(VM_SEARCHLIST,0,sizeof(fssearch_t*[MAX_VMSEARCHES]));
+}
+
+void VM_Search_Reset(void)
+{
+       int i;
+       // reset the fssearch list
+       for(i = 0; i < MAX_VMSEARCHES; i++)
+               if(VM_SEARCHLIST[i])
+                       FS_FreeSearch(VM_SEARCHLIST[i]);
+       memset(VM_SEARCHLIST,0,sizeof(fssearch_t*[MAX_VMSEARCHES]));
+}
+
+/*
+=========
+VM_search_begin
+
+float search_begin(string pattern, float caseinsensitive, float quiet)
+=========
+*/
+void VM_search_begin(void)
+{
+       int handle;
+       char *pattern;
+       int caseinsens, quiet;
+
+       VM_SAFEPARMCOUNT(3, VM_search_begin);
+
+       pattern = PRVM_G_STRING(OFS_PARM0);
+
+       VM_CheckEmptyString(pattern);
+
+       caseinsens = PRVM_G_FLOAT(OFS_PARM1);
+       quiet = PRVM_G_FLOAT(OFS_PARM2);
+       
+       for(handle = 0; handle < MAX_VMSEARCHES; handle++)
+               if(!VM_SEARCHLIST[handle])
+                       break;
+
+       if(handle >= MAX_VMSEARCHES)
+       {
+               Con_Printf("VM_search_begin: %s ran out of search handles (%i)\n", PRVM_NAME, MAX_VMSEARCHES);
+               PRVM_G_FLOAT(OFS_RETURN) = -2;
+               return;
+       }
+
+       if(!(VM_SEARCHLIST[handle] = FS_Search(pattern,caseinsens, quiet)))
+               PRVM_G_FLOAT(OFS_RETURN) = -1;
+       else
+               PRVM_G_FLOAT(OFS_RETURN) = handle;
+}
+
+/*
+=========
+VM_search_end
+
+void   search_end(float handle)
+=========
+*/
+void VM_search_end(void)
+{
+       int handle;
+       VM_SAFEPARMCOUNT(1, VM_search_end);
+
+       handle = PRVM_G_FLOAT(OFS_PARM0);
+       
+       if(handle < 0 || handle >= MAX_VMSEARCHES)
+       {
+               Con_Printf("VM_search_end: invalid handle %i used in %s\n", handle, PRVM_NAME);
+               return;
+       }
+       if(VM_SEARCHLIST[handle] == NULL)
+       {
+               Con_Printf("VM_search_end: no such handle %i in %s\n", handle, PRVM_NAME);
+               return;
+       }
+
+       FS_FreeSearch(VM_SEARCHLIST[handle]);
+       VM_SEARCHLIST[handle] = NULL;
+}
+
+/*
+=========
+VM_search_getsize
+
+float  search_getsize(float handle)
+=========
+*/
+void VM_search_getsize(void)
+{
+       int handle;
+       VM_SAFEPARMCOUNT(1, VM_M_search_getsize);
+
+       handle = PRVM_G_FLOAT(OFS_PARM0);
+
+       if(handle < 0 || handle >= MAX_VMSEARCHES)
+       {
+               Con_Printf("VM_search_getsize: invalid handle %i used in %s\n", handle, PRVM_NAME);
+               return;
+       }
+       if(VM_SEARCHLIST[handle] == NULL)
+       {
+               Con_Printf("VM_search_getsize: no such handle %i in %s\n", handle, PRVM_NAME);
+               return;
+       }
+       
+       PRVM_G_FLOAT(OFS_RETURN) = VM_SEARCHLIST[handle]->numfilenames;
+}
+
+/*
+=========
+VM_search_getfilename
+
+string search_getfilename(float handle, float num)
+=========
+*/
+void VM_search_getfilename(void)
+{
+       int handle, filenum;
+       char *tmp;
+       VM_SAFEPARMCOUNT(2, VM_search_getfilename);
+
+       handle = PRVM_G_FLOAT(OFS_PARM0);
+       filenum = PRVM_G_FLOAT(OFS_PARM1);
+
+       if(handle < 0 || handle >= MAX_VMSEARCHES)
+       {
+               Con_Printf("VM_search_getfilename: invalid handle %i used in %s\n", handle, PRVM_NAME);
+               return;
+       }
+       if(VM_SEARCHLIST[handle] == NULL)
+       {
+               Con_Printf("VM_search_getfilename: no such handle %i in %s\n", handle, PRVM_NAME);
+               return;
+       }
+       if(filenum < 0 || filenum >= VM_SEARCHLIST[handle]->numfilenames)
+       {
+               Con_Printf("VM_search_getfilename: invalid filenum %i in %s\n", filenum, PRVM_NAME);
+               return;
+       }
+       
+       tmp = VM_GetTempString();
+       strcpy(tmp, VM_SEARCHLIST[handle]->filenames[filenum]);
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetString(tmp);
+}
+
 //=============================================================================
 // Draw builtins (client & menu)
 
@@ -2584,13 +2747,15 @@ void VM_Cmd_Init(void)
 {
        // only init the stuff for the current prog
        VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME));
-       VM_Files_Init();                
+       VM_Files_Init();
+       VM_Search_Init();
 }
 
 void VM_Cmd_Reset(void)
 {
        //Mem_EmptyPool(VM_STRINGS_MEMPOOL);
        Mem_FreePool(&VM_STRINGS_MEMPOOL);
+       VM_Search_Reset();
        VM_Files_CloseAll();
 }
 
@@ -2874,6 +3039,28 @@ void VM_M_getresolution(void)
        PRVM_G_VECTOR(OFS_RETURN)[2] = 0;       
 }
 
+/*
+=========
+VM_M_keynumtostring
+
+string keynumtostring(float keynum)
+=========
+*/
+void VM_M_keynumtostring(void)
+{
+       int keynum;
+       char *tmp;
+       VM_SAFEPARMCOUNT(1, VM_M_keynumtostring);
+
+       keynum = PRVM_G_FLOAT(OFS_PARM0);
+
+       tmp = VM_GetTempString();
+       
+       strcpy(tmp, Key_KeynumToString(keynum));
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetString(tmp);
+}
+
 prvm_builtin_t vm_m_builtins[] = {
        0, // to be consistent with the old vm
        // common builtings (mostly)
@@ -2950,7 +3137,11 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_str_cvar,    
        VM_crash,
        VM_stackdump,   // 73
-       0,0,0,0,0,0,0,// 80
+       VM_search_begin,
+       VM_search_end,
+       VM_search_getsize,
+       VM_search_getfilename, // 77
+       0,0,0,// 80
        e10,                    // 90
        e10,                    // 100
        e100,                   // 200
@@ -2995,7 +3186,8 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_M_callfunction,
        VM_M_writetofile,
        VM_M_isfunction,
-       VM_M_getresolution // 608
+       VM_M_getresolution,
+       VM_M_keynumtostring // 609
 };
 
 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
@@ -3009,5 +3201,4 @@ void VM_M_Cmd_Reset(void)
 {
        //VM_Cmd_Init();
        VM_Cmd_Reset();
-}
-
+}
\ No newline at end of file
index 32de7663e2c19e73baa7b35b07cc8b19f8153301..1523b46f76722e3c00e1e29ada252391add9dfd6 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -42,7 +42,8 @@ int total_channels;
 
 int snd_blocked = 0;
 static qboolean snd_ambient = 1;
-qboolean snd_initialized = false;
+//qboolean snd_initialized = false;
+cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0"};
 
 // pointer should go away
 volatile dma_t *shm = 0;
@@ -144,7 +145,7 @@ void S_LoadSounds(void)
 
 void S_Startup(void)
 {
-       if (!snd_initialized)
+       if (!snd_initialized.integer)
                return;
 
        shm = &sn;
@@ -236,6 +237,7 @@ void S_Init(void)
 
        Cvar_RegisterVariable(&nosound);
        Cvar_RegisterVariable(&snd_precache);
+       Cvar_RegisterVariable(&snd_initialized);
        Cvar_RegisterVariable(&bgmbuffer);
        Cvar_RegisterVariable(&ambient_level);
        Cvar_RegisterVariable(&ambient_fade);
@@ -244,7 +246,7 @@ void S_Init(void)
        Cvar_RegisterVariable(&_snd_mixahead);
        Cvar_RegisterVariable(&snd_swapstereo); // LordHavoc: for people with backwards sound wiring
 
-       snd_initialized = true;
+       Cvar_SetValueQuick(&snd_initialized, true);
 
        known_sfx = Mem_Alloc(snd_mempool, MAX_SFX*sizeof(sfx_t));
        num_sfx = 0;
@@ -273,7 +275,7 @@ sfx_t *S_GetCached (const char *name)
 {
        int i;
 
-       if (!snd_initialized)
+       if (!snd_initialized.integer)
                return NULL;
 
        if (!name)
@@ -300,7 +302,7 @@ sfx_t *S_FindName (char *name)
        int i;
        sfx_t *sfx;
 
-       if (!snd_initialized)
+       if (!snd_initialized.integer)
                return NULL;
 
        if (!name)
@@ -345,7 +347,7 @@ sfx_t *S_PrecacheSound (char *name, int complain)
 {
        sfx_t *sfx;
 
-       if (!snd_initialized)
+       if (!snd_initialized.integer)
                return NULL;
 
        sfx = S_FindName(name);
@@ -724,7 +726,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up)
        channel_t       *ch;
        channel_t       *combine;
 
-       if (!snd_initialized || (snd_blocked > 0))
+       if (!snd_initialized.integer || (snd_blocked > 0))
                return;
 
        VectorCopy(origin, listener_vieworigin);
@@ -969,7 +971,7 @@ void S_LocalSound (char *sound)
 {
        sfx_t   *sfx;
 
-       if (!snd_initialized || nosound.integer)
+       if (!snd_initialized.integer || nosound.integer)
                return;
 
        sfx = S_PrecacheSound (sound, true);
diff --git a/sound.h b/sound.h
index 3ff662e137e3393271929e0b958ef4d51f6a0d50..e0ef6c73049e5a2f5acf49c71c5ed22e2b68f857 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -161,8 +161,8 @@ extern cvar_t bgmvolume;
 extern cvar_t volume;
 extern cvar_t snd_swapstereo;
 
-extern qboolean cdaudioinitialized;
-extern qboolean        snd_initialized;
+extern cvar_t cdaudioinitialized;
+extern cvar_t  snd_initialized;
 
 extern int snd_blocked;