Map Editor Optimization
Posted: Sat Jan 08, 2011 12:09 am
Hey err'body. I've been developing a map editor (C++ w/ Qt) for a project I'm doing at school (completely different language, Turing). The saving and, for the most part, displaying is completely optimized. I only display tiles that are actually in the viewable area of the map (the area scrolled to), and only tiles that are set to display.
The project is an RPG, because I wanted to be original and not make Pong like err'body else. I realized just yesterday, "Perhaps having layers would make it prettier! :D" So I implemented it, and as of right now, I have 2 layers displaying on screen. This is fine and dandy, but the map renders realllly slowly.
This is how I currently do it:
The paintEvent is just a small snippet, showing how I basically display things. I go through every item of the array, and attempt to display it. The "Tile" class' Render function just takes the QPainter, and a QPixmap tilesheet. The tile's have a boolean "display" flag, which holds whether or not they should be displayed. This is used by their Render member function to decide whether or not to draw. I tried doing something like a Linked List of tiles that should be displayed, and this didn't work out too well. I'm not sure what was wrong, but everything drew slower. I thought about a stack, but then I couldn't remove a randomly clicked tiles from the stack of tiles being checked.
Does anybody have a suggestion as to a better way of handling display of the tile maps with an array style like that? I'm stumped for ideas here. I just know that, say, the user makes a map 100 x 100 (in tiles), and each tile is 32 x 32 px. That would be drawing 10,000 tiles. If I have 2 + layers of that, it will get pretty slow, especially if there's a lot of stuff drawn on each layer.
So, if it makes any difference, I'm using QPainter to draw, and checking if each tile should be drawn, then drawing it if so. I'm just looking for a better approach then this, and not a linked list or stack. Unless I'm doing it wrong for one or both of those, in which case, any support in that manor would be greatly appreciated .
-- Jesse Guarascia
The project is an RPG, because I wanted to be original and not make Pong like err'body else. I realized just yesterday, "Perhaps having layers would make it prettier! :D" So I implemented it, and as of right now, I have 2 layers displaying on screen. This is fine and dandy, but the map renders realllly slowly.
This is how I currently do it:
Code: Select all
void Init(){
// Initialize the tiles
Tile** tile;
tile = new Tile*[mapWidth];
for (int x = 0; x < mapWidth; x++){
tile[x] = new Tile[mapHeight];
for (int y = 0; y < maHeight; y++){
// Set the positions of the tiles
tile[x][y].SetPos(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
}
}
}
void paintEvent(QPaintEvent *event){
QPainter paint (this);
for (int x = 0; x < mapWidth; x++){
for (int y = 0; y < mapHeight; y++){
tile[x][y].Render(paint, tileSheet);
}
}
}
Does anybody have a suggestion as to a better way of handling display of the tile maps with an array style like that? I'm stumped for ideas here. I just know that, say, the user makes a map 100 x 100 (in tiles), and each tile is 32 x 32 px. That would be drawing 10,000 tiles. If I have 2 + layers of that, it will get pretty slow, especially if there's a lot of stuff drawn on each layer.
So, if it makes any difference, I'm using QPainter to draw, and checking if each tile should be drawn, then drawing it if so. I'm just looking for a better approach then this, and not a linked list or stack. Unless I'm doing it wrong for one or both of those, in which case, any support in that manor would be greatly appreciated .
-- Jesse Guarascia