ImageTransparencyCalculator - Check sprite on click

Optimized again. I have a lot of images in the game that I have to track when I click.
For those who do not use large images or many images, you may not need to update.

I rewrote the click tracking module into a native extension.
The main reason for the slow initialization was that the transparency data was stored in the Lua array. And adding items to it was slow. I am assuming that when elements are added, the array is re-created.
Therefore, the data is now stored and checked in a C++ module.
When initializing with data, memory of a certain size is allocated and filled with the necessary data.

Comparison of module initialization time (maps from my game):
Europe:
0.659 sec -> 0.064 sec
America (The map is too big):
5.2 sec -> 0.364 sec

I could not think that data is added to the lua table so slowly compared to my implementation in native code.

I hope that I don’t need to change anything here anymore.
The data format has also changed, you will need to regenerate the data again or use this code by analogy with what was above

code
		local file = io.open("new_generated_data/"..v..".data", "wb")
		local new_data = string.gsub(loaded_data, " ", "")
		file:write(zlib.deflate(new_data))
		file:close()

The data format has changed since at first it was thought that you can adjust the transparency threshold for the click detection. Now that’s either transparent or not. Data is now located as compactly as possible

3 Likes