/******************************************************************************
*	File		-	simple_render_scene.h
*	Author		-	Joey Pollack
*	Date		-	2021/10/27 (y/m/d)
*	Mod Date	-	2021/10/27 (y/m/d)
*	Description	-	Displays a simple scene that tests basic render features.
******************************************************************************/

#ifndef SIMPLE_RENDER_SCENE_H_
#define SIMPLE_RENDER_SCENE_H_

#include "base_scene.h"
#include <renderer/renderer2D.h>
#include <core/types.h>
#include <utils/high_resolution_timer.h>
#include <string>

#include <run_modes/editor/contents/tile_map.h>
#include <run_modes/editor/contents/tile_set.h>

namespace lunarium
{
    class Texture;
    class FrameBuffer;
    class SimpleRenderScene : public BaseScene
    {
        enum TestMode
        {
            Basic,
            Stress,
            String,
            Shapes,
            TileMap,
            Parent,
        };

        enum ShapeMode
        {
            Lines,
            Boxes,
            Ellipses,
        };

    public:
        SimpleRenderScene(uint32_t logCat);
        ~SimpleRenderScene();
        virtual void OnLoad();
        virtual void OnTick(double delta);
        void RenderScene(Renderer2D& g);
        void RenderBatchStressTest(Renderer2D& g);
        void RenderStringTest(Renderer2D& g);
        void RenderShapesTest(Renderer2D& g);
        void RenderTileMapTest(Renderer2D& g);
        void RenderParentTest(Renderer2D& g);

    private:
        
        int mTextBoxWidth;
        Sizei mImageSize;
        bool flip_image = true;
        Texture* mpRenderedImage;
        Texture* mpTestImageLoad;
        Texture* mpTestImageLoad2;
        Texture* mpTestImageLoad3;
        Rectangle mSubTex;
        FrameBuffer* mFrameBufferOne;
        FrameBuffer* mFrameBufferTwo;
        float angle;
        float box_angle;
        int mEllipseResolution;
        float mEllipseRadii[2];

        float mSrcWidth;
        float mSrcHeight;
        i32 mTextDebugPosX;

        HighResTimer mTimer;
        double mFrameTime;
        i64 mNumFrames;
        Renderer2D::FrameStats mRenderStats;

        TestMode mTestMode;
        ShapeMode mShapeMode;

        // STRESS TEST MODE
        int mNumQuadsToRender = 500;
        bool mUseTextures = false;
        const int NUM_QUADS = 50000;
        Color* mQuadColors;
        Rectangle* mQuads;
        Texture** mQuadTexures;
        //

        // SHAPES MODE DATA
        int mNumLines = 100;
        struct LineData
        {
            glm::vec2 Position1;
            glm::vec2 Position2;
            Color Color;
            float Angle;
            float RotSpeed;
            float Thickness;
        };
        std::vector<LineData> mLines;

        int mNumEllipses = 100;
        struct EllipseData
        {
            glm::vec2 Position;
            Color Color;
            int Resolution;
            float Angle;
            float RotSpeed;
        };
        std::vector<EllipseData> mEllipses;
        //

        editor::TileMap mTestMap;
        editor::TileSet mTestSet;

        // PARENT CHILD TEST
        glm::vec3 mParentPos;
        float mParentAngle;
        glm::vec3 mChildPos;
        float mChildAngle;
        glm::vec3 mChild2Pos;
        float mChild2Angle;

        glm::vec3 mParentPos2;
        glm::vec3 mChildPos2;

        glm::vec3 mParentPos3;
        glm::vec3 mChildPos3;
        glm::vec3 mChildPos3_2;

        struct GridTestObj
        {
            int X;
            std::string msg;
        };

    private:
        void DrawStatsGUI();
        void LoadImages();
        void GenerateLines();
        void GenerateEllipses();
        void GenerateQuads();

        void DoFrameBufferSaveTest();
    };
}

#endif  // SIMPLE_RENDER_SCENE_H_