pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3928 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3928 - trunk/pingus/src
Date: Tue, 29 Jul 2008 02:13:03 +0200

Author: grumbel
Date: 2008-07-29 02:13:02 +0200 (Tue, 29 Jul 2008)
New Revision: 3928

Modified:
   trunk/pingus/src/font.cpp
Log:
Replaced std::map with std::vector, this wastes a bit of memoory, but speeds up 
glyph lookup a lot

Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp   2008-07-28 23:32:51 UTC (rev 3927)
+++ trunk/pingus/src/font.cpp   2008-07-29 00:13:02 UTC (rev 3928)
@@ -31,7 +31,7 @@
 {
 public:
   FramebufferSurface framebuffer_surface;
-  typedef std::map<uint32_t, GlyphDescription> Glyphs;
+  typedef std::vector<GlyphDescription*> Glyphs;
   Glyphs glyphs; // FIXME: Use a hashmap or something else faster then a map
   int    space_length;
   float  char_spacing;
@@ -52,15 +52,22 @@
 
     vertical_spacing = size * desc.vertical_spacing;
    
+    glyphs.resize(65536); // 16bit ought to be enough for everybody
+
     // Copyh Unicode -> Glyph mapping 
     for(std::vector<GlyphDescription>::const_iterator i = desc.glyphs.begin(); 
i != desc.glyphs.end(); ++i)
       {
-        glyphs[i->unicode] = *i;
+        if (i->unicode < glyphs.size())
+          glyphs[i->unicode] = new GlyphDescription(*i);
       }
   }
 
   ~FontImpl()
   {
+    for(Glyphs::iterator i = glyphs.begin(); i != glyphs.end(); ++i)
+      {
+        delete *i;
+      }
   }
 
   void render(Origin origin, int x, int y_, const std::string& text, 
Framebuffer& fb)
@@ -87,10 +94,9 @@
       {
         const uint32_t& unicode = *i;
 
-        Glyphs::iterator it = glyphs.find(unicode);
-        if (it != glyphs.end())
+        if (unicode < glyphs.size() && glyphs[unicode])
           {
-            const GlyphDescription& glyph = it->second;
+            const GlyphDescription& glyph = *glyphs[unicode];
             fb.draw_surface(framebuffer_surface, glyph.rect, 
Vector2i(static_cast<int>(dstx), static_cast<int>(dsty)) + glyph.offset);
             dstx += glyph.advance + char_spacing;
           }
@@ -108,9 +114,8 @@
 
   int get_width(uint32_t unicode) const
   {
-    Glyphs::const_iterator it = glyphs.find(unicode);
-    if (it != glyphs.end())
-      return it->second.advance;
+    if (unicode < glyphs.size() && glyphs[unicode])
+      return glyphs[unicode]->advance;
     else
       return 0;
   }





reply via email to

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