Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up the code #4

Closed
wants to merge 9 commits into from
Closed

Cleaned up the code #4

wants to merge 9 commits into from

Conversation

maciekmm
Copy link
Contributor

Cleaned it up and optimized a little.
Also you might look into your gravity/acceleration math because it's broken.

@pakastin
Copy link
Owner

Thanks, I'll check this out! Did you notice I just fixed collisions..?

@maciekmm
Copy link
Contributor Author

@pakastin Yes, I've merged it already. But acceleration is still kinda broken, look into calculating it using trigonometry.

@pakastin
Copy link
Owner

Cool, you're fast! ;)
hmm.. sorry it's hard to follow what's changed because so much refactoring.. What was the issue(s)?

@pakastin
Copy link
Owner

Which part of the gravitation math needs fixing?

@maciekmm
Copy link
Contributor Author

The issue is that the code doesn't follow almost any standards.

  • I've added squared distance check as rooting is quite heavy.
  • I've converted it to ES6.
  • And cleaned it all up.
    Merge it locally and check what has changed :).

Regarding gravitation:
https://github.com/pakastin/nodegarden/blob/master/scripts/index.js#L149-L159

@pakastin
Copy link
Owner

Sorry, I still don't understand how your lines differ:

var xAccA = force * direction.x / nodeA.mass;
var xAccB = force * direction.x / nodeA.mass;
var yAccA = force * direction.y / nodeB.mass;
var yAccB = force * direction.y / nodeB.mass;

// calculate new velocity after gravity
nodeA.velocityX += xAccA;
nodeA.velocityY += yAccA;

nodeB.velocityX -= xAccB;
nodeB.velocityY -= yAccB;

About those standards: I use standard code style and don't like ES6 classes / fat arrows.. I agree with the mess though – will refactor it my way, but merge to this pull request. Thank you so much for contribution!

@maciekmm
Copy link
Contributor Author

@pakastin They don't. I've not fixed it.
I can downgrade to ES5, But babel does this fine. Also ES6 is just around the corner for browsers and provides really readable syntax.

@pakastin
Copy link
Owner

I just don't like the ugly code babel makes with classes and fat arrows..but you have great things going on – I'll show you my fixes in a moment..

@zeroZshadow
Copy link

What he means is that xAccB is using nodeA's mass, instead of B's mass.
Also the temporary variabled are only used once, thus totally useless. (except of maby documentation)

pakastin added a commit that referenced this pull request Oct 23, 2015
pakastin added a commit that referenced this pull request Oct 23, 2015
pakastin added a commit that referenced this pull request Oct 23, 2015
@maciekmm
Copy link
Contributor Author

@pakastin Should I merge your new commits to this PR?

@pakastin
Copy link
Owner

I can fix this, no worries ;) Thank you so much – works great now!

@pakastin pakastin closed this in 2152f19 Oct 23, 2015
@pakastin
Copy link
Owner

Thanks for contribution!

pakastin added a commit that referenced this pull request Oct 23, 2015
pakastin added a commit that referenced this pull request Oct 23, 2015
@maciekmm
Copy link
Contributor Author

You have not implemented squareddistance check which i think is a great performance improvement.
I also find setting fill color and doing night check on every render call strange, same with variable declarations at the beginning of the function.

I'll contribute tomorrow by implementing #1 and some nicer screen edge behavior.

@pakastin
Copy link
Owner

I'm happy to merge, sorry I made this refactoring straight to the master branch, but there would've been something like 99.9% undoing and too much of a hassle pulling/pushing. Hope you're ok with my code style.

Didn't have time to investigate the square root optimization any further. I did realize there's more squaring than square rooting going on, so I believe it would make a difference. If you want you can make pull request for it.

I didn't notice your fix on setting fill and night check, sounds good also – I let that one for you to pull request as well if you want. Don't want to "steal" your contributions any more ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants