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

View File

@@ -18,7 +18,7 @@
<item name="Screwdriver"/>
</fixrequirement>
<Sprite texture ="reactor.png" depth="0.8"/>
<Sprite texture = "reactor.png" depth="0.8"/>
<Reactor canbeselected = "true">
<GuiFrame rect="0,0,0.6,0.7" alignment="Center" color="0.0,0.0,0.0,0.8"/>

View File

@@ -49,13 +49,11 @@
<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">
<Explosion range="5" damage="5" stun="10" force="0.1"/>
</StatusEffect>
</Throwable>
<Pickable slots="Any,RightHand,LeftHand"/>
</Item>
</Items>

View File

@@ -732,11 +732,6 @@ namespace Subsurface
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, (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);
}

View File

@@ -112,15 +112,24 @@ namespace Subsurface.Items.Components
targetLevel = null;
isActive = !isActive;
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);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true)) FlowPercentage += 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true)) FlowPercentage -= 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true))
{
FlowPercentage += 1.0f;
item.NewComponentEvent(this, true);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true))
{
FlowPercentage -= 1.0f;
item.NewComponentEvent(this, true);
}
item.NewComponentEvent(this, true);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)

View File

@@ -269,10 +269,12 @@ namespace Subsurface.Items.Components
}
bool valueChanged = false;
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
isActive = true;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
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);
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 + 80, 40, 40), "-", true)) FissionRate -= 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true))
{
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;
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);
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 + 80, 40, 40), "-", true)) CoolingRate -= 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true))
{
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;
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);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true)) shutDownTemp += 100.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true)) shutDownTemp -= 100.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true))
{
valueChanged = true;
shutDownTemp += 100.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true))
{
valueChanged = true;
shutDownTemp -= 100.0f;
}
item.NewComponentEvent(this, true);
if (valueChanged)
{
item.NewComponentEvent(this, true);
valueChanged = false;
}
}
static void UpdateGraph<T>(IList<T> graph, T newValue)

View File

@@ -21,6 +21,9 @@ namespace Subsurface.Items.Components
private static PathFinder pathFinder;
private float networkUpdateTimer;
private bool valueChanged;
bool AutoPilot
{
get { return autoPilot; }
@@ -90,6 +93,16 @@ namespace Subsurface.Items.Components
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.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.Y = -targetVelocity.Y;
item.NewComponentEvent(this, true);
valueChanged = true;
}
}
}

View File

@@ -195,9 +195,9 @@ namespace Subsurface.Items.Components
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))
{
item.NewComponentEvent(this, true);
{
rechargeSpeed = Math.Min(rechargeSpeed + 10.0f, maxRechargeSpeed);
item.NewComponentEvent(this, true);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 150, 40, 40), "-", true))

View File

@@ -38,7 +38,12 @@ namespace Subsurface.Items.Components
get { return ToolBox.Vector4ToString(lightColor.ToVector4()); }
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);
}
}

View File

@@ -500,6 +500,8 @@ namespace Subsurface.Networking
character.ID = ID;
character.Inventory.ID = inventoryID;
character.IsNetworkPlayer = true;
character.GiveJobItems(closestWaypoint);
return character;
@@ -516,7 +518,7 @@ namespace Subsurface.Networking
msg.Write((byte)type);
msg.Write(message);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
client.SendMessage(msg, NetDeliveryMethod.Unreliable);
}
/// <summary>

View File

@@ -439,11 +439,9 @@ namespace Subsurface.Networking
public void EndGame(string endMessage)
{
Submarine.Unload();
gameStarted = false;
if (connectedClients.Count>0)
if (connectedClients.Count > 0)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.EndGame);
@@ -461,6 +459,10 @@ namespace Subsurface.Networking
}
}
Submarine.Unload();
gameStarted = false;
Game1.NetLobbyScreen.Select();
DebugConsole.ThrowError(endMessage);
@@ -565,12 +567,12 @@ namespace Subsurface.Networking
}
if (recipients.Count>0)
{
server.SendMessage(msg, recipients, NetDeliveryMethod.ReliableUnordered, 0);
server.SendMessage(msg, recipients, NetDeliveryMethod.Unreliable, 0);
}
}
else
{
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
server.SendMessage(msg, server.Connections, NetDeliveryMethod.Unreliable, 0);
}
}

View File

@@ -18,7 +18,7 @@ namespace Subsurface.Networking
{
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;

Binary file not shown.