dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: New Game (Physics) Dynamics port

  1. #1
    Member
    Join Date
    Aug 2007
    Posts
    61

    New Game (Physics) Dynamics port

    So physics fans - its a day that has 'y' in it so in to that must mean a port of some physics engine has been converted to Actionsctipt!

    This time it a port of the C Chipmunk library to Actionsctipt (this is in part based on Box2D).

    I've not finished yet, lots more to do, several features and for example broadphase + loads of optimizations but it seems to work ok. The ultimate goal is to make this dead easy for anybody to use - there are only 12 classes that at the moment.

    Take a look here: pEngine

  2. #2
    Member
    Join Date
    Aug 2007
    Posts
    61
    A new stress test demo. Its basically the same as the previous demos, only demo 4 (click on control and press 4) is now 246 individual blocks.

    Fire blocks with the mouse into the scene...

    http://home.planet.nl/~borst595/pEngine246.swf

    Source to follow - but its ugly ugly ugly. The things we do in the name of performance....

  3. #3
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    Hi,

    Man that's impressive!!! I had so much fun just shooting the pyramid and restarting and doing it all over again.
    now known as dVyper

  4. #4
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    this is impressively fast- nice job! i'm excited to see the code. is it an api true port?

  5. #5
    Member
    Join Date
    Aug 2007
    Posts
    61
    Thanks - not sure what 'api true port' it though...

    A quick summary of how it went:

    First I did a straight C to AS3 port, just getting something working. Fortunately the original source was fairly well encapsulated so the conversion
    was not to bad. I got a version of the domino pyramid working (7 width x 7 high) at something like 10 fps, very high CPU load.

    Next, I made a list of the very C specific things that just were not going to run well in Flash.

    - First was all the Vector operations. To help with a bug free port I used my own Vector class to get all the vector math right. I inlined the math for the most critical sections which helped.

    - Second, I used the Flex profiler to look at object creation/deletion - there was lots. With a graphics frame rate of 30fps and the physics running at 60 fps there were millions of objects being create and delete every minute- and many of these were being insert and removed from arrays. I replaces all critical arrays with linked lists, and created object pools for these objects so once create, and used they could be recycled. This dropped the object count down by a factor of 10 to 100. In fact once the simulation is up a running almost no objects are ever created now.

    I then went back and inlined many more bits of code - specifically the impulse solver.

    The main things left to do at the moment are:
    1) Fix some circle/polygon collision issues
    2) Make the API real easy for people to use
    3) Implement some kind of broad phase - at the moment its just brute force

    The source code will be available - if you want it now pm me. I'll create a SVN repo soon. I need to tidy some things up. If you saw the main loop you might die - loads of inline linked list manipulation....

    Any ideas for broad phase? I'm gona try the Chipmunk Spacial hash, and maybe quad tree. My first attempt at some simple buckets did not go well, had a negative impact on performance, even though my comparison count went down from something like 30,000 to 2,000.

  6. #6
    Senior Member axcho's Avatar
    Join Date
    Jun 2006
    Posts
    113
    Wow, that's scary. I'd love to see the source code sometime.

  7. #7
    Programmer
    Join Date
    Aug 2007
    Posts
    173
    very nice and very fast

  8. #8
    Junior Member
    Join Date
    Jan 2008
    Location
    Lost in the Alps
    Posts
    25
    Beautiful.

  9. #9
    Flash developer
    Join Date
    Dec 2007
    Posts
    26
    Just, wow. Great job

    Might have to learn AS3 now after all.....

  10. #10
    Funkalicious TOdorus's Avatar
    Join Date
    Nov 2006
    Location
    Nijmegen, Netherlands
    Posts
    697
    Ooooh, I can imagine a game with the player bieng demolisher for hire right now!

    Kudos!

  11. #11
    Member
    Join Date
    Aug 2007
    Posts
    61
    Rather than wait until I'm 100% happy with the code (which is never) I've decided to release the code now, and carry on working on it over the next few months.

    The project home & SVN can be found here:
    http://code.google.com/p/glaze/

    The latest demos can always be found here:
    http://home.planet.nl/~borst595/glaze.html

    There are a few new demos + you can now attract shapes with shift + left mouse. My favorite at the moment is demo 5 + attract.


    Some notes about the source:

    - Almost every design/coding decision was taken on its performance merit. I don't really care if some thing is hard to read, the purpose of this engine is to enable physics in games for as little CPU overhead as possible

    - The core physics solver is based on Chipmunk, which in turn is somewhat based on Box2D

    - There is still lots to do!
    Last edited by rje; 02-06-2008 at 10:47 AM.

  12. #12
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    i've never looked at the Chipmunk source, but I wanted to say that this looks REALLY good! Very easy to get into, I think. I had a quick look through the source and it's really logically laid out and easy to follow. The performance is seriously awesome... I wonder how much of an increase you get by inlining so much.

    will it support constraints/joints in the future?

  13. #13
    Member
    Join Date
    Aug 2007
    Posts
    61
    Hey - thanks, took quite some effort. Converting Non-OOP C to OOP AS3 can be a bit of a headache sometime. I had to do some major refactoring from the C version, it relied heavily on constructing new arrays all the time - something that just wont fly in AS3.

    I tried to lay out the classes as simply as possible - in the end there were only 11, of which 4 are very very small.

    There is still lots to come. The broadphase in this version is my variant (if thats possible) of sort&sweep. Its very good in situations with lots of tightly packed shapes but I think I need quad-tree as well. I'll put the joints in this weekend.

    As for the inlining - I spent some serious time with the flex profiler. Inlining all the vector math must have doubled the performance I think, as well as inlining the main step function in the Space class. The other speed bump came from pooling/reusing objects - once up an running, very very objects are create/destroyed.

  14. #14
    Programmer
    Join Date
    Aug 2007
    Posts
    173
    i cant see the Demos


    EDIT fixed it....i can see em now ^^
    Last edited by hunty93; 02-12-2008 at 02:41 PM.

  15. #15
    Member
    Join Date
    Aug 2007
    Posts
    61
    I should add - best viewed with latest flash player AND Firefox Beta 3....

  16. #16
    Member
    Join Date
    Feb 2007
    Location
    Sydney, Australia
    Posts
    57
    That is amazing! Anything to do with Physics is amazing :P

  17. #17
    Junior Member
    Join Date
    Feb 2008
    Posts
    3
    man... i only have Flash 8. is there any AS2 physics engines out there?

    great engine, btw.

  18. #18
    Member
    Join Date
    Aug 2007
    Posts
    61
    thanks

    is there any AS2 physics engines out there?
    Before APE, Alex Cove wrote an AS2 engine called Flade. Also particle physics I think. Just google it..

  19. #19
    Member
    Join Date
    Aug 2007
    Posts
    61
    I just saw APE got back ported to AS2

    http://agave.tequila.com/node/15

  20. #20
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    Awesome rje, your physics demos never fail to impress me
    I downloaded the source but haven't looked at it yet, but I'm sure it'll be interesting to look through. Great job!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center