/*****************************************************************************
 * $LastChangedDate: 2011-04-23 21:07:07 -0400 (Sat, 23 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Collision-detection class.
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef COLLISION_COLLISION_HH
#define COLLISION_COLLISION_HH 1

#define GET_COLLISION() (Collision::GetInstance())

#include <set>
#include "base/singleton.hh"
using namespace base;
#include "object/module.hh"
#include "object/dyna.hh"
#include "object/events.hh"
using namespace object;

namespace collision {

////////////////////////////////////////////////////////////////////////////////
/// @brief Collision-detection class (Singleton).
///
/// Broadcasts the event of a pair of Objects colliding.
///
/// For factoring, this class is kept simple.
/// Extended actions (the testing of collisions, how to handle them,
/// storing colliders, etc) is delegated to clients (the Dyna class).
///
class Collision : public Singleton, public Threadable
{
PREVENT_COPYING(Collision)
private:
    Collision( void );
    ~Collision();

public:
    DEFINE_GetInstance( Collision )
    void                    Enable( const bool enable );
    bool                    IfEnabled( void );
    void                    SetCollidable( shptr<Object> object, const bool collidable );
    typedef Dyna::Colliders Colliders;
    const Colliders         GetCollisions( shptr<Dyna> dyna );

private:
    CLASS_DESTROY_OBJECT_LISTENER( Collision, mCollision )
    void                    Detach( shptr<Object> object );  // for destroy-object listener only

private:
    DECLARE_SINGLETON_CLASS_VARS( Collision )
    typedef std::set<shptr<Object> > Collidables;
    bool                        mEnabled;           ///< enable/disable collision-detection (affects nothing else)
    Collidables                 mCollidables;       ///< Objects that are collidable
};

} // namespace collision

#endif // COLLISION_COLLISION_HH
