Support for $modelname and $framerestore

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-16 21:02:56 +02:00
parent 3b9a6b3ace
commit 076503770d
3 changed files with 75 additions and 4 deletions

View 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;

70
lexer.c
View file

@ -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;

View file

@ -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);