2015/9/16 Roslyn Paradox LiveScripting

0eb58d770d6e4766150ef7cb6cdce3c7?s=47 Akiko Kawai
September 16, 2015
280

2015/9/16 Roslyn Paradox LiveScripting

Metro.cs #1 2015/9/16 ParadoxのLiveScripting事情 遥佐保
PPTX→ http://jyurimaru.info/data/20150916ParadoxLiveScripting/20150916_RoslynParadoxLiveScripting.pptx

0eb58d770d6e4766150ef7cb6cdce3c7?s=128

Akiko Kawai

September 16, 2015
Tweet

Transcript

  1. None
  2. None
  3. http://paradox3d.net https://github.com/SiliconStudio/paradox

  4. None
  5. None
  6. Paradox Game Studio Visual Studio Running EXE Roslyn利用

  7. None
  8. None
  9. Roslyn/MSBuild Project Part0-csproj Player.cs Part1-csproj Enemy.cs Player.dll Player.pdb Enemy.dll Enemy.pdb

    ↑こんなsln構成 だと思いますが WCF pipe
  10. None
  11. Game用のプロジェクトを新規作成 using Microsoft.CodeAnalysis private async Task<Project> OpenProject(string projectPath) { var

    csharpWorkspaceAssemblies = new[]{ System.Reflection.Assembly.Load("Microsoft.CodeAnalysis.Workspaces"), System.Reflection.Assembly.Load("Microsoft.CodeAnalysis.CSharp.Workspaces"), System.Reflection.Assembly.Load("Microsoft.CodeAnalysis.Workspaces.Desktop") }; var msWorkspace = MSBuildWorkspace.Create( ImmutableDictionary<string, string>.Empty, MefHostServices.Create(csharpWorkspaceAssemblies)); return await msWorkspace.OpenProjectAsync(projectPath); }
  12. Game用プロジェクトを新規に作成する 元Projectと”同じ様な”構造、だが1ファイルづつ var newproject = solution.AddProject(assemblyName, assemblyName, LanguageNames.CSharp) .WithMetadataReferences(motoProject.MetadataReferences) .WithProjectReferences(motoProject.AllProjectReferences)

    .WithCompilationOptions( new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); // ソースコードの追加 Newproject = newproject.AddDocument(syntaxTree.FilePath, syntaxTree.GetText()).Project; // 他のソースコードの参照があれば追加(※しれっと……???) project = newproject.AddProjectReference( new ProjectReference(dependencySourceGroup.Target.Project.Id));
  13. http://quickgraph.codeplex.com/ QuickGraph.AdjacencyGraph<SyntaxTree, SEdge<SyntaxTree>> QuickGraph.AdjacencyGraph

  14. Roslynでコンパイル、1ファイルづつ var compilation = await newproject.GetCompilationAsync();

  15. None
  16. MSBuildで改めて実際にコンパイル Task<BuildResult> BuildTask { get; private set; } Microsoft.Build.Evaluation.Project project;

    var projectInstance = new ProjectInstance( project.Xml, project.ProjectCollection.GlobalProperties, null, project.ProjectCollection); BuildTask = Task.Run(() =>{ … new BuildParameters BuildParameters(project.ProjectCollection) … }
  17. できたDLLをメモリに保存 // sourceGroupとは独自で作ったクラス // - PE(dllファイル) // - PDB //

    - Microsoft.CodeAnalysis.Project // - Mono.Cecil.AssemblyDefinition (ParadoxではScriptのシリアライズに利用している) sourceGroup.PE = File.ReadAllBytes(peFileName); sourceGroup.PDB = File.ReadAllBytes(pdbFileName);
  18. None
  19. WCF pipe通信 // gameDebuggerHostとは独自で作ったクラス // 今から起動させるアプリケーションのこと ServiceHost = new System.ServiceModel.ServiceHost(gameDebuggerHost);

    ServiceHost.AddServiceEndpoint( typeof(IGameDebuggerHost), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = int.MaxValue }, address); ServiceHost.Open(); var startInfo = new ProcessStartInfo{ FileName = gameHostAssembly, Arguments = "—-host=net.pipe://localhost/xxx", WorkingDirectory = workingDirectory, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; var process = new System.Diabnostics.Process { StartInfo = startInfo }; process.Start();
  20. None
  21. Paradox Game Studio FileSystemWatcher

  22. FileSystemWatcher public Watcher(string path) { watcher = new FileSystemWatcher(){ Path

    = path, NotifyFilter = ( NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName), IncludeSubdirectories = true, Filter = "" }; watcher.BeginInit(); watcher.Changed += OnModified; watcher.Created += OnModified; watcher.Deleted += OnModified; watcher.Renamed += OnModified; watcher.EndInit(); }
  23. None
  24. Roslyn/MSBuild Project Part0-csproj Player.cs Part1-csproj Enemy.cs Player.dll Player.pdb Enemy.dll Enemy.pdb

  25. None
  26. Running EXE Paradox Game Studio // Target(Running EXE)に送って実行させる(DLLのSwap) // Game

    Studioは何もしていない debugTarget.AssemblyLoadRaw( loadedProject.PE, loadedProject.PDB); // 実際にSwapを実行しているのは、Running EXE側 public Assembly AssemblyLoadRaw(byte[] peData, byte[] pdbData) { return Assembly.Load(peData, pdbData); } https://github.com/SiliconStudio/paradox/blob/master/sources/engine/Silicon Studio.Paradox.Debugger/Debugger/GameDebuggerTarget.cs DLL Hot Swap .NETだから可能な技術
  27. None
  28. Running EXE https://github.com/SiliconStudio/paradox/blob/master/sources/engine/SiliconStudio.Paradox.Debugger/De bugger/LiveAssemblyReloader.cs

  29. Paradox Game Studio Visual Studio Running EXE Roslyn利用

  30. None
  31. None
  32. https://www.surveymonkey.com/r/YGD8VYH

  33. 33 Windowsアプリ操作系最強! Is a magical library! It break through the

    walls of processes. NuGetで「めとべや」で検索! ひらがなで引っかかるのはこれだけ!? 9/19 Friendlyハンズオン at SHIFT様 3名様に9/20発売のSeleniumデザパタ本をプレゼント! めとべや公式ライブラリもあり! 友達だから何でもできる!
  34. None