Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Vectors of vectors of vectors  (Read 764 times)

0 Members and 1 Guest are viewing this topic.
Vectors of vectors of vectors
« on: May 06, 2007, 05:11:00 pm »
  • MetalRidley was here
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 235
I'm having a few troubles with this. I can get it to work fine, but I don't know how to do out-of-range checking. Here is the line of code accessing the vector:

thisTile = tile->tiles[0][leftTileIndex + i][topTileIndex + j];

Code: [Select]
for (int i = 0; i < SCREEN_WIDTH / tile->tileWidth + 1; i++)
{
for (int j = 0; j < SCREEN_HEIGHT / tile->tileHeight + 1; j++)
{
try
{
thisTile = tile->tiles[0][leftTileIndex + i][topTileIndex + j];
srcRect.x = (thisTile % tile->numTilesPerRow - 1) * tile->tileWidth;
srcRect.y = floor((float)(thisTile / tile->tileHeight));
destRect.x = i * tile->tileWidth;
destRect.y = j * tile->tileHeight;

SDL_BlitSurface(tile->image, &srcRect, screen, &destRect);
}
catch (std::out_of_range &)
{
// Vector was out of range, so just let the bg color be drawn
}
}
}

and this is the declaration in the TileSet class:

std::vector<std::vector<std::vector<int> > > tiles;

tile is a pointer to a TileSet object, the part I'm talking about is bolded.
Basically all I want to know is how I could somehow use .at instead of each set of brackets for exception handling, since at the edge of a room the tileset ends but the function still checks for more tiles.
Logged



THE MUSIC IS REVERSIBLE, BUT TIME IS NOT. TURN BACK... turn back... turn back...
Re: Vectors of vectors of vectors
« Reply #1 on: May 06, 2007, 05:18:11 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Don't use exceptions for out-of-bounds checking, that is an awfull idea. Exceptions have a high preformance penalty when used in real-time (really, really slow).

Anyway just do something like this.

Code: [Select]
if (leftTileIndex + i < 0 || leftTileIndex + i >= MAP_WIDTH || topTileIndex + j < 0 || topTileIndex + j >= MAP_HEIGHT)
{
// Out of range code
}
Logged
Re: Vectors of vectors of vectors
« Reply #2 on: May 06, 2007, 05:51:23 pm »
  • MetalRidley was here
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 235
I see, it was my first time ever trying to use exceptions anyways. I had no idea they were so slow. Thanks, I'll do that instead.
Logged



THE MUSIC IS REVERSIBLE, BUT TIME IS NOT. TURN BACK... turn back... turn back...
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.02 seconds with 43 queries.