Developing my mphys package with demo

Many of you were nice enough to try this out before so I thought I’d put progress over in its own thread instead of always clogging up the screenshots thread. I’ve moved the download and done an update with a stats HUD and stuff. It also actually puts objects to sleep when they are inactive versus always processing them all the time.

The new download page is here:

…a bit nicer download speed, too, I guess.

From before…

So, this past week I started rewriting my physics engine from the ground up based on several years of lessons learned. This time I intend to build in ‘zones’ right from the start. Part of this was a redesign to clean a bunch of things up so it’s always exciting when it starts working again. Even kind of more exciting when I find and fix a bunch of bugs that existed in the math for a long time but only now are easy to find because of the better infrastructure.

I’m building this as part of a suite of Mythruna-related infrastructure that I may open source separately at some point. It kind of just depends on how far it goes and if it stays clean enough.

Anyway, not much to see but I do have some screen shots today. These are pictures of my demo app that I use to test things. I can shoot various size ‘bullets’ as well as drop big 1 meter radius bombs. This sequence is after I spammed a bunch of stuff and I’m watching it settle and the temperatures cool down (I use simulated annealing for improved accuracy but that’s another story.) The solid shapes are static. The textures shapes are the bullets and bombs and stuff.


Full discussion starts here:

Also from before:

WASD + mouse moves/looks. Left mouse fires big bullets, right mouse fires little bullets… space bar drops a bomb at the section of ground you are looking at. With no crosshair it’s kind of find to guess.

The settings are currently optimized for stability so it’s possible to get the balls to hang over the edges of the cubes and stuff if you hit them right. I’m also not sure why friction stops the small balls instantly on a rebound. It may be due to some other friction changes I made and it may just be a fact of counter rotation + high friction and low restitution (bounce).

Either way, I will always err on the side of stable versus chaotic. It works better for me and my game. (And hours of playing Skyrim makes me feel much better about my physics engine, anyway.)

To that I will add that F5 toggles the JME HUD. I haven’t setup a key for the new physics stats HUD so it will always be on.

In the new stats HUD:
Total: the total number of objects.

Active: the number of objects that have not cooled and gone to sleep.

Frame load: the percentage of a theoretical 1/60th of a second that the physics step is taking. Low is good. more then 100% means frames are dropping for sure.

Object load: is the average number of ms that a single object costs. This is more for me to compare the performance of the new algorithms I add. Some of them will add a constant per-object-load while decreasing the maximum per object load in the busiest cases. I needed a way to see this and see when I’ve done something really wrong in a way that doesn’t necessarily require me to spam 1000 objects first. (Though note: low object counts get penalized for the non-per-object stuff.)


And I know the thread title is strange but there was a silly minimum length requirement and technically I will probably be talking about the development here, too.

Hopefully in the next version, I will have space partitioned into a grid. The fundamental raison d’être.

Objects are now being tracked by “bin” and the overall bin activity is tracked. (No new release yet… just pictures.)

I have it setup on a 10x10 grid now for the binning. It’s not used for collision reduction or anything yet… I’m just trying to make sure it’s applied correctly and that I have nice debug views of the status of each bin and whether it exists or not.

Yellow highlighting shows the regular 10x10 grid. A slightly inside, brighter, box will display for bins that have objects in them… red indicates the objects are still active, cyan indicates that the objects have all gone to sleep. Bins are removed as they empty.

Still to add before I deal with using this to reduce processing and collisions checks: keeping the neighbors of active bins resident even if they only have static objects. Once state is properly mapped and thoroughly debugged I can start implementing one of two collision reduction approaches.


Putting this here also:
Objects organized into spatial ‘bins’ and only the active bins (and neighbors) are managed at any given time.

Animated 1000+ balls cooling down:

Is it not an open source?

Not yet. Going to bang on it a while and then see.

Edit: but also note, for most people bullet will be a better solution.

Really cool.

Have you done any bench marking yet ? Approx where does performance sit atm, on par with Bullet, faster, slower ?

Probably slower… in some cases. I don’t know really because I have never used bullet.

And anyway, this is only able to do sphere-sphere and sphere-to-axis-aligned boxes at the moment. It will slow down more when I add block mesh collisions. Hopefully not too much.

One thing I think I have over bullet is the ability to load/unload sections of the world on the fly and automatically track which bin/zone an object ends up in. But I’ve never looked into bullet.

I would like to investigate the performance of your library and try to make some optimization :slight_smile:

Cool. Knowing there is actual interest means I’m that much more likely to publish it when it’s ready.

Also, I would like to integrate your library to my editor :slight_smile:

Was your library built for a specific use case? If so, could you say a little about what case it was intended to address?

This post might answer most of the questions:

1 Like

I’ve posted a new version if anyone wants to try it:

It aggressively manages its bins and only has the minimum loaded into the physics engine at any given time.

On one of my computers, I see the case where with lots of objects, after the bins have all become unloaded, firing a projectile has a noticeable pause. This is instantaneous on another of my systems and seems to have to do with log file buffering.

Anyway, other than that, it should work ok. If in the off chance it crashes for anyone due to an exception then I’d like to see the log from that run.

Pushed another version up:

In addition to all of the previous bin stuff this version also exposes a bunch of physics related parameters in a pop-up settings panel. You can change all kinds of stuff like the projectile speed/size/mass, gravity, damping, annealing thresholds, and so on.

It also has a nice pop-up help page that shows the input bindings for the various functions.

In-game help:

(the interesting thing about the in-game help is that it’s nearly completely driven by the actual input mappings… I hope to make this more generic later and turn it into a lemur extension.)

Settings panel:

1 Like