Progress on tutorial, misc bugfixes

This commit is contained in:
Regalis
2015-08-20 00:42:24 +03:00
parent e19ac600ff
commit 8c559f716f
19 changed files with 356 additions and 85 deletions
+22 -7
View File
@@ -72,13 +72,18 @@ namespace Subsurface.Networking
myCharacter = Character.Controlled;
// Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
NetPeerConfiguration Config = new NetPeerConfiguration("subsurface");
//Config.SimulatedLoss = 0.2f;
//Config.SimulatedMinimumLatency = 0.5f;
NetPeerConfiguration config = new NetPeerConfiguration("subsurface");
#if DEBUG
config.SimulatedLoss = 0.2f;
config.SimulatedMinimumLatency = 0.3f;
#endif
config.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt
| NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
// Create new client, with previously created configs
client = new NetClient(Config);
client = new NetClient(config);
NetOutgoingMessage outmsg = client.CreateMessage();
client.Start();
@@ -267,9 +272,19 @@ namespace Subsurface.Networking
Character.Controlled = null;
Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
}
else
else if (gameStarted)
{
if (gameStarted) new NetworkEvent(myCharacter.ID, true);
Vector2 charMovement = myCharacter.AnimController.TargetMovement;
if ((charMovement==Vector2.Zero || charMovement.Length()<0.001f) &&
!myCharacter.ActionKeyDown.State && !myCharacter.SecondaryKeyDown.State)
{
new NetworkEvent(NetworkEventType.NotMoving, myCharacter.ID, true);
}
else
{
new NetworkEvent(myCharacter.ID, true);
}
}
}
+35 -6
View File
@@ -30,7 +30,7 @@ namespace Subsurface.Networking
private Client myClient;
public GameServer(string name, int port, bool isPublic = false, string password="", bool attemptUPnP = false, int maxPlayers = 10)
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
{
var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD);
endRoundButton.OnClicked = EndButtonHit;
@@ -41,8 +41,10 @@ namespace Subsurface.Networking
config = new NetPeerConfiguration("subsurface");
//config.SimulatedLoss = 0.2f;
//config.SimulatedMinimumLatency = 0.5f;
#if DEBUG
config.SimulatedLoss = 0.2f;
config.SimulatedMinimumLatency = 0.3f;
#endif
config.Port = port;
Port = port;
@@ -53,6 +55,9 @@ namespace Subsurface.Networking
}
config.MaximumConnections = maxPlayers;
config.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt
| NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
@@ -457,6 +462,31 @@ namespace Subsurface.Networking
{
//System.Diagnostics.Debug.WriteLine("networkevent "+networkEvent.ID);
List<NetConnection> recipients = new List<NetConnection>();
if (!networkEvent.IsImportant)
{
Entity e = Entity.FindEntityByID(networkEvent.ID);
foreach (Client c in connectedClients)
{
if (c.character==null) continue;
if (Vector2.Distance(e.SimPosition, c.character.SimPosition) > 2000.0f) continue;
recipients.Add(c.Connection);
}
}
else
{
foreach (Client c in connectedClients)
{
if (c.character == null) continue;
recipients.Add(c.Connection);
}
}
if (recipients.Count == 0) return;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NetworkEvent);
//if (!networkEvent.IsClient) continue;
@@ -467,7 +497,7 @@ namespace Subsurface.Networking
if (server.ConnectionsCount>0)
{
server.SendMessage(message, server.Connections,
server.SendMessage(message, recipients,
(networkEvent.IsImportant) ? NetDeliveryMethod.Unreliable : NetDeliveryMethod.ReliableUnordered, 0);
}
@@ -703,8 +733,7 @@ namespace Subsurface.Networking
spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + server.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White);
spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + server.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White);
y += 110;
foreach (Client c in connectedClients)
{
+3 -2
View File
@@ -11,14 +11,15 @@ namespace Subsurface.Networking
DropItem = 3,
InventoryUpdate = 4,
PickItem = 5,
UpdateProperty = 6
UpdateProperty = 6,
NotMoving = 7
}
class NetworkEvent
{
public static List<NetworkEvent> events = new List<NetworkEvent>();
private static bool[] isImportant = { false, true, false, true, true, true };
private static bool[] isImportant = { false, true, false, true, true, true, true, false };
private int id;