Hello, I am new to Defold. I have some questions about the engnie and how I should better make some thins.
Game mechanics: You have sheet of paper, which can be any of shape. You can set fire to it and fire will spread over this sheet of paper with some logic.
So, I imagine this as 2D matrix with big amount of cells, something like 500x500. Every cell has “hp”, if cell is burinig it is loosing hp and spreading fire to nearby cells.
Will it work well, if I would calculate it in lua? There should be a lot of calculations for each burning cell.
And how is it better to display this?
I am trying to use png images, as “maps” for each level. So, I want to decode them with defold-png by @britzl and than use that data for 2D matrix calculations and to display result.
Also, what is better in this case: draw to pixels in texture or to make a shader?
It could work well in Lua but it depends on a couple of things:
- What’s your target platform? Desktop builds can squeeze out quite a bit more performance than mobile. And HTML5 uses plain Lua 5.1 instead of LuaJIT so it will be slower.
- Iterating a 500x500 Lua table acting as a 2D array is not a problem.
- What do you mean by “there should be lots of calculations for burning cells”? It could mean that doing it using Lua is a no-go or it could mean that it’s no problem at all.
- Does it have to be calculated every frame? If yes, then it could be a problem depending on answers to above questions. If no, then you can spread out the calculation over multiple frames using a coroutine and get good performance regardless of answers to above questions.
It depends. Updating all pixels every frame using Lua = Slow. @AGulev is working on a native extension to help with some of the drawing, but it will probably still be a performance issue. Maybe a combination of shader and pixel manipulation?
Do you really need this kind of granularity to get a realistic result? I actually doubt that. I think you can reduce this quite a bit and represent the fire using much fewer cells, but let each cell affect multiple pixels.
Mobile and HTML5
Each frame cell can loose some “hp” and spread fire if “hp” of that cell is in a certain range. Fire spreading speed depends on current “hp” and rotation of sheet (like fire in real life goes up faster), so I need to calculate for each cell in some radius aroud that cell, how much “heat” it will get from that cell. Initial data for those calculations will be “up vector” of sheet (which is same for all cells for that frame) and vector between those two cells.
Of course there could be a lot of optimisations and simplifications.
No, I am not sure right now, that was like maximum option.