void CStateParser::PareseState(CTokenizer &tok,CStateManager &StateManager) { std::string ret; while( !tok.CheckToken("[",false) && !tok.AtEndOfFile() ) { if( tok.CheckToken("type") ) { if( !tok.CheckToken("=") ) throw(CError("expected =")); ret = tok.GetToken(); nController=GetControllerType(ret.c_str(),tok ); } else if ( tok.CheckTokenLike("trigger", false) ) { std::string trigger = tok.GetToken(); if( !tok.CheckToken("=") ) Error("expected =",tok); //fix me add triggerall ParseTrigger(tok,StateManager); if (trigger.compare("triggerall") == 0) { StateManager.AddTriggerToState(TRIGGERALL); } else { //½âÎö³öÊÇÄĸötrigger std::string value = trigger.substr(strlen("trigger"), trigger.length() - strlen("trigger")); StateManager.AddTriggerToState(atoi(value.c_str())); } }/*else if( tok.CheckToken("trigger1") || tok.CheckToken("trigger2") || tok.CheckToken("trigger3") || tok.CheckToken("trigger4") || tok.CheckToken("trigger5") || tok.CheckToken("trigger6") || tok.CheckToken("trigger7") || tok.CheckToken("trigger8") || tok.CheckToken("trigger9") || tok.CheckToken("trigger10") || tok.CheckToken("trigger11") || tok.CheckToken("trigger12") || tok.CheckToken("trigger13") || tok.CheckToken("trigger14") || tok.CheckToken("trigger15") || tok.CheckToken("trigger16") || tok.CheckToken("trigger17") || tok.CheckToken("trigger18") || tok.CheckToken("trigger19") || tok.CheckToken("trigger20")) { if( !tok.CheckToken("=") ) Error("expected =",tok); ParseTrigger(tok,StateManager); StateManager.AddTriggerToState(TRIGGERNUM); }*/ else break; } //parse the controller ParserController(tok,StateManager,nController); StateManager.AddTypeToState(nController); }
// // this actually reads XSI or GLA headers... historical mutation strikes again... // static void ReadASEHeader_Actual(LPCSTR psFilename, int &iStartFrame, int &iFrameCount, int &iFrameSpeed, bool bReadingGLA, bool bCanSkipXSIRead /* = false */) { // since the XSI loader is so damn slow and flakey I'm going to have to cache the info to avoid re-reading... // // do we have it in the cache?... // if (strstr(psFilename,".xsi") || strstr(psFilename,".XSI")) { ASECachedInfo_t::iterator iter = ASECachedInfo.find(psFilename); if (iter != ASECachedInfo.end()) { iStartFrame = 0; iFrameCount = (*iter).second.first; iFrameSpeed = (*iter).second.second; return; } } // is it a GLA file?... // if (bReadingGLA) { char sTemp[1024]; strcpy(sTemp,psFilename); if (!(strstr(psFilename,".gla") || strstr(psFilename,".GLA"))) { strcat(sTemp,".gla"); } iStartFrame = 0; iFrameCount = GLA_ReadHeader(sTemp); iFrameSpeed = 20; // any old value for GLA file return; } // it's not in the cache, but we may be able to avoid having to read it under some circumstances... // bool bXSIShouldBeRead = true; if (gbCarWash_DoingScan) { bCanSkipXSIRead = false; // stop it asking the question bXSIShouldBeRead= gbCarWash_YesToXSIScan; } if ( (strstr(psFilename,".xsi") || strstr(psFilename,".XSI")) && bCanSkipXSIRead ) { if (!gbSkipXSIRead && !gbSkipXSIRead_QuestionAsked) { gbSkipXSIRead_QuestionAsked = true; gbSkipXSIRead = !GetYesNo(va("Model file: \"%s\"\n\n... is an XSI, and they can be damn slow to read in\n\nDo you want to scan all the XSIs?",psFilename)); } bXSIShouldBeRead = !gbSkipXSIRead; } if (strstr(psFilename,".xsi") || strstr(psFilename,".XSI")) { if (bXSIShouldBeRead) { ReadXSIHeader(psFilename, iStartFrame, iFrameCount, iFrameSpeed); if (iFrameCount!=0) { // cache it for future... // ASECachedInfo[psFilename] = FrameCountAndSpeed_t(iFrameCount,iFrameSpeed); } } return; } // it must be an ASE file then instead.... // CTokenizer* tokenizer = CTokenizer::Create(); tokenizer->AddParseFile(psFilename, ((CAssimilateApp*)AfxGetApp())->GetBufferSize()); tokenizer->SetSymbols(CSequence_s_Symbols); tokenizer->SetKeywords(CSequence_s_Keywords); CToken* curToken = tokenizer->GetToken(); while(curToken != NULL) { switch (curToken->GetType()) { case TK_EOF: curToken->Delete(); curToken = NULL; break; case TK_ASTERISK: curToken->Delete(); curToken = tokenizer->GetToken(); switch(curToken->GetType()) { case TK_ASE_FIRSTFRAME: curToken->Delete(); curToken = tokenizer->GetToken(); if (curToken->GetType() == TK_INTEGER) { iStartFrame = curToken->GetIntValue(); curToken->Delete(); curToken = tokenizer->GetToken(); } break; case TK_ASE_LASTFRAME: curToken->Delete(); curToken = tokenizer->GetToken(); if (curToken->GetType() == TK_INTEGER) { iFrameCount = curToken->GetIntValue() + 1; curToken->Delete(); curToken = NULL; // tells outer loop to finish } break; case TK_ASE_FRAMESPEED: curToken->Delete(); curToken = tokenizer->GetToken(); if (curToken->GetType() == TK_INTEGER) { iFrameSpeed = curToken->GetIntValue(); curToken->Delete(); curToken = tokenizer->GetToken(); } break; case TK_EOF: curToken->Delete(); curToken = NULL; break; default: curToken->Delete(); curToken = tokenizer->GetToken(); break; } break; default: curToken->Delete(); curToken = tokenizer->GetToken(); break; } } tokenizer->Delete(); iFrameCount -= iStartFrame; iStartFrame = 0; }
void CStateParser::ParseStateDef(CTokenizer &tok,CStateManager &StateManager) { while( !tok.CheckToken("[",false) && !tok.AtEndOfFile() ) { //parse state type if( tok.CheckToken("type") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); //to get a single char char c=tok.GetToken()[0]; //make sure we use uperchars if(c >= 97) c-=32; switch(c) { case 'S': StateManager.SetStateDefType(stand); break; case 'C': StateManager.SetStateDefType(crouch); break; case 'A': StateManager.SetStateDefType(air); break; case 'L': StateManager.SetStateDefType(liedown); break; case 'U': StateManager.SetStateDefType(untouch); break; default: Error("Unknown statetype",tok); break; } } else if( tok.CheckToken("movetype") ) { if( !tok.CheckToken("=") ) Error("expected '=' in line ",tok); //to get a single char char c=tok.GetToken()[0]; //make sure we use uperchars if(c >= 97) c-=32; switch(c) { case 'A': StateManager.SetStateMoveType(attack); break; case 'I': StateManager.SetStateMoveType(idle); break; case 'H': StateManager.SetStateMoveType(hit); break; case 'U': StateManager.SetStateMoveType(untouch); break; default: Error("Unknown movetype",tok); break; } } else if( tok.CheckToken("physics") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); //to get a single char char c=tok.GetToken()[0]; //make sure we use uperchars if(c >= 97) c-=32; switch(c) { case 'S': StateManager.SetStatePhysicType(stand); break; case 'C': StateManager.SetStatePhysicType(crouch); break; case 'A': StateManager.SetStatePhysicType(air); break; case 'N': StateManager.SetStatePhysicType(none); break; case 'U': StateManager.SetStatePhysicType(untouch); break; default: Error("Unknown physic type",tok); break; } } else if( tok.CheckToken("anim") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if(!tok.CheckTokenIsNumber()) Error("Expected a number for anim",tok); StateManager.SetStateAnim(tok.GetInt()); } else if( tok.CheckToken("velset") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); float x=tok.GetFloat(); if( !tok.CheckToken(",") ) Error("expected ,",tok); float y=tok.GetFloat(); StateManager.SetVelSet(x,y); } else if( tok.CheckToken("ctrl") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if(!tok.CheckTokenIsNumber()) Error("Expected a number for ctrl",tok); StateManager.SetStateCtrl(tok.GetInt()); } else if( tok.CheckToken("poweradd") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if(!tok.CheckTokenIsNumber()) Error("Expected a number for poweradd",tok); StateManager.SetStatePowerAdd(tok.GetInt()); } else if( tok.CheckToken("juggle") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if(!tok.CheckTokenIsNumber()) Error("Expected a number for juggle",tok); StateManager.SetStateJuggle(tok.GetInt()); } else if( tok.CheckToken("facep2") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if( !tok.CheckTokenIsNumber() ) Error("Expected a number for facep2",tok); StateManager.SetStateFaceP2(tok.GetInt()); } else if( tok.CheckToken("hitdefpersist") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if( !tok.CheckTokenIsNumber() ) Error("Expected a number for hitdefpersist",tok); StateManager.SetStateHitDefPresit(tok.GetInt()); } else if( tok.CheckToken("movehitpersist") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if( !tok.CheckTokenIsNumber() ) Error("Expected a number for movehitpersist",tok); StateManager.SetMoveHitPresit(tok.GetInt()); } else if( tok.CheckToken("hitcountpersist") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if( !tok.CheckTokenIsNumber() ) Error("Expected a number for hitcountpersist",tok); StateManager.SetStateHitCounterPresit(tok.GetInt()); } else if( tok.CheckToken("sprpriority") ) { if( !tok.CheckToken("=") ) Error("expected =",tok); if( !tok.CheckTokenIsNumber() ) Error("Expected a number for sprpriority",tok); StateManager.SetSprPriority(tok.GetInt()); }else //faile in statedef { throw(CError("Unknown token at line %s",tok.GetToken())); break; } } }
void CStateParser::ParseStateFile(const char* strFileName,CStateManager &StateManager,CAllocater *a) { //Set pointer to allocater m_pAlloc=a; CTokenizer tok; bool foundState=false; if( !tok.OpenFile(strFileName) ) throw(CError("CStateParser::ParseState: File %s not found",strFileName)); tok.SetIsCaseSensitive(false); tok.SetReturnNegativeSeperatelyFromNumber(false); while( !tok.AtEndOfFile() ) { foundState=false; if( tok.CheckToken("[") ) { if( tok.CheckToken("statedef") ) { foundState=true; if(!tok.CheckTokenIsNumber()) Error("Expected a number in statedef block",tok); StateManager.AddStateDef(tok.GetInt()); //Skip useless stuff while( !tok.AtEndOfLine() ) tok.GetToken(); //parse the state def ParseStateDef(tok,StateManager); } if( tok.CheckToken("state") ) { foundState=true; if(!tok.CheckTokenIsNumber()) Error("Expected a number in state block",tok); int stateno = tok.GetInt(); tok.CheckToken(","); // if(!tok.CheckTokenIsQuotedString() // && !tok.CheckTokenIsNumber()) // Error("Expected a number in state block",tok); std::string str = tok.GetToken(); StateManager.AddState(stateno, str.c_str()); while(!tok.AtEndOfLine()) tok.GetToken(); PareseState(tok,StateManager); } } //skip useless stuff if(!foundState) tok.GetToken(); } tok.CloseFile(); }
//evaluates a primary void CStateParser::Primary(CTokenizer &tok,CStateManager &StateManager) { //a negate operator if( tok.CheckToken("-") ) { //EvaluateExpression(tok,StateManager); Primary(tok,StateManager); StateManager.AddInstruction(OP_NEG,0,"#"); }else if( tok.CheckTokenIsNumber() ) //we have a number { StateManager.AddInstruction(OP_PUSH,tok.GetFloat(),"#"); }else if( tok.CheckTokenIsQuotedString() ) //it is a "quitedstring" { StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); }else if( tok.CheckToken("(") ) //here we have to check a lot of possibilitys { EvaluateExpression(tok,StateManager); if( !tok.CheckToken(")") ) Error("Missing )",tok); }else if( tok.CheckToken("!") ) { Primary(tok,StateManager); StateManager.AddInstruction(OP_NOT,0,"#"); } else //check for a trigger name { std::string ret = tok.GetToken(); int i=GetTriggerType(ret.c_str(),tok); if ( i == OP_Vel - OP_Abs) { if (tok.CheckToken("x")) { StateManager.AddInstruction(OP_Vel,1.0,"#"); } else if (tok.CheckToken("y")) { StateManager.AddInstruction(OP_Vel,0.0,"#"); } }else if ( i == OP_Pos - OP_Abs) { if (tok.CheckToken("x")) { StateManager.AddInstruction(OP_Pos,1.0,"#"); } else if (tok.CheckToken("y")) { StateManager.AddInstruction(OP_Pos,0.0,"#"); } } else if ( i == OP_Const - OP_Abs) { if (!tok.CheckToken("(")) Error("Missing (",tok); StateManager.AddInstruction(OP_Const,0.0,tok.GetToken()); if (!tok.CheckToken(")")) Error("Missing )",tok); } else if ( i == OP_IfElse - OP_Abs) { if (!tok.CheckToken("(")) Error("Missing (",tok); EvaluateExpression(tok,StateManager); if (!tok.CheckToken(",")) Error("Missing ,",tok); Term(tok,StateManager); if (!tok.CheckToken(",")) Error("Missing ,",tok); Term(tok,StateManager); StateManager.AddInstruction(OP_IfElse,0,"#"); if (!tok.CheckToken(")")) Error("Missing )",tok); } else if (i == OP_StateType - OP_Abs) { if (tok.CheckToken("=")) { StateManager.AddInstruction(OP_StateType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_EQUAL,0,"#"); }else if (tok.CheckToken("!=")) { StateManager.AddInstruction(OP_StateType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_NOTEQUAL,0,"#"); } } else if (i == OP_P2StateType - OP_Abs) { if (tok.CheckToken("=")) { StateManager.AddInstruction(OP_P2StateType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_EQUAL,0,"#"); }else if (tok.CheckToken("!=")) { StateManager.AddInstruction(OP_P2StateType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_NOTEQUAL,0,"#"); } } else if (i == OP_P2MoveType - OP_Abs) { if (tok.CheckToken("=")) { StateManager.AddInstruction(OP_P2MoveType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_EQUAL,0,"#"); }else if (tok.CheckToken("!=")) { StateManager.AddInstruction(OP_P2MoveType,0,"#"); StateManager.AddInstruction(OP_PUSH,0,tok.GetToken()); StateManager.AddInstruction(OP_NOTEQUAL,0,"#"); } } else if (i == OP_GetHitVar - OP_Abs) { if (!tok.CheckToken("(")) Error("Missing (",tok); StateManager.AddInstruction(OP_GetHitVar,0,tok.GetToken()); if (!tok.CheckToken(")")) Error("Missing )",tok); } else if (i == OP_HitDefAttr - OP_Abs) { while (!tok.AtEndOfLine()) tok.GetToken(); } else if (i == OP_P2BodyDist - OP_Abs) { while (!tok.AtEndOfLine()) tok.GetToken(); } else { StateManager.AddInstruction(i+OP_Abs,0,"#"); } } }
bool CCmdManager::LoadCMDFile( const char* file ) { int defaultCommandTime = 15; int defaultBufferTime = 1; m_CommandCount = 0; CTokenizer tok; //changed this to throw a exception if( !tok.OpenFile( file ) ) { throw(CError("CCmdManager::LoadCMDFile : Can't open %s",file)); return false; } // get count first to set up memory while( !tok.AtEndOfFile() ) { bool foundSomething = false; if( tok.CheckToken( "command.time" ) ) { foundSomething = true; if( !tok.CheckToken( "=" ) ) { } if( tok.CheckTokenIsNumber() ) { defaultCommandTime = tok.GetInt(); } } if( tok.CheckToken( "command.buffer.time" ) ) { foundSomething = true; if( !tok.CheckToken( "=" ) ) { } if( tok.CheckTokenIsNumber() ) { defaultBufferTime = tok.GetInt(); } } if( tok.CheckToken( "[" ) ) { foundSomething = true; if( tok.CheckToken( "Command" ) ) { if( tok.CheckToken( "]" ) ) { m_CommandCount++; } } } if( !foundSomething ) { tok.GetToken(); // skip it } } tok.CloseFile(); if( !tok.OpenFile( file ) ) return false; m_Commands = new PLCOMMAND[ m_CommandCount ]; PLCOMMAND* command = m_Commands; while( !tok.AtEndOfFile() ) { bool foundCommand = false; if( tok.CheckToken( "[" ) ) { if( tok.CheckToken( "Command" ) ) { if( !tok.CheckToken( "]" ) ) { } foundCommand = true; command->nCommandTime = defaultCommandTime; command->nBufferTime = defaultBufferTime; command->strCommand[0] = 0; command->nHowManyCommand = 0; while( command->nHowManyCommand < MAXCOMMAND && !tok.CheckToken( "[", false ) && !tok.AtEndOfFile() ) { if( tok.CheckToken( "name" ) ) { if( !tok.CheckToken( "=" ) ) { } strcpy( command->strCommand, tok.GetToken() ); } else if( tok.CheckToken( "command" ) ) { if( !tok.CheckToken( "=" ) ) { } while( !tok.AtEndOfLine() ) { const char* token = tok.GetToken(); if( !strcmp( token, "~" ) ) { command->nCommand[ command->nHowManyCommand ].keyModifier += PLC_KEYMOD_ON_RELEASE; if( tok.CheckTokenIsNumber() ) { command->nCommand[ command->nHowManyCommand ].gameTicksForHold = tok.GetInt(); } else { command->nCommand[ command->nHowManyCommand ].gameTicksForHold = 1; } } else if( !strcmp( token, "+" ) ) { } else if( !strcmp( token, "/" ) ) { command->nCommand[ command->nHowManyCommand ].keyModifier += PLC_KEYMOD_MUST_BE_HELD; } else if( !strcmp( token, "$" ) ) { command->nCommand[ command->nHowManyCommand ].keyModifier += PLC_KEYMOD_DETECT_AS_4WAY; } else if( !strcmp( token, ">" ) ) { command->nCommand[ command->nHowManyCommand ].keyModifier += PLC_KEYMOD_BAN_OTHER_INPUT; } else if( !strcmp( token, "," ) ) { command->nHowManyCommand++; } else if( !strcmp( token, "D" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_DOWN ); } else if( !strcmp( token, "U" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_UP ); } else if( !strcmp( token, "B" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_LEFT ); } else if( !strcmp( token, "F" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_RIGHT ); } else if( !strcmp( token, "DB" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_DOWN ) + PLC_KEYCODE( KEY_LEFT ); } else if( !strcmp( token, "DF" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_DOWN ) + PLC_KEYCODE( KEY_RIGHT ); } else if( !strcmp( token, "UF" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_UP ) + PLC_KEYCODE( KEY_LEFT ); } else if( !strcmp( token, "UB" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_UP ) + PLC_KEYCODE( KEY_LEFT ); } else if( !strcmp( token, "a" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_A ); } else if( !strcmp( token, "b" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_B ); } else if( !strcmp( token, "c" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_C ); } else if( !strcmp( token, "x" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_X ); } else if( !strcmp( token, "y" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_Y ); } else if( !strcmp( token, "z" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_Z ); } else if( !strcmp( token, "s" ) ) { command->nCommand[ command->nHowManyCommand ].keyCode += PLC_KEYCODE( KEY_BUTTON_START ); } } command->nHowManyCommand++; } else if( tok.CheckToken( "time" ) ) { if( !tok.CheckToken( "=" ) ) { } if( !tok.CheckTokenIsNumber() ) { } command->nCommandTime = tok.GetInt(); } else if( tok.CheckToken( "buffer.time" ) ) { if( !tok.CheckToken( "=" ) ) { } if( !tok.CheckTokenIsNumber() ) { } command->nBufferTime = tok.GetInt(); } } command++; } } if( !foundCommand ) tok.GetToken(); // skip it } tok.CloseFile(); return true; }
void CASEFile::Parse() { if (m_file == NULL) { return; } CAlertErrHandler errhandler; CTokenizer* tokenizer = CTokenizer::Create(TKF_USES_EOL | TKF_NUMERICIDENTIFIERSTART); tokenizer->SetErrHandler(&errhandler); tokenizer->SetKeywords(s_keywords); tokenizer->SetSymbols(s_symbols); tokenizer->AddParseFile(m_file, 16 * 1024); int tokType = TK_UNDEFINED; while(tokType != TK_EOF) { CToken* curToken = tokenizer->GetToken(); if (curToken->GetType() == TK_EOF) { curToken->Delete(); tokType = TK_EOF; break; } if (curToken->GetType() == TK_EOL) { curToken->Delete(); continue; } if (curToken->GetType() != TK_ASE_ASTERISK) { tokenizer->Error(TKERR_UNEXPECTED_TOKEN); curToken->Delete(); tokenizer->GetToEndOfLine()->Delete(); continue; } curToken->Delete(); curToken = tokenizer->GetToken(); tokType = curToken->GetType(); curToken->Delete(); switch(tokType) { case TK_EOF: break; case TK_GEOMOBJECT: ParseGeomObject(tokenizer); break; case TK_SCENE: ParseScene(tokenizer); break; case TK_MATERIAL_LIST: ParseMaterialList(tokenizer); break; case TK_ASE_COMMENT: ParseComment(tokenizer); break; case TK_3DSMAX_ASCIIEXPORT: ParseAsciiExport(tokenizer); break; default: tokenizer->Error(TKERR_UNEXPECTED_TOKEN); tokenizer->GetToEndOfLine()->Delete(); break; } } }