Skip to content

Commit

Permalink
Removal of the messaging system.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Apr 13, 2024
1 parent 68be708 commit 9ae2c7a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 109 deletions.
68 changes: 26 additions & 42 deletions FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace CompilerPlugin
public class CompilerPlugin : PluginBase
{

public override string FriendlyName => "Compiler Plugin";

public override Version Version => new Version(1, 0);
public override bool ShutDown(PluginShutDownReason shutDownReason)
{
return true;
Expand Down Expand Up @@ -87,9 +90,6 @@ public void HandleCompilerViewModelPropertyChanged(object sender, PropertyChange
}
}

public override string FriendlyName => "Compiler Plugin";

public override Version Version => new Version(1, 0);
#endregion

#region Private Methods
Expand Down Expand Up @@ -227,51 +227,35 @@ public override void HandleEvent(string eventName, string payload)
}
}

protected override async Task<string> HandleEventWithReturnImplementation(string eventName, string payload)
public Task KillGameProcess() => _runner.KillGameProcess();

public async Task Compile(string configuration, bool printMsBuildCommand, CompileGeneralResponse generalResponse)
{
switch (eventName)

try
{
case "Compiler_DoCompile":
{
var settings = JObject.Parse(payload);
try
{
var result = await _compiler.Compile(
(value) =>
ReactToPluginEvent("Compiler_Output_Standard", value),
(value) =>
ReactToPluginEvent("Compiler_Output_Error", value),
settings.ContainsKey("Configuration") ? settings.Value<string>("Configuration") : _compilerViewModel.Configuration,
settings.ContainsKey("PrintMsBuildCommand") ? settings.Value<bool>("PrintMsBuildCommand") : _compilerViewModel.IsPrintMsBuildCommandChecked
);

return JsonConvert.SerializeObject(result);
}
catch (Exception ex)
{
return JsonConvert.SerializeObject(new CompileGeneralResponse
{
Succeeded = false,
Message = ex.ToString()
});
}
}
var result = await _compiler.Compile(
(value) => ReactToPluginEvent("Compiler_Output_Standard", value),
(value) => ReactToPluginEvent("Compiler_Output_Error", value),
configuration,
printMsBuildCommand
);

case "Runner_DoRun":
{
var settings = JObject.Parse(payload);
var preventFocus = settings.ContainsKey("PreventFocus") ? settings.Value<bool>("PreventFocus") : false;
var runArguments = settings.ContainsKey("RunArguments") ? settings.Value<string>("RunArguments") : "";
var runResponse =
await _runner.Run(preventFocus, runArguments);
return JsonConvert.SerializeObject(runResponse);
}
case "Runner_Kill":
return await _runner.KillGameProcess();
generalResponse.SetFrom(result);
}
catch (Exception ex)
{
generalResponse.Succeeded = false;
generalResponse.Message = ex.ToString();
}
}

return null;
public async Task DoRun(bool preventFocus, string runArguments, GeneralResponse generalResponse)
{
var response = await _runner.Run(preventFocus, runArguments);
generalResponse.SetFrom(response);
}

#endregion

#region Classes
Expand Down
10 changes: 6 additions & 4 deletions FRBDK/Glue/CompilerPlugin/Managers/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ internal async Task<CompileGeneralResponse> Compile(Action<string> printOutput,
}
}

succeeded = await StartMsBuildWithParameters(printOutput, printError, startOutput, endOutput, arguments, msBuildPath);
succeeded = StartMsBuildWithParameters(printOutput, printError, startOutput, endOutput, arguments, msBuildPath);
}

#endregion
Expand Down Expand Up @@ -274,7 +274,7 @@ internal async Task<CompileGeneralResponse> Compile(Action<string> printOutput,
printOutput?.Invoke($"\"{msBuildPath}\" {arguments}");
}

succeeded = await StartMsBuildWithParameters(printOutput, printError, startOutput, endOutput, arguments, msBuildPath);
succeeded = StartMsBuildWithParameters(printOutput, printError, startOutput, endOutput, arguments, msBuildPath);
}

#endregion
Expand Down Expand Up @@ -320,7 +320,7 @@ internal async Task<CompileGeneralResponse> Compile(Action<string> printOutput,
return toReturn;
}

private async Task<bool> StartMsBuildWithParameters(Action<string> printOutput, Action<string> printError, string startOutput, string endOutput, string arguments, string msbuildLocation)
private bool StartMsBuildWithParameters(Action<string> printOutput, Action<string> printError, string startOutput, string endOutput, string arguments, string msbuildLocation)
{
var effectiveMsBuildLocation = msBuildLocation == "dotnet" ? "dotnet" : $"\"{msbuildLocation}\"";
Process process = CreateProcess(effectiveMsBuildLocation, arguments);
Expand All @@ -331,7 +331,9 @@ private async Task<bool> StartMsBuildWithParameters(Action<string> printOutput,
StringBuilder outputStringBuilder = new StringBuilder();
StringBuilder errorStringBuilder = new StringBuilder();

var errorString = await Task.Run(() => RunProcess(outputStringBuilder, errorStringBuilder, msbuildLocation, process));
// This puts the task on a different thread, we don't want that!
//var errorString = await Task.Run(() => RunProcess(outputStringBuilder, errorStringBuilder, msbuildLocation, process));
var errorString = RunProcess(outputStringBuilder, errorStringBuilder, msbuildLocation, process);

if (outputStringBuilder.Length > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using FlatRedBall.Glue.Plugins.ExportedInterfaces.CommandInterfaces;
using System.Security.Permissions;
using Microsoft.Xna.Framework.Graphics;
using GeneralResponse = ToolsUtilities.GeneralResponse;

namespace GameCommunicationPlugin.GlueControl
{
Expand Down Expand Up @@ -344,10 +345,9 @@ public async Task BuildAndRun()

if(innerResult == MessageBoxResult.Yes)
{
await ReactToPluginEventWithReturn("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = false
}));
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun",
false, // preventFocus
string.Empty, new GeneralResponse());
CompilerViewModel.IsEditChecked = false;
}
}
Expand All @@ -356,10 +356,9 @@ await ReactToPluginEventWithReturn("Runner_DoRun", JsonConvert.SerializeObject(n
PluginManager.ReceiveOutput("Building succeeded. Running project...");

CompilerViewModel.IsEditChecked = false;
await ReactToPluginEventWithReturn("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = false
}));
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun",
false, // preventFocus
string.Empty, new GeneralResponse());
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using ToolsUtilities;
using CompilerLibrary.ViewModels;
using FlatRedBall.Glue;
using CompilerLibrary.Error;

namespace GameCommunicationPlugin.GlueControl.Managers
{
Expand All @@ -40,21 +41,19 @@ public void Initialize(GameHostView gameHostView, Action<string> output,
this.glueViewSettingsTab = glueViewSettingsTab;
gameHostView.StopClicked += async (not, used) =>
{
await eventCallerWithAction("Runner_Kill", "");
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "KillGameProcess");
};

gameHostView.RestartGameClicked += async (not, used) =>
{
compilerViewModel.IsPaused = false;
await eventCallerWithAction("Runner_Kill", "");
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "KillGameProcess");
var succeeded = await Compile();
if (succeeded)
{
// don't change if it's in edit mode or not here
await eventCallerWithAction("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = false
}));
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun",
false, // preventFocus
string.Empty, new GeneralResponse());
}
else
{
Expand All @@ -74,23 +73,21 @@ await eventCallerWithAction("Runner_DoRun", JsonConvert.SerializeObject(new
string commandLineArgs = await GetCommandLineArgs(isRunning:true);

compilerViewModel.IsPaused = false;
await eventCallerWithAction("Runner_Kill", "");
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "KillGameProcess");

var compileSucceeded = await Compile();
bool runSucceeded = false;
string runError = "";
if (compileSucceeded)
{
// don't change if it's in edit mode
var runResponse = JObject.Parse(await eventCallerWithAction("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = false,
CommandLineArgs = commandLineArgs
})));

runSucceeded = runResponse.Value<bool>("Succeeded");
GeneralResponse response = new GeneralResponse();
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun",
false, // prevent focus
commandLineArgs, // RunArguments
response);

if (runResponse.ContainsKey("Error"))
runError = runResponse.Value<string>("Error");
runSucceeded = response.Succeeded;
}
else
{
Expand Down Expand Up @@ -243,20 +240,21 @@ private void StartRunInEditMode(object sender, EventArgs e)
{
string commandLineArgs = await GetCommandLineArgs(isRunning:false);

var runResponse = JObject.Parse( await _eventCallerWithAction("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = false,
RunArguments = commandLineArgs
})));
if (runResponse.Value<bool>("Succeeded"))
GeneralResponse response = new GeneralResponse();
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun",
false, // prevent focus
commandLineArgs, // RunArguments
response);

if (response.Succeeded)
{
compilerViewModel.IsEditChecked = true;
}
else
{
GlueCommands.Self.PrintError(runResponse.Value<string>("Error"));
GlueCommands.Self.PrintError(response.Message);
}
succeeded = runResponse.Value<bool>("Succeeded");
succeeded = response.Succeeded;

if(glueViewSettingsViewModel.EmbedGameInGameTab && glueViewSettingsViewModel.EnableLiveEdit)
{
Expand All @@ -277,16 +275,14 @@ private void StartRunInEditMode(object sender, EventArgs e)

public async Task<bool> Compile()
{
await _eventCallerWithAction("Runner_Kill", "");
var generalResponse = new CompileGeneralResponse();

var eventResponse =
await _eventCallerWithAction("Compiler_DoCompile", JsonConvert.SerializeObject(new
{
Configuration = compilerViewModel.Configuration,
PrintMsBuildCommand = compilerViewModel.IsPrintMsBuildCommandChecked
}));
var toReturn = JObject.Parse(eventResponse);
return toReturn.Value<bool>("Succeeded");
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "Compile",
compilerViewModel.Configuration,
compilerViewModel.IsPrintMsBuildCommandChecked,
generalResponse);

return generalResponse.Succeeded;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1115,23 +1115,23 @@ bool DoesTaskManagerHaveAnotherRestartTask()
printOutput("Could not get the game's screen, restarting game from startup screen");
}

var response = await _eventCallerWithReturn("Runner_Kill", "");
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "KillGameProcess");
}

bool compileSucceeded = false;
var wasCancelled = false;
if (!DoesTaskManagerHaveAnotherRestartTask())
{
var doCompileJsonResult =
await _eventCallerWithReturn("Compiler_DoCompile", JsonConvert.SerializeObject(new
{
Configuration = "Debug",
PrintMsBuildCommand = false
}));
var generalResponse = new CompileGeneralResponse();

await PluginManager.CallPluginMethodAsync("Compiler Plugin", "Compile",
"Debug",
false,
generalResponse);

var compileResult = JsonConvert.DeserializeObject<CompileGeneralResponse>(doCompileJsonResult);
wasCancelled = compileResult.WasCancelled;
compileSucceeded = compileResult.Succeeded;

wasCancelled = generalResponse.WasCancelled;
compileSucceeded = generalResponse.Succeeded;
}

if (compileSucceeded)
Expand All @@ -1140,16 +1140,16 @@ await _eventCallerWithReturn("Compiler_DoCompile", JsonConvert.SerializeObject(n
{
// If we aren't generating Glue, then the game will not be embedded, so prevent focus
var preventFocus = ViewModel.IsGenerateGlueControlManagerInGame1Checked == false;
var response = JObject.Parse(await _eventCallerWithReturn("Runner_DoRun", JsonConvert.SerializeObject(new
{
PreventFocus = preventFocus,
RunArguments = screenToRestartOn
})));
if (response.Value<bool>("Succeeded") == false)

GeneralResponse response = new GeneralResponse();
await PluginManager.CallPluginMethodAsync("Compiler Plugin", "DoRun", preventFocus, screenToRestartOn, response);


if (response.Succeeded == false)
{
printError(response.Value<string>("Error"));
printError(response.Message);
}
failedToRebuildAndRestart = response.Value<bool>("Succeeded") == false;
failedToRebuildAndRestart = response.Succeeded == false;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1520,8 +1520,12 @@ await TaskManager.Self.AddAsync(async () =>
public async Task AddNamedObjectToAsync(NamedObjectSave newNos, GlueElement elementToAddTo, NamedObjectSave listToAddTo = null, bool selectNewNos = true,
bool performSaveAndGenerateCode = true, bool updateUi = true)
{
var frameId1 = System.Threading.Thread.CurrentThread.ManagedThreadId;
await TaskManager.Self.AddAsync(async () =>
{

var frameId2 = System.Threading.Thread.CurrentThread.ManagedThreadId;

var ati = newNos.GetAssetTypeInfo();

if (listToAddTo != null)
Expand Down Expand Up @@ -1573,11 +1577,14 @@ await TaskManager.Self.AddAsync(async () =>
{
GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(elementToAddTo);
}
var frameId3 = System.Threading.Thread.CurrentThread.ManagedThreadId;

// run after generated code so plugins like level editor work off latest code
await PluginManager.ReactToNewObjectListAsync(new List<NamedObjectSave>(){ newNos});
if (listToAddTo != null)
{
var frameId4 = System.Threading.Thread.CurrentThread.ManagedThreadId;

await PluginManager.ReactToObjectContainerChanged(newNos, listToAddTo);
}

Expand Down
Loading

0 comments on commit 9ae2c7a

Please sign in to comment.