-
Notifications
You must be signed in to change notification settings - Fork 75
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
Tilesets #201
Tilesets #201
Conversation
A note on performance, I tested an extreme case with a 1024 x 576 window size, using a large 4032 × 3024 tileset image. I Then selected a random 100 16x16 tiles, to use and filled the entire 1024x576 window with tiles, so 2304 tiles in total. On my M1 laptop I see around ~ 44% CPU usage from the process and ~ 31% GPU usage shown in activity monitor. This seems 'acceptible' as it should still hit 60fps on a machine half as powerful in an extreme case (i'd expect a typical tileset to be smaller and tiles to be larger). but performance could definitely be improved by avoiding rendering the entire image each time. |
Code to test performance: require 'ruby2d'
GRID_SIZE = 16
set background: 'white'
set width: GRID_SIZE * 64
set height: GRID_SIZE * 36
tileset = Tileset.new('/path/to/very/large/image.jpeg', tile_width: GRID_SIZE, tile_height: GRID_SIZE, padding: 0, spacing: 0)
100.times { |i| tileset.define_tile(i.to_s, rand(252),rand(189)) }
64.times do |i|
36.times do |j|
tileset.set_tile(rand(100).to_s, [
{x: GRID_SIZE * i, y: GRID_SIZE * j}
])
end
end
show |
On a performance note, we actually haven’t implemented batch rendering for textures yet (here’s what it looks like for triangles), so that should dramatically speed things up when we do through reduced draw calls. |
Multiple tiles are being rendered from the same tileset successfully. I believe some of the values may be mixed up and so the rendering seems a bit broken at the moment. It's squashing an image rather than cropping it I believe.
The 4 texture x/y points are meant to be floats scaled to the width/height of the image, so fixed that. Also I was incorrectly using `INT2NUM` rather than `NUM2INT` which was giving weird random numbers instead of the passed values, fixed that also :)
Also rename some variables in `Tileset` for clarity
A tileset implementation
TODO:
Add ability to set width/height of the original tileset, to scale the tile size, same how sprites workAdd ability to rotate tiles (same as sprites)Add ability to mirror tiles (same as sprites)