[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src plf_res_mgr.cxx,1.1,1.2 plf_res_mgr.h
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src plf_res_mgr.cxx,1.1,1.2 plf_res_mgr.hxx,1.1,1.2 system.cxx,1.8,1.9 system.hxx,1.7,1.8 |
Date: |
7 Mar 2003 18:49:23 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv20318
Modified Files:
plf_res_mgr.cxx plf_res_mgr.hxx system.cxx system.hxx
Log Message:
- added file-changed-on-disk test for plf-cache
- fixed typo in entrance gui
Index: plf_res_mgr.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/plf_res_mgr.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- plf_res_mgr.cxx 4 Mar 2003 10:26:18 -0000 1.1
+++ plf_res_mgr.cxx 7 Mar 2003 18:49:20 -0000 1.2
@@ -30,57 +30,74 @@
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;
+ PLFMap::iterator i = plf_map.find(res_name);
+
+ if (i == plf_map.end())
+ { // Entry not cached, so load it and add it to cache
+ pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from DISK: '" <<
res_name << "' -> '" << filename << "'" << std::endl;
- PLF* plf = PLF::create(filename);
+ PLF* plf = PLF::create(filename);
- plf_map[res_name] = plf;
+ PLFEntry entry;
- return PLFHandle (plf);
+ entry.plf = plf;
+ entry.mtime = System::get_mtime(filename);
+
+ plf_map[res_name] = entry;
+
+ // FIXME: leaking pointers to the outsite work is not such a good
+ // idea, could lead to throuble sooner or later
+ return PLFHandle (entry.plf);
+ }
+ else
+ {
+ unsigned int current_mtime = System::get_mtime(filename);
+ if (current_mtime != i->second.mtime)
+ {
+ delete i->second.plf;
+
+ pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: level changed on DISK,
reloading: '" << res_name << "' -> '" << filename << "'" << std::endl;
+
+ // Reload the file since it has changed on disk
+ PLF* plf = PLF::create(filename);
+
+ PLFEntry entry;
+
+ entry.plf = plf;
+ entry.mtime = System::get_mtime(filename);
+
+ plf_map[res_name] = entry;
+
+ // FIXME: leaking pointers to the outsite work is not such a good
+ // idea, could lead to throuble sooner or later
+ return PLFHandle (entry.plf);
+ }
+ else
+ { // File in cache is up to date, everything is already, return it
+ pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from CACHE:
'" << res_name << "' -> '" << filename << "'" << std::endl;
+
+ return i->second.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);
- }
+ return load_plf_raw(res_name.substr(0, res_name.length()-4),
+ filename);
}
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);
- }
+ return load_plf_raw(res_name,
+ path_manager.complete("levels/" + res_name + ".xml"));
}
/* EOF */
Index: plf_res_mgr.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/plf_res_mgr.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- plf_res_mgr.hxx 4 Mar 2003 10:26:18 -0000 1.1
+++ plf_res_mgr.hxx 7 Mar 2003 18:49:20 -0000 1.2
@@ -26,7 +26,12 @@
class PLFResMgr
{
private:
- typedef std::map<std::string, PLF*> PLFMap;
+ struct PLFEntry {
+ PLF* plf;
+ unsigned int mtime;
+ };
+
+ typedef std::map<std::string, PLFEntry> PLFMap;
static PLFMap plf_map;
/** Loads PLF from filename and stores it under 'res_name' in the
Index: system.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/system.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- system.cxx 4 Mar 2003 17:02:51 -0000 1.8
+++ system.cxx 7 Mar 2003 18:49:20 -0000 1.9
@@ -442,4 +442,14 @@
return to_string (checksum);
}
+unsigned int
+System::get_mtime(const std::string& filename)
+{
+ struct stat stat_buf;
+ if (stat(filename.c_str(), &stat_buf) == 0)
+ return stat_buf.st_mtime;
+ else
+ return 0;
+}
+
/* EOF */
Index: system.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/system.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- system.hxx 4 Mar 2003 17:02:51 -0000 1.7
+++ system.hxx 7 Mar 2003 18:49:20 -0000 1.8
@@ -119,6 +119,9 @@
/** Get the currently country code, in a two letter ISO 639 syntax */
static std::string get_language();
+ /** Return the modification time of a file */
+ static unsigned int get_mtime(const std::string& filename);
+
/** Choose the correct translation out of the map, if there is none
present, fall back to the default language */
static std::string translate(const std::map<std::string, std::string>& strs);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src plf_res_mgr.cxx,1.1,1.2 plf_res_mgr.hxx,1.1,1.2 system.cxx,1.8,1.9 system.hxx,1.7,1.8,
grumbel <=