Results 1 to 7 of 7

Thread: Big slowdown while drawing tiles from a vector

  1. #1

    Default Big slowdown while drawing tiles from a vector

    Hello,

    (This is a continuation of my previous thread)

    I'm doing a map loader system with ClanLib
    the map is defined in a XML file, it has different tilesets (PNG: a collection of 16*16 tiles) and different layers

    A layer is composed of multiples tiles, a tile is composed of the position X & Y and the ID of the positon on the associated tileset
    A tileset is a simple CL_Sprite wich contains all the image tiles.

    Here is my loop for drawing these :
    PHP Code:
        unsigned char tileset_index;
        
    unsigned short gid;
        
    unsigned int pos_x;
        
    unsigned int pos_y;

        for (
    int i 0layers.size(); ++i)
        {
            
    Layer layer layers[i];
            for (
    int j 0layer.get_tiles().size(); ++j)
            {
                
    Tile tile layer.get_tiles()[j];
                
    gid tile.get_gid();
                
    tileset_index tile.get_tileset();
                
    pos_x tile.get_x();
                
    pos_y tile.get_y();
                if (
    tileset_index != 0)
                    
    tilesets[tileset_index].draw_gid(gidpos_xpos_y);
            }
        } 
    Where gid is the image i want to draw
    PHP Code:
    void Tileset::draw_gid(unsigned short gidint xint y)
    {
        
    tileset->set_frame(gid);
        
    tileset->draw(World::get_gc(), xy);

    But this method is very very slow.

    Any advices ?

    Thanks

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Slow in the DEBUG build, or the RELEASE build?

  3. #3

    Default

    Quote Originally Posted by rombust View Post
    Slow in the DEBUG build, or the RELEASE build?
    Hello rombust,

    I'm developping under gcc, I compile with this command line : (in reality it's a custom Makefile from example folder)
    Code:
    g++ `pkg-config --cflags clanCore-2.3 clanDisplay-2.3 clanApp-2.3 clanSWRender-2.3 clanGL-2.3 clanGL1-2.3` -pthread -Isrc/includes -c src.cpp

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Are the pngs contained in the same file?

    If not, they will really slow down the OpenGL pipeline because you cannot batch draw them

    (technically, for clanGL you are allowed 3 pngs without breaking the batcher)

    There is a utility to do this: ClanLib-2.3/Utilities/TexturePacker
    It also adds a pixel border to each image, so that you do not get colour bleeding problems with stretched images (An alternative is to also disable linear filtering)
    If I remember correctly, it does not work 100% on linux because it is missing a file requester, but no harm trying


    This process should ideally be automated by clanlib internally. Maybe for ClanLib 3.0

  5. #5

    Default

    Hello rombust

    Actually my map only uses 3 tilesets (so 2 PNGs : there is a collision layer that isn't drawn)

    I tried with only one tileset (only one PNG image of 640x640), but there is still an important FPS drop.

    I use CL_Sprite for tilesets (and a CL_SpriteDescription to cut my tileset in 16x16 tiles with a spacing/margin of 1)

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Use CL_Image instead of CL_Sprite, that should make it faster.

    The fastest way is to use "gc.draw_primitives() via a CL_VertexArrayBuffer, when a single OpenGL can draw the scene.

    But you would need to do a bit of coding.

    Also try clanGL vs clanGL1

  7. #7
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I don't think the slowdown is caused by ClanLib.

    My theory would be that he's making a copy of the vector when doing "Layer layer = layers[i];" and "Tile tile = layer.get_tiles()[j];" - that is a lot of memory copying.

    Try pass them by reference or pointer, i.e. "Layer &layer = layers[i];"

Similar Threads

  1. How can I rotate and translade a Sprite using Matrix and Vector with Clanlib?
    By RawArkanis in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 08-23-2012, 08:45 PM
  2. Support for Scalable Vector Graphics
    By fdaniels in forum Novashell Game Creation System
    Replies: 2
    Last Post: 03-23-2010, 04:35 AM
  3. Making tiles
    By Suudsu2200 in forum Novashell Game Creation System
    Replies: 3
    Last Post: 03-05-2007, 10:30 PM
  4. How to use the vector data from CL_Raw ?
    By ARme in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-21-2006, 08:35 PM
  5. Dink Tiles 19 to 23
    By in forum Dink Smallwood HD
    Replies: 8
    Last Post: 08-15-2002, 10:58 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •