1

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?

1 Answer 1

1

It is updated, here:

f.s[i*n + j] = s

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.