Setting ragdoll position without limbs going through walls, rotating entire ragdoll, using combined network messages client->server, fixed fabricators

This commit is contained in:
Regalis
2015-11-08 22:20:29 +02:00
parent 5a21d64b3a
commit cd48d12be6
31 changed files with 551 additions and 313 deletions
+1
View File
@@ -95,6 +95,7 @@
<Compile Include="Source\Items\Components\Signal\SignalCheckComponent.cs" /> <Compile Include="Source\Items\Components\Signal\SignalCheckComponent.cs" />
<Compile Include="Source\Items\Components\ItemLabel.cs" /> <Compile Include="Source\Items\Components\ItemLabel.cs" />
<Compile Include="Source\Items\FixRequirement.cs" /> <Compile Include="Source\Items\FixRequirement.cs" />
<Compile Include="Source\Items\ItemSpawner.cs" />
<Compile Include="Source\Map\Levels\WrappingWall.cs" /> <Compile Include="Source\Map\Levels\WrappingWall.cs" />
<Compile Include="Source\Map\Lights\LightSource.cs" /> <Compile Include="Source\Map\Lights\LightSource.cs" />
<Compile Include="Source\Map\LocationType.cs" /> <Compile Include="Source\Map\LocationType.cs" />
@@ -48,6 +48,18 @@
<topwall sprite="Content/Map/testroom.png" sourcerect="144,464,496,32" depth ="0.06" castshadow="true" <topwall sprite="Content/Map/testroom.png" sourcerect="144,464,496,32" depth ="0.06" castshadow="true"
width = "64" height ="32" resizehorizontal="true" body="true" health="500"/> width = "64" height ="32" resizehorizontal="true" body="true" health="500"/>
<CornerUpperLeft sprite="Content/Map/testroom.png" sourcerect="192,512,224,160" depth ="0.03"
width = "224" height ="160"/>
<CornerUpperRight sprite="Content/Map/testroom.png" sourcerect="416,512,224,160" depth ="0.03"
width = "224" height ="160"/>
<CornerBottomLeft sprite="Content/Map/testroom.png" sourcerect="192,512,224,160" depth ="0.03"
width = "224" height ="160" flipvertical="true"/>
<CornerBottomRight sprite="Content/Map/testroom.png" sourcerect="416,512,224,160" depth ="0.03"
width = "224" height ="160" flipvertical="true"/>
<topwindow sprite="Content/Map/testroom.png" sourcerect="208,352,128,80" depth ="0.05" <topwindow sprite="Content/Map/testroom.png" sourcerect="208,352,128,80" depth ="0.05"
width = "128" height ="80" body="true" health="100"/> width = "128" height ="80" body="true" health="100"/>
@@ -78,6 +90,9 @@
<bgpanels sprite="Content/Map/testroom.png" sourcerect="768,320,224,224" depth = "1.0" <bgpanels sprite="Content/Map/testroom.png" sourcerect="768,320,224,224" depth = "1.0"
width="64" height="64" resizehorizontal="true" resizevertical="true"/> width="64" height="64" resizehorizontal="true" resizevertical="true"/>
<bgpanelswindow sprite="Content/Map/testroom.png" sourcerect="768,544,224,224" depth = "1.0"
width="64" height="64" resizehorizontal="true" resizevertical="true"/>
<stairsright sprite="Content/Map/testroom.png" sourcerect="0,704,256,320" <stairsright sprite="Content/Map/testroom.png" sourcerect="0,704,256,320"
width="256" height="320" depth = "0.1" stairdirection="Right"/> width="256" height="320" depth = "0.1" stairdirection="Right"/>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 716 KiB

After

Width:  |  Height:  |  Size: 957 KiB

+22 -21
View File
@@ -91,19 +91,19 @@ namespace Barotrauma
return true; return true;
case NetworkEventType.ImportantEntityUpdate: case NetworkEventType.ImportantEntityUpdate:
int i = 0; int i = 0;
foreach (Limb limb in AnimController.Limbs) //foreach (Limb limb in AnimController.Limbs)
{ //{
if (limb.ignoreCollisions) continue; //if (RefLimb.ignoreCollisions) continue;
if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(limb.body.Rotation); message.Write(AnimController.RefLimb.Rotation);
i++; // i++;
} //}
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
message.Write((byte)((health / maxHealth) * 255.0f)); message.Write((byte)((health / maxHealth) * 255.0f));
@@ -126,8 +126,9 @@ namespace Barotrauma
return true; return true;
} }
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{ {
data = null;
Enabled = true; Enabled = true;
switch (type) switch (type)
@@ -136,12 +137,12 @@ namespace Barotrauma
Kill(CauseOfDeath.Damage, true); Kill(CauseOfDeath.Damage, true);
return; return;
case NetworkEventType.ImportantEntityUpdate: case NetworkEventType.ImportantEntityUpdate:
foreach (Limb limb in AnimController.Limbs) //foreach (Limb limb in AnimController.Limbs)
{ //{
if (limb.ignoreCollisions) continue; // if (limb.ignoreCollisions) continue;
Vector2 limbPos = limb.SimPosition; Vector2 limbPos = AnimController.RefLimb.SimPosition;
float rotation = limb.Rotation; float rotation = AnimController.RefLimb.Rotation;
try try
{ {
@@ -155,14 +156,14 @@ namespace Barotrauma
return; return;
} }
if (limb.body != null) if (AnimController.RefLimb.body != null)
{ {
limb.body.TargetVelocity = limb.body.LinearVelocity; //AnimController.RefLimb.body.TargetVelocity = limb.body.LinearVelocity;
limb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0); AnimController.RefLimb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
limb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0); AnimController.RefLimb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
limb.body.TargetAngularVelocity = limb.body.AngularVelocity; //limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
} }
} //}
float newStunTimer = 0.0f, newHealth = 0.0f; float newStunTimer = 0.0f, newHealth = 0.0f;
+20 -4
View File
@@ -443,6 +443,12 @@ namespace Barotrauma
return keys[(int)inputType].Held; return keys[(int)inputType].Held;
} }
public void ClearInput(InputType inputType)
{
keys[(int)inputType].Hit = false;
keys[(int)inputType].Held = false;
}
public void ClearInputs() public void ClearInputs()
{ {
foreach (Key key in keys) foreach (Key key in keys)
@@ -577,10 +583,13 @@ namespace Barotrauma
public void CreateUpdateNetworkEvent(bool isClient) public void CreateUpdateNetworkEvent(bool isClient)
{ {
new NetworkEvent(importantUpdateTimer <= 0 ? NetworkEventType.ImportantEntityUpdate : NetworkEventType.EntityUpdate, ID, isClient); //new NetworkEvent(importantUpdateTimer <= 0 ? NetworkEventType.ImportantEntityUpdate : NetworkEventType.EntityUpdate, ID, isClient);
importantUpdateTimer -= 1; new NetworkEvent(NetworkEventType.EntityUpdate, ID, isClient);
if (importantUpdateTimer < 0) importantUpdateTimer = (this is AICharacter) ? 40 : 25;
//importantUpdateTimer -= 1;
//if (importantUpdateTimer < 0) importantUpdateTimer = (this is AICharacter) ? 30 : 10;
} }
@@ -1301,9 +1310,10 @@ namespace Barotrauma
} }
} }
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{ {
Enabled = true; Enabled = true;
data = null;
switch (type) switch (type)
{ {
@@ -1315,6 +1325,8 @@ namespace Barotrauma
bool pickHit = message.ReadBoolean(); bool pickHit = message.ReadBoolean();
bool actionHit = message.ReadBoolean(); bool actionHit = message.ReadBoolean();
data = new int[] { (int)itemId, pickHit ? 1 : 0, actionHit ? 1: 0 };
System.Diagnostics.Debug.WriteLine("item id: "+itemId); System.Diagnostics.Debug.WriteLine("item id: "+itemId);
Item item = FindEntityByID(itemId) as Item; Item item = FindEntityByID(itemId) as Item;
@@ -1323,6 +1335,8 @@ namespace Barotrauma
return; return;
case NetworkEventType.SelectCharacter: case NetworkEventType.SelectCharacter:
ushort characterId = message.ReadUInt16(); ushort characterId = message.ReadUInt16();
data = characterId;
if (characterId==0) if (characterId==0)
{ {
DeselectCharacter(false); DeselectCharacter(false);
@@ -1352,6 +1366,8 @@ namespace Barotrauma
causeOfDeath = CauseOfDeath.Damage; causeOfDeath = CauseOfDeath.Damage;
} }
data = causeOfDeath;
if (causeOfDeath==CauseOfDeath.Pressure) if (causeOfDeath==CauseOfDeath.Pressure)
{ {
Implode(true); Implode(true);
+71 -13
View File
@@ -649,9 +649,63 @@ namespace Barotrauma
} }
limb.Update(deltaTime); limb.Update(deltaTime);
}
}
public void SetPosition(Vector2 simPosition)
{
Vector2 moveAmount = simPosition - refLimb.SimPosition;
foreach (Limb limb in Limbs)
{
if (limb==refLimb)
{
limb.body.SetTransform(simPosition, limb.Rotation);
continue;
}
//check visibility from the new position of RefLimb to the new position of this limb
Vector2 movePos = limb.SimPosition + moveAmount;
TrySetLimbPosition(limb, simPosition, movePos);
}
}
private void TrySetLimbPosition(Limb limb, Vector2 original, Vector2 simPosition)
{
if (original == simPosition) return;
Body body = Submarine.CheckVisibility(original, simPosition);
Vector2 movePos = simPosition;
//if there's something in between the limbs
if (body != null)
{
//move the limb close to the position where the raycast hit something
movePos = original + ((simPosition - original) * Submarine.LastPickedFraction * 0.9f);
} }
limb.body.SetTransform(movePos, limb.Rotation);
}
public void SetRotation(float rotation)
{
float rotateAmount = rotation - refLimb.Rotation;
Matrix rotationMatrix = Matrix.CreateRotationZ(rotateAmount);
refLimb.body.SetTransform(refLimb.SimPosition, rotation);
foreach (Limb limb in Limbs)
{
if (limb == refLimb) continue;
Vector2 newPos = limb.SimPosition - refLimb.SimPosition;
newPos = Vector2.Transform(newPos, rotationMatrix);
TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos);
limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount);
}
} }
private void UpdateNetPlayerPosition() private void UpdateNetPlayerPosition()
@@ -708,22 +762,26 @@ namespace Barotrauma
if (resetAll) if (resetAll)
{ {
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions"); System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
foreach (Limb limb in Limbs) SetPosition(refLimb.body.TargetPosition);
{
//if (limb.body.TargetPosition == Vector2.Zero)
//{
limb.body.SetTransform(limb.body.SimPosition + diff, limb.body.Rotation);
//continue;
//}
//limb.body.LinearVelocity = limb.body.TargetVelocity; if (character is AICharacter) SetRotation(refLimb.body.TargetRotation);
//limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
//limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation); //foreach (Limb limb in Limbs)
limb.body.TargetPosition = Vector2.Zero; //{
} // if (limb.body.TargetPosition == Vector2.Zero)
// {
// limb.body.SetTransform(limb.body.SimPosition + diff, limb.body.Rotation);
// continue;
// }
// limb.body.LinearVelocity = limb.body.TargetVelocity;
// limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
// limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation);
// limb.body.TargetPosition = Vector2.Zero;
//}
} }
} }
+2 -2
View File
@@ -239,10 +239,10 @@ namespace Barotrauma
break; break;
case "generatelevel": case "generatelevel":
GameMain.Level = new Level("asdf", 50.0f, 500,500, 50); GameMain.Level = new Level("asdf", 50.0f, 500,500, 50);
GameMain.Level.Generate(100.0f); GameMain.Level.Generate();
break; break;
case "fixitems": case "fixitems":
foreach (Item it in Item.itemList) foreach (Item it in Item.ItemList)
{ {
it.Condition = 100.0f; it.Condition = 100.0f;
} }
+1 -1
View File
@@ -287,7 +287,7 @@ namespace Barotrauma
} }
else else
{ {
NetworkEvent.events.Clear(); NetworkEvent.Events.Clear();
} }
} }
@@ -102,7 +102,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("Open the door at your right side by highlighting the button next to it with your cursor and pressing E"); infoBox = CreateInfoFrame("Open the door at your right side by highlighting the button next to it with your cursor and pressing E");
Door tutorialDoor = Item.itemList.Find(i => i.HasTag("tutorialdoor")).GetComponent<Door>(); Door tutorialDoor = Item.ItemList.Find(i => i.HasTag("tutorialdoor")).GetComponent<Door>();
while (!tutorialDoor.IsOpen) while (!tutorialDoor.IsOpen)
{ {
@@ -124,7 +124,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("At the moment the submarine has no power, which means that crucial systems such as the oxygen generator or the engine aren't running. Let's fix this: go to the upper left corner of the submarine, where you'll find a nuclear reactor."); infoBox = CreateInfoFrame("At the moment the submarine has no power, which means that crucial systems such as the oxygen generator or the engine aren't running. Let's fix this: go to the upper left corner of the submarine, where you'll find a nuclear reactor.");
Reactor reactor = Item.itemList.Find(i => i.HasTag("tutorialreactor")).GetComponent<Reactor>(); Reactor reactor = Item.ItemList.Find(i => i.HasTag("tutorialreactor")).GetComponent<Reactor>();
reactor.MeltDownTemp = 20000.0f; reactor.MeltDownTemp = 20000.0f;
while (Vector2.Distance(Character.Controlled.Position, reactor.Item.Position)>200.0f) while (Vector2.Distance(Character.Controlled.Position, reactor.Item.Position)>200.0f)
@@ -183,7 +183,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("That's the basics of operating the reactor! Now that there's power available for the engines, it's time to get the submarine moving. " infoBox = CreateInfoFrame("That's the basics of operating the reactor! Now that there's power available for the engines, it's time to get the submarine moving. "
+"Deselect the reactor by pressing E and head to the command room at the right edge of the vessel."); +"Deselect the reactor by pressing E and head to the command room at the right edge of the vessel.");
Steering steering = Item.itemList.Find(i => i.HasTag("tutorialsteering")).GetComponent<Steering>(); Steering steering = Item.ItemList.Find(i => i.HasTag("tutorialsteering")).GetComponent<Steering>();
Radar radar = steering.Item.GetComponent<Radar>(); Radar radar = steering.Item.GetComponent<Radar>();
while (Vector2.Distance(Character.Controlled.Position, steering.Item.Position) > 150.0f) while (Vector2.Distance(Character.Controlled.Position, steering.Item.Position) > 150.0f)
@@ -233,7 +233,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("Head back to the navigation terminal to fix the wiring."); infoBox = CreateInfoFrame("Head back to the navigation terminal to fix the wiring.");
PowerTransfer junctionBox = Item.itemList.Find(i => i!=null && i.HasTag("tutorialjunctionbox")).GetComponent<PowerTransfer>(); PowerTransfer junctionBox = Item.ItemList.Find(i => i!=null && i.HasTag("tutorialjunctionbox")).GetComponent<PowerTransfer>();
while ((Character.Controlled.SelectedConstruction != junctionBox.Item && while ((Character.Controlled.SelectedConstruction != junctionBox.Item &&
Character.Controlled.SelectedConstruction != steering.Item) || Character.Controlled.SelectedConstruction != steering.Item) ||
@@ -380,15 +380,15 @@ namespace Barotrauma
Submarine.Loaded.GodMode = true; Submarine.Loaded.GodMode = true;
var capacitor1 = Item.itemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>(); var capacitor1 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>();
var capacitor2 = Item.itemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>(); var capacitor2 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>();
CoroutineManager.StartCoroutine(KeepEnemyAway(moloch, new PowerContainer[] { capacitor1, capacitor2 })); CoroutineManager.StartCoroutine(KeepEnemyAway(moloch, new PowerContainer[] { capacitor1, capacitor2 }));
infoBox = CreateInfoFrame("The hull has been breached! Close all the doors to the command room to stop the water from flooding the entire sub!"); infoBox = CreateInfoFrame("The hull has been breached! Close all the doors to the command room to stop the water from flooding the entire sub!");
Door commandDoor1 = Item.itemList.Find(i => i.HasTag("commanddoor1")).GetComponent<Door>(); Door commandDoor1 = Item.ItemList.Find(i => i.HasTag("commanddoor1")).GetComponent<Door>();
Door commandDoor2 = Item.itemList.Find(i => i.HasTag("commanddoor2")).GetComponent<Door>(); Door commandDoor2 = Item.ItemList.Find(i => i.HasTag("commanddoor2")).GetComponent<Door>();
Door commandDoor3 = Item.itemList.Find(i => i.HasTag("commanddoor3")).GetComponent<Door>(); Door commandDoor3 = Item.ItemList.Find(i => i.HasTag("commanddoor3")).GetComponent<Door>();
while (commandDoor1.IsOpen || (commandDoor2.IsOpen || commandDoor3.IsOpen)) while (commandDoor1.IsOpen || (commandDoor2.IsOpen || commandDoor3.IsOpen))
{ {
@@ -425,7 +425,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("Now you should stop the creature attacking the submarine before it does any more damage. Head to the railgun room at the upper right corner of the sub."); infoBox = CreateInfoFrame("Now you should stop the creature attacking the submarine before it does any more damage. Head to the railgun room at the upper right corner of the sub.");
var railGun = Item.itemList.Find(i => i.GetComponent<Turret>()!=null); var railGun = Item.ItemList.Find(i => i.GetComponent<Turret>()!=null);
while (Vector2.Distance(Character.Controlled.Position, railGun.Position)>500) while (Vector2.Distance(Character.Controlled.Position, railGun.Position)>500)
{ {
@@ -445,7 +445,7 @@ namespace Barotrauma
"time to head to the room below and load some shells for the railgun."); "time to head to the room below and load some shells for the railgun.");
var loader = Item.itemList.Find(i => i.Name == "Railgun Loader").GetComponent<ItemContainer>(); var loader = Item.ItemList.Find(i => i.Name == "Railgun Loader").GetComponent<ItemContainer>();
while (Math.Abs(Character.Controlled.Position.Y - loader.Item.Position.Y)>80) while (Math.Abs(Character.Controlled.Position.Y - loader.Item.Position.Y)>80)
{ {
@@ -525,7 +525,7 @@ namespace Barotrauma
infoBox = CreateInfoFrame("Great! However, there's still quite a bit of water inside the sub. It should be pumped out " infoBox = CreateInfoFrame("Great! However, there's still quite a bit of water inside the sub. It should be pumped out "
+"using the pump in the room at the bottom of the submarine."); +"using the pump in the room at the bottom of the submarine.");
Pump pump = Item.itemList.Find(i => i.HasTag("tutorialpump")).GetComponent<Pump>(); Pump pump = Item.ItemList.Find(i => i.HasTag("tutorialpump")).GetComponent<Pump>();
while (Vector2.Distance(Character.Controlled.Position, pump.Item.Position) > 100.0f) while (Vector2.Distance(Character.Controlled.Position, pump.Item.Position) > 100.0f)
{ {
@@ -640,7 +640,7 @@ namespace Barotrauma
reactor.ShutDownTemp = 5000.0f; reactor.ShutDownTemp = 5000.0f;
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
} while (Item.itemList.Contains(reactor.Item)); } while (Item.ItemList.Contains(reactor.Item));
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
+1 -1
View File
@@ -121,7 +121,7 @@ namespace Barotrauma
if (level != null) if (level != null)
{ {
level.Generate(submarine == null ? 100.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height)); level.Generate();
submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f)); submarine.SetPosition(level.StartPosition - new Vector2(0.0f, 2000.0f));
GameMain.GameScreen.BackgroundSpriteManager.SpawnSprites(80); GameMain.GameScreen.BackgroundSpriteManager.SpawnSprites(80);
@@ -373,6 +373,8 @@ namespace Barotrauma
public override void ReadNetworkData(NetworkEventType type, NetBuffer message) public override void ReadNetworkData(NetworkEventType type, NetBuffer message)
{ {
character.ClearInput(InputType.Use);
for (int i = 0; i<5; i++) for (int i = 0; i<5; i++)
{ {
ushort itemId = message.ReadUInt16(); ushort itemId = message.ReadUInt16();
@@ -391,18 +393,12 @@ namespace Barotrauma
List<ushort> newItemIDs = new List<ushort>(); List<ushort> newItemIDs = new List<ushort>();
try for (int i = 5; i < capacity; i++)
{ {
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8)) newItemIDs.Add(message.ReadUInt16());
{
newItemIDs.Add(message.ReadUInt16());
}
}
catch
{
return;
} }
for (int i = 5; i < capacity; i++) for (int i = 5; i < capacity; i++)
{ {
if (items[i] == null) continue; if (items[i] == null) continue;
@@ -73,34 +73,23 @@ namespace Barotrauma.Items.Components
} }
int width = 400, height = 300; int width = 500, height = 300;
itemList = new GUIListBox(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), Color.White * 0.7f); itemList = new GUIListBox(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
itemList.OnSelected = SelectItem; itemList.OnSelected = SelectItem;
//structureList.CheckSelected = MapEntityPrefab.GetSelected; //structureList.CheckSelected = MapEntityPrefab.GetSelected;
foreach (FabricableItem fi in fabricableItems) foreach (FabricableItem fi in fabricableItems)
{ {
Color color = ((itemList.CountChildren % 2) == 0) ? Color.White : Color.LightGray; Color color = ((itemList.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.3f;
//GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, itemList);
//frame.UserData = fi;
//frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
//frame.Color = color;
//frame.HoverColor = Color.Gold * 0.2f;
//frame.SelectedColor = Color.Gold * 0.5f;
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), fi.TargetItem.Name, new Rectangle(0, 0, 0, 25), fi.TargetItem.Name,
color, Color.Black, color, Color.White,
Alignment.Left, Alignment.Left, null, itemList); Alignment.Left, Alignment.Left, null, itemList);
textBlock.UserData = fi; textBlock.UserData = fi;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
textBlock.HoverColor = Color.Gold * 0.2f;
//if (fi.TargetItem.sprite != null) textBlock.SelectedColor = Color.Gold * 0.5f;
//{
// GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), fi.TargetItem.sprite, Alignment.Left, frame);
// img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
//}
} }
} }
@@ -110,7 +99,7 @@ namespace Barotrauma.Items.Components
if (targetItem == null) return false; if (targetItem == null) return false;
int width = 200, height = 150; int width = 200, height = 150;
selectedItemFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, itemList.Rect.Bottom+20, width, height), Color.Black*0.8f); selectedItemFrame = new GUIFrame(new Rectangle(itemList.Rect.Right - width - 20, GameMain.GraphicsHeight/2-height/2, width, height), Color.Black*0.8f);
//selectedItemFrame.Padding = GUI.style.smallPadding; //selectedItemFrame.Padding = GUI.style.smallPadding;
if (targetItem.TargetItem.sprite != null) if (targetItem.TargetItem.sprite != null)
@@ -177,7 +166,7 @@ namespace Barotrauma.Items.Components
container.inventory.RemoveItem(requiredItem); container.inventory.RemoveItem(requiredItem);
} }
new Item(fabricatedItem.TargetItem, item.Position); Item.Spawner.QueueItem(fabricatedItem.TargetItem, item.Position);
IsActive = false; IsActive = false;
fabricatedItem = null; fabricatedItem = null;
@@ -199,7 +188,6 @@ namespace Barotrauma.Items.Components
} }
} }
itemList.Update(0.016f); itemList.Update(0.016f);
itemList.Draw(spriteBatch); itemList.Draw(spriteBatch);
@@ -131,10 +131,14 @@ namespace Barotrauma.Items.Components
float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center); float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center);
if (cellDot > 0) continue; if (cellDot > 0) continue;
float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center + Level.Loaded.Position));
facingDot = MathHelper.Clamp(facingDot, -1.0f, 1.0f);
Vector2 point1 = (edge.point1 + Level.Loaded.Position); Vector2 point1 = (edge.point1 + Level.Loaded.Position);
Vector2 point2 = (edge.point2 + Level.Loaded.Position); Vector2 point2 = (edge.point2 + Level.Loaded.Position);
for (float x=0; x<(point1-point2).Length(); x+=Rand.Range(600.0f, 800.0f)) float length = (point1 - point2).Length();
for (float x=0; x<length; x+=Rand.Range(600.0f, 800.0f))
{ {
Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x; Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x;
@@ -144,15 +148,18 @@ namespace Barotrauma.Items.Components
if (pointDist < prevPingRadius || pointDist > pingRadius) continue; if (pointDist < prevPingRadius || pointDist > pingRadius) continue;
float step = 4.0f; float step = 5.0f * (Math.Abs(facingDot)+1.0f);
float alpha = Rand.Range(1.5f, 2.0f);
for (float z = 0; z<radius-pointDist;z+=step) for (float z = 0; z<radius-pointDist;z+=step)
{ {
var blip = new RadarBlip( var blip = new RadarBlip(
point + Rand.Vector(150.0f) - Level.Loaded.Position + Vector2.Normalize(point) * z / displayScale, point + Rand.Vector(150.0f) - Level.Loaded.Position + Vector2.Normalize(point) * z / displayScale,
Rand.Range(0.8f, 1.0f) / (step-4.0f)); alpha);
radarBlips.Add(blip); radarBlips.Add(blip);
step += 0.5f; step += 0.5f;
alpha -= (z == 0) ? 0.5f : 0.1f;
} }
} }
@@ -199,7 +206,7 @@ namespace Barotrauma.Items.Components
foreach (RadarBlip radarBlip in radarBlips) foreach (RadarBlip radarBlip in radarBlips)
{ {
DrawBlip(spriteBatch, center, radarBlip.Position, Color.Green * radarBlip.FadeTimer); DrawBlip(spriteBatch,radarBlip, center, Color.Green * radarBlip.FadeTimer, radius);
} }
prevPingRadius = pingRadius; prevPingRadius = pingRadius;
@@ -262,17 +269,18 @@ namespace Barotrauma.Items.Components
voltage = 0.0f; voltage = 0.0f;
} }
private void DrawBlip(SpriteBatch spriteBatch, Vector2 center, Vector2 pos, Color color) private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)
{ {
pos = (pos + Level.Loaded.Position) * displayScale; Vector2 pos = (blip.Position + Level.Loaded.Position) * displayScale;
pos.Y = -pos.Y; pos.Y = -pos.Y;
//spriteBatch.Draw(radarBlipSprite, center+pos, if (pos.Length() > radius)
// new Rectangle((int)(radarBlip.SpriteIndex % 4 * 32), (int)(Math.Floor(radarBlip.SpriteIndex / 4.0f) * 32), 32, 32), {
// Color.White * radarBlip.FadeTimer, 0.0f, new Vector2(16.0f, 16.0f), 0.5f, SpriteEffects.None, 0.0f); blip.FadeTimer = 0.0f;
return;
}
pos.X = MathUtils.Round(pos.X, 4); pos.X = MathUtils.Round(pos.X, 4);
pos.Y = MathUtils.Round(pos.Y, 2); pos.Y = MathUtils.Round(pos.Y, 2);
GUI.DrawRectangle(spriteBatch, center + pos, new Vector2(4, 2), color, true); GUI.DrawRectangle(spriteBatch, center + pos, new Vector2(4, 2), color, true);
+7 -13
View File
@@ -297,10 +297,11 @@ namespace Barotrauma
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data) public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
{ {
for (int i = 0; i<capacity; i++) var foundItems = Array.FindAll(items, i => i != null);
message.Write((byte)foundItems.Count());
foreach (Item item in foundItems)
{ {
if (items[i] == null) continue; message.Write((ushort)item.ID);
message.Write((ushort)items[i].ID);
} }
return true; return true;
@@ -310,17 +311,10 @@ namespace Barotrauma
{ {
List<ushort> newItemIDs = new List<ushort>(); List<ushort> newItemIDs = new List<ushort>();
try byte count = message.ReadByte();
for (int i = 0; i<count; i++)
{ {
newItemIDs.Add(message.ReadUInt16());
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8))
{
newItemIDs.Add(message.ReadUInt16());
}
}
catch
{
return;
} }
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
+19 -8
View File
@@ -23,9 +23,11 @@ namespace Barotrauma
class Item : MapEntity, IDamageable, IPropertyObject class Item : MapEntity, IDamageable, IPropertyObject
{ {
public static List<Item> itemList = new List<Item>(); public static List<Item> ItemList = new List<Item>();
protected ItemPrefab prefab; protected ItemPrefab prefab;
public static ItemSpawner Spawner = new ItemSpawner();
private List<string> tags; private List<string> tags;
public Hull CurrentHull; public Hull CurrentHull;
@@ -308,7 +310,7 @@ namespace Barotrauma
} }
InsertToList(); InsertToList();
itemList.Add(this); ItemList.Add(this);
} }
public T GetComponent<T>() public T GetComponent<T>()
@@ -359,7 +361,7 @@ namespace Barotrauma
{ {
base.Move(amount); base.Move(amount);
if (itemList != null && body != null) if (ItemList != null && body != null)
{ {
amount = ConvertUnits.ToSimUnits(amount); amount = ConvertUnits.ToSimUnits(amount);
//Vector2 pos = new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f); //Vector2 pos = new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f);
@@ -387,7 +389,7 @@ namespace Barotrauma
/// </summary> /// </summary>
public static void UpdateHulls() public static void UpdateHulls()
{ {
foreach (Item item in itemList) item.FindHull(); foreach (Item item in ItemList) item.FindHull();
} }
public virtual Hull FindHull() public virtual Hull FindHull()
@@ -812,7 +814,7 @@ namespace Barotrauma
Vector2 displayPos = ConvertUnits.ToDisplayUnits(position); Vector2 displayPos = ConvertUnits.ToDisplayUnits(position);
Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition); Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition);
foreach (Item item in itemList) foreach (Item item in ItemList)
{ {
if (ignoredItems!=null && ignoredItems.Contains(item)) continue; if (ignoredItems!=null && ignoredItems.Contains(item)) continue;
//if (hull != item.CurrentHull && (hull==null || (item.Rect.Height<hull.Rect.Height && item.rect.Width < hull.Rect.Width))) continue; //if (hull != item.CurrentHull && (hull==null || (item.Rect.Height<hull.Rect.Height && item.rect.Width < hull.Rect.Width))) continue;
@@ -1295,8 +1297,10 @@ namespace Barotrauma
return true; return true;
} }
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{ {
data = null;
Condition = (float)message.ReadByte()/2.55f; Condition = (float)message.ReadByte()/2.55f;
switch (type) switch (type)
@@ -1310,11 +1314,14 @@ namespace Barotrauma
case NetworkEventType.ItemFixed: case NetworkEventType.ItemFixed:
byte requirementIndex = message.ReadByte(); byte requirementIndex = message.ReadByte();
data = requirementIndex;
if (requirementIndex>=FixRequirements.Count) return; if (requirementIndex>=FixRequirements.Count) return;
FixRequirements[requirementIndex].Fixed = true; FixRequirements[requirementIndex].Fixed = true;
break; break;
case NetworkEventType.InventoryUpdate: case NetworkEventType.InventoryUpdate:
var itemContainer = GetComponent<ItemContainer>(); var itemContainer = GetComponent<ItemContainer>();
if (itemContainer == null || itemContainer.inventory == null) return; if (itemContainer == null || itemContainer.inventory == null) return;
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message); itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
@@ -1322,6 +1329,9 @@ namespace Barotrauma
case NetworkEventType.ComponentUpdate: case NetworkEventType.ComponentUpdate:
case NetworkEventType.ImportantComponentUpdate: case NetworkEventType.ImportantComponentUpdate:
int componentIndex = message.ReadByte(); int componentIndex = message.ReadByte();
data = componentIndex;
if (componentIndex < 0 || componentIndex > components.Count - 1) return; if (componentIndex < 0 || componentIndex > components.Count - 1) return;
components[componentIndex].ReadNetworkData(type, message); components[componentIndex].ReadNetworkData(type, message);
break; break;
@@ -1331,6 +1341,7 @@ namespace Barotrauma
try try
{ {
propertyName = message.ReadString(); propertyName = message.ReadString();
data = propertyName;
} }
catch catch
{ {
@@ -1380,9 +1391,9 @@ namespace Barotrauma
{ {
ic.Remove(); ic.Remove();
} }
itemList.Remove(this); ItemList.Remove(this);
foreach (Item it in itemList) foreach (Item it in ItemList)
{ {
if (it.linkedTo.Contains(this)) if (it.linkedTo.Contains(this))
{ {
+1 -1
View File
@@ -111,7 +111,7 @@ namespace Barotrauma
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
{ {
new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this); new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this);
placePosition = Vector2.Zero;
//selected = null; //selected = null;
return; return;
} }
+37
View File
@@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
class ItemSpawner
{
private Queue<Pair<ItemPrefab, Vector2>> spawnQueue;
public ItemSpawner()
{
spawnQueue = new Queue<Pair<ItemPrefab, Vector2>>();
}
public void QueueItem(ItemPrefab itemPrefab, Vector2 position)
{
var itemInfo = new Pair<ItemPrefab, Vector2>();
itemInfo.First = itemPrefab;
itemInfo.Second = position;
spawnQueue.Enqueue(itemInfo);
}
public void Update()
{
while (spawnQueue.Count>0)
{
var itemInfo = spawnQueue.Dequeue();
new Item(itemInfo.First, itemInfo.Second);
}
}
}
}
+4 -1
View File
@@ -69,7 +69,10 @@ namespace Barotrauma
{ {
return false; return false;
} }
public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) { } public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{
data = null;
}
/// <summary> /// <summary>
/// Find an entity based on the ID /// Find an entity based on the ID
+3 -1
View File
@@ -479,8 +479,10 @@ namespace Barotrauma
return true; return true;
} }
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, out object data)
{ {
data = null;
float newVolume = this.volume; float newVolume = this.volume;
try try
+5 -3
View File
@@ -145,7 +145,7 @@ namespace Barotrauma
return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 40000, 2000); return new Level(seed, Rand.Range(30.0f,80.0f,false), 100000, 40000, 2000);
} }
public void Generate(float minWidth, bool mirror=false) public void Generate(bool mirror=false)
{ {
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
@@ -230,6 +230,8 @@ namespace Barotrauma
Debug.WriteLine("find cells: " + sw2.ElapsedMilliseconds + " ms"); Debug.WriteLine("find cells: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart(); sw2.Restart();
float minWidth = Submarine.Loaded == null ? 3000.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
//generate a path from the left edge of the map to right edge //generate a path from the left edge of the map to right edge
Rectangle pathBorders = new Rectangle( Rectangle pathBorders = new Rectangle(
borders.X + (int)minWidth * 2, borders.Y + (int)minWidth * 2, borders.X + (int)minWidth * 2, borders.Y + (int)minWidth * 2,
@@ -775,7 +777,7 @@ namespace Barotrauma
} }
} }
foreach (Item item in Item.itemList) foreach (Item item in Item.ItemList)
{ {
if (item.body==null || item.CurrentHull != null) continue; if (item.body==null || item.CurrentHull != null) continue;
item.body.LinearVelocity += simVelocity; item.body.LinearVelocity += simVelocity;
@@ -815,7 +817,7 @@ namespace Barotrauma
} }
} }
foreach (Item item in Item.itemList) foreach (Item item in Item.ItemList)
{ {
if (item.body == null || item.CurrentHull != null) continue; if (item.body == null || item.CurrentHull != null) continue;
item.body.LinearVelocity -= prevVelocity; item.body.LinearVelocity -= prevVelocity;
+3 -27
View File
@@ -199,7 +199,7 @@ namespace Barotrauma
/// </summary> /// </summary>
public static void UpdateAll(Camera cam, float deltaTime) public static void UpdateAll(Camera cam, float deltaTime)
{ {
foreach (Item item in Item.itemList) foreach (Item item in Item.ItemList)
{ {
item.Updated = false; item.Updated = false;
} }
@@ -214,36 +214,12 @@ namespace Barotrauma
gap.Update(cam, deltaTime); gap.Update(cam, deltaTime);
} }
foreach (Item item in Item.itemList) foreach (Item item in Item.ItemList)
{ {
item.Update(cam, deltaTime); item.Update(cam, deltaTime);
} }
//Stopwatch sw = new Stopwatch(); Item.Spawner.Update();
//for (int i = 0; i < mapEntityList.Count; i++)
//{
// sw.Restart();
// mapEntityList[i].Update(cam, deltaTime);
// sw.Stop();
// if (timeElapsed.ContainsKey(mapEntityList[i].Name))
// {
// float asd = 0.0f;
// timeElapsed.TryGetValue(mapEntityList[i].Name, out asd);
// asd += sw.ElapsedTicks;
// timeElapsed.Remove(mapEntityList[i].Name);
// timeElapsed.Add(mapEntityList[i].Name, asd);
// }
// else
// {
// timeElapsed.Add(mapEntityList[i].Name, sw.ElapsedTicks);
// }
//}
} }
public virtual void Update(Camera cam, float deltaTime) { } public virtual void Update(Camera cam, float deltaTime) { }
+19 -4
View File
@@ -449,6 +449,8 @@ namespace Barotrauma
if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return; if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return;
if (!prefab.HasBody) return; if (!prefab.HasBody) return;
if (!MathUtils.IsValid(damage)) return;
if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage)>5.0f) if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage)>5.0f)
{ {
new NetworkEvent(NetworkEventType.WallDamage, ID, false); new NetworkEvent(NetworkEventType.WallDamage, ID, false);
@@ -640,9 +642,16 @@ namespace Barotrauma
{ {
message.Write((float)NetTime.Now); message.Write((float)NetTime.Now);
for (int i = 0; i < sections.Length; i++) var updateSections = Array.FindAll(sections, s => s != null && Math.Abs(s.damage - s.lastSentDamage)/Health > 0.01f);
if (updateSections.Length == 0) return false;
Debug.Assert(updateSections.Length<255);
message.Write((byte)updateSections.Length);
for (int i = 0; i < updateSections.Length; i++)
{ {
if (Math.Abs(sections[i].damage - sections[i].lastSentDamage) < 0.1f) continue;
message.Write((byte)i); message.Write((byte)i);
message.WriteRangedSingle(sections[i].damage / Health, 0.0f, 1.0f, 8); message.WriteRangedSingle(sections[i].damage / Health, 0.0f, 1.0f, 8);
@@ -652,16 +661,22 @@ namespace Barotrauma
return true; return true;
} }
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{ {
data = null;
float updateTime = message.ReadFloat(); float updateTime = message.ReadFloat();
if (updateTime < lastUpdate) return; if (updateTime < lastUpdate) return;
while (message.Position <= message.LengthBits-8) int sectionCount = message.ReadByte();
for (int i = 0; i<sectionCount; i++)
{ {
byte sectionIndex = message.ReadByte(); byte sectionIndex = message.ReadByte();
float damage = message.ReadRangedSingle(0.0f, 1.0f, 8) * Health; float damage = message.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
if (sectionIndex < 0 || sectionIndex >= sections.Length) continue;
SetDamage(sectionIndex, damage); SetDamage(sectionIndex, damage);
} }
} }
+6 -5
View File
@@ -254,8 +254,6 @@ namespace Barotrauma
public static Body PickBody(Vector2 rayStart, Vector2 rayEnd, List<Body> ignoredBodies = null, Category? collisionCategory = null) public static Body PickBody(Vector2 rayStart, Vector2 rayEnd, List<Body> ignoredBodies = null, Category? collisionCategory = null)
{ {
float closestFraction = 1.0f; float closestFraction = 1.0f;
Body closestBody = null; Body closestBody = null;
GameMain.World.RayCast((fixture, point, normal, fraction) => GameMain.World.RayCast((fixture, point, normal, fraction) =>
@@ -302,7 +300,8 @@ namespace Barotrauma
GameMain.World.RayCast((fixture, point, normal, fraction) => GameMain.World.RayCast((fixture, point, normal, fraction) =>
{ {
if (fixture == null || fixture.CollisionCategories != Physics.CollisionWall) return -1; if (fixture == null ||
(fixture.CollisionCategories != Physics.CollisionWall && fixture.CollisionCategories != Physics.CollisionLevel)) return -1;
Structure structure = fixture.Body.UserData as Structure; Structure structure = fixture.Body.UserData as Structure;
if (structure != null) if (structure != null)
@@ -397,8 +396,10 @@ namespace Barotrauma
return true; return true;
} }
public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message) public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message, out object data)
{ {
data = null;
float sendingTime; float sendingTime;
Vector2 newTargetPosition, newSpeed; Vector2 newTargetPosition, newSpeed;
try try
@@ -630,7 +631,7 @@ namespace Barotrauma
MapEntity.MapLoaded(); MapEntity.MapLoaded();
foreach (Item item in Item.itemList) foreach (Item item in Item.ItemList)
{ {
foreach (ItemComponent ic in item.components) foreach (ItemComponent ic in item.components)
{ {
+17 -7
View File
@@ -23,10 +23,10 @@ namespace Barotrauma
public WaterRenderer(GraphicsDevice graphicsDevice) public WaterRenderer(GraphicsDevice graphicsDevice)
{ {
#if WINDOWS #if WINDOWS
byte[] bytecode = File.ReadAllBytes("Content/watershader.mgfx"); byte[] bytecode = File.ReadAllBytes("Content/watershader.mgfx");
#endif #endif
#if LINUX #if LINUX
byte[] bytecode = File.ReadAllBytes("Content/effects_linux.mgfx"); byte[] bytecode = File.ReadAllBytes("Content/watershader_opengl.mgfx");
#endif #endif
waterEffect = new Effect(graphicsDevice, bytecode); waterEffect = new Effect(graphicsDevice, bytecode);
@@ -34,9 +34,14 @@ namespace Barotrauma
waterTexture = TextureLoader.FromFile("Content/waterbump.png"); waterTexture = TextureLoader.FromFile("Content/waterbump.png");
waterEffect.Parameters["xWaveWidth"].SetValue(0.05f); waterEffect.Parameters["xWaveWidth"].SetValue(0.05f);
waterEffect.Parameters["xWaveHeight"].SetValue(0.05f); waterEffect.Parameters["xWaveHeight"].SetValue(0.05f);
#if WINDOWS
waterEffect.Parameters["xTexture"].SetValue(waterTexture);
#endif
#if LINUX
waterEffect.Parameters["xWaterBumpMap"].SetValue(waterTexture);
#endif
if (basicEffect == null)
if (basicEffect==null)
{ {
basicEffect = new BasicEffect(GameMain.CurrGraphicsDevice); basicEffect = new BasicEffect(GameMain.CurrGraphicsDevice);
basicEffect.VertexColorEnabled = false; basicEffect.VertexColorEnabled = false;
@@ -45,12 +50,11 @@ namespace Barotrauma
} }
} }
public void RenderBack (SpriteBatch spriteBatch, RenderTarget2D texture, float blurAmount = 0.0f) public void RenderBack(SpriteBatch spriteBatch, RenderTarget2D texture, float blurAmount = 0.0f)
{ {
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap);
waterEffect.CurrentTechnique = waterEffect.Techniques["WaterShader"]; waterEffect.CurrentTechnique = waterEffect.Techniques["WaterShader"];
waterEffect.Parameters["xTexture"].SetValue(texture);
waterEffect.Parameters["xWavePos"].SetValue(wavePos); waterEffect.Parameters["xWavePos"].SetValue(wavePos);
waterEffect.Parameters["xBlurDistance"].SetValue(blurAmount); waterEffect.Parameters["xBlurDistance"].SetValue(blurAmount);
waterEffect.CurrentTechnique.Passes[0].Apply(); waterEffect.CurrentTechnique.Passes[0].Apply();
@@ -58,7 +62,13 @@ namespace Barotrauma
wavePos.X += 0.0001f; wavePos.X += 0.0001f;
wavePos.Y += 0.0001f; wavePos.Y += 0.0001f;
spriteBatch.Draw(waterTexture, new Rectangle(0,0,GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); #if WINDOWS
waterEffect.Parameters["xTexture"].SetValue(texture);
spriteBatch.Draw(waterTexture, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
#elif LINUX
spriteBatch.Draw(texture, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
#endif
spriteBatch.End(); spriteBatch.End();
} }
+38 -49
View File
@@ -75,6 +75,7 @@ namespace Barotrauma.Networking
// Create new client, with previously created configs // Create new client, with previously created configs
client = new NetClient(config); client = new NetClient(config);
netPeer = client;
reliableChannel = new ReliableChannel(client); reliableChannel = new ReliableChannel(client);
NetOutgoingMessage outmsg = client.CreateMessage(); NetOutgoingMessage outmsg = client.CreateMessage();
@@ -359,32 +360,45 @@ namespace Barotrauma.Networking
} }
} }
foreach (NetworkEvent networkEvent in NetworkEvent.events) var message = ComposeNetworkEventMessage(true);
if (message != null)
{ {
if (networkEvent.IsImportant) ReliableMessage reliableMessage = reliableChannel.CreateMessage();
{ message.Position = 0;
ReliableMessage reliableMessage = reliableChannel.CreateMessage(); reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
reliableMessage.InnerMessage.Write((byte)PacketTypes.NetworkEvent);
if (networkEvent.FillData(reliableMessage.InnerMessage)) reliableChannel.SendMessage(reliableMessage, client.ServerConnection);
{
reliableChannel.SendMessage(reliableMessage, client.ServerConnection);
}
}
else
{
NetOutgoingMessage message = client.CreateMessage();
message.Write((byte)PacketTypes.NetworkEvent);
if (networkEvent.FillData(message))
{
client.SendMessage(message, NetDeliveryMethod.Unreliable);
}
}
} }
NetworkEvent.events.Clear(); message = ComposeNetworkEventMessage(false);
if (message != null) client.SendMessage(message, NetDeliveryMethod.Unreliable);
//foreach (NetworkEvent networkEvent in NetworkEvent.Events)
//{
// if (networkEvent.IsImportant)
// {
// ReliableMessage reliableMessage = reliableChannel.CreateMessage();
// reliableMessage.InnerMessage.Write((byte)PacketTypes.NetworkEvent);
// if (networkEvent.FillData(reliableMessage.InnerMessage))
// {
// reliableChannel.SendMessage(reliableMessage, client.ServerConnection);
// }
// }
// else
// {
// NetOutgoingMessage message = client.CreateMessage();
// message.Write((byte)PacketTypes.NetworkEvent);
// if (networkEvent.FillData(message))
// {
// client.SendMessage(message, NetDeliveryMethod.Unreliable);
// }
// }
//}
NetworkEvent.Events.Clear();
// Update current time // Update current time
updateTimer = DateTime.Now + updateInterval; updateTimer = DateTime.Now + updateInterval;
@@ -475,32 +489,7 @@ namespace Barotrauma.Networking
//read the data from the message and update client state accordingly //read the data from the message and update client state accordingly
if (!gameStarted) break; if (!gameStarted) break;
byte msgCount = inc.ReadByte(); NetworkEvent.ReadMessage(inc);
long currPos = inc.PositionInBytes;
System.Diagnostics.Debug.WriteLine("msgcount: " + msgCount + " startpos: " + inc.PositionInBytes);
for (int i = 0; i < msgCount; i++ )
{
byte msgLength = inc.ReadByte();
System.Diagnostics.Debug.WriteLine("msglength: "+msgLength);
try
{
NetworkEvent.ReadData(inc);
}
catch
{
int afghj = 1;
}
//+1 because msgLength is one additional byte
currPos += msgLength+1;
inc.Position = currPos*8;
System.Diagnostics.Debug.WriteLine("currpos: " + currPos);
}
break; break;
case (byte)PacketTypes.UpdateNetLobby: case (byte)PacketTypes.UpdateNetLobby:
@@ -800,7 +789,7 @@ namespace Barotrauma.Networking
case 2: case 2:
msg.Write((byte)PacketTypes.NetworkEvent); msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)NetworkEventType.ComponentUpdate); msg.Write((byte)NetworkEventType.ComponentUpdate);
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID); msg.Write((int)Item.ItemList[Rand.Int(Item.ItemList.Count)].ID);
msg.Write(Rand.Int(8)); msg.Write(Rand.Int(8));
break; break;
case 3: case 3:
+107 -69
View File
@@ -74,6 +74,7 @@ namespace Barotrauma.Networking
try try
{ {
server = new NetServer(config); server = new NetServer(config);
netPeer = server;
server.Start(); server.Start();
} }
catch (Exception e) catch (Exception e)
@@ -282,7 +283,7 @@ namespace Barotrauma.Networking
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
if (c as AICharacter == null) continue; if (c as AICharacter == null || c.IsDead) continue;
if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue;
@@ -312,6 +313,13 @@ namespace Barotrauma.Networking
{ {
if (gameStarted) new NetworkEvent(Submarine.Loaded.ID, false); if (gameStarted) new NetworkEvent(Submarine.Loaded.ID, false);
foreach (Character c in Character.CharacterList)
{
if (c as AICharacter != null || c.IsDead) continue;
new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false);
}
sparseUpdateTimer = DateTime.Now + sparseUpdateInterval; sparseUpdateTimer = DateTime.Now + sparseUpdateInterval;
} }
@@ -433,34 +441,34 @@ namespace Barotrauma.Networking
{ {
case (byte)PacketTypes.NetworkEvent: case (byte)PacketTypes.NetworkEvent:
if (!gameStarted) break; if (!gameStarted) break;
if (!NetworkEvent.ReadData(inc)) break; NetworkEvent.ReadMessage(inc, true);
List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame); //List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
if (recipients.Count == 0) break; //if (recipients.Count == 0) break;
if (isReliable) //if (isReliable)
{ //{
Debug.WriteLine("receiver reliable networkevent"); // Debug.WriteLine("receiver reliable networkevent");
foreach (Client c in recipients) // foreach (Client c in recipients)
{ // {
var reliableMessage = c.ReliableChannel.CreateMessage(); // var reliableMessage = c.ReliableChannel.CreateMessage();
inc.Position = 8+16; // inc.Position = 8+16;
byte[] messageBytes = inc.ReadBytes(inc.LengthBytes-3); // byte[] messageBytes = inc.ReadBytes(inc.LengthBytes-3);
reliableMessage.InnerMessage.Write(messageBytes); // reliableMessage.InnerMessage.Write(messageBytes);
c.ReliableChannel.SendMessage(reliableMessage, c.Connection); // c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
} // }
} //}
else //else
{ //{
outmsg = server.CreateMessage(); // outmsg = server.CreateMessage();
outmsg.Write(inc); // outmsg.Write(inc);
List<NetConnection> recipientConnections = new List<NetConnection>(); // List<NetConnection> recipientConnections = new List<NetConnection>();
foreach (Client c in recipients) recipientConnections.Add(c.Connection); // foreach (Client c in recipients) recipientConnections.Add(c.Connection);
server.SendMessage(outmsg, recipientConnections, inc.DeliveryMethod, 0); // server.SendMessage(outmsg, recipientConnections, inc.DeliveryMethod, 0);
} //}
break; break;
case (byte)PacketTypes.Chatmessage: case (byte)PacketTypes.Chatmessage:
@@ -624,7 +632,7 @@ namespace Barotrauma.Networking
private void SendNetworkEvents() private void SendNetworkEvents()
{ {
if (NetworkEvent.events.Count == 0) return; if (NetworkEvent.Events.Count == 0) return;
List<Client> recipients = connectedClients.FindAll(c => c.character != null); List<Client> recipients = connectedClients.FindAll(c => c.character != null);
@@ -636,54 +644,84 @@ namespace Barotrauma.Networking
if (recipients.Count == 0) return; if (recipients.Count == 0) return;
for (int i = 0; i<2; i++) //foreach (Client c in recipients)
//{
// for (int i = 0; i < 2; i++)
// {
// bool important = i == 0;
// var events = NetworkEvent.Events.FindAll(e => e.IsImportant == important && e.SenderConnection != c.Connection);
// if (events.Count == 0) continue;
// List<byte[]> msgBytes = new List<byte[]>();
// int totalLength = 1;
// foreach (NetworkEvent unreliableEvent in events)
// {
// NetBuffer tempMessage = new NetBuffer();// server.CreateMessage();
// if (!unreliableEvent.FillData(tempMessage)) continue;
// tempMessage.WritePadBits();
// tempMessage.Position = 0;
// msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes));
// //one extra byte for writing the length
// totalLength += 1 + tempMessage.LengthBytes;
// }
// //NetOutgoingMessage combinedMessage = null;
// //reliableMessage = null;
// if (important)
// {
// ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
// reliableMessage.InnerMessage.Write((byte)msgBytes.Count);
// foreach (byte[] msgData in msgBytes)
// {
// if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)");
// reliableMessage.InnerMessage.Write((byte)msgData.Length);
// reliableMessage.InnerMessage.Write(msgData);
// }
// c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
// }
// else
// {
// var combinedMessage = server.CreateMessage(totalLength);
// combinedMessage.Write((byte)msgBytes.Count);
// foreach (byte[] msgData in msgBytes)
// {
// if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)");
// combinedMessage.Write((byte)msgData.Length);
// combinedMessage.Write(msgData);
// }
// server.SendMessage(combinedMessage, c.Connection, NetDeliveryMethod.Unreliable, 0);
// }
// }
//}
foreach (Client c in recipients)
{ {
bool important = i==0; var message = ComposeNetworkEventMessage(true, c.Connection);
if (message != null)
var unreliableEvents = NetworkEvent.events.FindAll(e => e.IsImportant == important);
if (unreliableEvents.Count == 0) continue;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NetworkEvent);
List<byte[]> msgBytes = new List<byte[]>();
foreach (NetworkEvent unreliableEvent in unreliableEvents)
{ {
NetBuffer tempMessage = new NetBuffer();// server.CreateMessage(); ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
if (!unreliableEvent.FillData(tempMessage)) continue; message.Position = 0;
tempMessage.WritePadBits(); reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
tempMessage.Position = 0; c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes));
} }
message.Write((byte)msgBytes.Count); message = ComposeNetworkEventMessage(false, c.Connection);
foreach (byte[] msgData in msgBytes) if (message != null)
{ {
if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent ("+msgData.Length+" bytes)"); server.SendMessage(message, c.Connection, NetDeliveryMethod.Unreliable, 0);
message.Write((byte)msgData.Length);
message.Write(msgData);
}
if (important)
{
foreach (Client c in recipients)
{
ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
message.Position = 0;
reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
}
}
else
{
if (server.ConnectionsCount>0)
{
server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
}
} }
} }
@@ -720,7 +758,7 @@ namespace Barotrauma.Networking
// } // }
// } // }
//} //}
NetworkEvent.events.Clear(); NetworkEvent.Events.Clear();
} }
@@ -1372,7 +1410,7 @@ namespace Barotrauma.Networking
case 1: case 1:
msg.Write((byte)PacketTypes.NetworkEvent); msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)NetworkEventType.ComponentUpdate); msg.Write((byte)NetworkEventType.ComponentUpdate);
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID); msg.Write((int)Item.ItemList[Rand.Int(Item.ItemList.Count)].ID);
msg.Write(Rand.Int(8)); msg.Write(Rand.Int(8));
break; break;
case 2: case 2:
+5 -3
View File
@@ -109,7 +109,7 @@ namespace Barotrauma.Networking
public float Average() public float Average()
{ {
return values.Average(); return values.Length == 0 ? 0.0f : values.Average();
} }
public void Update(float newValue) public void Update(float newValue)
@@ -133,11 +133,13 @@ namespace Barotrauma.Networking
graphMaxVal = (float)maxVal; graphMaxVal = (float)maxVal;
} }
GUI.DrawRectangle(spriteBatch, rect, Color.White);
if (values.Length == 0) return;
float lineWidth = (float)rect.Width / (float)(values.Length - 2); float lineWidth = (float)rect.Width / (float)(values.Length - 2);
float yScale = (float)rect.Height / graphMaxVal; 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); Vector2 prevPoint = new Vector2(rect.Right, rect.Bottom - (values[1] + (values[0] - values[1]) * xOffset) * yScale);
float currX = rect.Right - ((xOffset - 1.0f) * lineWidth); float currX = rect.Right - ((xOffset - 1.0f) * lineWidth);
+39 -5
View File
@@ -26,7 +26,7 @@ namespace Barotrauma.Networking
class NetworkEvent class NetworkEvent
{ {
public static List<NetworkEvent> events = new List<NetworkEvent>(); public static List<NetworkEvent> Events = new List<NetworkEvent>();
private static bool[] isImportant; private static bool[] isImportant;
private static bool[] overridePrevious; private static bool[] overridePrevious;
@@ -68,6 +68,8 @@ namespace Barotrauma.Networking
private object data; private object data;
public NetConnection SenderConnection;
//private NetOutgoingMessage message; //private NetOutgoingMessage message;
public ushort ID public ushort ID
@@ -110,7 +112,7 @@ namespace Barotrauma.Networking
if (overridePrevious[(int)type]) if (overridePrevious[(int)type])
{ {
if (events.Find(e => e.id == id && e.eventType == type) != null) return; if (Events.Find(e => e.id == id && e.eventType == type) != null) return;
} }
this.id = id; this.id = id;
@@ -118,7 +120,7 @@ namespace Barotrauma.Networking
this.data = data; this.data = data;
events.Add(this); Events.Add(this);
} }
public bool FillData(NetBuffer message) public bool FillData(NetBuffer message)
@@ -147,7 +149,31 @@ namespace Barotrauma.Networking
return true; return true;
} }
public static bool ReadData(NetIncomingMessage message) public static void ReadMessage(NetIncomingMessage message, bool resend=false)
{
byte msgCount = message.ReadByte();
long currPos = message.PositionInBytes;
for (int i = 0; i < msgCount; i++)
{
byte msgLength = message.ReadByte();
try
{
NetworkEvent.ReadData(message, resend);
}
catch
{
int afghj = 1;
}
//+1 because msgLength is one additional byte
currPos += msgLength + 1;
message.Position = currPos * 8;
}
}
public static bool ReadData(NetIncomingMessage message, bool resend=false)
{ {
NetworkEventType eventType; NetworkEventType eventType;
ushort id; ushort id;
@@ -175,9 +201,11 @@ namespace Barotrauma.Networking
return false; return false;
} }
object data;
try try
{ {
e.ReadNetworkData(eventType, message); e.ReadNetworkData(eventType, message, out data);
} }
catch (Exception exception) catch (Exception exception)
{ {
@@ -187,6 +215,12 @@ namespace Barotrauma.Networking
return false; return false;
} }
if (resend)
{
var resendEvent = new NetworkEvent(eventType, id, false, data);
resendEvent.SenderConnection = message.SenderConnection;
}
return true; return true;
} }
} }
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System.Collections.Generic; using System.Collections.Generic;
using Lidgren.Network;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
@@ -42,6 +43,8 @@ namespace Barotrauma.Networking
protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen }; protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen };
protected NetPeer netPeer;
protected string name; protected string name;
protected TimeSpan updateInterval; protected TimeSpan updateInterval;
@@ -120,6 +123,44 @@ namespace Barotrauma.Networking
Voting = new Voting(); Voting = new Voting();
} }
protected NetOutgoingMessage ComposeNetworkEventMessage(bool isImportant, NetConnection excludedConnection = null)
{
if (netPeer == null) return null;
var events = NetworkEvent.Events.FindAll(e => e.IsImportant == isImportant);
if (events.Count == 0) return null;
List<byte[]> msgBytes = new List<byte[]>();
foreach (NetworkEvent networkEvent in events)
{
if (excludedConnection != null && networkEvent.SenderConnection == excludedConnection) continue;
NetBuffer tempMessage = new NetBuffer();// server.CreateMessage();
if (!networkEvent.FillData(tempMessage)) continue;
tempMessage.WritePadBits();
tempMessage.Position = 0;
msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes));
}
if (msgBytes.Count == 0) return null;
NetOutgoingMessage message = netPeer.CreateMessage();
message.Write((byte)PacketTypes.NetworkEvent);
message.Write((byte)msgBytes.Count);
foreach (byte[] msgData in msgBytes)
{
if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)");
message.Write((byte)msgData.Length);
message.Write(msgData);
}
return message;
}
protected void CreateCrewFrame(List<Character> crew) protected void CreateCrewFrame(List<Character> crew)
{ {
int width = 600, height = 400; int width = 600, height = 400;
+8 -8
View File
@@ -7,17 +7,17 @@ namespace Barotrauma
{ {
class EditMapScreen : Screen class EditMapScreen : Screen
{ {
Camera cam; private Camera cam;
GUIComponent GUIpanel; private GUIComponent GUIpanel;
GUIComponent[] GUItabs; private GUIComponent[] GUItabs;
int selectedTab; private int selectedTab;
//a character used for picking up and manipulating items //a character used for picking up and manipulating items
Character dummyCharacter; private Character dummyCharacter;
bool characterMode; private bool characterMode;
public Camera Cam public Camera Cam
{ {
@@ -31,12 +31,12 @@ namespace Barotrauma
private string GetItemCount() private string GetItemCount()
{ {
return "Items: " +Item.itemList.Count; return "Items: " +Item.ItemList.Count;
} }
private string GetStructureCount() private string GetStructureCount()
{ {
return "Structures: " + (MapEntity.mapEntityList.Count - Item.itemList.Count); return "Structures: " + (MapEntity.mapEntityList.Count - Item.ItemList.Count);
} }
private string GetPhysicsBodyCount() private string GetPhysicsBodyCount()
Binary file not shown.