Advices for faster data management for loops idk

im making a really basic 2d sandbox(literally sand in a box) game. currently I only added sand and its gravity movement.
but project is so slow... I know I use if else blocks but I dont know any better way to compare datas to execute correct code on pixel(sand) shrug

do you have any tips to make the project faster? what blocks usually uses alot of performance other than trigonometry stuff?

Long press space to place sand

as a solution way, Im also noting @cymplecy 's way here since I think it will help maybe not for simulation games but other rendering stuff for me:

Another idea - create a costume of 50x40 (if I remember you matrix size correctly) and use the pixels of that costume as your matrix instead of canvas

Then update those pixels instead of your canvas matrix and just stretch the costume to make it fill the stage

Might be too blurry for you but that could be overcome by using a point resizer
Here is a demo of my idea
unfortunately - the point resizer isn't fast enough :frowning:

^project

Maybe just draw the sand
image

If you want the nice border - just draw that once at beginning of project

well yeah it would be faster but ofc my idea is improving it in future to make it fun to play (pain).

I tried adding a "will be updated?" info to block data but it make things worse because I had to access around blocks and make them "it also gotta update" when main block updates itself. otherwise when block goes to "no need to update" phase there is no going back.
so it creates a deadly droplet wave of 8x updates on screen.

now I tried some small thing like this for future updates:
image
so I could have bunch of sand like particles with different colors in one go. but ofcourse it made things even slower :upside_down_face:

"num 1,2,3" different blocks. "space press" place

I dont wanna be that guy but I have done some Project like this in scratch and its s m o o t h. what might be causing this? lists in lists is a bad idea for this specific situation? am I using warp blocks in a way that they mess up somehow idk? snap is slightly worse than scratch when it comes to rendering and it stacked up here?

should I just give up?

:pain: :upside_down_face:

Try making it so it only updates and/or redraws areas that change?

I remixed your project implementing the change I suggested. It runs a lot faster now.
https://snap.berkeley.edu/snap/snap.html#present:Username=pumpkinhead&ProjectName=sandboxtest%20help
(read the project notes)

That might work well :slight_smile:

Keep a list of moving blocks and only update their positions - once they stop moving, mark them as non-movers and remove them from the list

Another idea - create a costume of 50x40 (if I remember you matrix size correctly) and use the pixels of that costume as your matrix instead of canvas

Then update those pixels instead of your canvas matrix and just stretch the costume to make it fill the stage

Might be too blurry for you but that could be overcome by using a point resizer

this is clearly the way I should move on I guess. performance is amazing. Thanks for the idea and example alot!
how do you think I can implement a deleting block system? since it has to update all pixels around it (there might be water ans stuff) and if those blocks also moves, they gotta update all blocks around them. and chain reaction again. whats a good handling of these re-updating system?

@cymplecy what do you mean by point resizer? you mean manually increasing the square(pixel) sizes? do you have an example project or know some project that uses something like that?

Here is a demo of my idea
unfortunately - the point resizer isn't fast enough :frowning:

ProjectName=sandboxTest

maybe make it so when adding something to the update list, if the same position is already in the list, it won't be added again?

Also please make it so sand falls down slopes.

Just saying that I've re-written the point resizer to speed it up dramatically but it's probably still not fast enough.

But at least it spurred me on to do it :slight_smile:

The OP projects perform 2000 iterations per frame. It takes hundreds of milliseconds to render (200-400).
pumpkinhead projects use incremental rendering. For every frame, it performs only a few operations (3-50). Speedup is amazing.
But... without any sand placed on stage, doing literally nothing, the frame rendering takes 5 ms or more (fps 150-200).
After removing "for each (pos) in [queue]" it's less than 1ms. So executing "for each" for an empty list takes 5ms depending on the length of the body.
It really needs attention from Snap! developers.
I do test on Chrome@Win10@i7 laptop with energy savings enabled. I'm curious, how it performs on other computers.

Strange performance for
sandboxtest help script pic

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.