pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/sound Makefile.am,NONE,1.1 slot_manag


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/sound Makefile.am,NONE,1.1 slot_manager.cxx,NONE,1.1 slot_manager.hxx,NONE,1.1 sound.cxx,NONE,1.1 sound.hxx,NONE,1.1 sound_dummy.cxx,NONE,1.1 sound_dummy.hxx,NONE,1.1 sound_real.cxx,NONE,1.1 sound_real.hxx,NONE,1.1 sounds.hxx,NONE,1.1
Date: 18 Feb 2003 17:30:35 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/sound
In directory dark:/tmp/cvs-serv6134

Added Files:
        Makefile.am slot_manager.cxx slot_manager.hxx sound.cxx 
        sound.hxx sound_dummy.cxx sound_dummy.hxx sound_real.cxx 
        sound_real.hxx sounds.hxx 
Log Message:
added sound/ subdirectory


--- NEW FILE: Makefile.am ---
# Pingus - A free Lemmings clone
# Copyright (C) 1999 Ingo Ruhnke <address@hidden>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# -- Static Libs --
noinst_LIBRARIES = libpingus_sound.a

libpingus_sound_a_SOURCES = \
        sound.cxx  sound_dummy.cxx  sound_real.cxx \
        sound.hxx  sound_dummy.hxx  sound_real.hxx \
        sounds.hxx

# EOF #

--- NEW FILE: slot_manager.cxx ---
//  $Id: slot_manager.cxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "slot_manager.hxx"

SlotEntry& find_slot(const std::string& name)
{
  
}

void
SlotManager::play_sound(const std::string& name)
{
  CL_SoundBuffer         * buffer;
  CL_SoundBuffer_Session sess;
  
  try {
    buffer = new CL_SoundBuffer (new CL_Sample(filename.c_str(), NULL), true);
    sess   = buffer -> prepare();
  } catch (const CL_Error & e) {
    perr(PINGUS_DEBUG_SOUND) << "Can't open file " << filename << " -- 
skipping\n"
                             << "  CL_Error: " << e.message << std::endl;    
    return;
  }
  
  sess.set_volume(volume);
  sess.set_pan(panning);
  sess.set_looping(false);
  sess.play();  
}

/* EOF */

--- NEW FILE: slot_manager.hxx ---
//  $Id: slot_manager.hxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_SLOT_MANAGER_HXX
#define HEADER_PINGUS_SLOT_MANAGER_HXX

namespace Sound {

struct SlotEntry
{
  /** Name of the sound effect */
  std::string name; 

  /** Time when the last sound playback started */
  unsigned int last_time;

  /** The data of this sound effect */
  CL_SoundBuffer* buffer;

  /** Currently active sessinos playing the sound effect */
  std::vector<CL_SoundBuffer_Session> sessions;
};

/** Manager class for sound slots, if a sound effect gets played it
    will be placed in a slot, if the same effect gets played again and
    the slot is still busy it won't get played again */
class SlotManager
{
private:
  std::map<std::string, SlotEntry> slots;
  
public:
  SlotManager();

  void play_sound(const std::string& name);
  
private:
  SlotEntry& find_slot(const std::string& name);

  SlotManager (const Slot_Manager&);
  SlotManager& operator= (const Slot_Manager&);
};

} // namespace Sound

#endif

/* EOF */

--- NEW FILE: sound.cxx ---
//  $Id: sound.cxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <iostream>
#include <assert.h>
#include "../path_manager.hxx"
#include "../globals.hxx"
#include "sound_dummy.hxx"
#include "sound_real.hxx"

PingusSound* PingusSound::sound;

using namespace Sound;

void
PingusSound::init (PingusSound* s)
{
  if (s == 0)
    {
      if (sound_enabled || music_enabled) 
        {
          if (verbose)
            std::cout << "Init Sound" << std::endl;

          PingusSound::init (new PingusSoundReal ());
        }
      else
        {
          if (verbose)
            std::cout << "Sound disabled" << std::endl;
          PingusSound::init (new PingusSoundDummy ());
        }
    }
  else
    {
      sound = s;
    }
}

void
PingusSound::deinit ()
{
  delete sound;
  sound = 0;
}

/** Load a sound file and play it immediately.
    
    @param filename The complete filename */
   
void 
PingusSound::play_sound(const std::string & filename, float volume, float 
panning)
{
  assert (sound);
  sound->real_play_sound (path_manager.complete (filename), volume, panning);
}

void
PingusSound::play_sound(Sound::Name name, float volume, float panning)
{
  // FIXME: We need to return a handle to the sound

  // This should be configurable via a .xml file
  switch (name)
    {
    case Sound::DIGGER:
      play_sound (path_manager.complete ("sounds/digger.wav"), volume, panning);
      break;
    case Sound::PLOP:
      play_sound (path_manager.complete ("sounds/plop.wav"), volume, panning);
      break;
    case Sound::GOODIDEA:
      play_sound (path_manager.complete ("sounds/goodidea.wav"), volume, 
panning);
      break;
    case Sound::OHNO:
      play_sound (path_manager.complete ("sounds/ohno.wav"), volume, panning);
      break;
    case Sound::TICK:
      play_sound (path_manager.complete ("sounds/tick.wav"), volume, panning);
      break;
    }
}

/** Load a sound file and play it immediately.
    
    @param filename The complete filename 
    @param volume   volume */
void 
PingusSound::play_music(const std::string & filename, float volume)
{
  assert (sound);
  sound->real_play_music(path_manager.complete (filename), volume);
}

void
PingusSound::stop_music()
{
  assert(sound);
  sound->real_stop_music();
}

/* EOF */


--- NEW FILE: sound.hxx ---
//  $Id: sound.hxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_SOUND_HXX
#define HEADER_PINGUS_SOUND_HXX

#include <string>
#include "sounds.hxx"

class PingusSound
{
protected: 
  /** FIXME: this should be SoundImpl, not PingusSound */
  static PingusSound* sound;
  
protected:
  PingusSound () { }

  virtual void real_play_sound(const std::string & filename, float volume, 
float panning) =0;
  virtual void real_play_music(const std::string & filename, float volume) =0;
  virtual void real_stop_music() =0;

public:
  static void init (PingusSound* s = 0);
  static void deinit ();

  /** Load a sound file and play it immediately.

      @param filename The complete filename 
      @param volume   volume
      @param panning  panning */
  static void play_sound(const std::string & filename, float volume = 1.0f, 
float panning = 0.0f);
  
  static void play_music(const std::string & filename, float volume = 1.0f);
  static void stop_music();

  static void play_sound(Sound::Name name, float volume = 1.0f, float panning = 
0.0f);
  
private:
  PingusSound (const PingusSound&);
  PingusSound& operator= (const PingusSound&);
};

#endif

/* EOF */

--- NEW FILE: sound_dummy.cxx ---
//  $Id: sound_dummy.cxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "../globals.hxx"
#include "../debug.hxx"
#include "sound_dummy.hxx"

namespace Sound {

void 
PingusSoundDummy::real_play_sound(const std::string & filename, float 
/*volume*/, float /*panning*/)
{
  pout(PINGUS_DEBUG_SOUND) << "PingusSoundDummy::real_play_sound: " << filename 
<< std::endl;
}


void 
PingusSoundDummy::real_play_music(const std::string & filename, float 
/*volume*/)
{
  pout(PINGUS_DEBUG_SOUND) << "PingusSoundDummy::real_play_music: " << filename 
<< std::endl;
}

void
PingusSoundDummy::real_stop_music()
{
}

} // namespace Sound

/* EOF */


--- NEW FILE: sound_dummy.hxx ---
//  $Id: sound_dummy.hxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_SOUND_DUMMY_HXX
#define HEADER_PINGUS_SOUND_DUMMY_HXX

#include "sound.hxx"

namespace Sound {

class PingusSoundDummy : public PingusSound
{
public:
  PingusSoundDummy () { }

  virtual void real_play_sound (const std::string & filename, float volume, 
float panning);
  virtual void real_play_music (const std::string & filename, float volume);
  virtual void real_stop_music();
private:
  PingusSoundDummy (const PingusSoundDummy&);
  PingusSoundDummy& operator= (const PingusSoundDummy&);
};

} // namespace Sound

#endif

/* EOF */

--- NEW FILE: sound_real.cxx ---
//  $Id: sound_real.cxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


#include <ClanLib/sound.h>
#include <ClanLib/Core/System/error.h>

#include "../globals.hxx"
#include "../debug.hxx"
#include "sound_real.hxx"

#ifdef HAVE_LIBCLANVORBIS
#  include <ClanLib/vorbis.h>
#endif

#ifdef HAVE_LIBCLANMIKMOD
#  include <ClanLib/mikmod.h>
#  include <ClanLib/MikMod/setupmikmod.h>
#endif

namespace Sound {

PingusSoundReal::PingusSoundReal ()
  : music_sample (0), music_session(0)
{
  pout(PINGUS_DEBUG_SOUND) << "Initializing ClanLib-Sound" << std::endl;
    
  CL_SetupSound::init();
  
  pout(PINGUS_DEBUG_SOUND) << "Initializing ClanLib-MikMod" << std::endl;
  
#ifdef HAVE_LIBCLANVORBIS
  CL_SetupVorbis::init();
#endif

#ifdef HAVE_LIBCLANMIKMOD
  CL_SetupMikMod::init();
#endif
}

PingusSoundReal::~PingusSoundReal()
{
  real_stop_music();

#ifdef HAVE_LIBCLANMIKMOD
  CL_SetupMikMod::deinit();
#endif

#ifdef HAVE_LIBCLANVORBIS
  CL_SetupVorbis::init();
#endif

  CL_SetupSound::deinit();
}

struct sound_is_finished
{
  bool operator()(CL_SoundBuffer_Session& sess) {
    return !sess.is_playing();
  }
};

void
PingusSoundReal::real_play_sound(const std::string & filename, float volume, 
float panning)
{
  pout(PINGUS_DEBUG_SOUND) << "PingusSoundReal: Playing sound: " << filename << 
"Buffer-Size: " << sound_holder.size() << std::endl;

  if (!sound_enabled)
    return;


  std::cout << "FIXME: this is broken PingusSoundReal::real_play_sound(const 
std::string & filename, float volume, float panning)" << std::endl;
  // search for unused SoundBuffer_Sessions - clean them up
  /*sound_holder.erase(std::remove_if (sound_holder.begin (), sound_holder.end 
(), 
    sound_is_finished()),
    sound_holder.end());*/
          

  CL_SoundBuffer         * buffer;
  CL_SoundBuffer_Session sess;
  
  try {
    // FIXME: Memory hole, resource system or cache might help here
    buffer = new CL_SoundBuffer (new CL_Sample(filename.c_str(), NULL), true);
    sess   = buffer -> prepare();
  } catch (const CL_Error & e) {
    perr(PINGUS_DEBUG_SOUND) << "Can't open file " << filename << " -- 
skipping\n"
                             << "  CL_Error: " << e.message << std::endl;    
    return;
  }
  
  sess.set_volume(volume);
  sess.set_pan(panning);
  sess.set_looping(false);
  sess.play();  
}

void
PingusSoundReal::real_stop_music ()
{
  if (music_session)
    {
      music_session->stop();
      delete music_session;
      music_session = 0;

      if (music_sample)
        {
          delete music_sample;
          music_sample = NULL;
        }
    }
}

void
PingusSoundReal::real_play_music (const std::string & arg_filename, float 
volume)
{
  std::string filename;

  filename = arg_filename;

  if (!music_enabled)
    return;

  pout(PINGUS_DEBUG_SOUND) << "PingusSoundReal: Playing music: " << filename << 
std::endl;
  
  real_stop_music();

  music_sample = 0;

  if (filename.substr(filename.size()-4, 4) == ".ogg") 
    {
#ifdef HAVE_LIBCLANVORBIS
      music_sample = new CL_SoundBuffer (new 
CL_VorbisSoundProvider(filename.c_str()), true);
#else
      music_sample = 0;
#endif
    }
  else if (filename.substr(filename.size()-4, 4) == ".wav") 
    {
      music_sample = new CL_SoundBuffer (new CL_Sample(filename.c_str(), NULL), 
true);
    } 
  else
    {  // MikMod should support the rest...
#ifdef HAVE_LIBCLANMIKMOD
      music_sample = new CL_SoundBuffer (new 
CL_Streamed_MikModSample(filename.c_str()), true);
#else
      music_sample = 0;
#endif    
    }
  
  music_session = new CL_SoundBuffer_Session(music_sample->prepare());
  music_session->set_volume(volume);
  music_session->set_looping(false);
  music_session->play();
}

} // namespace Sound

/* EOF */


--- NEW FILE: sound_real.hxx ---
//  $Id: sound_real.hxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_SOUND_REAL_HXX
#define HEADER_PINGUS_SOUND_REAL_HXX

#include <config.h>
#include <vector>
#include "sound.hxx"
#include <ClanLib/Sound/soundbuffer_session.h>

class CL_SoundBuffer;
class CL_SoundBuffer_Session;

namespace Sound {

/** A simple wrapper class around SDL_Mixer, it will init itself
    automatically if a sound is played. */
class PingusSoundReal : public PingusSound
{
private:
  /** The current music file */
  CL_SoundBuffer * music_sample;

  /** Music Controller Session */
  CL_SoundBuffer_Session* music_session;

  /** Stores all Sound Effects */
  std::vector<CL_SoundBuffer*> sound_holder;

public:
  PingusSoundReal ();
  virtual ~PingusSoundReal ();

  /** Load a music file and play it immediately.

      @param filename The complete filename
      @param volume   The volume to play the music with  */
  virtual void real_play_music(const std::string & filename, float volume);

  virtual void real_stop_music();

  /** Load a sound file and play it immediately
  
      @param filename The complete filename
      @param volume   The volume to play the sound at 
      @param panning  The panning to play the sound with */

  virtual void real_play_sound(const std::string & filename, float volume, 
float panning);

private:
  PingusSoundReal (const PingusSoundReal&);
  PingusSoundReal& operator= (const PingusSoundReal&);  
};

} // namespace Sound

#endif

/* EOF */

--- NEW FILE: sounds.hxx ---
//  $Id: sounds.hxx,v 1.1 2003/02/18 17:30:32 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_SOUNDS_HXX
#define HEADER_PINGUS_SOUNDS_HXX

#include "../pingus.hxx"

namespace Sound
{
  enum Name {
    DIGGER,
    PLOP,
    GOODIDEA,
    OHNO,
    TICK
  };
}

#endif

/* EOF */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]