From 7a413aee933d60ed747253183854eb987c5f6c0c Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Wed, 20 Dec 2017 19:41:23 -0300 Subject: [PATCH] Optimized GameScreen.DrawMap - Downscaled lightmap, since blurring will make this unnoticeable anyway (TODO: make this optional) - Render LOS in fewer passes by using a shader - Use light volume to calculate LOS - This also means we can use the override texture to render the diving suit obstruct effect - Don't render bunks and labels onto LOS background (TODO: add the option to render back into the LOS background, i.e. just use multiplicative blending as if it was the lightmap) - Prefer SpriteSortMode.Deferred over all others, prefer SamplerState.LinearClamp/PointClamp over all others - Remove shader blur in favor of geometry blur (TODO: improve on this further, right now it has a few artifacts) - Trim light volumes - Do some weird shit with the background particles (use DrawTiled instead of relying on SamplerState.LinearWrap, because that's faster somehow :/ ) - Pressing up/down in the console only returns a typed command now --- .../Source/Characters/Character.cs | 10 +- .../Source/GUI/GUIComponent.cs | 64 +- .../BarotraumaClient/Source/GUI/GUIMessage.cs | 2 +- .../BarotraumaClient/Source/GUI/GUITickBox.cs | 4 +- .../BarotraumaClient/Source/Map/FireSource.cs | 6 +- .../Source/Map/Levels/LevelRenderer.cs | 40 +- .../Source/Map/Levels/WaterRenderer.cs | 10 +- .../Source/Map/Lights/LightManager.cs | 110 +- .../Source/Map/Lights/LightSource.cs | 158 +- .../Source/Particles/Particle.cs | 2 +- .../Source/Screens/GameScreen.cs | 265 +-- .../BarotraumaClient/Source/Sprite/Sprite.cs | 25 +- .../Source/Utils/TextureLoader.cs | 4 +- .../Source/Utils/MonogameTypes/Color.cs | 108 +- .../MonogameTypes/Graphics/SpriteEffects.cs | 2 +- .../Utils/MonogameTypes/Input/KeyState.cs | 20 +- .../MonogameTypes/Input/KeyboardState.cs | 2 +- .../Source/Utils/MonogameTypes/Input/Keys.cs | 330 +-- .../Source/Utils/MonogameTypes/Point.cs | 2 +- .../Source/Utils/MonogameTypes/Quaternion.cs | 706 +++---- .../Source/Utils/MonogameTypes/Rectangle.cs | 6 +- .../Source/Utils/MonogameTypes/Vector4.cs | 2 +- .../BarotraumaShared/Content/watershader.fx | 5 +- .../Content/watershader_opengl.xnb | Bin 2133 -> 2154 bytes .../BarotraumaShared/Source/DebugConsole.cs | 25 +- .../BarotraumaShared/Source/Items/Item.cs | 2 +- .../Source/Map/Levels/Voronoi.cs | 1764 ++++++++--------- .../Source/Map/Levels/VoronoiElements.cs | 196 +- .../BarotraumaShared/Source/Map/MapEntity.cs | 4 +- .../BarotraumaShared/Source/PlayerInput.cs | 72 +- 30 files changed, 1986 insertions(+), 1960 deletions(-) mode change 100644 => 100755 Barotrauma/BarotraumaShared/Content/watershader_opengl.xnb diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 8d54f0a0d..286b0779f 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -1,4 +1,4 @@ -using Barotrauma.Networking; +using Barotrauma.Networking; using Barotrauma.Particles; using FarseerPhysics; using FarseerPhysics.Dynamics; @@ -299,6 +299,14 @@ namespace Barotrauma if (info != null) { Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom; + Vector2 screenSize = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight); + Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height); + namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y; + namePos *= screenSize / viewportSize; + namePos.X = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y); + namePos *= viewportSize / screenSize; + namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y; + Color nameColor = Color.White; if (Character.Controlled != null && TeamID != Character.Controlled.TeamID) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs index 8d5f89034..79feedd6e 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIComponent.cs @@ -1,4 +1,4 @@ -using EventInput; +using EventInput; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -130,40 +130,40 @@ namespace Barotrauma get { return new Vector2(rect.Center.X, rect.Center.Y); } } - protected Rectangle ClampRect(Rectangle r) - { - if (parent == null) return r; - Rectangle parentRect = parent.ClampRect(parent.rect); - if (parentRect.Width <= 0 || parentRect.Height <= 0) return Rectangle.Empty; - if (parentRect.X > r.X) - { - int diff = parentRect.X - r.X; - r.X = parentRect.X; - r.Width -= diff; - } - if (parentRect.Y > r.Y) - { - int diff = parentRect.Y - r.Y; - r.Y = parentRect.Y; - r.Height -= diff; - } - if (parentRect.X + parentRect.Width < r.X + r.Width) - { - int diff = (r.X + r.Width) - (parentRect.X + parentRect.Width); - r.Width -= diff; - } - if (parentRect.Y + parentRect.Height < r.Y + r.Height) - { - int diff = (r.Y + r.Height) - (parentRect.Y + parentRect.Height); - r.Height -= diff; - } - if (r.Width <= 0 || r.Height <= 0) return Rectangle.Empty; - return r; - } + protected Rectangle ClampRect(Rectangle r) + { + if (parent == null) return r; + Rectangle parentRect = parent.ClampRect(parent.rect); + if (parentRect.Width <= 0 || parentRect.Height <= 0) return Rectangle.Empty; + if (parentRect.X > r.X) + { + int diff = parentRect.X - r.X; + r.X = parentRect.X; + r.Width -= diff; + } + if (parentRect.Y > r.Y) + { + int diff = parentRect.Y - r.Y; + r.Y = parentRect.Y; + r.Height -= diff; + } + if (parentRect.X + parentRect.Width < r.X + r.Width) + { + int diff = (r.X + r.Width) - (parentRect.X + parentRect.Width); + r.Width -= diff; + } + if (parentRect.Y + parentRect.Height < r.Y + r.Height) + { + int diff = (r.Y + r.Height) - (parentRect.Y + parentRect.Height); + r.Height -= diff; + } + if (r.Width <= 0 || r.Height <= 0) return Rectangle.Empty; + return r; + } public virtual Rectangle Rect { - get { return rect; } + get { return rect; } set { int prevX = rect.X, prevY = rect.Y; diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs index cb1f6b437..8161b3f09 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs @@ -50,7 +50,7 @@ namespace Barotrauma public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered) { - coloredText = new ColoredText(text, color); + coloredText = new ColoredText(text, color, false); pos = position; this.lifeTime = lifeTime; this.Alignment = textAlignment; diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs index 7bdce1606..df50e273d 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Barotrauma @@ -63,7 +63,7 @@ namespace Barotrauma public override Rectangle MouseRect { - get { return ClampRect(box.Rect); } + get { return ClampRect(box.Rect); } } public override ScalableFont Font diff --git a/Barotrauma/BarotraumaClient/Source/Map/FireSource.cs b/Barotrauma/BarotraumaClient/Source/Map/FireSource.cs index 37609a7a3..2a6dd19e6 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/FireSource.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/FireSource.cs @@ -1,4 +1,4 @@ -using Barotrauma.Lights; +using Barotrauma.Lights; using Barotrauma.Particles; using Microsoft.Xna.Framework; using System; @@ -76,9 +76,9 @@ namespace Barotrauma } } - lightSource.Range = Math.Max(size.X, size.Y) * 10.0f / 2.0f; lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f); - lightSource.Position = position + Vector2.UnitY * 30.0f; + if (Math.Abs((lightSource.Range * 0.2f) - Math.Max(size.X, size.Y)) > 1.0f) lightSource.Range = Math.Max(size.X, size.Y) * 5.0f; + if (Vector2.DistanceSquared(lightSource.Position,position) > 5.0f) lightSource.Position = position + Vector2.UnitY * 30.0f; if (size.X > 256.0f) { diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs index 1d816503f..f1e5e209f 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Levels/LevelRenderer.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; @@ -63,6 +63,7 @@ namespace Barotrauma public void Update(float deltaTime) { dustOffset -= Vector2.UnitY * 10.0f * deltaTime; + while (dustOffset.Y <= -1024.0f) dustOffset.Y += 1024.0f; } public static VertexPositionColorTexture[] GetColoredVertices(VertexPositionTexture[] vertices, Color color) @@ -108,7 +109,7 @@ namespace Barotrauma Vector2 backgroundPos = cam.WorldViewCenter; backgroundPos.Y = -backgroundPos.Y; - backgroundPos /= 20.0f; + backgroundPos *= 0.05f; if (backgroundPos.Y < 1024) { @@ -130,35 +131,38 @@ namespace Barotrauma spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.BackToFront, + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.Default, null, null, cam.Transform); + + Vector2 origin = new Vector2(cam.WorldView.X, -cam.WorldView.Y); + Vector2 offset = -origin + dustOffset; + while (offset.X <= -1024.0f) offset.X += 1024.0f; + while (offset.X > 0.0f) offset.X -= 1024.0f; + while (offset.Y <= -1024.0f) offset.Y += 1024.0f; + while (offset.Y > 0.0f) offset.Y -= 1024.0f; if (backgroundSpriteManager != null) backgroundSpriteManager.DrawSprites(spriteBatch, cam); if (backgroundCreatureManager != null) backgroundCreatureManager.Draw(spriteBatch); - + for (int i = 0; i < 4; i++) { float scale = 1.0f - i * 0.2f; + float recipScale = 1.0f / scale; - //alpha goes from 1.0 to 0.0 when scale is in the range of 0.2-0.1 - float alpha = (cam.Zoom * scale) < 0.2f ? (cam.Zoom * scale - 0.1f) * 10.0f : 1.0f; + //alpha goes from 1.0 to 0.0 when scale is in the range of 0.5-0.25 + float alpha = (cam.Zoom * scale) < 0.5f ? (cam.Zoom * scale - 0.25f) * 40.0f : 1.0f; if (alpha <= 0.0f) continue; - Vector2 offset = (new Vector2(cam.WorldViewCenter.X, cam.WorldViewCenter.Y) + dustOffset) * scale; - Vector3 origin = new Vector3(cam.WorldView.Width, cam.WorldView.Height, 0.0f) * 0.5f; + Vector2 offsetS = offset * scale + new Vector2(cam.WorldView.Width, cam.WorldView.Height) * (1.0f - scale) * 0.5f - new Vector2(256.0f * i); + while (offsetS.X <= -1024.0f*scale) offsetS.X += 1024.0f*scale; + while (offsetS.X > 0.0f) offsetS.X -= 1024.0f*scale; + while (offsetS.Y <= -1024.0f*scale) offsetS.Y += 1024.0f*scale; + while (offsetS.Y > 0.0f) offsetS.Y -= 1024.0f*scale; - dustParticles.SourceRect = new Rectangle( - (int)((offset.X - origin.X + (i * 256)) / scale), - (int)((-offset.Y - origin.Y + (i * 256)) / scale), - (int)((cam.WorldView.Width) / scale), - (int)((cam.WorldView.Height) / scale)); - - spriteBatch.Draw(dustParticles.Texture, - new Vector2(cam.WorldViewCenter.X, -cam.WorldViewCenter.Y), - dustParticles.SourceRect, Color.White * alpha, 0.0f, - new Vector2(cam.WorldView.Width, cam.WorldView.Height) * 0.5f / scale, scale, SpriteEffects.None, 1.0f - scale); + Rectangle srcRect = new Rectangle(0, 0, 2048, 2048); + dustParticles.DrawTiled(spriteBatch, origin + offsetS, new Vector2(cam.WorldView.Width - offsetS.X, cam.WorldView.Height - offsetS.Y), Vector2.Zero, srcRect, Color.White * alpha, new Vector2(scale)); } spriteBatch.End(); diff --git a/Barotrauma/BarotraumaClient/Source/Map/Levels/WaterRenderer.cs b/Barotrauma/BarotraumaClient/Source/Map/Levels/WaterRenderer.cs index 130b41319..723a45e92 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Levels/WaterRenderer.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Levels/WaterRenderer.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; @@ -13,7 +13,11 @@ namespace Barotrauma public VertexPositionTexture[] vertices = new VertexPositionTexture[DefaultBufferSize]; - private Effect waterEffect; + public Effect waterEffect + { + get; + private set; + } private BasicEffect basicEffect; public int PositionInBuffer = 0; @@ -93,7 +97,7 @@ namespace Barotrauma basicEffect.CurrentTechnique.Passes[0].Apply(); - graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; + graphicsDevice.SamplerStates[0] = SamplerState.PointWrap; graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3); } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs index aded0f755..1b84da7f2 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightManager.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System.Collections.Generic; using System.Linq; @@ -23,7 +23,17 @@ namespace Barotrauma.Lights public Color AmbientLight; - RenderTarget2D lightMap, losTexture; + private float lightmapScale = 0.5f; + public RenderTarget2D lightMap + { + get; + private set; + } + public RenderTarget2D losTexture + { + get; + private set; + } BasicEffect lightEffect; @@ -36,8 +46,9 @@ namespace Barotrauma.Lights public bool LightingEnabled = true; public bool ObstructVision; + LightSource losSource; - private Texture2D visionCircle; + private Sprite visionCircle; private Dictionary hullAmbientLights; private Dictionary smoothedHullAmbientLights; @@ -50,21 +61,26 @@ namespace Barotrauma.Lights AmbientLight = new Color(20, 20, 20, 255); - visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png"); + //visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png"); + visionCircle = new Sprite("Content/Lights/visioncircle.png", new Vector2(0.2f, 0.5f)); var pp = graphics.PresentationParameters; lightMap = new RenderTarget2D(graphics, - GameMain.GraphicsWidth, GameMain.GraphicsHeight, false, + (int)(GameMain.GraphicsWidth*lightmapScale), (int)(GameMain.GraphicsHeight*lightmapScale), false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); - losTexture = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + losTexture = new RenderTarget2D(graphics, (int)(GameMain.GraphicsWidth*lightmapScale), (int)(GameMain.GraphicsHeight*lightmapScale), false, SurfaceFormat.Alpha8, DepthFormat.None); + + losSource = new LightSource(Vector2.Zero, GameMain.GraphicsWidth, Color.White, null, false); + losSource.texture = new Texture2D(graphics, 1, 1); + losSource.texture.SetData(new Color[] { Color.White });// fill the texture with white if (lightEffect == null) { lightEffect = new BasicEffect(GameMain.Instance.GraphicsDevice); - lightEffect.VertexColorEnabled = false; + lightEffect.VertexColorEnabled = true; lightEffect.TextureEnabled = true; lightEffect.Texture = LightSource.LightTexture; @@ -141,9 +157,9 @@ namespace Barotrauma.Lights //clear to some small ambient light graphics.Clear(AmbientLight); graphics.BlendState = BlendState.Additive; + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform * Matrix.CreateScale(new Vector3(lightmapScale, lightmapScale, 1.0f))); - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform); - Matrix transform = cam.ShaderTransform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; @@ -158,8 +174,8 @@ namespace Barotrauma.Lights } lightEffect.World = Matrix.CreateTranslation(offset) * transform; - - GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive); + + //GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive); if (Character.Controlled != null) { @@ -201,56 +217,43 @@ namespace Barotrauma.Lights public void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition) { - if (!LosEnabled && !ObstructVision) return; + if (!LosEnabled || ViewTarget == null) return; graphics.SetRenderTarget(losTexture); - spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cam.Transform); + //-------------------------------------- + graphics.Clear(Color.Black); if (ObstructVision) { - //graphics.Clear(Color.Black); - Vector2 diff = lookAtPosition - ViewTarget.WorldPosition; - diff.Y = -diff.Y; float rotation = MathUtils.VectorToAngle(diff); - - Vector2 scale = new Vector2(MathHelper.Clamp(diff.Length()/256.0f, 2.0f, 5.0f), 2.0f); - spriteBatch.Draw(visionCircle, new Vector2(ViewTarget.WorldPosition.X, -ViewTarget.WorldPosition.Y), null, Color.White, rotation, - new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f); + Vector2 scale = new Vector2(MathHelper.Clamp(diff.Length() / 256.0f, 2.0f, 5.0f), 2.0f) * 0.3f; + + visionCircle.size = new Vector2(visionCircle.SourceRect.Width * scale.X, visionCircle.SourceRect.Height * scale.Y); + losSource.overrideLightTexture = visionCircle; + losSource.Rotation = rotation; } else { - graphics.Clear(Color.White); + losSource.overrideLightTexture = null; } - spriteBatch.End(); + graphics.BlendState = BlendState.Additive; - //-------------------------------------- + Vector2 pos = ViewTarget.Position; + losSource.Position = pos; + losSource.NeedsRecalculation = true; + losSource.ParentSub = ViewTarget.Submarine; - if (LosEnabled && ViewTarget != null) - { - Vector2 pos = ViewTarget.WorldPosition; + Matrix transform = cam.ShaderTransform + * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; + + losSource.Draw(spriteBatch, lightEffect, transform); - Rectangle camView = new Rectangle(cam.WorldView.X, cam.WorldView.Y - cam.WorldView.Height, cam.WorldView.Width, cam.WorldView.Height); + graphics.BlendState = BlendState.AlphaBlend; - Matrix shadowTransform = cam.ShaderTransform - * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; - - var convexHulls = ConvexHull.GetHullsInRange(viewTarget.Position, cam.WorldView.Width*0.75f, viewTarget.Submarine); - - if (convexHulls != null) - { - foreach (ConvexHull convexHull in convexHulls) - { - if (!convexHull.Intersects(camView)) continue; - //if (!camView.Intersects(convexHull.BoundingBox)) continue; - - convexHull.DrawShadows(graphics, cam, pos, shadowTransform); - } - } - } graphics.SetRenderTarget(null); } @@ -338,22 +341,11 @@ namespace Barotrauma.Lights { if (!LightingEnabled) return; - spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, effect); - spriteBatch.Draw(lightMap, Vector2.Zero, Color.White); + spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, null); + spriteBatch.Draw(lightMap, new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.White); spriteBatch.End(); } - public void DrawLOS(SpriteBatch spriteBatch, Effect effect,bool renderingBackground) - { - if (!LosEnabled || ViewTarget == null) return; - - spriteBatch.Begin(SpriteSortMode.Deferred, renderingBackground ? CustomBlendStates.LOS : CustomBlendStates.Multiplicative, null, null, null, effect); - spriteBatch.Draw(losTexture, Vector2.Zero, Color.White); - spriteBatch.End(); - - if (!renderingBackground) ObstructVision = false; - } - public void ClearLights() { lights.Clear(); @@ -376,16 +368,10 @@ namespace Barotrauma.Lights MultiplyWithAlpha = new BlendState(); MultiplyWithAlpha.ColorDestinationBlend = MultiplyWithAlpha.AlphaDestinationBlend = Blend.One; MultiplyWithAlpha.ColorSourceBlend = MultiplyWithAlpha.AlphaSourceBlend = Blend.DestinationAlpha; - - LOS = new BlendState(); - LOS.ColorSourceBlend = LOS.AlphaSourceBlend = Blend.Zero; - LOS.ColorDestinationBlend = LOS.AlphaDestinationBlend = Blend.InverseSourceColor; - LOS.ColorBlendFunction = LOS.AlphaBlendFunction = BlendFunction.Add; } public static BlendState Multiplicative { get; private set; } public static BlendState WriteToAlpha { get; private set; } public static BlendState MultiplyWithAlpha { get; private set; } - public static BlendState LOS { get; private set; } } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs index b2ab034fc..77a8881ad 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; @@ -17,8 +17,8 @@ namespace Barotrauma.Lights private Color color; private float range; - private Sprite overrideLightTexture; - private Texture2D texture; + public Sprite overrideLightTexture; + public Texture2D texture; public Sprite LightSprite; @@ -140,7 +140,7 @@ namespace Barotrauma.Lights } } - public LightSource(Vector2 position, float range, Color color, Submarine submarine) + public LightSource(Vector2 position, float range, Color color, Submarine submarine, bool addLight=true) { hullsInRange = new List(); @@ -156,7 +156,7 @@ namespace Barotrauma.Lights diffToSub = new Dictionary(); - GameMain.LightManager.AddLight(this); + if (addLight) GameMain.LightManager.AddLight(this); } /*public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform) @@ -322,6 +322,7 @@ namespace Barotrauma.Lights hulls.AddRange(chList.List); } + float bounds = range*2; //find convexhull segments that are close enough and facing towards the light source List visibleSegments = new List(); List points = new List(); @@ -336,6 +337,10 @@ namespace Barotrauma.Lights { points.Add(s.Start); points.Add(s.End); + if (Math.Abs(s.Start.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.Start.WorldPos.X - drawPos.X); + if (Math.Abs(s.Start.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.Start.WorldPos.Y - drawPos.Y); + if (Math.Abs(s.End.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.End.WorldPos.X - drawPos.X); + if (Math.Abs(s.End.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.End.WorldPos.Y - drawPos.Y); } } @@ -344,14 +349,21 @@ namespace Barotrauma.Lights //(might be more effective to calculate if we actually need these extra points) var boundaryCorners = new List { - new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y + range*2)), - new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y - range*2)), - new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y - range*2)), - new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y + range*2)) + new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y + bounds)), + new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y - bounds)), + new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y - bounds)), + new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y + bounds)) }; + //points.Clear(); points.AddRange(boundaryCorners); + //visibleSegments.Clear(); + for (int i=0;i<4;i++) + { + visibleSegments.Add(new Segment(boundaryCorners[i], boundaryCorners[(i + 1) % 4])); + } + var compareCCW = new CompareSegmentPointCW(drawPos); try { @@ -368,14 +380,16 @@ namespace Barotrauma.Lights } List output = new List(); + //List> preOutput = new List>(); //remove points that are very close to each other for (int i = 0; i < points.Count - 1; i++) { - if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 3 && - Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 3) + if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 6 && + Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 6) { points.RemoveAt(i + 1); + i--; } } @@ -385,32 +399,52 @@ namespace Barotrauma.Lights Vector2 dirNormal = new Vector2(-dir.Y, dir.X)*3; //do two slightly offset raycasts to hit the segment itself and whatever's behind it - Vector2 intersection1 = RayCast(drawPos, drawPos + dir * range * 2 - dirNormal, visibleSegments); - Vector2 intersection2 = RayCast(drawPos, drawPos + dir * range * 2 + dirNormal, visibleSegments); + Pair intersection1 = RayCast(drawPos, drawPos + dir * bounds * 2 - dirNormal, visibleSegments); + Pair intersection2 = RayCast(drawPos, drawPos + dir * bounds * 2 + dirNormal, visibleSegments); - //hit almost the same position -> only add one vertex to output - if ((Math.Abs(intersection1.X - intersection2.X) < 5 && - Math.Abs(intersection1.Y - intersection2.Y) < 5)) + if (intersection1.First < 0) return new List(); + if (intersection2.First < 0) return new List(); + Segment seg1 = visibleSegments[intersection1.First]; + Segment seg2 = visibleSegments[intersection2.First]; + + bool isPoint1 = MathUtils.LineToPointDistance(seg1.Start.WorldPos, seg1.End.WorldPos, p.WorldPos) < 5.0f; + bool isPoint2 = MathUtils.LineToPointDistance(seg2.Start.WorldPos, seg2.End.WorldPos, p.WorldPos) < 5.0f; + + //hit at the current segmentpoint -> place the segmentpoint into the list + if (isPoint1 && isPoint2) { - output.Add(intersection1); + output.Add(p.WorldPos); } - else + else if (intersection1.First != intersection2.First) { - output.Add(intersection1); - output.Add(intersection2); + output.Add(isPoint1 ? p.WorldPos : intersection1.Second); + output.Add(isPoint2 ? p.WorldPos : intersection2.Second); } } - + + //remove points that are very close to each other + for (int i = 0; i < output.Count - 1; i++) + { + if (Math.Abs(output[i].X - output[i + 1].X) < 6 && + Math.Abs(output[i].Y - output[i + 1].Y) < 6) + { + output.RemoveAt(i + 1); + i--; + } + } + return output; } - private Vector2 RayCast(Vector2 rayStart, Vector2 rayEnd, List segments) + private Pair RayCast(Vector2 rayStart, Vector2 rayEnd, List segments) { float closestDist = 0.0f; Vector2? closestIntersection = null; - - foreach (Segment s in segments) + int segment = -1; + + for (int i=0;i retVal = new Pair(); + retVal.Second = closestIntersection == null ? rayEnd : (Vector2)closestIntersection; + retVal.First = segment; + return retVal; } private void CalculateLightVertices(List rayCastHits) { - List vertices = new List(); + List vertices = new List(); Vector2 drawPos = position; if (ParentSub != null) drawPos += ParentSub.DrawPosition; @@ -446,16 +484,19 @@ namespace Barotrauma.Lights } // Add a vertex for the center of the mesh - vertices.Add(new VertexPositionTexture(new Vector3(position.X, position.Y, 0), - new Vector2(0.5f, 0.5f) + uvOffset)); + vertices.Add(new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0), + Color.White,new Vector2(0.5f, 0.5f) + uvOffset)); // Add all the other encounter points as vertices // storing their world position as UV coordinates - foreach (Vector2 vertex in rayCastHits) + for (int i = 0; i < rayCastHits.Count; i++) { + Vector2 vertex = rayCastHits[i]; + Vector2 prevVertex = rayCastHits[i > 0 ? i - 1 : rayCastHits.Count - 1]; + Vector2 nextVertex = rayCastHits[i < rayCastHits.Count - 1 ? i + 1 : 0]; Vector2 rawDiff = vertex - drawPos; Vector2 diff = rawDiff; - diff /= range*2.0f; + diff /= range * 2.0f; if (overrideLightTexture != null) { Vector2 originDiff = diff; @@ -467,22 +508,52 @@ namespace Barotrauma.Lights diff += uvOffset; } - vertices.Add(new VertexPositionTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0), - new Vector2(0.5f, 0.5f) + diff)); + Vector2 nDiff1 = vertex - nextVertex; + float tx = nDiff1.X; nDiff1.X = -nDiff1.Y; nDiff1.Y = tx; + nDiff1 /= Math.Max(Math.Abs(nDiff1.X), Math.Abs(nDiff1.Y)); + Vector2 nDiff2 = prevVertex - vertex; + tx = nDiff2.X; nDiff2.X = -nDiff2.Y; nDiff2.Y = tx; + nDiff2 /= Math.Max(Math.Abs(nDiff2.X),Math.Abs(nDiff2.Y)); + Vector2 nDiff = nDiff1 + nDiff2; + nDiff /= Math.Max(Math.Abs(nDiff.X), Math.Abs(nDiff.Y)); + nDiff *= 50.0f; + if (Vector2.DistanceSquared(nDiff, rawDiff) > Vector2.DistanceSquared(-nDiff, rawDiff)) nDiff = -nDiff; + VertexPositionColorTexture fadeVert = new VertexPositionColorTexture(new Vector3(position.X + rawDiff.X + nDiff.X, position.Y + rawDiff.Y + nDiff.Y, 0), + Color.White * 0.0f, new Vector2(0.5f, 0.5f) + diff); + + vertices.Add(new VertexPositionColorTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0), + Color.White, new Vector2(0.5f, 0.5f) + diff)); + vertices.Add(fadeVert); } // Compute the indices to form triangles List indices = new List(); - for (int i = 0; i < rayCastHits.Count - 1; i++) + for (int i = 0; i < rayCastHits.Count-1; i++) { indices.Add(0); - indices.Add((short)((i + 2) % vertices.Count)); - indices.Add((short)((i + 1) % vertices.Count)); + indices.Add((short)((i*2 + 3) % vertices.Count)); + indices.Add((short)((i*2 + 1) % vertices.Count)); + + indices.Add((short)((i*2 + 1) % vertices.Count)); + indices.Add((short)((i*2 + 3) % vertices.Count)); + indices.Add((short)((i*2 + 4) % vertices.Count)); + + indices.Add((short)((i*2 + 2) % vertices.Count)); + indices.Add((short)((i*2 + 1) % vertices.Count)); + indices.Add((short)((i*2 + 4) % vertices.Count)); } indices.Add(0); indices.Add((short)(1)); - indices.Add((short)(vertices.Count - 1)); + indices.Add((short)(vertices.Count - 2)); + + indices.Add((short)(1)); + indices.Add((short)(vertices.Count-1)); + indices.Add((short)(vertices.Count-2)); + + indices.Add((short)(1)); + indices.Add((short)(2)); + indices.Add((short)(vertices.Count-1)); vertexCount = vertices.Count; indexCount = indices.Count; @@ -491,19 +562,19 @@ namespace Barotrauma.Lights //now we just create a buffer for 64 verts and make it larger if needed if (lightVolumeBuffer == null) { - lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None); + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None); lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None); } - else if (vertexCount > lightVolumeBuffer.VertexCount) + else if (vertexCount > lightVolumeBuffer.VertexCount || indexCount > lightVolumeIndexBuffer.IndexCount) { lightVolumeBuffer.Dispose(); lightVolumeIndexBuffer.Dispose(); - lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None); + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None); lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None); } - - lightVolumeBuffer.SetData(vertices.ToArray()); + + lightVolumeBuffer.SetData(vertices.ToArray()); lightVolumeIndexBuffer.SetData(indices.ToArray()); } @@ -562,7 +633,7 @@ namespace Barotrauma.Lights } else { - lightEffect.Texture = LightTexture; + lightEffect.Texture = texture??LightTexture; } lightEffect.CurrentTechnique.Passes[0].Apply(); @@ -571,6 +642,7 @@ namespace Barotrauma.Lights GameMain.Instance.GraphicsDevice.DrawIndexedPrimitives ( + //PrimitiveType.LineList, 0, 0, indexCount / 2 PrimitiveType.TriangleList, 0, 0, indexCount / 3 ); } diff --git a/Barotrauma/BarotraumaClient/Source/Particles/Particle.cs b/Barotrauma/BarotraumaClient/Source/Particles/Particle.cs index 1d11736b0..8272abf7c 100644 --- a/Barotrauma/BarotraumaClient/Source/Particles/Particle.cs +++ b/Barotrauma/BarotraumaClient/Source/Particles/Particle.cs @@ -258,7 +258,7 @@ namespace Barotrauma.Particles } else { - Hull newHull = Hull.FindHull(position); + Hull newHull = Hull.FindHull(position,currentHull); if (newHull != currentHull) { currentHull = newHull; diff --git a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs index eb1e61524..f71becd75 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; @@ -14,7 +14,7 @@ namespace Barotrauma readonly RenderTarget2D renderTargetBackground; readonly RenderTarget2D renderTarget; readonly RenderTarget2D renderTargetWater; - readonly RenderTarget2D renderTargetAir; + readonly RenderTarget2D renderTargetFinal; private Effect damageEffect; @@ -27,9 +27,9 @@ namespace Barotrauma cam.Translate(new Vector2(-10.0f, 50.0f)); renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); - renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); - renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + renderTargetFinal = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight, false, SurfaceFormat.Color, DepthFormat.None); #if LINUX @@ -97,7 +97,6 @@ namespace Barotrauma public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch) { - foreach (Submarine sub in Submarine.Loaded) { sub.UpdateTransform(); @@ -113,197 +112,137 @@ namespace Barotrauma GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition); } - //---------------------------------------------------------------------------------------- - //1. draw the background, characters and the parts of the submarine that are behind them - //---------------------------------------------------------------------------------------- - graphics.SetRenderTarget(renderTargetBackground); - if (Level.Loaded == null) { graphics.Clear(new Color(11, 18, 26, 255)); } else { + //graphics.Clear(new Color(255, 255, 255, 255)); Level.Loaded.DrawBack(graphics, spriteBatch, cam); } - //draw structures that are in water and not part of any sub (e.g. ruins) - spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); - Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine == null); - spriteBatch.End(); - - //draw alpha blended particles that are in water and behind subs + //draw alpha blended particles that are in water and behind subs #if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.None, null, null, cam.Transform); #else - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform); #endif - GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.AlphaBlend); - spriteBatch.End(); - - //draw additive particles that are in water and behind subs - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform); - GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.Additive); - spriteBatch.End(); - - //draw submarine structures that are behind water - spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); - Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine != null); - spriteBatch.End(); + GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.AlphaBlend); + spriteBatch.End(); + //draw additive particles that are in water and behind subs + //TODO: make these draw properly somehow, since they're not rendered into the lightmap anymore + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.None, null, null, cam.Transform); + GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.Additive); + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform); + Submarine.DrawBack(spriteBatch, false, s => s is Structure && ((Structure)s).ResizeVertical && ((Structure)s).ResizeHorizontal); + foreach (Structure s in Structure.WallList) + { + if ((s.ResizeVertical != s.ResizeHorizontal) && s.CastShadow) + { + GUI.DrawRectangle(spriteBatch, new Vector2(s.DrawPosition.X-s.WorldRect.Width/2,-s.DrawPosition.Y-s.WorldRect.Height/2), new Vector2(s.WorldRect.Width, s.WorldRect.Height), Color.Black, true); + } + } + spriteBatch.End(); graphics.SetRenderTarget(renderTarget); - - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Opaque); - spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); - spriteBatch.End(); - - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, - null, null, null, null, - cam.Transform); - - Submarine.DrawBack(spriteBatch, false, s => !(s is Structure)); - + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, null); + spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform); + Submarine.DrawBack(spriteBatch, false, s => !(s is Structure)); + Submarine.DrawBack(spriteBatch, false, s => s is Structure && !(((Structure)s).ResizeVertical && ((Structure)s).ResizeHorizontal)); foreach (Character c in Character.CharacterList) c.Draw(spriteBatch); - spriteBatch.End(); - - //---------------------------------------------------------------------------------------- - //draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater - graphics.SetRenderTarget(renderTargetWater); - - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); - spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), waterColor); - spriteBatch.End(); - - //draw alpha blended particles that are inside a sub -#if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); -#else - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); -#endif - GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.AlphaBlend); - spriteBatch.End(); - - //draw additive particles that are inside a sub - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform); - GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.Additive); - spriteBatch.End(); - - //---------------------------------------------------------------------------------------- - //draw the rendertarget and particles that are only supposed to be drawn in air into renderTargetAir - - graphics.SetRenderTarget(renderTargetAir); - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); - spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); - spriteBatch.End(); - - //draw alpha blended particles that are not in water -#if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); -#else - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); -#endif - GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.AlphaBlend); - spriteBatch.End(); - - //draw additive particles that are not in water - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.DepthRead, null, null, cam.Transform); - GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive); - spriteBatch.End(); - - if (Character.Controlled != null && GameMain.LightManager.LosEnabled) - { - graphics.SetRenderTarget(renderTarget); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Opaque, null, null, null, lightBlur.Effect); - - spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); - - spriteBatch.End(); - - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, SamplerState.LinearWrap, - null, null, null, - cam.Transform); - - Submarine.DrawDamageable(spriteBatch, null, false); - Submarine.DrawFront(spriteBatch, false, s => s is Structure); - - spriteBatch.End(); - - GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, true); - } - - graphics.SetRenderTarget(null); - - //---------------------------------------------------------------------------------------- - //2. pass the renderTarget to the water shader to do the water effect - //---------------------------------------------------------------------------------------- - - Hull.renderer.RenderBack(spriteBatch, renderTargetWater); - - Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length); - Hull.renderer.PositionInBuffer = 0; - foreach (Hull hull in Hull.hullList) - { - hull.Render(graphics, cam); - } - - Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform); - - //---------------------------------------------------------------------------------------- - //3. draw the sections of the map that are on top of the water - //---------------------------------------------------------------------------------------- - - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, SamplerState.LinearWrap, - null, null, null, - cam.Transform); + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, null, null, cam.Transform); Submarine.DrawFront(spriteBatch, false, null); - spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Immediate, - BlendState.NonPremultiplied, SamplerState.LinearWrap, - null, null, - damageEffect, - cam.Transform); + //draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater + graphics.SetRenderTarget(renderTargetWater); - Submarine.DrawDamageable(spriteBatch, damageEffect, false); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); + spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), waterColor); + spriteBatch.End(); - spriteBatch.End(); + //draw alpha blended particles that are inside a sub +#if LINUX + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#else + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#endif + GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.AlphaBlend); + spriteBatch.End(); - GameMain.LightManager.DrawLightMap(spriteBatch, lightBlur.Effect); + graphics.SetRenderTarget(renderTarget); - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, SamplerState.LinearWrap, - null, null, null, - cam.Transform); + //draw alpha blended particles that are not in water +#if LINUX + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#else + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#endif + GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.AlphaBlend); + spriteBatch.End(); - if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch); + //draw additive particles that are not in water + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.None, null, null, cam.Transform); + GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive); + spriteBatch.End(); - foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch, cam); + graphics.SetRenderTarget(renderTargetFinal); + Hull.renderer.RenderBack(spriteBatch, renderTargetWater); - spriteBatch.End(); + Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length); + Hull.renderer.PositionInBuffer = 0; + foreach (Hull hull in Hull.hullList) + { + hull.Render(graphics, cam); + } - if (Character.Controlled != null && GameMain.LightManager.LosEnabled) - { - GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, false); + Hull.renderer.Render(graphics, cam, renderTarget, Cam.ShaderTransform); - spriteBatch.Begin(SpriteSortMode.Immediate, - BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone, null); + spriteBatch.Begin(SpriteSortMode.Immediate, + BlendState.NonPremultiplied, SamplerState.LinearWrap, + null, null, + damageEffect, + cam.Transform); + Submarine.DrawDamageable(spriteBatch, damageEffect, false); + spriteBatch.End(); - float r = Math.Min(CharacterHUD.damageOverlayTimer * 0.5f, 0.5f); - spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), - Color.Lerp(GameMain.LightManager.AmbientLight * 0.5f, Color.Red, r)); + //draw additive particles that are inside a sub + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform); + GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.Additive); + spriteBatch.End(); - spriteBatch.End(); - } + if (GameMain.LightManager.LightingEnabled) + { + spriteBatch.Begin(SpriteSortMode.Deferred, Lights.CustomBlendStates.Multiplicative, null, DepthStencilState.None, null, null, null); + spriteBatch.Draw(GameMain.LightManager.lightMap, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); + spriteBatch.End(); + } + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, null, null, cam.Transform); + foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch, cam); + + if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch); + spriteBatch.End(); + + graphics.SetRenderTarget(null); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, null, null, null); + if (GameMain.LightManager.LosEnabled && Character.Controlled!=null) + { + spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), new Color(10, 24, 30, 255)); + spriteBatch.End(); + Hull.renderer.waterEffect.CurrentTechnique = Hull.renderer.waterEffect.Techniques["LosShader"]; + Hull.renderer.waterEffect.Parameters["xLosTexture"].SetValue(GameMain.LightManager.losTexture); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, null, Hull.renderer.waterEffect, null); + } + spriteBatch.Draw(renderTargetFinal, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); + spriteBatch.End(); } } } diff --git a/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs b/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs index 86bc750d0..6bbaae831 100644 --- a/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs +++ b/Barotrauma/BarotraumaClient/Source/Sprite/Sprite.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.IO; @@ -186,18 +186,23 @@ namespace Barotrauma public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color) { - DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color); + DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color, Vector2.One); } public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color) + { + DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color, Vector2.One); + } + + public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color, Vector2 scale) { //pos.X = (int)pos.X; //pos.Y = (int)pos.Y; //how many times the texture needs to be drawn on the x-axis - int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width); + int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / (sourceRect.Width*scale.X)); //how many times the texture needs to be drawn on the y-axis - int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height); + int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / (sourceRect.Height*scale.Y)); Vector2 position = pos - startOffset; Rectangle drawRect = sourceRect; @@ -211,11 +216,11 @@ namespace Barotrauma if (x == xTiles - 1) { - drawRect.Width -= (int)((position.X + sourceRect.Width) - (pos.X + targetSize.X)); + drawRect.Width -= (int)((position.X + sourceRect.Width*scale.X) - (pos.X + targetSize.X)); } else { - drawRect.Width = sourceRect.Width; + drawRect.Width = (int)(sourceRect.Width*scale.X); } if (position.X < pos.X) @@ -234,11 +239,11 @@ namespace Barotrauma if (y == yTiles - 1) { - drawRect.Height -= (int)((position.Y + sourceRect.Height) - (pos.Y + targetSize.Y)); + drawRect.Height -= (int)((position.Y + sourceRect.Height*scale.Y) - (pos.Y + targetSize.Y)); } else { - drawRect.Height = sourceRect.Height; + drawRect.Height = (int)(sourceRect.Height*scale.Y); } if (position.Y < pos.Y) @@ -252,10 +257,10 @@ namespace Barotrauma spriteBatch.Draw(texture, position, drawRect, color, rotation, Vector2.Zero, 1.0f, effects, depth); - position.Y += sourceRect.Height; + position.Y += sourceRect.Height*scale.Y; } - position.X += sourceRect.Width; + position.X += sourceRect.Width*scale.X; } } diff --git a/Barotrauma/BarotraumaClient/Source/Utils/TextureLoader.cs b/Barotrauma/BarotraumaClient/Source/Utils/TextureLoader.cs index 2e47ee19b..706c11878 100644 --- a/Barotrauma/BarotraumaClient/Source/Utils/TextureLoader.cs +++ b/Barotrauma/BarotraumaClient/Source/Utils/TextureLoader.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Graphics; using System; using System.IO; using Color = Microsoft.Xna.Framework.Color; @@ -44,7 +44,7 @@ namespace Barotrauma try { - using (Stream fileStream = File.OpenRead(path)) + using (Stream fileStream = File.OpenRead(path)) { var texture = Texture2D.FromStream(_graphicsDevice, fileStream); texture = PreMultiplyAlpha(texture); diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs index c92c9138a..c34bdd284 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs @@ -168,7 +168,7 @@ namespace Microsoft.Xna.Framework // |-------|-------|-------|------- // A B G R private uint _packedValue; - + /// /// Constructs an RGBA color from a packed value. /// The value is a 32-bit unsigned integer, with R in the least significant octet. @@ -384,8 +384,8 @@ namespace Microsoft.Xna.Framework this._packedValue = (this._packedValue & 0x00ffffff) | ((uint)value << 24); } } - - /// + + /// /// Compares whether two instances are equal. /// /// instance on the left of the equal sign. @@ -395,13 +395,13 @@ namespace Microsoft.Xna.Framework { return (a._packedValue == b._packedValue); } - - /// + + /// /// Compares whether two instances are not equal. /// /// instance on the left of the not equal sign. /// instance on the right of the not equal sign. - /// true if the instances are not equal; false otherwise. + /// true if the instances are not equal; false otherwise. public static bool operator !=(Color a, Color b) { return (a._packedValue != b._packedValue); @@ -415,7 +415,7 @@ namespace Microsoft.Xna.Framework { return this._packedValue.GetHashCode(); } - + /// /// Compares whether current instance is equal to specified object. /// @@ -444,8 +444,8 @@ namespace Microsoft.Xna.Framework get; private set; } - - /// + + /// /// AliceBlue color (R:240,G:248,B:255,A:255). /// public static Color AliceBlue @@ -466,13 +466,13 @@ namespace Microsoft.Xna.Framework /// /// Aqua color (R:0,G:255,B:255,A:255). /// - public static Color Aqua + public static Color Aqua { get; private set; } - - /// + + /// /// Aquamarine color (R:127,G:255,B:212,A:255). /// public static Color Aquamarine @@ -484,13 +484,13 @@ namespace Microsoft.Xna.Framework /// /// Azure color (R:240,G:255,B:255,A:255). /// - public static Color Azure + public static Color Azure { get; private set; } - - /// + + /// /// Beige color (R:245,G:245,B:220,A:255). /// public static Color Beige @@ -610,13 +610,13 @@ namespace Microsoft.Xna.Framework /// /// Cornsilk color (R:255,G:248,B:220,A:255). /// - public static Color Cornsilk + public static Color Cornsilk { get; private set; } - - /// + + /// /// Crimson color (R:220,G:20,B:60,A:255). /// public static Color Crimson @@ -637,13 +637,13 @@ namespace Microsoft.Xna.Framework /// /// DarkBlue color (R:0,G:0,B:139,A:255). /// - public static Color DarkBlue + public static Color DarkBlue { get; private set; } - - /// + + /// /// DarkCyan color (R:0,G:139,B:139,A:255). /// public static Color DarkCyan @@ -664,13 +664,13 @@ namespace Microsoft.Xna.Framework /// /// DarkGray color (R:169,G:169,B:169,A:255). /// - public static Color DarkGray + public static Color DarkGray { get; private set; } - - /// + + /// /// DarkGreen color (R:0,G:100,B:0,A:255). /// public static Color DarkGreen @@ -733,7 +733,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// DarkSalmon color (R:233,G:150,B:122,A:255). /// public static Color DarkSalmon @@ -850,7 +850,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// Fuchsia color (R:255,G:0,B:255,A:255). /// public static Color Fuchsia @@ -1496,7 +1496,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// SaddleBrown color (R:139,G:69,B:19,A:255). /// public static Color SaddleBrown @@ -1504,7 +1504,7 @@ namespace Microsoft.Xna.Framework get; private set; } - + /// /// Salmon color (R:250,G:128,B:114,A:255). /// @@ -1532,7 +1532,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// SeaShell color (R:255,G:245,B:238,A:255). /// public static Color SeaShell @@ -1541,7 +1541,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// Sienna color (R:160,G:82,B:45,A:255). /// public static Color Sienna @@ -1550,7 +1550,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// Silver color (R:192,G:192,B:192,A:255). /// public static Color Silver @@ -1649,7 +1649,7 @@ namespace Microsoft.Xna.Framework private set; } - /// + /// /// Turquoise color (R:64,G:224,B:208,A:255). /// public static Color Turquoise @@ -1670,12 +1670,12 @@ namespace Microsoft.Xna.Framework /// /// Wheat color (R:245,G:222,B:179,A:255). /// - public static Color Wheat + public static Color Wheat { get; private set; } - + /// /// White color (R:255,G:255,B:255,A:255). /// @@ -1722,7 +1722,7 @@ namespace Microsoft.Xna.Framework /// Interpolated . public static Color Lerp(Color value1, Color value2, Single amount) { - amount = MathHelper.Clamp(amount, 0, 1); + amount = MathHelper.Clamp(amount, 0, 1); return new Color( (int)MathHelper.Lerp(value1.R, value2.R, amount), (int)MathHelper.Lerp(value1.G, value2.G, amount), @@ -1730,24 +1730,24 @@ namespace Microsoft.Xna.Framework (int)MathHelper.Lerp(value1.A, value2.A, amount) ); } - /// + /// /// Multiply by value. /// /// Source . /// Multiplicator. /// Multiplication result. - public static Color Multiply(Color value, float scale) - { - return new Color((int)(value.R * scale), (int)(value.G * scale), (int)(value.B * scale), (int)(value.A * scale)); - } - - /// + public static Color Multiply(Color value, float scale) + { + return new Color((int)(value.R * scale), (int)(value.G * scale), (int)(value.B * scale), (int)(value.A * scale)); + } + + /// /// Multiply by value. /// /// Source . /// Multiplicator. /// Multiplication result. - public static Color operator *(Color value, float scale) + public static Color operator *(Color value, float scale) { return new Color((int)(value.R * scale), (int)(value.G * scale), (int)(value.B * scale), (int)(value.A * scale)); } @@ -1769,7 +1769,7 @@ namespace Microsoft.Xna.Framework { return new Vector4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f); } - + /// /// Gets or sets packed value of this . /// @@ -1800,8 +1800,8 @@ namespace Microsoft.Xna.Framework /// {R:[red] G:[green] B:[blue] A:[alpha]} /// /// representation of this . - public override string ToString () - { + public override string ToString () + { StringBuilder sb = new StringBuilder(25); sb.Append("{R:"); sb.Append(R); @@ -1813,9 +1813,9 @@ namespace Microsoft.Xna.Framework sb.Append(A); sb.Append("}"); return sb.ToString(); - } - - /// + } + + /// /// Translate a non-premultipled alpha to a that contains premultiplied alpha. /// /// A representing color. @@ -1824,8 +1824,8 @@ namespace Microsoft.Xna.Framework { return new Color(vector.X * vector.W, vector.Y * vector.W, vector.Z * vector.W, vector.W); } - - /// + + /// /// Translate a non-premultipled alpha to a that contains premultiplied alpha. /// /// Red component value. @@ -1839,15 +1839,15 @@ namespace Microsoft.Xna.Framework } #region IEquatable Members - - /// + + /// /// Compares whether current instance is equal to specified . /// /// The to compare. /// true if the instances are equal; false otherwise. public bool Equals(Color other) { - return this.PackedValue == other.PackedValue; + return this.PackedValue == other.PackedValue; } #endregion diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs index 10937c51c..71c4ab237 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs @@ -15,7 +15,7 @@ namespace Microsoft.Xna.Framework.Graphics /// /// No options specified. /// - None = 0, + None = 0, /// /// Render the sprite reversed along the X axis. /// diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs index 51529dca0..0c06a42f8 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs @@ -44,15 +44,15 @@ namespace Microsoft.Xna.Framework.Input /// Identifies the state of a keyboard key. /// public enum KeyState - { - /// - /// Key is released. - /// - Up, + { + /// + /// Key is released. + /// + Up, - /// - /// Key is pressed. - /// - Down, - } + /// + /// Key is pressed. + /// + Down, + } } diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs index dd78935b6..0640442e6 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs @@ -9,7 +9,7 @@ namespace Microsoft.Xna.Framework.Input /// /// Holds the state of keystrokes by a keyboard. /// - public struct KeyboardState + public struct KeyboardState { // Used for the common situation where GetPressedKeys will return an empty array static Keys[] empty = new Keys[0]; diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs index 5420cd52a..133c0ac01 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs @@ -6,648 +6,648 @@ namespace Microsoft.Xna.Framework.Input { /// /// Defines the keys on a keyboard. - /// - public enum Keys - { + /// + public enum Keys + { /// /// Reserved. /// - None = 0, + None = 0, /// /// BACKSPACE key. /// - Back = 8, + Back = 8, /// /// TAB key. /// - Tab = 9, + Tab = 9, /// /// ENTER key. /// - Enter = 13, + Enter = 13, /// /// CAPS LOCK key. /// - CapsLock = 20, + CapsLock = 20, /// /// ESC key. /// - Escape = 27, + Escape = 27, /// /// SPACEBAR key. /// - Space = 32, + Space = 32, /// /// PAGE UP key. /// - PageUp = 33, + PageUp = 33, /// /// PAGE DOWN key. /// - PageDown = 34, + PageDown = 34, /// /// END key. /// - End = 35, + End = 35, /// /// HOME key. /// - Home = 36, + Home = 36, /// /// LEFT ARROW key. /// - Left = 37, + Left = 37, /// /// UP ARROW key. /// - Up = 38, + Up = 38, /// /// RIGHT ARROW key. /// - Right = 39, + Right = 39, /// /// DOWN ARROW key. /// - Down = 40, + Down = 40, /// /// SELECT key. /// - Select = 41, + Select = 41, /// /// PRINT key. /// - Print = 42, + Print = 42, /// /// EXECUTE key. /// - Execute = 43, + Execute = 43, /// /// PRINT SCREEN key. /// - PrintScreen = 44, + PrintScreen = 44, /// /// INS key. /// - Insert = 45, + Insert = 45, /// /// DEL key. /// - Delete = 46, + Delete = 46, /// /// HELP key. /// - Help = 47, + Help = 47, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D0 = 48, + D0 = 48, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D1 = 49, + D1 = 49, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D2 = 50, + D2 = 50, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D3 = 51, + D3 = 51, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D4 = 52, + D4 = 52, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D5 = 53, + D5 = 53, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D6 = 54, + D6 = 54, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D7 = 55, + D7 = 55, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D8 = 56, + D8 = 56, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - D9 = 57, + D9 = 57, /// /// A key. /// - A = 65, + A = 65, /// /// B key. /// - B = 66, + B = 66, /// /// C key. /// - C = 67, + C = 67, /// /// D key. /// - D = 68, + D = 68, /// /// E key. /// - E = 69, + E = 69, /// /// F key. /// - F = 70, + F = 70, /// /// G key. /// - G = 71, + G = 71, /// /// H key. /// - H = 72, + H = 72, /// /// I key. /// - I = 73, + I = 73, /// /// J key. /// - J = 74, + J = 74, /// /// K key. /// - K = 75, + K = 75, /// /// L key. /// - L = 76, + L = 76, /// /// M key. /// - M = 77, + M = 77, /// /// N key. /// - N = 78, + N = 78, /// /// O key. /// - O = 79, + O = 79, /// /// P key. /// - P = 80, + P = 80, /// /// Q key. /// - Q = 81, + Q = 81, /// /// R key. /// - R = 82, + R = 82, /// /// S key. /// - S = 83, + S = 83, /// /// T key. /// - T = 84, + T = 84, /// /// U key. /// - U = 85, + U = 85, /// /// V key. /// - V = 86, + V = 86, /// /// W key. /// - W = 87, + W = 87, /// /// X key. /// - X = 88, + X = 88, /// /// Y key. /// - Y = 89, + Y = 89, /// /// Z key. /// - Z = 90, + Z = 90, /// /// Left Windows key. /// - LeftWindows = 91, + LeftWindows = 91, /// /// Right Windows key. /// - RightWindows = 92, + RightWindows = 92, /// /// Applications key. /// - Apps = 93, + Apps = 93, /// /// Computer Sleep key. /// - Sleep = 95, + Sleep = 95, /// /// Numeric keypad 0 key. /// - NumPad0 = 96, + NumPad0 = 96, /// /// Numeric keypad 1 key. /// - NumPad1 = 97, + NumPad1 = 97, /// /// Numeric keypad 2 key. /// - NumPad2 = 98, + NumPad2 = 98, /// /// Numeric keypad 3 key. /// - NumPad3 = 99, + NumPad3 = 99, /// /// Numeric keypad 4 key. /// - NumPad4 = 100, + NumPad4 = 100, /// /// Numeric keypad 5 key. /// - NumPad5 = 101, + NumPad5 = 101, /// /// Numeric keypad 6 key. /// - NumPad6 = 102, + NumPad6 = 102, /// /// Numeric keypad 7 key. /// - NumPad7 = 103, + NumPad7 = 103, /// /// Numeric keypad 8 key. /// - NumPad8 = 104, + NumPad8 = 104, /// /// Numeric keypad 9 key. /// - NumPad9 = 105, + NumPad9 = 105, /// /// Multiply key. /// - Multiply = 106, + Multiply = 106, /// /// Add key. /// - Add = 107, + Add = 107, /// /// Separator key. /// - Separator = 108, + Separator = 108, /// /// Subtract key. /// - Subtract = 109, + Subtract = 109, /// /// Decimal key. /// - Decimal = 110, + Decimal = 110, /// /// Divide key. /// - Divide = 111, + Divide = 111, /// /// F1 key. /// - F1 = 112, + F1 = 112, /// /// F2 key. /// - F2 = 113, + F2 = 113, /// /// F3 key. /// - F3 = 114, + F3 = 114, /// /// F4 key. /// - F4 = 115, + F4 = 115, /// /// F5 key. /// - F5 = 116, + F5 = 116, /// /// F6 key. /// - F6 = 117, + F6 = 117, /// /// F7 key. /// - F7 = 118, + F7 = 118, /// /// F8 key. /// - F8 = 119, + F8 = 119, /// /// F9 key. /// - F9 = 120, + F9 = 120, /// /// F10 key. /// - F10 = 121, + F10 = 121, /// /// F11 key. /// - F11 = 122, + F11 = 122, /// /// F12 key. /// - F12 = 123, + F12 = 123, /// /// F13 key. /// - F13 = 124, + F13 = 124, /// /// F14 key. /// - F14 = 125, + F14 = 125, /// /// F15 key. /// - F15 = 126, + F15 = 126, /// /// F16 key. /// - F16 = 127, + F16 = 127, /// /// F17 key. /// - F17 = 128, + F17 = 128, /// /// F18 key. /// - F18 = 129, + F18 = 129, /// /// F19 key. /// - F19 = 130, + F19 = 130, /// /// F20 key. /// - F20 = 131, + F20 = 131, /// /// F21 key. /// - F21 = 132, + F21 = 132, /// /// F22 key. /// - F22 = 133, + F22 = 133, /// /// F23 key. /// - F23 = 134, + F23 = 134, /// /// F24 key. /// - F24 = 135, + F24 = 135, /// /// NUM LOCK key. /// - NumLock = 144, + NumLock = 144, /// /// SCROLL LOCK key. /// - Scroll = 145, + Scroll = 145, /// /// Left SHIFT key. /// - LeftShift = 160, + LeftShift = 160, /// /// Right SHIFT key. /// - RightShift = 161, + RightShift = 161, /// /// Left CONTROL key. /// - LeftControl = 162, + LeftControl = 162, /// /// Right CONTROL key. /// - RightControl = 163, + RightControl = 163, /// /// Left ALT key. /// - LeftAlt = 164, + LeftAlt = 164, /// /// Right ALT key. /// - RightAlt = 165, + RightAlt = 165, /// /// Browser Back key. /// - BrowserBack = 166, + BrowserBack = 166, /// /// Browser Forward key. /// - BrowserForward = 167, + BrowserForward = 167, /// /// Browser Refresh key. /// - BrowserRefresh = 168, + BrowserRefresh = 168, /// /// Browser Stop key. /// - BrowserStop = 169, + BrowserStop = 169, /// /// Browser Search key. /// - BrowserSearch = 170, + BrowserSearch = 170, /// /// Browser Favorites key. /// - BrowserFavorites = 171, + BrowserFavorites = 171, /// /// Browser Start and Home key. /// - BrowserHome = 172, - /// + BrowserHome = 172, + /// /// Volume Mute key. - /// + /// VolumeMute = 173, /// /// Volume Down key. /// - VolumeDown = 174, + VolumeDown = 174, /// /// Volume Up key. /// - VolumeUp = 175, + VolumeUp = 175, /// /// Next Track key. /// - MediaNextTrack = 176, + MediaNextTrack = 176, /// /// Previous Track key. /// - MediaPreviousTrack = 177, + MediaPreviousTrack = 177, /// /// Stop Media key. /// - MediaStop = 178, + MediaStop = 178, /// /// Play/Pause Media key. /// - MediaPlayPause = 179, + MediaPlayPause = 179, /// /// Start Mail key. /// - LaunchMail = 180, + LaunchMail = 180, /// /// Select Media key. /// - SelectMedia = 181, + SelectMedia = 181, /// /// Start Application 1 key. /// - LaunchApplication1 = 182, + LaunchApplication1 = 182, /// /// Start Application 2 key. /// - LaunchApplication2 = 183, + LaunchApplication2 = 183, /// /// The OEM Semicolon key on a US standard keyboard. /// - OemSemicolon = 186, + OemSemicolon = 186, /// /// For any country/region, the '+' key. /// - OemPlus = 187, + OemPlus = 187, /// /// For any country/region, the ',' key. /// - OemComma = 188, + OemComma = 188, /// /// For any country/region, the '-' key. /// - OemMinus = 189, + OemMinus = 189, /// /// For any country/region, the '.' key. /// - OemPeriod = 190, + OemPeriod = 190, /// /// The OEM question mark key on a US standard keyboard. /// - OemQuestion = 191, + OemQuestion = 191, /// /// The OEM tilde key on a US standard keyboard. /// - OemTilde = 192, + OemTilde = 192, /// /// The OEM open bracket key on a US standard keyboard. /// - OemOpenBrackets = 219, + OemOpenBrackets = 219, /// /// The OEM pipe key on a US standard keyboard. /// - OemPipe = 220, + OemPipe = 220, /// /// The OEM close bracket key on a US standard keyboard. /// - OemCloseBrackets = 221, + OemCloseBrackets = 221, /// /// The OEM singled/double quote key on a US standard keyboard. /// - OemQuotes = 222, + OemQuotes = 222, /// /// Used for miscellaneous characters; it can vary by keyboard. /// - Oem8 = 223, + Oem8 = 223, /// /// The OEM angle bracket or backslash key on the RT 102 key keyboard. /// - OemBackslash = 226, + OemBackslash = 226, /// /// IME PROCESS key. /// - ProcessKey = 229, + ProcessKey = 229, /// /// Attn key. /// - Attn = 246, + Attn = 246, /// /// CrSel key. /// - Crsel = 247, + Crsel = 247, /// /// ExSel key. /// - Exsel = 248, + Exsel = 248, /// /// Erase EOF key. /// - EraseEof = 249, + EraseEof = 249, /// /// Play key. /// - Play = 250, + Play = 250, /// /// Zoom key. /// - Zoom = 251, + Zoom = 251, /// /// PA1 key. /// - Pa1 = 253, + Pa1 = 253, /// /// CLEAR key. /// - OemClear = 254, + OemClear = 254, /// /// Green ChatPad key. /// - ChatPadGreen = 0xCA, + ChatPadGreen = 0xCA, /// /// Orange ChatPad key. /// - ChatPadOrange = 0xCB, + ChatPadOrange = 0xCB, /// /// PAUSE key. /// - Pause = 0x13, + Pause = 0x13, /// /// IME Convert key. /// - ImeConvert = 0x1c, + ImeConvert = 0x1c, /// /// IME NoConvert key. /// - ImeNoConvert = 0x1d, + ImeNoConvert = 0x1d, /// /// Kana key on Japanese keyboards. /// - Kana = 0x15, + Kana = 0x15, /// /// Kanji key on Japanese keyboards. /// - Kanji = 0x19, + Kanji = 0x19, /// /// OEM Auto key. /// - OemAuto = 0xf3, + OemAuto = 0xf3, /// /// OEM Copy key. /// - OemCopy = 0xf2, + OemCopy = 0xf2, /// /// OEM Enlarge Window key. /// - OemEnlW = 0xf4 - } + OemEnlW = 0xf4 + } } diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs index db63d3a77..671017b63 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs @@ -147,7 +147,7 @@ namespace Microsoft.Xna.Framework /// /// instance on the left of the not equal sign. /// instance on the right of the not equal sign. - /// true if the instances are not equal; false otherwise. + /// true if the instances are not equal; false otherwise. public static bool operator !=(Point a, Point b) { return !a.Equals(b); diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs index 78babbab5..395b75ccb 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs @@ -138,12 +138,12 @@ namespace Microsoft.Xna.Framework /// The result of the quaternion addition. public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2) { - Quaternion quaternion; - quaternion.X = quaternion1.X + quaternion2.X; - quaternion.Y = quaternion1.Y + quaternion2.Y; - quaternion.Z = quaternion1.Z + quaternion2.Z; - quaternion.W = quaternion1.W + quaternion2.W; - return quaternion; + Quaternion quaternion; + quaternion.X = quaternion1.X + quaternion2.X; + quaternion.Y = quaternion1.Y + quaternion2.Y; + quaternion.Z = quaternion1.Z + quaternion2.Z; + quaternion.W = quaternion1.W + quaternion2.W; + return quaternion; } /// @@ -154,10 +154,10 @@ namespace Microsoft.Xna.Framework /// The result of the quaternion addition as an output parameter. public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) { - result.X = quaternion1.X + quaternion2.X; - result.Y = quaternion1.Y + quaternion2.Y; - result.Z = quaternion1.Z + quaternion2.Z; - result.W = quaternion1.W + quaternion2.W; + result.X = quaternion1.X + quaternion2.X; + result.Y = quaternion1.Y + quaternion2.Y; + result.Z = quaternion1.Z + quaternion2.Z; + result.W = quaternion1.W + quaternion2.W; } #endregion @@ -171,8 +171,8 @@ namespace Microsoft.Xna.Framework /// The second to concatenate. /// The result of rotation of followed by rotation. public static Quaternion Concatenate(Quaternion value1, Quaternion value2) - { - Quaternion quaternion; + { + Quaternion quaternion; float x1 = value1.X; float y1 = value1.Y; @@ -180,17 +180,17 @@ namespace Microsoft.Xna.Framework float w1 = value1.W; float x2 = value2.X; - float y2 = value2.Y; - float z2 = value2.Z; - float w2 = value2.W; + float y2 = value2.Y; + float z2 = value2.Z; + float w2 = value2.W; - quaternion.X = ((x2 * w1) + (x1 * w2)) + ((y2 * z1) - (z2 * y1)); - quaternion.Y = ((y2 * w1) + (y1 * w2)) + ((z2 * x1) - (x2 * z1)); - quaternion.Z = ((z2 * w1) + (z1 * w2)) + ((x2 * y1) - (y2 * x1)); - quaternion.W = (w2 * w1) - (((x2 * x1) + (y2 * y1)) + (z2 * z1)); + quaternion.X = ((x2 * w1) + (x1 * w2)) + ((y2 * z1) - (z2 * y1)); + quaternion.Y = ((y2 * w1) + (y1 * w2)) + ((z2 * x1) - (x2 * z1)); + quaternion.Z = ((z2 * w1) + (z1 * w2)) + ((x2 * y1) - (y2 * x1)); + quaternion.W = (w2 * w1) - (((x2 * x1) + (y2 * y1)) + (z2 * z1)); - return quaternion; - } + return quaternion; + } /// /// Creates a new that contains concatenation between two quaternion. @@ -199,7 +199,7 @@ namespace Microsoft.Xna.Framework /// The second to concatenate. /// The result of rotation of followed by rotation as an output parameter. public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result) - { + { float x1 = value1.X; float y1 = value1.Y; float z1 = value1.Z; @@ -224,11 +224,11 @@ namespace Microsoft.Xna.Framework /// Transforms this quaternion into its conjugated version. /// public void Conjugate() - { - X = -X; - Y = -Y; - Z = -Z; - } + { + X = -X; + Y = -Y; + Z = -Z; + } /// /// Creates a new that contains conjugated version of the specified quaternion. @@ -236,9 +236,9 @@ namespace Microsoft.Xna.Framework /// The quaternion which values will be used to create the conjugated version. /// The conjugate version of the specified quaternion. public static Quaternion Conjugate(Quaternion value) - { - return new Quaternion(-value.X,-value.Y,-value.Z,value.W); - } + { + return new Quaternion(-value.X,-value.Y,-value.Z,value.W); + } /// /// Creates a new that contains conjugated version of the specified quaternion. @@ -246,12 +246,12 @@ namespace Microsoft.Xna.Framework /// The quaternion which values will be used to create the conjugated version. /// The conjugated version of the specified quaternion as an output parameter. public static void Conjugate(ref Quaternion value, out Quaternion result) - { - result.X = -value.X; - result.Y = -value.Y; - result.Z = -value.Z; - result.W = value.W; - } + { + result.X = -value.X; + result.Y = -value.Y; + result.Z = -value.Z; + result.W = value.W; + } #endregion @@ -265,10 +265,10 @@ namespace Microsoft.Xna.Framework /// The new quaternion builded from axis and angle. public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle) { - float half = angle * 0.5f; - float sin = (float)Math.Sin(half); - float cos = (float)Math.Cos(half); - return new Quaternion(axis.X * sin, axis.Y * sin, axis.Z * sin, cos); + float half = angle * 0.5f; + float sin = (float)Math.Sin(half); + float cos = (float)Math.Cos(half); + return new Quaternion(axis.X * sin, axis.Y * sin, axis.Z * sin, cos); } /// @@ -280,12 +280,12 @@ namespace Microsoft.Xna.Framework public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result) { float half = angle * 0.5f; - float sin = (float)Math.Sin(half); - float cos = (float)Math.Cos(half); - result.X = axis.X * sin; - result.Y = axis.Y * sin; - result.Z = axis.Z * sin; - result.W = cos; + float sin = (float)Math.Sin(half); + float cos = (float)Math.Cos(half); + result.X = axis.X * sin; + result.Y = axis.Y * sin; + result.Z = axis.Z * sin; + result.W = cos; } #endregion @@ -304,51 +304,51 @@ namespace Microsoft.Xna.Framework float half; float scale = matrix.M11 + matrix.M22 + matrix.M33; - if (scale > 0.0f) - { + if (scale > 0.0f) + { sqrt = (float)Math.Sqrt(scale + 1.0f); - quaternion.W = sqrt * 0.5f; + quaternion.W = sqrt * 0.5f; sqrt = 0.5f / sqrt; - quaternion.X = (matrix.M23 - matrix.M32) * sqrt; - quaternion.Y = (matrix.M31 - matrix.M13) * sqrt; - quaternion.Z = (matrix.M12 - matrix.M21) * sqrt; + quaternion.X = (matrix.M23 - matrix.M32) * sqrt; + quaternion.Y = (matrix.M31 - matrix.M13) * sqrt; + quaternion.Z = (matrix.M12 - matrix.M21) * sqrt; - return quaternion; - } - if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) - { + return quaternion; + } + if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) + { sqrt = (float) Math.Sqrt(1.0f + matrix.M11 - matrix.M22 - matrix.M33); half = 0.5f / sqrt; - quaternion.X = 0.5f * sqrt; - quaternion.Y = (matrix.M12 + matrix.M21) * half; - quaternion.Z = (matrix.M13 + matrix.M31) * half; - quaternion.W = (matrix.M23 - matrix.M32) * half; + quaternion.X = 0.5f * sqrt; + quaternion.Y = (matrix.M12 + matrix.M21) * half; + quaternion.Z = (matrix.M13 + matrix.M31) * half; + quaternion.W = (matrix.M23 - matrix.M32) * half; - return quaternion; - } - if (matrix.M22 > matrix.M33) - { + return quaternion; + } + if (matrix.M22 > matrix.M33) + { sqrt = (float) Math.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33); half = 0.5f / sqrt; - quaternion.X = (matrix.M21 + matrix.M12) * half; - quaternion.Y = 0.5f * sqrt; - quaternion.Z = (matrix.M32 + matrix.M23) * half; - quaternion.W = (matrix.M31 - matrix.M13) * half; + quaternion.X = (matrix.M21 + matrix.M12) * half; + quaternion.Y = 0.5f * sqrt; + quaternion.Z = (matrix.M32 + matrix.M23) * half; + quaternion.W = (matrix.M31 - matrix.M13) * half; - return quaternion; - } + return quaternion; + } sqrt = (float) Math.Sqrt(1.0f + matrix.M33 - matrix.M11 - matrix.M22); - half = 0.5f / sqrt; + half = 0.5f / sqrt; - quaternion.X = (matrix.M31 + matrix.M13) * half; - quaternion.Y = (matrix.M32 + matrix.M23) * half; - quaternion.Z = 0.5f * sqrt; - quaternion.W = (matrix.M12 - matrix.M21) * half; - - return quaternion; + quaternion.X = (matrix.M31 + matrix.M13) * half; + quaternion.Y = (matrix.M32 + matrix.M23) * half; + quaternion.Z = 0.5f * sqrt; + quaternion.W = (matrix.M12 - matrix.M21) * half; + + return quaternion; } /// @@ -417,7 +417,7 @@ namespace Microsoft.Xna.Framework /// Roll around the z axis in radians. /// A new quaternion from the concatenated yaw, pitch, and roll angles. public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll) - { + { float halfRoll = roll * 0.5f; float halfPitch = pitch * 0.5f; float halfYaw = yaw * 0.5f; @@ -442,8 +442,8 @@ namespace Microsoft.Xna.Framework /// Pitch around the x axis in radians. /// Roll around the z axis in radians. /// A new quaternion from the concatenated yaw, pitch, and roll angles as an output parameter. - public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result) - { + public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result) + { float halfRoll = roll * 0.5f; float halfPitch = pitch * 0.5f; float halfYaw = yaw * 0.5f; @@ -474,25 +474,25 @@ namespace Microsoft.Xna.Framework public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); - float num5 = 1f / num14; - float num4 = -quaternion2.X * num5; - float num3 = -quaternion2.Y * num5; - float num2 = -quaternion2.Z * num5; - float num = quaternion2.W * num5; - float num13 = (y * num2) - (z * num3); - float num12 = (z * num4) - (x * num2); - float num11 = (x * num3) - (y * num4); - float num10 = ((x * num4) + (y * num3)) + (z * num2); - quaternion.X = ((x * num) + (num4 * w)) + num13; - quaternion.Y = ((y * num) + (num3 * w)) + num12; - quaternion.Z = ((z * num) + (num2 * w)) + num11; - quaternion.W = (w * num) - num10; - return quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num13; + quaternion.Y = ((y * num) + (num3 * w)) + num12; + quaternion.Z = ((z * num) + (num2 * w)) + num11; + quaternion.W = (w * num) - num10; + return quaternion; } /// @@ -504,23 +504,23 @@ namespace Microsoft.Xna.Framework public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) { float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); - float num5 = 1f / num14; - float num4 = -quaternion2.X * num5; - float num3 = -quaternion2.Y * num5; - float num2 = -quaternion2.Z * num5; - float num = quaternion2.W * num5; - float num13 = (y * num2) - (z * num3); - float num12 = (z * num4) - (x * num2); - float num11 = (x * num3) - (y * num4); - float num10 = ((x * num4) + (y * num3)) + (z * num2); - result.X = ((x * num) + (num4 * w)) + num13; - result.Y = ((y * num) + (num3 * w)) + num12; - result.Z = ((z * num) + (num2 * w)) + num11; - result.W = (w * num) - num10; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + result.X = ((x * num) + (num4 * w)) + num13; + result.Y = ((y * num) + (num3 * w)) + num12; + result.Z = ((z * num) + (num2 * w)) + num11; + result.W = (w * num) - num10; } #endregion @@ -572,7 +572,7 @@ namespace Microsoft.Xna.Framework /// true if the instances are equal; false otherwise. public bool Equals(Quaternion other) { - return X == other.X && + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; @@ -599,13 +599,13 @@ namespace Microsoft.Xna.Framework public static Quaternion Inverse(Quaternion quaternion) { Quaternion quaternion2; - float num2 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); - float num = 1f / num2; - quaternion2.X = -quaternion.X * num; - quaternion2.Y = -quaternion.Y * num; - quaternion2.Z = -quaternion.Z * num; - quaternion2.W = quaternion.W * num; - return quaternion2; + float num2 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); + float num = 1f / num2; + quaternion2.X = -quaternion.X * num; + quaternion2.Y = -quaternion.Y * num; + quaternion2.Z = -quaternion.Z * num; + quaternion2.W = quaternion.W * num; + return quaternion2; } /// @@ -616,11 +616,11 @@ namespace Microsoft.Xna.Framework public static void Inverse(ref Quaternion quaternion, out Quaternion result) { float num2 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); - float num = 1f / num2; - result.X = -quaternion.X * num; - result.Y = -quaternion.Y * num; - result.Z = -quaternion.Z * num; - result.W = quaternion.W * num; + float num = 1f / num2; + result.X = -quaternion.X * num; + result.Y = -quaternion.Y * num; + result.Z = -quaternion.Z * num; + result.W = quaternion.W * num; } #endregion @@ -631,7 +631,7 @@ namespace Microsoft.Xna.Framework /// The magnitude of the quaternion components. public float Length() { - return (float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + return (float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); } /// @@ -655,30 +655,30 @@ namespace Microsoft.Xna.Framework public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount) { float num = amount; - float num2 = 1f - num; - Quaternion quaternion = new Quaternion(); - float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); - if (num5 >= 0f) - { - quaternion.X = (num2 * quaternion1.X) + (num * quaternion2.X); - quaternion.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); - quaternion.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); - quaternion.W = (num2 * quaternion1.W) + (num * quaternion2.W); - } - else - { - quaternion.X = (num2 * quaternion1.X) - (num * quaternion2.X); - quaternion.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); - quaternion.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); - quaternion.W = (num2 * quaternion1.W) - (num * quaternion2.W); - } - float num4 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); - float num3 = 1f / ((float) Math.Sqrt((double) num4)); - quaternion.X *= num3; - quaternion.Y *= num3; - quaternion.Z *= num3; - quaternion.W *= num3; - return quaternion; + float num2 = 1f - num; + Quaternion quaternion = new Quaternion(); + float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + if (num5 >= 0f) + { + quaternion.X = (num2 * quaternion1.X) + (num * quaternion2.X); + quaternion.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); + quaternion.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); + quaternion.W = (num2 * quaternion1.W) + (num * quaternion2.W); + } + else + { + quaternion.X = (num2 * quaternion1.X) - (num * quaternion2.X); + quaternion.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); + quaternion.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); + quaternion.W = (num2 * quaternion1.W) - (num * quaternion2.W); + } + float num4 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); + float num3 = 1f / ((float) Math.Sqrt((double) num4)); + quaternion.X *= num3; + quaternion.Y *= num3; + quaternion.Z *= num3; + quaternion.W *= num3; + return quaternion; } /// @@ -691,28 +691,28 @@ namespace Microsoft.Xna.Framework public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) { float num = amount; - float num2 = 1f - num; - float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); - if (num5 >= 0f) - { - result.X = (num2 * quaternion1.X) + (num * quaternion2.X); - result.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); - result.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); - result.W = (num2 * quaternion1.W) + (num * quaternion2.W); - } - else - { - result.X = (num2 * quaternion1.X) - (num * quaternion2.X); - result.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); - result.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); - result.W = (num2 * quaternion1.W) - (num * quaternion2.W); - } - float num4 = (((result.X * result.X) + (result.Y * result.Y)) + (result.Z * result.Z)) + (result.W * result.W); - float num3 = 1f / ((float) Math.Sqrt((double) num4)); - result.X *= num3; - result.Y *= num3; - result.Z *= num3; - result.W *= num3; + float num2 = 1f - num; + float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + if (num5 >= 0f) + { + result.X = (num2 * quaternion1.X) + (num * quaternion2.X); + result.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); + result.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); + result.W = (num2 * quaternion1.W) + (num * quaternion2.W); + } + else + { + result.X = (num2 * quaternion1.X) - (num * quaternion2.X); + result.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); + result.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); + result.W = (num2 * quaternion1.W) - (num * quaternion2.W); + } + float num4 = (((result.X * result.X) + (result.Y * result.Y)) + (result.Z * result.Z)) + (result.W * result.W); + float num3 = 1f / ((float) Math.Sqrt((double) num4)); + result.X *= num3; + result.Y *= num3; + result.Z *= num3; + result.W *= num3; } @@ -730,33 +730,33 @@ namespace Microsoft.Xna.Framework public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount) { float num2; - float num3; - Quaternion quaternion; - float num = amount; - float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); - bool flag = false; - if (num4 < 0f) - { - flag = true; - num4 = -num4; - } - if (num4 > 0.999999f) - { - num3 = 1f - num; - num2 = flag ? -num : num; - } - else - { - float num5 = (float) Math.Acos((double) num4); - float num6 = (float) (1.0 / Math.Sin((double) num5)); - num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; - num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); - } - quaternion.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); - quaternion.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); - quaternion.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); - quaternion.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); - return quaternion; + float num3; + Quaternion quaternion; + float num = amount; + float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + bool flag = false; + if (num4 < 0f) + { + flag = true; + num4 = -num4; + } + if (num4 > 0.999999f) + { + num3 = 1f - num; + num2 = flag ? -num : num; + } + else + { + float num5 = (float) Math.Acos((double) num4); + float num6 = (float) (1.0 / Math.Sin((double) num5)); + num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; + num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); + } + quaternion.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); + quaternion.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); + quaternion.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); + quaternion.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); + return quaternion; } /// @@ -769,31 +769,31 @@ namespace Microsoft.Xna.Framework public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) { float num2; - float num3; - float num = amount; - float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); - bool flag = false; - if (num4 < 0f) - { - flag = true; - num4 = -num4; - } - if (num4 > 0.999999f) - { - num3 = 1f - num; - num2 = flag ? -num : num; - } - else - { - float num5 = (float) Math.Acos((double) num4); - float num6 = (float) (1.0 / Math.Sin((double) num5)); - num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; - num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); - } - result.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); - result.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); - result.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); - result.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); + float num3; + float num = amount; + float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + bool flag = false; + if (num4 < 0f) + { + flag = true; + num4 = -num4; + } + if (num4 > 0.999999f) + { + num3 = 1f - num; + num2 = flag ? -num : num; + } + else + { + float num5 = (float) Math.Acos((double) num4); + float num6 = (float) (1.0 / Math.Sin((double) num5)); + num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; + num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); + } + result.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); + result.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); + result.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); + result.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); } #endregion @@ -809,11 +809,11 @@ namespace Microsoft.Xna.Framework public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - quaternion.X = quaternion1.X - quaternion2.X; - quaternion.Y = quaternion1.Y - quaternion2.Y; - quaternion.Z = quaternion1.Z - quaternion2.Z; - quaternion.W = quaternion1.W - quaternion2.W; - return quaternion; + quaternion.X = quaternion1.X - quaternion2.X; + quaternion.Y = quaternion1.Y - quaternion2.Y; + quaternion.Z = quaternion1.Z - quaternion2.Z; + quaternion.W = quaternion1.W - quaternion2.W; + return quaternion; } /// @@ -825,9 +825,9 @@ namespace Microsoft.Xna.Framework public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) { result.X = quaternion1.X - quaternion2.X; - result.Y = quaternion1.Y - quaternion2.Y; - result.Z = quaternion1.Z - quaternion2.Z; - result.W = quaternion1.W - quaternion2.W; + result.Y = quaternion1.Y - quaternion2.Y; + result.Z = quaternion1.Z - quaternion2.Z; + result.W = quaternion1.W - quaternion2.W; } #endregion @@ -843,23 +843,23 @@ namespace Microsoft.Xna.Framework public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num4 = quaternion2.X; - float num3 = quaternion2.Y; - float num2 = quaternion2.Z; - float num = quaternion2.W; - float num12 = (y * num2) - (z * num3); - float num11 = (z * num4) - (x * num2); - float num10 = (x * num3) - (y * num4); - float num9 = ((x * num4) + (y * num3)) + (z * num2); - quaternion.X = ((x * num) + (num4 * w)) + num12; - quaternion.Y = ((y * num) + (num3 * w)) + num11; - quaternion.Z = ((z * num) + (num2 * w)) + num10; - quaternion.W = (w * num) - num9; - return quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num12; + quaternion.Y = ((y * num) + (num3 * w)) + num11; + quaternion.Z = ((z * num) + (num2 * w)) + num10; + quaternion.W = (w * num) - num9; + return quaternion; } /// @@ -871,11 +871,11 @@ namespace Microsoft.Xna.Framework public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor) { Quaternion quaternion; - quaternion.X = quaternion1.X * scaleFactor; - quaternion.Y = quaternion1.Y * scaleFactor; - quaternion.Z = quaternion1.Z * scaleFactor; - quaternion.W = quaternion1.W * scaleFactor; - return quaternion; + quaternion.X = quaternion1.X * scaleFactor; + quaternion.Y = quaternion1.Y * scaleFactor; + quaternion.Z = quaternion1.Z * scaleFactor; + quaternion.W = quaternion1.W * scaleFactor; + return quaternion; } /// @@ -887,9 +887,9 @@ namespace Microsoft.Xna.Framework public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result) { result.X = quaternion1.X * scaleFactor; - result.Y = quaternion1.Y * scaleFactor; - result.Z = quaternion1.Z * scaleFactor; - result.W = quaternion1.W * scaleFactor; + result.Y = quaternion1.Y * scaleFactor; + result.Z = quaternion1.Z * scaleFactor; + result.W = quaternion1.W * scaleFactor; } /// @@ -901,21 +901,21 @@ namespace Microsoft.Xna.Framework public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) { float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num4 = quaternion2.X; - float num3 = quaternion2.Y; - float num2 = quaternion2.Z; - float num = quaternion2.W; - float num12 = (y * num2) - (z * num3); - float num11 = (z * num4) - (x * num2); - float num10 = (x * num3) - (y * num4); - float num9 = ((x * num4) + (y * num3)) + (z * num2); - result.X = ((x * num) + (num4 * w)) + num12; - result.Y = ((y * num) + (num3 * w)) + num11; - result.Z = ((z * num) + (num2 * w)) + num10; - result.W = (w * num) - num9; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + result.X = ((x * num) + (num4 * w)) + num12; + result.Y = ((y * num) + (num3 * w)) + num11; + result.Z = ((z * num) + (num2 * w)) + num10; + result.W = (w * num) - num9; } #endregion @@ -929,7 +929,7 @@ namespace Microsoft.Xna.Framework /// The result of the quaternion negation. public static Quaternion Negate(Quaternion quaternion) { - return new Quaternion(-quaternion.X, -quaternion.Y, -quaternion.Z, -quaternion.W); + return new Quaternion(-quaternion.X, -quaternion.Y, -quaternion.Z, -quaternion.W); } /// @@ -940,9 +940,9 @@ namespace Microsoft.Xna.Framework public static void Negate(ref Quaternion quaternion, out Quaternion result) { result.X = -quaternion.X; - result.Y = -quaternion.Y; - result.Z = -quaternion.Z; - result.W = -quaternion.W; + result.Y = -quaternion.Y; + result.Z = -quaternion.Z; + result.W = -quaternion.W; } #endregion @@ -954,11 +954,11 @@ namespace Microsoft.Xna.Framework /// public void Normalize() { - float num = 1f / ((float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W))); - X *= num; - Y *= num; - Z *= num; - W *= num; + float num = 1f / ((float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W))); + X *= num; + Y *= num; + Z *= num; + W *= num; } /// @@ -969,12 +969,12 @@ namespace Microsoft.Xna.Framework public static Quaternion Normalize(Quaternion quaternion) { Quaternion result; - float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); + float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); result.X = quaternion.X * num; result.Y = quaternion.Y * num; result.Z = quaternion.Z * num; result.W = quaternion.W * num; - return result; + return result; } /// @@ -984,11 +984,11 @@ namespace Microsoft.Xna.Framework /// The unit length quaternion an output parameter. public static void Normalize(ref Quaternion quaternion, out Quaternion result) { - float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); - result.X = quaternion.X * num; - result.Y = quaternion.Y * num; - result.Z = quaternion.Z * num; - result.W = quaternion.W * num; + float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); + result.X = quaternion.X * num; + result.Y = quaternion.Y * num; + result.Z = quaternion.Z * num; + result.W = quaternion.W * num; } #endregion @@ -1025,11 +1025,11 @@ namespace Microsoft.Xna.Framework public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - quaternion.X = quaternion1.X + quaternion2.X; - quaternion.Y = quaternion1.Y + quaternion2.Y; - quaternion.Z = quaternion1.Z + quaternion2.Z; - quaternion.W = quaternion1.W + quaternion2.W; - return quaternion; + quaternion.X = quaternion1.X + quaternion2.X; + quaternion.Y = quaternion1.Y + quaternion2.Y; + quaternion.Z = quaternion1.Z + quaternion2.Z; + quaternion.W = quaternion1.W + quaternion2.W; + return quaternion; } /// @@ -1041,25 +1041,25 @@ namespace Microsoft.Xna.Framework public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); - float num5 = 1f / num14; - float num4 = -quaternion2.X * num5; - float num3 = -quaternion2.Y * num5; - float num2 = -quaternion2.Z * num5; - float num = quaternion2.W * num5; - float num13 = (y * num2) - (z * num3); - float num12 = (z * num4) - (x * num2); - float num11 = (x * num3) - (y * num4); - float num10 = ((x * num4) + (y * num3)) + (z * num2); - quaternion.X = ((x * num) + (num4 * w)) + num13; - quaternion.Y = ((y * num) + (num3 * w)) + num12; - quaternion.Z = ((z * num) + (num2 * w)) + num11; - quaternion.W = (w * num) - num10; - return quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num13; + quaternion.Y = ((y * num) + (num3 * w)) + num12; + quaternion.Z = ((z * num) + (num2 * w)) + num11; + quaternion.W = (w * num) - num10; + return quaternion; } /// @@ -1078,14 +1078,14 @@ namespace Microsoft.Xna.Framework /// /// instance on the left of the not equal sign. /// instance on the right of the not equal sign. - /// true if the instances are not equal; false otherwise. + /// true if the instances are not equal; false otherwise. public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2) { if (((quaternion1.X == quaternion2.X) && (quaternion1.Y == quaternion2.Y)) && (quaternion1.Z == quaternion2.Z)) - { - return (quaternion1.W != quaternion2.W); - } - return true; + { + return (quaternion1.W != quaternion2.W); + } + return true; } /// @@ -1097,23 +1097,23 @@ namespace Microsoft.Xna.Framework public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - float x = quaternion1.X; - float y = quaternion1.Y; - float z = quaternion1.Z; - float w = quaternion1.W; - float num4 = quaternion2.X; - float num3 = quaternion2.Y; - float num2 = quaternion2.Z; - float num = quaternion2.W; - float num12 = (y * num2) - (z * num3); - float num11 = (z * num4) - (x * num2); - float num10 = (x * num3) - (y * num4); - float num9 = ((x * num4) + (y * num3)) + (z * num2); - quaternion.X = ((x * num) + (num4 * w)) + num12; - quaternion.Y = ((y * num) + (num3 * w)) + num11; - quaternion.Z = ((z * num) + (num2 * w)) + num10; - quaternion.W = (w * num) - num9; - return quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num12; + quaternion.Y = ((y * num) + (num3 * w)) + num11; + quaternion.Z = ((z * num) + (num2 * w)) + num10; + quaternion.W = (w * num) - num9; + return quaternion; } /// @@ -1125,11 +1125,11 @@ namespace Microsoft.Xna.Framework public static Quaternion operator *(Quaternion quaternion1, float scaleFactor) { Quaternion quaternion; - quaternion.X = quaternion1.X * scaleFactor; - quaternion.Y = quaternion1.Y * scaleFactor; - quaternion.Z = quaternion1.Z * scaleFactor; - quaternion.W = quaternion1.W * scaleFactor; - return quaternion; + quaternion.X = quaternion1.X * scaleFactor; + quaternion.Y = quaternion1.Y * scaleFactor; + quaternion.Z = quaternion1.Z * scaleFactor; + quaternion.W = quaternion1.W * scaleFactor; + return quaternion; } /// @@ -1141,11 +1141,11 @@ namespace Microsoft.Xna.Framework public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2) { Quaternion quaternion; - quaternion.X = quaternion1.X - quaternion2.X; - quaternion.Y = quaternion1.Y - quaternion2.Y; - quaternion.Z = quaternion1.Z - quaternion2.Z; - quaternion.W = quaternion1.W - quaternion2.W; - return quaternion; + quaternion.X = quaternion1.X - quaternion2.X; + quaternion.Y = quaternion1.Y - quaternion2.Y; + quaternion.Z = quaternion1.Z - quaternion2.Z; + quaternion.W = quaternion1.W - quaternion2.W; + return quaternion; } @@ -1157,11 +1157,11 @@ namespace Microsoft.Xna.Framework public static Quaternion operator -(Quaternion quaternion) { Quaternion quaternion2; - quaternion2.X = -quaternion.X; - quaternion2.Y = -quaternion.Y; - quaternion2.Z = -quaternion.Z; - quaternion2.W = -quaternion.W; - return quaternion2; + quaternion2.X = -quaternion.X; + quaternion2.Y = -quaternion.Y; + quaternion2.Z = -quaternion.Z; + quaternion2.W = -quaternion.W; + return quaternion2; } #endregion diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs index 57ce68b56..f8a73be11 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs @@ -236,7 +236,7 @@ namespace Microsoft.Xna.Framework /// The x coordinate of the point to check for containment. /// The y coordinate of the point to check for containment. /// true if the provided coordinates lie inside this ; false otherwise. - public bool Contains(int x, int y) + public bool Contains(int x, int y) { return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height))); } @@ -251,7 +251,7 @@ namespace Microsoft.Xna.Framework { return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height))); } - + /// /// Gets whether or not the provided lies within the bounds of this . /// @@ -517,7 +517,7 @@ namespace Microsoft.Xna.Framework result.Width = Math.Max(value1.Right, value2.Right) - result.X; result.Height = Math.Max(value1.Bottom, value2.Bottom) - result.Y; } - + #endregion } } diff --git a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs index 66e64cf5d..cfeb52c3d 100644 --- a/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs +++ b/Barotrauma/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs @@ -1120,7 +1120,7 @@ namespace Microsoft.Xna.Framework /// /// instance on the left of the not equal sign. /// instance on the right of the not equal sign. - /// true if the instances are not equal; false otherwise. + /// true if the instances are not equal; false otherwise. public static bool operator !=(Vector4 value1, Vector4 value2) { return !(value1 == value2); diff --git a/Barotrauma/BarotraumaShared/Content/watershader.fx b/Barotrauma/BarotraumaShared/Content/watershader.fx index 2412c3df6..b2d324b33 100644 --- a/Barotrauma/BarotraumaShared/Content/watershader.fx +++ b/Barotrauma/BarotraumaShared/Content/watershader.fx @@ -48,8 +48,9 @@ float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoor float4 main2(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 { float4 losColor = tex2D(LosSampler, texCoord); + float4 sample = tex2D(TextureSampler, texCoord); - float4 outColor = float4(losColor.x, losColor.y, losColor.z, color.w); + float4 outColor = float4(sample.x, sample.y, sample.z, losColor.x); return outColor; } @@ -69,4 +70,4 @@ technique LosShader { PixelShader = compile ps_4_0_level_9_1 main2(); } -} \ No newline at end of file +} diff --git a/Barotrauma/BarotraumaShared/Content/watershader_opengl.xnb b/Barotrauma/BarotraumaShared/Content/watershader_opengl.xnb old mode 100644 new mode 100755 index cf7be0fbe86e99939c23652d0e315a2284a27860..d200722c621c8036db2393408b097128f75d7e41 GIT binary patch delta 109 zcmcaA@JfI^!p|v%l_6^)dn?~9b_NDtcee-*hRAJ-?i*)Cu`=dQ{>oZ1IgY7$G6%Z^ zqrqfFcGbyj?7~WhItm5F@nr^j6_uLSyj+|>PQJ5&Ub%uTNW2IrK6x*zI6DI?kXLLt IIfMNz0KT>#wEzGB delta 163 zcmaDQa8-ak!p|v%l_7K@dn?~jb_NDtcee-*h5%;%*;zy zC`(N?Q7CgO%Fiot&d0SK3I^~!-p)$(%jaxpRh0V~k7VuQ)G>~8^EUom9> diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index a403ff2ce..56e47e964 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -13,13 +13,15 @@ namespace Barotrauma { public string Text; public Color Color; + public bool IsCommand; public readonly string Time; - public ColoredText(string text, Color color) + public ColoredText(string text, Color color, bool isCommand) { this.Text = text; this.Color = color; + this.IsCommand = isCommand; Time = DateTime.Now.ToString(); } @@ -1028,9 +1030,14 @@ namespace Barotrauma direction = MathHelper.Clamp(direction, -1, 1); - selectedIndex += direction; - if (selectedIndex < 0) selectedIndex = Messages.Count - 1; - selectedIndex = selectedIndex % Messages.Count; + int i = 0; + do + { + selectedIndex += direction; + if (selectedIndex < 0) selectedIndex = Messages.Count - 1; + selectedIndex = selectedIndex % Messages.Count; + if (++i >= Messages.Count) break; + } while (!Messages[selectedIndex].IsCommand); return Messages[selectedIndex].Text; } @@ -1042,7 +1049,7 @@ namespace Barotrauma #if CLIENT activeQuestionText = null; #endif - NewMessage(command, Color.White); + NewMessage(command, Color.White, true); //reset the variable before invoking the delegate because the method may need to activate another question var temp = activeQuestionCallback; activeQuestionCallback = null; @@ -1056,7 +1063,7 @@ namespace Barotrauma if (!splitCommand[0].ToLowerInvariant().Equals("admin")) { - NewMessage(command, Color.White); + NewMessage(command, Color.White, true); } #if !DEBUG && CLIENT @@ -1131,12 +1138,12 @@ namespace Barotrauma return null; } - public static void NewMessage(string msg, Color color) + public static void NewMessage(string msg, Color color, bool isCommand = false) { if (string.IsNullOrEmpty((msg))) return; #if SERVER - Messages.Add(new ColoredText(msg, color)); + Messages.Add(new ColoredText(msg, color, isCommand)); //TODO: REMOVE Console.ForegroundColor = XnaToConsoleColor.Convert(color); @@ -1151,7 +1158,7 @@ namespace Barotrauma #elif CLIENT lock (queuedMessages) { - queuedMessages.Enqueue(new ColoredText(msg, color)); + queuedMessages.Enqueue(new ColoredText(msg, color, isCommand)); } #endif } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 027689244..5af2b007d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1204,7 +1204,7 @@ namespace Barotrauma Color color = Color.Red; if (ic.HasRequiredSkills(character) && ic.HasRequiredItems(character, false)) color = Color.Orange; - texts.Add(new ColoredText(ic.Msg, color)); + texts.Add(new ColoredText(ic.Msg, color, false)); } return texts; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Voronoi.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Voronoi.cs index 8be0768ff..064ffe147 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Voronoi.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Voronoi.cs @@ -1,4 +1,4 @@ -/* +/* * Created by SharpDevelop. * User: Burhan * Date: 17/06/2014 @@ -73,902 +73,902 @@ namespace Voronoi2 /// Description of Voronoi. /// public class Voronoi - { - // ************* Private members ****************** - double borderMinX, borderMaxX, borderMinY, borderMaxY; - int siteidx; - double xmin, xmax, ymin, ymax, deltax, deltay; - int nvertices; - int nedges; - int nsites; - Site[] sites; - Site bottomsite; - int sqrt_nsites; - double minDistanceBetweenSites; - int PQcount; - int PQmin; - int PQhashsize; - Halfedge[] PQhash; - - const int LE = 0; - const int RE = 1; + { + // ************* Private members ****************** + double borderMinX, borderMaxX, borderMinY, borderMaxY; + int siteidx; + double xmin, xmax, ymin, ymax, deltax, deltay; + int nvertices; + int nedges; + int nsites; + Site[] sites; + Site bottomsite; + int sqrt_nsites; + double minDistanceBetweenSites; + int PQcount; + int PQmin; + int PQhashsize; + Halfedge[] PQhash; + + const int LE = 0; + const int RE = 1; - int ELhashsize; - Halfedge[] ELhash; - Halfedge ELleftend, ELrightend; - List allEdges; - - - // ************* Public methods ****************** - // ****************************************** - - // constructor - public Voronoi ( double minDistanceBetweenSites ) - { - siteidx = 0; - sites = null; - - allEdges = null; - this.minDistanceBetweenSites = minDistanceBetweenSites; - } - - /** - * - * @param xValuesIn Array of X values for each site. - * @param yValuesIn Array of Y values for each site. Must be identical length to yValuesIn - * @param minX The minimum X of the bounding box around the voronoi - * @param maxX The maximum X of the bounding box around the voronoi - * @param minY The minimum Y of the bounding box around the voronoi - * @param maxY The maximum Y of the bounding box around the voronoi - * @return - */ - // تستدعى هذه العملية لإنشاء مخطط فورونوي - public List generateVoronoi ( double[] xValuesIn, double[] yValuesIn, double minX, double maxX, double minY, double maxY ) - { - sort(xValuesIn, yValuesIn, xValuesIn.Length); - - // Check bounding box inputs - if mins are bigger than maxes, swap them - double temp = 0; - if ( minX > maxX ) - { - temp = minX; - minX = maxX; - maxX = temp; - } - if ( minY > maxY ) - { - temp = minY; - minY = maxY; - maxY = temp; - } - - borderMinX = minX; - borderMinY = minY; - borderMaxX = maxX; - borderMaxY = maxY; - - siteidx = 0; - voronoi_bd (); - return allEdges; - } - - - /********************************************************* - * Private methods - implementation details - ********************************************************/ - - private void sort ( double[] xValuesIn, double[] yValuesIn, int count ) - { - sites = null; - allEdges = new List(); - - nsites = count; - nvertices = 0; - nedges = 0; - - double sn = (double)nsites + 4; - sqrt_nsites = (int) Math.Sqrt ( sn ); - - // Copy the inputs so we don't modify the originals - double[] xValues = new double[count]; - double[] yValues = new double[count]; - for (int i = 0; i < count; i++) - { - xValues[i] = xValuesIn[i]; - yValues[i] = yValuesIn[i]; - } - sortNode ( xValues, yValues, count ); - } - - private void qsort ( Site[] sites ) - { - List listSites = new List( sites.Length ); - for ( int i = 0; i < sites.Length; i++ ) - { - listSites.Add ( sites[i] ); - } - - listSites.Sort ( new SiteSorterYX () ); - - // Copy back into the array - for (int i=0; i < sites.Length; i++) - { - sites[i] = listSites[i]; - } - } - - private void sortNode ( double[] xValues, double[] yValues, int numPoints ) - { - nsites = numPoints; - sites = new Site[nsites]; - xmin = xValues[0]; - ymin = yValues[0]; - xmax = xValues[0]; - ymax = yValues[0]; - - for ( int i = 0; i < nsites; i++ ) - { - sites[i] = new Site(); - sites[i].coord.setPoint ( xValues[i], yValues[i] ); - sites[i].sitenbr = i; - - if ( xValues[i] < xmin ) - xmin = xValues[i]; - else if ( xValues[i] > xmax ) - xmax = xValues[i]; - - if ( yValues[i] < ymin ) - ymin = yValues[i]; - else if ( yValues[i] > ymax ) - ymax = yValues[i]; - } - - qsort ( sites ); - deltax = xmax - xmin; - deltay = ymax - ymin; - } - - private Site nextone () - { - Site s; - if ( siteidx < nsites ) - { - s = sites[siteidx]; - siteidx++; - return s; - } - return null; - } - - private Edge bisect ( Site s1, Site s2 ) - { - double dx, dy, adx, ady; - Edge newedge; - - newedge = new Edge(); - - newedge.reg[0] = s1; - newedge.reg[1] = s2; - - newedge.ep [0] = null; - newedge.ep[1] = null; - - dx = s2.coord.x - s1.coord.x; - dy = s2.coord.y - s1.coord.y; - - adx = dx > 0 ? dx : -dx; - ady = dy > 0 ? dy : -dy; - newedge.c = (double)(s1.coord.x * dx + s1.coord.y * dy + (dx * dx + dy* dy) * 0.5); - - if ( adx > ady ) - { - newedge.a = 1.0; - newedge.b = dy / dx; - newedge.c /= dx; - } - else - { - newedge.a = dx / dy; - newedge.b = 1.0; - newedge.c /= dy; - } - - newedge.edgenbr = nedges; - nedges++; - - return newedge; - } - - private void makevertex ( Site v ) - { - v.sitenbr = nvertices; - nvertices++; - } - - private bool PQinitialize () - { - PQcount = 0; - PQmin = 0; - PQhashsize = 4 * sqrt_nsites; - PQhash = new Halfedge[ PQhashsize ]; - - for ( int i = 0; i < PQhashsize; i++ ) - { - PQhash [i] = new Halfedge(); - } - return true; - } - - private int PQbucket ( Halfedge he ) - { - int bucket; - - bucket = (int) ((he.ystar - ymin) / deltay * PQhashsize); - if ( bucket < 0 ) - bucket = 0; - if ( bucket >= PQhashsize ) - bucket = PQhashsize - 1; - if ( bucket < PQmin ) - PQmin = bucket; - - return bucket; - } - - // push the HalfEdge into the ordered linked list of vertices - private void PQinsert ( Halfedge he, Site v, double offset ) - { - Halfedge last, next; - - he.vertex = v; - he.ystar = (double)(v.coord.y + offset); - last = PQhash [ PQbucket (he) ]; - - while - ( - (next = last.PQnext) != null - && - (he.ystar > next.ystar || (he.ystar == next.ystar && v.coord.x > next.vertex.coord.x)) - ) - { - last = next; - } - - he.PQnext = last.PQnext; - last.PQnext = he; - PQcount++; - } - - // remove the HalfEdge from the list of vertices - private void PQdelete ( Halfedge he ) - { - Halfedge last; - - if (he.vertex != null) - { - last = PQhash [ PQbucket (he) ]; - while ( last.PQnext != he ) - { - last = last.PQnext; - } - - last.PQnext = he.PQnext; - PQcount--; - he.vertex = null; - } - } - - private bool PQempty () - { - return ( PQcount == 0 ); - } - - private Point PQ_min () - { - Point answer = new Point (); - - while ( PQhash[PQmin].PQnext == null ) - { - PQmin++; - } - - answer.x = PQhash[PQmin].PQnext.vertex.coord.x; - answer.y = PQhash[PQmin].PQnext.ystar; - return answer; - } - - private Halfedge PQextractmin () - { - Halfedge curr; - - curr = PQhash[PQmin].PQnext; - PQhash[PQmin].PQnext = curr.PQnext; - PQcount--; - - return curr; - } - - private Halfedge HEcreate(Edge e, int pm) - { - Halfedge answer = new Halfedge(); - answer.ELedge = e; - answer.ELpm = pm; - answer.PQnext = null; - answer.vertex = null; - - return answer; - } - - private bool ELinitialize() - { - ELhashsize = 2 * sqrt_nsites; - ELhash = new Halfedge[ELhashsize]; - - for (int i = 0; i < ELhashsize; i++) - { - ELhash[i] = null; - } - - ELleftend = HEcreate ( null, 0 ); - ELrightend = HEcreate ( null, 0 ); - ELleftend.ELleft = null; - ELleftend.ELright = ELrightend; - ELrightend.ELleft = ELleftend; - ELrightend.ELright = null; - ELhash[0] = ELleftend; - ELhash[ELhashsize - 1] = ELrightend; - - return true; - } - - private Halfedge ELright( Halfedge he ) - { - return he.ELright; - } - - private Halfedge ELleft( Halfedge he ) - { - return he.ELleft; - } - - private Site leftreg( Halfedge he ) - { - if (he.ELedge == null) - { - return bottomsite; - } - return (he.ELpm == LE ? he.ELedge.reg[LE] : he.ELedge.reg[RE]); - } - - private void ELinsert( Halfedge lb, Halfedge newHe ) - { - newHe.ELleft = lb; - newHe.ELright = lb.ELright; - (lb.ELright).ELleft = newHe; - lb.ELright = newHe; - } - - /* - * This delete routine can't reclaim node, since pointers from hash table - * may be present. - */ - private void ELdelete( Halfedge he ) - { - (he.ELleft).ELright = he.ELright; - (he.ELright).ELleft = he.ELleft; - he.deleted = true; - } - - /* Get entry from hash table, pruning any deleted nodes */ - private Halfedge ELgethash( int b ) - { - Halfedge he; - if (b < 0 || b >= ELhashsize) - return null; - - he = ELhash[b]; - if (he == null || !he.deleted ) - return he; - - /* Hash table points to deleted half edge. Patch as necessary. */ - ELhash[b] = null; - return null; - } - - private Halfedge ELleftbnd( Point p ) - { - int bucket; - Halfedge he; - - /* Use hash table to get close to desired halfedge */ - // use the hash function to find the place in the hash map that this - // HalfEdge should be - bucket = (int) ((p.x - xmin) / deltax * ELhashsize); - - // make sure that the bucket position is within the range of the hash - // array - if ( bucket < 0 ) bucket = 0; - if ( bucket >= ELhashsize ) bucket = ELhashsize - 1; - - he = ELgethash ( bucket ); - - // if the HE isn't found, search backwards and forwards in the hash map - // for the first non-null entry - if ( he == null ) - { - for ( int i = 1; i < ELhashsize; i++ ) - { - if ( (he = ELgethash ( bucket - i ) ) != null ) - break; - if ( (he = ELgethash ( bucket + i ) ) != null ) - break; - } - } - - /* Now search linear list of halfedges for the correct one */ - if ( he == ELleftend || ( he != ELrightend && right_of (he, p) ) ) - { - // keep going right on the list until either the end is reached, or - // you find the 1st edge which the point isn't to the right of - do - { - he = he.ELright; - } - while ( he != ELrightend && right_of(he, p) ); - he = he.ELleft; - } - else - // if the point is to the left of the HalfEdge, then search left for - // the HE just to the left of the point - { - do - { - he = he.ELleft; - } - while ( he != ELleftend && !right_of(he, p) ); - } - - /* Update hash table and reference counts */ - if ( bucket > 0 && bucket < ELhashsize - 1) - { - ELhash[bucket] = he; - } - - return he; - } - - private void pushGraphEdge( Site leftSite, Site rightSite, Vector2 point1, Vector2 point2 ) - { - GraphEdge newEdge = new GraphEdge(point1, point2); - allEdges.Add ( newEdge ); - - newEdge.site1 = leftSite; - newEdge.site2 = rightSite; - } - - private void clip_line( Edge e ) - { - double pxmin, pxmax, pymin, pymax; - Site s1, s2; - - double x1 = e.reg[0].coord.x; - double y1 = e.reg[0].coord.y; - double x2 = e.reg[1].coord.x; - double y2 = e.reg[1].coord.y; - double x = x2- x1; - double y = y2 - y1; - - // if the distance between the two points this line was created from is - // less than the square root of 2 عن جد؟, then ignore it - if ( Math.Sqrt ( (x*x) + (y*y) ) < minDistanceBetweenSites ) - { - return; - } - pxmin = borderMinX; - pymin = borderMinY; - pxmax = borderMaxX; - pymax = borderMaxY; - - if ( e.a == 1.0 && e.b >= 0.0 ) - { - s1 = e.ep[1]; - s2 = e.ep[0]; - } - else - { - s1 = e.ep[0]; - s2 = e.ep[1]; - } - - if ( e.a == 1.0 ) - { - y1 = pymin; - - if ( s1 != null && s1.coord.y > pymin ) - y1 = s1.coord.y; - if ( y1 > pymax ) - y1 = pymax; - x1 = e.c - e.b * y1; - y2 = pymax; - - if ( s2 != null && s2.coord.y < pymax ) - y2 = s2.coord.y; - if ( y2 < pymin ) - y2 = pymin; - x2 = e.c - e.b * y2; - if ( ( (x1 > pxmax) & (x2 > pxmax) ) | ( (x1 < pxmin) & (x2 < pxmin) ) ) - return; - - if ( x1 > pxmax ) - { - x1 = pxmax; - y1 = ( e.c - x1 ) / e.b; - } - if ( x1 < pxmin ) - { - x1 = pxmin; - y1 = ( e.c - x1 ) / e.b; - } - if ( x2 > pxmax ) - { - x2 = pxmax; - y2 = ( e.c - x2 ) / e.b; - } - if ( x2 < pxmin ) - { - x2 = pxmin; - y2 = ( e.c - x2 ) / e.b; - } - - } - else - { - x1 = pxmin; - if ( s1 != null && s1.coord.x > pxmin ) - x1 = s1.coord.x; - if ( x1 > pxmax ) - x1 = pxmax; - y1 = e.c - e.a * x1; - - x2 = pxmax; - if ( s2 != null && s2.coord.x < pxmax ) - x2 = s2.coord.x; - if ( x2 < pxmin ) - x2 = pxmin; - y2 = e.c - e.a * x2; - - if (((y1 > pymax) & (y2 > pymax)) | ((y1 < pymin) & (y2 < pymin))) - return; - - if ( y1 > pymax ) - { - y1 = pymax; - x1 = ( e.c - y1 ) / e.a; - } - if ( y1 < pymin ) - { - y1 = pymin; - x1 = ( e.c - y1 ) / e.a; - } - if ( y2 > pymax ) - { - y2 = pymax; - x2 = ( e.c - y2 ) / e.a; - } - if ( y2 < pymin ) - { - y2 = pymin; - x2 = ( e.c - y2 ) / e.a; - } - } + int ELhashsize; + Halfedge[] ELhash; + Halfedge ELleftend, ELrightend; + List allEdges; + + + // ************* Public methods ****************** + // ****************************************** + + // constructor + public Voronoi ( double minDistanceBetweenSites ) + { + siteidx = 0; + sites = null; + + allEdges = null; + this.minDistanceBetweenSites = minDistanceBetweenSites; + } + + /** + * + * @param xValuesIn Array of X values for each site. + * @param yValuesIn Array of Y values for each site. Must be identical length to yValuesIn + * @param minX The minimum X of the bounding box around the voronoi + * @param maxX The maximum X of the bounding box around the voronoi + * @param minY The minimum Y of the bounding box around the voronoi + * @param maxY The maximum Y of the bounding box around the voronoi + * @return + */ + // تستدعى هذه العملية لإنشاء مخطط فورونوي + public List generateVoronoi ( double[] xValuesIn, double[] yValuesIn, double minX, double maxX, double minY, double maxY ) + { + sort(xValuesIn, yValuesIn, xValuesIn.Length); + + // Check bounding box inputs - if mins are bigger than maxes, swap them + double temp = 0; + if ( minX > maxX ) + { + temp = minX; + minX = maxX; + maxX = temp; + } + if ( minY > maxY ) + { + temp = minY; + minY = maxY; + maxY = temp; + } + + borderMinX = minX; + borderMinY = minY; + borderMaxX = maxX; + borderMaxY = maxY; + + siteidx = 0; + voronoi_bd (); + return allEdges; + } + + + /********************************************************* + * Private methods - implementation details + ********************************************************/ + + private void sort ( double[] xValuesIn, double[] yValuesIn, int count ) + { + sites = null; + allEdges = new List(); + + nsites = count; + nvertices = 0; + nedges = 0; + + double sn = (double)nsites + 4; + sqrt_nsites = (int) Math.Sqrt ( sn ); + + // Copy the inputs so we don't modify the originals + double[] xValues = new double[count]; + double[] yValues = new double[count]; + for (int i = 0; i < count; i++) + { + xValues[i] = xValuesIn[i]; + yValues[i] = yValuesIn[i]; + } + sortNode ( xValues, yValues, count ); + } + + private void qsort ( Site[] sites ) + { + List listSites = new List( sites.Length ); + for ( int i = 0; i < sites.Length; i++ ) + { + listSites.Add ( sites[i] ); + } + + listSites.Sort ( new SiteSorterYX () ); + + // Copy back into the array + for (int i=0; i < sites.Length; i++) + { + sites[i] = listSites[i]; + } + } + + private void sortNode ( double[] xValues, double[] yValues, int numPoints ) + { + nsites = numPoints; + sites = new Site[nsites]; + xmin = xValues[0]; + ymin = yValues[0]; + xmax = xValues[0]; + ymax = yValues[0]; + + for ( int i = 0; i < nsites; i++ ) + { + sites[i] = new Site(); + sites[i].coord.setPoint ( xValues[i], yValues[i] ); + sites[i].sitenbr = i; + + if ( xValues[i] < xmin ) + xmin = xValues[i]; + else if ( xValues[i] > xmax ) + xmax = xValues[i]; + + if ( yValues[i] < ymin ) + ymin = yValues[i]; + else if ( yValues[i] > ymax ) + ymax = yValues[i]; + } + + qsort ( sites ); + deltax = xmax - xmin; + deltay = ymax - ymin; + } + + private Site nextone () + { + Site s; + if ( siteidx < nsites ) + { + s = sites[siteidx]; + siteidx++; + return s; + } + return null; + } + + private Edge bisect ( Site s1, Site s2 ) + { + double dx, dy, adx, ady; + Edge newedge; + + newedge = new Edge(); + + newedge.reg[0] = s1; + newedge.reg[1] = s2; + + newedge.ep [0] = null; + newedge.ep[1] = null; + + dx = s2.coord.x - s1.coord.x; + dy = s2.coord.y - s1.coord.y; + + adx = dx > 0 ? dx : -dx; + ady = dy > 0 ? dy : -dy; + newedge.c = (double)(s1.coord.x * dx + s1.coord.y * dy + (dx * dx + dy* dy) * 0.5); + + if ( adx > ady ) + { + newedge.a = 1.0; + newedge.b = dy / dx; + newedge.c /= dx; + } + else + { + newedge.a = dx / dy; + newedge.b = 1.0; + newedge.c /= dy; + } + + newedge.edgenbr = nedges; + nedges++; + + return newedge; + } + + private void makevertex ( Site v ) + { + v.sitenbr = nvertices; + nvertices++; + } + + private bool PQinitialize () + { + PQcount = 0; + PQmin = 0; + PQhashsize = 4 * sqrt_nsites; + PQhash = new Halfedge[ PQhashsize ]; + + for ( int i = 0; i < PQhashsize; i++ ) + { + PQhash [i] = new Halfedge(); + } + return true; + } + + private int PQbucket ( Halfedge he ) + { + int bucket; + + bucket = (int) ((he.ystar - ymin) / deltay * PQhashsize); + if ( bucket < 0 ) + bucket = 0; + if ( bucket >= PQhashsize ) + bucket = PQhashsize - 1; + if ( bucket < PQmin ) + PQmin = bucket; + + return bucket; + } + + // push the HalfEdge into the ordered linked list of vertices + private void PQinsert ( Halfedge he, Site v, double offset ) + { + Halfedge last, next; + + he.vertex = v; + he.ystar = (double)(v.coord.y + offset); + last = PQhash [ PQbucket (he) ]; + + while + ( + (next = last.PQnext) != null + && + (he.ystar > next.ystar || (he.ystar == next.ystar && v.coord.x > next.vertex.coord.x)) + ) + { + last = next; + } + + he.PQnext = last.PQnext; + last.PQnext = he; + PQcount++; + } + + // remove the HalfEdge from the list of vertices + private void PQdelete ( Halfedge he ) + { + Halfedge last; + + if (he.vertex != null) + { + last = PQhash [ PQbucket (he) ]; + while ( last.PQnext != he ) + { + last = last.PQnext; + } + + last.PQnext = he.PQnext; + PQcount--; + he.vertex = null; + } + } + + private bool PQempty () + { + return ( PQcount == 0 ); + } + + private Point PQ_min () + { + Point answer = new Point (); + + while ( PQhash[PQmin].PQnext == null ) + { + PQmin++; + } + + answer.x = PQhash[PQmin].PQnext.vertex.coord.x; + answer.y = PQhash[PQmin].PQnext.ystar; + return answer; + } + + private Halfedge PQextractmin () + { + Halfedge curr; + + curr = PQhash[PQmin].PQnext; + PQhash[PQmin].PQnext = curr.PQnext; + PQcount--; + + return curr; + } + + private Halfedge HEcreate(Edge e, int pm) + { + Halfedge answer = new Halfedge(); + answer.ELedge = e; + answer.ELpm = pm; + answer.PQnext = null; + answer.vertex = null; + + return answer; + } + + private bool ELinitialize() + { + ELhashsize = 2 * sqrt_nsites; + ELhash = new Halfedge[ELhashsize]; + + for (int i = 0; i < ELhashsize; i++) + { + ELhash[i] = null; + } + + ELleftend = HEcreate ( null, 0 ); + ELrightend = HEcreate ( null, 0 ); + ELleftend.ELleft = null; + ELleftend.ELright = ELrightend; + ELrightend.ELleft = ELleftend; + ELrightend.ELright = null; + ELhash[0] = ELleftend; + ELhash[ELhashsize - 1] = ELrightend; + + return true; + } + + private Halfedge ELright( Halfedge he ) + { + return he.ELright; + } + + private Halfedge ELleft( Halfedge he ) + { + return he.ELleft; + } + + private Site leftreg( Halfedge he ) + { + if (he.ELedge == null) + { + return bottomsite; + } + return (he.ELpm == LE ? he.ELedge.reg[LE] : he.ELedge.reg[RE]); + } + + private void ELinsert( Halfedge lb, Halfedge newHe ) + { + newHe.ELleft = lb; + newHe.ELright = lb.ELright; + (lb.ELright).ELleft = newHe; + lb.ELright = newHe; + } + + /* + * This delete routine can't reclaim node, since pointers from hash table + * may be present. + */ + private void ELdelete( Halfedge he ) + { + (he.ELleft).ELright = he.ELright; + (he.ELright).ELleft = he.ELleft; + he.deleted = true; + } + + /* Get entry from hash table, pruning any deleted nodes */ + private Halfedge ELgethash( int b ) + { + Halfedge he; + if (b < 0 || b >= ELhashsize) + return null; + + he = ELhash[b]; + if (he == null || !he.deleted ) + return he; + + /* Hash table points to deleted half edge. Patch as necessary. */ + ELhash[b] = null; + return null; + } + + private Halfedge ELleftbnd( Point p ) + { + int bucket; + Halfedge he; + + /* Use hash table to get close to desired halfedge */ + // use the hash function to find the place in the hash map that this + // HalfEdge should be + bucket = (int) ((p.x - xmin) / deltax * ELhashsize); + + // make sure that the bucket position is within the range of the hash + // array + if ( bucket < 0 ) bucket = 0; + if ( bucket >= ELhashsize ) bucket = ELhashsize - 1; + + he = ELgethash ( bucket ); + + // if the HE isn't found, search backwards and forwards in the hash map + // for the first non-null entry + if ( he == null ) + { + for ( int i = 1; i < ELhashsize; i++ ) + { + if ( (he = ELgethash ( bucket - i ) ) != null ) + break; + if ( (he = ELgethash ( bucket + i ) ) != null ) + break; + } + } + + /* Now search linear list of halfedges for the correct one */ + if ( he == ELleftend || ( he != ELrightend && right_of (he, p) ) ) + { + // keep going right on the list until either the end is reached, or + // you find the 1st edge which the point isn't to the right of + do + { + he = he.ELright; + } + while ( he != ELrightend && right_of(he, p) ); + he = he.ELleft; + } + else + // if the point is to the left of the HalfEdge, then search left for + // the HE just to the left of the point + { + do + { + he = he.ELleft; + } + while ( he != ELleftend && !right_of(he, p) ); + } + + /* Update hash table and reference counts */ + if ( bucket > 0 && bucket < ELhashsize - 1) + { + ELhash[bucket] = he; + } + + return he; + } + + private void pushGraphEdge( Site leftSite, Site rightSite, Vector2 point1, Vector2 point2 ) + { + GraphEdge newEdge = new GraphEdge(point1, point2); + allEdges.Add ( newEdge ); + + newEdge.site1 = leftSite; + newEdge.site2 = rightSite; + } + + private void clip_line( Edge e ) + { + double pxmin, pxmax, pymin, pymax; + Site s1, s2; + + double x1 = e.reg[0].coord.x; + double y1 = e.reg[0].coord.y; + double x2 = e.reg[1].coord.x; + double y2 = e.reg[1].coord.y; + double x = x2- x1; + double y = y2 - y1; + + // if the distance between the two points this line was created from is + // less than the square root of 2 عن جد؟, then ignore it + if ( Math.Sqrt ( (x*x) + (y*y) ) < minDistanceBetweenSites ) + { + return; + } + pxmin = borderMinX; + pymin = borderMinY; + pxmax = borderMaxX; + pymax = borderMaxY; + + if ( e.a == 1.0 && e.b >= 0.0 ) + { + s1 = e.ep[1]; + s2 = e.ep[0]; + } + else + { + s1 = e.ep[0]; + s2 = e.ep[1]; + } + + if ( e.a == 1.0 ) + { + y1 = pymin; + + if ( s1 != null && s1.coord.y > pymin ) + y1 = s1.coord.y; + if ( y1 > pymax ) + y1 = pymax; + x1 = e.c - e.b * y1; + y2 = pymax; + + if ( s2 != null && s2.coord.y < pymax ) + y2 = s2.coord.y; + if ( y2 < pymin ) + y2 = pymin; + x2 = e.c - e.b * y2; + if ( ( (x1 > pxmax) & (x2 > pxmax) ) | ( (x1 < pxmin) & (x2 < pxmin) ) ) + return; + + if ( x1 > pxmax ) + { + x1 = pxmax; + y1 = ( e.c - x1 ) / e.b; + } + if ( x1 < pxmin ) + { + x1 = pxmin; + y1 = ( e.c - x1 ) / e.b; + } + if ( x2 > pxmax ) + { + x2 = pxmax; + y2 = ( e.c - x2 ) / e.b; + } + if ( x2 < pxmin ) + { + x2 = pxmin; + y2 = ( e.c - x2 ) / e.b; + } + + } + else + { + x1 = pxmin; + if ( s1 != null && s1.coord.x > pxmin ) + x1 = s1.coord.x; + if ( x1 > pxmax ) + x1 = pxmax; + y1 = e.c - e.a * x1; + + x2 = pxmax; + if ( s2 != null && s2.coord.x < pxmax ) + x2 = s2.coord.x; + if ( x2 < pxmin ) + x2 = pxmin; + y2 = e.c - e.a * x2; + + if (((y1 > pymax) & (y2 > pymax)) | ((y1 < pymin) & (y2 < pymin))) + return; + + if ( y1 > pymax ) + { + y1 = pymax; + x1 = ( e.c - y1 ) / e.a; + } + if ( y1 < pymin ) + { + y1 = pymin; + x1 = ( e.c - y1 ) / e.a; + } + if ( y2 > pymax ) + { + y2 = pymax; + x2 = ( e.c - y2 ) / e.a; + } + if ( y2 < pymin ) + { + y2 = pymin; + x2 = ( e.c - y2 ) / e.a; + } + } pushGraphEdge(e.reg[0], e.reg[1], new Vector2((float)x1, (float)y1), new Vector2((float)x2, (float)y2)); - } - - private void endpoint( Edge e, int lr, Site s ) - { - e.ep[lr] = s; - if ( e.ep[RE - lr] == null ) - return; - clip_line ( e ); - } - - /* returns true if p is to right of halfedge e */ - private bool right_of(Halfedge el, Point p) - { - Edge e; - Site topsite; - bool right_of_site; - bool above, fast; - double dxp, dyp, dxs, t1, t2, t3, yl; - - e = el.ELedge; - topsite = e.reg[1]; - - if ( p.x > topsite.coord.x ) - right_of_site = true; - else - right_of_site = false; - - if ( right_of_site && el.ELpm == LE ) - return true; - if (!right_of_site && el.ELpm == RE ) - return false; - - if ( e.a == 1.0 ) - { - dxp = p.x - topsite.coord.x; - dyp = p.y - topsite.coord.y; - fast = false; - - if ( (!right_of_site & (e.b < 0.0)) | (right_of_site & (e.b >= 0.0)) ) - { - above = dyp >= e.b * dxp; - fast = above; - } - else - { - above = p.x + p.y * e.b > e.c; - if ( e.b < 0.0 ) - above = !above; - if ( !above ) - fast = true; - } - if ( !fast ) - { - dxs = topsite.coord.x - ( e.reg[0] ).coord.x; - above = e.b * (dxp * dxp - dyp * dyp) - < dxs * dyp * (1.0 + 2.0 * dxp / dxs + e.b * e.b); - - if ( e.b < 0 ) - above = !above; - } - } - else // e.b == 1.0 - { - yl = e.c - e.a * p.x; - t1 = p.y - yl; - t2 = p.x - topsite.coord.x; - t3 = yl - topsite.coord.y; - above = t1 * t1 > t2 * t2 + t3 * t3; - } - return ( el.ELpm == LE ? above : !above ); - } - - private Site rightreg(Halfedge he) - { - if (he.ELedge == (Edge) null) - // if this halfedge has no edge, return the bottom site (whatever - // that is) - { - return (bottomsite); - } + } + + private void endpoint( Edge e, int lr, Site s ) + { + e.ep[lr] = s; + if ( e.ep[RE - lr] == null ) + return; + clip_line ( e ); + } + + /* returns true if p is to right of halfedge e */ + private bool right_of(Halfedge el, Point p) + { + Edge e; + Site topsite; + bool right_of_site; + bool above, fast; + double dxp, dyp, dxs, t1, t2, t3, yl; + + e = el.ELedge; + topsite = e.reg[1]; + + if ( p.x > topsite.coord.x ) + right_of_site = true; + else + right_of_site = false; + + if ( right_of_site && el.ELpm == LE ) + return true; + if (!right_of_site && el.ELpm == RE ) + return false; + + if ( e.a == 1.0 ) + { + dxp = p.x - topsite.coord.x; + dyp = p.y - topsite.coord.y; + fast = false; + + if ( (!right_of_site & (e.b < 0.0)) | (right_of_site & (e.b >= 0.0)) ) + { + above = dyp >= e.b * dxp; + fast = above; + } + else + { + above = p.x + p.y * e.b > e.c; + if ( e.b < 0.0 ) + above = !above; + if ( !above ) + fast = true; + } + if ( !fast ) + { + dxs = topsite.coord.x - ( e.reg[0] ).coord.x; + above = e.b * (dxp * dxp - dyp * dyp) + < dxs * dyp * (1.0 + 2.0 * dxp / dxs + e.b * e.b); + + if ( e.b < 0 ) + above = !above; + } + } + else // e.b == 1.0 + { + yl = e.c - e.a * p.x; + t1 = p.y - yl; + t2 = p.x - topsite.coord.x; + t3 = yl - topsite.coord.y; + above = t1 * t1 > t2 * t2 + t3 * t3; + } + return ( el.ELpm == LE ? above : !above ); + } + + private Site rightreg(Halfedge he) + { + if (he.ELedge == (Edge) null) + // if this halfedge has no edge, return the bottom site (whatever + // that is) + { + return (bottomsite); + } - // if the ELpm field is zero, return the site 0 that this edge bisects, - // otherwise return site number 1 - return (he.ELpm == LE ? he.ELedge.reg[RE] : he.ELedge.reg[LE]); - } - - private double dist( Site s, Site t ) - { - double dx, dy; - dx = s.coord.x - t.coord.x; - dy = s.coord.y - t.coord.y; - return Math.Sqrt ( dx * dx + dy * dy ); - } - - // create a new site where the HalfEdges el1 and el2 intersect - note that - // the Point in the argument list is not used, don't know why it's there - private Site intersect( Halfedge el1, Halfedge el2 ) - { - Edge e1, e2, e; - Halfedge el; - double d, xint, yint; - bool right_of_site; - Site v; // vertex - - e1 = el1.ELedge; - e2 = el2.ELedge; - - if ( e1 == null || e2 == null ) - return null; - - // if the two edges bisect the same parent, return null - if ( e1.reg[1] == e2.reg[1] ) - return null; - - d = e1.a * e2.b - e1.b * e2.a; - if ( -1.0e-10 < d && d < 1.0e-10 ) - return null; - - xint = ( e1.c * e2.b - e2.c * e1.b ) / d; - yint = ( e2.c * e1.a - e1.c * e2.a ) / d; - - if ( (e1.reg[1].coord.y < e2.reg[1].coord.y) - || (e1.reg[1].coord.y == e2.reg[1].coord.y && e1.reg[1].coord.x < e2.reg[1].coord.x) ) - { - el = el1; - e = e1; - } - else - { - el = el2; - e = e2; - } - - right_of_site = xint >= e.reg[1].coord.x; - if ((right_of_site && el.ELpm == LE) - || (!right_of_site && el.ELpm == RE)) - return null; - - // create a new site at the point of intersection - this is a new vector - // event waiting to happen - v = new Site(); - v.coord.x = xint; - v.coord.y = yint; - return v; - } - - /* - * implicit parameters: nsites, sqrt_nsites, xmin, xmax, ymin, ymax, deltax, - * deltay (can all be estimates). Performance suffers if they are wrong; - * better to make nsites, deltax, and deltay too big than too small. (?) - */ - private bool voronoi_bd() - { - Site newsite, bot, top, temp, p; - Site v; - Point newintstar = null; - int pm; - Halfedge lbnd, rbnd, llbnd, rrbnd, bisector; - Edge e; + // if the ELpm field is zero, return the site 0 that this edge bisects, + // otherwise return site number 1 + return (he.ELpm == LE ? he.ELedge.reg[RE] : he.ELedge.reg[LE]); + } + + private double dist( Site s, Site t ) + { + double dx, dy; + dx = s.coord.x - t.coord.x; + dy = s.coord.y - t.coord.y; + return Math.Sqrt ( dx * dx + dy * dy ); + } + + // create a new site where the HalfEdges el1 and el2 intersect - note that + // the Point in the argument list is not used, don't know why it's there + private Site intersect( Halfedge el1, Halfedge el2 ) + { + Edge e1, e2, e; + Halfedge el; + double d, xint, yint; + bool right_of_site; + Site v; // vertex + + e1 = el1.ELedge; + e2 = el2.ELedge; + + if ( e1 == null || e2 == null ) + return null; + + // if the two edges bisect the same parent, return null + if ( e1.reg[1] == e2.reg[1] ) + return null; + + d = e1.a * e2.b - e1.b * e2.a; + if ( -1.0e-10 < d && d < 1.0e-10 ) + return null; + + xint = ( e1.c * e2.b - e2.c * e1.b ) / d; + yint = ( e2.c * e1.a - e1.c * e2.a ) / d; + + if ( (e1.reg[1].coord.y < e2.reg[1].coord.y) + || (e1.reg[1].coord.y == e2.reg[1].coord.y && e1.reg[1].coord.x < e2.reg[1].coord.x) ) + { + el = el1; + e = e1; + } + else + { + el = el2; + e = e2; + } + + right_of_site = xint >= e.reg[1].coord.x; + if ((right_of_site && el.ELpm == LE) + || (!right_of_site && el.ELpm == RE)) + return null; + + // create a new site at the point of intersection - this is a new vector + // event waiting to happen + v = new Site(); + v.coord.x = xint; + v.coord.y = yint; + return v; + } + + /* + * implicit parameters: nsites, sqrt_nsites, xmin, xmax, ymin, ymax, deltax, + * deltay (can all be estimates). Performance suffers if they are wrong; + * better to make nsites, deltax, and deltay too big than too small. (?) + */ + private bool voronoi_bd() + { + Site newsite, bot, top, temp, p; + Site v; + Point newintstar = null; + int pm; + Halfedge lbnd, rbnd, llbnd, rrbnd, bisector; + Edge e; - PQinitialize(); - ELinitialize(); + PQinitialize(); + ELinitialize(); - bottomsite = nextone(); - newsite = nextone(); - while (true) - { - if (!PQempty()) - { - newintstar = PQ_min(); - } - // if the lowest site has a smaller y value than the lowest vector - // intersection, - // process the site otherwise process the vector intersection + bottomsite = nextone(); + newsite = nextone(); + while (true) + { + if (!PQempty()) + { + newintstar = PQ_min(); + } + // if the lowest site has a smaller y value than the lowest vector + // intersection, + // process the site otherwise process the vector intersection - if (newsite != null && (PQempty() - || newsite.coord.y < newintstar.y - || (newsite.coord.y == newintstar.y - && newsite.coord.x < newintstar.x))) - { - /* new site is smallest -this is a site event */ - // get the first HalfEdge to the LEFT of the new site - lbnd = ELleftbnd((newsite.coord)); - // get the first HalfEdge to the RIGHT of the new site - rbnd = ELright(lbnd); - // if this halfedge has no edge,bot =bottom site (whatever that - // is) - bot = rightreg(lbnd); - // create a new edge that bisects - e = bisect(bot, newsite); + if (newsite != null && (PQempty() + || newsite.coord.y < newintstar.y + || (newsite.coord.y == newintstar.y + && newsite.coord.x < newintstar.x))) + { + /* new site is smallest -this is a site event */ + // get the first HalfEdge to the LEFT of the new site + lbnd = ELleftbnd((newsite.coord)); + // get the first HalfEdge to the RIGHT of the new site + rbnd = ELright(lbnd); + // if this halfedge has no edge,bot =bottom site (whatever that + // is) + bot = rightreg(lbnd); + // create a new edge that bisects + e = bisect(bot, newsite); - // create a new HalfEdge, setting its ELpm field to 0 - bisector = HEcreate(e, LE); - // insert this new bisector edge between the left and right - // vectors in a linked list - ELinsert(lbnd, bisector); + // create a new HalfEdge, setting its ELpm field to 0 + bisector = HEcreate(e, LE); + // insert this new bisector edge between the left and right + // vectors in a linked list + ELinsert(lbnd, bisector); - // if the new bisector intersects with the left edge, - // remove the left edge's vertex, and put in the new one - if ((p = intersect(lbnd, bisector)) != null) - { - PQdelete(lbnd); - PQinsert(lbnd, p, dist(p, newsite)); - } - lbnd = bisector; - // create a new HalfEdge, setting its ELpm field to 1 - bisector = HEcreate(e, RE); - // insert the new HE to the right of the original bisector - // earlier in the IF stmt - ELinsert(lbnd, bisector); + // if the new bisector intersects with the left edge, + // remove the left edge's vertex, and put in the new one + if ((p = intersect(lbnd, bisector)) != null) + { + PQdelete(lbnd); + PQinsert(lbnd, p, dist(p, newsite)); + } + lbnd = bisector; + // create a new HalfEdge, setting its ELpm field to 1 + bisector = HEcreate(e, RE); + // insert the new HE to the right of the original bisector + // earlier in the IF stmt + ELinsert(lbnd, bisector); - // if this new bisector intersects with the new HalfEdge - if ((p = intersect(bisector, rbnd)) != null) - { - // push the HE into the ordered linked list of vertices - PQinsert(bisector, p, dist(p, newsite)); - } - newsite = nextone(); - } else if (!PQempty()) - /* intersection is smallest - this is a vector event */ - { - // pop the HalfEdge with the lowest vector off the ordered list - // of vectors - lbnd = PQextractmin(); - // get the HalfEdge to the left of the above HE - llbnd = ELleft(lbnd); - // get the HalfEdge to the right of the above HE - rbnd = ELright(lbnd); - // get the HalfEdge to the right of the HE to the right of the - // lowest HE - rrbnd = ELright(rbnd); - // get the Site to the left of the left HE which it bisects - bot = leftreg(lbnd); - // get the Site to the right of the right HE which it bisects - top = rightreg(rbnd); + // if this new bisector intersects with the new HalfEdge + if ((p = intersect(bisector, rbnd)) != null) + { + // push the HE into the ordered linked list of vertices + PQinsert(bisector, p, dist(p, newsite)); + } + newsite = nextone(); + } else if (!PQempty()) + /* intersection is smallest - this is a vector event */ + { + // pop the HalfEdge with the lowest vector off the ordered list + // of vectors + lbnd = PQextractmin(); + // get the HalfEdge to the left of the above HE + llbnd = ELleft(lbnd); + // get the HalfEdge to the right of the above HE + rbnd = ELright(lbnd); + // get the HalfEdge to the right of the HE to the right of the + // lowest HE + rrbnd = ELright(rbnd); + // get the Site to the left of the left HE which it bisects + bot = leftreg(lbnd); + // get the Site to the right of the right HE which it bisects + top = rightreg(rbnd); - v = lbnd.vertex; // get the vertex that caused this event - makevertex(v); // set the vertex number - couldn't do this - // earlier since we didn't know when it would be processed - endpoint(lbnd.ELedge, lbnd.ELpm, v); - // set the endpoint of - // the left HalfEdge to be this vector - endpoint(rbnd.ELedge, rbnd.ELpm, v); - // set the endpoint of the right HalfEdge to - // be this vector - ELdelete(lbnd); // mark the lowest HE for - // deletion - can't delete yet because there might be pointers - // to it in Hash Map - PQdelete(rbnd); - // remove all vertex events to do with the right HE - ELdelete(rbnd); // mark the right HE for - // deletion - can't delete yet because there might be pointers - // to it in Hash Map - pm = LE; // set the pm variable to zero + v = lbnd.vertex; // get the vertex that caused this event + makevertex(v); // set the vertex number - couldn't do this + // earlier since we didn't know when it would be processed + endpoint(lbnd.ELedge, lbnd.ELpm, v); + // set the endpoint of + // the left HalfEdge to be this vector + endpoint(rbnd.ELedge, rbnd.ELpm, v); + // set the endpoint of the right HalfEdge to + // be this vector + ELdelete(lbnd); // mark the lowest HE for + // deletion - can't delete yet because there might be pointers + // to it in Hash Map + PQdelete(rbnd); + // remove all vertex events to do with the right HE + ELdelete(rbnd); // mark the right HE for + // deletion - can't delete yet because there might be pointers + // to it in Hash Map + pm = LE; // set the pm variable to zero - if (bot.coord.y > top.coord.y) - // if the site to the left of the event is higher than the - // Site - { // to the right of it, then swap them and set the 'pm' - // variable to 1 - temp = bot; - bot = top; - top = temp; - pm = RE; - } - e = bisect(bot, top); // create an Edge (or line) - // that is between the two Sites. This creates the formula of - // the line, and assigns a line number to it - bisector = HEcreate(e, pm); // create a HE from the Edge 'e', - // and make it point to that edge - // with its ELedge field - ELinsert(llbnd, bisector); // insert the new bisector to the - // right of the left HE - endpoint(e, RE - pm, v); // set one endpoint to the new edge - // to be the vector point 'v'. - // If the site to the left of this bisector is higher than the - // right Site, then this endpoint - // is put in position 0; otherwise in pos 1 + if (bot.coord.y > top.coord.y) + // if the site to the left of the event is higher than the + // Site + { // to the right of it, then swap them and set the 'pm' + // variable to 1 + temp = bot; + bot = top; + top = temp; + pm = RE; + } + e = bisect(bot, top); // create an Edge (or line) + // that is between the two Sites. This creates the formula of + // the line, and assigns a line number to it + bisector = HEcreate(e, pm); // create a HE from the Edge 'e', + // and make it point to that edge + // with its ELedge field + ELinsert(llbnd, bisector); // insert the new bisector to the + // right of the left HE + endpoint(e, RE - pm, v); // set one endpoint to the new edge + // to be the vector point 'v'. + // If the site to the left of this bisector is higher than the + // right Site, then this endpoint + // is put in position 0; otherwise in pos 1 - // if left HE and the new bisector intersect, then delete - // the left HE, and reinsert it - if ((p = intersect(llbnd, bisector)) != null) - { - PQdelete(llbnd); - PQinsert(llbnd, p, dist(p, bot)); - } + // if left HE and the new bisector intersect, then delete + // the left HE, and reinsert it + if ((p = intersect(llbnd, bisector)) != null) + { + PQdelete(llbnd); + PQinsert(llbnd, p, dist(p, bot)); + } - // if right HE and the new bisector intersect, then - // reinsert it - if ((p = intersect(bisector, rrbnd)) != null) - { - PQinsert(bisector, p, dist(p, bot)); - } - } else - { - break; - } - } + // if right HE and the new bisector intersect, then + // reinsert it + if ((p = intersect(bisector, rrbnd)) != null) + { + PQinsert(bisector, p, dist(p, bot)); + } + } else + { + break; + } + } - for (lbnd = ELright(ELleftend); lbnd != ELrightend; lbnd = ELright(lbnd)) - { - e = lbnd.ELedge; - clip_line(e); - } + for (lbnd = ELright(ELleftend); lbnd != ELrightend; lbnd = ELright(lbnd)) + { + e = lbnd.ELedge; + clip_line(e); + } - return true; - } + return true; + } public List MakeVoronoiGraph(List sites, float minX, float minY, float maxX, float maxY) { @@ -994,5 +994,5 @@ namespace Voronoi2 return generateVoronoi(xVal, yVal, 0, width, 0, height); } - } // Voronoi Class End + } // Voronoi Class End } // namespace Voronoi2 End \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs index a8e039f9b..22641dfb4 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs @@ -1,4 +1,4 @@ -/* +/* * Created by SharpDevelop. * User: Burhan * Date: 17/06/2014 @@ -8,31 +8,31 @@ */ /* - Copyright 2011 James Humphreys. All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY James Humphreys ``AS IS\" AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - The views and conclusions contained in the software and documentation are those of the - authors and should not be interpreted as representing official policies, either expressed - or implied, of James Humphreys. + Copyright 2011 James Humphreys. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY James Humphreys ``AS IS\" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + The views and conclusions contained in the software and documentation are those of the + authors and should not be interpreted as representing official policies, either expressed + or implied, of James Humphreys. */ /* @@ -58,63 +58,63 @@ using System.Collections.Generic; namespace Voronoi2 { public class Point - { - public double x, y; - - public void setPoint ( double x, double y ) - { - this.x = x; - this.y = y; - } - } - - // use for sites and vertecies - public class Site - { - public Point coord; - public int sitenbr; + { + public double x, y; + + public void setPoint ( double x, double y ) + { + this.x = x; + this.y = y; + } + } + + // use for sites and vertecies + public class Site + { + public Point coord; + public int sitenbr; public void SetPoint(Vector2 point) { coord.setPoint(point.X, point.Y); } - - public Site () - { - coord = new Point(); - } - } - - public class Edge - { - public double a = 0, b = 0, c = 0; - public Site[] ep; - public Site[] reg; - public int edgenbr; - - public Edge () - { - ep = new Site[2]; - reg = new Site[2]; - } - } - - - public class Halfedge - { - public Halfedge ELleft, ELright; - public Edge ELedge; - public bool deleted; - public int ELpm; - public Site vertex; - public double ystar; - public Halfedge PQnext; - - public Halfedge () - { - PQnext = null; - } - } + + public Site () + { + coord = new Point(); + } + } + + public class Edge + { + public double a = 0, b = 0, c = 0; + public Site[] ep; + public Site[] reg; + public int edgenbr; + + public Edge () + { + ep = new Site[2]; + reg = new Site[2]; + } + } + + + public class Halfedge + { + public Halfedge ELleft, ELright; + public Edge ELedge; + public bool deleted; + public int ELpm; + public Site vertex; + public double ystar; + public Halfedge PQnext; + + public Halfedge () + { + PQnext = null; + } + } public enum CellType { @@ -187,11 +187,11 @@ namespace Voronoi2 return true; } } - - public class GraphEdge - { + + public class GraphEdge + { public Vector2 point1, point2; - public Site site1, site2; + public Site site1, site2; public VoronoiCell cell1, cell2; public bool isSolid; @@ -239,20 +239,20 @@ namespace Voronoi2 return normal; } - } - - // للترتيب - public class SiteSorterYX : IComparer - { - public int Compare ( Site p1, Site p2 ) - { - Point s1 = p1.coord; - Point s2 = p2.coord; - if ( s1.y < s2.y ) return -1; - if ( s1.y > s2.y ) return 1; - if ( s1.x < s2.x ) return -1; - if ( s1.x > s2.x ) return 1; - return 0; - } - } + } + + // للترتيب + public class SiteSorterYX : IComparer + { + public int Compare ( Site p1, Site p2 ) + { + Point s1 = p1.coord; + Point s2 = p2.coord; + if ( s1.y < s2.y ) return -1; + if ( s1.y > s2.y ) return 1; + if ( s1.x < s2.x ) return -1; + if ( s1.x > s2.x ) return 1; + return 0; + } + } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index f8daabce2..5f620dd21 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -89,11 +89,11 @@ namespace Barotrauma get { return false; } } - protected bool ResizeHorizontal + public bool ResizeHorizontal { get { return prefab != null && prefab.ResizeHorizontal; } } - protected bool ResizeVertical + public bool ResizeVertical { get { return prefab != null && prefab.ResizeVertical; } } diff --git a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs index 93d14d3f2..4b8df2fa1 100644 --- a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs +++ b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Input; namespace Barotrauma { @@ -94,9 +94,9 @@ namespace Barotrauma } } - class Key - { - private bool hit, hitQueue; + class Key + { + private bool hit, hitQueue; private bool held, heldQueue; @@ -106,23 +106,23 @@ namespace Barotrauma //{ // get { return canBeHeld; } //} - - public Key(KeyOrMouse binding) - { + + public Key(KeyOrMouse binding) + { this.binding = binding; - } + } - public bool Hit - { - get - { - return hit; - } - set - { - hit = value; - } - } + public bool Hit + { + get + { + return hit; + } + set + { + hit = value; + } + } public bool Held { @@ -141,14 +141,14 @@ namespace Barotrauma get { return binding; } } - public void SetState() - { - hit = binding.IsHit(); - if (hit) hitQueue = true; + public void SetState() + { + hit = binding.IsHit(); + if (hit) hitQueue = true; held = binding.IsDown(); if (held) heldQueue = true; - } + } public void SetState(bool hit, bool held) { @@ -156,12 +156,12 @@ namespace Barotrauma if (held) heldQueue = true; } - public bool DequeueHit() - { - bool value = hitQueue; - hitQueue = false; - return value; - } + public bool DequeueHit() + { + bool value = hitQueue; + hitQueue = false; + return value; + } public bool DequeueHeld() { @@ -187,11 +187,11 @@ namespace Barotrauma held = false; } - public void ResetHit() - { - hit = false; - //stateQueue = false; - } + public void ResetHit() + { + hit = false; + //stateQueue = false; + } public void ResetHeld() @@ -199,5 +199,5 @@ namespace Barotrauma held = false; //stateQueue = false; } - } + } }