]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
-Removed the NG Menu part, since it isnt used anymore (the old layout
[xonotic/darkplaces.git] / prvm_cmds.c
index 01902dbe5dc2fd8cbec2b44debff8cf1f377bf4f..b6c6b16c89628d4f16cfc637183eb41d1c65fcb9 100644 (file)
@@ -150,6 +150,7 @@ string      gethostcachestring(float type, float hostnr)
 
 #include "quakedef.h"
 #include "progdefs.h"
+#include "progsvm.h"
 #include "clprogdefs.h"
 #include "mprogdefs.h"
 
@@ -391,8 +392,6 @@ void VM_sprint (void)
        }
        
        client = svs.clients + clientnum;
-       if (!client->netconnection)
-               return;
        VM_VarString(1, string, sizeof(string));
        MSG_WriteChar(&client->message,svc_print);
        MSG_WriteString(&client->message, string);
@@ -560,13 +559,9 @@ float random()
 */
 void VM_random (void)
 {
-       float           num;
-
        VM_SAFEPARMCOUNT(0,VM_random);
 
-       num = (rand ()&0x7fff) / ((float)0x7fff);
-
-       PRVM_G_FLOAT(OFS_RETURN) = num;
+       PRVM_G_FLOAT(OFS_RETURN) = lhrandom(0, 1);
 }
 
 /*
@@ -627,7 +622,7 @@ void VM_localsound(void)
 
        s = PRVM_G_STRING(OFS_PARM0);
 
-       if(!S_LocalSound(s, true))
+       if(!S_LocalSound (s))
        {
                Con_Printf("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME);
                PRVM_G_FLOAT(OFS_RETURN) = -4;
@@ -1041,7 +1036,7 @@ void VM_findchain (void)
                if (strcmp(t,s))
                        continue;
 
-               PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
                chain = ent;
        }
 
@@ -1084,10 +1079,10 @@ void VM_findchainfloat (void)
                prog->xfunction->builtinsprofile++;
                if (ent->p.e->free)
                        continue;
-               if (E_FLOAT(ent,f) != s)
+               if (PRVM_E_FLOAT(ent,f) != s)
                        continue;
 
-               PRVM_E_FLOAT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+               PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain);
                chain = ent;
        }
 
@@ -1137,8 +1132,8 @@ void VM_precache_sound (void)
        s = PRVM_G_STRING(OFS_PARM0);
        PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
        VM_CheckEmptyString (s);
-       
-       if(!S_PrecacheSound(s,true, true, true))
+
+       if(!S_PrecacheSound (s,true, true))
                Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
 }
 
@@ -1542,7 +1537,7 @@ void VM_registercvar (void)
                return;
        }
 
-       Cvar_Get(name, value, 0);
+       Cvar_Get(name, value, flags);
 
        PRVM_G_FLOAT(OFS_RETURN) = 1; // success
 }
@@ -1595,7 +1590,7 @@ void VM_max (void)
                for (i = 1;i < prog->argc;i++)
                        if (PRVM_G_FLOAT((OFS_PARM0+i*3)) > f)
                                f = PRVM_G_FLOAT((OFS_PARM0+i*3));
-               G_FLOAT(OFS_RETURN) = f;
+               PRVM_G_FLOAT(OFS_RETURN) = f;
        }
        else
                PRVM_ERROR("VM_max: %s must supply at least 2 floats\n", PRVM_NAME);
@@ -1912,8 +1907,8 @@ void VM_strcat(void)
 {
        char *s;
 
-       if(prog->argc < 2
-               PRVM_ERROR("VM_strcat wrong parameter count (min. 2 expected ) !\n");
+       if(prog->argc < 1
+               PRVM_ERROR("VM_strcat wrong parameter count (min. 1 expected ) !\n");
        
        s = VM_GetTempString();
        VM_VarString(0, s, VM_STRINGTEMP_LENGTH);
@@ -1997,9 +1992,14 @@ strunzone(string s)
 //void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!)
 void VM_strunzone(void)
 {
+       char *str;
        VM_SAFEPARMCOUNT(1,VM_strunzone);
 
-       Mem_Free(PRVM_G_STRING(OFS_PARM0));
+       str = PRVM_G_STRING(OFS_PARM0);
+       if( developer.integer && !Mem_IsAllocated( VM_STRINGS_MEMPOOL, str ) )
+               PRVM_ERROR( "VM_strunzone: Zone string already freed in %s!", PRVM_NAME );
+       else
+               Mem_Free( str );
 }
 
 /*
@@ -2829,6 +2829,14 @@ void VM_Cmd_Init(void)
 void VM_Cmd_Reset(void)
 {
        //Mem_EmptyPool(VM_STRINGS_MEMPOOL);
+       if( developer.integer >= 2 && VM_STRINGS_MEMPOOL ) {
+               memheader_t *header;
+               int     i;
+
+               for( i = 0, header = VM_STRINGS_MEMPOOL->chain ; header ; header = header->next, i++ )
+                       Con_DPrintf( "Leaked string %i (size: %i): %.*s\n", i, header->size, header->size, ((char*)header) + sizeof( memheader_t ) );
+       }
+
        Mem_FreePool(&VM_STRINGS_MEMPOOL);
        VM_Search_Reset();
        VM_Files_CloseAll();