2
« on: December 11, 2013, 10:41:12 pm »
I'll try to be as clear as possible.
Background:
In the game I'm creating, there are several different types of game objects (tiles, walls, items, interactive objects like a door, fixed structures like a statue, players, etc). Each type can be expressed easily in their own separate image files. Say, Player.png stores the motions of a distinct character on each row, Tile.png and Wall.png stores all tiles in a grid-like fashion. Furthermore, walls can be a different size than tiles and fixed structures. All objects are around (50-200)x(50-200) pixels and each map can be up to 500x500 tiles. There will be many maps (only the player's current chunk will be drawn) and many of each category (i.e. 500-100 tiles, 200-300 items, etc).
Tiles can easily be implemented via a tile-map with the vertex array since they are always fixed and in the background.
On the other hand, walls and other fixed structures, although fixed, have to be in drawn in an order (picture a player standing behind a table but in front of a chair). And of course, the characters themselves are not fixed as they move around.
Since tile-maps can only use one texture at a time per draw call, I can't use it since all objects must be drawn in some unfixed order among different textures. I don't want to combine all textures into one file, but rather group them into these categories to avoid hard coding (especially since different categories may be added during development).
My question:
Is the attempt below efficient? Otherwise, what would you recommend? Would you recommend I merge tiles with the attempt or should I use two draw calls draw(tilemap) and draw(map_img) per frame?
Attempt:
At the start of the program, load each image: sf::Image tiles_img, sf::Image player_img, etc with their respective files. Each time I want to draw the map, I create an image sf::Image map_img that is as big as the screen. As I go along the coordinates, I determine which object should be drawn according to the order and use sf::Image::copy to copy the necessary instance from say, player_img, to the map_img. I repeat until I have no remaining object. Then I create an texture and LoadFromImage(map_img), create a sprite, setTexture, and then draw it.
I appreciate the help.
Solved
Did some research and implemented a variant of the Z-buffer algorithm (with additional constraints that suit my needs). The algorithm improved my FPS tenfold.
To add
The attempt algorithm above is bad for large maps. Do not use.