69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using System.Threading.Channels;
|
|
using Domain.Interfaces;
|
|
using Domain.RenderPart;
|
|
|
|
namespace Domain;
|
|
|
|
public class Render
|
|
{
|
|
public Guid Id { get; }
|
|
public Guid ProjectId { get; }
|
|
|
|
private readonly IEnumerable<ILayer> _layers;
|
|
private readonly uint _width;
|
|
private readonly uint _height;
|
|
|
|
private readonly bool _useBigFrames = true;
|
|
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
|
|
|
public Render(Project project)
|
|
{
|
|
Id = Guid.NewGuid();
|
|
ProjectId = project.Id;
|
|
_width = project.Width;
|
|
_height = project.Height;
|
|
_layers = project.Layers;
|
|
}
|
|
|
|
public async Task Run(Channel<IFrameRender> channel)
|
|
{
|
|
foreach (var layer in _layers)
|
|
{
|
|
await layer.Prerender();
|
|
}
|
|
|
|
if (_useBigFrames)
|
|
{
|
|
await MakeBigFrames(channel);
|
|
}
|
|
else
|
|
{
|
|
throw new NotImplementedException();
|
|
// MakeFrames(channel);
|
|
}
|
|
|
|
//maybe returb render result
|
|
}
|
|
|
|
private async Task MakeBigFrames(Channel<IFrameRender> channel)
|
|
{
|
|
uint bigFrameWidth = 8, bigFrameHeight = 8;
|
|
|
|
for (uint y = 0; y < _height; y += bigFrameHeight)
|
|
{
|
|
uint currentBigFrameHeight = Math.Min(bigFrameHeight, _height - y);
|
|
|
|
for (uint x = 0; x < _width; x += bigFrameWidth)
|
|
{
|
|
uint currentBigFrameWidth = Math.Min(bigFrameWidth, _width - x);
|
|
var bigFrameRender = new BigFrameRender(_layers, x, y, currentBigFrameWidth, currentBigFrameHeight, Id);
|
|
await channel.Writer.WriteAsync(bigFrameRender);
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task Stop()
|
|
{
|
|
await Task.Delay(100);
|
|
}
|
|
} |