Page 1 of 1

[Twinsen][0.16.21] I broke a fluid box (division by 0?)

Posted: Mon Feb 12, 2018 10:51 am
by eradicator
While experimenting around with an assemblers fluidbox it broke in a weird way. (thread)
fluidbroke.jpg
fluidbroke.jpg (24.44 KiB) Viewed 2986 times

Code: Select all

local f = data.raw["assembling-machine"]["assembling-machine-3"].fluid_boxes

f[1]. pipe_connections = {
  { type="input-output", position = {0, -2} },
  { type="input-output", position = {0,  2} },
  }
f[1]. base_area = 1
f[1]. height = 0
f[1]. base_level = 0
I guess height=0 is causing division by 0 somewhere?
I've attached the mod and a demonstration savegame (place a pipe to make it happen) in case needed.
testmod-assembler-fluid-sharing_0.0.0.zip
(1022 Bytes) Downloaded 134 times
_autosave4.zip
(741.71 KiB) Downloaded 139 times

Re: [Twinsen][0.16.21] I broke a fluid box (division by 0?)

Posted: Mon Feb 12, 2018 3:30 pm
by Twinsen
Fluidboxes are very strangely defined. Height Influences the volume, since the volume is calculated like this:
double getVolume() const { return 100 * this->baseArea * this->height; }
When the volume is set by an assembling machine, for example, it's done like this:
void setVolume(double volume) { this->baseArea = volume / (this->height * 100); }

So you can't have a height of 0 since it will mean a fluidbox with size 0.

I updated the value checking in the next version so 0 values are not allowed.

Re: [Twinsen][0.16.21] I broke a fluid box (division by 0?)

Posted: Tue Feb 20, 2018 10:28 pm
by Mimos
Twinsen wrote: double getVolume() const { return 100 * this->baseArea * this->height; }
Twinsen wrote: void setVolume(double volume) { this->baseArea = volume / (this->height * 100); }
I don't know if you use double for all liquid calculations but if you do, maybe you could increase performance a little by using float instead? On modern CPUs the speed of the Instructions should basically be the same, but maybe the reduced memory footprint could be helpful (more data can fit into the caches/be prefetched/whatever). Of course only if the precision still is sufficient, but I hope it would be ok.