]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
patch from Dresk for DP_QC_STRINGCOLORFUNCTIONS extension (strlennocol measures lengt...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 24 Nov 2006 22:55:08 +0000 (22:55 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 24 Nov 2006 22:55:08 +0000 (22:55 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6626 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h
svvm_cmds.c

index 4e284d21e9043daeb278ed18fe4049f4f0227757..cc7130b81f1973337a156c5cfb2758c692578789 100644 (file)
@@ -68,6 +68,7 @@ char *vm_cl_extensions =
 "DP_QC_RANDOMVEC "
 "DP_QC_SINCOSSQRTPOW "
 //"DP_QC_STRINGBUFFERS "       //[515]: not needed ?
 "DP_QC_RANDOMVEC "
 "DP_QC_SINCOSSQRTPOW "
 //"DP_QC_STRINGBUFFERS "       //[515]: not needed ?
+"DP_QC_STRINGCOLORFUNCTIONS "
 "DP_QC_TRACEBOX "
 //"DP_QC_TRACETOSS "
 "DP_QC_TRACE_MOVETYPE_HITMODEL "
 "DP_QC_TRACEBOX "
 //"DP_QC_TRACETOSS "
 "DP_QC_TRACE_MOVETYPE_HITMODEL "
@@ -2729,8 +2730,8 @@ VM_acos,                                  // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan,                                       // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
 VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan,                                       // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
 VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
-NULL,                                          // #476
-NULL,                                          // #477
+VM_strlennocol,                                // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
+VM_strdecolorize,                      // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
 NULL,                                          // #478
 NULL,                                          // #479
 e10, e10                       // #480-499 (LordHavoc)
 NULL,                                          // #478
 NULL,                                          // #479
 e10, e10                       // #480-499 (LordHavoc)
index 43919655a50c77cb0f21a3b734a4b95c7e3d637a..19f3ced7b7d422dd639b8182b6e6bd131db28c37 100644 (file)
@@ -5,7 +5,8 @@
 
 char *vm_m_extensions =
 "DP_CINEMATIC_DPV "
 
 char *vm_m_extensions =
 "DP_CINEMATIC_DPV "
-"DP_QC_ASINACOSATANATAN2TAN";
+"DP_QC_ASINACOSATANATAN2TAN "
+"DP_QC_STRINGCOLORFUNCTIONS";
 
 /*
 =========
 
 /*
 =========
@@ -916,7 +917,9 @@ prvm_builtin_t vm_m_builtins[] = {
        VM_atan,                                        // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
        VM_atan2,                                       // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
        VM_tan,                                         // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
        VM_atan,                                        // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
        VM_atan2,                                       // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
        VM_tan,                                         // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
-       0,0,0,0,0,                      // 480
+       VM_strlennocol,                         // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
+       VM_strdecolorize,                       // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
+       0,0,0,                  // 480
        e10,                    // 490
        e10,                    // 500
        e100,                   // 600
        e10,                    // 490
        e10,                    // 500
        e100,                   // 600
index bca257373edf300d7ce4733b202d7ee5d975d008..b78d2e75eda43b1c6e24ab9f65cda3190dc27e90 100644 (file)
@@ -1787,6 +1787,138 @@ void VM_strlen(void)
                PRVM_G_FLOAT(OFS_RETURN) = 0;
 }
 
                PRVM_G_FLOAT(OFS_RETURN) = 0;
 }
 
+// DRESK - Decolorized String
+/*
+=========
+VM_strdecolorize
+
+string strdecolorize(string s)
+=========
+*/
+// string (string s) strdecolorize = #472; // returns the passed in string with color codes stripped
+void VM_strdecolorize(void)
+{
+       char *szNewString;
+       const char *szString;
+       size_t nCnt;
+       int nPos;
+       int nFillPos;
+       int bFinished;
+               nPos = 0;
+               nFillPos = 0;
+               nCnt = 0;
+               bFinished = 0;
+
+       // Prepare Strings
+       VM_SAFEPARMCOUNT(1,VM_strdecolorize);
+       szString = PRVM_G_STRING(OFS_PARM0);
+       szNewString = VM_GetTempString();
+
+       while(!bFinished)
+       { // Traverse through String
+               if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
+               { // String End Found
+                       szNewString[nFillPos++] = szString[nPos];
+                       bFinished = 1;
+               }
+               else
+               if( szString[nPos] == STRING_COLOR_TAG)
+               { // Color Code Located
+                       if( szString[nPos + 1] == STRING_COLOR_TAG)
+                       { // Valid Characters to Include
+                               szNewString[nFillPos++] = szString[nPos];
+                               nPos = nPos + 1;
+                               szNewString[nFillPos++] = szString[nPos];
+                       }
+                       else
+                       if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
+                       { // Color Code Found; Increment Position
+                               nPos = nPos + 1;
+                       }
+                       else
+                       { // Unknown Color Code; Include
+                               szNewString[nFillPos++] = szString[nPos];
+                               nPos = nPos + 1;
+                       }
+               }
+               else
+                       // Include Character
+                       szNewString[nFillPos++] = szString[nPos];
+
+                       // Increment Position
+                       nPos = nPos + 1;
+       }
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(szNewString);
+}
+
+// DRESK - String Length (not counting color codes)
+/*
+=========
+VM_strlennocol
+
+float  strlennocol(string s)
+=========
+*/
+// float(string s) strlennocol = #471; // returns how many characters are in a string not including color codes
+// For example, ^2Dresk returns a length of 5
+void VM_strlennocol(void)
+{
+       const char *szString;
+       size_t nCnt;
+       int nPos;
+       int bFinished;
+               nPos = 0;
+               nCnt = 0;
+               bFinished = 0;
+
+       VM_SAFEPARMCOUNT(1,VM_strlennocol);
+
+       szString = PRVM_G_STRING(OFS_PARM0);
+       if(szString)
+       { // Valid String
+               while(!bFinished)
+               { // Count Characters
+                       // SV_BroadcastPrintf("Position '%d'; Character '%c'; Length '%d'\n", nPos, szString[nPos], nCnt);
+
+                       if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
+                       { // String End Found
+                               // SV_BroadcastPrintf("Found End of String at '%d'\n", nPos);
+                               bFinished = 1;
+                       }
+                       else
+                       if( szString[nPos] == STRING_COLOR_TAG)
+                       { // Color Code Located
+                               if( szString[nPos + 1] == STRING_COLOR_TAG)
+                               { // Increment Length; Skip Color Code
+                                       nCnt = nCnt + 1;
+                                       nPos = nPos + 1;
+                               }
+                               else
+                               if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
+                               { // Color Code Found; Increment Position
+                                       // SV_BroadcastPrintf("Found Color Codes at '%d'\n", nPos);
+                                       nPos = nPos + 1;
+                               }
+                               else
+                               { // Unknown Color Code; Increment Length!
+                                       nPos = nPos + 1;
+                                       nCnt = nCnt + 1;
+                               }
+                       }
+                       else
+                               // Increment String Length
+                               nCnt = nCnt + 1;
+
+                       // Increment Position
+                       nPos = nPos + 1;
+               }
+               PRVM_G_FLOAT(OFS_RETURN) = nCnt;
+       }
+       else
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+}
+
 /*
 =========
 VM_strcat
 /*
 =========
 VM_strcat
index 2cc2a89019ef647ba9a42009cd0a79badf28c1ce..562fe586d9ccf8caecf6b60141166ae910d83ad8 100644 (file)
@@ -294,6 +294,11 @@ void VM_stov(void);
 void VM_strzone(void);
 void VM_strunzone(void);
 
 void VM_strzone(void);
 void VM_strunzone(void);
 
+// DRESK - String Length (not counting color codes)
+void VM_strlennocol(void);
+// DRESK - Decolorized String
+void VM_strdecolorize(void);
+
 void VM_clcommand (void);
 
 void VM_tokenize (void);
 void VM_clcommand (void);
 
 void VM_tokenize (void);
index 1bf84cb50da1fd4a4786b7711c5d380bc10749ea..89760f551885a1ab34e2fc1fbb994262f451500c 100644 (file)
@@ -67,6 +67,7 @@ char *vm_sv_extensions =
 "DP_QC_RANDOMVEC "
 "DP_QC_SINCOSSQRTPOW "
 "DP_QC_STRINGBUFFERS "
 "DP_QC_RANDOMVEC "
 "DP_QC_SINCOSSQRTPOW "
 "DP_QC_STRINGBUFFERS "
+"DP_QC_STRINGCOLORFUNCTIONS "
 "DP_QC_TRACEBOX "
 "DP_QC_TRACETOSS "
 "DP_QC_TRACE_MOVETYPE_HITMODEL "
 "DP_QC_TRACEBOX "
 "DP_QC_TRACETOSS "
 "DP_QC_TRACE_MOVETYPE_HITMODEL "
@@ -2856,8 +2857,8 @@ VM_acos,                                  // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan,                                       // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
 VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan,                                       // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
 VM_atan2,                                      // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
 VM_tan,                                                // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
-NULL,                                          // #476
-NULL,                                          // #477
+VM_strlennocol,                                // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
+VM_strdecolorize,                      // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
 NULL,                                          // #478
 NULL,                                          // #479
 e10, e10                                       // #480-499 (LordHavoc)
 NULL,                                          // #478
 NULL,                                          // #479
 e10, e10                                       // #480-499 (LordHavoc)