Ejemplo n.º 1
0
void ChangesNotifier::OnEventsModified(
    gd::Project& game,
    gd::Layout& scene,
    bool indirectChange,
    gd::String sourceOfTheIndirectChange) const {
#if !defined(GD_NO_WX_GUI)  // Compilation is not supported when wxWidgets
                            // support is disabled.
  std::cout << "Changes occured inside " << scene.GetName() << "...";

  scene.SetRefreshNeeded();
  if (!indirectChange ||
      !game.HasExternalEventsNamed(
          sourceOfTheIndirectChange))  // Changes occured directly in the scene:
                                       // Recompile it.
  {
    scene.SetCompilationNeeded();
    CodeCompilationHelpers::CreateSceneEventsCompilationTask(game, scene);
    std::cout << "Recompilation triggered." << std::endl;
  } else {
    DependenciesAnalyzer analyzer(
        game, game.GetExternalEvents(sourceOfTheIndirectChange));
    if (analyzer.ExternalEventsCanBeCompiledForAScene() == scene.GetName()) {
      // Do nothing: Changes occured in an external event which is compiled
      // separately
      std::cout << "But nothing to do." << std::endl;
    } else {
      // Changes occurred in an external event which is directly included in the
      // scene events.
      scene.SetCompilationNeeded();
      std::cout << "Recompilation asked for later." << std::endl;
    }
  }
#endif
}
Ejemplo n.º 2
0
void LinkEvent::ReplaceLinkByLinkedEvents(gd::Project & project, EventsList & eventList, unsigned int indexOfTheEventInThisList)
{
    //Finding what to link to.
    const EventsList * eventsToInclude = NULL;
    gd::ExternalEvents * linkedExternalEvents = NULL;
    if ( project.HasExternalEventsNamed(GetTarget()) )
    {
        linkedExternalEvents = &project.GetExternalEvents(GetTarget());
        eventsToInclude = &project.GetExternalEvents(GetTarget()).GetEvents();
    }
    else if ( project.HasLayoutNamed(GetTarget()) ) eventsToInclude = &project.GetLayout(GetTarget()).GetEvents();

    if ( eventsToInclude != NULL )
    {
        unsigned int firstEvent = IncludeAllEvents() ? 0 : GetIncludeStart();
        unsigned int lastEvent = IncludeAllEvents() ? eventsToInclude->size() - 1 : GetIncludeEnd();

        //Check bounds
        if ( firstEvent >= eventsToInclude->size() )
        {
            std::cout << "Unable to get events from a link ( Invalid start )" << std::endl;
            linkWasInvalid = true;
            return;
        }
        if ( lastEvent >= eventsToInclude->size() )
        {
            std::cout << "Unable to get events from a link ( Invalid end )" << std::endl;
            linkWasInvalid = true;
            return;
        }
        if ( firstEvent > lastEvent )
        {
            std::cout << "Unable to get events from a link ( End is before start )" << std::endl;
            linkWasInvalid = true;
            return;
        }

        //Insert an empty event to replace the link event ( we'll delete the link event at the end )
        //( If we just erase the link event without adding a blank event to replace it,
        //the first event inserted by the link will not be preprocessed ( and it can be annoying if it require preprocessing, such as another link event ). )
        gd::EmptyEvent emptyEvent;
        eventList.InsertEvent(emptyEvent, indexOfTheEventInThisList);
        eventList.InsertEvents(*eventsToInclude, firstEvent, lastEvent, indexOfTheEventInThisList+1);

        //Delete the link event ( which is now at the end of the list of events we've just inserted )
        eventList.RemoveEvent(indexOfTheEventInThisList + 1 + static_cast<unsigned>(lastEvent-firstEvent)+1);
    }
    else
    {
        std::cout << "Unable to get events from a link." << std::endl;
        linkWasInvalid = true;

        //Delete the link event
        eventList.RemoveEvent(indexOfTheEventInThisList);
        return;
    }

    linkWasInvalid = false;
}
Ejemplo n.º 3
0
void ChangesNotifier::RequestFullRecompilation(gd::Project& game,
                                               gd::Layout* scene) const {
#if !defined(GD_NO_WX_GUI)  // Compilation is not supported when wxWidgets
                            // support is disabled.
  if (scene) {
    // Notify the scene it has been changed...
    scene->SetRefreshNeeded();

    //...as well as the dependencies
    DependenciesAnalyzer analyzer(game, *scene);
    if (!analyzer.Analyze()) {
      std::cout << "WARNING: Circular dependency for scene " << scene->GetName()
                << std::endl;
      return;
    }

    std::set<gd::String> externalEventsDependencies =
        analyzer.GetExternalEventsDependencies();
    for (std::set<gd::String>::const_iterator i =
             externalEventsDependencies.begin();
         i != externalEventsDependencies.end();
         ++i) {
      if (game.HasExternalEventsNamed(*i))
        game.GetExternalEvents(*i).SetLastChangeTimeStamp(
            wxDateTime::Now().GetTicks());
    }

    // And ask for a recompilation of everything.
    CodeCompilationHelpers::CreateSceneEventsCompilationTask(game, *scene);
  } else  // Scene pointer is NULL: Mark all scenes as modified
  {
    for (std::size_t i = 0; i < game.GetLayoutsCount(); ++i) {
      game.GetLayout(i).SetRefreshNeeded();
      game.GetLayout(i).SetCompilationNeeded();
    }
    for (std::size_t i = 0; i < game.GetExternalEventsCount(); ++i) {
      game.GetExternalEvents(i).SetLastChangeTimeStamp(
          wxDateTime::Now()
              .GetTicks());  // Do no forget external events as they can have
                             // been compiled separately from scenes.
    }
  }
#endif
}
Ejemplo 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);
  }
}
Ejemplo n.º 5
0
void ChangesNotifier::OnEventsModified(
    gd::Project& game,
    gd::ExternalEvents& events,
    bool indirectChange,
    gd::String sourceOfTheIndirectChange) const {
#if !defined(GD_NO_WX_GUI)  // Compilation is not supported when wxWidgets
                            // support is disabled.
  DependenciesAnalyzer analyzer(game, events);
  gd::String associatedScene = analyzer.ExternalEventsCanBeCompiledForAScene();
  bool externalEventsAreCompiledSeparately = !associatedScene.empty();

  if (!externalEventsAreCompiledSeparately) return;

  std::cout << "Changes occured inside " << events.GetName()
            << " (compiled separately)..." << std::endl;

  // The external events are compiled separately from the scene events:
  // We need to recompile them if the changes occured inside them.

  if (!indirectChange ||
      !game.HasExternalEventsNamed(sourceOfTheIndirectChange)) {
    // Changes occurred directly inside the external events: We need to
    // recompile them
    events.SetLastChangeTimeStamp(wxDateTime::Now().GetTicks());
    CodeCompilationHelpers::CreateExternalEventsCompilationTask(game, events);
    std::cout << "Recompilation triggered." << std::endl;
  } else {
    DependenciesAnalyzer analyzer(
        game, game.GetExternalEvents(sourceOfTheIndirectChange));
    if (analyzer.ExternalEventsCanBeCompiledForAScene() == associatedScene) {
      // Do nothing: Changes occurred in an external event which is compiled
      // separately
      std::cout << "But nothing to do." << std::endl;
    } else {
      // Changes occurred in an another external event which is directly
      // included in our external events.
      events.SetLastChangeTimeStamp(wxDateTime::Now().GetTicks());
      CodeCompilationHelpers::CreateExternalEventsCompilationTask(game, events);
      std::cout << "Recompilation triggered." << std::endl;
    }
  }
#endif
}