reliable network messages aren't sent as frequently, equippable grenades/detonators

This commit is contained in:
Regalis
2015-08-01 13:48:20 +03:00
parent 85b0cda4ca
commit 01b1dfe0df
12 changed files with 90 additions and 32 deletions
+1 -3
View File
@@ -49,13 +49,11 @@
<Body width="11" height="24" density="15" friction="0.8f"/> <Body width="11" height="24" density="15" friction="0.8f"/>
<Throwable holdpos="0,0" handle1="0,0" throwforce="5.0" aimpos="35,-10"> <Throwable slots="Any,RightHand,LeftHand" holdpos="0,0" handle1="0,0" throwforce="5.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0" sound="Content/Items/Weapons/stunGrenade.ogg"> <StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0" sound="Content/Items/Weapons/stunGrenade.ogg">
<Explosion range="5" damage="5" stun="10" force="0.1"/> <Explosion range="5" damage="5" stun="10" force="0.1"/>
</StatusEffect> </StatusEffect>
</Throwable> </Throwable>
<Pickable slots="Any,RightHand,LeftHand"/>
</Item> </Item>
</Items> </Items>
@@ -732,11 +732,6 @@ namespace Subsurface
Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 50.0f); Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 50.0f);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false); GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true); GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true);
//GUI.DrawLine(spriteBatch, ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y),
// ConvertUnits.ToDisplayUnits(animController.limbs[0].SimPosition.X, animController.limbs[0].SimPosition.Y) +
// ConvertUnits.ToDisplayUnits(animController.targetMovement.X, animController.targetMovement.Y), Color.Green);
} }
@@ -112,15 +112,24 @@ namespace Subsurface.Items.Components
targetLevel = null; targetLevel = null;
isActive = !isActive; isActive = !isActive;
if (!isActive) currPowerConsumption = 0.0f; if (!isActive) currPowerConsumption = 0.0f;
item.NewComponentEvent(this, true);
} }
spriteBatch.DrawString(GUI.Font, "Flow percentage: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White); spriteBatch.DrawString(GUI.Font, "Flow percentage: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true)) FlowPercentage += 1.0f; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true)) FlowPercentage -= 1.0f; {
FlowPercentage += 1.0f;
item.NewComponentEvent(this, true); item.NewComponentEvent(this, true);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true))
{
FlowPercentage -= 1.0f;
item.NewComponentEvent(this, true);
}
} }
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
@@ -269,10 +269,12 @@ namespace Subsurface.Items.Components
} }
bool valueChanged = false;
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{ {
isActive = true; isActive = true;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X; int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y; int y = GuiFrame.Rect.Y;
@@ -291,27 +293,59 @@ namespace Subsurface.Items.Components
spriteBatch.DrawString(GUI.Font, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y + 30), Color.White); spriteBatch.DrawString(GUI.Font, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y + 30), Color.White);
DrawGraph(fissionRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset); DrawGraph(fissionRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) FissionRate += 1.0f; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) FissionRate -= 1.0f; {
valueChanged = true;
FissionRate += 1.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true))
{
valueChanged = true;
FissionRate -= 1.0f;
}
y += 130; y += 130;
spriteBatch.DrawString(GUI.Font, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 30, y + 30), Color.White); spriteBatch.DrawString(GUI.Font, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 30, y + 30), Color.White);
DrawGraph(coolingRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset); DrawGraph(coolingRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) CoolingRate += 1.0f; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) CoolingRate -= 1.0f; {
valueChanged = true;
CoolingRate += 1.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true))
{
valueChanged = true;
CoolingRate -= 1.0f;
}
y = y - 260; y = y - 260;
spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White); spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 60, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON"))) autoTemp = !autoTemp; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 60, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON")))
{
valueChanged = true;
autoTemp = !autoTemp;
}
spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White); spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true)) shutDownTemp += 100.0f; if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true)) shutDownTemp -= 100.0f; {
valueChanged = true;
shutDownTemp += 100.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true))
{
valueChanged = true;
shutDownTemp -= 100.0f;
}
if (valueChanged)
{
item.NewComponentEvent(this, true); item.NewComponentEvent(this, true);
valueChanged = false;
}
} }
static void UpdateGraph<T>(IList<T> graph, T newValue) static void UpdateGraph<T>(IList<T> graph, T newValue)
@@ -21,6 +21,9 @@ namespace Subsurface.Items.Components
private static PathFinder pathFinder; private static PathFinder pathFinder;
private float networkUpdateTimer;
private bool valueChanged;
bool AutoPilot bool AutoPilot
{ {
get { return autoPilot; } get { return autoPilot; }
@@ -90,6 +93,16 @@ namespace Subsurface.Items.Components
TargetVelocity = targetSpeed*100.0f; TargetVelocity = targetSpeed*100.0f;
} }
} }
else if (valueChanged)
{
networkUpdateTimer -= deltaTime;
if (networkUpdateTimer<=0.0f)
{
item.NewComponentEvent(this, true);
networkUpdateTimer = 1.0f;
valueChanged = false;
}
}
item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out"); item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out");
item.SendSignal((-targetVelocity.Y).ToString(CultureInfo.InvariantCulture), "velocity_y_out"); item.SendSignal((-targetVelocity.Y).ToString(CultureInfo.InvariantCulture), "velocity_y_out");
@@ -136,7 +149,7 @@ namespace Subsurface.Items.Components
targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y); targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y);
targetVelocity.Y = -targetVelocity.Y; targetVelocity.Y = -targetVelocity.Y;
item.NewComponentEvent(this, true); valueChanged = true;
} }
} }
} }
@@ -196,8 +196,8 @@ namespace Subsurface.Items.Components
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (rechargeSpeed / maxRechargeSpeed), new Vector2(x + 30, y + 100), Color.White); spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (rechargeSpeed / maxRechargeSpeed), new Vector2(x + 30, y + 100), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 50, y + 150, 40, 40), "+", true)) if (GUI.DrawButton(spriteBatch, new Rectangle(x + 50, y + 150, 40, 40), "+", true))
{ {
item.NewComponentEvent(this, true);
rechargeSpeed = Math.Min(rechargeSpeed + 10.0f, maxRechargeSpeed); rechargeSpeed = Math.Min(rechargeSpeed + 10.0f, maxRechargeSpeed);
item.NewComponentEvent(this, true);
} }
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 150, 40, 40), "-", true)) if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 150, 40, 40), "-", true))
@@ -38,7 +38,12 @@ namespace Subsurface.Items.Components
get { return ToolBox.Vector4ToString(lightColor.ToVector4()); } get { return ToolBox.Vector4ToString(lightColor.ToVector4()); }
set set
{ {
lightColor = new Color(ToolBox.ParseToVector4(value)); Vector4 newColor = ToolBox.ParseToVector4(value);
newColor.X = MathHelper.Clamp(newColor.X, 0.0f, 1.0f);
newColor.Y = MathHelper.Clamp(newColor.Y, 0.0f, 1.0f);
newColor.Z = MathHelper.Clamp(newColor.Z, 0.0f, 1.0f);
newColor.W = MathHelper.Clamp(newColor.W, 0.0f, 1.0f);
lightColor = new Color(newColor);
} }
} }
+3 -1
View File
@@ -500,6 +500,8 @@ namespace Subsurface.Networking
character.ID = ID; character.ID = ID;
character.Inventory.ID = inventoryID; character.Inventory.ID = inventoryID;
character.IsNetworkPlayer = true;
character.GiveJobItems(closestWaypoint); character.GiveJobItems(closestWaypoint);
return character; return character;
@@ -516,7 +518,7 @@ namespace Subsurface.Networking
msg.Write((byte)type); msg.Write((byte)type);
msg.Write(message); msg.Write(message);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); client.SendMessage(msg, NetDeliveryMethod.Unreliable);
} }
/// <summary> /// <summary>
+6 -4
View File
@@ -439,9 +439,7 @@ namespace Subsurface.Networking
public void EndGame(string endMessage) public void EndGame(string endMessage)
{ {
Submarine.Unload();
gameStarted = false;
if (connectedClients.Count > 0) if (connectedClients.Count > 0)
{ {
@@ -461,6 +459,10 @@ namespace Subsurface.Networking
} }
} }
Submarine.Unload();
gameStarted = false;
Game1.NetLobbyScreen.Select(); Game1.NetLobbyScreen.Select();
DebugConsole.ThrowError(endMessage); DebugConsole.ThrowError(endMessage);
@@ -565,12 +567,12 @@ namespace Subsurface.Networking
} }
if (recipients.Count>0) if (recipients.Count>0)
{ {
server.SendMessage(msg, recipients, NetDeliveryMethod.ReliableUnordered, 0); server.SendMessage(msg, recipients, NetDeliveryMethod.Unreliable, 0);
} }
} }
else else
{ {
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0); server.SendMessage(msg, server.Connections, NetDeliveryMethod.Unreliable, 0);
} }
} }
+1 -1
View File
@@ -18,7 +18,7 @@ namespace Subsurface.Networking
{ {
public static List<NetworkEvent> events = new List<NetworkEvent>(); public static List<NetworkEvent> events = new List<NetworkEvent>();
private static bool[] isImportant = { false, true, true, true, true, true }; private static bool[] isImportant = { false, true, false, true, true, true };
private int id; private int id;
Binary file not shown.