Faster tiling methods?

This is a discussion on Faster tiling methods? within the Game Programming forums, part of the General Programming Boards category; Erm, this is basically the method I'm using. It loads in a map from an array (hence the post I ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    106

    Faster tiling methods?

    Erm, this is basically the method I'm using.

    It loads in a map from an array (hence the post I made on the main C++ forum). It then basically runs the array through this mass case/switch/for katamar:

    Code:
    int genMap()
    {
         int xp = 0;
         int yp = 0;
         for(int x=0; x<10; x++)
         {
              for(int y=0; y<10; y++)
              {
                   switch(map[x][y])
                   {
                        case 'W': 
                             drawImg(water_tile00, xp, yp);
                             break;                        
                        case 'M':
                             drawImg(mount_tile00, xp, yp);
                             break;
                        case 'G':
                             drawImg(grass_tile00, xp, yp);
                             break;                         
                   }
                   if(xp == 288)
                   {
                        xp = 0;
                        break;
                   } 
                   else
                   {
                        xp = xp + 32;
                   }
              }
              
              yp = yp + 32;
         }          
         return 0;
    }
    Just wondering if this'll get slow with bigger maps with more than three tiles. It looks like it probably will. My other method involved creating an array of SDL_Surfaces too, for some reason. No idea why. That'd add a lot more code. Array is what I want when I create a tile class, I assume (at which point, I can just hardcode in tile data, and have an array of tile pointers point to the tiles, I assume? [MY GOD REDUNDANT {Redundancy is actually my god}]).

    Anyway, currently working on cleaning up source code (and adding classes proper). Maybe something'll come to me in the process.

    (Also, I know I should be using tilesets and classes to handle tiles. This is more proof of concept for myself).

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You can cut down on code and get a slight speed incase by having a tile index in your tile map and using it to index a tile array.
    exmample
    Code:
        for(int x=0; x<10; x++)
         {
              for(int y=0; y<10; y++)
                 drawImg(Tiles[Map[x][Y]], xp, yp);
                             
    }

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    And cut down more by using a linear array instead of a 2D.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  2. Turn Based Stradegy System Methods
    By TylerMoyer in forum Game Programming
    Replies: 2
    Last Post: 07-30-2007, 10:45 PM
  3. Computations - which is faster?
    By ulillillia in forum C Programming
    Replies: 9
    Last Post: 12-09-2006, 09:23 PM
  4. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03:09 PM
  5. Replies: 8
    Last Post: 07-27-2003, 01:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21