int CInterpreter::GetVariable( int type ) { const char *varName; variable_t *var; CToken *token; //Get the variable's name token = m_tokenizer->GetToken( 0, 0 ); varName = token->GetStringValue(); //See if we already have a variable by this name var = FindVar( varName ); //Variable names must be unique on creation if ( var ) return Error( "\"%s\" : already exists\n", varName ); //Add the variable AddVar( varName, type ); //Insert the variable into the stream CBlock block; block.Create( TYPE_VARIABLE ); block.Write( TK_FLOAT, (float) type ); block.Write( TK_STRING, varName ); m_blockStream->WriteBlock( &block ); token->Delete(); return true; }
int CInterpreter::GetLoop( void ) { CBlock block; block.Create( ID_LOOP ); if (!Match( TK_OPEN_PARENTHESIS )) return Error("syntax error : '(' not found"); if ( LookAhead( TK_CLOSED_PARENTHESIS ) ) { //-1 denotes an infinite loop block.Write( TK_FLOAT, (float) -1); } else { if ( GetInteger( &block ) == false ) return false; } if (!Match( TK_CLOSED_PARENTHESIS )) return Error("GetLoop : too many parameters"); m_blockStream->WriteBlock( &block ); return true; }
int CInterpreter::GetAffect( void ) { CBlock block; char typeName[MAX_STRING_SIZE]; int type; block.Create( ID_AFFECT ); if (!Match( TK_OPEN_PARENTHESIS )) return Error("syntax error : '(' not found"); if ( GetString( &block ) == false ) return false; if (!LookAhead( TK_IDENTIFIER )) return Error("syntax error : identifier not found"); if ( MatchGet() ) return Error("syntax error : illegal use of \"get\""); if ( GetType( (char *) typeName ) == false ) return false; type = FindSymbol( typeName, m_typeKeywords); switch ( type ) { case TYPE_INSERT: case TYPE_FLUSH: block.Write( TK_FLOAT, (float) type ); break; default: return Error("'%s': unknown affect type", typeName ); break; } if (!Match( TK_CLOSED_PARENTHESIS )) return Error("affect : too many parameters"); if (!LookAhead( TK_BLOCK_START )) return Error("syntax error : '{' not found"); m_blockStream->WriteBlock( &block ); return true; }
int CInterpreter::GetDeclare( void ) { CBlock block; char typeName[MAX_STRING_LENGTH]; int type; block.Create( ID_DECLARE ); if (!Match( TK_OPEN_PARENTHESIS )) return Error("syntax error : '(' not found"); if ( GetType( (char *) typeName ) == false ) return false; type = FindSymbol( typeName, m_typeKeywords); switch ( type ) { case TK_FLOAT: case TK_VECTOR: case TK_STRING: block.Write( TK_FLOAT, (float) type ); break; default: return Error("unknown identifier %s", typeName ); break; } if ( GetString( &block ) == false ) return false; if (!Match( TK_CLOSED_PARENTHESIS )) return Error("declare : too many parameters"); m_blockStream->WriteBlock( &block ); return true; }
int CInterpreter::GetCamera( void ) { CBlock block; char typeName[MAX_STRING_SIZE]; int type; block.Create( ID_CAMERA ); if (!Match( TK_OPEN_PARENTHESIS )) return Error("syntax error : '(' not found"); if ( GetType( (char *) typeName ) == false ) return false; type = FindSymbol( typeName, m_typeKeywords); switch ( type ) { case TYPE_PAN: //PAN ( ANGLES, DURATION ) block.Write( TK_FLOAT, (float) type ); if ( GetVector( &block ) == false ) return false; if ( GetVector( &block ) == false ) return false; if ( GetFloat( &block ) == false ) return false; break; case TYPE_ZOOM: //ZOOM ( FOV, DURATION ) block.Write( TK_FLOAT, (float) type ); if ( GetFloat( &block ) == false ) return false; if ( GetFloat( &block ) == false ) return false; break; case TYPE_MOVE: //MOVE ( ORIGIN, DURATION ) block.Write( TK_FLOAT, (float) type ); if ( GetVector( &block ) == false ) return false; if ( GetFloat( &block ) == false ) return false; break; case TYPE_FADE: //FADE ( SOURCE(R,G,B,A), DEST(R,G,B,A), DURATION ) block.Write( TK_FLOAT, (float) type ); //Source color if ( GetVector( &block ) == false ) return false; if ( GetFloat( &block ) == false ) return false; //Dest color if ( GetVector( &block ) == false ) return false; if ( GetFloat( &block ) == false ) return false; //Duration if ( GetFloat( &block ) == false ) return false; break; case TYPE_PATH: //PATH ( FILENAME ) block.Write( TK_FLOAT, (float) type ); //Filename if ( GetString( &block ) == false ) return false; break; case TYPE_ENABLE: case TYPE_DISABLE: block.Write( TK_FLOAT, (float) type ); break; case TYPE_SHAKE: //SHAKE ( INTENSITY, DURATION ) block.Write( TK_FLOAT, (float) type ); //Intensity if ( GetFloat( &block ) == false ) return false; //Duration if ( GetFloat( &block ) == false ) return false; break; case TYPE_ROLL: //ROLL ( ANGLE, TIME ) block.Write( TK_FLOAT, (float) type ); //Angle if ( GetFloat( &block ) == false ) return false; //Time if ( GetFloat( &block ) == false ) return false; break; case TYPE_TRACK: //TRACK ( TARGETNAME, SPEED, INITLERP ) block.Write( TK_FLOAT, (float) type ); //Target name if ( GetString( &block ) == false ) return false; //Speed if ( GetFloat( &block ) == false ) return false; //Init lerp if ( GetFloat( &block ) == false ) return false; break; case TYPE_FOLLOW: //FOLLOW ( CAMERAGROUP, SPEED, INITLERP ) block.Write( TK_FLOAT, (float) type ); //Camera group if ( GetString( &block ) == false ) return false; //Speed if ( GetFloat( &block ) == false ) return false; //Init lerp if ( GetFloat( &block ) == false ) return false; break; case TYPE_DISTANCE: //DISTANCE ( DISTANCE, INITLERP ) block.Write( TK_FLOAT, (float) type ); //Distance if ( GetFloat( &block ) == false ) return false; //Init lerp if ( GetFloat( &block ) == false ) return false; break; } if (!Match( TK_CLOSED_PARENTHESIS )) return Error("camera : too many parameters"); m_blockStream->WriteBlock( &block ); return true; }