Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/mutliplayer #326

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8ee72ec
Improved multiplayer a bit
susch19 Oct 6, 2022
4101c25
Started implementation of command line for server
susch19 Oct 17, 2022
0e4290c
Continued work on server command line functions
susch19 Oct 19, 2022
0091b1f
Refactor baseclient started
susch19 Nov 2, 2022
11a723b
Implemented stop command
susch19 Nov 9, 2022
101718e
Fixed default port not working
susch19 Nov 9, 2022
a208482
Replace container ressource manager with gameservice
susch19 Dec 1, 2022
ac6ccb6
Fixed initializiation order for new gameservice
susch19 Dec 14, 2022
f6a2ee9
Reworked awaiter for future use
susch19 Dec 14, 2022
1ec68ed
Started refactoring of package management
susch19 Dec 21, 2022
cb0d7da
Added first version of the network action hub
susch19 Jan 25, 2023
1c448b6
Continued the work on multiplayer
susch19 Feb 1, 2023
3ab5ff2
made multiplayer work again with a few workarounds
susch19 Feb 8, 2023
ab8a0d2
Fixed some more network issues
susch19 Feb 15, 2023
381ea15
Integrated nooson
susch19 Mar 15, 2023
c8424ba
Continued work on multiplayer rework
susch19 Mar 23, 2023
5a52528
Continued work on mutliplayer and type container
susch19 Apr 12, 2023
ec4129f
Send network via instance component
susch19 Apr 12, 2023
3a77602
Fixed entity notification transfer
susch19 Apr 26, 2023
9f300c8
Reworked notification send procedure
susch19 May 24, 2023
37fe501
Added possibility for syncing more data
susch19 Jun 14, 2023
6ae16dd
Reworked Components and network communication
susch19 Aug 2, 2023
a3aa566
Moved the component change handler outside of the handler
susch19 Aug 2, 2023
8da3935
Fixed singleplayer with unification of game start
susch19 Aug 9, 2023
cbcc926
Implement a simple chat
Gallimathias Aug 23, 2023
d04fccb
Fixed bugs in chat
susch19 Aug 23, 2023
53e6e6d
Fixed base client connections
susch19 Aug 30, 2023
5393a68
Centralized the serialization id attributes
susch19 Sep 6, 2023
38cd67d
Merge remote-tracking branch 'origin/develop' into refactor/baseclient
susch19 Feb 28, 2024
feac0e8
Merge branch 'refactor/baseclient' into refactor/mutliplayer
susch19 Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions OctoAwesome/Design Documents/Notifications_Multiplayer_Rework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Fragen:
1. Was macht eine Notification aus?
1. Will man steuern können, ob Notifications gesendet werden (Beibehaltung des Network Channels)?
2. Einfach jede senden?
2. Darf man am PAH (PackageActionHub) auf eine Notification Registern?
1. Dürfen mehrere Leute an einer Notification am PAH registrieren?
3. Sollte Notification den Target Channel beinhalten?
1. Darf eine Notification nur in ein Target Channel gepusht werden?
4. Mehr über Updatehub machen und weniger über locale Relays?

Antworten:
1. Package Flag Notification
1. Ja (Wie noch zu klären)
1. Network Channel beibehalten fürs senden
2. UpdateHub prüft auf SerID Existenz und sendet bei Ja vorhanden
3. Man regelt das über die AddSource Methode im Update hub, das hießt der updatehub kann das intern regeln, das wäre ein Mixtur aus 1 und 2. New Parameter SendOverNetwork
2. Nein
2. Ja
1. Wäre toll, aber aufwand
3. Vlt. müsste nach SerId kommen und wäre damit Pflichtfeld. Als erweiterung vom UpdateHub
1. Eher nicht, sondern nur mit multi Relays / PushNetworkOnly
4. Joa why not? Maxi sieht damit kein Problem

Aussagen:
1. Alle "Notifications" eigene Ser Id
2. Serializer Neue Methode SerializeNetwork wegen SerId
52 changes: 52 additions & 0 deletions OctoAwesome/OctoAwesome.Basics/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using OctoAwesome;
using OctoAwesome.Basics;
using OctoAwesome.Basics.Entities;
using OctoAwesome.Basics.EntityComponents;
using OctoAwesome.Basics.FunctionBlocks;
using OctoAwesome.Basics.SimulationComponents;
using OctoAwesome.Basics.UI.Components;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[assembly: NoosonConfiguration(
GenerateDeserializeExtension = false,
DisableWarnings = true,
GenerateStaticDeserializeWithCtor = true,
GenerateDeserializeOnInstance = true,
GenerateStaticSerialize = true,
GenerateStaticDeserializeIntoInstance = true,
NameOfStaticDeserializeWithCtor = "DeserializeAndCreate",
NameOfDeserializeOnInstance = "Deserialize",
NameOfStaticDeserializeIntoInstance = "Deserialize",
NameOfStaticDeserializeWithOutParams = "DeserializeOut")]

[assembly: SerializationId<WauziEntity>(2, 1)]
[assembly: SerializationId<Chest>(2, 2)]
[assembly: SerializationId<Furnace>(2, 3)]
[assembly: SerializationId<ComplexPlanet>(2, 4)]
[assembly: SerializationId<BodyPowerComponent>(2, 5)]
[assembly: SerializationId<ProductionInventoriesComponent>(2, 6)]
[assembly: SerializationId<BurningComponent>(2, 7)]
[assembly: SerializationId<EntityCollisionComponent>(2, 8)]
[assembly: SerializationId<ForceComponent>(2, 9)]
[assembly: SerializationId<GravityComponent>(2, 10)]
[assembly: SerializationId<MassComponent>(2, 11)]
[assembly: SerializationId<MoveableComponent>(2, 12)]
[assembly: SerializationId<PowerComponent>(2, 13)]
[assembly: SerializationId<RelatedEntityComponent>(2, 14)]
[assembly: SerializationId<TransferComponent>(2, 15)]
[assembly: SerializationId<AccelerationComponent>(2, 16)]
[assembly: SerializationId<BlockInteractionComponent>(2, 17)]
[assembly: SerializationId<CollisionComponent>(2, 18)]
[assembly: SerializationId<ComponentContainerInteractionComponent>(2, 19)]
[assembly: SerializationId<ForceAggregatorComponent>(2, 20)]
[assembly: SerializationId<MoveComponent>(2, 21)]
[assembly: SerializationId<NewtonGravitatorComponent>(2, 22)]
[assembly: SerializationId<PowerAggregatorComponent>(2, 23)]
[assembly: SerializationId<WattMoverComponent>(2, 24)]
[assembly: SerializationId<FurnaceUIComponent>(2, 25)]
[assembly: SerializationId<TransferUIComponent>(2, 26)]
16 changes: 8 additions & 8 deletions OctoAwesome/OctoAwesome.Basics/ComplexPlanet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using OctoAwesome.Basics.Biomes;
using OctoAwesome.Serialization;

using OctoAwesome.Location;

using System;
Expand All @@ -10,16 +12,19 @@ namespace OctoAwesome.Basics
/// <summary>
/// A complex planet implementation with complex features.
/// </summary>
public class ComplexPlanet : Planet
[SerializationId(), Nooson]
public partial class ComplexPlanet : Planet, IConstructionSerializable<ComplexPlanet>
{
// The gravitational constant was chosen on purpose to be that "big", see Issue #220

private const double GravitationalConstant = 6.67e-7;

private SurfaceBiomeGenerator? biomeGenerator;

/// <summary>
/// Gets the biome generator used for generating biomes on the planet.
/// </summary>
[NoosonIgnore]
public SurfaceBiomeGenerator BiomeGenerator
{
get
Expand Down Expand Up @@ -49,20 +54,15 @@ public ComplexPlanet(int id, Guid universe, Index3 size, IMapGenerator generator
Initialize();
}



/// <summary>
/// Initializes a new instance of the <see cref="ComplexPlanet"/> class.
/// </summary>
/// <param name="generator">The map generator to use for generating the planet.</param>
public ComplexPlanet(IMapGenerator generator)
: base(generator)
{
//Initalize();
}

/// <inheritdoc />
public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);
Initialize();
}

Expand Down
10 changes: 5 additions & 5 deletions OctoAwesome/OctoAwesome.Basics/ComplexPlanetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
using OctoAwesome.Definitions;
using OctoAwesome.Location;
using OctoAwesome.Pooling;
using OctoAwesome.Serialization;

using System;
using System.Buffers;
using System.IO;
using System.Linq;

namespace OctoAwesome.Basics
{
/// <summary>
/// Map generator used for generating a <see cref="ComplexPlanet"/>.
/// </summary>
public class ComplexPlanetGenerator : IMapGenerator
public partial class ComplexPlanetGenerator : IMapGenerator
{
private readonly ChunkPool chunkPool;

Expand Down Expand Up @@ -58,7 +58,7 @@ ushort GetBlockDefinitionInfo<T>()

IChunk[] chunks = new IChunk[planet.Size.Z];
for (int i = 0; i < planet.Size.Z; i++)
chunks[i] = chunkPool.Rent(new Index3(index, i), localPlanet);
chunks[i] = chunkPool.Rent(new Index3(index, i), localPlanet.Id);

int obersteSchicht;
bool surfaceBlock;
Expand Down Expand Up @@ -148,7 +148,7 @@ ushort GetBlockDefinitionInfo<T>()
}
}
ArrayPool<float>.Shared.Return(localHeightmap);
ChunkColumn column = new ChunkColumn(chunks, localPlanet, index);
ChunkColumn column = new ChunkColumn(chunks, localPlanet.Id, index);
column.CalculateHeights();
return column;
}
Expand All @@ -165,7 +165,7 @@ public IPlanet GeneratePlanet(Stream stream)
/// <inheritdoc />
public IChunkColumn GenerateColumn(Stream stream, IPlanet planet, Index2 index)
{
IChunkColumn column = new ChunkColumn(planet);
IChunkColumn column = new ChunkColumn(planet.Id);
using (var reader = new BinaryReader(stream))
column.Deserialize(reader);
return column;
Expand Down
6 changes: 3 additions & 3 deletions OctoAwesome/OctoAwesome.Basics/DebugMapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public IChunkColumn GenerateColumn(IDefinitionManager definitionManager, IPlanet

IChunk[] result = new IChunk[planet.Size.Z];

ChunkColumn column = new ChunkColumn(result, planet, index);
ChunkColumn column = new ChunkColumn(result, planet.Id, index);


for (int layer = 0; layer < planet.Size.Z; layer++)
result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet);
result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet.Id);

int part = (planet.Size.Z * Chunk.CHUNKSIZE_Z) / 4;

Expand Down Expand Up @@ -74,7 +74,7 @@ public IPlanet GeneratePlanet(Stream stream)
/// <inheritdoc />
public IChunkColumn GenerateColumn(Stream stream, IPlanet planet, Index2 index)
{
IChunkColumn column = new ChunkColumn(planet);
IChunkColumn column = new ChunkColumn(planet.Id);
using (var reader = new BinaryReader(stream))
column.Deserialize(reader);
return column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace OctoAwesome.Basics.Definitions.Items
/// </summary>
public class ChestItem : Item, IDisposable
{
private readonly IUpdateHub updateHub;
private readonly Relay<Notification> simulationRelay;
private readonly IDisposable simulationSource;

Expand All @@ -29,7 +30,7 @@ public class ChestItem : Item, IDisposable
public ChestItem(ChestItemDefinition definition, IMaterialDefinition materialDefinition)
: base(definition, materialDefinition)
{
var updateHub = TypeContainer.Get<IUpdateHub>();
updateHub = TypeContainer.Get<IUpdateHub>();
simulationRelay = new Relay<Notification>();

simulationSource = updateHub.AddSource(simulationRelay, DefaultChannels.Simulation);
Expand All @@ -49,6 +50,7 @@ public override int Apply(IMaterialDefinition material, IBlockInteraction hitInf
};

simulationRelay.OnNext(notification);

return 0;
}

Expand Down
61 changes: 31 additions & 30 deletions OctoAwesome/OctoAwesome.Basics/Entities/WauziEntity.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Diagnostics;
using System.Diagnostics;

using engenious;

using OctoAwesome.Basics.Definitions.Items.Food;
Expand All @@ -9,14 +9,14 @@
using OctoAwesome.Location;
using OctoAwesome.Extension;
using OctoAwesome.Serialization;

namespace OctoAwesome.Basics.Entities
{
/// <summary>
/// An entity used for dogs in the game.
/// </summary>
[SerializationId(1, 2)]
public class WauziEntity : Entity
[SerializationId()]
[Nooson]
public partial class WauziEntity : Entity, ISerializable<WauziEntity>
{
class MoveLogic
{
Expand Down Expand Up @@ -127,31 +127,32 @@ public WauziEntity() : base()
{
}

/// <inheritdoc />
protected override void OnInteract(GameTime gameTime, Entity entity)
{
if (!entity.Components.TryGet<ToolBarComponent>(out var toolbar)
|| !entity.Components.TryGet<InventoryComponent>(out var inventory)
|| !entity.Components.TryGet<PositionComponent>(out var position)
|| toolbar.ActiveTool?.Item is not MeatRaw)
return;

Controller.JumpInput = true;
if (!Components.Contains<RelatedEntityComponent>())
{
var relEntity = new RelatedEntityComponent();
relEntity.RelatedEntityId = entity.Id;
Components.Add(relEntity);
followEntity = entity;
}

inventory.RemoveUnit(toolbar.ActiveTool);
if (toolbar.ActiveTool.Amount < 1)
{
inventory.Remove(toolbar.ActiveTool);
toolbar.RemoveSlot(toolbar.ActiveTool);
}
}
///<inheritdoc/>
//protected override void OnInteract(GameTime gameTime, Entity entity)
//{
// if (!entity.Components.TryGet<ToolBarComponent>(out var toolbar)
// || !entity.Components.TryGet<InventoryComponent>(out var inventory)
// || !entity.Components.TryGet<PositionComponent>(out var position)
// || toolbar.ActiveTool?.Item is not MeatRaw
// || !Components.TryGet<ControllableComponent>(out var controller))
// return;

// controller.JumpInput = true;
// if (!Components.Contains<RelatedEntityComponent>())
// {
// var relEntity = new RelatedEntityComponent();
// relEntity.RelatedEntityId = entity.Id;
// Components.AddIfTypeNotExists(relEntity);
// followEntity = entity;
// }

// inventory.RemoveUnit(toolbar.ActiveTool);
// if (toolbar.ActiveTool.Amount < 1)
// {
// inventory.Remove(toolbar.ActiveTool);
// toolbar.RemoveSlot(toolbar.ActiveTool);
// }
//}


/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
using System.IO;

namespace OctoAwesome.Basics.EntityComponents
namespace OctoAwesome.Basics.EntityComponents
{
/// <summary>
/// Component to apply power to the body of an entity.
/// </summary>
public sealed class BodyPowerComponent : PowerComponent
[Nooson]
[SerializationId()]
public sealed partial class BodyPowerComponent : PowerComponent
{
/// <summary>
/// Gets or sets a value indicating the time a jump should take.
/// </summary>
public int JumpTime { get; set; }

/// <inheritdoc />
public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);

writer.Write(JumpTime);
}

/// <inheritdoc />
public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);

JumpTime = reader.ReadInt32();
}
}
}

Loading
Loading