1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-24 21:48:35 +01:00

Compare commits

..

No commits in common. "04dc2bf2d01cf7d56348ef3d77afc0d5963ce2fc" and "08bd443c36d5693a5f14094b65d5c45faef910c4" have entirely different histories.

3 changed files with 14 additions and 21 deletions

View file

@ -13,9 +13,6 @@ Additions
- Added GenericFont SplitStringSeparate which differentiates between existing newline characters and splits due to maximum width
- Added StaticSpriteBatch class
Improvements
- Exposed Camera's RoundPosition
### MLEM.Ui
Additions
- Allow specifying a maximum amount of characters for a TextField

View file

@ -58,7 +58,7 @@ namespace MLEM.Cameras {
get {
var sc = this.ActualScale;
var pos = -this.Position * sc;
if (this.RoundPosition)
if (this.roundPosition)
pos = pos.FloorCopy();
return Matrix.CreateScale(sc, sc, 1) * Matrix.CreateTranslation(new Vector3(pos, 0));
}
@ -82,13 +82,9 @@ namespace MLEM.Cameras {
/// The viewport of this camera, based on the game's <see cref="GraphicsDevice.Viewport"/> and this camera's <see cref="ActualScale"/>
/// </summary>
public Vector2 ScaledViewport => new Vector2(this.Viewport.Width, this.Viewport.Height) / this.ActualScale;
/// <summary>
/// Whether the camera's <see cref="Position"/> should be rounded to full integers when calculating the <see cref="ViewMatrix"/>.
/// If this value is true, the occurence of rendering fragments due to floating point rounding might be reduced.
/// </summary>
public bool RoundPosition;
private Rectangle Viewport => this.graphicsDevice.Viewport.Bounds;
private readonly bool roundPosition;
private readonly GraphicsDevice graphicsDevice;
private float scale = 1;
@ -96,11 +92,11 @@ namespace MLEM.Cameras {
/// Creates a new camera.
/// </summary>
/// <param name="graphicsDevice">The game's graphics device</param>
/// <param name="roundPosition">Whether the camera's <see cref="Position"/> should be rounded to full integers when calculating the <see cref="ViewMatrix"/></param>
/// <param name="roundPosition">If this is true, the camera's <see cref="Position"/> and related properties will be rounded to full integers.</param>
public Camera(GraphicsDevice graphicsDevice, bool roundPosition = true) {
this.graphicsDevice = graphicsDevice;
this.AutoScaleReferenceSize = this.Viewport.Size;
this.RoundPosition = roundPosition;
this.roundPosition = roundPosition;
}
/// <summary>

View file

@ -12,10 +12,6 @@ namespace MLEM.Misc {
/// </summary>
public class StaticSpriteBatch : IDisposable {
// this maximum is limited by indices being a short
private const int MaxBatchItems = short.MaxValue / 6;
private static readonly VertexPositionColorTexture[] Data = new VertexPositionColorTexture[MaxBatchItems * 4];
/// <summary>
/// The amount of vertices that are currently batched
/// </summary>
@ -67,24 +63,28 @@ namespace MLEM.Misc {
return;
this.batchChanged = false;
// this maximum is limited by indices being a short
const int maxBatchItems = short.MaxValue / 6;
// ensure we have enough vertex buffers
var requiredBuffers = (this.vertices.Count / (MaxBatchItems * 4F)).Ceil();
var requiredBuffers = (this.vertices.Count / (maxBatchItems * 4F)).Ceil();
while (this.vertexBuffers.Count < requiredBuffers)
this.vertexBuffers.Add(new VertexBuffer(this.graphicsDevice, VertexPositionColorTexture.VertexDeclaration, MaxBatchItems * 4, BufferUsage.WriteOnly));
this.vertexBuffers.Add(new VertexBuffer(this.graphicsDevice, VertexPositionColorTexture.VertexDeclaration, maxBatchItems * 4, BufferUsage.WriteOnly));
// fill vertex buffers
var arrayIndex = 0;
var totalIndex = 0;
var data = new VertexPositionColorTexture[maxBatchItems * 4];
while (totalIndex < this.vertices.Count) {
var now = Math.Min(this.vertices.Count - totalIndex, Data.Length);
var now = Math.Min(this.vertices.Count - totalIndex, data.Length);
for (var i = 0; i < now; i++)
Data[i] = this.vertices[totalIndex + i];
this.vertexBuffers[arrayIndex++].SetData(Data);
data[i] = this.vertices[totalIndex + i];
this.vertexBuffers[arrayIndex++].SetData(data);
totalIndex += now;
}
// ensure we have enough indices
var maxItems = Math.Min(this.vertices.Count / 4, MaxBatchItems);
var maxItems = Math.Min(this.vertices.Count / 4, maxBatchItems);
// each item has 2 triangles which each have 3 indices
if (this.indices == null || this.indices.IndexCount < 6 * maxItems) {
var newIndices = new short[6 * maxItems];