Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    570
  • comments
    2427
  • views
    216941

Untitled

Sign in to follow this  
Mushu

97 views

zomg map editor



There are still some issues with it - stuff like deleting a tile sheet that is being used on the map. Yeah, that isn't good :|

It'll take another little refactor job (basically an extension of the one I did earlier - move all map-related resources into a shared "Map" class. Dur dur why didn't I do that from the beginning?). But yeah, shouldn't be too hard.

The other (really weird) thing is that the top-left tile doesn't want to get set. I MSPaint'ed it in to hide that fact, but I can't seem to figure it out. Once I write the event handler code to right-drag scroll the map I think it'll turn up though. At least, I hope it will :X

AHA.

See if you can spot the error -
int _getIndex( int x, int y ) {
if ( x > _maxX || x < 0 ||
y > _maxY || y < 0 ) return -1;

return y * _maxX + x;
}

void _setTile( TileType tile, int x, int y ) {
if ( int pos = _getIndex( x, y ) ) {
_tiles[ pos ] = tile;
}
}

Cookie for the first person to find it!
Sign in to follow this  


10 Comments


Recommended Comments

Quote:
The other (really weird) thing is that the top-left tile doesn't want to get set. I MSPaint'ed it in to hide that fact, but I can't seem to figure it out.


Sounds like the kind of thing I'd turn into a 'feature'. [smile]

"And check the awesome, fearsome Tile Of Unchangibility! For an additional $14.99 charge, you can fill your whole map with these amazing broken, er, specially featured tiles!"

Share this comment


Link to comment
Either that or I'll work it into the plot -

"..and must destroy the evil Communist Hitlars who have stolen the top-left tile of the world!!!"

Share this comment


Link to comment
And among other things, the tile at (0,0) will have an index which evaluates to 0. False. Which means it doesn't get set :)

Hooray!

Share this comment


Link to comment
Argh, just fixed another bug -

The display of the map is an array (vector) of pointers to tiles. The tiles are stored in a tilesheet (vector). Guess what happens when you create a tilesheet, make some tiles on the map with it, then go back and edit the tilesheet?

WHOO WHOO YOU GUESSED IT!

Iterator invalidation. Swapped it over to a list of tiles; since I'm accessing the data directly with a pointer anyway, there won't be that much of a performance hit. But I need to be guarenteed that it's not going to reallocate my tiles somewhere random.

Damn you vectors, damn you! :O

Share this comment


Link to comment
void _setTile( TileType tile, int x, int y ) {
if ( int pos = _getIndex( x, y ) ) {
_tiles[ pos ] = tile;
}
}

why not?


void _setTile( TileType tile, int x, int y ) {
int indx = _getIndex( x, y )
if ( indx >= 0){
_tiles[ indx ] = tile;
}
}


Not like it should optimize any different.

Share this comment


Link to comment
MustEatYemen - Yeah, that's what I ended up doing.

Steve - the maximum element of a vector is vector::size() - 1. Allowing it to be equal to the maximum size would cause an access violation.

Share this comment


Link to comment
Exactly:

int _getIndex( int x, int y ) {
if ( x > _maxX || x < 0 ||
y > _maxY || y < 0 ) return -1;

return y * _maxX + x;
}

If y == x == vector::size(), access violation. Using >= would fix that.

Share this comment


Link to comment
Oh, so i c.

I think _maxX and _maxY are set to the size-1 already. I think, because I honestly don't know, but my "OMFG CLICK EVERYWHERE" test didn't crash it :]

But yeah, that's why you have a job and I don't [sad]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!