]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
qc_vlen, and adding numbers to all builtins for clarity
authorWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 22 Aug 2012 13:39:15 +0000 (15:39 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 22 Aug 2012 13:39:15 +0000 (15:39 +0200)
exec.c

diff --git a/exec.c b/exec.c
index 52ce15e0529e04cfd059f9931242b1ccafb3fbd8..fdff7870eec0d85824735f511001c21fa0a04e36 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -610,6 +610,8 @@ cleanup:
  */
 
 #if defined(QCVM_EXECUTOR)
+#include <math.h>
+
 const char *type_name[TYPE_COUNT] = {
     "void",
     "string",
@@ -703,14 +705,27 @@ static int qc_kill(qc_program *prog)
     return 0;
 }
 
+static int qc_vlen(qc_program *prog)
+{
+    qcany *vec, len;
+    CheckArgs(1);
+    vec = GetArg(0);
+    len._float = sqrt(vec->vector[0] * vec->vector[0] + 
+                      vec->vector[1] * vec->vector[1] +
+                      vec->vector[2] * vec->vector[2]);
+    Return(len);
+    return 0;
+}
+
 static prog_builtin qc_builtins[] = {
     NULL,
-    &qc_print,
-    &qc_ftos,
-    &qc_spawn,
-    &qc_kill,
-    &qc_vtos,
-    &qc_error
+    &qc_print, /*   1   */
+    &qc_ftos,  /*   2   */
+    &qc_spawn, /*   3   */
+    &qc_kill,  /*   4   */
+    &qc_vtos,  /*   5   */
+    &qc_error, /*   6   */
+    &qc_vlen   /*   7   */
 };
 static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);