Skip to content

Commit

Permalink
Merge branch 'NetStandard' of https://github.com/vchelaru/FlatRedBall
Browse files Browse the repository at this point in the history
…into NetStandard
  • Loading branch information
vchelaru committed Jan 23, 2024
2 parents b21107f + 96651e4 commit b6a0290
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 53 deletions.
9 changes: 4 additions & 5 deletions Engines/FlatRedBallXNA/FlatRedBall/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public partial class ContentManager : Microsoft.Xna.Framework.Content.ContentMan
TextureContentLoader textureContentLoader = new TextureContentLoader();

//internal Dictionary<string, Type> mAssetTypeAssociation;
internal Dictionary<string, object> mAssets;
internal Dictionary<string, IDisposable> mDisposableDictionary = new Dictionary<string, IDisposable>();
Dictionary<string, object> mNonDisposableDictionary = new Dictionary<string, object>();
internal Dictionary<string, object> mAssets = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

internal Dictionary<string, IDisposable> mDisposableDictionary = new Dictionary<string, IDisposable>(StringComparer.OrdinalIgnoreCase);
Dictionary<string, object> mNonDisposableDictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

Dictionary<string, Action> mUnloadMethods = new Dictionary<string, Action>();

Expand Down Expand Up @@ -199,7 +200,6 @@ public ContentManager(string name, IServiceProvider serviceProvider)
{
mName = name;
// mAssetTypeAssociation = new Dictionary<string, Type>();
mAssets = new Dictionary<string, object>();
ManualResetEventList = new List<ManualResetEvent>();
}

Expand All @@ -208,7 +208,6 @@ public ContentManager(string name, IServiceProvider serviceProvider, string root
{
mName = name;
// mAssetTypeAssociation = new Dictionary<string, Type>();
mAssets = new Dictionary<string, object>();
ManualResetEventList = new List<ManualResetEvent>();
}

Expand Down
15 changes: 1 addition & 14 deletions Engines/FlatRedBallXNA/FlatRedBall/Graphics/Renderer.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,7 @@ private static void DrawMixed(SpriteList spriteListUnfiltered, SortType sortType
// DRAWABLE BATCHES: Only DrawableBatches remain so draw them all.
while (batchIndex < mVisibleBatches.Count)
{
IDrawableBatch batchAtIndex = mVisibleBatches[batchIndex];
if (mUpdateDrawableBatches && batchAtIndex.UpdateEveryFrame)
{
batchAtIndex.Update();
}
var batchAtIndex = mVisibleBatches[batchIndex];

if (Renderer.RecordRenderBreaks)
{
Expand Down Expand Up @@ -633,11 +629,6 @@ private static void DrawMixed(SpriteList spriteListUnfiltered, SortType sortType
{
IDrawableBatch batchAtIndex = mVisibleBatches[batchIndex];

if (mUpdateDrawableBatches && batchAtIndex.UpdateEveryFrame)
{
batchAtIndex.Update();
}

if(Renderer.RecordRenderBreaks)
{
// Even though we aren't using a RenderBreak here, we should record a render break
Expand Down Expand Up @@ -1149,10 +1140,6 @@ private static void DrawUnlayeredObjects(Camera camera, RenderMode renderMode, S

foreach (var drawableBatch in SpriteManager.mZBufferedDrawableBatches)
{
if (drawableBatch.UpdateEveryFrame)
{
drawableBatch.Update();
}
drawableBatch.Draw(camera);
}

Expand Down
45 changes: 45 additions & 0 deletions Engines/FlatRedBallXNA/FlatRedBall/SpriteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ public static class SpriteManager
static PositionedObjectList<SpriteFrame> mSpriteFrames;
static ReadOnlyCollection<SpriteFrame> mSpriteFramesReadOnly;

/// <summary>
/// Unlayered, sorted drawable batches
/// </summary>
static List<IDrawableBatch> mDrawableBatches;

/// <summary>
/// Unlayered, ZBuffered drawable batches
/// </summary>
static internal List<IDrawableBatch> mZBufferedDrawableBatches = new List<IDrawableBatch>();
static ReadOnlyCollection<IDrawableBatch> mDrawableBatchesReadOnlyCollection;

Expand Down Expand Up @@ -2984,6 +2991,44 @@ public static void Update(Section section )
mSpriteFrames[i].Manage();
}

// January 21,2024
// This used to be handled
// in Renderer, but now we want
// to have this happen before CustomActivity
// so that updating collision will properly use
// animation state.
if(Renderer.UpdateDrawableBatches)
{
for(int i = 0; i < mDrawableBatches.Count; i++)
{
var batch = mDrawableBatches[i];
if(batch.UpdateEveryFrame)
{
batch.Update();
}
}
for(int i = 0; i < mZBufferedDrawableBatches.Count; i++)
{
var batch = mZBufferedDrawableBatches[i];
if (batch.UpdateEveryFrame)
{
batch.Update();
}
}
for (int i = 0; i < mLayers.Count; i++)
{
var layer = mLayers[i];
for(int idbIndex = 0; idbIndex < layer.Batches.Count; idbIndex++)
{
var batch = layer.Batches[idbIndex];
if (batch.UpdateEveryFrame)
{
batch.Update();
}
}
}
}

if (section != null)
{
Section.EndContextAndTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void RefreshMenuItems()
}
}

recentFilesMenuItem.DropDownItems.Add(L.Texts.More, null, HandleLoadRecentClicked);
recentFilesMenuItem.DropDownItems.Add(L.Texts.More, null, HandleMoreClicked);

void AddToRecentFilesMenuItem(RecentFileSave item)
{
Expand All @@ -77,7 +77,7 @@ void AddToRecentFilesMenuItem(RecentFileSave item)
}
}

private async void HandleLoadRecentClicked(object sender, EventArgs e)
private async void HandleMoreClicked(object sender, EventArgs e)
{
var viewModel = new LoadRecentViewModel();
var recentFiles = GlueState.Self.GlueSettingsSave?.RecentFileList;
Expand All @@ -93,10 +93,11 @@ private async void HandleLoadRecentClicked(object sender, EventArgs e)
};
vm.RemoveClicked += () => HandleRemovedRecentFile(vm, viewModel);
viewModel.AllItems.Add(vm);

}
}



viewModel.RefreshFilteredItems();

var window = new LoadRecentWindow();
Expand Down Expand Up @@ -127,6 +128,28 @@ private async void HandleLoadRecentClicked(object sender, EventArgs e)
GlueCommands.Self.GluxCommands.SaveSettings();
}

foreach (var item in viewModel.AllItems)
{
item.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(item.IsFavorite))
{
var isFavorite = item.IsFavorite;
var existing = GlueSettings.RecentFileList.FirstOrDefault(candidate => candidate.FileName == item.FullPath);
if (existing != null)
{
existing.IsFavorite = isFavorite;
}
GlueCommands.Self.GluxCommands.SaveSettings();
RefreshMenuItems();
}
};
}
}

private void HandleRemovedRecentFile(RecentItemViewModel vm, LoadRecentViewModel mainViewModel)
Expand Down
18 changes: 1 addition & 17 deletions FRBDK/Glue/Glue/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,23 +496,7 @@ public static bool UpdateExternallyBuiltFile(string changedFile)

return wasAnythingBuild;
}

/// <summary>
/// Updates the presence of the RFS in the main project. If the RFS has project specific files, then those
/// files are updated in the appropriate synced project.
/// </summary>
/// <remarks>
/// This method does not update synced projects if the synced projects use the same file. The reason is because
/// this is taken care of when the projects are saved later on.
/// </remarks>
/// <param name="referencedFileSave">The RFS representing the file to update membership on.</param>
/// <returns>Whether anything was added to any projects.</returns>
[Obsolete("Use GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject")]
public static bool UpdateFileMembershipInProject(ReferencedFileSave referencedFileSave)
{
return GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(referencedFileSave);
}


#endregion

#region Internal Methods
Expand Down
32 changes: 32 additions & 0 deletions FRBDK/Glue/Glue/VSHelpers/VSSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ public string FullFileName
set;
}

public static bool RemoveProjectReference(FilePath solution, string project, out string output, out string error)
{
output = string.Empty;
error = string.Empty;

if(solution.Exists())
{
var contents = System.IO.File.ReadAllText(solution.FullPath);

if(contents?.Contains(project) == true)
{
var indexOfProjectReference = contents.IndexOf(project);
const string startOfTextToRemove = "Project(\"";
const string endOfTextToRemove = "EndProject";

var indexOfStart = contents.LastIndexOf(startOfTextToRemove, indexOfProjectReference);
var indexOfEnd = contents.IndexOf(endOfTextToRemove, indexOfProjectReference + project.Length);

if(indexOfStart > -1 && indexOfEnd > -1)
{
var endWithLenth = indexOfEnd + endOfTextToRemove.Length;
// Remove between indexOfStart and indexOfEnd
contents = contents.Remove(indexOfStart, endWithLenth - indexOfStart);

System.IO.File.WriteAllText(solution.FullPath, contents);
return true;
}
}
}
return false;
}

public static bool AddExistingProjectWithDotNet(FilePath solution, FilePath project, out string output, out string error)
{
output = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public T LoadContent<T>(string contentName)
#if ANDROID || IOS
contentName = contentName.ToLowerInvariant();
#endif
// alwasy prefer global content first:

return FlatRedBall.FlatRedBallServices.Load<T>(contentName, ContentManagerName);
}
}
Expand Down
8 changes: 7 additions & 1 deletion FRBDK/Glue/GumPlugin/GumPlugin/MainGumPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,19 @@ await TaskManager.Self.AddAsync(() =>
startInfo.FileName = executable;
startInfo.UseShellExecute = false;
GlueCommands.Self.PrintOutput($"{startInfo.FileName} {startInfo.Arguments}");
var process = System.Diagnostics.Process.Start(startInfo);
process.WaitForExit();
},
Localization.Texts.RefreshingFontCache);


var gumRfs = GumProjectManager.Self.GetRfsForGumProject();
if(gumRfs != null)
{
GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(gumRfs);
}
}
}

Expand Down
15 changes: 13 additions & 2 deletions FRBDK/Glue/GumPlugin/GumPlugin/Managers/AssetTypeInfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using static FlatRedBall.Glue.SaveClasses.GlueProjectSave;
using FlatRedBall.Glue.Parsing;
using Gum.DataTypes.Variables;

namespace GumPlugin.Managers
{
Expand Down Expand Up @@ -770,14 +771,19 @@ public void UpdateAtiForElement(AssetTypeInfo newAti, ElementSave element)
variableName = "Current" + variableName;
}

var hasAlreadyBeenAdded = newAti.VariableDefinitions.Any(item => item.Name == variableName);
var existing = newAti.VariableDefinitions.FirstOrDefault(item => item.Name == variableName);
var hasAlreadyBeenAdded = existing != null;

if (!hasAlreadyBeenAdded)
{

var variableDefinition = new VariableDefinition();
variableDefinition.Category = variable.Category;
variableDefinition.DefaultValue = variable.Value?.ToString();

// We should bubble up the recursive value so that it can show here:
//variableDefinition.DefaultValue = variable.Value?.ToString();
variableDefinition.DefaultValue = state.GetValueRecursive(variableName)?.ToString();

variableDefinition.Name = variableName; // gum variables can have spaces, but Glue variables can't

variableDefinition.Type = QualifyGumVariableType(variable, element);
Expand All @@ -787,6 +793,11 @@ public void UpdateAtiForElement(AssetTypeInfo newAti, ElementSave element)
newAti.VariableDefinitions.Add(variableDefinition);

}
else
{
// This could be different per type so let's do this:
existing.DefaultValue = state.GetValueRecursive(variableName)?.ToString();
}
}
}
}
Expand Down
Loading

0 comments on commit b6a0290

Please sign in to comment.