// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

/* ////////////////////////////////////////////////////////////////////////////
includes
*/

#include <stdio.h>
#include "bIrrlicht.h"

/* ////////////////////////////////////////////////////////////////////////////
global variables
*/

/* ////////////////////////////////////////////////////////////////////////////
external variables
*/
extern ISoundEngine* engine;


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

all of the below functions are declared as C functions and are exposed without
any mangled names so that they can be easily imported into imperative
languages like FreeBasic
*/
extern "C"
{

/* ////////////////////////////////////////////////////////////////////////////
SYSTEM FUNCTIONS
*/
/* ----------------------------------------------------------------------------
only one irrklang device object is supported by this wrapper. this call creates
the device object that is exposed to FreeBasic
*/
DLL_EXPORT bool BBCALL iKlangInit( void )
{
	bool boInitStatus = true;
	// start the sound engine with default parameters
	engine = createIrrKlangDevice();

	if (!engine)
	{
		boInitStatus = false; // error starting up the engine
	}
    return boInitStatus;
}


/* ----------------------------------------------------------------------------
Update the IrrKlang system when running in single threaded mode
*/
DLL_EXPORT void BBCALL iKlangUpdate ( void )
{
    // updated the irrklang system when running in single threaded mode
    engine->update();
}


/* ----------------------------------------------------------------------------
Set the global sound volume
*/
DLL_EXPORT void BBCALL iMasterVolume ( float volume )
{
    // end the scene and display it
    engine->setSoundVolume( volume );
}


/* ----------------------------------------------------------------------------
Play a 2D sound
*/
DLL_EXPORT ISound * BBCALL iPlaySound (
								const char * file,
								bool playLooped,
								bool startPaused,
								bool track,
								E_STREAM_MODE streamMode,
								bool enableSoundEffects )
{
	return engine->play2D( file, playLooped, startPaused, track, streamMode,enableSoundEffects );
}

/* ----------------------------------------------------------------------------
Pause all sounds
*/
DLL_EXPORT void BBCALL iPauseAllSounds( bool pause )
{
	// pause all sounds
	engine->setAllSoundsPaused( pause );
}


/* ----------------------------------------------------------------------------
Stop all sounds
*/
DLL_EXPORT void BBCALL iStopAllSounds ()
{
	// pause all sounds
	engine->stopAllSounds();
}

/* ----------------------------------------------------------------------------
Release a sound
*/
DLL_EXPORT void BBCALL iFreeSound ( ISound * sound )
{
    // release the sound resourse
    sound->drop();
}


/* ----------------------------------------------------------------------------
Remove a specific sound file from memory
*/
DLL_EXPORT void BBCALL iFreeSoundFile ( const char * file )
{
    // remove a specific sound file from memory
    engine->removeSoundSource( file );
}


/* ----------------------------------------------------------------------------
Stop all sounds and remove all sound files from memory
*/
DLL_EXPORT void BBCALL iFreeAllSoundFiles ( void )
{
    // begin the scene
	engine->removeAllSoundSources();
}


/* ----------------------------------------------------------------------------
Stop the sound engine
*/
DLL_EXPORT void BBCALL iKlangEnd( void )
{
	engine->drop();
}


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