Added setup system. Changed reader and writer for texture atlas and nine patch to have image and serialized data be in same file. Some refactors occurred as well.
This commit is contained in:
@@ -20,19 +20,20 @@ namespace RecrownedAthenaeum.Render
|
||||
BasicEffect basicEffect;
|
||||
PrimitiveType primitiveType;
|
||||
int verticesPerPrimitive;
|
||||
GraphicsDevice graphicsDevice;
|
||||
GraphicsDevice graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice;
|
||||
bool began;
|
||||
bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a batch used to draw primitives.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">The current graphics device being used.</param>
|
||||
/// <param name="camera">The current camera being used.</param>
|
||||
/// <param name="graphicsDevice">The graphics device used to draw the primitives. Will be using <see cref="Setup"/>'s graphics device from graphics device manager if null. Default is null.</param>
|
||||
/// <param name="verticesPerBatch">The amount of vertices every batch can hold before flushing. Default is 450. Should be changed to be the most optimal number if possible to prevent unnecessary resizing. Especially if using strip primitive types.</param>
|
||||
public PrimitiveBatch(GraphicsDevice graphicsDevice, Camera2D camera, int verticesPerBatch = 500)
|
||||
public PrimitiveBatch(Camera2D camera, GraphicsDevice graphicsDevice = null, int verticesPerBatch = 500)
|
||||
{
|
||||
this.graphicsDevice = graphicsDevice ?? throw new ArgumentNullException("Graphics device can't be null.");
|
||||
if (graphicsDevice != null) this.graphicsDevice = graphicsDevice;
|
||||
if (this.graphicsDevice == null) throw new ArgumentNullException("Graphics device can't be null in setup and argument. One must not be null for use.");
|
||||
basicEffect = new BasicEffect(graphicsDevice);
|
||||
basicEffect.VertexColorEnabled = true;
|
||||
basicEffect.View = camera.Matrix;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.Render
|
||||
@@ -8,10 +7,10 @@ namespace RecrownedAthenaeum.Render
|
||||
/// <summary>
|
||||
/// Renders rectangles using the <see cref="PrimitiveBatch"/>.
|
||||
/// </summary>
|
||||
public class RectangleRenderer : IDisposable
|
||||
public class RectangleRenderer
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="PrimitiveBatch"/> used.
|
||||
/// The <see cref="PrimitiveBatch"/> used. Needs to be disposed.
|
||||
/// </summary>
|
||||
public readonly PrimitiveBatch primitiveBatch;
|
||||
private bool disposed;
|
||||
@@ -27,16 +26,6 @@ namespace RecrownedAthenaeum.Render
|
||||
this.primitiveBatch = primitiveBatch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rectangle renderer.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">The graphics device used to create the <see cref="PrimitiveBatch"/></param>
|
||||
/// <param name="camera">The camera containing the matrix to be used for the transformations.</param>
|
||||
public RectangleRenderer(GraphicsDevice graphicsDevice, Camera2D camera) : this(new PrimitiveBatch(graphicsDevice, camera, 4))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the render batch.
|
||||
/// </summary>
|
||||
@@ -98,40 +87,5 @@ namespace RecrownedAthenaeum.Render
|
||||
primitiveBatch.AddVertex(corners[3], color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to dispose of this object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name);
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An overridable of disposable.
|
||||
/// </summary>
|
||||
/// <param name="disposing">Only true when called by user code dispose. Destructor calling this results in false.</param>
|
||||
public virtual void Dispose(bool disposing)
|
||||
{
|
||||
disposed = true;
|
||||
if (!disposed && disposing)
|
||||
{
|
||||
disposed = true;
|
||||
if (primitiveBatch != null)
|
||||
{
|
||||
primitiveBatch.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destructor.
|
||||
/// </summary>
|
||||
~RectangleRenderer ()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user