]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
faster surface culling check in light processing
[xonotic/darkplaces.git] / prvm_cmds.c
index 5ed34b794a1958a3ceb27eeba91e7121ab76169f..5d3650421bc7a819df64cf07788f2ada940aef61 100644 (file)
@@ -25,7 +25,7 @@ void VM_Warning(const char *fmt, ...)
        dpvsnprintf(msg,sizeof(msg),fmt,argptr);
        va_end(argptr);
 
-       Con_Print(msg);
+       Con_DPrint(msg);
 
        // TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Con_Printf [9/13/2006 Black]
        if(prvm_backtraceforwarnings.integer && recursive != realtime) // NOTE: this compares to the time, just in case if PRVM_PrintState causes a Host_Error and keeps recursive set
@@ -204,19 +204,19 @@ void VM_UpdateEdictSkeleton(prvm_edict_t *ed, const dp_model_t *edmodel, const f
                        int blendindex;
                        int bonenum;
                        int numbones = ed->priv.server->skeleton.model->num_bones;
-                       const float *poses = ed->priv.server->skeleton.model->data_poses;
-                       const float *framebones;
+                       const short *framebones6s;
                        float lerp;
+                       float scale = ed->priv.server->skeleton.model->num_posescale;
                        matrix4x4_t *relativetransforms = ed->priv.server->skeleton.relativetransforms;
                        matrix4x4_t matrix;
                        memset(relativetransforms, 0, numbones * sizeof(matrix4x4_t));
                        for (blendindex = 0;blendindex < MAX_FRAMEBLENDS && frameblend[blendindex].lerp > 0;blendindex++)
                        {
                                lerp = frameblend[blendindex].lerp;
-                               framebones = poses + 12 * frameblend[blendindex].subframe * numbones;
+                               framebones6s = ed->priv.server->skeleton.model->data_poses6s + 6 * frameblend[blendindex].subframe * numbones;
                                for (bonenum = 0;bonenum < numbones;bonenum++)
                                {
-                                       Matrix4x4_FromArray12FloatD3D(&matrix, framebones + 12 * bonenum);
+                                       Matrix4x4_FromBonePose6s(&matrix, scale, framebones6s + 6 * bonenum);
                                        Matrix4x4_Accumulate(&ed->priv.server->skeleton.relativetransforms[bonenum], &matrix, lerp);
                                }
                        }
@@ -744,15 +744,12 @@ void VM_dprint (void)
 {
        char string[VM_STRINGTEMP_LENGTH];
        VM_SAFEPARMCOUNTRANGE(1, 8, VM_dprint);
-       if (developer.integer)
-       {
-               VM_VarString(0, string, sizeof(string));
+       VM_VarString(0, string, sizeof(string));
 #if 1
-               Con_Printf("%s", string);
+       Con_DPrintf("%s", string);
 #else
-               Con_Printf("%s: %s", PRVM_NAME, string);
+       Con_DPrintf("%s: %s", PRVM_NAME, string);
 #endif
-       }
 }
 
 /*
@@ -974,12 +971,12 @@ void VM_remove (void)
        ed = PRVM_G_EDICT(OFS_PARM0);
        if( PRVM_NUM_FOR_EDICT(ed) <= prog->reserved_edicts )
        {
-               if (developer.integer >= 1)
+               if (developer.integer)
                        VM_Warning( "VM_remove: tried to remove the null entity or a reserved entity!\n" );
        }
        else if( ed->priv.required->free )
        {
-               if (developer.integer >= 1)
+               if (developer.integer)
                        VM_Warning( "VM_remove: tried to remove an already freed entity!\n" );
        }
        else
@@ -1845,14 +1842,14 @@ void VM_fopen(void)
        if (prog->openfiles[filenum] == NULL)
        {
                PRVM_G_FLOAT(OFS_RETURN) = -1;
-               if (developer.integer >= 100)
+               if (developer_extra.integer)
                        VM_Warning("VM_fopen: %s: %s mode %s failed\n", PRVM_NAME, filename, modestring);
        }
        else
        {
                PRVM_G_FLOAT(OFS_RETURN) = filenum;
-               if (developer.integer >= 100)
-                       Con_Printf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
+               if (developer_extra.integer)
+                       Con_DPrintf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
                prog->openfiles_origin[filenum] = PRVM_AllocationOrigin();
        }
 }
@@ -1886,8 +1883,8 @@ void VM_fclose(void)
        prog->openfiles[filenum] = NULL;
        if(prog->openfiles_origin[filenum])
                PRVM_Free((char *)prog->openfiles_origin[filenum]);
-       if (developer.integer >= 100)
-               Con_Printf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
+       if (developer_extra.integer)
+               Con_DPrintf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
 }
 
 /*
@@ -1937,8 +1934,8 @@ void VM_fgets(void)
                if (c != '\n')
                        FS_UnGetc(prog->openfiles[filenum], (unsigned char)c);
        }
-       if (developer.integer >= 100)
-               Con_Printf("fgets: %s: %s\n", PRVM_NAME, string);
+       if (developer_extra.integer)
+               Con_DPrintf("fgets: %s: %s\n", PRVM_NAME, string);
        if (c >= 0 || end)
                PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(string);
 }
@@ -1973,8 +1970,8 @@ void VM_fputs(void)
        VM_VarString(1, string, sizeof(string));
        if ((stringlength = (int)strlen(string)))
                FS_Write(prog->openfiles[filenum], string, stringlength);
-       if (developer.integer >= 100)
-               Con_Printf("fputs: %s: %s\n", PRVM_NAME, string);
+       if (developer_extra.integer)
+               Con_DPrintf("fputs: %s: %s\n", PRVM_NAME, string);
 }
 
 /*
@@ -3151,8 +3148,6 @@ void VM_chr(void)
        VM_SAFEPARMCOUNT(1, VM_chr);
 
        len = u8_fromchar((Uchar)PRVM_G_FLOAT(OFS_PARM0), tmp, sizeof(tmp));
-       if (len < 0)
-               len = 0;
        tmp[len] = 0;
        PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(tmp);
 }
@@ -3290,7 +3285,7 @@ void VM_drawcharacter(void)
        }
 
        getdrawfontscale(&sx, &sy);
-       DrawQ_String_Font_Scale(pos[0], pos[1], &character, 1, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
+       DrawQ_String_Scale(pos[0], pos[1], &character, 1, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 
@@ -3333,7 +3328,7 @@ void VM_drawstring(void)
                Con_Printf("VM_drawstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
 
        getdrawfontscale(&sx, &sy);
-       DrawQ_String_Font_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
+       DrawQ_String_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
        //Font_DrawString(pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
@@ -3377,7 +3372,7 @@ void VM_drawcolorcodedstring(void)
 
        color = -1;
        getdrawfontscale(&sx, &sy);
-       DrawQ_String_Font_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
+       DrawQ_String_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 /*
@@ -3421,7 +3416,7 @@ void VM_stringwidth(void)
        string = PRVM_G_STRING(OFS_PARM0);
        colors = (int)PRVM_G_FLOAT(OFS_PARM1);
 
-       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(string, szv[0], szv[1], sx, sy, &maxlen, NULL, !colors, getdrawfont(), 1000000000) * mult; // 1x1 characters, don't actually draw
+       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_UntilWidth_TrackColors_Scale(string, &maxlen, szv[0], szv[1], sx, sy, NULL, !colors, getdrawfont(), 1000000000) * mult;
 /*
        if(prog->argc == 3)
        {
@@ -3436,7 +3431,7 @@ void VM_stringwidth(void)
        string = PRVM_G_STRING(OFS_PARM0);
        colors = (int)PRVM_G_FLOAT(OFS_PARM1);
 
-       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_Font(string, 0, !colors, getdrawfont()) * mult; // 1x1 characters, don't actually draw
+       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth(string, 0, !colors, getdrawfont()) * mult; // 1x1 characters, don't actually draw
 */
 
 }
@@ -5062,7 +5057,10 @@ void VM_str2chr (void)
 
        if((unsigned)index < strlen(s))
        {
-               ch = u8_getchar(s + index, NULL);
+               if (utf8_enable.integer)
+                       ch = u8_getchar_noendptr(s + index);
+               else
+                       ch = (unsigned char)s[index];
                PRVM_G_FLOAT(OFS_RETURN) = ch;
        }
        else
@@ -5086,11 +5084,7 @@ void VM_chr2str (void)
        size_t len = 0;
        VM_SAFEPARMCOUNTRANGE(0, 8, VM_chr2str);
        for(i = 0; i < prog->argc && len < sizeof(t)-1; ++i)
-       {
-               int add = u8_fromchar((Uchar)PRVM_G_FLOAT(OFS_PARM0+i*3), t + len, sizeof(t)-1);
-               if(add > 0)
-                       len += add;
-       }
+               len += u8_fromchar((Uchar)PRVM_G_FLOAT(OFS_PARM0+i*3), t + len, sizeof(t)-1);
        t[len] = 0;
        PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(t);
 }
@@ -5609,7 +5603,7 @@ void VM_CL_getextresponse (void)
                int first;
                --cl_net_extresponse_count;
                first = (cl_net_extresponse_last + NET_EXTRESPONSE_MAX - cl_net_extresponse_count) % NET_EXTRESPONSE_MAX;
-               PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl_net_extresponse[first]);
+               PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(cl_net_extresponse[first]);
        }
 }
 
@@ -5624,7 +5618,7 @@ void VM_SV_getextresponse (void)
                int first;
                --sv_net_extresponse_count;
                first = (sv_net_extresponse_last + NET_EXTRESPONSE_MAX - sv_net_extresponse_count) % NET_EXTRESPONSE_MAX;
-               PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(sv_net_extresponse[first]);
+               PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(sv_net_extresponse[first]);
        }
 }
 
@@ -5811,6 +5805,11 @@ noflags:
                                                else
                                                        width = argpos++;
                                                width = GETARG_FLOAT(width);
+                                               if(width < 0)
+                                               {
+                                                       flags |= PRINTF_LEFT;
+                                                       width = -width;
+                                               }
                                        }
                                        else if(*s >= '0' && *s <= '9')
                                        {
@@ -5821,12 +5820,13 @@ noflags:
                                                        goto finished;
                                                }
                                                s = err;
+                                               if(width < 0)
+                                               {
+                                                       flags |= PRINTF_LEFT;
+                                                       width = -width;
+                                               }
                                        }
-                                       if(width < 0)
-                                       {
-                                               flags |= PRINTF_LEFT;
-                                               width = -width;
-                                       }
+                                       // otherwise width stays -1
                                }
 
                                if(*s == '.')
@@ -5902,24 +5902,28 @@ nolength:
                                        *f++ = *s;
                                        *f++ = 0;
 
-                                       if(width < 0)
+                                       if(width < 0) // not set
                                                width = 0;
 
                                        switch(*s)
                                        {
                                                case 'd': case 'i':
+                                                       if(precision < 0) // not set
+                                                               precision = 1;
                                                        o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (int) GETARG_FLOAT(thisarg) : (int) GETARG_INT(thisarg)));
                                                        break;
                                                case 'o': case 'u': case 'x': case 'X':
+                                                       if(precision < 0) // not set
+                                                               precision = 1;
                                                        o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (unsigned int) GETARG_FLOAT(thisarg) : (unsigned int) GETARG_INT(thisarg)));
                                                        break;
                                                case 'e': case 'E': case 'f': case 'F': case 'g': case 'G':
-                                                       if(precision < 0)
+                                                       if(precision < 0) // not set
                                                                precision = 6;
                                                        o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (double) GETARG_FLOAT(thisarg) : (double) GETARG_INT(thisarg)));
                                                        break;
                                                case 'c':
-                                                       if(precision < 0)
+                                                       if(precision < 0) // not set
                                                                precision = end - o - 1;
                                                        if(flags & PRINTF_ALTERNATE)
                                                                o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (unsigned int) GETARG_FLOAT(thisarg) : (unsigned int) GETARG_INT(thisarg)));
@@ -5933,7 +5937,7 @@ nolength:
                                                        }
                                                        break;
                                                case 's':
-                                                       if(precision < 0)
+                                                       if(precision < 0) // not set
                                                                precision = end - o - 1;
                                                        if(flags & PRINTF_ALTERNATE)
                                                                o += dpsnprintf(o, end - o, formatbuf, width, precision, GETARG_STRING(thisarg));