v0.2.2: updated Lidgren, railgun shells can be bought, autorestart server, netstats, tutorial moloch spawning in a wall fix, misc error checks
This commit is contained in:
@@ -299,7 +299,7 @@ namespace Barotrauma
|
||||
//the collision is ignored if the lowest limb is under the platform
|
||||
if (lowestLimb==null || lowestLimb.Position.Y < structure.Rect.Y) return false;
|
||||
}
|
||||
else if (structure.StairDirection!=Direction.None)
|
||||
else if (structure.StairDirection!=Direction.None && lowestLimb != null)
|
||||
{
|
||||
if (targetMovement.Y < 0.5f)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Barotrauma
|
||||
|
||||
public bool Wrap;
|
||||
|
||||
private float textDepth;
|
||||
|
||||
public override Vector4 Padding
|
||||
{
|
||||
get { return padding; }
|
||||
@@ -41,6 +43,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public float TextDepth
|
||||
{
|
||||
get { return textDepth; }
|
||||
set { textDepth = MathHelper.Clamp(value, 0.0f, 1.0f); }
|
||||
}
|
||||
|
||||
public bool LimitText
|
||||
{
|
||||
get;
|
||||
@@ -221,7 +229,7 @@ namespace Barotrauma
|
||||
new Vector2(rect.X, rect.Y) + textPos,
|
||||
textColor * (textColor.A / 255.0f),
|
||||
0.0f, origin, 1.0f,
|
||||
SpriteEffects.None, 0.0f);
|
||||
SpriteEffects.None, textDepth);
|
||||
}
|
||||
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace Barotrauma
|
||||
Client traitor;
|
||||
Client target;
|
||||
|
||||
private Character traitorCharacter, targetCharacter;
|
||||
|
||||
public TraitorMode(GameModePreset preset)
|
||||
: base(preset)
|
||||
{
|
||||
@@ -47,34 +49,38 @@ namespace Barotrauma
|
||||
}
|
||||
target = GameMain.Server.connectedClients[targetIndex];
|
||||
|
||||
traitorCharacter = traitor.character;
|
||||
targetCharacter = target.character;
|
||||
|
||||
|
||||
GameMain.Server.NewTraitor(traitor, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target.character.IsDead)
|
||||
if (target.character == null || target.character.IsDead)
|
||||
{
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". The task was successful.";
|
||||
string endMessage = traitorCharacter.Name + " was a traitor! ";
|
||||
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + targetCharacter.Name + ". The task was successful.";
|
||||
End(endMessage);
|
||||
}
|
||||
else if (traitor.character.IsDead)
|
||||
else if (traitor.character == null || traitor.character.IsDead)
|
||||
{
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ", but ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "he" : "she";
|
||||
endMessage += " got " + ((traitor.character.Info.Gender == Gender.Male) ? "himself" : "herself");
|
||||
string endMessage = traitorCharacter.Name + " was a traitor! ";
|
||||
//TODO: remove references to traitor.character
|
||||
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + targetCharacter.Name + ", but ";
|
||||
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "he" : "she";
|
||||
endMessage += " got " + ((traitorCharacter.Info.Gender == Gender.Male) ? "himself" : "herself");
|
||||
endMessage += " killed before completing it.";
|
||||
End(endMessage);
|
||||
return;
|
||||
}
|
||||
else if (Level.Loaded.AtEndPosition)
|
||||
{
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". ";
|
||||
string endMessage = traitorCharacter.Name + " was a traitor! ";
|
||||
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + targetCharacter.Name + ". ";
|
||||
endMessage += "The task was unsuccessful - the has submarine reached its destination.";
|
||||
End(endMessage);
|
||||
return;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Barotrauma
|
||||
|
||||
GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameModePreset.list.Find(gm => gm.Name.ToLower()=="tutorial"));
|
||||
|
||||
GameMain.GameSession.StartShift("tutorial");
|
||||
GameMain.GameSession.StartShift("tuto");
|
||||
|
||||
GameMain.GameSession.taskManager.Tasks.Clear();
|
||||
|
||||
@@ -164,6 +164,7 @@ namespace Barotrauma
|
||||
|
||||
while (Math.Abs(reactor.Temperature-3000.0f) > 100.0f)
|
||||
{
|
||||
reactor.AutoTemp = false;
|
||||
reactor.ShutDownTemp = Math.Min(reactor.ShutDownTemp, 5000.0f);
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
@@ -131,6 +131,18 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
picker = character;
|
||||
|
||||
if (item.body == null)
|
||||
{
|
||||
if (body!=null)
|
||||
{
|
||||
item.body = body;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.body.Enabled)
|
||||
{
|
||||
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace Barotrauma.Items.Components
|
||||
null, null, true);
|
||||
textBlock.Font = GUI.SmallFont;
|
||||
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
textBlock.TextDepth = item.Sprite.Depth - 0.0001f;
|
||||
}
|
||||
return textBlock;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (stickJoint != null && doesStick)
|
||||
{
|
||||
if (stickTarget!=null) item.body.FarseerBody.RestoreCollisionWith(stickTarget);
|
||||
if (stickTarget != null)
|
||||
{
|
||||
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
|
||||
stickTarget = null;
|
||||
}
|
||||
GameMain.World.RemoveJoint(stickJoint);
|
||||
stickJoint = null;
|
||||
}
|
||||
@@ -111,25 +115,19 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (stickJoint != null)
|
||||
if (stickJoint != null && stickJoint.JointTranslation < 0.01f)
|
||||
{
|
||||
if (stickJoint.JointTranslation < 0.01f)
|
||||
if (stickTarget!=null)
|
||||
{
|
||||
if (stickTarget!=null)
|
||||
{
|
||||
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
|
||||
}
|
||||
|
||||
GameMain.World.RemoveJoint(stickJoint);
|
||||
stickJoint = null;
|
||||
|
||||
IsActive = false;
|
||||
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
|
||||
stickTarget = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
GameMain.World.RemoveJoint(stickJoint);
|
||||
stickJoint = null;
|
||||
|
||||
IsActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnProjectileCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
|
||||
@@ -230,6 +230,13 @@ namespace Barotrauma
|
||||
int itemCapacity = item.Capacity;
|
||||
if (itemCapacity == 0) return;
|
||||
|
||||
#if DEBUG
|
||||
System.Diagnostics.Debug.Assert(slotIndex>=0 && slotIndex<items.Length);
|
||||
#else
|
||||
if (slotIndex<0 || slotIndex>=items.Length) return;
|
||||
#endif
|
||||
|
||||
|
||||
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (rect.Height + 10) * itemCapacity - 5,
|
||||
rect.Width + 10, rect.Height + (rect.Height + 10) * itemCapacity + 10);
|
||||
|
||||
@@ -253,6 +260,7 @@ namespace Barotrauma
|
||||
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.1f : 0.3f), true);
|
||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.2f : 0.4f), false);
|
||||
|
||||
if (item == null) return;
|
||||
|
||||
|
||||
@@ -1163,11 +1163,19 @@ namespace Barotrauma
|
||||
switch (type)
|
||||
{
|
||||
case NetworkEventType.DropItem:
|
||||
if (body != null) body.FillNetworkData(type, message);
|
||||
if (body != null)
|
||||
{
|
||||
message.Write(body.SimPosition.X);
|
||||
message.Write(body.SimPosition.Y);
|
||||
}
|
||||
break;
|
||||
case NetworkEventType.UpdateComponent:
|
||||
message.Write((int)data);
|
||||
components[(int)data].FillNetworkData(type, message);
|
||||
|
||||
int componentIndex = (int)data;
|
||||
if (componentIndex < 0 || componentIndex >= components.Count) return;
|
||||
|
||||
message.Write((byte)componentIndex);
|
||||
components[componentIndex].FillNetworkData(type, message);
|
||||
break;
|
||||
case NetworkEventType.UpdateProperty:
|
||||
var allProperties = GetProperties<InGameEditable>();
|
||||
@@ -1215,11 +1223,16 @@ namespace Barotrauma
|
||||
switch (type)
|
||||
{
|
||||
case NetworkEventType.DropItem:
|
||||
if (body != null) body.ReadNetworkData(type, message);
|
||||
Vector2 newSimPos = Vector2.Zero;
|
||||
if (body != null)
|
||||
{
|
||||
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
}
|
||||
SetTransform(newSimPos, body.Rotation);
|
||||
Drop(null, false);
|
||||
break;
|
||||
case NetworkEventType.UpdateComponent:
|
||||
int componentIndex = message.ReadInt32();
|
||||
int componentIndex = message.ReadByte();
|
||||
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
||||
components[componentIndex].ReadNetworkData(type, message);
|
||||
break;
|
||||
@@ -1272,7 +1285,7 @@ namespace Barotrauma
|
||||
base.Remove();
|
||||
|
||||
//sprite.Remove();
|
||||
if (body != null) body.Remove();
|
||||
//if (body != null) body.Remove();
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
|
||||
@@ -255,7 +255,15 @@ namespace Barotrauma
|
||||
assignedWayPoints[i] = GetRandom(SpawnType.Human);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < assignedWayPoints.Length; i++ )
|
||||
{
|
||||
if (assignedWayPoints[i]==null)
|
||||
{
|
||||
DebugConsole.ThrowError("Couldn't find a waypoint for " + crew[i].Name + "!");
|
||||
assignedWayPoints[i] = WayPointList[0];
|
||||
}
|
||||
}
|
||||
|
||||
return assignedWayPoints;
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace Barotrauma.Networking
|
||||
NetConnectionStatus connectionStatus = (NetConnectionStatus)inc.ReadByte();
|
||||
Debug.WriteLine(connectionStatus);
|
||||
|
||||
if (connectionStatus != NetConnectionStatus.Connected)
|
||||
if (connectionStatus == NetConnectionStatus.Disconnected)
|
||||
{
|
||||
string denyMessage = inc.ReadString();
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Barotrauma.Networking
|
||||
//for keeping track of disconnected clients in case the reconnect shortly after
|
||||
private List<Client> disconnectedClients = new List<Client>();
|
||||
|
||||
private NetStats netStats;
|
||||
|
||||
//is the server running
|
||||
bool started;
|
||||
|
||||
@@ -34,6 +36,20 @@ namespace Barotrauma.Networking
|
||||
|
||||
private string password;
|
||||
|
||||
private bool autoRestart;
|
||||
|
||||
public bool AutoRestart
|
||||
{
|
||||
get { return (connectedClients.Count==0) ? false : autoRestart; }
|
||||
set
|
||||
{
|
||||
autoRestart = value;
|
||||
|
||||
AutoRestartTimer = autoRestart ? 20.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
public float AutoRestartTimer;
|
||||
|
||||
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
||||
{
|
||||
var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD);
|
||||
@@ -44,9 +60,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
config = new NetPeerConfiguration("barotrauma");
|
||||
|
||||
netStats = new NetStats();
|
||||
|
||||
#if DEBUG
|
||||
config.SimulatedLoss = 0.2f;
|
||||
config.SimulatedMinimumLatency = 0.3f;
|
||||
config.SimulatedDuplicatesChance = 0.05f;
|
||||
config.SimulatedMinimumLatency = 0.1f;
|
||||
#endif
|
||||
config.Port = port;
|
||||
Port = port;
|
||||
@@ -61,9 +81,9 @@ namespace Barotrauma.Networking
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
||||
NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt |
|
||||
NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
|
||||
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||
|
||||
|
||||
CoroutineManager.StartCoroutine(StartServer(isPublic));
|
||||
}
|
||||
|
||||
@@ -190,21 +210,23 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server", response.ErrorException);
|
||||
DebugConsole.ThrowError("Error while registering to master server", response.ErrorException);
|
||||
registeredToMaster = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")");
|
||||
registeredToMaster = false;
|
||||
DebugConsole.NewMessage("Error while reporting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")", Color.Red);
|
||||
//registeredToMaster = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (GameMain.DebugDraw) netStats.Update(deltaTime);
|
||||
|
||||
if (!started) return;
|
||||
|
||||
base.Update(deltaTime);
|
||||
@@ -212,6 +234,24 @@ namespace Barotrauma.Networking
|
||||
if (gameStarted)
|
||||
{
|
||||
inGameHUD.Update((float)Physics.step);
|
||||
|
||||
//if all characters dead
|
||||
if (AutoRestart &&
|
||||
connectedClients.Find(c => c.character != null && !c.character.IsDead)==null &&
|
||||
(myCharacter == null || myCharacter.IsDead))
|
||||
{
|
||||
EndButtonHit(null, null);
|
||||
AutoRestartTimer = 20.0f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0)
|
||||
{
|
||||
AutoRestartTimer -= deltaTime;
|
||||
if (AutoRestartTimer < 0.0f)
|
||||
{
|
||||
StartGameClicked(null,null);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = disconnectedClients.Count - 1; i >= 0; i-- )
|
||||
@@ -628,7 +668,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
List<Character> crew = new List<Character>();
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
||||
|
||||
|
||||
for (int i = 0; i < connectedClients.Count; i++)
|
||||
{
|
||||
connectedClients[i].character = new Character(
|
||||
@@ -817,7 +857,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void NewTraitor(Client traitor, Client target)
|
||||
{
|
||||
new GUIMessageBox("New traitor", traitor.name + " is the traitor and the target is " + target.name+".");
|
||||
//new GUIMessageBox("New traitor", traitor.name + " is the traitor and the target is " + target.name+".");
|
||||
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.Traitor);
|
||||
@@ -846,15 +886,27 @@ namespace Barotrauma.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);
|
||||
|
||||
|
||||
int resentMessages = 0;
|
||||
|
||||
y += 110;
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.SmallFont, c.name + ":", new Vector2(x + 10, y), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "- avg roundtrip " + c.Connection.AverageRoundtripTime+" s", new Vector2(x + 20, y + 15), Color.White);
|
||||
y += 50;
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "- resent messages " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 30), Color.White);
|
||||
|
||||
resentMessages += (int)c.Connection.Statistics.ResentMessages;
|
||||
|
||||
y += 50;
|
||||
}
|
||||
|
||||
netStats.AddValue(NetStats.NetStatType.ResentMessages, resentMessages);
|
||||
netStats.AddValue(NetStats.NetStatType.SentBytes, server.Statistics.SentBytes);
|
||||
netStats.AddValue(NetStats.NetStatType.ReceivedBytes, server.Statistics.ReceivedBytes);
|
||||
|
||||
netStats.Draw(spriteBatch, new Rectangle(200,0,800,200));
|
||||
|
||||
}
|
||||
|
||||
public bool UpdateNetLobby(object obj)
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class NetStats
|
||||
{
|
||||
public enum NetStatType
|
||||
{
|
||||
SentBytes = 0,
|
||||
ReceivedBytes = 1,
|
||||
ResentMessages = 2
|
||||
}
|
||||
|
||||
private Graph[] graphs;
|
||||
|
||||
private Queue<float>[] valueQueue;
|
||||
|
||||
private float[] lastValues;
|
||||
|
||||
const float UpdateInterval = 1.0f;
|
||||
float updateTimer;
|
||||
|
||||
public NetStats()
|
||||
{
|
||||
graphs = new Graph[3];
|
||||
|
||||
valueQueue = new Queue<float>[3];
|
||||
for (int i = 0; i < 3; i++ )
|
||||
{
|
||||
valueQueue[i] = new Queue<float>();
|
||||
graphs[i] = new Graph();
|
||||
}
|
||||
|
||||
lastValues = new float[3];
|
||||
}
|
||||
|
||||
public void AddValue(NetStatType statType, float value)
|
||||
{
|
||||
float valueChange = value - lastValues[(int)statType];
|
||||
|
||||
valueQueue[(int)statType].Enqueue(valueChange);
|
||||
|
||||
lastValues[(int)statType] = value;
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
updateTimer -= deltaTime;
|
||||
|
||||
if (updateTimer > 0.0f) return;
|
||||
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
int valueCount = valueQueue[i].Count;
|
||||
float totalValue = 0.0f;
|
||||
while (valueQueue[i].Count>1)
|
||||
{
|
||||
totalValue += valueQueue[i].Dequeue();
|
||||
}
|
||||
|
||||
graphs[i].Update(valueCount==0 ? 0.0f : totalValue/valueCount);
|
||||
}
|
||||
|
||||
updateTimer = UpdateInterval;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Rectangle rect)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Black*0.4f, true);
|
||||
|
||||
graphs[(int)NetStatType.ReceivedBytes].Draw(spriteBatch, rect, null, 0.0f, Color.Cyan);
|
||||
|
||||
graphs[(int)NetStatType.SentBytes].Draw(spriteBatch, rect, null, 0.0f, Color.Orange);
|
||||
|
||||
graphs[(int)NetStatType.ResentMessages].Draw(spriteBatch, rect, null, 0.0f, Color.Red);
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Max received: "+graphs[(int)NetStatType.ReceivedBytes].LargestValue()+" bytes/s",
|
||||
new Vector2(rect.X + 10, rect.Y+10), Color.Cyan);
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Max sent: " + graphs[(int)NetStatType.SentBytes].LargestValue() + " bytes/s",
|
||||
new Vector2(rect.X + 10, rect.Y + 30), Color.Orange);
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Max resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
||||
new Vector2(rect.X + 10, rect.Y + 50), Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
class Graph
|
||||
{
|
||||
const int ArraySize = 100;
|
||||
|
||||
private float[] values;
|
||||
|
||||
public Graph()
|
||||
{
|
||||
values = new float[ArraySize];
|
||||
}
|
||||
|
||||
public float LargestValue()
|
||||
{
|
||||
float maxValue = 0.0f;
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
if (values[i] > maxValue) maxValue = values[i];
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void Update(float newValue)
|
||||
{
|
||||
for (int i = values.Length-1; i > 0; i--)
|
||||
{
|
||||
values[i] = values[i - 1];
|
||||
}
|
||||
values[0] = newValue;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float? maxVal, float xOffset, Color color)
|
||||
{
|
||||
float graphMaxVal = 1.0f;
|
||||
if (maxVal == null)
|
||||
{
|
||||
graphMaxVal = LargestValue();
|
||||
}
|
||||
else if (maxVal > 0.0f)
|
||||
{
|
||||
graphMaxVal = (float)maxVal;
|
||||
}
|
||||
|
||||
float lineWidth = (float)rect.Width / (float)(values.Length - 2);
|
||||
float yScale = (float)rect.Height / graphMaxVal;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.White);
|
||||
|
||||
Vector2 prevPoint = new Vector2(rect.Right, rect.Bottom - (values[1] + (values[0] - values[1]) * xOffset) * yScale);
|
||||
|
||||
float currX = rect.Right - ((xOffset - 1.0f) * lineWidth);
|
||||
|
||||
for (int i = 1; i < values.Length - 1; i++)
|
||||
{
|
||||
currX -= lineWidth;
|
||||
|
||||
Vector2 newPoint = new Vector2(currX, rect.Bottom - values[i] * yScale);
|
||||
|
||||
GUI.DrawLine(spriteBatch, prevPoint, newPoint - new Vector2(1.0f, 0), color);
|
||||
|
||||
prevPoint = newPoint;
|
||||
}
|
||||
|
||||
Vector2 lastPoint = new Vector2(rect.X,
|
||||
rect.Bottom - (values[values.Length - 1] + (values[values.Length - 2] - values[values.Length - 1]) * xOffset) * yScale);
|
||||
|
||||
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -124,8 +124,15 @@ namespace Barotrauma.Networking
|
||||
System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString());
|
||||
|
||||
//System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e);
|
||||
|
||||
e.ReadNetworkData(eventType, message);
|
||||
try
|
||||
{
|
||||
e.ReadNetworkData(eventType, message);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Received invalid network message");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,19 +28,19 @@ namespace Barotrauma
|
||||
{
|
||||
using (var game = new GameMain())
|
||||
{
|
||||
//#if !DEBUG
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
game.Run();
|
||||
//#if !DEBUG
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CrashDump(game, "crashreport.txt", e);
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Barotrauma
|
||||
private GUIListBox playerList;
|
||||
|
||||
private GUIListBox subList, modeList, chatBox;
|
||||
|
||||
|
||||
private GUIListBox jobList;
|
||||
|
||||
private GUITextBox textBox, seedBox;
|
||||
@@ -29,6 +29,8 @@ namespace Barotrauma
|
||||
|
||||
private GUIFrame playerFrame;
|
||||
|
||||
private GUITickBox autoRestartBox;
|
||||
|
||||
private float camAngle;
|
||||
|
||||
public bool IsServer;
|
||||
@@ -91,10 +93,18 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//public string DurationText()
|
||||
//{
|
||||
// return "Duration: " + GameDuration.TotalMinutes + " min";
|
||||
//}
|
||||
private float autoRestartTimer;
|
||||
|
||||
public string AutoRestartText()
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
if (!GameMain.Server.AutoRestart) return "";
|
||||
return "Restarting in " + (int)GameMain.Server.AutoRestartTimer;
|
||||
}
|
||||
if (autoRestartTimer == 0.0f) return "";
|
||||
return "Restarting in " + (int)autoRestartTimer;
|
||||
}
|
||||
|
||||
public NetLobbyScreen()
|
||||
{
|
||||
@@ -194,7 +204,6 @@ namespace Barotrauma
|
||||
|
||||
//gamemode description ------------------------------------------------------------------
|
||||
|
||||
|
||||
var modeDescription = new GUITextBlock(
|
||||
new Rectangle(columnX, 150, (int)(columnWidth * 1.5f), infoFrame.Rect.Height - 150 - 80),
|
||||
"", GUI.Style, Alignment.TopLeft, Alignment.TopLeft, infoFrame, true, GameMain.GraphicsWidth>1024 ? GUI.Font : GUI.SmallFont);
|
||||
@@ -214,6 +223,14 @@ namespace Barotrauma
|
||||
seedBox.OnTextChanged = SelectSeed;
|
||||
LevelSeed = ToolBox.RandomSeed(8);
|
||||
|
||||
//automatic restart ------------------------------------------------------------------
|
||||
|
||||
autoRestartBox = new GUITickBox(new Rectangle(columnX, 190, 20, 20), "Automatic restart", Alignment.TopLeft, infoFrame);
|
||||
autoRestartBox.OnSelected = ToggleAutoRestart;
|
||||
|
||||
var restartText = new GUITextBlock(new Rectangle(columnX, 210, 20, 20), "", GUI.Style, infoFrame);
|
||||
restartText.TextGetter = AutoRestartText;
|
||||
|
||||
//server info ------------------------------------------------------------------
|
||||
|
||||
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.Style, infoFrame);
|
||||
@@ -230,6 +247,8 @@ namespace Barotrauma
|
||||
public override void Deselect()
|
||||
{
|
||||
textBox.Deselect();
|
||||
|
||||
seedBox.Text = ToolBox.RandomSeed(8);
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
@@ -372,6 +391,20 @@ namespace Barotrauma
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ToggleAutoRestart(object obj)
|
||||
{
|
||||
if (GameMain.Server == null) return false;
|
||||
|
||||
GUITickBox tickBox = obj as GUITickBox;
|
||||
if (tickBox==null) return false;
|
||||
|
||||
GameMain.Server.AutoRestart = tickBox.Selected;
|
||||
|
||||
GameMain.Server.UpdateNetLobby(obj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SelectMap(GUIComponent component, object obj)
|
||||
{
|
||||
if (GameMain.Server != null) GameMain.Server.UpdateNetLobby(obj);
|
||||
@@ -491,6 +524,11 @@ namespace Barotrauma
|
||||
if (jobInfoFrame != null) jobInfoFrame.Update((float)deltaTime);
|
||||
|
||||
if (playerFrame != null) playerFrame.Update((float)deltaTime);
|
||||
|
||||
if (autoRestartTimer != 0.0f && autoRestartBox.Selected)
|
||||
{
|
||||
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
|
||||
}
|
||||
|
||||
//durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
|
||||
}
|
||||
@@ -722,13 +760,15 @@ namespace Barotrauma
|
||||
//msg.Write(durationBar.BarScroll);
|
||||
msg.Write(LevelSeed);
|
||||
|
||||
msg.Write(GameMain.Server==null ? false : GameMain.Server.AutoRestart);
|
||||
msg.Write(GameMain.Server == null ? 0.0f : GameMain.Server.AutoRestartTimer);
|
||||
|
||||
msg.Write((byte)(playerList.CountChildren));
|
||||
for (int i = 0; i < playerList.CountChildren; i++)
|
||||
{
|
||||
string clientName = playerList.children[i].UserData as string;
|
||||
msg.Write(clientName==null ? "" : clientName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -741,6 +781,10 @@ namespace Barotrauma
|
||||
//float durationScroll = 0.0f;
|
||||
string levelSeed = "";
|
||||
|
||||
bool autoRestart = false;
|
||||
|
||||
float restartTimer = 0.0f;
|
||||
|
||||
try
|
||||
{
|
||||
mapName = msg.ReadString();
|
||||
@@ -755,6 +799,9 @@ namespace Barotrauma
|
||||
|
||||
levelSeed = msg.ReadString();
|
||||
|
||||
autoRestart = msg.ReadBoolean();
|
||||
restartTimer = msg.ReadFloat();
|
||||
|
||||
int playerCount = msg.ReadByte();
|
||||
|
||||
playerList.ClearChildren();
|
||||
@@ -773,6 +820,9 @@ namespace Barotrauma
|
||||
|
||||
modeList.Select(modeIndex);
|
||||
|
||||
autoRestartBox.Selected = autoRestart;
|
||||
autoRestartTimer = restartTimer;
|
||||
|
||||
//durationBar.BarScroll = durationScroll;
|
||||
|
||||
LevelSeed = levelSeed;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Barotrauma
|
||||
|
||||
new GUITextBlock(new Rectangle(middleX + columnX[0], 30, 0, 30), "Name", GUI.Style, menu);
|
||||
new GUITextBlock(new Rectangle(middleX + columnX[1], 30, 0, 30), "Players", GUI.Style, menu);
|
||||
new GUITextBlock(new Rectangle(middleX + columnX[2], 30, 0, 30), "Running", GUI.Style, menu);
|
||||
new GUITextBlock(new Rectangle(middleX + columnX[2], 30, 0, 30), "Round started", GUI.Style, menu);
|
||||
|
||||
joinButton = new GUIButton(new Rectangle(-170, 0, 150, 30), "Refresh", Alignment.BottomRight, GUI.Style, menu);
|
||||
joinButton.OnClicked = RefreshServers;
|
||||
@@ -90,8 +90,7 @@ namespace Barotrauma
|
||||
base.Select();
|
||||
|
||||
|
||||
//RefreshServers(null, null);
|
||||
//UpdateServerList();
|
||||
RefreshServers(null, null);
|
||||
}
|
||||
|
||||
private bool SelectServer(GUIComponent component, object obj)
|
||||
|
||||
Reference in New Issue
Block a user