]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
patch from Spike which makes getstati accept 3 parameters to extract a
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 17 Jun 2007 07:19:59 +0000 (07:19 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 17 Jun 2007 07:19:59 +0000 (07:19 +0000)
shifted bit range from a stat

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

clvm_cmds.c

index c40d668f10354a8cd3bf3439ed45992bd1eb679b..9d7d73dd1f3537ab6f587775ccd67eacae65e30f 100644 (file)
@@ -850,8 +850,24 @@ static void VM_CL_getstatf (void)
 static void VM_CL_getstati (void)
 {
        int i, index;
-       VM_SAFEPARMCOUNT(1, VM_CL_getstati);
+       int firstbit, bitcount;
+
+       VM_SAFEPARMCOUNTRANGE(1, 3, VM_CL_getstati);
+
        index = (int)PRVM_G_FLOAT(OFS_PARM0);
+       if (prog->argc > 1)
+       {
+               firstbit = (int)PRVM_G_FLOAT(OFS_PARM1);
+               if (prog->argc > 2)
+                       bitcount = (int)PRVM_G_FLOAT(OFS_PARM2);
+               else
+                       bitcount = 1;
+       }
+       else
+       {
+               firstbit = 0;
+               bitcount = 32;
+       }
 
        if(index < 0 || index >= MAX_CL_STATS)
        {
@@ -859,6 +875,8 @@ static void VM_CL_getstati (void)
                return;
        }
        i = cl.stats[index];
+       if (bitcount != 32)     //32 causes the mask to overflow, so there's nothing to subtract from.
+               i = (((unsigned int)i)&(((1<<bitcount)-1)<<firstbit))>>firstbit;
        PRVM_G_FLOAT(OFS_RETURN) = i;
 }