This commit is contained in:
Sofia 2017-11-25 13:20:59 +02:00
parent e646141055
commit a97b2568e5
4 changed files with 11 additions and 6 deletions

View File

@ -44,7 +44,7 @@ namespace Network {
return inList; return inList;
} }
} }
return null; return Optional<Connection>.None;
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace Network {
PacketPeer = packetPeer; PacketPeer = packetPeer;
IsServer = isServer; IsServer = isServer;
ConnectionList = new ConnectionList(this); ConnectionList = new ConnectionList(this);
PacketDistributor = new PacketDistributor(this, 0.5f); PacketDistributor = new PacketDistributor(this, 2);
} }
public void Update(float delta) { public void Update(float delta) {

View File

@ -1,4 +1,5 @@
 
using Godot;
using Network.PacketHandling; using Network.PacketHandling;
using System.Collections.Generic; using System.Collections.Generic;
using Util; using Util;
@ -24,7 +25,7 @@ namespace Network.Syncing {
public void Update(float delta) { public void Update(float delta) {
TimeSinceLastSync += delta; TimeSinceLastSync += delta;
if (TimeSinceLastSync > Interval) { if (TimeSinceLastSync > Interval) {
TimeSinceLastSync -= Interval; TimeSinceLastSync = 0;
foreach (ConnectionHandler Handler in HandlerList) { foreach (ConnectionHandler Handler in HandlerList) {
Handler.SerializeAndSendQueues(); Handler.SerializeAndSendQueues();
@ -35,9 +36,10 @@ namespace Network.Syncing {
public void HandleRawPacket(PacketBuffer packetBuffer, Connection connection) { public void HandleRawPacket(PacketBuffer packetBuffer, Connection connection) {
var Handler = GetHandlerFor(connection); var Handler = GetHandlerFor(connection);
if (Handler.isEmpty) { if (Handler.isEmpty) {
var Temp = new ConnectionHandler(Peer, connection); Handler = new ConnectionHandler(Peer, connection);
HandlerList.Add(Temp); HandlerList.Add(Handler);
} }
Handler.Value.ReceiveBuffer(packetBuffer);
} }
public void AddHandler(Connection connection) { public void AddHandler(Connection connection) {
@ -77,7 +79,7 @@ namespace Network.Syncing {
return Curr; return Curr;
} }
} }
return null; return Optional<ConnectionHandler>.None;
} }
} }

View File

@ -16,6 +16,8 @@ namespace Util {
} }
} }
public Optional() { }
public Optional(T val) { public Optional(T val) {
Value = val; Value = val;
} }
@ -38,5 +40,6 @@ namespace Util {
if (opt.HasValue == HasValue) { return Equals(opt.Value, Value); } if (opt.HasValue == HasValue) { return Equals(opt.Value, Value); }
else { return opt.HasValue == HasValue; } else { return opt.HasValue == HasValue; }
} }
public static Optional<T> None { get { return new Optional<T>(); } }
} }
} }