Round end cinematic, CoroutineManager deltatime

This commit is contained in:
Regalis11
2015-12-26 19:33:23 +02:00
parent b2d5704f7e
commit 064e2eadd0
18 changed files with 138 additions and 38 deletions

Binary file not shown.

View File

@@ -121,8 +121,9 @@
<Compile Include="Source\Map\Levels\LevelRenderer.cs" />
<Compile Include="Source\Map\Levels\WrappingWall.cs" />
<Compile Include="Source\Map\Lights\LightSource.cs" />
<Compile Include="Source\Map\LocationType.cs" />
<Compile Include="Source\Map\Map\LocationType.cs" />
<Compile Include="Source\Map\SubmarineBody.cs" />
<Compile Include="Source\Map\TransitionCinematic.cs" />
<Compile Include="Source\Networking\BanList.cs" />
<Compile Include="Source\Networking\NetConfig.cs" />
<Compile Include="Source\Networking\NetStats.cs" />
@@ -200,8 +201,8 @@
<Compile Include="Source\Map\Levels\Level.cs" />
<Compile Include="Source\Map\Lights\ConvexHull.cs" />
<Compile Include="Source\Map\Lights\LightManager.cs" />
<Compile Include="Source\Map\Location.cs" />
<Compile Include="Source\Map\Map.cs" />
<Compile Include="Source\Map\Map\Location.cs" />
<Compile Include="Source\Map\Map\Map.cs" />
<Compile Include="Source\Map\Md5Hash.cs" />
<Compile Include="Source\Map\Levels\Voronoi.cs" />
<Compile Include="Source\Map\Levels\VoronoiElements.cs" />
@@ -239,7 +240,7 @@
<Compile Include="Source\Map\Submarine.cs" />
<Compile Include="Source\Map\Structure.cs" />
<Compile Include="Source\Map\StructurePrefab.cs" />
<Compile Include="Source\Map\WaterRenderer.cs" />
<Compile Include="Source\Map\Levels\WaterRenderer.cs" />
<Compile Include="Source\Map\WayPoint.cs" />
<Compile Include="Source\Networking\GameClient.cs" />
<Compile Include="Source\Networking\GameServer.cs" />

View File

@@ -6,7 +6,7 @@
linkable="true"
pickdistance="150">
<Sprite texture ="railgunbase.png"/>
<Sprite texture ="railgunbase.png" depth = "0.01"/>
<Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="128, 128"
rotationlimits="180,360"

View File

@@ -1108,11 +1108,11 @@ namespace Barotrauma
float timer = 0.0f;
Color prevAmbientLight = GameMain.LightManager.AmbientLight;
Color darkLight = new Color(0.2f,0.2f,0.2f, 1.0f);
Color darkLight = new Color(0.2f, 0.2f, 0.2f, 1.0f);
while (timer < dimDuration)
{
timer += 1.0f / 60.0f;
timer += CoroutineManager.DeltaTime;
if (controlled == this)
{

View File

@@ -16,6 +16,8 @@ namespace Barotrauma
{
static List<IEnumerator<object>> Coroutines = new List<IEnumerator<object>>();
public static float DeltaTime;
// Starting a coroutine just means adding an enumerator to the list.
// You might also want to be able to stop coroutines or delete them,
// which might mean putting them into a dictionary
@@ -42,6 +44,8 @@ namespace Barotrauma
// Updating just means stepping through all the coroutines
public static void Update(float deltaTime)
{
DeltaTime = deltaTime;
for (int i = Coroutines.Count-1; i>=0; i--)
{
if (Coroutines[i].Current != null)

View File

@@ -20,12 +20,12 @@ namespace Barotrauma
{
public static GUIStyle Style;
static Texture2D t;
private static Texture2D t;
public static SpriteFont Font, SmallFont, LargeFont;
private static Sprite cursor;
private static GraphicsDevice graphicsDevice;
private static GraphicsDevice graphicsDevice;
private static List<GUIMessage> messages = new List<GUIMessage>();
@@ -34,6 +34,8 @@ namespace Barotrauma
private static bool pauseMenuOpen;
private static GUIFrame pauseMenu;
public static Color ScreenOverlayColor;
public static void Init(ContentManager content)
{
GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content);
@@ -60,8 +62,7 @@ namespace Barotrauma
// create 1x1 texture for line drawing
t = new Texture2D(graphicsDevice, 1, 1);
t.SetData<Color>(
new Color[] { Color.White });// fill the texture with white
t.SetData(new Color[] { Color.White });// fill the texture with white
Style = new GUIStyle("Content/UI/style.xml");
}
@@ -294,6 +295,14 @@ namespace Barotrauma
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
{
if (ScreenOverlayColor.A>0.0f)
{
DrawRectangle(
spriteBatch,
new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
ScreenOverlayColor, true);
}
spriteBatch.DrawString(Font,
"FPS: " + (int)GameMain.FrameCounter.AverageFramesPerSecond,
new Vector2(10, 10), Color.White);

View File

@@ -234,10 +234,25 @@ namespace Barotrauma
private bool EndShift(GUIButton button, object obj)
{
End("");
var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam);
CoroutineManager.StartCoroutine(EndCinematic(cinematic));
return true;
}
private IEnumerable<object> EndCinematic(TransitionCinematic cinematic)
{
while (cinematic.Running)
{
yield return CoroutineStatus.Running;
}
End("");
yield return CoroutineStatus.Success;
}
public void Save(XElement element)
{
//element.Add(new XAttribute("day", day));

View File

@@ -87,6 +87,12 @@ namespace Barotrauma
private set;
}
public Body[] ShaftBodies
{
get;
private set;
}
public Level(string seed, float difficulty, int width, int height, int siteInterval)
{
this.seed = seed;
@@ -333,14 +339,14 @@ namespace Barotrauma
}
ShaftBodies = new Body[2];
for (int i = 0; i < 2; i++)
{
Body shaftBody = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f);
shaftBody.BodyType = BodyType.Kinematic;
shaftBody.CollisionCategories = Physics.CollisionLevel;
shaftBody.SetTransform(ConvertUnits.ToSimUnits((i == 0) ? startPosition : endPosition), 0.0f);
shaftBody.SleepingAllowed = false;
bodies.Add(shaftBody);
ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f);
ShaftBodies[i].BodyType = BodyType.Static;
ShaftBodies[i].CollisionCategories = Physics.CollisionLevel;
ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits((i == 0) ? startPosition : endPosition), 0.0f);
bodies.Add(ShaftBodies[i]);
}
foreach (VoronoiCell cell in cells)

View File

@@ -175,13 +175,11 @@ namespace Barotrauma
basicEffect.TextureEnabled = false;
basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_VertexColor"];
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f));
for (int side = 0; side < 2; side++)
{
for (int i = 0; i < 2; i++)
{
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].BodyVertices);
@@ -189,7 +187,6 @@ namespace Barotrauma
graphicsDevice.DrawPrimitives(
PrimitiveType.TriangleList, 0,
(int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.VertexCount / 3.0f));
}
}

View File

@@ -0,0 +1,73 @@
using FarseerPhysics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Barotrauma
{
class TransitionCinematic
{
public bool Running
{
get;
private set;
}
public TransitionCinematic(Submarine submarine, Camera cam)
{
Vector2 targetPos = submarine.Position;
if (submarine.AtEndPosition)
{
targetPos = Level.Loaded.EndPosition + Vector2.UnitY * 500.0f;
}
else if (submarine.AtStartPosition)
{
targetPos = Level.Loaded.StartPosition + Vector2.UnitY * 500.0f;
}
Running = true;
CoroutineManager.StartCoroutine(UpdateTransitionCinematic(submarine, cam, targetPos));
}
private IEnumerable<object> UpdateTransitionCinematic(Submarine sub, Camera cam, Vector2 targetPos)
{
Character.Controlled = null;
GameMain.LightManager.LosEnabled = false;
Vector2 diff = targetPos - sub.Position;
float targetSpeed = 10.0f;
Level.Loaded.ShaftBodies[0].Enabled = false;
Level.Loaded.ShaftBodies[1].Enabled = false;
cam.TargetPos = Vector2.Zero;
float duration = 5.0f;
float timer = 0.0f;
while (timer < duration)
{
Vector2 cameraPos = sub.Position;
cameraPos.Y = ConvertUnits.ToDisplayUnits(Level.Loaded.ShaftBodies[0].Position.Y) - cam.WorldView.Height/2.0f;
GUI.ScreenOverlayColor = Color.Lerp(Color.TransparentBlack, Color.Black, timer/duration);
cam.Translate((cameraPos - cam.Position) * CoroutineManager.DeltaTime);
cam.Zoom = Math.Max(0.2f, cam.Zoom - CoroutineManager.DeltaTime * 0.1f);
sub.ApplyForce((Vector2.Normalize(diff) * targetSpeed - sub.Velocity) * 500.0f);
timer -= CoroutineManager.DeltaTime;
yield return CoroutineStatus.Running;
}
Running = false;
yield return CoroutineStatus.Success;
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Barotrauma
public const Category CollisionLevel = Category.Cat7;
public static double accumulator;
public static double step = 1.0f/60.0f;
public static double step = 1.0/60.0;
public const float DisplayToSimRation = 100.0f;

View File

@@ -153,6 +153,8 @@ namespace Barotrauma
{
base.Select();
GUI.ScreenOverlayColor = Color.Transparent;
gameMode = GameMain.GameSession.gameMode as SinglePlayerMode;
foreach (GUIComponent component in topPanel.children)
@@ -163,8 +165,6 @@ namespace Barotrauma
button.Enabled = GameMain.GameSession.Map.CurrentLocation.Type.HasHireableCharacters;
break;
}
//hireButton.Enabled = location.Type.HasHireableCharacters;
UpdateCharacterLists();
}
@@ -201,11 +201,7 @@ namespace Barotrauma
c.Salary.ToString(),
null, null,
Alignment.TopRight, GUI.Style, frame);
}
}
else
{
//(topPanel.FindChild(PanelTab.CurrentLocation) as GUIButton).Enabled = false;
}
}
}

View File

@@ -282,8 +282,8 @@ namespace Barotrauma
public override void Select()
{
GameMain.LightManager.LosEnabled = false;
//infoFrame.ClearChildren();
GUI.ScreenOverlayColor = Color.Transparent;
textBox.Select();
@@ -297,8 +297,7 @@ namespace Barotrauma
serverMessage.Enabled = GameMain.Server != null;
autoRestartBox.Enabled = GameMain.Server != null;
ServerName = (GameMain.Server==null) ? "Server" : GameMain.Server.Name;
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton"));
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "settingsButton"));
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton"));

View File

@@ -197,13 +197,13 @@ namespace Barotrauma
public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null)
{
//for (int x = -1; x < 3; x+=2 )
//for (int x = -1; x < 3; x += 2)
//{
// for (int y = -1; y < 3; y+=2 )
// for (int y = -1; y < 3; y += 2)
// {
// spriteBatch.Draw(texture, pos + offset + new Vector2(x, y)*1.0f, sourceRect, Color.Black, rotation + rotate, origin, scale, spriteEffect, (depth == null ? this.depth : (float)depth)+0.0001f);
// }
// spriteBatch.Draw(texture, pos + offset + new Vector2(x, y) * 1.0f, sourceRect, Color.Black, rotation + rotate, origin, scale, spriteEffect, (depth == null ? this.depth : (float)depth) + 0.0001f);
// }
//}
spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);