///////////////////////////////////////////////////////////////////////
// Header file: "Tools.h"
//
// (C) Copyright 2001, RightMark Gathering.  All Rights Reserved.
//
// @Author: Konstantin Mironovich (km) develop@rightmark3d.org
//   derivation work from original code by Alex Simkin (1998)
//
// Purpose: 
//   Checks system setup, declares some useful helper macros
//
// History: 
//   2001/05/10 created. (km)
//
///////////////////////////////////////////////////////////////////////

#pragma once

// Verify compilator settings

#if !defined(__cplusplus)
    #error C++ compilation required
#endif

#if (_MSC_VER < 1200)
    #error Compilation requires at least Visual C++ 6.0
#endif

#if !defined(_WIN32) || !defined(_MT)
    #error Compilation requires Win-32 Multithreaded environment
#endif

#if !defined(_M_IX86)
    #error Can be compiled only for Intel processors
#endif

#if defined(_CHAR_UNSIGNED)
    #error Char type must be signed
#endif

#if !defined(_CPPUNWIND)
    #error Exception handling must be enabled
#endif

#if defined(_ATL_MIN_CRT)
    #error CRT startup code is required for EH. Turn _ATL_MIN_CRT off
#endif

// Platform SDK Libraries

#if defined(_WINDOWS_)
    #error windows.h must not be included
#endif

#if !defined(STRICT)
    #define STRICT  1
#endif

// Exclude rarely-used stuff from Windows headers
#if !defined(WIN32_LEAN_AND_MEAN)
    #define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <objbase.h>

#if defined(OLE2ANSI)
    #error COM must support Unicode 
#endif

#if defined(UNICODE) || defined(_UNICODE)
    #error Compilation for Unicode not supported
#endif

#if !defined(_MBCS)
    #error Multibyte Character Set must be default
#endif

#include <tchar.h>
#include <mbctype.h>

// C++ Libraries

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>
#include <stddef.h>
#include <stdarg.h>

#include <math.h>
// MS <math.h> file do not define M_PI...
#if !defined(M_PI)
#define M_PI            3.14159265358979323846
#endif

#define M_PIinv         (1/M_PI)
#define M_PIhlf         (M_PI/2)
#define M_PI2           (M_PI*2)
#define DEG2RAD(d)      ((d)*(M_PI/180.0))
#define RAD2DEG(r)      ((r)*(180.0/M_PI))

// Tools library helper macros

#define DLL_IMPORT  __declspec(dllimport)
#define DLL_EXPORT  __declspec(dllexport)

#define CHECK(_f_, _rc_)        do { if (!(_f_)) return (_rc_); } while (0)
#define CHECK_NULL(_p_, _rc_)   do { if (NULL == (_p_)) return (_rc_); } while (0)
#define ATTEMPT(_hr_)           do { if (FAILED(_hr_)) ThrowException(_hr_); } while (0)
#define ENDEAVOR(_hr_)          do { if (S_OK != (_hr_)) ThrowException(_hr_); } while (0)
#define COUNTOF(_array_)        (sizeof(_array_)/sizeof(_array_[0]))

#define DELETE_PTR(_p_) { if (NULL != (_p_)) { delete (_p_); (_p_) = NULL; } }
#define RELEASE(_p_)    { if (NULL != (_p_)) { (_p_)->Release(); (_p_) = NULL; } }

#define FREE_TM(_p_)    { if (NULL != (_p_)) ::CoTaskMemFree(_p_); (_p_) = NULL; }

// MS DirectX uuid(x) binding helper macro
#define BIND_IID(name, iid) struct __declspec(uuid(iid)) name


#if defined(TOOLS_DLL)
#if defined(TOOLS_EXPORTS)
    #define TOOLS_PUBLIC    DLL_EXPORT
#else
    #define TOOLS_PUBLIC    DLL_IMPORT
#endif
#else
    #define TOOLS_PUBLIC
#endif


//#include "Debug.h"
#include "Except.h"

void TOOLS_PUBLIC WINAPI TkInitialize(void);
void TOOLS_PUBLIC WINAPI TkTerminate(void);

