Profile Falling Sand Game    Hell of Sand Game   Profile NEW Sand Game   Profile Pyro Sand Game Profile Pyro Sand II   
Profile X Sand    Profile Etch A Sketch Sand    Profile FSG Wiki    Profile Game Overview

realSand - Vector Physics + Lua Modding (Lua library fixed)

Discussion of programming and creation of new sand games.

realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby Jacob on Sun Nov 01, 2009 10:45 am

Scroll down a bit for a download link!

History
I actually started this in C around January 2008 or so, but my bad C skills and complete non-use of OOP led to a horribly buggy and slow prototype. Recently I've been learning Java for Minecraft stuff, and decided to make a sand game with Java. So, I present to you, realSand!

Introduction
This game uses vectors for physics instead of the standard if-no-particle-below-then-move behavior, so simulation is much more realistic and modding is much more flexible. However, I tried to make it similar to the original FSGs in the way particles behave, so you can't make giant columns of sand like in the powder game, for example. Also, you can do basic modding like in most FSGs, or you can take full capability of Lua.

I know there's bad horizontal bias right now, I'll fix it later :P

There is no wind yet, since I have no idea how to do that, but with the vector collisions and physics it might not be too hard if I find a guide somewhere. Collisions are done with sectors for increased performance, and everything uses object-oriented programming.

Prototype
I don't want to sound like I'm making uncertain promises, so here is a download link.

Download prototype v2 (requires Java)

UPDATE at 5:10 ET:
-Added a simple GUI, now there can be more than 2 elements
-Physics speed improvements
-Minor physics changes to remove bias and fix some inaccuracies

Old Versions
Prototype 1

Controls: Left click to place sand, right for a "trampoline" element, and middle (press mouse wheel) for a kind of explosion (sort of). As I said, it's just a demonstration.

Modding
The game is already powered by Lua, but modding is not finished yet, although you're welcome to try (might be hard with two elements!) If you look in default.lua you can see what modding will eventually be like (later, this file will just be a library of functions, and user mods will be stored in separate files.) You can use addElement() and addInteraction() [not implemented yet] for basic FSG modding, or you can specify a collision function that is called every time a particle of the specified element hits any other particle. The trampoline is an example of this. I'll make a more complete guide to modding as I add more features and the game is closer to finished.

Please try it, and tell me if you like it! I'm going to hopefully update often.
Last edited by Jacob on Mon Nov 02, 2009 2:03 pm, edited 1 time in total.
Jacob
Level 1.5
Level 1.5
 
Posts: 104
Joined: Sat Jan 27, 2007 10:32 am

Re: realSand - Vector Physics + Lua Modding (update 5:10ET 11/1)

Postby purple100 on Mon Nov 02, 2009 10:07 am

Code: Select all
C:\Documents and Settings\Andrew\Desktop>java -jar realSand.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/keplerproject/luajava/LuaException
        at com.mynet.realsand.Sand.main(Sand.java:239)
Caused by: java.lang.ClassNotFoundException: org.keplerproject.luajava.LuaException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        ... 1 more


Looks like I'm missing a package.
THERE'S A SPOON IN MY EAR!!!
Image
User avatar
purple100
____________________
____________________
 
Posts: 2304
Joined: Sun Mar 12, 2006 3:17 pm

Re: realSand - Vector Physics + Lua Modding (update 5:10ET 11/1)

Postby Jacob on Mon Nov 02, 2009 2:03 pm

Sorry about that, I left out the lua library by accident. I reuploaded prototype 2 with the library, and a .bat file to run the game.

It probably won't work on Mac right now; I need to find the JNI file for Mac for the library I'm using.

Edit: Also, should be a modding update pretty soon.
Jacob
Level 1.5
Level 1.5
 
Posts: 104
Joined: Sat Jan 27, 2007 10:32 am

Re: realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby JadestoneX on Fri Dec 11, 2009 8:09 pm

Jacob i think you should add these because they are kinda simple and kinda go with all fsg's...
Only reason i made Water Inert is because idk how to make Salt and Water Make Salt Water
if i could do that i would add fire to make steam too...

Code: Select all
function wallcol(x1, y1, x2, y2, element2, element2, vx1, vy1, vx2, vy2)
   game:setVelocity(x2, y2, vx2, vy2 * 0)
end

addElement("Wall", 100, 100, 100, 0, nil, wallcol)

quickAddElement("Sand", 255, 255, 145, 0.5)
quickAddElement("Water", 0, 0, 255, 0.5)
JadestoneX
Newbie
Newbie
 
Posts: 32
Joined: Mon Jun 29, 2009 4:41 pm

Re: realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby Asteranx on Thu Dec 31, 2009 12:17 am

Lua is an interesting choice for an interaction engine. On the one hand, it's incredibly flexible, but on the other it's slow. Personally, I don't think slow is something you can overcome in this case. Your engine is reasonably fast with small numbers of grains, but as the number increases, the calls into script can easily go into the tens of thousands per frame, and no matter what scripting language you use, that will never be acceptably quick.

What you need is a way to use Lua (or some other language) to describe, or perhaps configure some kind of optimized engine. You potentially lose flexibility this way, but the performance gain would be well worth it. Think of how programmable shaders work in graphics cards. The engine should be handling anything done that frequently at the lowest possible level.

Also, object orientation isn't necessarily a performance gain. It was never actually introduced to make coding more efficient. Typically it makes code more readable and more maintainable, but you should look into something called data oriented design if you're interested in crunching large numeric systems like this in real time.

Also, I've noticed that your prototype seems to have an issue where it puts 'too many' grains in during paint operations. If you draw two circles of the same pen size, one of sand and one of trampoline, by the time the sand has finished falling the pile is much larger than the trampoline circle. Perhaps a related issue, but the eraser brush doesn't reliably erase sand, just trampoline. It's been a while, though, so you've likely ironed these things out by now.
Asteranx
Newbie
Newbie
 
Posts: 23
Joined: Fri Aug 22, 2008 12:05 pm
Location: Seattle, WA

Re: realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby Graham on Sat Jan 16, 2010 11:29 am

Perhaps as opposed to LuaJava, you could use something like Groovy which will compile to JVM bytecode. That way you get the benefits of a scripting language, but similar performance to writing it all using Java.

Using vectors is a pretty neat idea though :).
Graham
Newbie
Newbie
 
Posts: 1
Joined: Sun May 18, 2008 9:40 am

Re: realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby tehz on Wed Jan 20, 2010 2:51 am

AFAIK Groovy does not COMPILE into java. It'll just make "stub" classes with the uncompiled groovy code. Then itll call the groovy code when needed.
Things i made
The below statement is true.
The above statement is false.

How to prove that god exists:
Love exists.
God is love.
God exists and is chemical reactions in your brain messing you up. (aka madness)
tehz
Level 1
Level 1
 
Posts: 60
Joined: Sat Jan 02, 2010 11:51 am

Re: realSand - Vector Physics + Lua Modding (Lua library fixed)

Postby IRabbit on Sun Feb 21, 2010 8:26 am

Can't run. It just doesn't show anything. No window, loader, not even an error message.
IRabbit
Newbie
Newbie
 
Posts: 5
Joined: Sat Oct 31, 2009 10:26 am


Return to Sand Development

Who is online

Users browsing this forum: No registered users and 1 guest