I am looking at this snippet in a fluid simulation tutorial.
I have searched for where those values are initialised and it seems they are never written to? There is a line that initialises the array this.s
.
this.s = new Float32Array(this.fNumCells);
However, past that, I fail to see a single write into it. There's multiple reads throughout the code.
e.g.:
var s = this.s[center];
var sx0 = this.s[left];
var sx1 = this.s[right];
var sy0 = this.s[bottom];
var sy1 = this.s[top];
Am I missing something? I am not that familiar with javascript but under the assumption that declaring an array with a known size defaults initialises its values to 0, my current reading of the code suggests this snippet is not doing anything, since s would always be 0 and it would be skipped?
But when I run it in the browser and use a console.log
statement to inspect s, it does have values I see s = 3, 4 etc...
How does it have any values?
It is updated, here:
f.s[i*n + j] = s