]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Support for $modelname and $framerestore
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 19:02:56 +0000 (21:02 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 19:02:56 +0000 (21:02 +0200)
data/parsing.qc
lexer.c
lexer.h

index f75a136da9fda7bd61581d7de7be167404f33582..3c039e58f23b794530b426f101ad987f3cb47d9c 100644 (file)
@@ -11,8 +11,12 @@ void(entity)        kill   = #4;
 .float mema;
 .float memb;
 
-$framevalue 37
-$frame stand1 stand2 stand3
+$framevalue 0
+$frame stand1 stand2 standX
+$framerestore stand2
+$frame stand3
+$modelname foobar
+$modelname foobar3
 
 void() main = {
     entity pawn;
diff --git a/lexer.c b/lexer.c
index 5042c03f5ef941894e3dc714ef41e836fe2545e1..9bf460ac950041e140289455b6bc2beb8024295d 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -387,8 +387,9 @@ static bool lex_finish_frames(lex_file *lex)
             return false;
 
         m.value = lex->framevalue++;
-        m.name = util_strdup(lex->tok->value);
-        if (!m.name || !lex_file_frames_add(lex, m)) {
+        m.name = lex->tok->value;
+        lex->tok->value = NULL;
+        if (!lex_file_frames_add(lex, m)) {
             lexerror(lex, "out of memory");
             return false;
         }
@@ -594,6 +595,71 @@ int lex_do(lex_file *lex)
             return lex_do(lex);
         }
 
+        if (!strcmp(v, "framerestore"))
+        {
+            int rc;
+
+                   token_delete(lex->tok);
+               lex->tok = token_new();
+
+            rc = lex_parse_frame(lex);
+
+            if (rc > 0) {
+                lexerror(lex, "$framerestore requires a framename parameter");
+                return lex_do(lex);
+            }
+            if (rc < 0)
+                return (lex->tok->ttype = TOKEN_FATAL);
+
+            v = lex->tok->value;
+            for (frame = 0; frame < lex->frames_count; ++frame) {
+                if (!strcmp(v, lex->frames[frame].name)) {
+                    lex->framevalue = lex->frames[frame].value;
+                    return lex_do(lex);
+                }
+            }
+            lexerror(lex, "unknown framename `%s`", v);
+            return lex_do(lex);
+        }
+
+        if (!strcmp(v, "modelname"))
+        {
+            int rc;
+
+                   token_delete(lex->tok);
+               lex->tok = token_new();
+
+            rc = lex_parse_frame(lex);
+
+            if (rc > 0) {
+                lexerror(lex, "$framerestore requires a framename parameter");
+                return lex_do(lex);
+            }
+            if (rc < 0)
+                return (lex->tok->ttype = TOKEN_FATAL);
+
+            v = lex->tok->value;
+            if (lex->modelname) {
+                frame_macro m;
+                m.value = lex->framevalue;
+                m.name = lex->modelname;
+                lex->modelname = NULL;
+                if (!lex_file_frames_add(lex, m)) {
+                    lexerror(lex, "out of memory");
+                    return (lex->tok->ttype = TOKEN_FATAL);
+                }
+            }
+            lex->modelname = lex->tok->value;
+            lex->tok->value = NULL;
+            for (frame = 0; frame < lex->frames_count; ++frame) {
+                if (!strcmp(v, lex->frames[frame].name)) {
+                    lex->framevalue = lex->frames[frame].value;
+                    break;
+                }
+            }
+            return lex_do(lex);
+        }
+
         if (!strcmp(v, "flush"))
         {
             size_t frame;
diff --git a/lexer.h b/lexer.h
index 261fdf9dca93fe8bd3128ab6a869864bd8971f72..7389ba3f8a4b3856974340da3f1f31e86afac835 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -103,6 +103,7 @@ typedef struct {
 
     int framevalue;
        MEM_VECTOR_MAKE(frame_macro, frames);
+       char *modelname;
 } lex_file;
 
 MEM_VECTOR_PROTO(lex_file, char, token);