Merge branch 'master' into new-netcode

Conflicts:
	Subsurface/Source/Events/MonsterEvent.cs
This commit is contained in:
Regalis
2017-03-21 18:16:25 +02:00
8 changed files with 159 additions and 85 deletions
@@ -631,11 +631,24 @@ namespace Barotrauma
walkPos += movement.Length() * 0.15f; walkPos += movement.Length() * 0.15f;
footPos = Collider.SimPosition - new Vector2((float)Math.Sin(-Collider.Rotation), (float)Math.Cos(-Collider.Rotation)) * 0.4f; footPos = Collider.SimPosition - new Vector2((float)Math.Sin(-Collider.Rotation), (float)Math.Cos(-Collider.Rotation)) * 0.4f;
var rightThigh = GetLimb(LimbType.RightThigh); for (int i = -1; i<2; i+=2)
var leftThigh = GetLimb(LimbType.LeftThigh); {
var thigh = i == -1 ? GetLimb(LimbType.LeftThigh) : GetLimb(LimbType.RightThigh);
var leg = i == -1 ? GetLimb(LimbType.LeftLeg) : GetLimb(LimbType.RightLeg);
rightThigh.body.SmoothRotate(torso.Rotation + (float)Math.Sin(walkPos) * 0.3f, 2.0f); float thighDiff = Math.Abs(MathUtils.GetShortestAngle(torso.Rotation, thigh.Rotation));
leftThigh.body.SmoothRotate(torso.Rotation - (float)Math.Sin(walkPos) * 0.3f, 2.0f); if (thighDiff > MathHelper.PiOver2)
{
//thigh bent too close to the torso -> force the leg to extend
float thighTorque = thighDiff * thigh.Mass * Math.Sign(torso.Rotation - thigh.Rotation) * 10.0f;
thigh.body.ApplyTorque(thighTorque);
leg.body.ApplyTorque(thighTorque);
}
else
{
thigh.body.SmoothRotate(torso.Rotation + (float)Math.Sin(walkPos) * i * 0.3f, 2.0f);
}
}
Vector2 transformedFootPos = new Vector2((float)Math.Sin(walkPos) * 0.5f, 0.0f); Vector2 transformedFootPos = new Vector2((float)Math.Sin(walkPos) * 0.5f, 0.0f);
transformedFootPos = Vector2.Transform( transformedFootPos = Vector2.Transform(
+1 -1
View File
@@ -252,7 +252,7 @@ namespace Barotrauma
suicideButton.ToolTip = GameMain.NetworkMember == null ? suicideButton.ToolTip = GameMain.NetworkMember == null ?
"The character can no longer be revived if you give in." : "The character can no longer be revived if you give in." :
"Let go of your character and enter spectator mode (other players will now longer be able to revive you)"; "Let go of your character and enter spectator mode (other players will no longer be able to revive you)";
suicideButton.OnClicked = (button, userData) => suicideButton.OnClicked = (button, userData) =>
{ {
+61 -33
View File
@@ -260,7 +260,34 @@ namespace Barotrauma
public override void AddToGUIUpdateList() public override void AddToGUIUpdateList()
{ {
base.AddToGUIUpdateList(); if (!Visible) return;
if (ComponentsToUpdate.Contains(this)) return;
ComponentsToUpdate.Add(this);
try
{
List<GUIComponent> fixedChildren = new List<GUIComponent>(children);
int lastVisible = 0;
for (int i = 0; i < fixedChildren.Count; i++)
{
if (fixedChildren[i] == frame) continue;
if (!IsChildVisible(fixedChildren[i]))
{
if (lastVisible > 0) break;
continue;
}
lastVisible = i;
fixedChildren[i].AddToGUIUpdateList();
}
}
catch (Exception e)
{
DebugConsole.NewMessage("Error in AddToGUIUpdateList! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
throw e;
}
if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList(); if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList();
} }
@@ -353,18 +380,8 @@ namespace Barotrauma
else else
rect.Width += scrollBar.Rect.Width; rect.Width += scrollBar.Rect.Width;
//float oldScroll = scrollBar.BarScroll;
//float oldSize = scrollBar.BarSize;
UpdateScrollBarSize(); UpdateScrollBarSize();
UpdateChildrenRect(0.0f); UpdateChildrenRect(0.0f);
//if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f;
//if (scrollBar.BarSize < 1.0f && oldScroll == 1.0f)
//{
// scrollBar.BarScroll = 1.0f;
//}
} }
public override void ClearChildren() public override void ClearChildren()
@@ -386,42 +403,53 @@ namespace Barotrauma
{ {
if (!Visible) return; if (!Visible) return;
//base.Draw(spriteBatch);
frame.Draw(spriteBatch); frame.Draw(spriteBatch);
if (!scrollBarHidden) scrollBar.Draw(spriteBatch); if (!scrollBarHidden) scrollBar.Draw(spriteBatch);
int lastVisible = 0;
for (int i = 0; i < children.Count; i++) for (int i = 0; i < children.Count; i++)
{ {
GUIComponent child = children[i]; GUIComponent child = children[i];
if (child == frame || !child.Visible) continue; if (child == frame) continue;
if (scrollBar.IsHorizontal) if (!IsChildVisible(child))
{ {
if (child.Rect.Right < rect.X) continue; if (lastVisible > 0) break;
if (child.Rect.Right > rect.Right) break; continue;
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
{
continue;
}
}
else
{
if (child.Rect.Y + child.Rect.Height < rect.Y) continue;
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) break;
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
{
continue;
}
} }
lastVisible = i;
child.Draw(spriteBatch); child.Draw(spriteBatch);
} }
}
//GUI.DrawRectangle(spriteBatch, rect, Color.Black, false); private bool IsChildVisible(GUIComponent child)
{
if (child == null || !child.Visible) return false;
if (scrollBar.IsHorizontal)
{
if (child.Rect.Right < rect.X) return false;
if (child.Rect.Right > rect.Right) return false;
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
{
return false;
}
}
else
{
if (child.Rect.Y + child.Rect.Height < rect.Y) return false;
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) return false;
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
{
return false;
}
}
return true;
} }
} }
} }
+19 -1
View File
@@ -40,6 +40,8 @@ namespace Barotrauma.Lights
//when were the vertices of the light volume last calculated //when were the vertices of the light volume last calculated
private float lastRecalculationTime; private float lastRecalculationTime;
private Dictionary<Submarine, Vector2> diffToSub;
private DynamicVertexBuffer lightVolumeBuffer; private DynamicVertexBuffer lightVolumeBuffer;
private DynamicIndexBuffer lightVolumeIndexBuffer; private DynamicIndexBuffer lightVolumeIndexBuffer;
private int vertexCount; private int vertexCount;
@@ -151,6 +153,8 @@ namespace Barotrauma.Lights
texture = LightTexture; texture = LightTexture;
diffToSub = new Dictionary<Submarine, Vector2>();
GameMain.LightManager.AddLight(this); GameMain.LightManager.AddLight(this);
} }
@@ -275,7 +279,7 @@ namespace Barotrauma.Lights
Rectangle subBorders = sub.Borders; Rectangle subBorders = sub.Borders;
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height); subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height);
//only draw if the light overlaps with the sub //don't draw any shadows if the light doesn't overlap with the borders of the sub
if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders))
{ {
if (chList.List.Count > 0) NeedsRecalculation = true; if (chList.List.Count > 0) NeedsRecalculation = true;
@@ -283,6 +287,20 @@ namespace Barotrauma.Lights
continue; continue;
} }
//recalculate vertices if the subs have moved > 5 px relative to each other
Vector2 diff = ParentSub.WorldPosition - sub.WorldPosition;
Vector2 prevDiff;
if (!diffToSub.TryGetValue(sub, out prevDiff))
{
diffToSub.Add(sub, diff);
NeedsRecalculation = true;
}
else if (Vector2.DistanceSquared(diff, prevDiff) > 5.0f*5.0f)
{
diffToSub[sub] = diff;
NeedsRecalculation = true;
}
RefreshConvexHullList(chList, lightPos, sub); RefreshConvexHullList(chList, lightPos, sub);
} }
} }
+5 -1
View File
@@ -463,7 +463,11 @@ namespace Barotrauma
Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center); Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center);
selectedList = new List<MapEntity>(clones); selectedList = new List<MapEntity>(clones);
selectedList.ForEach(c => c.Move(moveAmount)); foreach (MapEntity clone in selectedList)
{
clone.Move(moveAmount);
clone.Submarine = Submarine.MainSub;
}
} }
} }
+4 -4
View File
@@ -160,17 +160,17 @@ namespace Barotrauma
private List<Vector2> GenerateConvexHull() private List<Vector2> GenerateConvexHull()
{ {
if (!Structure.WallList.Any()) List<Structure> subWalls = Structure.WallList.FindAll(wall => wall.Submarine == submarine);
if (subWalls.Count == 0)
{ {
return new List<Vector2> { new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f) }; return new List<Vector2> { new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f) };
} }
List<Vector2> points = new List<Vector2>(); List<Vector2> points = new List<Vector2>();
foreach (Structure wall in Structure.WallList) foreach (Structure wall in subWalls)
{ {
if (wall.Submarine != submarine) continue;
points.Add(new Vector2(wall.Rect.X, wall.Rect.Y)); points.Add(new Vector2(wall.Rect.X, wall.Rect.Y));
points.Add(new Vector2(wall.Rect.X + wall.Rect.Width, wall.Rect.Y)); points.Add(new Vector2(wall.Rect.X + wall.Rect.Width, wall.Rect.Y));
points.Add(new Vector2(wall.Rect.X, wall.Rect.Y - wall.Rect.Height)); points.Add(new Vector2(wall.Rect.X, wall.Rect.Y - wall.Rect.Height));
+38 -29
View File
@@ -346,42 +346,51 @@ namespace Barotrauma
private static List<BackgroundMusic> GetSuitableMusicClips() private static List<BackgroundMusic> GetSuitableMusicClips()
{ {
Task criticalTask = null; string musicType = "default";
if (GameMain.GameSession != null && GameMain.GameSession.TaskManager != null) if (OverrideMusicType != null)
{ {
foreach (Task task in GameMain.GameSession.TaskManager.Tasks) musicType = OverrideMusicType;
}
else if (Character.Controlled != null &&
Level.Loaded != null && Level.Loaded.Ruins != null &&
Level.Loaded.Ruins.Any(r => r.Area.Contains(Character.Controlled.WorldPosition)))
{
musicType = "ruins";
}
else if ((Character.Controlled != null && Character.Controlled.Submarine != null && Character.Controlled.Submarine.AtDamageDepth) ||
(Screen.Selected == GameMain.GameScreen && GameMain.GameScreen.Cam.Position.Y < SubmarineBody.DamageDepth))
{
musicType = "deep";
}
else
{
Task criticalTask = null;
if (GameMain.GameSession != null && GameMain.GameSession.TaskManager != null)
{ {
if (!task.IsStarted) continue; foreach (Task task in GameMain.GameSession.TaskManager.Tasks)
if (criticalTask == null || task.Priority > criticalTask.Priority)
{ {
criticalTask = task; if (!task.IsStarted) continue;
if (criticalTask == null || task.Priority > criticalTask.Priority)
{
criticalTask = task;
}
} }
} }
if (criticalTask != null)
{
var suitableClips =
musicClips.Where(music =>
music != null &&
music.type == criticalTask.MusicType &&
music.priorityRange.X < criticalTask.Priority &&
music.priorityRange.Y > criticalTask.Priority).ToList();
if (suitableClips.Count > 0) return suitableClips;
}
} }
if (OverrideMusicType != null) return musicClips.Where(music => music != null && music.type == musicType).ToList();
{
return musicClips.Where(x => x != null && x.type == OverrideMusicType).ToList();
}
else if (Character.Controlled != null && Level.Loaded != null && Level.Loaded.Ruins!=null && Level.Loaded.Ruins.Any(r => r.Area.Contains(Character.Controlled.WorldPosition)))
{
return musicClips.Where(x => x != null && x.type == "ruins").ToList();
}
else if (Submarine.MainSub != null && Submarine.MainSub.AtDamageDepth)
{
return musicClips.Where(x => x != null && x.type == "deep").ToList();
}
else if (criticalTask == null)
{
return musicClips.Where(x => x != null && x.type == "default").ToList();
}
return musicClips.Where(x =>
x != null &&
x.type == criticalTask.MusicType &&
x.priorityRange.X < criticalTask.Priority &&
x.priorityRange.Y > criticalTask.Priority).ToList();
} }
public static void PlaySplashSound(Vector2 worldPosition, float strength) public static void PlaySplashSound(Vector2 worldPosition, float strength)
+2
View File
@@ -381,6 +381,8 @@ namespace Barotrauma
public static List<Vector2> GiftWrap(List<Vector2> points) public static List<Vector2> GiftWrap(List<Vector2> points)
{ {
if (points.Count == 0) return points;
Vector2 leftMost = points[0]; Vector2 leftMost = points[0];
foreach (Vector2 point in points) foreach (Vector2 point in points)
{ {