virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context) { codeGenerator.AddIncludeFile("TimedEvent/TimedEventTools.h"); std::string codeName = "GDNamedTimedEvent_"+codeGenerator.ConvertToString(instruction.GetParameter(1).GetPlainString()); return "GDpriv::TimedEvents::Reset(*runtimeContext->scene, \""+codeName+"\");\n"; return ""; };
virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context) { codeGenerator.AddGlobalDeclaration(FunctionEvent::globalDeclaration); std::string functionName = instruction.GetParameter(0).GetPlainString(); const gd::Project & project = codeGenerator.GetProject(); const gd::Layout & scene = codeGenerator.GetLayout(); const FunctionEvent * functionEvent = FunctionEvent::SearchForFunctionInEvents(scene.GetEvents(), functionName); if ( !functionEvent ) { std::cout << "Function \""+functionName+"\" not found!" << std::endl; return "//Function \""+functionName+"\" not found.\n"; } std::string code; //Generate code for objects passed as arguments std::string objectsAsArgumentCode; { objectsAsArgumentCode += "runtimeContext->ClearObjectListsMap()"; std::vector<std::string> realObjects = codeGenerator.ExpandObjectsName(functionEvent->GetObjectsPassedAsArgument(), context); for (unsigned int i = 0;i<realObjects.size();++i) { context.EmptyObjectsListNeeded(realObjects[i]); objectsAsArgumentCode += ".AddObjectListToMap(\""+codeGenerator.ConvertToString(realObjects[i])+"\", "+ManObjListName(realObjects[i])+")"; } objectsAsArgumentCode += ".ReturnObjectListsMap()"; } //Generate code for evaluating parameters code += "std::vector<std::string> functionParameters;\n"; for (unsigned int i = 1;i<8;++i) { std::string parameterCode; gd::CallbacksForGeneratingExpressionCode callbacks(parameterCode, codeGenerator, context); gd::ExpressionParser parser(instruction.GetParameter(i).GetPlainString()); parser.ParseStringExpression(CppPlatform::Get(), project, scene, callbacks); if (parameterCode.empty()) parameterCode = "\"\""; code += "functionParameters.push_back("+parameterCode+");\n"; } code += "std::vector<std::string> * oldFunctionParameters = currentFunctionParameters;\n"; code += "currentFunctionParameters = &functionParameters;\n"; code += FunctionEvent::MangleFunctionName(*functionEvent)+"(runtimeContext, "+objectsAsArgumentCode+");\n"; code += "currentFunctionParameters = oldFunctionParameters;\n"; return code; };
virtual std::string Generate(gd::BaseEvent & event_, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context) { TimedEvent & event = dynamic_cast<TimedEvent&>(event_); const gd::Layout & scene = codeGenerator.GetLayout(); codeGenerator.AddIncludeFile("TimedEvent/TimedEventTools.h"); //Notify parent timed event that they have a child for (unsigned int i = 0;i<TimedEvent::codeGenerationCurrentParents.size();++i) TimedEvent::codeGenerationCurrentParents[i]->codeGenerationChildren.push_back(&event); //And register this event as potential parent TimedEvent::codeGenerationCurrentParents.push_back(&event); event.codeGenerationChildren.clear(); //Prepare code for computing timeout std::string timeOutCode; gd::CallbacksForGeneratingExpressionCode callbacks(timeOutCode, codeGenerator, context); gd::ExpressionParser parser(event.GetTimeoutExpression()); if (!parser.ParseMathExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), scene, callbacks) || timeOutCode.empty()) timeOutCode = "0"; //Prepare name std::string codeName = !event.GetName().empty() ? "GDNamedTimedEvent_"+codeGenerator.ConvertToString(event.GetName()) : "GDTimedEvent_"+ToString(&event); std::string outputCode; outputCode += "if ( static_cast<double>(GDpriv::TimedEvents::UpdateAndGetTimeOf(*runtimeContext->scene, \""+codeName+"\"))/1000000.0 > "+timeOutCode+")"; outputCode += "{"; outputCode += codeGenerator.GenerateConditionsListCode(event.GetConditions(), context); std::string ifPredicat; for (unsigned int i = 0;i<event.GetConditions().size();++i) { if (i!=0) ifPredicat += " && "; ifPredicat += "condition"+ToString(i)+"IsTrue"; } if ( !ifPredicat.empty() ) outputCode += "if (" +ifPredicat+ ")\n"; outputCode += "{\n"; outputCode += codeGenerator.GenerateActionsListCode(event.GetActions(), context); if ( event.HasSubEvents() ) //Sub events { outputCode += "\n{\n"; outputCode += codeGenerator.GenerateEventsListCode(event.GetSubEvents(), context); outputCode += "}\n"; } outputCode += "}\n"; outputCode += "}"; //This event cannot be a parent of other TimedEvent anymore if (!TimedEvent::codeGenerationCurrentParents.empty()) TimedEvent::codeGenerationCurrentParents.pop_back(); else std::cout << "Error! CodeGenerationCurrentParents cannot be empty!"; return outputCode; }
virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context) { codeGenerator.AddIncludeFile("TimedEvent/TimedEventTools.h"); for (unsigned int i = 0;i<TimedEvent::codeGenerationCurrentParents.size();++i) { if ( TimedEvent::codeGenerationCurrentParents[i] == NULL ) { std::cout << "WARNING : NULL timed event in codeGenerationCurrentParents"; continue; } if (TimedEvent::codeGenerationCurrentParents[i]->GetName() == instruction.GetParameter(0).GetPlainString()) { TimedEvent & timedEvent = *TimedEvent::codeGenerationCurrentParents[i]; std::string code; { std::string codeName = !timedEvent.GetName().empty() ? "GDNamedTimedEvent_"+codeGenerator.ConvertToString(timedEvent.GetName()) : "GDTimedEvent_"+ToString(&timedEvent); code += "GDpriv::TimedEvents::Reset(*runtimeContext->scene, \""+codeName+"\");\n"; } for (unsigned int j = 0;j<timedEvent.codeGenerationChildren.size();++j) { std::string codeName = !timedEvent.codeGenerationChildren[j]->GetName().empty() ? "GDNamedTimedEvent_"+codeGenerator.ConvertToString(timedEvent.codeGenerationChildren[j]->GetName()) : "GDTimedEvent_"+ToString(timedEvent.codeGenerationChildren[j]); code += "GDpriv::TimedEvents::Reset(*runtimeContext->scene, \""+codeName+"\");\n"; } return code; } } return ""; };