• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ gd::EventsCodeGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中gd::EventsCodeGenerator的典型用法代码示例。如果您正苦于以下问题:C++ EventsCodeGenerator类的具体用法?C++ EventsCodeGenerator怎么用?C++ EventsCodeGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EventsCodeGenerator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: GenerateCode

            virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)
            {
                std::string value1Code;
                {
                    gd::CallbacksForGeneratingExpressionCode callbacks(value1Code, codeGenerator, context);
                    gd::ExpressionParser parser(instruction.GetParameters()[0].GetPlainString());
                    if (!parser.ParseMathExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks) || value1Code.empty()) value1Code = "0";
                }

                std::string value2Code;
                {
                    gd::CallbacksForGeneratingExpressionCode callbacks(value2Code, codeGenerator, context);
                    gd::ExpressionParser parser(instruction.GetParameters()[2].GetPlainString());
                    if (!parser.ParseMathExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks) || value2Code.empty()) value2Code = "0";
                }

                std::string resultingBoolean = codeGenerator.GenerateBooleanFullName("conditionTrue", context)+".val";

                if ( instruction.GetParameters()[1].GetPlainString() == "=" || instruction.GetParameters()[1].GetPlainString().empty() )
                    return resultingBoolean + " = ("+value1Code+" == "+value2Code+");\n";
                else if ( instruction.GetParameters()[1].GetPlainString() == ">")
                    return resultingBoolean + " = ("+value1Code+" > "+value2Code+");\n";
                else if ( instruction.GetParameters()[1].GetPlainString() == "<")
                    return resultingBoolean + " = ("+value1Code+" < "+value2Code+");\n";
                else if ( instruction.GetParameters()[1].GetPlainString() == "<=")
                    return resultingBoolean + " = ("+value1Code+" <= "+value2Code+");\n";
                else if ( instruction.GetParameters()[1].GetPlainString() == ">=")
                    return resultingBoolean + " = ("+value1Code+" >= "+value2Code+");\n";
                else if ( instruction.GetParameters()[1].GetPlainString() == "!=")
                    return resultingBoolean + " = ("+value1Code+" != "+value2Code+");\n";

                return "";
            };
开发者ID:Slulego,项目名称:GD,代码行数:33,代码来源:SceneExtension.cpp


示例2: GenerateCode

            virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)
            {
                std::string expressionCode;
                {
                    gd::CallbacksForGeneratingExpressionCode callbacks(expressionCode, codeGenerator, context);
                    gd::ExpressionParser parser(instruction.GetParameters()[2].GetPlainString());
                    if (!parser.ParseStringExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks) || expressionCode.empty())
                        expressionCode = "\"\"";
                }

                std::string varGetter;
                {
                    VariableCodeGenerationCallbacks callbacks(varGetter, codeGenerator, context, VariableCodeGenerationCallbacks::LAYOUT_VARIABLE);
                    gd::VariableParser parser(instruction.GetParameters()[0].GetPlainString());
                    if ( !parser.Parse(callbacks) )
                        varGetter = "runtimeScene.getVariables().get(\"\")";
                }

                std::string op = instruction.GetParameters()[1].GetPlainString();
                if ( op == "=" )
                    return varGetter+".setString("+expressionCode+");\n";
                else if ( op == "+" )
                    return varGetter+".concatenate("+expressionCode+");\n";

                return "";
            };
开发者ID:Slulego,项目名称:GD,代码行数:26,代码来源:VariablesExtension.cpp


示例3: GenerateCode

                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 "";
                };
开发者ID:cubemoon,项目名称:GD,代码行数:9,代码来源:Extension.cpp


示例4: GenerateCode

            virtual std::string GenerateCode(gd::Instruction & instruction, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)
            {
                std::string outputCode;

                std::vector<std::string> realObjects = codeGenerator.ExpandObjectsName(instruction.GetParameter(0).GetPlainString(), context);
                for (unsigned int i = 0;i<realObjects.size();++i)
                {
                    context.SetCurrentObject(realObjects[i]);
                    context.ObjectsListNeeded(realObjects[i]);

                    std::string newX, newY;

                    std::string expression1Code;
                    {
                        gd::CallbacksForGeneratingExpressionCode callbacks(expression1Code, codeGenerator, context);
                        gd::ExpressionParser parser(instruction.GetParameters()[2].GetPlainString());
                        if (!parser.ParseMathExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks) || expression1Code.empty())
                            expression1Code = "0";
                    }

                    std::string expression2Code;
                    {
                        gd::CallbacksForGeneratingExpressionCode callbacks(expression2Code, codeGenerator, context);
                        gd::ExpressionParser parser(instruction.GetParameters()[4].GetPlainString());
                        if (!parser.ParseMathExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks) || expression2Code.empty())
                            expression2Code = "0";
                    }

                    std::string op1 = instruction.GetParameter(1).GetPlainString();
                    if ( op1 == "=" || op1.empty() )
                        newX = expression1Code;
                    else if ( op1 == "/" || op1 == "*" || op1 == "-" || op1 == "+" )
                        newX = codeGenerator.GetObjectListName(realObjects[i], context)+"[i].getX() "+op1 + expression1Code;
                    else
                        return "";
                    std::string op2 = instruction.GetParameter(3).GetPlainString();
                    if ( op2 == "=" || op2.empty() )
                        newY = expression2Code;
                    else if ( op2 == "/" || op2 == "*" || op2 == "-" || op2 == "+" )
                        newY = codeGenerator.GetObjectListName(realObjects[i], context)+"[i].getY() "+op2 + expression2Code;
                    else
                        return "";

                    std::string call = codeGenerator.GetObjectListName(realObjects[i], context)+"[i].setPosition("+newX+","+newY+")";

                    outputCode += "for(var i = 0, len = "+codeGenerator.GetObjectListName(realObjects[i], context)+".length ;i < len;++i) {\n";
                    outputCode += "    "+call+";\n";
                    outputCode += "}\n";

                    context.SetNoCurrentObject();
                }

                return outputCode;
            };
开发者ID:manolaz,项目名称:GDJS,代码行数:54,代码来源:BaseObjectExtension.cpp


示例5: Generate

                virtual std::string Generate(gd::BaseEvent & event_, gd::EventsCodeGenerator & codeGenerator,
                                             gd::EventsCodeGenerationContext & /* The function has nothing to do with the current context */)
                {
                    FunctionEvent & event = dynamic_cast<FunctionEvent&>(event_);

                    //Declaring the pointer to the function parameters
                    codeGenerator.AddGlobalDeclaration(event.globalDeclaration);

                    //Declaring function prototype.
                    codeGenerator.AddGlobalDeclaration("void "+FunctionEvent::MangleFunctionName(event)+"(RuntimeContext *, std::map <std::string, std::vector<RuntimeObject*> *>);\n");

                    //Generating function code:
                    std::string functionCode;
                    functionCode += "\nvoid "+FunctionEvent::MangleFunctionName(event)+"(RuntimeContext * runtimeContext, std::map <std::string, std::vector<RuntimeObject*> *> objectsListsMap)\n{\n";

                    gd::EventsCodeGenerationContext callerContext;
                    {
                        std::vector<std::string> realObjects = codeGenerator.ExpandObjectsName(event.GetObjectsPassedAsArgument(), callerContext);
                        for (unsigned int i = 0;i<realObjects.size();++i)
                        {
                            callerContext.EmptyObjectsListNeeded(realObjects[i]);
                            functionCode += "std::vector<RuntimeObject*> "+ManObjListName(realObjects[i]) + ";\n";
                            functionCode += "if ( objectsListsMap[\""+realObjects[i]+"\"] != NULL ) "+ManObjListName(realObjects[i])+" = *objectsListsMap[\""+realObjects[i]+"\"];\n";
                        }
                    }
                    functionCode += "{";

                    gd::EventsCodeGenerationContext context;
                    context.InheritsFrom(callerContext);

                    //Generating function body code
                    std::string conditionsCode = codeGenerator.GenerateConditionsListCode(event.GetConditions(), context);
                    std::string actionsCode = codeGenerator.GenerateActionsListCode(event.GetActions(), context);
                    std::string subeventsCode = codeGenerator.GenerateEventsListCode(event.GetSubEvents(), context);

                    functionCode += codeGenerator.GenerateObjectsDeclarationCode(context);
                    std::string ifPredicat = "true";
                    for (unsigned int i = 0;i<event.GetConditions().size();++i)
                        ifPredicat += " && condition"+ToString(i)+"IsTrue";

                    functionCode += conditionsCode;
                    functionCode += "if (" +ifPredicat+ ")\n";
                    functionCode += "{\n";
                    functionCode += actionsCode;
                    if ( event.HasSubEvents() ) //Sub events
                    {
                        functionCode += "\n{\n";
                        functionCode += subeventsCode;
                        functionCode += "}\n";
                    }
                    functionCode += "}\n";

                    functionCode += "}\n"; //Context end
                    functionCode += "}\n"; //Function end
                    codeGenerator.AddCustomCodeOutsideMain(functionCode);

                    return "";
                }
开发者ID:cubemoon,项目名称:GD,代码行数:58,代码来源:Extension.cpp


示例6: GenerateEventCode

gd::String ProfileEvent::GenerateEventCode(gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & parentContext)
{
    const gd::Layout & scene = codeGenerator.GetLayout();
    codeGenerator.AddIncludeFile("GDCpp/BuiltinExtensions/ProfileTools.h");

    ProfileLink profileLink;
    profileLink.originalEvent = originalEvent;
    std::cout << scene.GetProfiler() << std::endl;
    if ( scene.GetProfiler() ) //Should always be not NULL
    {
        scene.GetProfiler()->profileEventsInformation.push_back(profileLink);
        index = scene.GetProfiler()->profileEventsInformation.size()-1;
    }
    gd::String code;

    if ( previousProfileEvent )
        code += "EndProfileTimer(*runtimeContext->scene, "+gd::String::From(previousProfileEvent->index)+");\n";

    code += "StartProfileTimer(*runtimeContext->scene, "+gd::String::From(index)+");\n";

    return code;
}
开发者ID:sanyaade-teachings,项目名称:GD,代码行数:22,代码来源:ProfileEvent.cpp


示例7: GenerateEventCode

std::string BaseEvent::GenerateEventCode(gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)
{
    if ( IsDisabled() ) return "";

    try
    {
        if ( type.empty() ) return "";

        const gd::Platform & platform = codeGenerator.GetPlatform();

        //First try to guess the extension used
        std::string eventNamespace = type.substr(0, type.find("::"));
        std::shared_ptr<gd::PlatformExtension> guessedExtension = platform.GetExtension(eventNamespace);
        if ( guessedExtension )
        {
            std::map<std::string, gd::EventMetadata > & allEvents = guessedExtension->GetAllEvents();
            if ( allEvents.find(type) != allEvents.end() )
                return allEvents[type].codeGeneration(*this, codeGenerator, context);
        }


        //Else make a search in all the extensions
        for (unsigned int i = 0;i<platform.GetAllPlatformExtensions().size();++i)
        {
            std::shared_ptr<gd::PlatformExtension> extension = platform.GetAllPlatformExtensions()[i];
            if ( !extension ) continue;

            std::map<std::string, gd::EventMetadata > & allEvents = extension->GetAllEvents();
            if ( allEvents.find(type) != allEvents.end() )
                return allEvents[type].codeGeneration(*this, codeGenerator, context);
        }
    }
    catch(...)
    {
        std::cout << "ERROR: Exception caught during code generation for event \"" << type <<"\"." << std::endl;
    }

    return "";
}
开发者ID:AntonioModer,项目名称:GD,代码行数:39,代码来源:Event.cpp


示例8: Preprocess

void BaseEvent::Preprocess(gd::EventsCodeGenerator & codeGenerator, gd::EventsList & eventList, unsigned int indexOfTheEventInThisList)
{
    if ( IsDisabled() || !MustBePreprocessed() ) return;

    try
    {
        if ( type.empty() ) return;

        const gd::Platform & platform = codeGenerator.GetPlatform();

        //First try to guess the extension used
        std::string eventNamespace = type.substr(0, type.find("::"));
        boost::shared_ptr<gd::PlatformExtension> guessedExtension = platform.GetExtension(eventNamespace);
        if ( guessedExtension )
        {
            std::map<std::string, gd::EventMetadata > & allEvents = guessedExtension->GetAllEvents();
            if ( allEvents.find(type) != allEvents.end() && allEvents[type].codeGeneration )
                return allEvents[type].codeGeneration->Preprocess(*this, codeGenerator, eventList, indexOfTheEventInThisList);
        }


        //Else make a search in all the extensions
        for (unsigned int i = 0;i<platform.GetAllPlatformExtensions().size();++i)
        {
            boost::shared_ptr<gd::PlatformExtension> extension = platform.GetAllPlatformExtensions()[i];
            if ( !extension ) continue;

            std::map<std::string, gd::EventMetadata > & allEvents = extension->GetAllEvents();
            if ( allEvents.find(type) != allEvents.end() && allEvents[type].codeGeneration )
                return allEvents[type].codeGeneration->Preprocess(*this, codeGenerator, eventList, indexOfTheEventInThisList);
        }
    }
    catch(...)
    {
        std::cout << "ERROR: Exception caught during preprocessing of event \"" << type <<"\"." << std::endl;
    }
}
开发者ID:cubemoon,项目名称:GD,代码行数:37,代码来源:Event.cpp


示例9: code

std::string Array3DEvent::CodeGenerator::Generate(gd::BaseEvent & event_, gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext &context)
{
    arr::threeDim::Array3DEvent &event = dynamic_cast<arr::threeDim::Array3DEvent&>(event_);

            // Adding needed includes
            codeGenerator.AddIncludeFile("stack");
            codeGenerator.AddIncludeFile("Array/ArrayValue.h");
            codeGenerator.AddIncludeFile("Array/Array3D.h");
            codeGenerator.AddIncludeFile("Array/ArrayTools.h");

            //Adding the main code of the event
            std::string code("// 3D-Array Iterate Event\n");

            std::string arrayNameExpr;
            gd::CallbacksForGeneratingExpressionCode callbacks(arrayNameExpr, codeGenerator, context);
            gd::ExpressionParser parser(event.GetArrayName());
            parser.ParseStringExpression(codeGenerator.GetPlatform(), codeGenerator.GetProject(), codeGenerator.GetLayout(), callbacks);
            if (arrayNameExpr.empty()) arrayNameExpr = "\"\""; //If generation failed, we make sure output code is not empty.

            code += "arr::Array3D &currentArray = arr::ArrayManager::GetInstance()->GetArray3D(runtimeContext->scene->game, " + arrayNameExpr + ");\n";
            code += "for(unsigned int x = 0; x < currentArray.GetSize(1); x++)\n";
            code += "{\n";
            {
                code += "for(unsigned int y = 0; y < currentArray.GetSize(2); y++)\n";
                code += "{\n";
                {
                    code += "for(unsigned int z = 0; z < currentArray.GetSize(3); z++)\n";
                    code += "{\n";
                    {

                        code += "arr::ArrayManager::GetInstance()->GetArray3DEventInfo(runtimeContext->scene->game).PushNewEventInfo(x, y, z, currentArray.GetValue(x, y, z));";

                        // Generating condition/action/sub-event //
                        code += 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() ) code += "if (" +ifPredicat+ ")\n";

                        code += "{\n";
                        code += codeGenerator.GenerateActionsListCode(event.GetActions(), context);

                        if ( event.HasSubEvents() )
                        {
                            code += "\n{\n";
                            code += codeGenerator.GenerateEventsListCode(event.GetSubEvents(), context);
                            code += "}\n";
                        }

                        code += "}\n";
                        ///////////////////////////////////////////

                        code += "arr::ArrayManager::GetInstance()->GetArray3DEventInfo(runtimeContext->scene->game).PopEventInfo();";
                    }
                    code += "}\n";
                }
                code += "}\n";
            }
            code += "}\n";


            return code;
}
开发者ID:victorlevasseur,项目名称:GD-Array-Extension,代码行数:69,代码来源:Array3DEvent.cpp



注:本文中的gd::EventsCodeGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ gd::InitialInstance类代码示例发布时间:2022-05-31
下一篇:
C++ gd::ArbitraryResourceWorker类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap