• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemoBytom / DemoEngine / 23389549430

21 Mar 2026 09:40PM UTC coverage: 32.417% (-0.05%) from 32.468%
23389549430

push

coveralls.net

DemoBytom
Mediator shader compilation and loading at the start of the app

Shader compilation and loading is now performed through Mediator, at the start of the application, instead when `MainLoop` starts. This should ensure (for now) that shaders are properly compiled and loaded when needed (for example in `GPass`)

1262 of 3893 relevant lines covered (32.42%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Demo.Engine.Core/Services/EngineService.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Reflection;
5
using Demo.Engine.Core.Features.StaThread;
6
using Demo.Engine.Core.Interfaces;
7
using Demo.Engine.Core.Requests;
8
using Mediator;
9
using Microsoft.Extensions.DependencyInjection;
10
using Microsoft.Extensions.Hosting;
11
using Microsoft.Extensions.Logging;
12

13
namespace Demo.Engine.Core.Services;
14

15
internal sealed class EngineService(
×
16
    ILogger<EngineService> logger,
×
17
    IHostApplicationLifetime hostApplicationLifetime,
×
18
    IServiceScopeFactory scopeFactory,
×
19
    IMediator mediator)
×
20
    : IHostedService,
21
      IDisposable
22
{
23
    private readonly ILogger<EngineService> _logger = logger;
×
24
    private readonly IHostApplicationLifetime _hostApplicationLifetime = hostApplicationLifetime;
×
25
    private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
×
26
    private readonly IMediator _mediator = mediator;
×
27
    private readonly string _serviceName = "Engine";
×
28
    private Task? _executingTask;
29
    private bool _stopRequested;
30
    private bool _disposedValue;
31

32
    private readonly string _version = Assembly
×
33
        .GetEntryAssembly()
×
34
        ?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
×
35
        ?.InformationalVersion ?? "0.0.0";
×
36

37
    public Task StartAsync(CancellationToken cancellationToken)
38
    {
39
        _logger.LogServiceIsStarting(_serviceName, _version);
×
40
        _executingTask = DoWorkAsync();
×
41

42
        return _executingTask.IsCompleted
×
43
            ? _executingTask
×
44
            : Task.CompletedTask;
×
45
    }
46

47
    public async Task StopAsync(CancellationToken cancellationToken)
48
    {
49
        _logger.LogServiceStopping(_serviceName);
×
50

51
        _stopRequested = true;
×
52
        if (_executingTask is null)
×
53
        {
54
            return;
×
55
        }
56

57
        _ = await Task.WhenAny(
×
58
            _executingTask,
×
59
            Task.Delay(Timeout.Infinite, cancellationToken));
×
60
    }
×
61

62
    private async Task DoWorkAsync()
63
    {
64
        await using var scope = _scopeFactory.CreateAsyncScope();
×
65
        var serviceProvider = scope.ServiceProvider;
×
66
        var mainLoopLifetime = serviceProvider.GetService<IMainLoopLifetime>();
×
67

68
        try
69
        {
70
            //var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
71
            //var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
72

73
            _ = await _mediator.Send(new CompileShaders(), _hostApplicationLifetime.ApplicationStopping);
×
74
            _ = await _mediator.Send(new LoadShadersRequest(), _hostApplicationLifetime.ApplicationStopping);
×
75

76
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
77
            var executeAsync = mainLoopService.ExecutingTask;
×
78

79
            var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
×
80
            var runStaThread = staThreadService.ExecutingTask;
×
81

82
            await Task.WhenAll(
×
83
                [
×
84
                    executeAsync,
×
85
                    runStaThread
×
86
                ]);
×
87
        }
×
88
        catch (OperationCanceledException)
×
89
        {
90
            mainLoopLifetime?.Cancel();
×
91
        }
×
92
        catch (Exception ex)
×
93
        {
94
            _logger.LogServiceFailedWithError(ex, _serviceName);
×
95
        }
×
96
        finally
97
        {
98
            if (!_stopRequested)
×
99
            {
100
                _hostApplicationLifetime.StopApplication();
×
101
            }
102
        }
103
    }
×
104

105
    private void Dispose(bool disposing)
106
    {
107
        if (!_disposedValue)
×
108
        {
109
            if (disposing)
×
110
            {
111
                _hostApplicationLifetime.StopApplication();
×
112
            }
113

114
            _disposedValue = true;
×
115
        }
116
    }
×
117

118
    public void Dispose()
119
    {
120
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
121
        Dispose(disposing: true);
×
122
        GC.SuppressFinalize(this);
×
123
    }
×
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc