Thanks, everyone! I've got it working now. So my game used ~19132 kb or RAM, and now it uses ~18672kb. Considering a level is not very big it's pretty good result. However I'm wondering if I'm doing it right.
So, my Tile struct looks like this now:
struct Tile {
//collision information, animation information will be there soon
int tx, ty; // position of tile in a tileset texture
};
Tileset is defined like this:
std::map<char, Tile*> tilesetMap;
And map is just:
std::vector<char> map
So for example my level is
SSSSS
SSSSS
SSSSS
GGGGG
And it's very easy to get corresponding tile from a tileset:
Tile currentTile = &tilesetMap[map[x + y * width]];
So, back to rendering. Here's how I set up VertexArray:
//these are not changing so it's outside drawing function
sf::RenderStates states;
states.texture = &tileset.getTilesetTexture();
sf::VertexArray map(sf::Quads, 4 * levelWidth * levelHeight);
int w, h;
w = h = 16;
...
//left, right, top, down - these are the number of tiles currently seen on screen
for (int i = left; i < right; ++i)
for (int j = top; j < down; ++j)
{
id = i + j * levelWidth;
float tx = tileset.getTile(tiles[id])->tx;
float ty = tileset.getTile(tiles[id])->ty;
map[(id) * 4 + 0] = sf::Vertex(sf::Vector2f(i * w, j * h), sf::Vector2f(tx, ty));
map[(id) * 4 + 1] = sf::Vertex(sf::Vector2f((i + 1) * w, j * h), sf::Vector2f(tx + w, ty));
map[(id) * 4 + 2] = sf::Vertex(sf::Vector2f((i + 1) * w, (j + 1) * h), sf::Vector2f(tx + w, ty + h));
map[(id) * 4 + 3] = sf::Vertex(sf::Vector2f(i * w, (j + 1) * h), sf::Vector2f(tx, ty + h));
}
//So let's draw it.
mainWindow->draw(map, states);
Am I drawing my map efficiently now?