pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src plf_res_mgr.cxx,NONE,1.1 plf_res_mgr.


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src plf_res_mgr.cxx,NONE,1.1 plf_res_mgr.hxx,NONE,1.1 Makefile.am,1.135,1.136 pingus_main.cxx,1.49,1.50 pingus_resource.cxx,1.23,1.24 pingus_resource.hxx,1.12,1.13 theme.cxx,1.13,1.14
Date: 4 Mar 2003 10:26:20 -0000

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

Modified Files:
        Makefile.am pingus_main.cxx pingus_resource.cxx 
        pingus_resource.hxx theme.cxx 
Added Files:
        plf_res_mgr.cxx plf_res_mgr.hxx 
Log Message:
splitted PLF stuff from  PingusResource to reduce dependencies a bit


--- NEW FILE: plf_res_mgr.cxx ---
//  $Id: plf_res_mgr.cxx,v 1.1 2003/03/04 10:26:18 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 "plf.hxx"
#include "globals.hxx"
#include "debug.hxx"
#include "system.hxx"
#include "path_manager.hxx"
#include "plf_res_mgr.hxx"

PLFResMgr::PLFMap PLFResMgr::plf_map;

PLFHandle 
PLFResMgr::load_plf_raw(const std::string& res_name,
                        const std::string& filename)
{
  pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from disk: '" << 
res_name << "' -> '" << filename << "'" << std::endl;

  PLF* plf = PLF::create(filename);
  
  plf_map[res_name]  = plf;

  return PLFHandle (plf);
}

PLFHandle
PLFResMgr::load_plf_from_filename(const std::string& filename)
{
  // FIXME: This should reload levels if they have changed on disk

  // FIXME: Might cut of the 'playable/' or 'wip/' directories, not so
  // good. saving the PLF's under filenames would also lead to
  // throuble, since multiple filenames can map to the same file
  // (../../data/levels/bla.xml, ../levels/bla.xml, etc.)
  std::string res_name = System::basename(filename); 
  res_name = res_name.substr(0, res_name.length()-4);
  
  PLFMap::iterator i = plf_map.find(res_name);

  if (i == plf_map.end ())
    {
      return load_plf_raw (res_name, filename);
    }
  else
    {
      pout(PINGUS_DEBUG_LOADING) 
        << "PLFResMgr: Loading level from cache: '" << res_name << "' -> '" << 
filename << "'" << std::endl;
      return PLFHandle (i->second);
    }
}

PLFHandle
PLFResMgr::load_plf(const std::string& res_name)
{
  std::string filename = path_manager.complete("levels/" + res_name + ".xml");
  PLFMap::iterator i   = plf_map.find(res_name);

  if (i == plf_map.end ())
    {
      pout(PINGUS_DEBUG_LOADING) 
        << "PLFResMgr: Loading level from cache: '" << res_name << "' -> '" << 
filename << "'" << std::endl;
      return load_plf_raw (res_name, filename);
    }
  else
    {
      return PLFHandle (i->second);
    }
}

/* EOF */

--- NEW FILE: plf_res_mgr.hxx ---
//  $Id: plf_res_mgr.hxx,v 1.1 2003/03/04 10:26:18 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_PLF_RES_MGR_HXX
#define HEADER_PINGUS_PLF_RES_MGR_HXX

#include "plf_handle.hxx"

/** */
class PLFResMgr
{
private:
  typedef std::map<std::string, PLF*> PLFMap; 
  static  PLFMap plf_map;

  /** Loads PLF from filename and stores it under 'res_name' in the
      map */
  static PLFHandle load_plf_raw(const std::string& res_name,
                                const std::string& filename);
public:
  /** @returns a handle to the PLF, which the caller *must not* delete

      @param res_name The resource name of the level, aka "snow11-grumbel"
   */
  static PLFHandle load_plf(const std::string& res_name);

  /** @return a handle to the PLF, instead of loading it from a
      res_name, load it from a system dependend filename 
  
      @param filename The filename of the plf, aka 
"../data/levels/snow11-grumbel.xml" */
  static PLFHandle load_plf_from_filename(const std::string& filename); 
};

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -d -r1.135 -r1.136
--- Makefile.am 19 Feb 2003 23:03:51 -0000      1.135
+++ Makefile.am 4 Mar 2003 10:26:18 -0000       1.136
@@ -224,6 +224,8 @@
 playfield_view.hxx \
 plf.cxx \
 plf.hxx \
+plf_res_mgr.hxx \
+plf_res_mgr.cxx \
 plt_xml.cxx \
 plt_xml.hxx \
 prefab.cxx \

Index: pingus_main.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- pingus_main.cxx     3 Mar 2003 20:32:18 -0000       1.49
+++ pingus_main.cxx     4 Mar 2003 10:26:18 -0000       1.50
@@ -69,6 +69,7 @@
 #include "config_xml.hxx"
 #include "console.hxx"
 #include "fps_counter.hxx"
+#include "plf_res_mgr.hxx"
 #include "game_session.hxx"
 #include "demo_session.hxx"
 #include "debug.hxx"
@@ -725,7 +726,8 @@
             } 
           else
             {
-              ScreenManager::instance()->push_screen(new PingusGameSession 
(PingusResource::load_plf_raw(levelfile)), true);
+              ScreenManager::instance()->push_screen
+                (new PingusGameSession 
(PLFResMgr::load_plf_from_filename(levelfile)), true);
             }
         }    
     }

Index: pingus_resource.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_resource.cxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- pingus_resource.cxx 3 Mar 2003 20:32:18 -0000       1.23
+++ pingus_resource.cxx 4 Mar 2003 10:26:18 -0000       1.24
@@ -33,13 +33,11 @@
 #include "pingus_resource.hxx"
 #include "blitter.hxx"
 #include "debug.hxx"
-#include "plf.hxx"
 #include "debug.hxx"
 
 std::map<std::string, CL_ResourceManager*> PingusResource::resource_map;
 std::map<ResDescriptor, CL_Surface>        PingusResource::surface_map;
 std::map<ResDescriptor, CL_Font*>          PingusResource::font_map;
-PingusResource::PLFMap PingusResource::plf_map;
 
 void 
 PingusResource::init()
@@ -337,49 +335,6 @@
       std::cout << "PingusResource::get_mtime: CL_Error: " << err.message << 
std::endl;
       return 0;
     }
-}
-
-PLFHandle
-PingusResource::load_plf_raw(const std::string& filename)
-{
-  std::string res_name = System::basename(filename);
-  res_name = res_name.substr(0, res_name.length()-4);
-  
-  pout(PINGUS_DEBUG_LOADING) << "PingusResource: Loading level: '" << res_name 
<< "' -> '" << filename << "'" << std::endl;
-
-  PLFMap::iterator i = plf_map.find(res_name);
-
-  if (i == plf_map.end ())
-    {
-      PLF* plf = PLF::create(filename);
-      plf_map[res_name]  = plf;
-      return PLFHandle (plf);
-    }
-  else
-    {
-      return PLFHandle (i->second);
-    }
-}
-
-PLFHandle
-PingusResource::load_plf(const std::string& res_name)
-{
-  PLFMap::iterator i   = plf_map.find(res_name);
-  std::string filename = path_manager.complete("levels/" + res_name + ".xml");
-
-  pout(PINGUS_DEBUG_LOADING) << "PingusResource: Loading level: '" << res_name 
<< "' -> '" << filename << "'" << std::endl;
-
-  if (i == plf_map.end ())
-    {
-      PLF* plf = PLF::create(filename);
-      plf_map[res_name]  = plf;
-      return PLFHandle (plf);
-    }
-  else
-    {
-      return PLFHandle (i->second);
-    }
-
 }
 
 /* EOF */

Index: pingus_resource.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_resource.hxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pingus_resource.hxx 3 Mar 2003 20:32:18 -0000       1.12
+++ pingus_resource.hxx 4 Mar 2003 10:26:18 -0000       1.13
@@ -23,7 +23,6 @@
 #include <map>
 
 #include <ClanLib/Display/Display/surface.h>
-#include "plf_handle.hxx"
 #include "res_descriptor.hxx"
 
 class CL_Font;
@@ -35,9 +34,6 @@
 class PingusResource
 {
 private:
-  typedef std::map<std::string, PLF*> PLFMap; 
-  static  PLFMap plf_map;
-
   static std::map<std::string, CL_ResourceManager*> resource_map;
   static std::map<ResDescriptor, CL_Surface> surface_map;
   static std::map<ResDescriptor, CL_Font*> font_map;
@@ -53,13 +49,6 @@
   /** */
   static unsigned int get_mtime (const std::string& res_name,
                                 const std::string& datafile);
-
-  /** @returns a handle to the PLF, which the caller *must not* delete */
-  static PLFHandle load_plf(const std::string& res_name);
-
-  /** @return a handle to the PLF, instead of loading it from a
-      res_name, load it from a system dependend filename */
-  static PLFHandle load_plf_raw(const std::string& filename);
 
   /** Load a surface with res_name from datafile */
   static CL_Surface load_surface(const std::string& res_name,

Index: theme.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/theme.cxx,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- theme.cxx   3 Mar 2003 20:32:18 -0000       1.13
+++ theme.cxx   4 Mar 2003 10:26:18 -0000       1.14
@@ -28,6 +28,7 @@
 #include "system.hxx"
 #include "pingus_resource.hxx"
 #include "pingus_error.hxx"
+#include "plf_res_mgr.hxx"
 #include "game_session.hxx"
 #include "globals.hxx"
 #include "theme.hxx"
@@ -262,7 +263,7 @@
       assert (!"Theme::play unimplemented");
       
       ScreenManager::instance()->push_screen
-       (new 
PingusGameSession(PingusResource::load_plf(plt.get_levels()[current_level])));
+       (new 
PingusGameSession(PLFResMgr::load_plf(plt.get_levels()[current_level])));
 
       if (current_level == accessible_levels)
        ++accessible_levels;





reply via email to

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