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 sound_res_mgr.cxx,NONE,1.1 soun


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/sound sound_res_mgr.cxx,NONE,1.1 sound_res_mgr.hxx,NONE,1.1 Makefile.am,1.1,1.2 sound.cxx,1.2,1.3 sound.hxx,1.1,1.2 sound_real.cxx,1.3,1.4 sound_real.hxx,1.1,1.2
Date: 4 Mar 2003 13:59:46 -0000

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

Modified Files:
        Makefile.am sound.cxx sound.hxx sound_real.cxx sound_real.hxx 
Added Files:
        sound_res_mgr.cxx sound_res_mgr.hxx 
Log Message:
fixed memleak in sound


--- NEW FILE: sound_res_mgr.cxx ---
//  $Id: sound_res_mgr.cxx,v 1.1 2003/03/04 13:59:44 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 <ClanLib/sound.h>
#include "../path_manager.hxx"
#include "../globals.hxx"
#include "../debug.hxx"
#include "sound_res_mgr.hxx"

SoundResMgr::SoundMap SoundResMgr::sound_map;

SoundHandle
SoundResMgr::load(const std::string& name)
{
  SoundMap::iterator i = sound_map.find(name);

  if (i == sound_map.end())
    {
      std::string filename = path_manager.complete("sounds/" + name + ".wav");
      CL_SoundBuffer* buffer = new CL_SoundBuffer (new CL_Sample(filename, 
NULL), true); 
      pout(PINGUS_DEBUG_LOADING) << "SoundResMgr: Loading sound from disk: " 
                                 << name << " -> " << filename << std::endl;

      sound_map[name] = buffer;
      return buffer;
    }
  else
    {
      pout(PINGUS_DEBUG_LOADING) << "SoundResMgr: Loading sound from cache: " 
<< name << std::endl;
      return i->second;
    }
}

/* EOF */

--- NEW FILE: sound_res_mgr.hxx ---
//  $Id: sound_res_mgr.hxx,v 1.1 2003/03/04 13:59:44 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_SOUND_RES_MGR_HXX
#define HEADER_PINGUS_SOUND_RES_MGR_HXX

#include <map>

class CL_SoundBuffer;

typedef CL_SoundBuffer* SoundHandle;

/** */
class SoundResMgr
{
private:
  typedef std::map<std::string, CL_SoundBuffer*> SoundMap;
  static SoundMap sound_map;

public:
  static SoundHandle load(const std::string& name);

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

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sound/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am 18 Feb 2003 17:30:32 -0000      1.1
+++ Makefile.am 4 Mar 2003 13:59:44 -0000       1.2
@@ -21,6 +21,6 @@
 libpingus_sound_a_SOURCES = \
        sound.cxx  sound_dummy.cxx  sound_real.cxx \
        sound.hxx  sound_dummy.hxx  sound_real.hxx \
-        sounds.hxx
+        sounds.hxx sound_res_mgr.hxx sound_res_mgr.cxx
 
 # EOF #

Index: sound.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sound/sound.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sound.cxx   19 Feb 2003 11:33:00 -0000      1.2
+++ sound.cxx   4 Mar 2003 13:59:44 -0000       1.3
@@ -65,10 +65,10 @@
     @param filename The complete filename */
    
 void 
-PingusSound::play_sound(const std::string & filename, float volume, float 
panning)
+PingusSound::play_sound(const std::string& name, float volume, float panning)
 {
   assert (sound);
-  sound->real_play_sound (path_manager.complete (filename), volume, panning);
+  sound->real_play_sound(name, volume, panning);
 }
 
 void
@@ -99,13 +99,13 @@
 
 /** Load a sound file and play it immediately.
     
-    @param filename The complete filename 
+    @param name
     @param volume   volume */
 void 
-PingusSound::play_music(const std::string & filename, float volume)
+PingusSound::play_music(const std::string & name, float volume)
 {
   assert (sound);
-  sound->real_play_music(path_manager.complete ("music/" + filename), volume);
+  sound->real_play_music(path_manager.complete ("music/" + name), volume);
 }
 
 void

Index: sound.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sound/sound.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sound.hxx   18 Feb 2003 17:30:32 -0000      1.1
+++ sound.hxx   4 Mar 2003 13:59:44 -0000       1.2
@@ -32,8 +32,8 @@
 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_play_sound(const std::string & name, float volume, float 
panning) =0;
+  virtual void real_play_music(const std::string & name, float volume) =0;
   virtual void real_stop_music() =0;
 
 public:
@@ -42,12 +42,12 @@
 
   /** Load a sound file and play it immediately.
 
-      @param filename The complete filename 
+      @param name     Name of the sound, aka 'ohno'
       @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_sound(const std::string & name, float volume = 1.0f, float 
panning = 0.0f);
   
-  static void play_music(const std::string & filename, float volume = 1.0f);
+  static void play_music(const std::string & name, float volume = 1.0f);
   static void stop_music();
 
   static void play_sound(Sound::Name name, float volume = 1.0f, float panning 
= 0.0f);

Index: sound_real.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sound/sound_real.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sound_real.cxx      20 Feb 2003 19:20:09 -0000      1.3
+++ sound_real.cxx      4 Mar 2003 13:59:44 -0000       1.4
@@ -23,6 +23,7 @@
 
 #include "../globals.hxx"
 #include "../debug.hxx"
+#include "sound_res_mgr.hxx"
 #include "sound_real.hxx"
 
 #ifdef HAVE_LIBCLANVORBIS
@@ -77,30 +78,20 @@
 };
 
 void
-PingusSoundReal::real_play_sound(const std::string & filename, float volume, 
float panning)
+PingusSoundReal::real_play_sound(const std::string& name, 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();
+    buffer = SoundResMgr::load(name);
+    sess   = buffer->prepare();
   } catch (const CL_Error & e) {
-    perr(PINGUS_DEBUG_SOUND) << "Can't open file " << filename << " -- 
skipping\n"
+    perr(PINGUS_DEBUG_SOUND) << "Can't open sound '" << name << "' -- 
skipping\n"
                             << "  CL_Error: " << e.message << std::endl;    
     return;
   }

Index: sound_real.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/sound/sound_real.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sound_real.hxx      18 Feb 2003 17:30:32 -0000      1.1
+++ sound_real.hxx      4 Mar 2003 13:59:44 -0000       1.2
@@ -41,9 +41,6 @@
   /** Music Controller Session */
   CL_SoundBuffer_Session* music_session;
 
-  /** Stores all Sound Effects */
-  std::vector<CL_SoundBuffer*> sound_holder;
-
 public:
   PingusSoundReal ();
   virtual ~PingusSoundReal ();





reply via email to

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