2D Physic Engine what perfermance?

Hi all, my name's Francesco, my first post here :smiley:

I'm writing a little 2D physic engine in C for fun, and in the simulator it always runs smootly at 30 fps, no matter how many object I have.

I have no real Playdate, so I don't have any idea of the performace, that could be really bad, I known. I don't care too much because I'm doing it to learn how to implement a physic simulation, anyway it would be great if the it could move a few objects :D!!

I attach some videos of the developing progresses :slight_smile:

Update 1.

Update 2.

Update 3.

Update 4.

3 Likes

If you want me to test it, plz attached a zipped pdx built for hardware

1 Like

As I understand it, lua performance is somewhat throttled, but C performance is basically at the same speed as your PC, more or less. It's definitely worth testing this on device to see what real world performance looks like.

Nice job Frank, it seems you do some nice progress :slight_smile:

@robinmaypanpan The performance in C are not the same as on PC. C is more performant than Lua but both will not run as fast as on PC simply because it is not reliable to emulate the playdate performance in the simulator.

As Nino suggested, the best is to share playdate builds so that people can try and record it.

For reference Dustin already ported box2d lite on playdate and this is pretty fun to use in a game even though it can handle only few objects at a time.

I've done a bit of testing and it seems like Chipmunk2D C lib handles more objects than playbox but I haven't done extensive testing. Considering switching to it for Playmaker at some point.

Just want to +1 this. Performance in the simulator is not indicative of device performance.

Interesting this is I have used the playbox and Chipmunk examples in these forums and they work great in the simulator and i've not gotten ANY of them to run on the actual device. I even used chipmunk2d from scratch (not based on the code in the forum) and stripped the code down to the very basics, it's only 150 lines for my game. And the physics WILL NOT work on the device even though it works perfectly in the simulator. The gravity works but the items won't bounce or collide or anything. I've spent almost a month troubleshooting things and I'm at my wits end.

Do you have your test code hosted somewhere? I'd be interested in taking a look because I have a couple of ideas that rely on physics. I'm certain 50fps physics is possible

@Nino has chipmunk running using Nim https://discord.com/channels/675983554655551509/989632121410842625/1189339798503174154

1 Like

You might also link the Github repo: GitHub - ninovanhooff/playdate-dirtbike-experiment

Since it is still in the prototype phase, the code is messy and the juicy bits are the in hello.nim

The current code runs at 50fps with 30% cpu. If you keep it simple, it's possible on this device.

In my case it means having only the wheels and the ground as collision objects

2 Likes

Same implementation in Nim, as you can (barely) see, I get 57+ fps on device, depending on the size of the portion of the screen being refreshed.

IMG_0590 2 8

1 Like

Is Nim the way to go for this? Is it better than Lua or full C?

Since the cpu has to do it all, native languages are preferred over Lua I'd say. Few Lua calls are needed to update the simulation, but rendering has been shown to be considerably slower in Lua. C and nim are interchangeable, performance-wise. So between nim and C, pick what you prefer

Maybe it's because I'm on windows and windows is the bane to my existence while coding, I couldn't get chipmunk to work on it for C on the device, and now trying to install Nim, I get this when trying to run the example:
playdate-0.12.0-3ebf44b45466dfec53e569583a9b86f8323c2729\playdate\api.nim:53:28: error: conflicting types for 'NimMain'; have 'void(void)'
53 | return -1

It's all very frustrating and I feel like pulling out teeth to get anything good coded with physics on the device. I've now been fighting it for 2 months

Quick Question... how does one get 57 fps? I thought it can only run at 30

Edit: i checked the documentation, there is a way to change it. The max it can go up to is 50 though, so im still confused

You can set the refresh rate to zero, which is unlimited, so the game will run as fast as it can go.

How fast your particular game can go will depend on two things: CPU load (how much it's doing) , and how much is being drawn to the screen (specifically how many dirty rows). @Rusty

1 Like