I remember seeing "games" like this in the early 2000s and being extremely interested in how they made it. I think a lot of other people were also curious how about this works. The more info the better!
THANK YOUUUU I’ve been working on a game with a falling sand mechanic and was really struggling to find videos covering the more advanced topics the past few days, and just found this
Really good video.I have been introduced to racing conditions and mutex vars in uni but never connected that it could be used for treading.Keep up the good work!!Also sand is satisfying
Sounds typical lol, some cool theories but no real world examples. Idk what you could of been doing besides threading though, as that's like the main point of mutex/race conditions lol.
@@WinterdevEvery example was about the hard drive ,printer,ram etc.Never on threading.They taught us at a low level how mutex etc work but not when they should be used.But it was an Operating systems course which was not that focused on coding (Mainly used c).So maybe we will be taught in a later course¿
@@apost7200 Oh that makes sense, I took a similar class, you'll prob end up doing some pthread stuff at some point. Threading unlocks some of the coolest parts of code, but is hard to wrap your head around at first. It's basically like the software version of multiple devices though
The diff animation is interesting.. I'm not sure how useful it is for readability or being able to follow along, but it definitely looks cool and lets you briefly describe the code changes very quickly.
I'll have to figure out what the best animation is, I think the fade might be a little distracting but it does give me some more time to talk over it. Thanks for the comment!
I think the fade happens too quickly to follow along, maybe with a background highlight of lines that are 'about to be replaced' ala GitHub's diff could improve readability! Love the quality of the videos, keep it up!
@@santitigre oo that's a good idea actually, it would fade a background on the lines to be removed and then fade them out. I'll try that out. Thanks for the comment!
Thanks for these videos, their really good. I have a suggestion for a 3rd or 4th video. Adding velocity because right now each partical moves one cell per frame so if the frame rate is lower then it will fall slower. By making cells move more than one space per frame based on the velocity cells would fall at a fixed rate and the water would be able to flow faster like in real life. I have a similar simulation as this so I’m wondering how you would do this. Thanks 😀
That's a good idea, I was trying to do something similar but I couldn't figure out how to make water slosh around. The main problem I was having was that if a particle collides then it needs to remove its velocity, so they would fall in weird ways.
@@Winterdev Yeah, I would be interested to see how you would implement it. I figured out how to make it move multiple spaces per frame but I still don't have the number of spaces it moves change based on the frame rate.
Ye it’s a little hard to get it perfect but that’s the idea and it looks ok. I’m not sure what the powder toy is doing. I think if you double buffer it instead of doing this list thing I’ve done you can get better looking movement, I’ve been looking into it... Gl with the velocities!
I did, but didn't have the time to go down that route. I can imagine that the way it would work is instead of looking from the POV of the filled cells, you would look from the POV of the destination and check the 8 surrounding cells. It might be the case that the fps is so high that you don't need more than a 3x3 convolution.
i don't know how hard that would be to implement, but the water seems to be going too slowly compared to the sand? maybe do two updates per frame (but that might be bad for the framerate) or have more movement possibilities (but that might be too complex/too big)?
Yeah I was trying to find a way to make it not look like goo, but in these vids I was just focusing on the engine bits. It seems like if you make it check 3 away, then 2, then 1, you get less viscous liquid, but I'm not sure if that's the real solution. i.gyazo.com/3760bbd2b0d41794376463aed0cab5ba.mp4
I'm having trouble adapting the dirty rectangle, 99% of particles move between the chunks (when it changes dirty rectangles to the other chunk's dirty rectangle) however there are a few particles that don't get added the rectangle so it just floats in the air. I don't know where im missing a call to the keepAlive method
Yes but it looked like a lot of work lol. I was thinking that if you used compute shaders then you could basically just render the tiles into the textures for super fast / big sprites as well.
@@Winterdev it definitely is, I was able to get the game of life running on a computer shader. But, falling sand, especially with multiple types of cells would be a whole other beast.
@@averysumner1369 idk about shaders to fix the issue of two particles moving to the same space, maybe you could use a 3x3 pass and test from the empty spaces, it would be much more complicated
So I have a question. Can't you just have a class that handles sand chunks, and just use a vector to contain all chunks and have a function to convert world coordinates to a position in the vector. This might be a bit biased as I am doing the same thing but my world is not infinite.
@@Winterdev I've done a bunch of stuff, and I implemented dirty rects and chunks. Movement between chunks and the dirty rects work. And while I can simulate more particles the simulation is still pretty slow. I have an 800 x 600 windows. And each sand particle is the size of a pixel. Dirty rects work by each chunk maintaining an update list and containing each particles old position and possible new position(s). I don't really know where I went wrong. Are there any suggestions you can make? Is this just because I haven't multithreaded it, or perhaps something I messed up in the code?
I’ll make some documentation once I’m back at the computer in a couple days. But basically you need to run premake5 on the main folder to gen the build files and then compile the extern libs and then the main solution. I wouldn’t even try tho lol, I’ll make a proper steps list in a few days
1:15 Maybe is just me but... Watch out? You are mixing Lists and Arrays! Lists are often called that as they are linked, in opposition to arrays, which are not.
I could see that but they are interchangeable. In Java arrays are called ArrayList, C# has List for everything related to lists and python calls them lists too. I think it's the concept of having a collection of items vs the implementation details, which are up to you
This makes me feel like a "Welcome back, to the SandPond saga. Let's get started."
I have been waiting so long for this! Like 2 days ago when I subbed.... For real tho, your work is amazing
Haha thanks :)
I remember seeing "games" like this in the early 2000s and being extremely interested in how they made it. I think a lot of other people were also curious how about this works.
The more info the better!
THANK YOUUUU I’ve been working on a game with a falling sand mechanic and was really struggling to find videos covering the more advanced topics the past few days, and just found this
Oh nice! Hopefully this helped, would love to see the results :)
Yo, thanks again for the amazing editing and clean Code! Keep it up :D
Thanks will do! :)
Nice simple description of the dirty rects. And it was cool seeing the process of iterating through the methodologies you used and discovered.
Thanks! That part definitely took the longest because there were so many edge cases
Really good video.I have been introduced to racing conditions and mutex vars in uni but never connected that it could be used for treading.Keep up the good work!!Also sand is satisfying
Sounds typical lol, some cool theories but no real world examples. Idk what you could of been doing besides threading though, as that's like the main point of mutex/race conditions lol.
@@WinterdevEvery example was about the hard drive ,printer,ram etc.Never on threading.They taught us at a low level how mutex etc work but not when they should be used.But it was an Operating systems course which was not that focused on coding (Mainly used c).So maybe we will be taught in a later course¿
@@apost7200 Oh that makes sense, I took a similar class, you'll prob end up doing some pthread stuff at some point. Threading unlocks some of the coolest parts of code, but is hard to wrap your head around at first. It's basically like the software version of multiple devices though
Finally!
The diff animation is interesting.. I'm not sure how useful it is for readability or being able to follow along, but it definitely looks cool and lets you briefly describe the code changes very quickly.
I'll have to figure out what the best animation is, I think the fade might be a little distracting but it does give me some more time to talk over it. Thanks for the comment!
I think the fade happens too quickly to follow along, maybe with a background highlight of lines that are 'about to be replaced' ala GitHub's diff could improve readability!
Love the quality of the videos, keep it up!
@@santitigre oo that's a good idea actually, it would fade a background on the lines to be removed and then fade them out. I'll try that out. Thanks for the comment!
Awesome!
I challenge you to do it in 3D!
You could use cubes, or the marching squares algorithm
I’ve been thinking about that haha I think I am going to try for the next project.
Thanks for these videos, their really good. I have a suggestion for a 3rd or 4th video. Adding velocity because right now each partical moves one cell per frame so if the frame rate is lower then it will fall slower. By making cells move more than one space per frame based on the velocity cells would fall at a fixed rate and the water would be able to flow faster like in real life. I have a similar simulation as this so I’m wondering how you would do this. Thanks 😀
That's a good idea, I was trying to do something similar but I couldn't figure out how to make water slosh around. The main problem I was having was that if a particle collides then it needs to remove its velocity, so they would fall in weird ways.
@@Winterdev Yeah, I would be interested to see how you would implement it. I figured out how to make it move multiple spaces per frame but I still don't have the number of spaces it moves change based on the frame rate.
You gotta multiply by the frame time and have the velocities be in the hundreds from what I can tell
@@Winterdev oh thanks
Ye it’s a little hard to get it perfect but that’s the idea and it looks ok. I’m not sure what the powder toy is doing. I think if you double buffer it instead of doing this list thing I’ve done you can get better looking movement, I’ve been looking into it... Gl with the velocities!
Another Great Video
This is SO cool
Have you ever considered using compute shaders for sand logic simulation ?
I did, but didn't have the time to go down that route. I can imagine that the way it would work is instead of looking from the POV of the filled cells, you would look from the POV of the destination and check the 8 surrounding cells. It might be the case that the fps is so high that you don't need more than a 3x3 convolution.
finally!
i don't know how hard that would be to implement, but the water seems to be going too slowly compared to the sand?
maybe do two updates per frame (but that might be bad for the framerate) or have more movement possibilities (but that might be too complex/too big)?
Yeah I was trying to find a way to make it not look like goo, but in these vids I was just focusing on the engine bits. It seems like if you make it check 3 away, then 2, then 1, you get less viscous liquid, but I'm not sure if that's the real solution. i.gyazo.com/3760bbd2b0d41794376463aed0cab5ba.mp4
I'm having trouble adapting the dirty rectangle, 99% of particles move between the chunks (when it changes dirty rectangles to the other chunk's dirty rectangle) however there are a few particles that don't get added the rectangle so it just floats in the air. I don't know where im missing a call to the keepAlive method
How do you not have more views and subs? Amazing video! I hope you make a channel discord, I'd so join
Thanks! I might make one over the summer
i was wondering how you could make a space game with sand, it being on the ground makes a lot more sense.
It makes much more sense but the game that I started on fell into a space shooter lol
9:44 happens every time when planning a project hahaha
So many little things popped up that I realized it was all over. Something as simple as rotation is made super complicated by the fixed grid :(
Are the threads limited to CPU cores (usually 8) or can some of this code run on the GPU for even more power?
Yes there is prob a way to put it onto the GPU. You’d need to double buffer it but I bet it wouldn’t be too hard/different
yeeey thanks for not disappearing
May have taken a while but I haven’t disappeared!!
@@Winterdev :D
how do you handle updating the dirty rect if two particles want to occupy the space but only one gets chosen?
its based on the final list of submitted moves
Have you ever thought about optimizing this using compute shaders?
Yes but it looked like a lot of work lol. I was thinking that if you used compute shaders then you could basically just render the tiles into the textures for super fast / big sprites as well.
@@Winterdev it definitely is, I was able to get the game of life running on a computer shader. But, falling sand, especially with multiple types of cells would be a whole other beast.
@@averysumner1369 idk about shaders to fix the issue of two particles moving to the same space, maybe you could use a 3x3 pass and test from the empty spaces, it would be much more complicated
@@Winterdev yeah, even games like noita where most of the gameplay is falling sand opt for CPU calculations.
So I have a question. Can't you just have a class that handles sand chunks, and just use a vector to contain all chunks and have a function to convert world coordinates to a position in the vector. This might be a bit biased as I am doing the same thing but my world is not infinite.
You could but you would have to reindex the array every time a new chunk is added so you'd end up basically with just a map.
@@Winterdev I've done a bunch of stuff, and I implemented dirty rects and chunks. Movement between chunks and the dirty rects work. And while I can simulate more particles the simulation is still pretty slow. I have an 800 x 600 windows. And each sand particle is the size of a pixel. Dirty rects work by each chunk maintaining an update list and containing each particles old position and possible new position(s). I don't really know where I went wrong. Are there any suggestions you can make? Is this just because I haven't multithreaded it, or perhaps something I messed up in the code?
A saga perhaps?
How to you run the code you have on github
I’ll make some documentation once I’m back at the computer in a couple days. But basically you need to run premake5 on the main folder to gen the build files and then compile the extern libs and then the main solution. I wouldn’t even try tho lol, I’ll make a proper steps list in a few days
@@Winterdev thank you so much, gl with all your projects!
@@joshuamora411 ok I took a stab at making some directions. Let me know if you have any questions! winter.dev/engine/
@@Winterdev Amazing, is there anywhere I can share with the community any experiments/debug/etc Ive done?
1:15 Maybe is just me but... Watch out? You are mixing Lists and Arrays! Lists are often called that as they are linked, in opposition to arrays, which are not.
I could see that but they are interchangeable. In Java arrays are called ArrayList, C# has List for everything related to lists and python calls them lists too. I think it's the concept of having a collection of items vs the implementation details, which are up to you
i cant figure out how to make a falling sand simulator in luau
wasup
yeah I'm making something like this but 3d, really gets laggy if you do that lmao
I REALLY want to see what that would look like I might explore that in the future
why use a map when you can use a 2d array?
If your world is static a 2d array is better, but a map allows for expansion without a lot of reallocation
;)