Giter Club home page Giter Club logo

box2d-optimized's Introduction

Box2D-optimized

This project is currently in alpha, work in progress

Box2D is a 2D physics engine for games, developed and maintained by Erin Catto.

Box2D-optimized is a Box2D fork that aims to offer improved perfromance and scalability, while maintining a similar API and feature set. This library merges commits from upstream Box2D regularly in order to be up to date.

A collection of various benchmarks and graphs showcasing the performance improvement can be found in the box2d-benchmarks repository.

There are a lot of under-the-hood changes in order to achieve this stated speedup, which are described in my dissertation for optimizing Box2D: optimizing-box2d

Contributing

Feel free to open issues for bugs and discussions or make pull requests.

License

Box2D is developed by Erin Catto, and uses the MIT license.

Box2D-optimized is developed by Manolis Tsamis and also uses the MIT license.

Box2D

The rest of the Box2D README is copied here for convinience

Features

Collision

  • Continuous collision detection
  • Contact callbacks: begin, end, pre-solve, post-solve
  • Convex polygons and circles
  • Multiple shapes per body
  • One-shot contact manifolds
  • Dynamic tree broadphase
  • Efficient pair management
  • Fast broadphase AABB queries
  • Collision groups and categories

Physics

  • Continuous physics with time of impact solver
  • Persistent body-joint-contact graph
  • Island solution and sleep management
  • Contact, friction, and restitution
  • Stable stacking with a linear-time solver
  • Revolute, prismatic, distance, pulley, gear, mouse joint, and other joint types
  • Joint limits, motors, and friction
  • Momentum decoupled position correction
  • Fairly accurate reaction forces/impulses

System

  • Small block and stack allocators
  • Centralized tuning parameters
  • Highly portable C++ with no use of STL containers

Testbed

  • OpenGL with GLFW
  • Graphical user interface with imgui
  • Extensible test framework
  • Support for loading world dumps

Building

  • Install CMake
  • Ensure CMake is in the user PATH
  • Visual Studio: run build.bat from the command prompt
  • Otherwise: run build.sh from a bash shell
  • Results are in the build sub-folder
  • On Windows you can open box2d.sln

Building Box2D - Using vcpkg

You can download and install Box2D using the vcpkg dependency manager:

The Box2D port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Note: vcpkg support is not provided by the Box2D project

Building for Xcode

  • Install CMake
  • Add Cmake to the path in .zprofile (the default Terminal shell is zsh)
    • export PATH="/Applications/CMake.app/Contents/bin:$PATH"
  • mkdir build
  • cd build
  • cmake -G Xcode ..
  • open box2d.xcodeproj
  • Select the testbed scheme
  • Edit the scheme to set a custom working directory, make this be in box2d/testbed
  • You can now build and run the testbed

Installing using CMake

You can use the CMake install feature to deploy the library to a central location that can be accessed using:

find_package(box2d REQUIRED)
target_link_libraries(mytarget PRIVATE box2d)

You can build and install the library and docs using this command sequence (requires Doxygen):

mkdir build
cd build
cmake -DBOX2D_BUILD_DOCS=ON ..
cmake --build .
cmake --build . --target INSTALL

On Windows this tries to install in Program Files and thus requires admin privileges. Alternatively you can target another directory using something like this:

mkdir build
cd build
cmake -DBOX2D_BUILD_DOCS=ON -DCMAKE_INSTALL_PREFIX="C:/packages" ..
cmake --build .
cmake --build . --target INSTALL

Documentation

Sponsorship

Support development of Box2D through Github Sponsors

box2d-optimized's People

Contributors

erincatto avatar jube avatar mtsamis avatar nancyli1013 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

box2d-optimized's Issues

The testbed 'Geometry/Edge Shapes' test crashed frequently.

When rapidly pressed '1-5' key to drop stuff, It will crashed.

  • Here is the screenshot:
    Screen Shot 2023-01-06 at 12 10 13
  • Here is the crash report:
    Crashed Thread:        0  Dispatch queue: com.apple.main-thread
    Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
    Exception Codes:       0x0000000000000001, 0x0000000000000000
    Exception Note:        EXC_CORPSE_NOTIFY
    
    Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
    Terminating Process:   exc handler [85566]
    
    VM Region Info: 0 is not in any region.  Bytes before following region: 4538880000
          REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
          UNUSED SPACE AT START
    --->  
          __TEXT                      10e89d000-10ea05000    [ 1440K] r-x/r-x SM=COW  ...nts/*/testbed
    
    Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
    0   testbed                       	       0x10e914c3c b2TreeNode::IsLeaf() const + 12 (b2_broad_phase.h:40)
    1   testbed                       	       0x10e8f574d void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 45 (b2_broad_phase.h:589)
    2   testbed                       	       0x10e8f58ed void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 461 (b2_broad_phase.h:619)
    3   testbed                       	       0x10e8f5846 void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 294 (b2_broad_phase.h:607)
    4   testbed                       	       0x10e8f58ed void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 461 (b2_broad_phase.h:619)
    5   testbed                       	       0x10e8f5846 void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 294 (b2_broad_phase.h:607)
    6   testbed                       	       0x10e8f5846 void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 294 (b2_broad_phase.h:607)
    7   testbed                       	       0x10e8f58ed void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 461 (b2_broad_phase.h:619)
    8   testbed                       	       0x10e8f5846 void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 294 (b2_broad_phase.h:607)
    9   testbed                       	       0x10e8f5846 void b2BroadPhase::QueryAll<b2ContactManager>(b2ContactManager*, b2TreeNode const*, b2TreeNode**, int) const + 294 (b2_broad_phase.h:607)
    10  testbed                       	       0x10e8f475b void b2BroadPhase::UpdateAndQuery<b2ContactManager>(b2ContactManager*) + 1067 (b2_broad_phase.h:324)
    11  testbed                       	       0x10e8f431c b2ContactManager::FindNewContacts() + 28 (b2_contact_manager.cpp:119)
    12  testbed                       	       0x10e910ff8 b2World::Solve(b2TimeStep const&) + 2360 (b2_world.cpp:666)
    13  testbed                       	       0x10e91303e b2World::Step(float, int, int, int) + 478 (b2_world.cpp:1151)
    14  testbed                       	       0x10e8b5b45 Test::Step(Settings&) + 501 (test.cpp:362)
    15  testbed                       	       0x10e8ceeb3 EdgeShapes::Step(Settings&) + 99 (edge_shapes.cpp:207)
    16  testbed                       	       0x10e8a9cca main + 1338 (main.cpp:595)
    17  dyld                          	       0x11954052e start + 462
    
  • Here is the lldb reports:
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
        frame #0: 0x000000010008e368 testbed`b2Fixture::RayCast(this=0x0000000130033e31, output=0x00007ff7bfefe260, input=0x00007ff7bfefe3b0) const at b2_fixture.h:385:19
       382   
       383   inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const
       384   {
    -> 385     return m_shape->RayCast(output, input, m_body->GetTransform());
       386   }
       387   
       388   inline void b2Fixture::GetMassData(b2MassData* massData) const
    
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x41)
        frame #0: 0x000000010001828c testbed`b2Fixture::GetBody(this=0x0000000000000031) at b2_fixture.h:310:10
       307   
       308   inline b2Body* b2Fixture::GetBody()
       309   {
    -> 310     return m_body;
       311   }
       312   
       313   inline const b2Body* b2Fixture::GetBody() const
    

I tested it many times, and produced many kinds of errors.

Crash after creating 28 dynamic objects at runtime.

For some reason after proceeding with Step function if i try create new dynamic object and number of dynamic object is more then 28 I get crash at ContactManager::FindNewContacts.

I don't have such issue with original lib.
Am I suppose to suppose to set up something?
Thank you.

image

image

inside b2BroadPhase::UpdateAndQuery(T* callback)
image

Implementation issues with TOI solver

There are some bugs in the reworked TOI implementation that make it not work correctly.

  • It looks like bullet bodies work, at least to some extend, as can be found out by playing around with the "Add pair" testbed scene.
  • Dynamic vs static isn't working. This can be seen in the "Platformer" testbed scene when compared to Box2d.

I need to fix these issues and investigate the correctness of the TOI implementation in general.

[bug] Static bodies get broken if its transform changed after creation.

If you create a body, defining it as static in BodyDef. And then you will try to transform to another position (even slightly), then it becomes completely broken. Collisions mostly stop working. Dynamic bodies don't interact with it, flying through, get pushed in random locations.

But debug draw draws them correctly.

To reproduce use this code for static bodies in Tiles Test:


			float a = 0.5f;
			int32 N = 200;
			int32 M = 10;
			b2Vec2 position;
			position.y = 0.0f;
			for (int32 j = 0; j < M; ++j)
			{
				position.x = -N * a;
				for (int32 i = 0; i < N; ++i)
				{
					b2BodyDef bd;
					bd.position = position;
					b2Body* ground = m_world->CreateBody(&bd);

					b2PolygonShape shape;
					shape.SetAsBox(a, a);
					ground->CreateFixture(&shape, 0.0f);
					++m_fixtureCount;
					position.x += 2.0f * a;
					ground->SetTransform(position+b2Vec2(-1, -1), 0.1);

				}
				position.y -= 2.0f * a;
			}

box2dbug

Box2D Testbed is not compatible with Box2D-optimized

I got some compiler errors...

Once be: b2ChainShape unknown

I thought In can use Box2D-optimized without any changes on my Box2D app.
Only switching from Box2D to Box2D-optimized and can use my original sources whitout any changes.

Update and merge into Box2D?

Found this via the benchmarks page, and honestly, it looks really good. Is there any reason for keeping it as a separate project instead of merging the optimisations into the base library?

Build instructions in README.md is out of date and irrelevant to Box2D-optimized

Due to the nature of this fork ditching the .sln file for building the bat file no longer works. Please either consider creating a new Visual Studio Solution, or update the readme with relevant library installation instructions.

I would love to use this library but without proper build instructions out of the box it feels like wasted extra steps

The testbed(Debug) 'Examples/Body Types' crashed when changed body type.

When press key 's' or 'k' to change body type, it will crash. It's a debug build.

  • Here is the screenshot.
    Screen Shot 2023-01-06 at 12 55 56
  • Here is the llbd report:
     * thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
         frame #4: 0x00000001000741cf testbed`b2Island::Add(this=0x00007ff7bfefeaf0, contact=0x000000010084f000) at b2_island.h:67:5
        64  	
        65  	  void Add(b2Contact* contact)
        66  	  {
     -> 67  	    b2Assert(m_contactCount < m_contactCapacity);
        68  	    m_contacts[m_contactCount++] = contact;
        69  	  }
        70  	
     Target 0: (testbed) stopped.
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.