diff --git a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs index 0ea3058..6b4a1fb 100644 --- a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs @@ -10,12 +10,15 @@ namespace RecrownedAthenaeum.ContentReaders { class NinePatchDataReader : ContentTypeReader { + public static GraphicsDevice graphicsDevice; + protected override NinePatch Read(ContentReader input, NinePatch existingInstance) { + if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice; Texture2D texture; using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32()))) { - texture = Texture2D.FromStream(Configuration.GraphicsDeviceManager.GraphicsDevice, stream); + texture = Texture2D.FromStream(graphicsDevice, stream); } NinePatchData ninePatchData = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32()))); NinePatch ninePatch = new NinePatch(texture, ninePatchData.left, ninePatchData.right, ninePatchData.bottom, ninePatchData.top); diff --git a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs index 79d57b5..19e2d28 100644 --- a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using RecrownedAthenaeum.Data; @@ -10,13 +11,16 @@ namespace RecrownedAthenaeum.ContentReaders { class TextureAtlasDataReader : ContentTypeReader { + public static GraphicsDevice graphicsDevice; + protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance) { + if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice; TextureAtlasData atlasData; Texture2D atlasTexture; using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32()))) { - atlasTexture = Texture2D.FromStream(Configuration.GraphicsDeviceManager.GraphicsDevice, stream); + atlasTexture = Texture2D.FromStream(graphicsDevice, stream); } string serialized = Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32())); atlasData = JsonConvert.DeserializeObject(serialized); diff --git a/RecrownedAthenaeum/RecrownedAthenaeum.csproj b/RecrownedAthenaeum/RecrownedAthenaeum.csproj index 9f64889..87b1f4a 100644 --- a/RecrownedAthenaeum/RecrownedAthenaeum.csproj +++ b/RecrownedAthenaeum/RecrownedAthenaeum.csproj @@ -51,8 +51,8 @@ - - + + diff --git a/RecrownedAthenaeum/Render/PrimitiveBatch.cs b/RecrownedAthenaeum/Render/PrimitiveBatch.cs index c9f4ed5..eece95e 100644 --- a/RecrownedAthenaeum/Render/PrimitiveBatch.cs +++ b/RecrownedAthenaeum/Render/PrimitiveBatch.cs @@ -51,7 +51,6 @@ namespace RecrownedAthenaeum.Render if (began) throw new InvalidOperationException("Begin is being called twice before being ended."); if (disposed) throw new ObjectDisposedException(this.GetType().Name); this.primitiveType = primitiveType; - verticesPerPrimitive = 0; switch (primitiveType) { case PrimitiveType.LineList: verticesPerPrimitive = 2; break; diff --git a/RecrownedAthenaeum/Render/RectangleRenderer.cs b/RecrownedAthenaeum/Render/RectangleRenderer.cs index 716f021..9e14ea9 100644 --- a/RecrownedAthenaeum/Render/RectangleRenderer.cs +++ b/RecrownedAthenaeum/Render/RectangleRenderer.cs @@ -79,7 +79,7 @@ namespace RecrownedAthenaeum.Render { primitiveBatch.primitiveCount = filled ? 3 : 4; Vector2[] corners = new Vector2[4]; - corners[1] = new Vector2 (width, 0); + corners[1] = new Vector2(width, 0); corners[2] = new Vector2(width, height); corners[3] = new Vector2(0, height); @@ -89,16 +89,22 @@ namespace RecrownedAthenaeum.Render for (int i = 0; i < corners.Length; i++) { corners[i] = Vector2.Transform(corners[i], rotMat); - corners[i].X += x; - corners[i].Y += y; } } + for (int i = 0; i < corners.Length; i++) + { + corners[i].X += x; + corners[i].Y += y; + } + primitiveBatch.AddVertex(corners[0], color); primitiveBatch.AddVertex(corners[1], color); primitiveBatch.AddVertex(corners[2], color); primitiveBatch.AddVertex(corners[3], color); primitiveBatch.AddVertex(corners[0], color); + + primitiveBatch.Flush(); } } } diff --git a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs index 37cad41..a4c9d80 100644 --- a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs +++ b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs @@ -129,13 +129,13 @@ namespace RecrownedAthenaeum.ScreenSystem { graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget); graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor); - spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.TransformationMatrix); + spriteBatch.Begin(effect: camera.BasicEffect); previousScreen.Draw(spriteBatch); spriteBatch.End(); graphics.GraphicsDevice.SetRenderTarget(null); Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget); } - spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.TransformationMatrix); + spriteBatch.Begin(effect: camera.BasicEffect); Screen.Draw(spriteBatch); spriteBatch.End(); } diff --git a/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs b/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs index d46ee47..e422dac 100644 --- a/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs +++ b/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs @@ -48,7 +48,7 @@ namespace RecrownedAthenaeum.UI.Modular if (scissorBounds != null) { batch.End(); - batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer, null, camera?.TransformationMatrix); + batch.Begin(effect: camera?.BasicEffect); scissorBounds.Width = bounds.Width; scissorBounds.Height = bounds.Height; scissorBounds.X = bounds.X; @@ -72,7 +72,7 @@ namespace RecrownedAthenaeum.UI.Modular { batch.GraphicsDevice.ScissorRectangle = scissorBounds; batch.End(); - batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera?.TransformationMatrix); + batch.Begin(effect: camera?.BasicEffect); } } diff --git a/RecrownedAthenaeum/Camera/Camera2D.cs b/RecrownedAthenaeum/View/Camera2D.cs similarity index 97% rename from RecrownedAthenaeum/Camera/Camera2D.cs rename to RecrownedAthenaeum/View/Camera2D.cs index accdf24..94fa626 100644 --- a/RecrownedAthenaeum/Camera/Camera2D.cs +++ b/RecrownedAthenaeum/View/Camera2D.cs @@ -28,6 +28,7 @@ namespace RecrownedAthenaeum.Camera { projectionMatrix = Matrix.CreateOrthographic(this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, 1); CenterPosition = new Vector2(0, 0); + upDirection = Vector3.Down; Apply(); } @@ -37,6 +38,7 @@ namespace RecrownedAthenaeum.Camera /// public override void Apply() { + position.Z = 0; lookAt = new Vector3(Position, 1f); base.Apply(); } @@ -64,9 +66,7 @@ namespace RecrownedAthenaeum.Camera /// Magnitude of how much to move per axis. public void MoveCamera(Vector2 move) { - Console.WriteLine(move); Position += move; - Console.WriteLine(Position); } } } diff --git a/RecrownedAthenaeum/Camera/Camera3D.cs b/RecrownedAthenaeum/View/Camera3D.cs similarity index 83% rename from RecrownedAthenaeum/Camera/Camera3D.cs rename to RecrownedAthenaeum/View/Camera3D.cs index dc6a2eb..7e4d312 100644 --- a/RecrownedAthenaeum/Camera/Camera3D.cs +++ b/RecrownedAthenaeum/View/Camera3D.cs @@ -53,20 +53,27 @@ namespace RecrownedAthenaeum.Camera /// protected GraphicsDevice graphicsDevice; + /// + /// The basic effect that contains the transformations. + /// + public BasicEffect BasicEffect { get; private set; } + /// /// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes. /// /// The graphics device to use. Will use graphics device from 's graphics device manager if this is null which it is by default. public Camera3D(GraphicsDevice graphicsDevice = null) { - this.graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice); - + graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice); + this.graphicsDevice = graphicsDevice; worldMatrix = Matrix.Identity; lookAt = Vector3.Forward; upDirection = Vector3.Up; - GraphicsDevice gDevice = this.graphicsDevice; projectionMatrix = Matrix.Identity; + + BasicEffect = new BasicEffect(graphicsDevice); + BasicEffect.TextureEnabled = true; Apply(); } @@ -77,6 +84,10 @@ namespace RecrownedAthenaeum.Camera { ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection); TransformationMatrix = projectionMatrix * ViewMatrix * worldMatrix; + + BasicEffect.World = worldMatrix; + BasicEffect.View = ViewMatrix; + BasicEffect.Projection = projectionMatrix; } ///