Esempio n. 1
0
void EventsCodeGenerator::PreprocessEventList(gd::EventsList& eventsList) {
  if (!HasProjectAndLayout()) return;

  for (std::size_t i = 0; i < eventsList.size(); ++i) {
    eventsList[i].Preprocess(*this, eventsList, i);
    if (i < eventsList.size()) {  // Be sure that that there is still an event!
                                  // ( Preprocess can remove it. )
      if (eventsList[i].CanHaveSubEvents())
        PreprocessEventList(eventsList[i].GetSubEvents());
    }
  }
}
Esempio n. 2
0
std::set < std::string > EventsVariablesFinder::FindArgumentsInEvents(const gd::Platform & platform,
    const gd::Project & project, const gd::Layout & layout, const gd::EventsList & events,
    const std::string & parameterType, const std::string & objectName)
{
    std::set < std::string > results;
    for (unsigned int i = 0;i<events.size();++i)
    {
        vector < const vector<gd::Instruction>* > conditionsVectors =  events[i].GetAllConditionsVectors();
        for (unsigned int j = 0;j < conditionsVectors.size();++j)
        {
            std::set < std::string > results2 = FindArgumentsInInstructions(platform, project, layout, *conditionsVectors[j], /*conditions=*/true, parameterType, objectName);
            results.insert(results2.begin(), results2.end());
        }

        vector < const vector<gd::Instruction>* > actionsVectors =  events[i].GetAllActionsVectors();
        for (unsigned int j = 0;j < actionsVectors.size();++j)
        {
            std::set < std::string > results2 = FindArgumentsInInstructions(platform, project, layout, *actionsVectors[j], /*conditions=*/false, parameterType, objectName);
            results.insert(results2.begin(), results2.end());
        }

        if ( events[i].CanHaveSubEvents() )
        {
            std::set < std::string > results2 = FindArgumentsInEvents(platform, project, layout, events[i].GetSubEvents(), parameterType, objectName);
            results.insert(results2.begin(), results2.end());
        }
    }

    return results;
}
Esempio n. 3
0
void ArbitraryEventsWorker::VisitEventList(gd::EventsList & events)
{
	DoVisitEventList(events);

    for (unsigned int i = 0;i<events.size();++i)
    {
    	VisitEvent(events[i]);

        if (events[i].CanHaveSubEvents())
        	VisitEventList(events[i].GetSubEvents());
    }
}
Esempio n. 4
0
void EventsChangesNotifier::GetScenesAndExternalEventsLinkedTo(
    const gd::EventsList& events,
    gd::Project& project,
    std::vector<gd::Layout*>& layouts,
    std::vector<gd::ExternalEvents*>& externalEvents) {
  for (std::size_t i = 0; i < events.size(); ++i) {
    try {
      const gd::LinkEvent& linkEvent =
          dynamic_cast<const gd::LinkEvent&>(events[i]);

      // We've got a link event, search now linked scene/external events
      if (project.HasExternalEventsNamed(linkEvent.GetTarget())) {
        gd::ExternalEvents& linkedExternalEvents =
            project.GetExternalEvents(linkEvent.GetTarget());

        // Protect against circular references
        if (find(externalEvents.begin(),
                 externalEvents.end(),
                 &linkedExternalEvents) == externalEvents.end()) {
          externalEvents.push_back(&linkedExternalEvents);
          GetScenesAndExternalEventsLinkedTo(linkedExternalEvents.GetEvents(),
                                             project,
                                             layouts,
                                             externalEvents);
        }
      } else if (project.HasLayoutNamed(linkEvent.GetTarget())) {
        gd::Layout& linkedLayout = project.GetLayout(linkEvent.GetTarget());

        // Protect against circular references
        if (find(layouts.begin(), layouts.end(), &linkedLayout) ==
            layouts.end()) {
          layouts.push_back(&linkedLayout);
          GetScenesAndExternalEventsLinkedTo(
              linkedLayout.GetEvents(), project, layouts, externalEvents);
        }
      }
    } catch (...) {
    }

    if (events[i].CanHaveSubEvents())
      GetScenesAndExternalEventsLinkedTo(
          events[i].GetSubEvents(), project, layouts, externalEvents);
  }
}
Esempio n. 5
0
void EventsCodeGenerator::PreprocessEventList( gd::EventsList & eventsList )
{
    #if !defined(GD_NO_WX_GUI) //No support for profiling when wxWidgets is disabled.
    std::shared_ptr<ProfileEvent> previousProfileEvent;
    #endif

    for ( std::size_t i = 0;i < eventsList.size();++i )
    {
        eventsList[i].Preprocess(*this, eventsList, i);
        if ( i < eventsList.size() ) { //Be sure that that there is still an event! ( Preprocess can remove it. )
            if ( eventsList[i].CanHaveSubEvents() )
                PreprocessEventList( eventsList[i].GetSubEvents());

            #if !defined(GD_NO_WX_GUI) //No support for profiling when wxWidgets is disabled.
            if ( scene.GetProfiler() && scene.GetProfiler()->profilingActivated && eventsList[i].IsExecutable() )
            {
                //Define a new profile event
                std::shared_ptr<ProfileEvent> profileEvent = std::shared_ptr<ProfileEvent>(new ProfileEvent);
                profileEvent->originalEvent = eventsList[i].originalEvent;
                profileEvent->SetPreviousProfileEvent(previousProfileEvent);

                //Add it before the event to profile
                eventsList.InsertEvent(profileEvent, i);

                previousProfileEvent = profileEvent;
                ++i; //Don't preprocess the newly added profile event
            }
            #endif
        }
    }

    #if !defined(GD_NO_WX_GUI) //No support for profiling when wxWidgets is disabled.
    if ( !eventsList.IsEmpty() && scene.GetProfiler() && scene.GetProfiler()->profilingActivated )
    {
        //Define a new profile events
        std::shared_ptr<ProfileEvent> profileEvent = std::shared_ptr<ProfileEvent>(new ProfileEvent);
        profileEvent->SetPreviousProfileEvent(previousProfileEvent);

        //Add it at the end of the events list
        eventsList.InsertEvent(profileEvent, eventsList.GetEventsCount());
    }
    #endif
}
Esempio n. 6
0
bool DependenciesAnalyzer::Analyze(gd::EventsList & events, bool isOnTopLevel)
{
    for (unsigned int i = 0;i<events.size();++i)
    {
        try {
            gd::LinkEvent & linkEvent = dynamic_cast<gd::LinkEvent &>(events[i]);

            DependenciesAnalyzer analyzer(*this);

            std::string linked = linkEvent.GetTarget();
            if ( project.HasExternalEventsNamed(linked) )
            {
                if ( std::find(parentExternalEvents.begin(), parentExternalEvents.end(), linked) != parentExternalEvents.end() )
                    return false; //Circular dependency!

                externalEventsDependencies.insert(linked); //There is a direct dependency
                if ( !isOnTopLevel ) notTopLevelExternalEventsDependencies.insert(linked);
                analyzer.AddParentExternalEvents(linked);
                if ( !analyzer.Analyze(project.GetExternalEvents(linked).GetEvents(), isOnTopLevel) )
                    return false;

            }
            else if ( project.HasLayoutNamed(linked) )
            {
                if ( std::find(parentScenes.begin(), parentScenes.end(), linked) != parentScenes.end() )
                    return false; //Circular dependency!

                scenesDependencies.insert(linked); //There is a direct dependency
                if ( !isOnTopLevel ) notTopLevelScenesDependencies.insert(linked);
                analyzer.AddParentScene(linked);
                if ( !analyzer.Analyze(project.GetLayout(linked).GetEvents(), isOnTopLevel) )
                    return false;
            }

            //Update with indirect dependencies.
            scenesDependencies.insert(analyzer.GetScenesDependencies().begin(), analyzer.GetScenesDependencies().end());
            externalEventsDependencies.insert(analyzer.GetExternalEventsDependencies().begin(), analyzer.GetExternalEventsDependencies().end());
            sourceFilesDependencies.insert(analyzer.GetSourceFilesDependencies().begin(), analyzer.GetSourceFilesDependencies().end());
            notTopLevelScenesDependencies.insert(analyzer.GetNotTopLevelScenesDependencies().begin(), analyzer.GetNotTopLevelScenesDependencies().end());
            notTopLevelExternalEventsDependencies.insert(analyzer.GetNotTopLevelExternalEventsDependencies().begin(), analyzer.GetNotTopLevelExternalEventsDependencies().end());

            if ( !isOnTopLevel )
            {
                notTopLevelScenesDependencies.insert(analyzer.GetScenesDependencies().begin(), analyzer.GetScenesDependencies().end());
                notTopLevelExternalEventsDependencies.insert(analyzer.GetExternalEventsDependencies().begin(), analyzer.GetExternalEventsDependencies().end());
            }
        } catch(...) {}

        try {
            CppCodeEvent & cppCodeEvent = dynamic_cast<CppCodeEvent &>(events[i]);

            const std::vector<std::string> & dependencies = cppCodeEvent.GetDependencies();
            sourceFilesDependencies.insert(dependencies.begin(), dependencies.end());
            sourceFilesDependencies.insert(cppCodeEvent.GetAssociatedGDManagedSourceFile(project));
        } catch(...) {}

        if ( events[i].CanHaveSubEvents() )
        {
            if ( !Analyze(events[i].GetSubEvents(), false) )
                return false;
        }
    }

    return true;
}
Esempio n. 7
0
void LaunchResourceWorkerOnEvents(const gd::Project & project, gd::EventsList & events, gd::ArbitraryResourceWorker & worker)
{
    //Get all extensions used
    std::vector< std::shared_ptr<gd::PlatformExtension> > allGameExtensions;
    std::vector<gd::String> usedExtensions = project.GetUsedExtensions();
    for (std::size_t i = 0;i<usedExtensions.size();++i)
    {
        std::shared_ptr<gd::PlatformExtension> extension = project.GetCurrentPlatform().GetExtension(usedExtensions[i]);

        if ( extension != std::shared_ptr<gd::PlatformExtension>() )
            allGameExtensions.push_back(extension);
    }

    for ( std::size_t j = 0;j < events.size() ;j++ )
    {
        vector < gd::InstructionsList* > allActionsVectors = events[j].GetAllActionsVectors();
        for (std::size_t i = 0;i<allActionsVectors.size();++i)
        {
            for ( std::size_t k = 0;k < allActionsVectors[i]->size() ;k++ )
            {
                gd::String type = allActionsVectors[i]->Get( k ).GetType();
                for (std::size_t e = 0;e<allGameExtensions.size();++e)
                {
                    bool extensionHasAction = false;

                    const std::map<gd::String, gd::InstructionMetadata> & allActions = allGameExtensions[e]->GetAllActions();
                    if ( allActions.find(type) != allActions.end() )
                        extensionHasAction = true;

                    const vector < gd::String > & objects = allGameExtensions[e]->GetExtensionObjectsTypes();
                    for (std::size_t o = 0;o<objects.size();++o)
                    {
                        const std::map<gd::String, gd::InstructionMetadata> & allObjectsActions = allGameExtensions[e]->GetAllActionsForObject(objects[o]);
                        if ( allObjectsActions.find(type) != allObjectsActions.end() )
                            extensionHasAction = true;
                    }

                    const vector < gd::String > & autos = allGameExtensions[e]->GetBehaviorsTypes();
                    for (std::size_t a = 0;a<autos.size();++a)
                    {
                        const std::map<gd::String, gd::InstructionMetadata> & allAutosActions = allGameExtensions[e]->GetAllActionsForBehavior(autos[a]);
                        if ( allAutosActions.find(type) != allAutosActions.end() )
                            extensionHasAction = true;
                    }

                    if ( extensionHasAction )
                    {
                        allGameExtensions[e]->ExposeActionsResources(allActionsVectors[i]->Get( k ), worker);
                        break;
                    }
                }

            }
        }

        vector < gd::InstructionsList* > allConditionsVector = events[j].GetAllConditionsVectors();
        for (std::size_t i = 0;i<allConditionsVector.size();++i)
        {
            for ( std::size_t k = 0;k < allConditionsVector[i]->size() ;k++ )
            {
                gd::String type = allConditionsVector[i]->Get( k ).GetType();
                for (std::size_t e = 0;e<allGameExtensions.size();++e)
                {
                    bool extensionHasCondition = false;

                    const std::map<gd::String, gd::InstructionMetadata> & allConditions = allGameExtensions[e]->GetAllConditions();
                    if ( allConditions.find(type) != allConditions.end() )
                        extensionHasCondition = true;

                    const vector < gd::String > & objects = allGameExtensions[e]->GetExtensionObjectsTypes();
                    for (std::size_t j = 0;j<objects.size();++j)
                    {
                        const std::map<gd::String, gd::InstructionMetadata> & allObjectsConditions = allGameExtensions[e]->GetAllConditionsForObject(objects[j]);
                        if ( allObjectsConditions.find(type) != allObjectsConditions.end() )
                            extensionHasCondition = true;
                    }

                    const vector < gd::String > & autos = allGameExtensions[e]->GetBehaviorsTypes();
                    for (std::size_t j = 0;j<autos.size();++j)
                    {
                        const std::map<gd::String, gd::InstructionMetadata> & allAutosConditions = allGameExtensions[e]->GetAllConditionsForBehavior(autos[j]);
                        if ( allAutosConditions.find(type) != allAutosConditions.end() )
                            extensionHasCondition = true;
                    }

                    if ( extensionHasCondition ) allGameExtensions[e]->ExposeConditionsResources(allConditionsVector[i]->Get( k ), worker);
                }

            }
        }

        if ( events[j].CanHaveSubEvents() )
            LaunchResourceWorkerOnEvents(project, events[j].GetSubEvents(), worker);
    }

    return;
}