The code is riddled with statements like
if (area[i].lft == ((lft + 1) & (map_width-1)))
and
size_t k = (y & (map_height - 1)) * map_width + (x & (map_width - 1));
They are short, terse, and computationally inexpensive, but they fail to work properly when the map_width and map_height values are not powers-of-two. I started to rewrite code to address it, and was making a little progress. Unfortunately the end product is several extra lines of code for each such instance, and involves more computationally expensive (costly) operations than a simple bit-wise AND and a subtraction operation. After 90 minutes of work, it was almost right in one function, as shown below.
512x384 map of the plates. Almost right, but still seeing red, which indicates plate is missing. 768x384 and 768x768 show similar problems. 512x256, 512x512, 512x1024, and 1024x256 maps do NOT. |
But not quite right. And that was in only one function among several, and many of those functions made far heavier use of those AND operations. So I made up my mind. Rather then go through the many hundreds of lines of code that use such statements, and rewrite them into more computationally expensive (costly) operations and adding many news lines of and taking perhaps another dozen hours, I shall give up on non-power-of-two dimensions for this release. Maybe someday in the future. So no 1024x768 or 640x480 or 512x384 output for now, but 1024x1024, 1024x512, etc. should work just fine. I'll make some comments in the code, remove the non-power-of-two dimensions from the GUI, and move on.
Integration of parameters from the GUI into the simulation will likely be my last thing to accomplish before I release this, unless I uncover additional problems.
No comments:
Post a Comment