]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
made darkplaces compile successfully with g++ to test for errors C doesn't care about...
[xonotic/darkplaces.git] / prvm_cmds.c
index cf72710d3674ccb847dfd3451afc8c824cd8bd98..e3f639294101fddda2a90ca74c9b9694fdf306c8 100644 (file)
@@ -74,9 +74,9 @@ checkextension(extensionname)
 // kind of helper function
 static qboolean checkextension(const char *name)
 {
-       size_t len;
+       int len;
        char *e, *start;
-       len = strlen(name);
+       len = (int)strlen(name);
 
        for (e = prog->extensionstring;*e;e++)
        {
@@ -87,7 +87,7 @@ static qboolean checkextension(const char *name)
                start = e;
                while (*e && *e != ' ')
                        e++;
-               if ((size_t)(e - start) == len && !strncasecmp(start, name, len))
+               if ((e - start) == len && !strncasecmp(start, name, len))
                        return true;
        }
        return false;
@@ -252,24 +252,20 @@ void VM_normalize (void)
 {
        float   *value1;
        vec3_t  newvalue;
-       float   new;
+       double  f;
 
        VM_SAFEPARMCOUNT(1,VM_normalize);
 
        value1 = PRVM_G_VECTOR(OFS_PARM0);
 
-       new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
-       new = sqrt(new);
-
-       if (new == 0)
-               newvalue[0] = newvalue[1] = newvalue[2] = 0;
-       else
+       f = VectorLength2(value1);
+       if (f)
        {
-               new = 1/new;
-               newvalue[0] = value1[0] * new;
-               newvalue[1] = value1[1] * new;
-               newvalue[2] = value1[2] * new;
+               f = 1.0 / sqrt(f);
+               VectorScale(value1, f, newvalue);
        }
+       else
+               VectorClear(newvalue);
 
        VectorCopy (newvalue, PRVM_G_VECTOR(OFS_RETURN));
 }
@@ -283,17 +279,8 @@ scalar vlen(vector)
 */
 void VM_vlen (void)
 {
-       float   *value1;
-       float   new;
-
        VM_SAFEPARMCOUNT(1,VM_vlen);
-
-       value1 = PRVM_G_VECTOR(OFS_PARM0);
-
-       new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
-       new = sqrt(new);
-
-       PRVM_G_FLOAT(OFS_RETURN) = new;
+       PRVM_G_FLOAT(OFS_RETURN) = VectorLength(PRVM_G_VECTOR(OFS_PARM0));
 }
 
 /*
@@ -1677,7 +1664,7 @@ fputs(float fhandle, string s)
 //void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file
 void VM_fputs(void)
 {
-       size_t stringlength;
+       int stringlength;
        char string[VM_STRINGTEMP_LENGTH];
        int filenum;
 
@@ -1695,7 +1682,7 @@ void VM_fputs(void)
                return;
        }
        VM_VarString(1, string, sizeof(string));
-       if ((stringlength = strlen(string)))
+       if ((stringlength = (int)strlen(string)))
                FS_Write(VM_FILES[filenum], string, stringlength);
        if (developer.integer)
                Con_Printf("fputs: %s: %s\n", PRVM_NAME, string);
@@ -2104,7 +2091,7 @@ loadfromfile(string file)
 void VM_loadfromfile(void)
 {
        const char *filename;
-       qbyte *data;
+       char *data;
 
        VM_SAFEPARMCOUNT(1,VM_loadfromfile);
 
@@ -2121,7 +2108,7 @@ void VM_loadfromfile(void)
        }
 
        // not conform with VM_fopen
-       data = FS_LoadFile(filename, tempmempool, false);
+       data = (char *)FS_LoadFile(filename, tempmempool, false);
        if (data == NULL)
                PRVM_G_FLOAT(OFS_RETURN) = -1;
 
@@ -2695,7 +2682,7 @@ void VM_cin_setstate( void )
        name = PRVM_G_STRING( OFS_PARM0 );
        VM_CheckEmptyString( name );
 
-       state = PRVM_G_FLOAT( OFS_PARM1 );
+       state = (clvideostate_t)PRVM_G_FLOAT( OFS_PARM1 );
 
        video = CL_GetVideo( name );
        if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )