

//
// Irrlicht Wrapper for Imperative Languages
// Frank Dodd  (initial) (2006)
//
// Additional Work
// Michael Taupitz (2006)
//
// This wrapper DLL encapsulates a sub-set of the features of the powerful
// Irrlicht 3D Graphics Engine exposing the Object Oriented architecture and
// providing a functional 3D SDK for languages that are not object oriented.
//
// This source was created with the help of the great examples in the Irrlicht
// SDK and the excellent Irrlicht documentation. This software was developed
// using the GCC compiler and Code::Blocks IDE
//

/* ////////////////////////////////////////////////////////////////////////////
includes
*/
#include "irrlichtwrapper.h"

//Fix for PureBasic

/*
#ifdef   __cplusplus
   extern "C" {
   #endif
    char _fltused;
    void _ftol2()
    {
       int r;
       _asm
       {
          fistp r
          mov eax, r
       }
    }
   #ifdef __cplusplus
   }
   #endif
*/

/* ////////////////////////////////////////////////////////////////////////////
Global variables
*/
IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ILogger* logger;
// The Instance of the Event Receiver Class
StackedEventReceiver receiver;

/* ////////////////////////////////////////////////////////////////////////////
Global Function Declarations

all of the below functions are delared as C functions and are exposed without
any mangled names so that they can be easily imported into unstructured
languages like FreeBasic
*/



extern "C"
{



STATIC_EXPORT void DLL_EXPORT  IrrRnd(f32 f1, f32 f2, f32 &back)
{
/*
    if (f1 == f2) {
        back = f1;
        return;
    }
    if (f1 > f2) {
        back = 0.0;
        return;
    }
*/
	back = f1 + (f2-f1)*(float)rnd_my()/4294967296.0f;
}

STATIC_EXPORT void DLL_EXPORT  IrrRndMax(f32 f, f32 &back)
{
	back = f*(float)rnd_my()/4294967296.0f;
}





/****f* IrrlichtWrapper/IrrDropPointer
* NAME
*    IrrDropPointer  - Drops a Pointer of a Irrlicht-Object
* SYNOPSIS
*    IrrDropPointer( *unknown.l)
* FUNCTION
*    To free Ressources you can use this Function. It tries to
*    delete the Object. It decreases the reference counter
* INPUTS
*    *unknown.l  - Pointer to a Irrlicht-Object.
* RESULT
*    nothing
* EXAMPLE
*    IrrDropPointer( *unknown.l)
* NOTES
*    This is only a Simple Wrapper-Function, but it can be very usefull
* BUGS
*    Be sure that the Pointer is Valid. This is not Checked !
****
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrDropPointer(*iUnknown.l)
*/

STATIC_EXPORT void DLL_EXPORT  IrrDropPointer( IReferenceCounted *unknown)
{
    if (unknown)
        unknown->drop();
}


STATIC_EXPORT void DLL_EXPORT  IrrLog( c8* text,  ELOG_LEVEL level)
{
    if (logger)
        logger->log(text,level);
}

STATIC_EXPORT void DLL_EXPORT  IrrLogHint( c8* text1, c8* hint, ELOG_LEVEL level)
{
    if (logger)
        logger->log(text1,hint,level);
}

STATIC_EXPORT void DLL_EXPORT  IrrSetLogLevel(ELOG_LEVEL level)
{
    if (logger)
        logger->setLogLevel(level);
}

STATIC_EXPORT u32 DLL_EXPORT  IrrGetLogLevel()
{
    if (logger)
        return (u32)logger->getLogLevel();
    return 0;
}




/* ////////////////////////////////////////////////////////////////////////////
all of the above functions are delared as C functions and are exposed without
any mangled names
*/
}
