232 lines
6.1 KiB
C#
232 lines
6.1 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Quik.CommandQueue
|
||
|
{
|
||
|
public class CommandQueue : Queue<Frame>
|
||
|
{
|
||
|
public void Invoke(QuikCommandHandler handler)
|
||
|
{
|
||
|
Enqueue(Command.Invoke);
|
||
|
Enqueue(new Frame(handler));
|
||
|
}
|
||
|
|
||
|
public void ConditionalBegin(bool value)
|
||
|
{
|
||
|
Enqueue(Command.ConditionalBegin);
|
||
|
Enqueue((Frame)(value ? 1 : 0));
|
||
|
}
|
||
|
|
||
|
public void ConditionalBegin(Func<bool> condition)
|
||
|
{
|
||
|
Enqueue(Command.ConditionalBegin);
|
||
|
Enqueue(new Frame(condition));
|
||
|
}
|
||
|
|
||
|
public void ConditionalEnd()
|
||
|
{
|
||
|
Enqueue(Command.ConditionalEnd);
|
||
|
}
|
||
|
|
||
|
public void PushViewport(in QuikRectangle viewport)
|
||
|
{
|
||
|
Enqueue(Command.PushViewport);
|
||
|
Enqueue(viewport);
|
||
|
}
|
||
|
|
||
|
public void StoreViewport(in QuikRectangle viewport)
|
||
|
{
|
||
|
Enqueue(Command.StoreViewport);
|
||
|
Enqueue(viewport);
|
||
|
}
|
||
|
|
||
|
public void PopViewport()
|
||
|
{
|
||
|
Enqueue(Command.PopViewport);
|
||
|
}
|
||
|
|
||
|
public void IncrementZ()
|
||
|
{
|
||
|
Enqueue(Command.IncrementZ);
|
||
|
}
|
||
|
|
||
|
public void AddZ(int value)
|
||
|
{
|
||
|
if (value == 1)
|
||
|
{
|
||
|
IncrementZ();
|
||
|
}
|
||
|
else if (value == -1)
|
||
|
{
|
||
|
DecrementZ();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Enqueue(Command.AddZ);
|
||
|
Enqueue((Frame)value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void StoreZ(int value)
|
||
|
{
|
||
|
Enqueue(Command.StoreZ);
|
||
|
Enqueue((Frame)value);
|
||
|
}
|
||
|
|
||
|
public void DecrementZ()
|
||
|
{
|
||
|
Enqueue(Command.DecrementZ);
|
||
|
}
|
||
|
|
||
|
public void Line(in QuikLine line)
|
||
|
{
|
||
|
Enqueue(Command.Line);
|
||
|
Enqueue(line);
|
||
|
}
|
||
|
|
||
|
public void Line(params QuikLine[] lines)
|
||
|
{
|
||
|
Enqueue(Command.Line);
|
||
|
Enqueue((Frame)lines.Length);
|
||
|
foreach (QuikLine line in lines)
|
||
|
Enqueue(line);
|
||
|
}
|
||
|
|
||
|
public void Bezier(in QuikBezier bezier)
|
||
|
{
|
||
|
Frame a, b;
|
||
|
Frame.Create(bezier, out a, out b);
|
||
|
|
||
|
Enqueue(Command.Bezier);
|
||
|
Enqueue(a);
|
||
|
Enqueue(b);
|
||
|
}
|
||
|
|
||
|
public void Bezier(params QuikBezier[] beziers)
|
||
|
{
|
||
|
Frame a, b;
|
||
|
|
||
|
Enqueue(Command.Bezier);
|
||
|
Enqueue((Frame)beziers.Length);
|
||
|
|
||
|
foreach (QuikBezier bezier in beziers)
|
||
|
{
|
||
|
Frame.Create(bezier, out a, out b);
|
||
|
Enqueue(a);
|
||
|
Enqueue(b);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Rectangle(in QuikRectangle rectangle)
|
||
|
{
|
||
|
Enqueue(Command.Rectangle);
|
||
|
Enqueue(rectangle);
|
||
|
}
|
||
|
|
||
|
public void Rectangle(QuikRectangle[] rectangles)
|
||
|
{
|
||
|
Enqueue(Command.Rectangle);
|
||
|
Enqueue((Frame)rectangles.Length);
|
||
|
foreach (QuikRectangle rectangle in rectangles)
|
||
|
Enqueue(rectangle);
|
||
|
}
|
||
|
|
||
|
public void Ellipse(in QuikEllipse ellipse)
|
||
|
{
|
||
|
Frame a, b;
|
||
|
Frame.Create(ellipse, out a, out b);
|
||
|
|
||
|
Enqueue(Command.Ellipse);
|
||
|
Enqueue(a);
|
||
|
Enqueue(b);
|
||
|
}
|
||
|
|
||
|
public void Ellipse(params QuikEllipse[] ellipses)
|
||
|
{
|
||
|
Frame a, b;
|
||
|
Enqueue(Command.Ellipse);
|
||
|
Enqueue((Frame)ellipses.Length);
|
||
|
foreach (QuikEllipse ellipse in ellipses)
|
||
|
{
|
||
|
Frame.Create(ellipse, out a, out b);
|
||
|
Enqueue(a);
|
||
|
Enqueue(b);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Triangle(in QuikTriangle triangle)
|
||
|
{
|
||
|
Enqueue(Command.Triangle);
|
||
|
Enqueue(triangle.A);
|
||
|
Enqueue(triangle.B);
|
||
|
Enqueue(triangle.C);
|
||
|
}
|
||
|
|
||
|
public void Triangle(params QuikTriangle[] triangles)
|
||
|
{
|
||
|
Enqueue(Command.Triangle);
|
||
|
Enqueue((Frame)triangles.Length);
|
||
|
foreach (QuikTriangle triangle in triangles)
|
||
|
{
|
||
|
Enqueue(triangle.A);
|
||
|
Enqueue(triangle.B);
|
||
|
Enqueue(triangle.C);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Polygon(params QuikVec2[] polygon)
|
||
|
{
|
||
|
Enqueue(Command.Polygon);
|
||
|
Enqueue((Frame)polygon.Length);
|
||
|
foreach (QuikVec2 vertex in polygon)
|
||
|
{
|
||
|
Enqueue(vertex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Image(IQuikTexture texture, in QuikRectangle rectangle)
|
||
|
{
|
||
|
Enqueue(Command.Image);
|
||
|
Enqueue((Frame)(int)ImageCommandFlags.Single);
|
||
|
Enqueue(new Frame(texture));
|
||
|
Enqueue(rectangle);
|
||
|
}
|
||
|
|
||
|
public void Image(IQuikTexture texture, in QuikRectangle rectangle, in QuikRectangle uv)
|
||
|
{
|
||
|
Enqueue(Command.Image);
|
||
|
Enqueue((Frame)(int)(ImageCommandFlags.Single | ImageCommandFlags.UVs));
|
||
|
Enqueue(new Frame(texture));
|
||
|
Enqueue(rectangle);
|
||
|
Enqueue(uv);
|
||
|
}
|
||
|
|
||
|
public void Image(IQuikTexture texture, QuikRectangle[] rectangles, bool interleavedUV = false)
|
||
|
{
|
||
|
ImageCommandFlags flags = interleavedUV ? ImageCommandFlags.UVs : ImageCommandFlags.None;
|
||
|
|
||
|
Enqueue(Command.Image);
|
||
|
Enqueue(new Frame((int)flags, rectangles.Length / 2));
|
||
|
Enqueue(new Frame(texture));
|
||
|
|
||
|
foreach (QuikRectangle rectangle in rectangles)
|
||
|
{
|
||
|
Enqueue(rectangle);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Image(IQuikTexture texture, QuikRectangle[] rectangles, QuikRectangle[] uvs)
|
||
|
{
|
||
|
int count = Math.Min(rectangles.Length, uvs.Length);
|
||
|
Enqueue(Command.Image);
|
||
|
Enqueue(new Frame((int)ImageCommandFlags.UVs, count));
|
||
|
Enqueue(new Frame(texture));
|
||
|
|
||
|
for (int i = 0; i < count; i++)
|
||
|
{
|
||
|
Enqueue(rectangles[i]);
|
||
|
Enqueue(uvs[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|