// Oleg Petruny proprietary.

#pragma once

#include "Components/SceneCaptureComponent2D.h"
#include "CoreMinimal.h"

#include "InteractableScreenCapturer.generated.h"

DECLARE_DELEGATE_OneParam(FInteractableInScreen, class AInteractable*);

/**
 * Notifies only once about interactable is in a camera view
 */
UCLASS(BlueprintType, hidecategories = (Collision, Object, Physics, SceneComponent), ClassGroup = Rendering, editinlinenew, meta = (BlueprintSpawnableComponent, ShortTooltip = "Notifies only once about interactable is in a camera view"), MinimalAPI)
class UInteractableScreenCapturer : public USceneCaptureComponent2D
{
    GENERATED_BODY()

public:
    UInteractableScreenCapturer(const FObjectInitializer& ObjectInitializer);
    virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

    FInteractableInScreen interactableInScreenDelegate;
    UFUNCTION(BlueprintImplementableEvent)
    void OnInteractableInScreen(class AInteractable* interactable);

    UPROPERTY(EditAnywhere)
    float scanDistance = 7000;

protected:
    /** Enques render thread task to find obect on screen  */
    void Process();

private:
    FMinimalViewInfo view; //!< Camera view cache
    TSet<class AInteractable*> _sawInteractables;
    //class UTextureRenderTarget2D* _output;
};
