Experimental Scala port

Discuss issues specific the Scala port of Box2D
Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Wed Jun 17, 2009 2:49 pm

Just as a side note: I ran the tests on Apache Harmony (5 M10) just for fun and the results are much worse. I'm getting 6 seconds to 50 seconds depending on VM options. And the more optimizing options are the ones that make it run slower (maybe they are optimized for more long-running processes). The -Xem:server_aggressive option crashed my app.

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Thu Jun 18, 2009 3:02 pm

ewjordan wrote:Have you tried turning on the Scala compiler optimizations? I've never experimented there so I don't know how well they work, but it might help a bit.


Tried again, and it seems they actually make it SLOWER (maybe < 1% so not really noticeable). I'm guessing these inlinings may make it harder for the JIT to apply the best optimizations in some cases. But anyway, the inlining is improved in Scala 2.8 (at least a few bus fixed), so I'll try again when a milestone/RC of 2.8 is out.

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Sun Jun 21, 2009 2:39 pm

Testbed now available via webstart: http://villane.org/scalabox2d/testbed/testbed.jnlp

The download is several megabytes (didn't manage to compress the libraries with ProGuard). Also note that as it runs under the Client VM, performance is way worse than it can be. Requires Java 1.6

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Tue Jun 23, 2009 7:55 am

I noticed something more interesting about the performance in the particular Pyramid 1000 steps benchmark:

ScalaBox2D seems to get even faster if I increase the warm-up time (let it run the loop about 20 times, then measure the 21st time). With some more optimizations (mostly manual inlining) in various places, and increased warm-up time, it's now pretty damn close to JBox2D:

Code: Select all

Scala: 1890 ms
 first 100: 312 ms
 last  900: 1578 ms
vectors created:22868550

Java: 1781 ms
 first 100: 234 ms
 last  900: 1547 ms
Vectors created: 6894982


Of course, this is only one test, in the Circles test (1000 steps), JBox2D is a lot faster:

Code: Select all

Scala: 9375 ms
 first 100: 703 ms
 last  900: 8672 ms
vectors created:89794895

Java: 6219 ms
 first 100: 578 ms
 last  900: 5641 ms
Vectors created: 12712541

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Tue Jun 23, 2009 3:40 pm

Some new features:

  • Material class that consists of density, friction and restitution. These can be applied to FixtureDef via normal use (defn.apply(material)) or the DSL (box(...) material(material)).
  • Sensor-managed controllers, which don't have their own list of bodies but rely on it's sensor body's current contacts *
  • the first working/tested controller: PlanetGravityController, PlanetGravity scene for TestBed

* this is implemented with traits and some functional collections (the base Controller trait defines abstract bodies method):

Code: Select all

trait SensorManagedBodies extends Controller {
  var sensor: Body = null
  def bodies: Set[Body] = Set() ++
    sensor.contactList filter {
      // Filter edges with no actual contacts
      _.contact.manifolds.size > 0
    } map { _.other }
}

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Experimental Scala port

Postby BorisTheBrave » Wed Jun 24, 2009 2:03 pm

Villane wrote:Sensor-managed controllers, which don't have their own list of bodies but rely on it's sensor body's current contacts
[/code]

Good work. I really wanted to do this in C++, but the language/event model makes it difficult.

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

Re: Experimental Scala port

Postby toucansam » Thu Jun 25, 2009 4:00 pm

Villane wrote:I noticed something more interesting about the performance in the particular Pyramid 1000 steps benchmark:

ScalaBox2D seems to get even faster if I increase the warm-up time (let it run the loop about 20 times, then measure the 21st time). With some more optimizations (mostly manual inlining) in various places, and increased warm-up time, it's now pretty damn close to JBox2D:

Code: Select all

Scala: 1890 ms
 first 100: 312 ms
 last  900: 1578 ms
vectors created:22868550

Java: 1781 ms
 first 100: 234 ms
 last  900: 1547 ms
Vectors created: 6894982


[/code]


I'm sure if you get rid of those Vec2 creations, you'll be leaving JBox2d in the dust (for now 8-) ) I don't know if you can do this in Scala, but it helped a lot for me if I put a final modifier in front of variables that i wanted to cut down allocations on, and the compiler will showed me every place it's assigned. I'm looking forward to seeing how this progresses :)

brainclog
Posts: 185
Joined: Mon Dec 17, 2007 10:11 pm
Contact:

Re: Experimental Scala port

Postby brainclog » Wed Sep 02, 2009 6:10 pm

So I'm trying to compile the Scala port, and I think I've tracked down all the libraries I need, but JOGL is missing some files! I'm a Java/Scala newb, but I've been using Box2D in AS3 for some time and am trying to get into Scala so I thought I'd try it out. So I'm not sure everything that's missing exactly, but at least these 2:

javax.media.opengl.DebugGL
javax.media.opengl.GL

I've done quite a bit of searching, downloaded about 10 different versions, and these files don't seem to be in any of the JOGL source packages! Even found someone posting about it on a forum about the same missing files, but no answers. Is there more than one library called JOGL? I'm really confused...

It would be really helpful if there was a list of dependencies also, with versions of each library that are used. Any ideas?

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Experimental Scala port

Postby Villane » Sun Sep 06, 2009 5:59 pm

There's a short description on how to build on the wiki: http://wiki.github.com/Villane/scalabox ... structions

The easiest thing would be to compile it with Maven 2. http://maven.apache.org/

If you don't want to do that, you can look up the dependencies from pom.xml (these are separate for each module)

The testbed doesn't depend on JOGL, it depends on Slick, LWJGL, FengGUI, versions of which are also listed in the testbed pom.xml:
http://github.com/Villane/scalabox2d/bl ... ed/pom.xml

brainclog
Posts: 185
Joined: Mon Dec 17, 2007 10:11 pm
Contact:

Re: Experimental Scala port

Postby brainclog » Sun Sep 06, 2009 10:33 pm

Thanks, still can't compile, but I see part of what happened. I was trying to compile ScalaBox2D and got frustrated because it wasn't working and tried to just compile someone else's basic Scala OpenGL test and confused the two. If you (or anyone else) knows where the hell I can find javax.media.opengl package I would still be interested. I'm sure I can track it down eventually, but could take many hours (have already spent several looking for it, not exactly how I like to spend weekends). Apparently some of the javax.media package resides in the Java Media Framework, other parts of javax.media are part of JOGL, other parts, including javax.media.opengl are god knows where. Here in Java code land apparently they like to take random code and spread it all over hell and then call it all the same package just to confuse AS3 programmers with their nice, sane packages.

Ok so, many hours later... Figured out one problem, when it says add JAR/Folder, it apparently means add a folder of source, OR a jar, not a folder of JARs...brilliant. No error either, adding a folder with nothing but JARs, and they even show up with all the package names as if they're loaded. Nice job Netbeans!

So I think that part is resolved, although Netbeans seems to completely ignore the source for fenggui... There is no refresh like in Eclipse (or it's hidden), and sometimes it will do it on its own and sometimes...nothing. Anyhow I have a bigger problem, I create a new project and it has a Main already, and I can't figure out what your main class is for the testbed, assuming there is one. I thought it was TestbedMain, but it's just a trait... I am kindof a scala newb, but have read most of the book. I tried to call one of the scene singeltons like PlanetGravity.createScene and passed in my own world object. It compiled, but didn't do anything. I selected Run Main Project.

I have to say, the special characters (e, pi) are annoying. Netbeans likes to put squiggly red lines starting at a special character until the end of the source file, but it doesn't flag an error, just makes it impossible to read the source, even though it apparently supports unicode (and the character shows up correctly). Plus it would be difficult to edit source, although most people won't need to.

I tried maven, but can't get it to work. Seems like I'm getting close though.


Return to “Scala”



Who is online

Users browsing this forum: No registered users and 1 guest