Giter Club home page Giter Club logo

box2dsharp's People

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

box2dsharp's Issues

Slow moving Body never sleeps, different compared to original Box2D

Hello,

I have this set-up running using Box2DSharp:

			var World = new World(new Vector2(0, -10));
			var groundShape = new ChainShape();
			groundShape.CreateLoop(new[]
			{
				new Vector2(-5, 0),
				new Vector2(5, 0),
				new Vector2(5, 5),
				new Vector2(4, 1),
				new Vector2(-4, 1),
				new Vector2(-5, 5)
			});
			var groundFixtureDef = new FixtureDef
			{
				Density = 0,
				Shape = groundShape
			};
			var groundBodyDef = new BodyDef
			{
				BodyType = BodyType.StaticBody
			};
			var groundBody = World.CreateBody(groundBodyDef);
			groundBody.CreateFixture(groundFixtureDef);

			var ballShape = new CircleShape { Radius = 1 };
			var ballFixtureDef = new FixtureDef
			{
				Density = 1,
				Restitution = 0.75f,
				Shape = ballShape
			};
			var ballBodyDef = new BodyDef
			{
				BodyType = BodyType.DynamicBody,
				Position = new Vector2(0, 10)
			};

			var ball = World.CreateBody(ballBodyDef);
			ball.CreateFixture(ballFixtureDef);
			ball.ApplyForceToCenter(new Vector2(-1000, -400), true);

and this one, an identical one running Box2D:

		b2Vec2 gravity;
		gravity.Set(0.0f, -10.0f);
		m_world = new b2World(gravity);
		b2ChainShape chainShape;
		b2Vec2 vertices[] = {b2Vec2(-5,0), b2Vec2(5,0), b2Vec2(5,5), b2Vec2(4,1), b2Vec2(-4,1), b2Vec2(-5,5)};
		chainShape.CreateLoop(vertices, 6);
		
		b2FixtureDef groundFixtureDef;
		groundFixtureDef.density = 0;
		groundFixtureDef.shape = &chainShape;
		
		b2BodyDef groundBodyDef;
		groundBodyDef.type = b2_dynamicBody;
		
		b2Body *groundBody = m_world->CreateBody(&groundBodyDef);
		b2Fixture *groundBodyFixture = groundBody->CreateFixture(&groundFixtureDef);
		
		b2CircleShape ballShape;
		ballShape.m_radius = 1;
		
		b2FixtureDef ballFixtureDef;
		ballFixtureDef.restitution = 0.75f;
		ballFixtureDef.density = 1;
		ballFixtureDef.shape = &ballShape;
		
		b2BodyDef ballBodyDef;
		ballBodyDef.type = b2BodyType::b2_dynamicBody;
		ballBodyDef.position = b2Vec2(0, 10);
		
		b2Body *ball = m_world->CreateBody(&ballBodyDef);
		b2Fixture *ballFixture = ball->CreateFixture(&ballFixtureDef);
		
		
		ball->ApplyForceToCenter(b2Vec2(-1000, -400), true);

I also made sure that both b2Settings were set the same.
As you might notice the original Box2D seems to be quicker at damping the force of the ball, my guess is that this might have something to do with the friction calculation or maybe a rounding issue. In this example, the original Box2D ball stops right away, while on Box2DSharp, the ball keeps on going even after colliding against the ball and then until it collides the other wall, but it takes a really long time for it to move, but makes it there. So the results are very different.
Any ideas of what could be causing this?

World.Locked,并发问题。

最近又拾起box2d,重新看了一些资料,然后又好奇box2d的线程安全怎么做的,发现仅仅通过一个变量控制的,这应该是不可靠的。建议Box2DSharp使用volatile bool _locked来标记,或者用mutex、lock语句。
使用一个普通类成员变量做多线程同步的标记产生的Bug不一定容易复现(一定会复现),但是不是正确的线程同步方法。

世界快照功能

现在有个想法是世界暂停后持久化/序列化,将来再恢复。希望加上这个feature。
我看到有Dump方法声明了,什么时候继续?

无法访问已释放的对象

新建了一个winform工程测试了下Box2DSharp。
关闭窗体退出程序就会报这个错:

System.ObjectDisposedException
HResult=0x80131622
Message=无法访问已释放的对象。
ObjectDisposed_ObjectName_Name
Source=mscorlib
StackTrace:
在 System.Threading.ThreadLocal1.GetValueSlow() 在 System.Threading.ThreadLocal1.get_Value()
在 System.Collections.Concurrent.ConcurrentBag1.GetThreadList(Boolean forceCreate) 在 System.Collections.Concurrent.ConcurrentBag1.Add(T item)
在 Box2DSharp.Common.SimpleObjectPool1.Return(IEnumerable1 items) 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Common\ObjectPool.cs 中: 第 88 行
在 Box2DSharp.Collision.DynamicTree.Dispose() 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Collision\DynamicTree.cs 中: 第 69 行
在 Box2DSharp.Collision.DynamicTree.Finalize() 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Collision\DynamicTree.cs 中: 第 56 行

======================
代码就new 了一个World,添加了几个body,什么都没做。
退出前手动world.Dispose()也不行。

安卓端报Fail,没有找到原因

image
04-25 11:27:08.624 32136 5338 I IL2CPP : Fail:
04-25 11:27:08.624 32136 5338 I IL2CPP : tactListener listener) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.ContactManager.Collide () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.Step (System.Single timeStep, System.Int32 velocityIterations, System.Int32 positionIterations) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at DJ.WorldComponentSystem.WorldLogic (DJ.WorldComponent self, System.Single delayTime) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at ET.EventSystem.FixedUpdate () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : ics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam
04-25 11:27:08.625 32136 5338 I IL2CPP : at System.Diagnostics.DefaultTraceListener.Fail (System.String message, System.String detailMessage) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at System.Diagnostics.TraceInternal.Fail (System.String message) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Collision.DynamicTree.RayCast (Box2DSharp.Dynamics.Internal.ITreeRayCastCallback& inputCallback, Box2DSharp.Collision.Collider.RayCastInput& input) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.RayCast (Box2DSharp.Dynamics.IRayCastCallback& callback, System.Numerics.Vector2& point1, System.Numerics.Vector2& point2) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.Tools.CheckMaskRay (System.Object obj, Box2DSharp.Dynamics.World world, System.UInt16 layerMask, System.Numerics.Vector2 start, System.Numerics.Vector2 end, DJ.ParamsRayCast paramsRayCast, System.Boolean debug) <0x00000 + 0xffffffff> 0 in <00000000000000000000000
04-25 11:27:08.625 32136 5338 I IL2CPP : 00000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.ColliderHelp.WithDesUnitHasBlock (DJ.ColliderComponent self, System.Numerics.Vector2 desPos, System.Boolean& hasBlock, System.UInt16 layerMask) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.BulletTypeStaticEffect.HitUnit (DJ.Unit eUnit) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.BulletHelper.CollectHitDes (DJ.BulletComponent self, DJ.ColliderComponent entity, System.Boolean hasDestroyItem) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.ColliderComponentSystem.CollisionStartEdge (DJ.ColliderComponent self, DJ.ColliderComponent entity, Box2DSharp.Dynamics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam
04-25 11:27:08.625 32136 5338 I IL2CPP : cs.IContactListener listener) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.ContactManager.Collide () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.Step (System.Single timeStep, System.Int32 velocityIterations, System.Int32 positionIterations) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.WorldComponentSystem.WorldLogic (DJ.WorldComponent self, System.Single delayTime) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at ET.EventSystem.FixedUpdate () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : ics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam

目前的性能是怎样的?

和cpp版的对比了下,代码大同小异,都是往一个大桶随机扔矩形和圆形,都是release版编译,我的Profile是这样的:
vs2
vs3

计算速度和位置这两步差的有点多?

Performance when using `in` arguments with Vector2

Hi,

I noticed that you use the in keyword when passing down a Vector2. I think you might be doing this for performance reasons to avoid copying the Vector2. However, Vector2 is not a readonly struct, so when you do this, I believe the compiler is making defensive copies of Vector2 regardless, making this not efficient.
https://github.com/Zonciu/Box2DSharp/blob/master/src/Common/MathUtils.cs#L12

More about in arguments with mutable structures:
https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-mutable-structs-as-an-in-argument

CPU is 100% loaded because of big gravity.

When I set gravity(Y) in world.Gravity/gravityScale for a body to a big value(40-50 gravityScale for example) I get my CPU 100% loaded. In the same time, I can create a lot of bodies with gravityScale<40 I get my processor works fine, as without these bodies at all.

对象池优化

优化对象回收到对象池的逻辑,发现问题请在此处留言。
分支:dev

Unity test.

Hi,

Is the Unity project really working/done? Apparently is using dependencies of ImGUI and several others, I can't compile.
Regards.

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.