/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A. - All Rights Reserved.                        *
*                                                                          *
***************************************************************************/
#pragma once

#include <glmCrowdIOAPI.h>
#include <glmVector3.h>
#include <glmArray.h>

#define VISUALFEEDBACK_SRC_COLOR 0xFF00FF00
#define VISUALFEEDBACK_INTERMEDIATE_COLOR 0xFF00FFFF
#define VISUALFEEDBACK_DST_COLOR 0xFF0000FF

namespace glm
{
	namespace crowdio
	{
		class GLM_CROWDIO_API SimulationCacheVisualFeedbackArray
		{
		public: //structures
			struct Line
			{
				Line(const Vector3& p1, const Vector3& p2, uint32_t colorABGR, float lineWidth, bool ZupToYup = true)
					: _p1(p1)
					, _p2(p2)
					, _colorABGR(colorABGR)
					, _lineWidth(lineWidth)
				{
					if (ZupToYup)
					{
						_p1.setValues(-p1[0], p1[2], p1[1]);
						_p2.setValues(-p2[0], p2[2], p2[1]);
					}
				}

				Vector3 _p1;
				Vector3 _p2;
				uint32_t _colorABGR;
				float _lineWidth;
			};

			struct Circle
			{
				Circle(const Vector3& center, const Vector3& normal, float radius, bool filled, uint32_t colorABGR)
					: _center(center)
					, _normal(normal)
					, _radius(radius)
					, _filled(filled)
					, _colorABGR(colorABGR)
				{ }

				Vector3 _center;
				Vector3 _normal;
				float _radius;
				bool _filled;
				uint32_t _colorABGR;
			};

		public: //functions
			GLM_CLASS_STAT_ID(glm::MemoryStatIds::PrevizAndRender)

			SimulationCacheVisualFeedbackArray()
			{ }

			~SimulationCacheVisualFeedbackArray()
			{ }

			inline void clear();

			inline bool isNodeInVisualFeedbackList(int32_t nodeID) const;
			inline bool isEntityInVisualFeedbackList(int64_t entityID) const;

		public: //data
			Array<Line>	_lines;
			Array<Circle> _circles;

			Array<int32_t>	_nodesIDs;	//layout nodes IDs to display debug info on
			Array<int64_t>	_entityIDs;	//entity IDs to display debug info on
		};


		inline void SimulationCacheVisualFeedbackArray::clear()
		{
			_lines.clear();
			_circles.clear();
		}

		inline bool SimulationCacheVisualFeedbackArray::isNodeInVisualFeedbackList(int32_t nodeID) const
		{
			for (size_t iDebugNode = 0; iDebugNode < _nodesIDs.size(); ++iDebugNode)
			{
				if (_nodesIDs[iDebugNode] == -1 || _nodesIDs[iDebugNode] == (int32_t)nodeID)	//-1 is for 'any'
				{
					return true;
					break;
				}
			}
			return false;
		}

		inline bool SimulationCacheVisualFeedbackArray::isEntityInVisualFeedbackList(int64_t entityID) const
		{
			for (size_t iDebugEntity = 0; iDebugEntity < _entityIDs.size(); ++iDebugEntity)
			{
				if (_entityIDs[iDebugEntity] == -1 || _entityIDs[iDebugEntity] == entityID)	//-1 is for 'any'
				{
					return true;
					break;
				}
			}
			return false;
		}

	}
}
