Falling sand game (WIP)

Community Forums/Showcase/Falling sand game (WIP)

tesuji(Posted 2008) [#1]
After wasting too much time playing this : http://dan-ball.jp/en/javagame/dust/
I decided to try my hand at a blitzmax version...

Still a work in progress, but I'd be interested to hear what FPS people get (trying to cope with a lot of particles at once is a bit of a challenge). It's only using OpenGL at the moment as I don't currently have a working Windows box for directx dev. Physics are a bit fudged and the codes a bit of a mess but it's a start.

Updated Version 0.3 - 13th April 2008

Download v.0.3 Windows Exe http://dl.dropbox.com/u/21540395/elemental.exe
Download v.0.3 Max OS X (Intel) zip http://dl.dropbox.com/u/21540395/elemental.zip



Blitzmax Source

version 0.3



Last edited 2012


Torrente(Posted 2008) [#2]
Great job!

These are a ton of fun -- you just managed to make me lose a half-hour of my day creating huge graphite/oil structures and then burning them up.


MGE(Posted 2008) [#3]
fps is all over the place, lots of negative values as well. ? ?


Who was John Galt?(Posted 2008) [#4]
Brilliant - genious - a great waste of time. Thanks for sharing the code.


Sonic(Posted 2008) [#5]
My god this is absolutely mind-blowing... You have to find a way to incorporate this into a game! Very smooth on my machine too.


Miss Blitz(Posted 2008) [#6]
This thing is astounding! And so fast! I was getting
a frame rate of, like 27-30 when there were over 15,000
of those granules as well as 2 or three concrete platforms!
... and how fast it was to build...
Just WOW!


Stevie G(Posted 2008) [#7]
Any chance of an exe for non Bmax users?


Amon(Posted 2008) [#8]
Impressive stuff. Wish I could even comprehend what's going on in the code. :)

[link to download in first post now]


Duckstab[o](Posted 2008) [#9]
yeah nice app what i realy liked was making a huge number of graphite platforms rising to the top a wide layer at the bottom comprising of magma and then letting a flow of oil over the graphite =nice fire trials


(tu) sinu(Posted 2008) [#10]
This was fantastic fun for 10mins this morning before work. Now make it into a game :-)


tesuji(Posted 2008) [#11]
Thanks everyone. I'm pleased that it appears to run ok on most peoples systems. Thanks Amon for hosting an Exe.

I've got a few ideas for how to make a game out of it, but for now, it's more of an inspirational spike to play around with some ideas. Here's my current todo list:

Elemental todo

Further Optimization

* DirectX rendering for Windows version
* Replace Floats with Ints
* Convert unchanging particles into bigger 'particle' blocks thereby reducing total particle count
* rewrite in C++ (really don't want to have to do this if I can help it)

New Functionality

Menu tools

* Cut and paste
* Load and Save
* Emitters (things that generate elements automatically)

Physics

* Gunpowder Element (explosive)
* Earth Element (neutral)
* Wood Element (burns leaving behind graphite)
* Seed Element (grows into a tree when it hits water and earth)
* Ice Element (reacts with Magma/Fire/Steam to form Water and freezes water)

A better model of energy/conductivity. Energy can be transferred between
elements changing their state when thresholds are reached. e.g. ice -> water -> steam

Game Characters

Introduction of complex entities that can interact with the simulation. e.g. fish, stick people, slugs etc..


Stevie G(Posted 2008) [#12]
I tried the exe - very nice and fast and simple to control.

I've seen some other falling sands games but they don't seem to have the detail / interaction you've implemented. Looking forward to seeing this made into a game.

Stevie


Tachyon(Posted 2008) [#13]
Good job!

* Replace Floats with Ints

I thought Floats were faster than Ints?


Grey Alien(Posted 2008) [#14]
Hey looks cool! Great framerate too (>100)

I thought Floats were faster than Ints?
No way (make a little test), unless you are trying to use an Int as a fake float and having to do fancy maths on it. Related: What I also found out a while back was that floats and doubles run at the same speed, so I have no worries about using doubles when precision required it. Also Bytes are no faster than Ints because we have 32-bit processors now.


tesuji(Posted 2008) [#15]
@Stevie
Thanks. Still a long way to go to catch up with the dan-ball version however ;)

@Tachyon

You may well be correct. I think I'll have to do some testing to see if it does indeed speed it up at all. There seems to be a big penalty incurred when mixing types up (casting must be expensive).

e.g.



Adding float to int took 463 ms
Adding int to int took 3 ms
Adding float to float took 5 ms
Multiplying int with float took 471 ms
Multiplying float with float took 4 ms
Dividing int by int took 17 ms


Grey Alien(Posted 2008) [#16]
You those casting times are horrible and worth bearing in mind! Probably worth making everything floats just to avoid that even though there is a small speed loss on general float to float operations. Hey that test could do with multiplying int by int as a comparison and also the two missing dividing by tests. Sorry for going off topic btw...


ImaginaryHuman(Posted 2008) [#17]
This is cool.


Vilu(Posted 2008) [#18]
Thank you making me waste an hour of my time, which I could've used for something productive like... working.

;)

Cool. I'd love to see this evolve further.


Xzider(Posted 2008) [#19]
Just wasted an hour of my time, good stuff:)


EOF(Posted 2008) [#20]
Definately good fun. My fave being filling a huge V shape made of Graphite with oil then tickling it with a small bit of fire at the bottom. Lovely lovely!


SillyPutty(Posted 2008) [#21]
Is there a binary I could try out ?


tesuji(Posted 2008) [#22]
Windows Exe link is in Amons post above.

When I've made a bit more progress, I'll put binaries for all platforms up on my website.


Blitzplotter(Posted 2008) [#23]
brilliant fun.... very enjoyable.


Rob Farley(Posted 2008) [#24]
It's good fun, I do get some strange graphic glitches with the exe though.

My one beef (and this is being picky) is that the water doesn't work properly, you can't make a U bend, it fills up like sand and doesn't push the water out of the other end.


Pineapple(Posted 2008) [#25]
I have to post my FSG engine after this =D Much simpler.
Using only simple math and one (!) array, it has the same approximate FPS. Use the mouse wheel to scroll through the different elements. Click to place element, right click to remove.

Yay for simple yet unrealistic physics!




Retimer(Posted 2008) [#26]
I think this is the coolest shared app I have seen on here. Extremely awsome particles effects, and so fast!

Thanks for sharing Tesuji


taumel(Posted 2008) [#27]
This is very good!

Oh and in the initial state i do get 19/20 fps on my Mini (G4 1.25Ghz).


tesuji(Posted 2008) [#28]
Thanks for all the feedback.

I've added a new version above with some links to compiled binaries. Had to remove v 0.1 source due to maximum size of post limit. Windows version was compiled on XP so I don't know how it'll fair with vista.

v 0.2

Some minor physics speed optimizations.
Added circle tool.
Pen tool doesn't leave gaps anymore.
Added Load/Save/Delete
Nicer GUI buttons
Added 'Wood' Element (Burns)
Added 'Acid' Element (Melts just about everything)
Added 'Seed' Element (Grows into wood when in contact with Sand + Water)
Added 'Gunpowder' Element (Explodes into fire missiles)

Some dev key shortcuts
r - cycle through rendering modes
v - toggle vertical sync
F1 - reset
F2..F3 - presets
F12 - Revert to last loaded/saved image
Left CTRL - Display zoom (Seems to crash my old win xp laptop. Maybe OGL driver issues).
CTRL + o - Open image
CTRL + s - Save image


taumel(Posted 2008) [#29]
Cool, thanks for the update.

I also noticed that there already is an iPhone version around and was pretty much surprised of the speed it's running at.

-> http://revver.com/video/649900/evolution-rgb/


DavidDC(Posted 2008) [#30]
It's great to see someone working on this! I think you've done a great job so far. It does seem to me though, that what you are doing is much more "Sand Game" than "Powder Game". The first button I looked for in your game was "Fan" :-)

Powder Game looks like it uses a different physics algorithm entirely - based on fluid dynamics by the look of it.

I'm guessing you've done as I have and googled away for a hint of what's going on only to come up with nothing?

For me, the Powder Game dynamics are where it's really at. I'm sure the code is out there, I just don't know the right terms to search for.

Any ideas anyone?


tesuji(Posted 2008) [#31]
Yeah, I agree that the Powder Game dynamics set the current benchmark for this sort of simulation.

I found this interesting PDF when doing a bit of research into how the powder game ticks : http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf

I imagine the powder game started out as a bog standard sand game before it evolved into what it is today. I would really like to add fluid dynamics/wind etc to elemental at some point but wanted to get the basics down first ;)


plash(Posted 2008) [#32]
Good info there, some amazing stuff really.


Geehawk(Posted 2008) [#33]
Great stuff.

One problem I've encountered is when I hit the pause button, I get a magnified version of the area around the cursor to the right of the main area (I'm running widescreen 1440x900) then the program bombs out back to windows.


Shambler(Posted 2008) [#34]
Same as Geehawk, running vista here.


tesuji(Posted 2008) [#35]
I get the same crash on my old laptop running XP. Thought it was just my flakey OpenGL drivers but I guess not. If you hold down left CTRL it should do the same thing. It's seems to be caused by my displayZoom() function using grabimage. Somehow it interferes with the open gl pixel plot.

I've got a workaround (i.e. not using grabimage) that should be finished at the weekend.

Thanks for letting me know.


Digital Anime(Posted 2008) [#36]
Tried it too and this is working great and really fast, at least 100 fps on a notebook. I like it :-)

Keep on the good work tesuji!


DavidDC(Posted 2008) [#37]
@tesuji - Great! That paper you found is exactly what's needed.

A little further digging revealed the entire demo source as a C project.

http://www.dgp.toronto.edu/people/stam/reality/Research/zip/CDROM_GDC03.zip

All that's required now is some kind of port/max interface :-)


tesuji(Posted 2008) [#38]
Nice find DavidDC

Here's a blitzmax fluid dynamics test using the code you dug up. It was amazingly easy to integrate it. Might come in useful for all sorts of applications.

Windows exe http://minimono.net/downloads/elemental/elemental-windows/fluidTest.exe

Source

Note - save both files into the same directory :

save as fluidTest.bmx


save as solver.c



DavidDC(Posted 2008) [#39]
@tesuji - Ha ha! You legend - this is awesome. Well done! Now we're definitely getting somewhere! :-)


Torrente(Posted 2008) [#40]
The newer version crashes with an "Unhandled Exception: Attempt to access field or method of Null object" whenever I attempt to put some seed on top of water and sand.


tesuji(Posted 2008) [#41]
Thanks for spotting that one Torrente. I don't run in debug mode often enough so it was failing silently here. I've just fixed it in the above source and will try and put up some new binaries tomorrow.


tesuji(Posted 2008) [#42]
New version is up.

* Zoom box issue should now be fixed.
* Fixed seed exception.
* Added grass.

Next thing I want to do is add wind so it may be a little while before the next update...


EOF(Posted 2008) [#43]
You are doing some really fantastic stuff here tesuji

The fluid test is nice!


impixi(Posted 2008) [#44]
Clever and interesting. Keep exploring the possibilities...

V0.3: 100 - 500 fps (NVIDIA GeForce 8800 GTS 640mb, Intel Core2Quad Q6600 2.4Ghz, 2GB RAM)


Armitage 1982(Posted 2008) [#45]
Waw very promising simulation over here !
Really good work !
Thanks for the sources :)


taumel(Posted 2008) [#46]
Looks good but the source did not compile on my mac and the exe crashed after some time.


Who was John Galt?(Posted 2008) [#47]
Just keeps getting better. I like building a contraption to rain seeds and water to grow a forest. Then of course I have to burn it down with gun powder!

I have to buy a faster PC!


andy_mc(Posted 2008) [#48]
I found a bug.

When the acid eats through the side of the screen on the right hand side, it crashes and quits.


tesuji(Posted 2008) [#49]
@taumel - What version of BlitzMax are you using? I'm compiling ok on a powerbook G4 with version 1.28.

@andy_mc - Thanks. I guess it's the acid eating its way through memory once it escapes the confines of the box. Not managed to replicate it locally yet but I'll keep trying. Most likely to be one of those pesky array index violations.


taumel(Posted 2008) [#50]
1.28 on a G4 (Mini) as well.


andy_mc(Posted 2008) [#51]
people, post some of your best starting pictures for this, I'm having problems getting trees to grow well. I use sand and water then drop some seeds on but nothing much happens.


Who was John Galt?(Posted 2008) [#52]
They grow on sand? Not tried that.

Make a flat bottomed bowl of wood. Then make two concrete cones well above it, one about an inch above the other. Fill the top one with seed and the bottom one with water, then using the thinnest line make a load of vertical holes that go through both cones. Voila- forest.


LineOf7s(Posted 2008) [#53]
Added 'Seed' Element (Grows into wood when in contact with Sand + Water)


Seed grows without sand?


tesuji(Posted 2008) [#54]
Seed grows when in contact with sand+water or wood+water. Sometimes seeds don't sprout if you've sprinkled too many as elements tend to separate from each other.

Here's a png that you can try out if you save it into your images directory (located in the same dir where you run elemental from) and load it up.



BTW, is anyone else having compilation issues? (trying to help taumel).


taumel(Posted 2008) [#55]
Btw my compilation errors were due to that BlitzMax said that certain variables have already been declared, if i remember correctly this happend in if else if structures...just had a quick try after the exe boomed here (could have been because of the acid here too).


tesuji(Posted 2008) [#56]
Hmmm, could it be cut and paste is somehow messing up the SuperStrict declaration? Maybe try pasting to a plain text editor first and then re-paste it into max ide?

I've got a fix for the acid leak issue (it was a index out of bounds) which I'll try and upload asap.


taumel(Posted 2008) [#57]
Yes this fixed it. Sorry that i didn't had a look at it on my own but i just had a quick try at it...


andy_mc(Posted 2008) [#58]
can someone upload some more example pics, I've rubbish at making my own.


z80jim(Posted 2008) [#59]
this is awesome! You lost me hours of a day playing the other sand game... unfortunately I don't like yours as much as the java one yet but you're getting there, especially with the full screen thing so you can have more room. You're on the way to making a great game, possibly a "real" game :P
here's an idea for a "campaign" thing...
So the user selects "campaign" or missions, whatever you wanna call it. It brings up a list of course, the first few being tutorials on what elements do when mixed together, but it just demonstrates one combination so there's room for testing on the user's part. Then you have missions, where you have objects/shapes made out of blocks, and the user has to do something like make a flamethrower or something. I can see how hard it could be to do this, you would have to check that they are mixing the elements inside the gun, that the elements are the right ones, that the elements are spraying out, and that they're burning up before touching the ground. You could also have shapes/objects made out of something that can be burned up, and your goal is to complete the objective WITHOUT harming the object. For these missions block would be disabled. Thanks for listening to my rambling! :lol:


Cp(Posted 2008) [#60]
Weird graphic glitches on my Vista widescreen laptop.
Oh well. It looked like fun.


Blitzplotter(Posted 2008) [#61]
Meanwhile back on a stable-ish OS (XP Home).... my two children think:



you could make a little concrete box that has gun powder in, make some wood stick lane, put some fire on the wood then wait until the fuse reaches the gun powder and there is a boom effect.

It is really fab because you can like make a beach by putting some sand on the bottom of the page and then put the water on top.




No glitches here, numerous effects on screen at once dropped the frame rate to about 6fps, (I've a 1.8Ghz athlon), but very impressive game play. Sheer genius. a WIP that is nearing fruition in my book!


Cp(Posted 2008) [#62]
I figured it out. :0
No OpenGL on my system.
you used that,right?
All of the openGL programs dont work.


OldNESJunkie(Posted 2009) [#63]
Anyone still working on this one ?

P.S.

If you're like me & don't mess with BMax as much as you should, make sure with newer versions to add:

import BRL.map

to the code or it won't compile....