//===========================================================================//
// File:	munga.hpp                                                           //
// Project: Adept           Brick: ???                                       //
// Contents: ???                                                             //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 00/00/00  XXX  Initial coding.                                            //
//---------------------------------------------------------------------------//
// Copyright (C) 1995-1996, Virtual World Entertainment, Inc.                //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#pragma warning(disable: 4018)	// signed/unsigned mismatches
#pragma warning(disable: 4097)	// typedef synonyms
#pragma warning(disable: 4100)	// unreferenced parameters
#pragma warning(disable: 4102)	// unreferenced labels
#pragma warning(disable: 4127)	// constant comparisons
#pragma warning(disable: 4130)	// logical operation on string constants
#pragma warning(disable: 4201)	// nameless structs
#pragma warning(disable: 4245)	// casting enum to long
#pragma warning(disable: 4355)	// this used in base initializers
#pragma warning(disable: 4511)	// no copy constructor
#pragma warning(disable: 4512)	// no assignment operator
#pragma warning(disable: 4514)
#if defined(_ARMOR) && !defined(_DEBUG)
	#pragma warning(disable: 4700)	// variable used without initialization
	#pragma warning(disable: 4701)	// variable maybe not initialized
#endif
#pragma warning(disable: 4710)	// inline not expanded
#pragma warning(disable: 4711)	// auto-inline selection
#pragma warning(disable: 4291)	// exception handlings and new

#pragma warning(push,3)

#include <math.h>
#include <float.h>
#include <time.h>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#pragma warning(pop)

#pragma warning(push)
#include <GameOS\gameOS.hpp>
#pragma warning(pop)

#define USE_ASSEMBLER_CODE	1

namespace Stuff {

	extern bool g_StuffInitizlized;

	//-------------------------
	// ClassID reserved blocks
	//-------------------------
	enum
	{
		FirstStuffClassID					=	0,
		StuffClassIDCount					=	64,
		LastStuffClassID					=	FirstStuffClassID + StuffClassIDCount-1,

		FirstMLRClassID,
		MLRClassIDCount					=	64,
		LastMLRClassID						=	FirstMLRClassID + MLRClassIDCount-1,

		FirstElementRendererClassID,
		ElementRendererClassIDCount	=	64,
		LastElementRendererClassID		=	FirstElementRendererClassID + ElementRendererClassIDCount-1,

		FirstProxyClassID,
		ProxyClassIDCount					=	64,
		LastProxyClassID					=	FirstProxyClassID + ProxyClassIDCount-1,

		FirstElementProxyClassID,
		ElementProxyClassIDCount		=	64,
		LastElementProxyClassID			=	FirstElementProxyClassID + ElementProxyClassIDCount-1,

		FirstMGProxyClassID,
		MGProxyClassIDCount				=	64,
		LastMGProxyClassID				=	FirstMGProxyClassID + MGProxyClassIDCount-1,

		FirstSIProxyClassID,
		SIProxyClassIDCount				=	64,
		LastSIProxyClassID				=	FirstSIProxyClassID + SIProxyClassIDCount-1,

		FirstAdeptClassID,
		AdeptClassIDCount					=	256,
		LastAdeptClassID					=	FirstAdeptClassID + AdeptClassIDCount-1,

		FirstWindowsAdeptClassID,
		WindowsAdeptClassIDCount		=	32,
		LastWindowsAdeptClassID			=	FirstWindowsAdeptClassID + WindowsAdeptClassIDCount-1,

		FirstGOSAdeptClassID,
		GOSAdeptClassIDCount				=	16,
		LastGOSAdeptClassID				=	FirstGOSAdeptClassID + GOSAdeptClassIDCount-1,

		FirstSRClassID,
		SRClassIDCount						=	256,
		LastSRClassID						=	FirstSRClassID + SRClassIDCount-1,

		FirstSRGOSClassID,
		SRGOSClassIDCount					=	16,
		LastSRGOSClassID					=	FirstSRGOSClassID + SRGOSClassIDCount-1,

		FirstMWGOSClassID,
		MWGOSClassIDCount					=	16,
		LastMWGOSClassID					=	FirstMWGOSClassID + MWGOSClassIDCount-1,

		FirstMAXProxiesClassID,
		MAXProxiesClassIDCount			=	16,
		LastMAXProxiesClassID				=	FirstMAXProxiesClassID + MAXProxiesClassIDCount-1,

		FirstMW4ClassID,
		MW4ClassIDCount						= 256,
		LastMW4ClassID						= FirstMW4ClassID + MW4ClassIDCount - 1,

		FirstgosFXClassID,
		gosFXClassIDCount					= 64,
		LastgosFXClassID					= FirstgosFXClassID + gosFXClassIDCount -1,
		
		//
		//------------------------------------------
		// Please note that all new class id's
		// should be above this comment.  NO
		// class id's shoud be put between
		// the temporary and the class id count
		//------------------------------------------
		//
		FirstTemporaryClassID,
		TemporaryClassIDCount				=	16,
		LastTemporaryClassID				=	FirstTemporaryClassID + TemporaryClassIDCount-1,

		ClassIDCount
	};

	//
	//--------------
	// Stuff classes
	//--------------
	//
	enum
	{
		//
		//-------------------------
		// attribute IDs
		//-------------------------
		//
		NullClassID = ClassIDCount,
		MStringClassID = FirstStuffClassID,
		IntClassID,
		ScalarClassID,
		RadianClassID,
		Vector3DClassID,
		Point3DClassID,
		Normal3DClassID,
		UnitQuaternionClassID,
		Motion3DClassID,
		AffineMatrix4DClassID,
		LinearMatrix4DClassID,
		Vector2DOfIntClassID,
		Vector2DOfScalarClassID,
		EulerAnglesClassID,
		BoolClassID,
		CharClassID,
		RGBAColorClassID,

		//
		//---------------------
		// Registered class IDs
		//---------------------
		//
		RegisteredClassClassID,

		MemoryStreamClassID,
		FileStreamClassID,

		PlugClassID,

		FirstFreeStuffClassID
	};

	void
		InitializeClasses(
			unsigned slot_link_count = 100,
			unsigned chain_link_count = 100,
			unsigned safe_chain_link_count = 100,
			unsigned class_id_count = ClassIDCount
		);
	void TerminateClasses();

	extern HGOSHEAP g_Heap;
	extern HGOSHEAP g_LibraryHeap;
}

#define GROUP_STUFF "Stuff::"
#define GROUP_STUFF_TEST "Stuff::Test"
#define GROUP_STUFF_MEMORY "Stuff::Memory"

//#define NO_TIMERS

#define DECLARE_TIMER(scope, t)\
	scope __int64 t##FrameTime
#define DEFINE_TIMER(c, t)\
	__int64 c::t##FrameTime

#if defined(LAB_ONLY) && !defined(_ARMOR)
	#if !defined(NO_TIMERS)
		#define Initialize_Timer(t, name)\
			do {\
				t##FrameTime = 0;\
				AddStatistic(name, "%", gos_timedata, &t##FrameTime, 0);\
			} while (0);
		#define Start_Timer(t)\
			do {\
				t##FrameTime -= GetCycles();\
			} while (0);
		#define Stop_Timer(t)\
			do {\
				t##FrameTime += GetCycles();\
			} while (0);
	#else
		#define Initialize_Timer(t, name)
		#define Start_Timer(t)
		#define Stop_Timer(t)
	#endif
#else
	#undef NO_TIMERS
	#define NO_TIMERS
	#define Initialize_Timer(t, name)
	#define Start_Timer(t)
	#define Stop_Timer(t)
#endif

//#define NO_STATS

#if defined(LAB_ONLY)
	#if !defined(NO_STATS)
		#define Set_Statistic(s,v) (s=v)
	#else
		#define Set_Statistic(s,v)
	#endif
#else
	#undef NO_STATS
	#define NO_STATS
	#define Set_Statistic(s,v)
#endif

#define NO_RENDER
//#define NO_LOGIC

#if defined(LAB_ONLY) && !defined(_ARMOR)
	#if !defined(NO_LOGIC)
		#define LOGIC(string) LOG_BLOCK("Game Logic::" string)
	#else
		#define LOGIC(string)
	#endif
	#if !defined(NO_RENDER)
		#define RENDER(string) LOG_BLOCK("Update Renderers::" string)
	#else
		#define RENDER(string)
	#endif
#else
	#undef NO_RENDER
	#define NO_RENDER
	#undef NO_LOGIC
	#define NO_LOGIC
	#define LOGIC(string)
	#define RENDER(string)
#endif

#include "Style.hpp"
#include "MArray.hpp"
#include "MString.hpp"
#include "Slot.hpp"
#include "Chain.hpp"
#include "SafeChain.hpp"
#include "SortedChain.hpp"
#include "Table.hpp"
#include "Tree.hpp"
#include "Hash.hpp"
#include "Angle.hpp"
#include "Color.hpp"
#include "ExtentBox.hpp"
#include "FileStream.hpp"
#include "FileStreamManager.hpp"
#include "Line.hpp"
#include "MatrixStack.hpp"
#include "Auto_Ptr.hpp"
#include "Auto_Container.hpp"
#include "Noncopyable.hpp"
#include "Initialized_Ptr.hpp"
#include "Motion.hpp"
#include "NotationFile.hpp"
#include "Page.hpp"
#include "Note.hpp"
#include "OBB.hpp"
#include "Origin.hpp"
#include "Plane.hpp"
#include "Point3D.hpp"
#include "Polar.hpp"
#include "Random.hpp"
#include "Sphere.hpp"
#include "Vector2D.hpp"
#include "Vector4D.hpp"
#include "Average.hpp"
