예제 #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
}
예제 #2
0
void EventsChangesNotifier::NotifyChangesInEventsOfScene(gd::Project& project,
                                                         gd::Layout& layout) {
  for (std::size_t j = 0; j < project.GetUsedPlatforms().size(); ++j)
    project.GetUsedPlatforms()[j]->GetChangesNotifier().OnEventsModified(
        project, layout);

  // Notify others scenes, which include the changed scene ( even indirectly ),
  // that their events has changed
  for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) {
    if (&project.GetLayout(i) == &layout) continue;

    std::vector<gd::Layout*> linkedScenes;
    std::vector<gd::ExternalEvents*> notUsed;

    GetScenesAndExternalEventsLinkedTo(
        project.GetLayout(i).GetEvents(), project, linkedScenes, notUsed);

    for (std::size_t j = 0; j < linkedScenes.size(); ++j) {
      if (linkedScenes[j]->GetName() == layout.GetName()) {
        for (std::size_t k = 0; k < project.GetUsedPlatforms().size(); ++k)
          project.GetUsedPlatforms()[k]->GetChangesNotifier().OnEventsModified(
              project,
              project.GetLayout(i),
              /*indirectChange=*/true,
              layout.GetName());
      }
    }
  }
  // Also notify external events
  for (std::size_t i = 0; i < project.GetExternalEventsCount(); ++i) {
    std::vector<gd::Layout*> linkedScenes;
    std::vector<gd::ExternalEvents*> notUsed;

    GetScenesAndExternalEventsLinkedTo(project.GetExternalEvents(i).GetEvents(),
                                       project,
                                       linkedScenes,
                                       notUsed);

    for (std::size_t j = 0; j < linkedScenes.size(); ++j) {
      if (linkedScenes[j]->GetName() == layout.GetName()) {
        for (std::size_t k = 0; k < project.GetUsedPlatforms().size(); ++k)
          project.GetUsedPlatforms()[k]->GetChangesNotifier().OnEventsModified(
              project,
              project.GetExternalEvents(i),
              /*indirectChange=*/true,
              layout.GetName());
      }
    }
  }
}
예제 #3
0
void CodeCompiler::DisableTaskRelatedTo(gd::Layout & scene)
{
    sf::Lock lock(pendingTasksMutex); //Disallow modifying pending tasks.

    std::cout << "Disabling tasks related to scene:" << scene.GetName() << endl;

    vector<Scene*>::iterator it = find(compilationDisallowed.begin(), compilationDisallowed.end(), &scene);
    if ( it == compilationDisallowed.end())
        compilationDisallowed.push_back(&scene);
}
예제 #4
0
gd::String EventsCodeGenerator::GenerateSceneEventsCompleteCode(
    gd::Project& project,
    gd::Layout& scene,
    const gd::EventsList& events,
    bool compilationForRuntime) {
  // Preprocessing then code generation can make changes to the events, so we
  // need to do the work on a copy of the events.
  gd::EventsList generatedEvents = events;

  gd::String output;

  // Prepare the global context ( Used to get needed header files )
  gd::EventsCodeGenerationContext context;
  EventsCodeGenerator codeGenerator(project, scene);

  // Generate whole events code
  codeGenerator.SetGenerateCodeForRuntime(compilationForRuntime);
  codeGenerator.PreprocessEventList(generatedEvents);
  gd::String wholeEventsCode =
      codeGenerator.GenerateEventsListCode(generatedEvents, context);

  // Generate default code around events:
  // Includes
  output +=
      "#include <vector>\n#include <map>\n#include <string>\n#include "
      "<algorithm>\n#include <SFML/System/Clock.hpp>\n#include "
      "<SFML/System/Vector2.hpp>\n#include <SFML/Graphics/Color.hpp>\n#include "
      "\"GDCpp/Runtime/RuntimeContext.h\"\n#include "
      "\"GDCpp/Runtime/RuntimeObject.h\"\n";
  for (set<gd::String>::iterator include =
           codeGenerator.GetIncludeFiles().begin();
       include != codeGenerator.GetIncludeFiles().end();
       ++include)
    output += "#include \"" + *include + "\"\n";

  // Extra declarations needed by events
  for (set<gd::String>::iterator declaration =
           codeGenerator.GetCustomGlobalDeclaration().begin();
       declaration != codeGenerator.GetCustomGlobalDeclaration().end();
       ++declaration)
    output += *declaration + "\n";

  output += codeGenerator.GetCustomCodeOutsideMain() +
            "\n"
            "extern \"C\" int GDSceneEvents" +
            gd::SceneNameMangler::GetMangledSceneName(scene.GetName()) +
            "(RuntimeContext * runtimeContext)\n"
            "{\n" +
            "runtimeContext->StartNewFrame();\n" + wholeEventsCode +
            "return 0;\n"
            "}\n";

  return output;
}
예제 #5
0
void GD_API CodeCompilationHelpers::CreateSceneEventsCompilationTask(gd::Project & game, gd::Layout & scene)
{
    CodeCompilerTask task;
    task.compilerCall.compilationForRuntime = false;
    task.compilerCall.optimize = false;
    task.compilerCall.eventsGeneratedCode = true;
    task.compilerCall.inputFile = string(CodeCompiler::Get()->GetOutputDirectory()+"GD"+ToString(&scene)+"EventsSource.cpp");
    task.compilerCall.outputFile = string(CodeCompiler::Get()->GetOutputDirectory()+"GD"+ToString(&scene)+"ObjectFile.o");
    task.scene = &scene;
    task.preWork = std::shared_ptr<CodeCompilerExtraWork>(new EventsCodeCompilerPreWork(&game, &scene));
    task.postWork = std::shared_ptr<CodeCompilerExtraWork>(new EventsCodeCompilerPostWork(&game, &scene));
    task.userFriendlyName = "Compilation of events of scene "+scene.GetName();

    CodeCompiler::Get()->AddTask(task);
}
예제 #6
0
void CodeCompiler::EnableTaskRelatedTo(gd::Layout & scene)
{
    bool mustLaunchCompilation = false;
    {
        sf::Lock lock(pendingTasksMutex); //Disallow modifying pending tasks.

        std::cout << "Enabling tasks related to scene:" << scene.GetName() << endl;

        vector<Scene*>::iterator it = find(compilationDisallowed.begin(), compilationDisallowed.end(), &scene);
        if ( it != compilationDisallowed.end())
            compilationDisallowed.erase(it);

        mustLaunchCompilation = !pendingTasks.empty();
    }

    //Launch pending tasks if needed
    if ( !processLaunched && mustLaunchCompilation )
    {
        std::cout << "Launching compilation thread...";
        processLaunched = true;
        StartTheNextTask();
    }
}
예제 #7
0
void ExternalLayoutEditor::SetupForScene(gd::Layout & layout)
{
    bool useExternalEditor = false;
    wxConfigBase::Get()->Read("/SceneEditor/ExternalSceneEditor", &useExternalEditor, false);

    if ( &layout == &emptyLayout )
    {
        layoutPanel->Hide();
        externalEditorPanel->Hide();
        helpPanel->Show();
    }
    else
    {
		if (useExternalEditor)
		{
	        layoutPanel->Hide();
	        externalEditorPanel->Show();
	        helpPanel->Hide();

	        CreateExternalLayoutEditor();
		} else {
	        layoutPanel->Show();
	        externalEditorPanel->Hide();
	        helpPanel->Hide();
		}

        gd::InitialInstancesContainer & instanceContainer = externalLayout.GetInitialInstances();

        //Destroy any existing editor
        if (objectsEditor != std::shared_ptr<ObjectsEditor>())
            m_mgr.DetachPane(objectsEditor.get());
        if (layersEditor != std::shared_ptr<LayersEditorPanel>())
            m_mgr.DetachPane(layersEditor.get());
        if (propertiesPnl != std::shared_ptr<LayoutEditorPropertiesPnl>())
            m_mgr.DetachPane(propertiesPnl.get());
        if (initialInstancesBrowser != std::shared_ptr<InitialPositionBrowserDlg>())
            m_mgr.DetachPane(initialInstancesBrowser.get());

        //(Re)create layout canvas
        if ( layoutEditorCanvas ) delete layoutEditorCanvas;
        layoutEditorCanvas = new gd::LayoutEditorCanvas(layoutPanel, project, layout, instanceContainer, externalLayout.GetAssociatedSettings(), mainFrameWrapper, &externalLayout);
        layoutEditorCanvas->SetParentAuiManager( &m_mgr );
        layoutEditorCanvas->SetScrollbars(scrollBar1, scrollBar2);

        //Creating external editors and linking them to the layout canvas
        objectsEditor = std::make_shared<gd::ObjectsEditor>(this, project, layout, mainFrameWrapper);
        layersEditor = std::make_shared<LayersEditorPanel>(this, project, layout, mainFrameWrapper);
        propertiesPnl = std::make_shared<LayoutEditorPropertiesPnl>(this, project, layout, layoutEditorCanvas, mainFrameWrapper);
        initialInstancesBrowser = std::make_shared<InitialPositionBrowserDlg>(this, instanceContainer, *layoutEditorCanvas);

        layoutEditorCanvas->AddAssociatedEditor(objectsEditor.get());
        layoutEditorCanvas->AddAssociatedEditor(layersEditor.get());
        layoutEditorCanvas->AddAssociatedEditor(propertiesPnl.get());
        layoutEditorCanvas->AddAssociatedEditor(initialInstancesBrowser.get());
        layersEditor->SetAssociatedLayoutEditorCanvas(layoutEditorCanvas);
        objectsEditor->SetAssociatedPropertiesPanel(propertiesPnl.get(), &m_mgr);

        //Display editors in panes
        m_mgr.AddPane( objectsEditor.get(), wxAuiPaneInfo().Name( wxT( "EO" ) ).Right().CloseButton( true ).Caption( _( "Objects' editor" ) ).MaximizeButton( true ).MinimizeButton( false ).CaptionVisible(true).MinSize(208, 100) );
        m_mgr.AddPane( layersEditor.get(), wxAuiPaneInfo().Name( wxT( "EL" ) ).Right().CloseButton( true ).Caption( _( "Layers' editor" ) ).MaximizeButton( true ).MinimizeButton( false ).CaptionVisible(true).MinSize(208, 100).Show(false) );
        m_mgr.AddPane( propertiesPnl.get(), wxAuiPaneInfo().Name( wxT( "PROPERTIES" ) ).Float().CloseButton( true ).Caption( _( "Properties" ) ).MaximizeButton( true ).MinimizeButton( false ).CaptionVisible(true).MinSize(50, 50).BestSize(230,200).Show(true) );
        m_mgr.AddPane( initialInstancesBrowser.get(), wxAuiPaneInfo().Name( wxT( "InstancesBrowser" ) ).Float().CloseButton( true ).Caption( _( "Instances list" ) ).MaximizeButton( true ).MinimizeButton( false ).CaptionVisible(true).MinSize(50, 50).BestSize(230,200).Show(true) );

        wxString perspective;
        wxConfigBase::Get()->Read("/ExternalLayoutEditor/LastWorkspace", &perspective);
        m_mgr.LoadPerspective(perspective);

		objectsEditor->OnChange([this](gd::String changeScope) {
			if (!externalLayoutEditor) return;

			if (changeScope == "object-added")
				externalLayoutEditor->SendUpdate("", true);
			else
				externalLayoutEditor->SetDirty();
		});
		layersEditor->OnChange([this](gd::String changeScope) {
			if (externalLayoutEditor) externalLayoutEditor->SetDirty();
		});

        m_mgr.Update();
        EditorDisplayed();
    }

    //Save the choice
    externalLayout.SetAssociatedLayout(layout.GetName());

    if (onAssociatedLayoutChangedCb) onAssociatedLayoutChangedCb();
}