public MovieRenderer(IMainWindow mainWindow, RenderingDevice device, VideoPlayer player,
                         MovieSubtitles?subtitles)
    {
        _mainWindow = mainWindow;
        _device     = device;
        _material   = CreateMaterial(device);
        _player     = player;

        if (subtitles != null)
        {
            _subtitleRenderer = new SubtitleRenderer(_device, subtitles);
        }

        _texture = device.CreateDynamicTexture(BufferFormat.X8R8G8B8,
                                               player.VideoWidth, player.VideoHeight);

        if (_player.HasAudio)
        {
            _soundSource = new SoLoudDynamicSource(_player.AudioChannels, _player.AudioSampleRate);
            Tig.Sound.PlayDynamicSource(_soundSource);
        }

        player.OnVideoFrame   += UpdateFrame;
        player.OnAudioSamples += PushAudioSamples;
    }
    /// <summary>
    /// Renders the Line Of Sight buffer for a given party member.
    /// </summary>
    public void RenderLineOfSight(IGameViewport viewport, int partyIndex)
    {
        var buffer = _system.GetLineOfSightBuffer(partyIndex, out var size, out var originTile);

        if (!_texture.IsValid || _texture.Resource.GetSize() != size)
        {
            _colorBuffer = new PackedLinearColorA[size.Width * size.Height];

            _texture.Dispose();
            _texture = _device.CreateDynamicTexture(BufferFormat.A8R8G8B8, size.Width, size.Height);
        }

        // Update color buffer
        for (int i = 0; i < buffer.Length; i++)
        {
            _colorBuffer[i] = GetColorFromLosFlags(buffer[i]);
        }

        var rawColorBuffer = MemoryMarshal.Cast <PackedLinearColorA, byte>(_colorBuffer);

        _texture.Resource.UpdateRaw(rawColorBuffer, size.Width * 4);

        var origin = new Vector4(originTile.ToInches3D(), 1);

        var widthVec  = new Vector4(size.Width * locXY.INCH_PER_SUBTILE, 0, 0, 0);
        var heightVec = new Vector4(0, 0, size.Height * locXY.INCH_PER_SUBTILE, 0);

        Span <ShapeVertex3d> corners = stackalloc ShapeVertex3d[4]
        {
            new ShapeVertex3d
            {
                pos = origin,
                uv  = new Vector2(0, 0)
            },
            new ShapeVertex3d
            {
                pos = origin + widthVec,
                uv  = new Vector2(1, 0)
            },
            new ShapeVertex3d
            {
                pos = origin + widthVec + heightVec,
                uv  = new Vector2(1, 1)
            },
            new ShapeVertex3d
            {
                pos = origin + heightVec,
                uv  = new Vector2(0, 1)
            }
        };

        Tig.ShapeRenderer3d.DrawQuad(viewport, corners, new PackedLinearColorA(255, 255, 255, 127), _texture.Resource);
    }
Example #3
0
    private void UpdateBufferSize(bool force = false)
    {
        if (!force &&
            _originalFogSize.Width == _fogSystem._fogScreenBufferWidthSubtiles &&
            _originalFogSize.Height == _fogSystem._fogScreenBufferHeightSubtiles)
        {
            return;
        }

        _originalFogSize = new Size(
            _fogSystem._fogScreenBufferWidthSubtiles,
            _fogSystem._fogScreenBufferHeightSubtiles
            );

        _blurredFogTexture.Dispose();

        _blurredFogWidth  = (_originalFogSize.Width / 4) * 4 + 8;
        _blurredFogHeight = (_originalFogSize.Height / 4) * 4 + 8;

        _blurredFogTexture = _device.CreateDynamicTexture(BufferFormat.A8, _blurredFogWidth, _blurredFogHeight);
        _blurredFog        = new byte[_blurredFogWidth * _blurredFogHeight];

        CreateMaterial();
    }