Skip to content

Commit

Permalink
Update as needed to match Guppy multithreading API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rettoph committed Oct 1, 2021
1 parent 0b968b3 commit e641caf
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 54 deletions.
21 changes: 21 additions & 0 deletions VoidHuntersRevived.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guppy.Network.Core", "libra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guppy.CommandLine", "libraries\Guppy\src\Guppy.CommandLine\Guppy.CommandLine.csproj", "{F92E8F3D-3C51-4EC7-9092-919BC8B6BA3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Guppy.Threading", "libraries\Guppy\src\Guppy.Threading\Guppy.Threading.csproj", "{CC3281DD-6399-45B3-A9C8-D7638C2299CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Verbose|Any CPU = Debug_Verbose|Any CPU
Expand Down Expand Up @@ -415,6 +417,24 @@ Global
{F92E8F3D-3C51-4EC7-9092-919BC8B6BA3F}.Release|x64.Build.0 = Release|Any CPU
{F92E8F3D-3C51-4EC7-9092-919BC8B6BA3F}.Release|x86.ActiveCfg = Release|Any CPU
{F92E8F3D-3C51-4EC7-9092-919BC8B6BA3F}.Release|x86.Build.0 = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|Any CPU.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|Any CPU.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|x64.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|x64.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|x86.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug_Verbose|x86.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|x64.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Debug|x86.Build.0 = Debug|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|Any CPU.Build.0 = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|x64.ActiveCfg = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|x64.Build.0 = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|x86.ActiveCfg = Release|Any CPU
{CC3281DD-6399-45B3-A9C8-D7638C2299CC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -446,6 +466,7 @@ Global
{C51B9905-F44E-4A5D-8A65-AED15D599D08} = {B692A3AD-DDD4-42C9-9125-21C351DE55FD}
{147FC080-FB18-45DD-A371-AA01484351C6} = {DA5CAD48-BEB9-4316-814A-820EA2A21081}
{F92E8F3D-3C51-4EC7-9092-919BC8B6BA3F} = {DA5CAD48-BEB9-4316-814A-820EA2A21081}
{CC3281DD-6399-45B3-A9C8-D7638C2299CC} = {DA5CAD48-BEB9-4316-814A-820EA2A21081}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8FCB1CA3-2B6C-469F-B569-084FC0B57488}
Expand Down
2 changes: 1 addition & 1 deletion libraries/Guppy
Submodule Guppy updated 36 files
+1 −1 src/Guppy.Core/DependencyInjection/TypePools/GenericTypePool.cs
+4 −44 src/Guppy.Core/DependencyInjection/TypePools/TypePool.cs
+37 −0 src/Guppy.Core/Interfaces/IPool.cs
+8 −2 src/Guppy.Core/Lists/ServiceList.cs
+49 −0 src/Guppy.Core/Utilities/Factory.cs
+60 −0 src/Guppy.Core/Utilities/Pool.cs
+5 −4 src/Guppy.IO/InputCommand.cs
+1 −1 src/Guppy.IO/Services/KeyboardService.cs
+1 −1 src/Guppy.IO/Services/MouseService.cs
+2 −2 src/Guppy.Network.Core/Channels/Channel.cs
+10 −0 src/Guppy.Network.Core/Delegates/MessageFactoryDelegate.cs
+1 −0 src/Guppy.Network.Core/Guppy.Network.Core.csproj
+10 −3 src/Guppy.Network.Core/Interfaces/IPeer.cs
+2 −1 src/Guppy.Network.Core/NetworkEntity.cs
+8 −0 src/Guppy.Network.Core/Peers/ClientPeer.cs
+28 −2 src/Guppy.Network.Core/Peers/Peer.cs
+5 −5 src/Guppy.Network.Core/Services/NetOutgoingMessageService.cs
+3 −2 src/Guppy.Network.Core/Utilities/MessageManager.cs
+42 −32 src/Guppy.Network.Core/Utilities/MessageTypeManager.cs
+13 −12 src/Guppy.Network/Components/NetworkEntityCRUDComponent.cs
+31 −19 src/Guppy.Network/Components/Scenes/NetworkSceneBaseCRUDComponent.cs
+2 −2 src/Guppy.Network/NetworkFrameable.cs
+2 −1 src/Guppy.Network/NetworkLayerable.cs
+1 −2 src/Guppy.Network/Utilities/Broadcast.cs
+20 −0 src/Guppy.Threading/Guppy.Threading.csproj
+54 −0 src/Guppy.Threading/TaskHelper.cs
+62 −0 src/Guppy.Threading/Utilities/ThreadQueue.cs
+29 −43 src/Guppy/Asyncable.cs
+4 −0 src/Guppy/Constants.cs
+6 −5 src/Guppy/Game.cs
+1 −0 src/Guppy/Guppy.csproj
+110 −4 src/Guppy/Lists/FrameableList.cs
+8 −71 src/Guppy/Lists/OrderableList.cs
+14 −4 src/Guppy/Scene.cs
+4 −2 src/Guppy/ServiceLoaders/GuppyServiceLoader.cs
+0 −66 src/Guppy/Utilities/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected override void Initialize(GuppyServiceProvider provider)
provider.Service(out _camera);
provider.Service(out _mouse);
provider.Service(out _debugView);


_effect = new BasicEffect(provider.GetService<GraphicsDevice>())
{
Expand All @@ -60,6 +61,14 @@ protected override void Initialize(GuppyServiceProvider provider)
_camera.ZoomBy((Single)Math.Pow(1.5, d.Delta / 120));
};
}

protected override void Release()
{
base.Release();

// TODO: RELEASE INTERNAL RESOURCES
throw new NotImplementedException();
}
#endregion

#region Frame Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ private void ReadCurrentUserMasterActionRequestMessage(MessageTypeManager sender
/// <param name="request"></param>
private void HandleRemoteCurrentUserSlaveActionRequest(UserPlayerCurrentUserActionBaseComponent<TAction> sender, TAction request)
{
NetOutgoingMessage om = this.Entity.Messages[this.ActionRequestMessageType].Create(this.Entity.Pipe);
this.WriteCurrentUserActionRequestMessage(om, request);
this.Entity.Messages[this.ActionRequestMessageType].Create(om =>
{
this.WriteCurrentUserActionRequestMessage(om, request);
}, this.Entity.Pipe);
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ private void HandleChainRootPostTreeClean(ShipPart sender, ShipPart source, Tree
}
else if(!source.IsRoot && source.Chain == this.Entity)
{ // The source was ADDED to the chain
this.WriteShipPartAttachedMessage(
shipPart: source,
om: this.Entity.Messages[Constants.Messages.Chain.ShipPartAttached].Create(this.Entity.Pipe));
this.Entity.Messages[Constants.Messages.Chain.ShipPartAttached].Create(om =>
{
this.WriteShipPartAttachedMessage(
shipPart: source,
om: om);
}, this.Entity.Pipe);
}
}
}
Expand Down
24 changes: 2 additions & 22 deletions src/VoidHuntersRevived.Library/Entities/Aether/AetherBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ public Object Tag
{
set => this.Do(body => body.Tag = value);
}

public BodyType BodyType
{
set => this.Do(body => body.BodyType = value);
}

public Single AngularDamping
{
set => this.Do(body => body.AngularDamping = value);
}

public Single LinearDamping
{
set => this.Do(body => body.LinearDamping = value);
}

public Boolean IgnoreGravity
{
set => this.Do(body => body.IgnoreGravity = value);
}
#endregion

#region Lifecycle Methods
Expand All @@ -74,12 +54,12 @@ protected override void Initialize(GuppyServiceProvider provider)

protected override void PostRelease()
{
base.PostRelease();

_fixtures.TryRelease();
_fixtures = default;

this.Do(body => body.TryRemove());

base.PostRelease();
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions src/VoidHuntersRevived.Library/Entities/Aether/AetherWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ protected override void PostRelease()
{
base.PostRelease();

_chunks = default;

_bodies.TryRelease();

_chunks = default;
_bodies = default;
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public abstract class BaseAetherWrapper<TAetherObject> : Frameable
#endregion

#region Lifecycle Methods
protected override void PreInitialize(GuppyServiceProvider provider)
{
base.PreInitialize(provider);
}

protected override void Initialize(GuppyServiceProvider provider)
{
base.Initialize(provider);
Expand Down Expand Up @@ -122,13 +127,13 @@ protected internal void BuildAetherInstances(GuppyServiceProvider provider)
{ NetworkAuthorization.Slave, this.BuildInstance(provider, NetworkAuthorization.Slave) }
};

switch(provider.Settings.Get<NetworkAuthorization>())
switch (provider.Settings.Get<NetworkAuthorization>())
{
case NetworkAuthorization.Master:
_localInstance = _instances[NetworkAuthorization.Master];
_platformInstances = new TAetherObject[]
{
_instances[NetworkAuthorization.Master]
_instances[NetworkAuthorization.Master]
};
break;
case NetworkAuthorization.Slave:
Expand All @@ -143,10 +148,10 @@ protected internal void BuildAetherInstances(GuppyServiceProvider provider)
}

/// <summary>
/// Preform an action on every internal <see cref="TAetherObject"/> instance.
/// Perform an action on every internal <see cref="TAetherObject"/> instance.
/// </summary>
/// <param name="action"></param>
protected void Do(Action<TAetherObject> action)
public void Do(Action<TAetherObject> action)
{
foreach (TAetherObject instance in _instances.Values)
action(instance);
Expand Down
9 changes: 5 additions & 4 deletions src/VoidHuntersRevived.Library/Entities/Chunks/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Guppy.Lists.Interfaces;
using Guppy.Network.Interfaces;
using Guppy.Network.Scenes;
using Guppy.Threading.Utilities;
using Guppy.Utilities;
using Microsoft.Xna.Framework;
using System;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class Chunk : Frameable

#region Privage Fields
private HashSet<Guid> _dependents;
private Synchronizer _synchronizer;
private ThreadQueue _updateThread;

/// <summary>
/// The amount of time in seconds the current chunk has gone without any dependents.
Expand Down Expand Up @@ -124,14 +125,14 @@ protected override void Initialize(GuppyServiceProvider provider)
this.Dependents = 0;
_dependentlessMilliseconds = 0;

provider.Service(out _synchronizer);
provider.Service(Guppy.Constants.ServiceConfigurationKeys.SceneUpdateThreadQueue, out _updateThread);
}

protected override void Release()
{
base.Release();

_synchronizer = default;
_updateThread = default;

_dependents.Clear();

Expand Down Expand Up @@ -168,7 +169,7 @@ protected override void Update(GameTime gameTime)
if(this.Dependents == 0)
{
if (_dependentlessMilliseconds > Chunk.MaxDependentlessThreshold)
_synchronizer.Enqueue(gt => this.TryRelease());
_updateThread.Enqueue(gt => this.TryRelease());
else
_dependentlessMilliseconds += gameTime.ElapsedGameTime.TotalMilliseconds;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Guppy.DependencyInjection;
using Guppy.Events.Delegates;
using Guppy.Network.Enums;
using Guppy.Network.Extensions.Lidgren;
using Guppy.Threading.Utilities;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
Expand Down Expand Up @@ -48,11 +50,14 @@ protected override void PreInitialize(GuppyServiceProvider provider)
// Setup the chain's body.
this.Body = provider.GetService<AetherWorld>().CreateBody((body, _, _) =>
{
body.Tag = this;
body.BodyType = BodyType.Dynamic;
body.LinearDamping = 0.2f;
body.AngularDamping = 0.1f;
body.IgnoreGravity = true;
body.Do(b =>
{
b.Tag = this;
b.BodyType = BodyType.Dynamic;
b.LinearDamping = 0.2f;
b.AngularDamping = 0.1f;
b.IgnoreGravity = true;
});
});
}

Expand All @@ -72,6 +77,7 @@ protected override void PostRelease()
base.PostRelease();

this.Body.TryRelease();

this.Body = default;
}
#endregion
Expand Down
6 changes: 3 additions & 3 deletions src/VoidHuntersRevived.Library/PrimaryGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ protected override void PreInitialize(GuppyServiceProvider provider)
protected override void Initialize(GuppyServiceProvider provider)
{
base.Initialize(provider);

this.Peer.StartAsync(50);
}

protected override void PostInitialize(GuppyServiceProvider provider)
{
base.PostInitialize(provider);

this.Peer.Start();

this.Scenes.Create<PrimaryScene>();
}
#endregion
Expand All @@ -52,7 +52,7 @@ protected override void PreUpdate(GameTime gameTime)
{
base.PreUpdate(gameTime);

this.Peer.TryUpdate();
// this.Peer.TryUpdate();
}
#endregion
}
Expand Down
11 changes: 8 additions & 3 deletions src/VoidHuntersRevived.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
using tainicom.Aether.Physics2D.Dynamics;
using System.Threading;
using System.Linq;
using System.Threading.Tasks;

namespace VoidHuntersRevived.Server
{
class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}

private static async Task MainAsync(string[] args)
{
var game = new GuppyLoader()
.Initialize()
.BuildGame<PrimaryGame>();


game.TryStart(false);
await game.TryStartAsync(false);
}
}
}
17 changes: 12 additions & 5 deletions src/VoidHuntersRevived.Server/Scenes/ServerPrimaryScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Guppy.Network.Interfaces;
using Guppy.Network.Lists;
using Guppy.Network.Peers;
using Guppy.Threading.Utilities;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -27,6 +28,8 @@ public class ServerPrimaryScene : PrimaryScene
private ChainService _chains;
private PlayerService _players;
private ShipService _ships;

private ThreadQueue _updateThread;
#endregion

#region Lifecycle Methods
Expand All @@ -38,6 +41,7 @@ protected override void Initialize(GuppyServiceProvider provider)
provider.Service(out _players);
provider.Service(out _ships);
provider.Service(out _chains);
provider.Service(out _updateThread);

_server.Users.OnAdded += this.HandleUserConnected;

Expand Down Expand Up @@ -87,12 +91,15 @@ private void HandleUserJoined(IServiceList<IUser> sender, IUser user)
{
this.Channel.Pipes.GetOrCreateById(VoidHuntersRevived.Library.Constants.PipeIds.PlayersPipeId).Users.TryAdd(user);

// Create a new player instance linked to the user.
var chain = _chains.Create(
contextName: "ship-part:hull:square",
position: Vector2.Zero);
_updateThread.Enqueue(_ =>
{
// Create a new player instance linked to the user.
var chain = _chains.Create(
contextName: "ship-part:hull:square",
position: Vector2.Zero);

var ship = _ships.Create(chain, _players.CreateUserPlayer(user));
var ship = _ships.Create(chain, _players.CreateUserPlayer(user));
});
}

private void HandleUserConnected(IServiceList<IUser> sender, IUser args)
Expand Down

0 comments on commit e641caf

Please sign in to comment.