MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ForDoOp

Function ForDoOp

engine/Evaluator/express.cpp:929–969  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

927}
928
929static GameValue ForDoOp(const GameState* state, GameValuePar oper1, GameValuePar oper2)
930{
931 auto* toData = static_cast<const GameDataForTo*>(oper1.GetData());
932 float from = toData->GetFrom();
933 float to = toData->GetTo();
934 float step = toData->GetStep();
935 RString body = oper2;
936
937 if (step == 0.0f)
938 {
939 state->SetError(EvalGen);
940 return NOTHING;
941 }
942
943 GameValue exitVal = NOTHING;
944 int maxIters = 100000;
945 int count = 0;
946 for (float i = from; (step > 0 ? i <= to : i >= to); i += step)
947 {
948 if (count++ >= maxIters)
949 {
950 RptF("Max iteration count exceeded in for loop");
951 state->SetError(EvalGen);
952 break;
953 }
954 GameVarSpace local(state->GetContext());
955 state->BeginContext(&local);
956 state->VarSetLocal(toData->GetVar(), GameValue(i));
957 const_cast<GameState*>(state)->Execute(body);
958 state->EndContext();
959 if (state->GetLastError() == EvalBreak)
960 {
961 exitVal = tls_exitWithValue;
962 const_cast<GameState*>(state)->SetError(EvalOK);
963 break;
964 }
965 if (state->GetLastError() != EvalOK)
966 break;
967 }
968 return exitVal;
969}
970
971static GameValue ArrayThen(const GameState* state, GameValuePar oper1, GameValuePar oper2)
972{

Callers

nothing calls this directly

Calls 13

BeginContextMethod · 0.80
VarSetLocalMethod · 0.80
EndContextMethod · 0.80
GetLastErrorMethod · 0.80
GameValueClass · 0.70
GetDataMethod · 0.45
GetFromMethod · 0.45
GetToMethod · 0.45
GetStepMethod · 0.45
SetErrorMethod · 0.45
GetContextMethod · 0.45
GetVarMethod · 0.45

Tested by

no test coverage detected