///////////////////////////////////////////////////////////////////////////////
/// @file deMapLoader.hpp
///
/// @brief Loader for Quake-style MAP files
///
/// @author Assassin
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Dec 2003
/// @author Assassin
/// @remarks Shifted into external CLI tool
///
///////////////////////////////////////////////////////////////////////////////

#ifndef DEMAPLOADER_HPP
#define DEMAPLOADER_HPP

#define USING_DESTINY3D
#define DESTINY3D_STATIC_LINK

#include "Destiny3D.hpp"
//#include "deFileSystem.hpp"
//#include "deFile.hpp"
//#include "deWorld.hpp"
//#include "deScene.hpp"
#include "deString.hpp"
#include "deList.hpp"

class IdeRenderTexture;

namespace deMapConverter
{
	const double Plane_Epsilon = 0.00001;
	const double Edge_Epsilon = 0.00001;
	
	// a brush plane with texture info
	struct BrushPlane_t
	{
		deVec3d Normal;
		deDouble Dist;
		deVec3d Axes[2];
		deFloat Offsets[2];
		deFloat Scales[2];
		long Texture;
	};

	// a brush face with texture info
	struct Face_t
	{
		Face_t():pNext(0){}
		Face_t(const Face_t& ref)
			:pNext(0),mVertices(ref.mVertices), Normal(ref.Normal), mTexture(ref.mTexture) {}
		struct Vert
		{
			deVec3d Pos;
			deTexCoord2 TexCoord;
		};
		long mTexture;
		deTArray<Vert> mVertices;
		deVec3d Normal;
		Face_t* pNext;
	};
	
	// a brush, composed of several planes intersected to form a convex hull of faces
	struct Brush_t
	{
		deTArray <BrushPlane_t> mPlanes;	// all planes used for brush
		deTArray <Face_t>		mFaces;		// all faces produced by brush
		deAABB BBox;
		deBoolean Invisible;
	};
	
	// a map entity - contains data and geometry
	struct Entity_t
	{
		struct entity_var_t
		{
			entity_var_t() {}
			entity_var_t(const deString2& name) : mName(name) {}
			deString2 mName;
			deString2 mValue;
		};
		deTArray <entity_var_t> mVars;
		deTList <Brush_t> mBrushes;
	};
	
	// the full map data
	struct FullData_t
	{
		deTList  <Entity_t>		mEntities;	// all entities, they include their brushes
		deTArray <IdeRenderTexture*> mTextures; // all textures used in the map
	};
} // namespace deMapConverter

void LogExportMsg(const char* format, ...);
class mapException
{
public:
	deString2 what;
	mapException() {}
	mapException(const deString & msg) : what(msg.const_str()) {}
	mapException(const char * msg) : what(msg) {}
	~mapException() {}
};

#endif