Hey guys,
I'm currently working on implementing some procedural cave generation systems in Love2D. The map is being represented by a 256x256 array of tiles -- that is, 65000 number values cooresponding to tile types. In a game setting, theres no way I'd be drawing all of these tiles on the screen at once. But just for fun, lets say I want to draw a representation of this entire map (65000 tiles) every frame, in a simple way, like one colored pixel per tile.
I've been digging through the API trying to find the optimal way to solve this problem. My first attempt was the most primitive, which I knew would likely be worst case, but I still wanted to see the performance: calling love.graphics.point() for each tile. The result is about 15fps on my machine. Next, I tried calling love.graphics.point() on an offscreen buffer, then drawing that each frame. The results were better, but still only about 20fps.
So far its looking like to me like the best way to go about doing this would be maintaining an ImageData object and calling setPixel when i want to update a tile coordinate?
Thoughts?
Drawing a large number of individual pixels per frame
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Drawing a large number of individual pixels per frame
Framebuffers.
If you want to be fancy, you could have framebuffers at different "zoom levels", and interchange them - like google maps does, changing to different resolution images when you zoom out.
If you want to be fancy, you could have framebuffers at different "zoom levels", and interchange them - like google maps does, changing to different resolution images when you zoom out.
When I write def I mean function.
Re: Drawing a large number of individual pixels per frame
Like i said, tried using a framebuffer, but I still think the overhead is with the large number of love.graphics.point() calls. It barely improved my performance. Haven't tried manipulating ImageData directly, but will do that tomorrow.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Drawing a large number of individual pixels per frame
Are you generating the framebuffer on every frame, by any chance?
When I write def I mean function.
Re: Drawing a large number of individual pixels per frame
Probably, drawing on a framebuffer once and then drawing just that framebuffer should be running at 60 fps even on a crappy computer, even if the framebuffer is quite large.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Drawing a large number of individual pixels per frame
As others have said, make sure you're only creating your framebuffer once.
An alternate (probably faster and more compatible) method would be to render your map as a simple image. You could use something like:
An alternate (probably faster and more compatible) method would be to render your map as a simple image. You could use something like:
Code: Select all
function makeMap( x, y )
-- Replace the condition with whatever you use to know if a tile is there or not
-- You could even have different colors for different tile types, etc.
if map[x] and map[x][y] then return 255,255,255,255 -- Tiles are white
else return 0,0,0,255 -- Empty space is black
end
end
gameMap = love.image.newImageData(256, 256)
gameMap:mapPixel( makeMap )
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Drawing a large number of individual pixels per frame
How big are your tiles? Depending on how often you would need to redraw the image, the imagedata solution could be better, since not all computers support framebuffers.
Re: Drawing a large number of individual pixels per frame
i use love.graphics.rectangle to draw dummy tiles it seems to scale well
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Drawing a large number of individual pixels per frame
I've had really good luck using love.graphics.newImageData in Kurosuke, I heartily recommend it: I don't think there's a single computer on the forums that doesn't support it (unlike framebuffers). In Kurosuke I draw chunks of terrain to PO2 imageData, and after that it runs quite speedily (about 300FPS on my crappy Intel 82945G).
Kurosuke needs beta testers
Re: Drawing a large number of individual pixels per frame
I am, because I'm looking for a solution where I can dynamically display the map. However I suppose what I can do is only call newPoint on the framebuffer when a tile's data changes.kikito wrote:Are you generating the framebuffer on every frame, by any chance?
Thanks for all the suggestions, I will profile this method against the ImageData method and post my results.
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 12 guests