From: Wolfgang (Blub) Bumiller Date: Thu, 16 Aug 2012 19:02:56 +0000 (+0200) Subject: Support for $modelname and $framerestore X-Git-Tag: 0.1-rc1~236 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=076503770d79dae16484e7dda3ba165573e6e877;p=xonotic%2Fgmqcc.git Support for $modelname and $framerestore --- diff --git a/data/parsing.qc b/data/parsing.qc index f75a136..3c039e5 100644 --- a/data/parsing.qc +++ b/data/parsing.qc @@ -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 5042c03..9bf460a 100644 --- 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 261fdf9..7389ba3 100644 --- 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);