Skip to content

Commit ebd35de

Browse files
authored
Merge pull request #575 from starfi5h/pr-ux
Enhance user experience + bump version
2 parents e5afc61 + b966cb5 commit ebd35de

File tree

20 files changed

+152
-34
lines changed

20 files changed

+152
-34
lines changed

.github/scripts/thunderstore_bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ function generateManifest() {
123123
BEPINEX_DEPENDENCY,
124124
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
125125
"PhantomGamers-IlLine-1.0.0",
126-
"CommonAPI-CommonAPI-1.5.1",
127-
"starfi5h-BulletTime-1.2.5",
126+
"CommonAPI-CommonAPI-1.5.4",
127+
"starfi5h-BulletTime-1.2.6",
128128
],
129129
website_url: "https://github.com/hubastard/nebula"
130130
};

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog
22

3+
0.8.10:
4+
5+
- @starfi5h: Fix compilation with 0.9.26.13034
6+
- @starfi5h: Fix a bug that makes advance miner power usage abnormal
7+
- @starfi5h: Add new chat settings NotificationDuration
8+
39
0.8.9:
410

511
- @PhantomGamers: Fixed compilation with 0.9.26

NebulaModel/MultiplayerOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public bool StreamerMode {
102102
[DisplayName("Default chat size"), Category("Chat")]
103103
public ChatSize DefaultChatSize { get; set; } = ChatSize.Medium;
104104

105+
[DisplayName("Notification duration"), Category("Chat")]
106+
public int NotificationDuration { get; set; } = 15;
107+
105108
[DisplayName("Cleanup inactive sessions"), Category("Network")]
106109
[Description("If disabled the underlying networking library will not cleanup inactive connections. This might solve issues with clients randomly disconnecting and hosts having a 'System.ObjectDisposedException'.")]
107110
public bool CleanupInactiveSessions { get; set; } = true;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace NebulaModel.Packets.GameStates
2+
{
3+
public class FragmentInfo
4+
{
5+
public int Size { get; set; }
6+
7+
public FragmentInfo() { }
8+
public FragmentInfo(int size)
9+
{
10+
Size = size;
11+
}
12+
}
13+
}

NebulaNetwork/Client.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
using NebulaModel.Packets.Session;
1010
using NebulaModel.Utils;
1111
using NebulaWorld;
12-
using NebulaWorld.SocialIntegration;
12+
using NebulaWorld.GameStates;
13+
using System.IO;
1314
using System.Net;
1415
using System.Net.Sockets;
1516
using System.Reflection;
@@ -21,6 +22,7 @@ namespace NebulaNetwork
2122
{
2223
public class Client : NetworkProvider, IClient
2324
{
25+
private const float FRAGEMENT_UPDATE_INTERVAL = 0.1f;
2426
private const float GAME_STATE_UPDATE_INTERVAL = 1f;
2527
private const float MECHA_SYNCHONIZATION_INTERVAL = 30f;
2628

@@ -32,7 +34,7 @@ public class Client : NetworkProvider, IClient
3234
private NebulaConnection serverConnection;
3335
private bool websocketAuthenticationFailure;
3436

35-
37+
private float fragmentUpdateTimer = 0f;
3638
private float mechaSynchonizationTimer = 0f;
3739
private float gameStateUpdateTimer = 0f;
3840

@@ -186,13 +188,23 @@ public override void Update()
186188
gameStateUpdateTimer = 0f;
187189
}
188190
}
191+
192+
fragmentUpdateTimer += Time.deltaTime;
193+
if (fragmentUpdateTimer >= FRAGEMENT_UPDATE_INTERVAL)
194+
{
195+
if (GameStatesManager.FragmentSize > 0)
196+
{
197+
GameStatesManager.UpdateBufferLength(GetFragmentBufferLength());
198+
}
199+
fragmentUpdateTimer = 0f;
200+
}
189201
}
190202

191203
private void ClientSocket_OnMessage(object sender, MessageEventArgs e)
192204
{
193205
if (!Multiplayer.IsLeavingGame)
194206
{
195-
PacketProcessor.EnqueuePacketForProcessing(e.RawData, new NebulaConnection(clientSocket, serverEndpoint, PacketProcessor));
207+
PacketProcessor.EnqueuePacketForProcessing(e.RawData, serverConnection);
196208
}
197209
}
198210

@@ -322,5 +334,18 @@ private static void DisableNagleAlgorithm(WebSocket socket)
322334
tcpClient.NoDelay = true;
323335
}
324336
}
337+
338+
private int GetFragmentBufferLength()
339+
{
340+
MemoryStream buffer = (MemoryStream)AccessTools.Field(typeof(WebSocket), "_fragmentsBuffer").GetValue(clientSocket);
341+
if (buffer != null)
342+
{
343+
return (int)buffer.Length;
344+
}
345+
else
346+
{
347+
return 0;
348+
}
349+
}
325350
}
326351
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NebulaAPI;
2+
using NebulaModel.Networking;
3+
using NebulaModel.Packets;
4+
using NebulaModel.Packets.GameStates;
5+
using NebulaWorld.GameStates;
6+
7+
namespace NebulaNetwork.PacketProcessors.GameStates
8+
{
9+
[RegisterPacketProcessor]
10+
public class FragmentInfoProcessor : PacketProcessor<FragmentInfo>
11+
{
12+
public override void ProcessPacket(FragmentInfo packet, NebulaConnection conn)
13+
{
14+
if (IsClient)
15+
{
16+
GameStatesManager.FragmentSize = packet.Size;
17+
}
18+
}
19+
}
20+
}

NebulaNetwork/PacketProcessors/GameStates/GameStateUpdateProcessor.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace NebulaNetwork.PacketProcessors.GameStates
1414
[RegisterPacketProcessor]
1515
public class GameStateUpdateProcessor : PacketProcessor<GameStateUpdate>
1616
{
17-
public float MaxUPS = 240f;
18-
public float MinUPS = 30f;
1917
public float BUFFERING_TIME = 30f;
2018
public float BUFFERING_TICK = 60f;
2119

@@ -68,23 +66,23 @@ public override void ProcessPacket(GameStateUpdate packet, NebulaConnection conn
6866
// Adjust client's UPS to match game tick with server, range 30~120 UPS
6967
float UPS = diff / 1f + avaerageUPS;
7068
long skipTick = 0;
71-
if (UPS > MaxUPS)
69+
if (UPS > GameStatesManager.MaxUPS)
7270
{
7371
// Try to disturbute game tick difference into BUFFERING_TIME (seconds)
74-
if (diff / BUFFERING_TIME + avaerageUPS > MaxUPS)
72+
if (diff / BUFFERING_TIME + avaerageUPS > GameStatesManager.MaxUPS)
7573
{
7674
// The difference is too large, need to skip ticks to catch up
77-
skipTick = (long)(UPS - MaxUPS);
75+
skipTick = (long)(UPS - GameStatesManager.MaxUPS);
7876
}
79-
UPS = MaxUPS;
77+
UPS = GameStatesManager.MaxUPS;
8078
}
81-
else if (UPS < MinUPS)
79+
else if (UPS < GameStatesManager.MinUPS)
8280
{
83-
if (diff + avaerageUPS - MinUPS < -BUFFERING_TICK)
81+
if (diff + avaerageUPS - GameStatesManager.MinUPS < -BUFFERING_TICK)
8482
{
85-
skipTick = (long)(UPS - MinUPS);
83+
skipTick = (long)(UPS - GameStatesManager.MinUPS);
8684
}
87-
UPS = MinUPS;
85+
UPS = GameStatesManager.MinUPS;
8886
}
8987
if (skipTick != 0)
9088
{

NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NebulaModel.Packets;
55
using NebulaModel.Packets.Planet;
66
using NebulaWorld;
7+
using NebulaWorld.GameStates;
78

89
namespace NebulaNetwork.PacketProcessors.Planet
910
{
@@ -16,6 +17,9 @@ public override void ProcessPacket(FactoryData packet, NebulaConnection conn)
1617
{
1718
return;
1819
}
20+
// The whole fragment is received
21+
GameStatesManager.FragmentSize = 0;
22+
1923
// Stop packet processing until factory is imported and loaded
2024
((NebulaModel.NetworkProvider)Multiplayer.Session.Network).PacketProcessor.Enable = false;
2125
Log.Info($"Pause PacketProcessor (FactoryDataProcessor)");

NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NebulaModel.Networking;
44
using NebulaModel.Packets;
55
using NebulaModel.Packets.Planet;
6+
using NebulaModel.Packets.GameStates;
67
using NebulaWorld;
78

89
namespace NebulaNetwork.PacketProcessors.Planet
@@ -25,6 +26,7 @@ public override void ProcessPacket(FactoryLoadRequest packet, NebulaConnection c
2526
factory.Export(writer.BinaryWriter);
2627
byte[] data = writer.CloseAndGetBytes();
2728
Log.Info($"Sent {data.Length} bytes of data for PlanetFactory {planet.name} (ID: {planet.id})");
29+
conn.SendPacket(new FragmentInfo(data.Length + planet.data.modData.Length));
2830
conn.SendPacket(new FactoryData(packet.PlanetID, data, planet.data.modData));
2931
}
3032

NebulaNetwork/PacketProcessors/Universe/DysonSphereDataProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NebulaModel.Packets;
55
using NebulaModel.Packets.Universe;
66
using NebulaWorld;
7+
using NebulaWorld.GameStates;
78
using System.Collections.Generic;
89
using System.IO;
910

@@ -41,6 +42,8 @@ public override void ProcessPacket(DysonSphereData packet, NebulaConnection conn
4142
break;
4243

4344
case DysonSphereRespondEvent.Load:
45+
// The whole fragment is received
46+
GameStatesManager.FragmentSize = 0;
4447
//Failsafe, if client does not have instantiated sphere for the star, it will create dummy one that will be replaced during import
4548
GameMain.data.dysonSpheres[packet.StarIndex] = new DysonSphere();
4649
GameMain.data.statistics.production.Init(GameMain.data);

0 commit comments

Comments
 (0)