<commit_before>﻿using System;
using AGS.API;

namespace AGS.Engine
{
    [RequiredComponent(typeof(IWorldPositionComponent))]
    public class PivotRendererComponent : AGSComponent, IRenderer
    {
        private readonly IGLUtils _utils;
        private readonly IAGSRenderPipeline _pipeline;
        private IWorldPositionComponent _worldPosition;
        private IEntity _entity;

        public PivotRendererComponent(IGLUtils utils, IAGSRenderPipeline pipeline)
        {
            _utils = utils;
            _pipeline = pipeline;
        }

		public override void Init(IEntity entity)
		{
            base.Init(entity);
            _entity = entity;
            entity.Bind<IWorldPositionComponent>(c => _worldPosition = c, _ => _worldPosition = null);
            _pipeline.Subscribe(entity.ID, this, -200);
		}

		public override void Dispose()
		{
            base.Dispose();
            var entity = _entity;
            if (entity == null) return;
            _pipeline.Unsubscribe(entity.ID, this);
		}

		public IRenderInstruction GetNextInstruction(IViewport viewport)
        {
            var worldPosition = _worldPosition;
            if (worldPosition == null) return null;
            return new Instruction { XY = worldPosition.WorldXY, Utils = _utils };
        }

        private class Instruction : IRenderInstruction
        {
            public PointF XY { get; set; }
            public IGLUtils Utils { get; set; }

            public void Release()
            {
            }

            public void Render()
            {
                Utils.DrawCross(XY.X, XY.Y, 5f, 5f, 1f, 1f, 1f, 1f);
            }
        }
    }
}<commit_msg>Pivot renderer- fix viewport was not accounted for<commit_after>﻿using System;
using AGS.API;

namespace AGS.Engine
{
    [RequiredComponent(typeof(IBoundingBoxComponent))]
    [RequiredComponent(typeof(IImageComponent))]
    public class PivotRendererComponent : AGSComponent, IRenderer
    {
        private readonly IAGSRenderPipeline _pipeline;
        private readonly ObjectPool<Instruction> _pool;
        private IBoundingBoxComponent _boundingBox;
        private IImageComponent _image;
        private IEntity _entity;

        public PivotRendererComponent(IGLUtils utils, IAGSRenderPipeline pipeline)
        {
            _pipeline = pipeline;
            _pool = new ObjectPool<Instruction>(pool => new Instruction(pool, utils), 2);
        }

		public override void Init(IEntity entity)
		{
            base.Init(entity);
            _entity = entity;
            entity.Bind<IBoundingBoxComponent>(c => _boundingBox = c, _ => _boundingBox = null);
            entity.Bind<IImageComponent>(c => _image = c, _ => _image = null);
            _pipeline.Subscribe(entity.ID, this, -200);
		}

		public override void Dispose()
		{
            base.Dispose();
            var entity = _entity;
            if (entity == null) return;
            _pipeline.Unsubscribe(entity.ID, this);
		}

		public IRenderInstruction GetNextInstruction(IViewport viewport)
        {
            var boxComponent = _boundingBox;
            if (boxComponent == null) return null;
            var image = _image;
            if (image == null) return null;
            var pivot = _image.Pivot;
            var box = boxComponent.GetBoundingBoxes(viewport).ViewportBox;
            var viewX = MathUtils.Lerp(0f, box.MinX, 1f, box.MaxX, pivot.X);
            var viewY = MathUtils.Lerp(0f, box.MinY, 1f, box.MaxY, pivot.Y);
            var instruction = _pool.Acquire();
            instruction.Setup(viewX, viewY);
            return instruction;
        }

        private class Instruction : IRenderInstruction
        {
            private readonly ObjectPool<Instruction> _pool;
            private readonly IGLUtils _utils;
            private float _x, _y;

            public Instruction(ObjectPool<Instruction> pool, IGLUtils utils)
            {
                _pool = pool;
                _utils = utils;
            }

            public void Setup(float x, float y)
            {
                _x = x;
                _y = y;
            }

            public void Release()
            {
                _pool.Release(this);
            }

            public void Render()
            {
                _utils.DrawCross(_x, _y, 5f, 5f, 1f, 1f, 1f, 1f);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08407789232531501, 'fraction_numerical': 0.005269186712485682, 'mean_word_length': 1.8761528326745718, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563736', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1180, 'n_words': 295}