38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
+177 -86
View File
@@ -1,24 +1,28 @@
using Barotrauma.Networking;
using Barotrauma.Particles;
using Barotrauma.Sounds;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Input;
using System.Linq;
namespace Barotrauma
{
partial class Hull : MapEntity, ISerializableEntity, IServerSerializable
{
public const int MaxDecalsPerHull = 10;
public static WaterRenderer renderer;
private List<Decal> decals = new List<Decal>();
private Sound currentFlowSound;
private int soundIndex;
private float soundVolume;
public override bool SelectableInEditor
{
get
{
return ShowHulls;
}
}
public override bool DrawBelowWater
{
@@ -35,7 +39,7 @@ namespace Barotrauma
return true;
}
}
public override bool IsMouseOn(Vector2 position)
{
if (!GameMain.DebugDraw && !ShowHulls) return false;
@@ -57,9 +61,25 @@ namespace Barotrauma
return decal;
}
private GUIComponent CreateEditingHUD(bool inGame = false)
{
editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this };
GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null);
new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true);
PositionEditingHUD();
return editingHUD;
}
public override void UpdateEditing(Camera cam)
{
if (editingHUD == null || editingHUD.UserData as Hull != this)
{
editingHUD = CreateEditingHUD(Screen.Selected != GameMain.SubEditorScreen);
}
if (!PlayerInput.KeyDown(Keys.Space)) return;
bool lClick = PlayerInput.LeftButtonClicked();
bool rClick = PlayerInput.RightButtonClicked();
@@ -124,53 +144,7 @@ namespace Barotrauma
}
decals.RemoveAll(d => d.FadeTimer >= d.LifeTime);
float strongestFlow = 0.0f;
foreach (Gap gap in ConnectedGaps)
{
if (gap.IsRoomToRoom)
{
//only the first linked hull plays the flow sound
if (gap.linkedTo[1] == this) continue;
}
float gapFlow = gap.LerpedFlowForce.Length();
if (gapFlow > strongestFlow)
{
strongestFlow = gapFlow;
}
}
if (strongestFlow > 1.0f)
{
soundVolume = soundVolume + ((strongestFlow < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f);
soundVolume = MathHelper.Clamp(soundVolume, 0.0f, 1.0f);
int index = (int)Math.Floor(MathHelper.Lerp(0, SoundPlayer.FlowSounds.Count - 1, strongestFlow / 600.0f));
index = Math.Min(index, SoundPlayer.FlowSounds.Count - 1);
var flowSound = SoundPlayer.FlowSounds[index];
if (flowSound != currentFlowSound && soundIndex > -1)
{
Sounds.SoundManager.Stop(soundIndex);
currentFlowSound = null;
soundIndex = -1;
}
currentFlowSound = flowSound;
soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, Math.Min(strongestFlow * 5.0f, 2000.0f));
}
else
{
if (soundIndex > -1)
{
Sounds.SoundManager.Stop(soundIndex);
currentFlowSound = null;
soundIndex = -1;
}
}
if (waterVolume < 1.0f) return;
for (int i = 1; i < waveY.Length - 1; i++)
{
@@ -251,6 +225,21 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.Center.X, -drawRect.Y + drawRect.Height / 2, 10, (int)(100 * (waterVolume - Volume) / MaxCompress)), Color.Red, true);
}
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.Center.X, -drawRect.Y + drawRect.Height / 2, 10, 100), Color.Black);
foreach (FireSource fs in FireSources)
{
Rectangle fireSourceRect = new Rectangle((int)fs.WorldPosition.X, -(int)fs.WorldPosition.Y, (int)fs.Size.X, (int)fs.Size.Y);
GUI.DrawRectangle(spriteBatch, fireSourceRect, Color.Orange, false, 0, 5);
//GUI.DrawRectangle(spriteBatch, new Rectangle((int)fs.LastExtinguishPos.X, (int)-fs.LastExtinguishPos.Y, 5,5), Color.Yellow, true);
}
/*GUI.DrawLine(spriteBatch, new Vector2(drawRect.X, -WorldSurface), new Vector2(drawRect.Right, -WorldSurface), Color.Cyan * 0.5f);
for (int i = 0; i < waveY.Length - 1; i++)
{
GUI.DrawLine(spriteBatch,
new Vector2(drawRect.X + WaveWidth * i, -WorldSurface - waveY[i] - 10),
new Vector2(drawRect.X + WaveWidth * (i + 1), -WorldSurface - waveY[i + 1] - 10), Color.Blue * 0.5f);
}*/
}
if ((IsSelected || isHighlighted) && editing)
@@ -262,22 +251,47 @@ namespace Barotrauma
}
}
public void Render(GraphicsDevice graphicsDevice, Camera cam)
public static void UpdateVertices(GraphicsDevice graphicsDevice, Camera cam, WaterRenderer renderer)
{
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
foreach (EntityGrid entityGrid in EntityGrids)
{
if (entityGrid.WorldRect.X > cam.WorldView.Right || entityGrid.WorldRect.Right < cam.WorldView.X) continue;
if (entityGrid.WorldRect.Y - entityGrid.WorldRect.Height > cam.WorldView.Y || entityGrid.WorldRect.Y < cam.WorldView.Y - cam.WorldView.Height) continue;
var allEntities = entityGrid.GetAllEntities();
foreach (Hull hull in allEntities)
{
hull.UpdateVertices(graphicsDevice, cam, entityGrid, renderer);
}
}
}
private void UpdateVertices(GraphicsDevice graphicsDevice, Camera cam, EntityGrid entityGrid, WaterRenderer renderer)
{
Vector2 submarinePos = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
//if there's no more space in the buffer, don't render the water in the hull
//not an ideal solution, but this seems to only happen in cases where the missing
//water is not very noticeable (e.g. zoomed very far out so that multiple subs and ruins are visible)
if (renderer.PositionInBuffer > renderer.vertices.Length - 6)
{
return;
}
if (!renderer.IndoorsVertices.ContainsKey(entityGrid))
{
renderer.IndoorsVertices[entityGrid] = new VertexPositionColorTexture[WaterRenderer.DefaultIndoorsBufferSize];
renderer.PositionInIndoorsBuffer[entityGrid] = 0;
}
//calculate where the surface should be based on the water volume
float top = rect.Y + submarinePos.Y;
float bottom = top - rect.Height;
float drawSurface = surface + submarinePos.Y;
Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
float renderSurface = drawSurface + submarinePos.Y;
if (bottom > cam.WorldView.Y || top < cam.WorldView.Y - cam.WorldView.Height) return;
Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
if (!update)
{
// create the four corners of our triangle.
@@ -310,54 +324,131 @@ namespace Barotrauma
return;
}
float x = rect.X + Submarine.DrawPosition.X;
float x = rect.X;
if (Submarine != null) { x += Submarine.DrawPosition.X; }
int start = (int)Math.Floor((cam.WorldView.X - x) / WaveWidth);
start = Math.Max(start, 0);
int end = (waveY.Length - 1)
- (int)Math.Floor((float)((x + rect.Width) - (cam.WorldView.X + cam.WorldView.Width)) / WaveWidth);
int end = (waveY.Length - 1) - (int)Math.Floor(((x + rect.Width) - (cam.WorldView.Right)) / WaveWidth);
end = Math.Min(end, waveY.Length - 1);
x += start * WaveWidth;
Vector3[] prevCorners = new Vector3[2];
Vector2[] prevUVs = new Vector2[2];
int width = WaveWidth;
for (int i = start; i < end; i++)
{
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
Vector3[] corners = new Vector3[4];
Vector3[] corners = new Vector3[6];
//top left
corners[0] = new Vector3(x, top, 0.0f);
corners[3] = new Vector3(corners[0].X, drawSurface + waveY[i], 0.0f);
//skip adjacent "water rects" if the surface of the water is roughly at the same position
int width = WaveWidth;
while (i < end - 1 && Math.Abs(waveY[i + 1] - waveY[i]) < 1.0f)
{
width += WaveWidth;
i++;
}
//watersurface left
corners[3] = new Vector3(corners[0].X, renderSurface + waveY[i], 0.0f);
//top right
corners[1] = new Vector3(x + width, top, 0.0f);
corners[2] = new Vector3(corners[1].X, drawSurface + waveY[i + 1], 0.0f);
//watersurface right
corners[2] = new Vector3(corners[1].X, renderSurface + waveY[i + 1], 0.0f);
//bottom left
corners[4] = new Vector3(x, bottom, 0.0f);
//bottom right
corners[5] = new Vector3(x + width, bottom, 0.0f);
Vector2[] uvCoords = new Vector2[4];
for (int n = 0; n < 4; n++)
{
uvCoords[n] = Vector2.Transform(new Vector2(corners[n].X, -corners[n].Y), transform);
}
renderer.vertices[renderer.PositionInBuffer] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.PositionInBuffer + 1] = new VertexPositionTexture(corners[1], uvCoords[1]);
renderer.vertices[renderer.PositionInBuffer + 2] = new VertexPositionTexture(corners[2], uvCoords[2]);
if (renderer.PositionInBuffer <= renderer.vertices.Length - 6)
{
if (i == start)
{
prevCorners[0] = corners[0];
prevCorners[1] = corners[3];
prevUVs[0] = uvCoords[0];
prevUVs[1] = uvCoords[3];
}
renderer.vertices[renderer.PositionInBuffer + 3] = new VertexPositionTexture(corners[0], uvCoords[0]);
renderer.vertices[renderer.PositionInBuffer + 4] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.vertices[renderer.PositionInBuffer + 5] = new VertexPositionTexture(corners[3], uvCoords[3]);
//we only create a new quad if this is the first or the last one, of if there's a wave large enough that we need more geometry
if (i == end - 1 || i == start || Math.Abs(prevCorners[1].Y - corners[3].Y) > 1.0f)
{
renderer.vertices[renderer.PositionInBuffer] = new VertexPositionTexture(prevCorners[0], prevUVs[0]);
renderer.vertices[renderer.PositionInBuffer + 1] = new VertexPositionTexture(corners[1], uvCoords[1]);
renderer.vertices[renderer.PositionInBuffer + 2] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.PositionInBuffer += 6;
renderer.vertices[renderer.PositionInBuffer + 3] = new VertexPositionTexture(prevCorners[0], prevUVs[0]);
renderer.vertices[renderer.PositionInBuffer + 4] = new VertexPositionTexture(corners[2], uvCoords[2]);
renderer.vertices[renderer.PositionInBuffer + 5] = new VertexPositionTexture(prevCorners[1], prevUVs[1]);
x += width;
prevCorners[0] = corners[1];
prevCorners[1] = corners[2];
prevUVs[0] = uvCoords[1];
prevUVs[1] = uvCoords[2];
renderer.PositionInBuffer += 6;
}
}
if (renderer.PositionInIndoorsBuffer[entityGrid] <= renderer.IndoorsVertices[entityGrid].Length - 12 &&
cam.Zoom > 0.6f)
{
const float SurfaceSize = 10.0f;
const float SineFrequency1 = 0.01f;
const float SineFrequency2 = 0.05f;
//surface shrinks and finally disappears when the water level starts to reach the top of the hull
float surfaceScale = 1.0f - MathHelper.Clamp(corners[3].Y - (top - SurfaceSize), 0.0f, 1.0f);
Vector3 surfaceOffset = new Vector3(0.0f, -SurfaceSize, 0.0f);
surfaceOffset.Y += (float)Math.Sin((rect.X + i * WaveWidth) * SineFrequency1 + renderer.WavePos.X * 0.25f) * 2;
surfaceOffset.Y += (float)Math.Sin((rect.X + i * WaveWidth) * SineFrequency2 - renderer.WavePos.X) * 2;
surfaceOffset *= surfaceScale;
Vector3 surfaceOffset2 = new Vector3(0.0f, -SurfaceSize, 0.0f);
surfaceOffset2.Y += (float)Math.Sin((rect.X + i * WaveWidth + width) * SineFrequency1 + renderer.WavePos.X * 0.25f) * 2;
surfaceOffset2.Y += (float)Math.Sin((rect.X + i * WaveWidth + width) * SineFrequency2 - renderer.WavePos.X) * 2;
surfaceOffset2 *= surfaceScale;
int posInBuffer = renderer.PositionInIndoorsBuffer[entityGrid];
renderer.IndoorsVertices[entityGrid][posInBuffer + 0] = new VertexPositionColorTexture(corners[3] + surfaceOffset, renderer.IndoorsWaterColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 1] = new VertexPositionColorTexture(corners[2] + surfaceOffset2, renderer.IndoorsWaterColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 2] = new VertexPositionColorTexture(corners[5], renderer.IndoorsWaterColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 3] = new VertexPositionColorTexture(corners[3] + surfaceOffset, renderer.IndoorsWaterColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 4] = new VertexPositionColorTexture(corners[5], renderer.IndoorsWaterColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 5] = new VertexPositionColorTexture(corners[4], renderer.IndoorsWaterColor, Vector2.Zero);
posInBuffer += 6;
renderer.PositionInIndoorsBuffer[entityGrid] = posInBuffer;
if (surfaceScale > 0)
{
renderer.IndoorsVertices[entityGrid][posInBuffer + 0] = new VertexPositionColorTexture(corners[3], renderer.IndoorsSurfaceTopColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 1] = new VertexPositionColorTexture(corners[2], renderer.IndoorsSurfaceTopColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 2] = new VertexPositionColorTexture(corners[2] + surfaceOffset2, renderer.IndoorsSurfaceBottomColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 3] = new VertexPositionColorTexture(corners[3], renderer.IndoorsSurfaceTopColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 4] = new VertexPositionColorTexture(corners[2] + surfaceOffset2, renderer.IndoorsSurfaceBottomColor, Vector2.Zero);
renderer.IndoorsVertices[entityGrid][posInBuffer + 5] = new VertexPositionColorTexture(corners[3] + surfaceOffset, renderer.IndoorsSurfaceBottomColor, Vector2.Zero);
renderer.PositionInIndoorsBuffer[entityGrid] += 6;
}
}
x += WaveWidth;
//clamp the last segment to the right edge of the hull
if (i == end - 2)
{
width -= (int)Math.Max((x + WaveWidth) - (Submarine == null ? rect.Right : (rect.Right + Submarine.DrawPosition.X)), 0);
}
}
}
}
}
}