Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3191 expose isbullet #5905

Merged
merged 7 commits into from Jul 19, 2021
Merged

Conversation

otsakir
Copy link
Contributor

@otsakir otsakir commented Jun 28, 2021

Introduces 'bullet' property to collisionobject. See #3191.

Implementation

Property added only for 2D physics - Box2D. In 3D physics if you try to get the 'bullet' property the following warning/error is displayed

WARNING:GAMESYS: 'bullet' property not supported in 3d physics mode
ERROR:SCRIPT: /main/bullet.script:38: '/go#collisionobject' does not have any property called 'bullet'
stack traceback:
  [C]:-1: in function get
  /main/bullet.script:38: in function </main/bullet.script:26>

Testing

The feature is tested by getting and setting the 'bullet' property and asserting it is valid. No test code is written to test actual behavior of a bullet sprite and whether this is accomplished. This is assumed to be part part of box2d testing. Also, you'll notice that i've renamed Sleeping2DCollisionObjectTest to CollisionObject2DTest. The idea is to use this test class as the base for generic high-level collision object testing in gamesys module. Also, properties.script is supposed to be the test script where elementary testing is done for physics properties.

I've also built the editor with bullet property support, created a new project that plays with the property and assured it is shown and initialized properly while getters setters also work. Everything seems to work ok.

Editor

After the core implementation (writing code that makes the calls to box2d and provide the lua api) and test, some further changes were needed to make the property work seamlessly, allow initialization from a .collisionobject file, get displayed in the editor. I used 'Locked Rotation' property as a guide.

@britzl
Copy link
Contributor

britzl commented Jun 28, 2021

Fantastic! Is the feature ready for review?

@otsakir
Copy link
Contributor Author

otsakir commented Jul 2, 2021

@JCash , please tell me if you need any more help with this PR. I noticed there is a test failing. I'll try merging from dev in case something is left out.

Copy link
Contributor

@JCash JCash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Missing test + implementation for null implementation.

@@ -1160,6 +1164,15 @@ namespace dmGameSystem
out_value.m_Variant = dmGameObject::PropertyVar(dmPhysics::GetMass2D(component->m_Object2D));
}
return dmGameObject::PROPERTY_RESULT_OK;
} else if (params.m_PropertyId == PROP_BULLET) {
if (physics_context->m_3D) {
// TODO - display not-implemented warning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've done the TODO, so you can remove the comment :)

@otsakir
Copy link
Contributor Author

otsakir commented Jul 4, 2021

@JCash , i've added "implementation" in physics_2d_null.cpp locally. I still need to understand how this works.

  • Is there some sort of test i need to add ? I think you mentioned something about test_physics_2d.cpp. Maybe something that just creates a collision object and accesses Bullet* operations ?
  • In the test build directory i noticed that there are both test_physics_2d and test_physics_2d_null binaries produced. Why have a "test_physics_2d_null" ? What is the behavior i should expect when running these ? I mean, there is a single test_physics but two test binaries produced...

@JCash
Copy link
Contributor

JCash commented Jul 6, 2021

@otsakir As I mentioned in the Discord chat, our users use the physics_null and physics_2d_null libraries too.
So if we don't implement the functions there too, they will get Undefined symbols errors when building the game.
An example of a fix for it is here.

Since it's easy to forget, we also added a unit test specifically for this. they are called test_physics_null and test_physics_2d_null.

These tests link against the physics_null and physics_2d_null libraries respectively. So, if you're using a new function in a test, but forget to add the null implementation, it is automatically caught and you'll get a linker error (Undefined symbol).

Try it!
Comment out your null implementation, add a test using the physics function, then build the physics tests, and you should get a linker error.

typename TypeParam::CollisionShapeType shape = (*TestFixture::m_Test.m_NewBoxShapeFunc)(TestFixture::m_Context, Vector3(0.5f, 0.5f, 0.0f));
typename TypeParam::CollisionObjectType dynamic_co = (*TestFixture::m_Test.m_NewCollisionObjectFunc)(TestFixture::m_World, data, &shape, 1u);

(*TestFixture::m_Test.m_IsBulletFunc)(dynamic_co);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you don't check the return values of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the test was mostly about calling the functions and assuring they don't produce a link error. Let me fix...

typename TypeParam::CollisionObjectType dynamic_co = (*TestFixture::m_Test.m_NewCollisionObjectFunc)(TestFixture::m_World, data, &shape, 1u);

(*TestFixture::m_Test.m_IsBulletFunc)(dynamic_co);
(*TestFixture::m_Test.m_SetBulletFunc)(dynamic_co, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SInce the default is false, isn't it better to test to set it to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the test was mostly about calling the functions and assuring they don't produce a link error. Let me fix...

@otsakir
Copy link
Contributor Author

otsakir commented Jul 13, 2021

@JCash , ready for review!

@JCash JCash merged commit b3ac504 into defold:dev Jul 19, 2021
pull bot pushed a commit to proteanblank/defold that referenced this pull request Jul 28, 2021
* Added 'bullet' property to go and underlying glue code with box2d - ref defold#3191

* Issue 3191: getter/setter test for collision-object bullet property - ref defold#3191

* Issue 3191: proper support for 'bullet' property in the engine

that is, besided interfacing with the box2d engine

* Issue 3191: Added 'bullet' property to editor - ref defold#3191

* Issue 3191: Added bullet tests for null physics implementation - ref defold#3191

Also removed obsolete comment

* Issue 3191: Small fix for IsBullet() test - ref defold#3191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants