pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] [pingus] 2 new revisions pushed by address@hidden on 2012-0


From: pingus
Subject: [Pingus-CVS] [pingus] 2 new revisions pushed by address@hidden on 2012-08-07 21:45 GMT
Date: Tue, 07 Aug 2012 21:46:34 +0000

2 new revisions:

Revision: f1031ba8786b
Author:   Ingo Ruhnke <address@hidden>
Date:     Tue Aug  7 05:39:37 2012
Log:      Added support for the XDG Base Directory Specification
http://code.google.com/p/pingus/source/detail?r=f1031ba8786b

Revision: 81abd0b34232
Author:   Ingo Ruhnke <address@hidden>
Date:     Tue Aug  7 14:45:03 2012
Log: Throw an exception when Surface() creation fails instead of the object...
http://code.google.com/p/pingus/source/detail?r=81abd0b34232

==============================================================================
Revision: f1031ba8786b
Author:   Ingo Ruhnke <address@hidden>
Date:     Tue Aug  7 05:39:37 2012
Log:      Added support for the XDG Base Directory Specification

http://code.google.com/p/pingus/source/detail?r=f1031ba8786b

Modified:
 /src/util/system.cpp

=======================================
--- /src/util/system.cpp        Wed Dec 28 18:42:46 2011
+++ /src/util/system.cpp        Tue Aug  7 05:39:37 2012
@@ -317,16 +317,39 @@
        }

 #else /* !WIN32 */
-  char* homedir = getenv("HOME");
+  // If ~/.pingus/ exist, use that for backward compatibility reasons,
+  // if it does not, use $XDG_CONFIG_HOME, see:
+  // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

-  if (homedir)
+  { // check for ~/.pingus/
+    char* homedir = getenv("HOME");
+    if (homedir && strcmp(homedir, "") != 0)
+    {
+ std::string old_pingus_config_dir = std::string(homedir) + "/.pingus/";
+      if (exist(old_pingus_config_dir))
+      {
+        return old_pingus_config_dir;
+      }
+    }
+  }
+
+  char* config_dir = getenv("XDG_CONFIG_HOME");
+  if (!config_dir || strcmp(config_dir, "") == 0)
   {
-    return std::string(homedir) + "/.pingus/";
+    char* homedir = getenv("HOME");
+    if (homedir && strcmp(homedir, "") != 0)
+    {
+      return std::string(homedir) + "/.config/pingus/";
+    }
+    else
+    {
+ raise_exception(std::runtime_error, "can't find userdir as neither $HOME nor $XDG_CONFIG_HOME is set");
+    }
   }
   else
   {
- raise_exception(std::runtime_error, "Environment variable $HOME not set, fix that and start again.");
-  }
+    return std::string(config_dir) + "/pingus/";
+  }
 #endif
 }


==============================================================================
Revision: 81abd0b34232
Author:   Ingo Ruhnke <address@hidden>
Date:     Tue Aug  7 14:45:03 2012
Log: Throw an exception when Surface() creation fails instead of the object getting invalid

Fixes issue 132

http://code.google.com/p/pingus/source/detail?r=81abd0b34232

Modified:
 /src/engine/display/font.cpp
 /src/engine/display/sdl_framebuffer.cpp
 /src/engine/display/sprite_impl.cpp
 /src/engine/display/surface.cpp
 /src/engine/display/surface.hpp

=======================================
--- /src/engine/display/font.cpp        Thu Oct 13 19:03:23 2011
+++ /src/engine/display/font.cpp        Tue Aug  7 14:45:03 2012
@@ -49,13 +49,14 @@
     // Copyh Unicode -> Glyph mapping
for(std::vector<GlyphImageDescription>::size_type j = 0; j < desc.images.size(); ++j)
     {
- framebuffer_surfaces.push_back(Display::get_framebuffer()->create_surface(Surface(desc.images[j].pathname)));
-
-      if (!framebuffer_surfaces.back())
+      Surface surface(desc.images[j].pathname);
+      if (!surface)
       {
         log_info("IMG: " << desc.images[j].pathname.str());
         assert(false);
       }
+
+ framebuffer_surfaces.push_back(Display::get_framebuffer()->create_surface(surface));

for(std::vector<GlyphDescription>::const_iterator i = desc.images[j].glyphs.begin();
           i != desc.images[j].glyphs.end();
=======================================
--- /src/engine/display/sdl_framebuffer.cpp     Thu Oct 13 19:34:13 2011
+++ /src/engine/display/sdl_framebuffer.cpp     Tue Aug  7 14:45:03 2012
@@ -149,14 +149,7 @@
 FramebufferSurface
 SDLFramebuffer::create_surface(const Surface& surface)
 {
-  if (surface)
-  {
- return FramebufferSurface(new SDLFramebufferSurfaceImpl(surface.get_surface()));
-  }
-  else
-  {
-    return FramebufferSurface();
-  }
+ return FramebufferSurface(new SDLFramebufferSurfaceImpl(surface.get_surface()));
 }

 void
=======================================
--- /src/engine/display/sprite_impl.cpp Thu Oct 13 19:03:23 2011
+++ /src/engine/display/sprite_impl.cpp Tue Aug  7 14:45:03 2012
@@ -24,20 +24,22 @@
FramebufferSurface load_framebuffer_surface(const Pathname& filename, ResourceModifier::Enum modifier)
 {
   // FIXME: Implement proper cache
-  Surface surface(filename);
-  if (modifier != ResourceModifier::ROT0)
+  try
   {
-    surface = surface.mod(modifier);
+    Surface surface(filename);
+    if (modifier != ResourceModifier::ROT0)
+    {
+      surface = surface.mod(modifier);
+    }
+    return Display::get_framebuffer()->create_surface(surface);
   }
-
-  if (!surface)
+  catch(const std::exception& err)
   {
-    log_error("couldn't load '" << filename << "'");
- surface = Surface(Pathname("images/core/misc/404.png", Pathname::DATA_PATH));
-    if (!surface) assert(!"Surface Couldn't find 404");
+    // return a dummy surface for cases where the image file can't be found
+    log_error(err.what());
+ Surface surface(Pathname("images/core/misc/404.png", Pathname::DATA_PATH));
+    return Display::get_framebuffer()->create_surface(surface);
   }
-
-  return Display::get_framebuffer()->create_surface(surface);
 }

 SpriteImpl::SpriteImpl() :
=======================================
--- /src/engine/display/surface.cpp     Thu Dec 29 14:49:33 2011
+++ /src/engine/display/surface.cpp     Tue Aug  7 14:45:03 2012
@@ -18,10 +18,12 @@

 #include <SDL_image.h>
 #include <boost/format.hpp>
+#include <stdexcept>

 #include "engine/display/blitter.hpp"
 #include "math/rect.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 class SurfaceImpl
 {
@@ -65,14 +67,18 @@
   impl()
 {
   SDL_Surface* surface = IMG_Load(pathname.get_sys_path().c_str());
-  if (surface)
+  if (!surface)
   {
-    impl = std::shared_ptr<SurfaceImpl>(new SurfaceImpl(surface));
+    raise_exception(std::runtime_error, "couldn't load: " << pathname);
+  }
+  else
+  {
+    impl.reset(new SurfaceImpl(surface));
   }
 }

-Surface::Surface(int width, int height, SDL_Palette* palette, int colorkey)
-  : impl(new SurfaceImpl())
+Surface::Surface(int width, int height, SDL_Palette* palette, int colorkey) :
+  impl(new SurfaceImpl)
 {
   if (colorkey == -1)
   {
=======================================
--- /src/engine/display/surface.hpp     Thu Dec 29 06:49:15 2011
+++ /src/engine/display/surface.hpp     Tue Aug  7 14:45:03 2012
@@ -34,8 +34,6 @@
 public:
   Surface();

-  Surface(std::shared_ptr<SurfaceImpl> impl);
-
   Surface(const Pathname& name);

   /** Create an empty RGBA Surface */
@@ -80,7 +78,9 @@

   void print(std::ostream& out);

-protected:
+private:
+  Surface(std::shared_ptr<SurfaceImpl> impl);
+
   std::shared_ptr<SurfaceImpl> impl;
 };




reply via email to

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