/*
	Rogue Trader.
	Copyright (c) 2007, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef SOUNDSYSTEM_H
#define SOUNDSYSTEM_H

//##############################################################################
// Contains definitions needed by direct sound
//##############################################################################

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

// MMSYSTEM generates a nameless struct/union warning: disable it

#pragma warning(disable:4201)

	#include <mmsystem.h>
	
#pragma warning(default:4201)

//##############################################################################
// Forward references
//##############################################################################

class	GLWindow;
class	Sound;
struct	IDirectSound8;
struct	IDirectSoundBuffer8;

//##############################################################################
// Stuff that can't be forward referenced
//##############################################################################

#include <list>
using std::list;

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   SoundSystem
// Purpose:      Static class that provides a simple interface to directsound.
//               Allows Playback of sounds and loading of sounds. Only allows
//               one shot, non positional playback however. This is useful only
//               for non in game sounds such as those in menu systems and certain
//               types of sounds we want to always have heard.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class SoundSystem
{
    //--------------------------------------------------------------------------
    // SoundScene is a friend of the Sound System
    //--------------------------------------------------------------------------

    friend class SoundScene;

 public:

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Setup the sound system: should be done at program startup

        static void initialise();

        // Shut down the sound system: should be done at program end

        static void shutdown();

        // Stops all currently playing sounds:

        static void stopAll();

        // Play a given sound:

        static void playSound( const Sound * sound );

        // Load a sound: returns a pointer to a sound object created. does not retain ownership of this object.

        static Sound * loadSound( const char * fileName );
        
        // Tells if sound is enabled
        
        static bool isSoundEnabled();
        
        // Enables / disables sound
        
        static void setSoundEnabled(bool enabled);

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 protected:

        //----------------------------------------------------------------------
        // Functions:
        //----------------------------------------------------------------------

        // Release any sounds that are finished playing in the sounds list:

        static void releasedFinishedSounds();

        //----------------------------------------------------------------------
        // Variables
        //----------------------------------------------------------------------

        // The direct sound object:

        static IDirectSound8 * directSound;

        // The primary sound buffer:

        static IDirectSoundBuffer8 * primaryBuffer;

        // A linked list of currently playing sounds:

        static list<IDirectSoundBuffer8*> * soundsList;
        
        // True if sound is enabled
        
        static bool soundEnabled;

}; // end of: class SoundSystem{}

//##############################################################################
// C++ Includes
//##############################################################################

#include <dsound.h>
#include "GLWindow.h"
#include "Sound.h"

#endif // end of: ifndef SOUNDSYSTEM_H
