Skip to content

Commit

Permalink
4.7.1 release, reducing allocations in main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMakesGames committed May 28, 2024
1 parent 7ee4533 commit 5859d24
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>An extension for PlayPlayMini which adds methods for generating &amp; playing simple waveforms.</Description>
<Copyright>2022-2023 Ben Hendel-Doying</Copyright>
<Version>0.5.0</Version>
<Version>0.5.1</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame playplaymini sound generation square triangle saw sine wave waveform</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>Some GraphicsManager extensions for PlayPlayMini.</Description>
<Copyright>2023-2024 Ben Hendel-Doying</Copyright>
<Version>4.7.0</Version>
<Version>4.7.1</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame playplaymini graphics extensions animations text</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>Get seamless looping music, and cross-fade, in your MonoGame-PlayPlayMini game using NAudio.</Description>
<Copyright>2024 Ben Hendel-Doying</Copyright>
<Version>0.3.0</Version>
<Version>0.3.1</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame playplaymini naudio music</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>An extension for PlayPlayMini, adding a skinnable, object-oriented UI framework.</Description>
<Copyright>2021-2024 Ben Hendel-Doying</Copyright>
<Version>4.7.0</Version>
<Version>4.7.1</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame mouse ui framework oo</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>An opinionated framework for making smallish games with MonoGame.</Description>
<Copyright>2021-2024 Ben Hendel-Doying</Copyright>
<Version>4.7.0</Version>
<Version>4.7.1</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame game engine framework di state</PackageTags>
Expand Down
12 changes: 8 additions & 4 deletions BenMakesGames.PlayPlayMini/GameStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ protected override void Initialize()

private void Input(GameTime gameTime)
{
foreach(var s in ServiceWatcher.InputServices)
s.Input(gameTime);
// ReSharper disable once ForCanBeConvertedToForeach
// for loop, instead of foreach, reduces allocations
for(var i = 0; i < ServiceWatcher.InputServices.Count; i++)
ServiceWatcher.InputServices[i].Input(gameTime);

CurrentState.Input(gameTime);
}
Expand All @@ -106,8 +108,10 @@ protected override void Update(GameTime gameTime)

base.Update(gameTime);

foreach (var s in ServiceWatcher.UpdatedServices)
s.Update(gameTime);
// ReSharper disable once ForCanBeConvertedToForeach
// for loop, instead of foreach, reduces allocations
for (var i = 0; i < ServiceWatcher.UpdatedServices.Count; i++)
ServiceWatcher.UpdatedServices[i].Update(gameTime);

FixedUpdateAccumulator += gameTime.ElapsedGameTime.TotalMilliseconds;

Expand Down
10 changes: 5 additions & 5 deletions BenMakesGames.PlayPlayMini/Services/ServiceWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public sealed class ServiceWatcher
private List<IServiceUpdate> ServicesWithUpdateEvents { get; } = new();
private List<IServiceDraw> ServicesWithDrawEvents { get; } = new();

public IReadOnlyCollection<IServiceLoadContent> ContentLoadingServices => ServiceWithLoadContentEvents;
public IReadOnlyCollection<IServiceInitialize> InitializedServices => ServicesWithInitializeEvents;
public IReadOnlyCollection<IServiceInput> InputServices => ServicesWithInputEvents;
public IReadOnlyCollection<IServiceUpdate> UpdatedServices => ServicesWithUpdateEvents;
public IReadOnlyCollection<IServiceDraw> DrawnServices => ServicesWithDrawEvents;
public IReadOnlyList<IServiceLoadContent> ContentLoadingServices => ServiceWithLoadContentEvents;
public IReadOnlyList<IServiceInitialize> InitializedServices => ServicesWithInitializeEvents;
public IReadOnlyList<IServiceInput> InputServices => ServicesWithInputEvents;
public IReadOnlyList<IServiceUpdate> UpdatedServices => ServicesWithUpdateEvents;
public IReadOnlyList<IServiceDraw> DrawnServices => ServicesWithDrawEvents;

public void RegisterService(object service)
{
Expand Down

0 comments on commit 5859d24

Please sign in to comment.