Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing a single tile during run #38

Closed
Luke004 opened this issue Jul 27, 2018 · 3 comments · Fixed by #49
Closed

Replacing a single tile during run #38

Luke004 opened this issue Jul 27, 2018 · 3 comments · Fixed by #49

Comments

@Luke004
Copy link

Luke004 commented Jul 27, 2018

Chunk(const tmx::TileLayer& layer, std::vector<const tmx::Tileset*> tilesets,

I am trying to modify the SFMLOrthogonalLayer.hpp so that I can update a single tile when the player destroys it (replace it with another tileID), but I'm having problems accessing the ChunkArray inside the Chunk which Vertices I would have to modify in order to replace a tile.
Any tips on how to do it? If not I might have to replace the whole renderer, that would be alot of work... I'm new to C++ and struggling to understand the unique pointers and all that stuff

@fallahn
Copy link
Owner

fallahn commented Jul 28, 2018

Sorry this isn't easily done without a bit of work. You'd probably need to keep your array of tile IDs around during run time, modify those, then resubmit them to build a new vertex array (if this happens infrequently then there should be very little impact on performance). If you have only a few tiles which change it might be OK to just draw a new sprite over the top of the tile layer. If you do decide to make your own renderer, I'd suggest starting at the basics. There's a tile map example on the sfml site here which you can use to get started. The main difference is that instead of a fixed array of tile IDs you use the tile IDs loaded from the tmx file. Once you get that working with a single tile set you can start to build on it, adding support for more textures, while including the option to update tiles. No smart pointers needed! :) Don't forget you can always hop on the sfml irc or discord server if you want some advice, there's usually someone helpful around to give you a hand

@Luke004
Copy link
Author

Luke004 commented Jul 28, 2018

It really depends on the playstyle of the player lol. If he decides to burn down the whole forest it would be like 500 tiles of 40.000.
Will it affect performance a lot when I'll just create a new sprite over it, as you mentioned? That seems to be the most efficient solution for me right now

Edit:
And what if I include my own little IF statement that only renders the created sprites when in players field of view? That would allow for unlimited tile overwrites I think...

@fallahn
Copy link
Owner

fallahn commented Jul 28, 2018

The problem with sprites is that you have a draw() call for each one, which is one of the mosts expensive parts of rendering. A few sprites is OK, probably a few hundred is OK, but you'll eventually start to notice a slow down in performance. What you could do, now that I think about it, is have your own vertex array to draw tiles over the top. Each time a new damage tile is created, add it to the vertex array. This way you only need to draw one extra vertex array on top of the map, which contains all the damage tiles.

Viewport culling (ie only drawing what's in view) is also a good idea. It gets a bit trickier when using vertex arrays, but they can be broken into smaller parts - which is the idea behind the Chunk class in the example. I'd say try a vertex array first. If it gets too big or there's noticible performance problems, then look at splitting it into chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants