void Triangle::Collide(SecondaryContext &ctx, int idx, int first, int last) const { Vec3q tnrm(plane.x, plane.y, plane.z); Vec3q ta(a), tca(ca), tba(ba); floatq zero(0.0f), one(1.0f), tit0(it0); int count = last - first + 1; for(int q = 0; q < count; q++) { int tq = q + first; const Vec3q dir = ctx.rayDir[tq]; floatq idet = Inv(dir | tnrm); Vec3q tvec = ctx.rayOrigin[tq] - ta; floatq dist = -(tvec | tnrm) * idet; Vec3q tvec0 = tba ^ tvec; Vec3q tvec1 = tvec ^ tca; idet *= tit0; floatq v = (dir | tvec0) * idet; floatq u = (dir | tvec1) * idet; f32x4b test = Min(u, v) >= zero && u + v <= one; test = test && /*idet > zero &&*/ dist >= zero && dist < ctx.distance[tq]; ctx.distance[tq] = Condition(test, dist, ctx.distance[tq]); ctx.normals[tq] = Condition(test, tnrm, ctx.normals[tq]); ctx.triIds[tq] = Condition(i32x4b(test), idx, ctx.triIds[tq]); ctx.barycentric[tq] = Condition(test, Vec2q(u, v), ctx.barycentric[tq]); } }
Liquid::Condition Liquid::IfTag::parseCondition(Parser& parser) { const Expression a = Expression::parse(parser); if (parser.look(Token::Type::Comparison)) { const StringRef opStr = parser.consume(); const Expression b = Expression::parse(parser); Condition::Operator op = Condition::Operator::None; if (opStr == "==") { op = Condition::Operator::Equal; } else if (opStr == "!=" || opStr == "<>") { op = Condition::Operator::NotEqual; } else if (opStr == "<") { op = Condition::Operator::LessThan; } else if (opStr == ">") { op = Condition::Operator::GreaterThan; } else if (opStr == "<=") { op = Condition::Operator::LessOrEqualThan; } else if (opStr == ">=") { op = Condition::Operator::GreaterOrEqualThan; } else if (opStr == "contains") { op = Condition::Operator::Contains; } return Condition(a, op, b); } return Condition(a); }
INLINE Vec2 ClampTexCoord(const Vec2 &coord) { Vec2 uv = coord - Vec2(Int(coord.x), Int(coord.y)); uv.x = Condition(uv.x < 0.0f, uv.x + 1.0f, uv.x); uv.y = Condition(uv.y < 0.0f, uv.y + 1.0f, uv.y); return uv; }
void MultiCollide(const Triangle &tri0, const Triangle &tri1, const Triangle &tri2, const Triangle &tri3, ShadowContext &ctx, int sidx, int firstA, int lastA) { //TODO: ulozyc odpowiednio (wektorowo) i liczyc test RayInterval - 4 trojkaty Vec3q tnrm[4], tvec0[4], tvec1[4]; floatq tmul[4], zero(0.0f), one(1.0f); tri0.Prepare(ctx, tnrm[0], tvec0[0], tvec1[0], tmul[0]); tri1.Prepare(ctx, tnrm[1], tvec0[1], tvec1[1], tmul[1]); tri2.Prepare(ctx, tnrm[2], tvec0[2], tvec1[2], tmul[2]); tri3.Prepare(ctx, tnrm[3], tvec0[3], tvec1[3], tmul[3]); for(int q = firstA; q <= lastA; q++) { Vec3q dir = ctx.rayDir[q]; floatq distance = ctx.distance[q]; floatq idet[4] = { Inv(dir | tnrm[0]), Inv(dir | tnrm[1]), Inv(dir | tnrm[2]), Inv(dir | tnrm[3]) }; floatq dist[4] = { idet[0] * tmul[0], idet[1] * tmul[1], idet[2] * tmul[2], idet[3] * tmul[3] }; floatq v[4] = { (dir | tvec0[0]) * idet[0], (dir | tvec0[1]) * idet[1], (dir | tvec0[2]) * idet[2], (dir | tvec0[3]) * idet[3], }; floatq u[4] = { (dir | tvec1[0]) * idet[0], (dir | tvec1[1]) * idet[1], (dir | tvec1[2]) * idet[2], (dir | tvec1[3]) * idet[3], }; f32x4b test[4] = { Min(u[0], v[0]) >= zero && u[0] + v[0] <= one, Min(u[1], v[1]) >= zero && u[1] + v[1] <= one, Min(u[2], v[2]) >= zero && u[2] + v[2] <= one, Min(u[3], v[3]) >= zero && u[3] + v[3] <= one, }; test[0] = test[0] /*&& idet[0] > zero*/ && dist[0] >= zero; test[1] = test[1] /*&& idet[1] > zero*/ && dist[1] >= zero; test[2] = test[2] /*&& idet[2] > zero*/ && dist[2] >= zero; test[3] = test[3] /*&& idet[3] > zero*/ && dist[3] >= zero; f32x4 minDist = distance; minDist = Condition(test[0] && dist[0] < minDist, dist[0], minDist); minDist = Condition(test[1] && dist[1] < minDist, dist[1], minDist); minDist = Condition(test[2] && dist[2] < minDist, dist[2], minDist); minDist = Condition(test[3] && dist[3] < minDist, dist[3], minDist); test[0] = test[0] && dist[0] <= minDist; test[1] = test[1] && dist[1] <= minDist; test[2] = test[2] && dist[2] <= minDist; test[3] = test[3] && dist[3] <= minDist; ctx.distance[q] = minDist; } }
void Statement() { switch (Symb.type) { case IDENT: { Gener(TA, varAddr(Symb.ident)); Symb = readLexem(); Compare(ASSIGN, __LINE__); Expression(); Gener(ST); break; } case kwWRITE: Symb = readLexem(); Expression(); Gener(WRT); break; case kwREAD: Symb = readLexem(); char id[MAX_IDENT_LEN]; Compare_IDENT(id, __LINE__); Gener(TA, varAddr(id)); Gener(RD); Gener(ST); break; case kwIF: { Symb = readLexem(); Condition(); int adrIFJ = Gener(IFJ); Compare(kwTHEN, __LINE__); Statement(); ElsePart(adrIFJ); break; } case kwWHILE: { int a1 = GetIC(); Symb = readLexem(); Condition(); int aIFJ = Gener(IFJ); Compare(kwDO, __LINE__); Statement(); Gener(JU, a1); PutIC(aIFJ); break; } case kwBEGIN: CompoundStatement(); break; default: break; } }
void DoIf() { Condition(); char L1[MAX_BUF]; char L2[MAX_BUF]; strcpy(L1, NewLabel()); strcpy(L2, L1); sprintf(tmp, "jz %s", L1); EmitLn(tmp); Block(); if (Token == 'l') { /* match *else* statement */ strcpy(L2, NewLabel()); sprintf(tmp, "jmp %s", L2); EmitLn(tmp); PostLabel(L1); Block(); } PostLabel(L2); MatchString("ENDIF"); }
/* <If> ::= if ( <Condition> ) <Statement> <If Prime> */ bool SyntaxAnalyzer::If() { if(rrr == k_if) { NextRecord(); if(rrr == s_openbracketround) { NextRecord(); Condition(); if(rrr == s_closebracketround) { NextRecord(); Statement(); IfPrime(); logger.Log("<If> ::= if ( <Condition> ) <Statement> <If Prime>"); return true; } else { insert(s_closebracketround); return true; } } else { insert(s_openbracketround); return true; } } else { // no error return false; } }
/* <While> ::= while ( <Condition> ) <Statement> */ bool SyntaxAnalyzer::While() { if(rrr == k_while) { NextRecord(); if(rrr == s_openbracketround) { NextRecord(); Condition(); if(rrr == s_closebracketround) { NextRecord(); Statement(); // log logger.Log("While> ::= while ( <Condition> ) <Statement>"); return true; } else { insert(s_closebracketround); return true; } } else { insert(s_openbracketround); return true; } } else { // no error return false; } }
bool Parser::If() { // watch out for pointer magic in these 'if' 'elseif' 'else' functions if (!("if" == lex)) { std::cout << "Expected 'if'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("(" == lex)) { std::cout << "if keyword not followed by '('\n"; return false; } else { L.getTokLex(tok,lex); } if (!Condition()) return false; if (!(")" == lex)) { std::cout << "if condition not followed by ')'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("begin" == lex)) { std::cout << "if body does not begin with keyword 'begin'\n"; return false; } else { L.getTokLex(tok,lex); } assembly.push_back(icode(a_line, "JMPZ")); int jz = a_line-1; ++a_line; int *jzp = &(jz); if (!OptStmtList()) return false; if (!("end" == lex)) { std::cout << "if body does not end with keyword 'end'\n"; return false; } else { L.getTokLex(tok,lex); } std::vector< int > jumps; std::vector< int > *jp = &jumps; if (!OptElseIf(jzp, jp)) return false; if (!OptElse(jz)) return false; for (int i=0; i < jumps.size(); i++) { assembly[jumps[i]].addr = std::to_string(a_line); } // std::cout << "If => if ( Condition ) begin OptStmtList end OptElseIf OptElse\n"; return true; }
// return the numerical statistics of blocks signalling the specified BIP9 condition in this current period BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const { BIP9Stats stats = {}; stats.period = Period(params); stats.threshold = Threshold(params); if (pindex == nullptr) return stats; // Find beginning of period const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period)); stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight; // Count from current block to beginning of period int count = 0; const CBlockIndex* currentIndex = pindex; while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){ if (Condition(currentIndex, params)) count++; currentIndex = currentIndex->pprev; } stats.count = count; stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count); return stats; }
Ability::Ability(string const& name, int damage, double manaCost, double heat, unsigned cooldown) : INIT_PRIVATE_VARIABLES(name, damage, manaCost, heat, cooldown) { if(name == "Shield-Skill03"){ m->activate = [](Combatant& attacker, Combatant& defender) { attacker.GainCondition(Condition(Guarding)); }; } }
Vec3q SATSampler::operator()(const Vec2q &uv,const Vec2q &diff) const { f32x4b fullMask=diff.x>=0.5f||diff.x>= 0.5f; if(ForAll(fullMask)) return Vec3q(avg.x,avg.y,avg.z); Vec2q tDiff=diff*floatq(0.5f); Vec2q a=(uv-tDiff),b=(uv+tDiff); a*=Vec2q(floatq(w),floatq(h)); b*=Vec2q(floatq(w),floatq(h)); i32x4 ax(a.x),ay(a.y); i32x4 bx(b.x),by(b.y); ax&=wMask; ay&=hMask; bx&=wMask; by&=hMask; union { __m128 count; float countf[4]; }; TSample sum[4]; i32x4 one(1); if(ForAll(ax<=bx&&ay<=by)) { count = (f32x4(by-ay+one)*f32x4(bx-ax+one)).m; ComputeRect(ax,ay,bx,by,sum); } else for(int k=0;k<4;k++) { if(ax[k]>bx[k]) { if(ay[k]>by[k]) { countf[k]=(bx[k]+1)*(by[k]+1)+(w-ax[k])*(h-ay[k]); sum[k]=ComputeRect(0,0,bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,h-1); } else { countf[k]=(bx[k]+1+w-ax[k])*(by[k]-ay[k]+1); sum[k]=ComputeRect(0,ay[k],bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,by[k]); } } else { if(ay[k]>by[k]) { countf[k]=(bx[k]-ax[k]+1)*(by[k]+h+1-ay[k]); sum[k]=ComputeRect(ax[k],0,bx[k],by[k])+ComputeRect(ax[k],ay[k],bx[k],h-1); } else { countf[k]=(by[k]-ay[k]+1)*(bx[k]-ax[k]+1); sum[k]=ComputeRect(ax[k],ay[k],bx[k],by[k]); } } } union { __m128 out[3]; struct { float ox[4]; float oy[4]; float oz[4]; } o; }; o.ox[0]=sum[0].R(); o.oy[0]=sum[0].G(); o.oz[0]=sum[0].B(); o.ox[1]=sum[1].R(); o.oy[1]=sum[1].G(); o.oz[1]=sum[1].B(); o.ox[2]=sum[2].R(); o.oy[2]=sum[2].G(); o.oz[2]=sum[2].B(); o.ox[3]=sum[3].R(); o.oy[3]=sum[3].G(); o.oz[3]=sum[3].B(); return Condition(fullMask,Vec3q(avg.x,avg.y,avg.z), Vec3q(out[0], out[1], out[2]) * Inv(floatq(count) * 255.0f)); }
void Jmp::Execute() { ResolveValue(0); if(Condition()) { char* target = VM_INSTANCE()->GetMemory(arguments[0]); if(target) VM_INSTANCE()->SetRegister(REG_EIP, arguments[0]); } }
bool Parser::OptElseIf(int* jzp, std::vector< int > *jp) { if (!("elseif" == lex)) { // std::cout << "OptElseIf => null\n"; return true; } else { L.getTokLex(tok,lex); } assembly.push_back(icode(a_line,"JUMP")); (*jp).push_back(a_line-1); ++a_line; assembly[(*jzp)].addr = std::to_string(a_line); if (!("(" == lex)) { std::cout << "elseif keyword not followed by '('\n"; return false; } else { L.getTokLex(tok,lex); } if (!Condition()) return false; if (!(")" == lex)) { std::cout << "elseif condition not followed by ')'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("begin" == lex)) { std::cout << "elseif body does not begin with keyword 'begin'\n"; return false; } else { L.getTokLex(tok,lex); } assembly.push_back(icode(a_line, "JMPZ")); *jzp = a_line-1; ++a_line; if (!OptStmtList()) return false; if (!("end" == lex)) { std::cout << "elseif body does not end with keyword 'end'\n"; return false; } else { L.getTokLex(tok,lex); } if (!OptElseIf(jzp, jp)) return false; // std::cout << "OptElseIf => elseif ( Condition ) begin OptStmtList end OptElseIf\n"; return true; }
SQLResult *SQLQueryExecutor::execute(const SQLQuery &sqlQuery) { if (!DB::current()) { throw Condition("Current database not open"); } sqlite3 *dbhandle=static_cast<sqlite3 *>(DB::current()->getDatabase()->getDbHandle()); sqlite3_stmt *stmt=0; int result=sqlite3_prepare_v2(dbhandle, sqlQuery.sqlQuery.c_str(), -1, &stmt, NULL); if (result!=SQLITE_OK) throw Condition("Error preparing query: %s (%d). Query string was '%s'", sqlite3_errmsg(dbhandle), result, sqlQuery.sqlQuery.c_str()); SQLite3Result *sqlResult=new SQLite3Result(stmt); try { sqlResult->prepare(); return sqlResult; } catch (...) { delete sqlResult; throw; } }
bool Parser::While() { if (!("while" == lex)) { std::cout << "Expected 'while'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("(" == lex)) { std::cout << "while keyword not followed by '('\n"; return false; } else { L.getTokLex(tok,lex); } int cond_line = a_line; if (!Condition()) return false; if (!(")" == lex)) { std::cout << "while condition not followed by ')'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("begin" == lex)) { std::cout << "while body does not begin with keyword 'begin'\n"; return false; } else { L.getTokLex(tok,lex); } assembly.push_back(icode(a_line, "JMPZ")); int jz_instr = a_line-1; ++a_line; if (!OptStmtList()) return false; assembly.push_back(icode(a_line,"JUMP",std::to_string(cond_line))); ++a_line; assembly[jz_instr].addr = std::to_string(a_line); if (!("end" == lex)) { std::cout << "while body does not end with keyword 'end'\n"; return false; } else { L.getTokLex(tok,lex); } // std::cout << "While => while ( Condition ) begin OptStmtList end\n"; return true; }
int AbstractThresholdConditionChecker::CountBlocksInWindow(const CBlockIndex* pindex, const Consensus::Params& params) const { int nPeriod = Period(params); int nStopHeight = pindex->nHeight - (pindex->nHeight % nPeriod) - 1; const CBlockIndex* pindexCount = pindex; int count = 0; while (pindexCount && pindexCount->nHeight != nStopHeight) { if (Condition(pindexCount, params)) { count++; } pindexCount = pindexCount->pprev; } return count; }
Statm *Statement() { switch (Symb.type) { case IDENT: { Var *var = new Var(varAddr(Symb.ident),false); Symb = readLexem(); Compare(ASSIGN, __LINE__); return new Assign(var, Expression()); } case kwWRITE: Symb = readLexem(); return new Write(Expression()); case kwREAD: Symb = readLexem(); char id[MAX_IDENT_LEN]; Compare_IDENT(id, __LINE__); return new Read(new Var(varAddr(id), false)); case kwIF: { Symb = readLexem(); Expr *cond = Condition(); Compare(kwTHEN, __LINE__); Statm *prikaz = Statement(); return new If(cond, prikaz, ElsePart()); } case kwWHILE: { Expr *cond; Symb = readLexem(); cond = Condition(); Compare(kwDO, __LINE__); return new While(cond, Statement()); } case kwBEGIN: return CompoundStatement(); default: return new Empty; } }
bool Parser::If() { if (!("if" == lex)) { std::cout << "Expected 'if'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("(" == lex)) { std::cout << "if keyword not followed by '('\n"; return false; } else { L.getTokLex(tok,lex); } if (!Condition()) return false; if (!(")" == lex)) { std::cout << "if condition not followed by ')'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("begin" == lex)) { std::cout << "if body does not begin with keyword 'begin'\n"; return false; } else { L.getTokLex(tok,lex); } if (!OptStmtList()) return false; if (!("end" == lex)) { std::cout << "if body does not end with keyword 'end'\n"; return false; } else { L.getTokLex(tok,lex); } if (!OptElseIf()) return false; if (!OptElse()) return false; std::cout << "If => if ( Condition ) begin OptStmtList end OptElseIf OptElse\n"; return true; }
////////////////////////////////////////////////////////////////////////// // // // // ////////////////////////////////////////////////////////////////////////// SCTokenBlock CPreprocessor::ProcessHashElif(CPreprocessorTokenParser* pcParser, CPPConditional* pcCond, SCTokenBlock iLine) { BOOL bEvaluated; CPPTokenHolder cTokenHolder; CChars sz; cTokenHolder.Init(32); ProcessLine(&cTokenHolder, pcParser, TRUE, 0); sz.Init(128); cTokenHolder.Append(&sz); bEvaluated = Evaluate(sz.Text());; mcConditionalStack.SwapForElseIf(bEvaluated); sz.Kill(); cTokenHolder.Kill(); return Condition(pcCond, iLine); }
/** * Methode statique, effectue la comparaison avec les élément fournient dans la description * * @brief Inst_Cond::ComparaisonStatique * @param Manager Manager de module parent * @param Description Description de la condition * @return Le retour de la condition */ bool Inst_Cond::ComparaisonStatique(ModuleManager * Manager, DescCondition Description) { Inst_Cond Condition(Description) ; bool ReponseCondition(false) ; switch (Condition.getTCondition()) { case LOG: ReponseCondition = Condition.ComparaisonLogicielle(Manager) ; break ; case MAT: ReponseCondition = Condition.ComparaisonMaterielle(Manager) ; break ; } return ReponseCondition ; }
bool Parser::While() { if (!("while" == lex)) { std::cout << "Expected 'while'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("(" == lex)) { std::cout << "while keyword not followed by '('\n"; return false; } else { L.getTokLex(tok,lex); } if (!Condition()) return false; if (!(")" == lex)) { std::cout << "while condition not followed by ')'\n"; return false; } else { L.getTokLex(tok,lex); } if (!("begin" == lex)) { std::cout << "while body does not begin with keyword 'begin'\n"; return false; } else { L.getTokLex(tok,lex); } if (!OptStmtList()) return false; if (!("end" == lex)) { std::cout << "while body does not end with keyword 'end'\n"; return false; } else { L.getTokLex(tok,lex); } std::cout << "While => while ( Condition ) begin OptStmtList end\n"; return true; }
////////////////////////////////////////////////////////////////////////// // // // // ////////////////////////////////////////////////////////////////////////// SCTokenBlock CPreprocessor::ProcessHashIfdef(CPreprocessorTokenParser* pcParser, CPPConditional* pcCond, SCTokenBlock iLine) { CExternalString cIdentifier; CDefine* pcDefine; BOOL bResult; BOOL bEvaluated; pcParser->SkipWhiteSpace(); bResult = pcParser->GetIdentifier(&cIdentifier); if (bResult) { pcDefine = mcDefines.GetDefine(&cIdentifier); bEvaluated = (pcDefine != NULL); mcConditionalStack.PushIfDefined(bEvaluated); } else { mcConditionalStack.PushIfDefined(TRUE); } return Condition(pcCond, iLine); }
bool syntaxparser::While(){ bool bWhile = false; if (lexeme == "while"){ print(); cout<<endl; string addr; addr = project3.get_instr_address(); project3.gen_inst("Label", "-999"); Lexer(); if(displayFlag){ cout << "<While> ::=( <Condition> ) <Statement>" << endl; printproduction("<While> ::=( <Condition> ) <Statement>"); } if (lexeme == "("){ print(); cout<<endl; Lexer(); Condition(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); Statement(); project3.gen_inst("JUMP", addr); addr = project3.get_instr_address(); project3.back_patch( addr); bWhile = true; }else error("Missing ')'"); } } return bWhile; }
//parse a statement void Statement(){ char* ident = malloc(sizeof(char*) * 12); int number; int tmp; int jaddr; int caddr; int jaddr2; symbol* curSym; //ident if(!strcmp(token, "2")){ //get the specific ident ident = input[tptr++]; Get(); //ident := expression if(!strcmp(token, ":=")) Get(); else Error(11); //get our ident from the table //make sure our ident is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } else{ //if the variable has not yet been assigned, //assign its position on the stack if(curSym->position == -1){ curSym->position = offset++; } //parse the expression and store the rseult Expression(); Gen(4,(lex - curSym->level),curSym->position); } } //call a procedure else if(!strcmp(token, "call")){ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 2){ Error(15); } else{ PList(); Gen(5, (lex - curSym->level), curSym->position); } } else Error(14); Get(); } //begin else if(!strcmp(token, "begin")){ Get(); Statement(); while(!strcmp(token, ";")){ Get(); Statement(); } if(!strcmp(token, "end")){ Get(); } else{ Error(10); } } //if - then else if(!strcmp(token, "if")){ Get(); Condition(); if(!strcmp(token, "then")){ Get(); //store the line where our jump address is written for future use jaddr = line; Gen(8,0,0); Statement(); if(!strcmp(token, ";")){ //update our jump addresses to the correct one codegen[jaddr].m = line; Get(); } if(!strcmp(token, "else")){ jaddr2 = line; Gen(7,0,0); Get(); codegen[jaddr].m = line; Statement(); //update our jump addresses to the correct one codegen[jaddr2].m = line; } else{ codegen[jaddr].m = line; token = ";"; tptr--; } } else Error(16); } //while else if(!strcmp(token, "while")){ Get(); //store the position of the start of the loop caddr = line; Condition(); if(!strcmp(token, "do")){ //store the line where our jump address is written for future use jaddr = line; Gen(8,0,0); Get(); Statement(); //write the jump to the top of the loop Gen(7,0,caddr); //update our jump address to the correct one codegen[jaddr].m = line; } else Error(18); } //read from console else if(!strcmp(token, "read")){ Gen(10,0,0); Get(); //ident to store input if(!strcmp(token, "2")){ //actual variable ident = input[tptr++]; Get(); //get the current symbol and make sure it is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } //if the variable has not yet been assigned, //assign its position on the stack if(curSym->position == -1){ curSym->position = offset++; } Gen(4,(lex - curSym->level),curSym->position); } } //write to console else if(!strcmp(token, "write")){ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; Get(); //get the current symbol and make sure it is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } if(curSym->position == -1){ Error(11); } Gen(3,(lex - curSym->level),curSym->position); Gen(9,0,0); } } }
ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const { int nPeriod = Period(params); int nThreshold = Threshold(params); int64_t nTimeStart = BeginTime(params); int64_t nTimeTimeout = EndTime(params); // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1. if (pindexPrev != nullptr) { pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod)); } // Walk backwards in steps of nPeriod to find a pindexPrev whose information is known std::vector<const CBlockIndex*> vToCompute; while (cache.count(pindexPrev) == 0) { if (pindexPrev == nullptr) { // The genesis block is by definition defined. cache[pindexPrev] = THRESHOLD_DEFINED; break; } if (pindexPrev->GetMedianTimePast() < nTimeStart) { // Optimization: don't recompute down further, as we know every earlier block will be before the start time cache[pindexPrev] = THRESHOLD_DEFINED; break; } vToCompute.push_back(pindexPrev); pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); } // At this point, cache[pindexPrev] is known assert(cache.count(pindexPrev)); ThresholdState state = cache[pindexPrev]; // Now walk forward and compute the state of descendants of pindexPrev while (!vToCompute.empty()) { ThresholdState stateNext = state; pindexPrev = vToCompute.back(); vToCompute.pop_back(); switch (state) { case THRESHOLD_DEFINED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = THRESHOLD_FAILED; } else if (pindexPrev->GetMedianTimePast() >= nTimeStart) { stateNext = THRESHOLD_STARTED; } break; } case THRESHOLD_STARTED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = THRESHOLD_FAILED; break; } // We need to count const CBlockIndex* pindexCount = pindexPrev; int count = 0; for (int i = 0; i < nPeriod; i++) { if (Condition(pindexCount, params)) { count++; } pindexCount = pindexCount->pprev; } if (count >= nThreshold) { stateNext = THRESHOLD_LOCKED_IN; } break; } case THRESHOLD_LOCKED_IN: { // Always progresses into ACTIVE. stateNext = THRESHOLD_ACTIVE; break; } case THRESHOLD_FAILED: case THRESHOLD_ACTIVE: { // Nothing happens, these are terminal states. break; } } cache[pindexPrev] = state = stateNext; } return state; }
void Strange_device::load() { condition_ = Condition(save_handling::get_int()); }
/** * Methode statique effectuant l'équivalent de toString à partir de élément de la description * * @brief Inst_Cond::toStringStatique * @param Description Description à convertir * @return La chaine à afficher * @see toString */ QString Inst_Cond::toStringStatique(DescCondition Description) { Inst_Cond Condition(Description) ; return Condition.toString() ; }
Consume_item Strange_device::activate(Actor* const actor) { assert(actor); if (data_->is_identified) { const std::string item_name = name(Item_ref_type::plain, Item_ref_inf::none); const std::string item_name_a = name(Item_ref_type::a, Item_ref_inf::none); msg_log::add("I activate " + item_name_a + "..."); //Damage user? Fail to run effect? Condition degrade? Warning? const std::string hurt_msg = "It hits me with a jolt of electricity!"; bool is_effect_failed = false; bool is_cond_degrade = false; bool is_warning = false; int bon = 0; if (actor->has_prop(Prop_id::blessed)) { bon += 2; } if (actor->has_prop(Prop_id::cursed)) { bon -= 2; } const int RND = rnd::range(1, 8 + bon); switch (condition_) { case Condition::breaking: { if (RND == 5 || RND == 6) { msg_log::add(hurt_msg, clr_msg_bad); actor->hit(rnd::dice(2, 4), Dmg_type::electric); } is_effect_failed = RND == 3 || RND == 4; is_cond_degrade = RND <= 2; is_warning = RND == 7 || RND == 8; } break; case Condition::shoddy: { if (RND == 4) { msg_log::add(hurt_msg, clr_msg_bad); actor->hit(rnd::dice(1, 4), Dmg_type::electric); } is_effect_failed = RND == 3; is_cond_degrade = RND <= 2; is_warning = RND == 5 || RND == 6; } break; case Condition::fine: { is_cond_degrade = RND <= 2; is_warning = RND == 3 || RND == 4; } break; } if (!map::player->is_alive()) { return Consume_item::no; } Consume_item consumed_state = Consume_item::no; if (is_effect_failed) { msg_log::add("It suddenly stops."); } else { consumed_state = trigger_effect(); } if (consumed_state == Consume_item::no) { if (is_cond_degrade) { if (condition_ == Condition::breaking) { msg_log::add("The " + item_name + " breaks!"); consumed_state = Consume_item::yes; } else { msg_log::add("The " + item_name + " makes a terrible grinding noise."); msg_log::add("I seem to have damaged it."); condition_ = Condition(int(condition_) - 1); } } if (is_warning) { msg_log::add("The " + item_name + " hums ominously."); } } game_time::tick(); return consumed_state; } else //Not identified { msg_log::add("This device is completely alien to me, "); msg_log::add("I could never understand it through normal means."); return Consume_item::no; } }
bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd) { String parseString = value.stripWhiteSpace(); double sign = 1.; bool ok; size_t pos = parseString.find('+'); if (pos == notFound) { pos = parseString.find('-'); if (pos != notFound) sign = -1.; } String conditionString; SMILTime offset = 0; if (pos == notFound) conditionString = parseString; else { conditionString = parseString.left(pos).stripWhiteSpace(); String offsetString = parseString.substring(pos + 1).stripWhiteSpace(); offset = parseOffsetValue(offsetString); if (offset.isUnresolved()) return false; offset = offset * sign; } if (conditionString.isEmpty()) return false; pos = conditionString.find('.'); String baseID; String nameString; if (pos == notFound) nameString = conditionString; else { baseID = conditionString.left(pos); nameString = conditionString.substring(pos + 1); } if (nameString.isEmpty()) return false; Condition::Type type; int repeats = -1; if (nameString.startsWith("repeat(") && nameString.endsWith(')')) { // FIXME: For repeat events we just need to add the data carrying TimeEvent class and // fire the events at appropiate times. repeats = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok); if (!ok) return false; nameString = "repeat"; type = Condition::EventBase; } else if (nameString == "begin" || nameString == "end") { if (baseID.isEmpty()) return false; type = Condition::Syncbase; } else if (nameString.startsWith("accesskey(")) { // FIXME: accesskey() support. type = Condition::AccessKey; } else type = Condition::EventBase; m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset, repeats)); if (type == Condition::EventBase && beginOrEnd == End) m_hasEndEventConditions = true; return true; }