Strided Arrays
Posted: Sat Jan 04, 2014 7:46 pm
tl;dr: This is painful to write: map[1+ (y-1) * width + (x-1)], write this instead: map:get(x, y)
Link: https://gist.github.com/inmatarian/8259581
Explanation:
I had this trapped in my head and needed to get in out in Lua code. A strided array is a generalized multidimensional array. In python it's offered as ndarray in NumPy. The best way to understand it is for me to explain it in 3d: map[1+ (z-1)*width*height + (y-1)*width + (x-1)]. Strided Arrays turn that into a loop. I haven't tested the speed of this, and I totally don't want to see people using this for pixel access to a surface 60 times a second. However, I got sick of writing this in an ungeneralized form over and over for stuff like loading an array into a tile layer.
Here's a better blog from a better authority: http://0fps.wordpress.com/2013/05/22/im ... avascript/
Oh, and I forgot to set a license on it. meh, public domain, wtfpl, mit, you get the idea.
Link: https://gist.github.com/inmatarian/8259581
Explanation:
I had this trapped in my head and needed to get in out in Lua code. A strided array is a generalized multidimensional array. In python it's offered as ndarray in NumPy. The best way to understand it is for me to explain it in 3d: map[1+ (z-1)*width*height + (y-1)*width + (x-1)]. Strided Arrays turn that into a loop. I haven't tested the speed of this, and I totally don't want to see people using this for pixel access to a surface 60 times a second. However, I got sick of writing this in an ungeneralized form over and over for stuff like loading an array into a tile layer.
Here's a better blog from a better authority: http://0fps.wordpress.com/2013/05/22/im ... avascript/
Oh, and I forgot to set a license on it. meh, public domain, wtfpl, mit, you get the idea.