Add PhysicsBehavior support to newIDE, with an example

This commit is contained in:
Florian Rival
2018-01-21 22:11:24 +01:00
parent c876f67502
commit f115b6607f
22 changed files with 7454 additions and 760 deletions

View File

@@ -13,6 +13,7 @@
"/usr/local/lib/wx/include/osx_cocoa-unicode-3.0",
"/usr/local/include/wx-3.0",
"/usr/include/machine",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.0.0/include",

View File

@@ -67,7 +67,10 @@
"__functional_base": "cpp",
"__functional_base_03": "cpp",
"chrono": "cpp",
"ratio": "cpp"
"ratio": "cpp",
"atomic": "cpp",
"locale": "cpp",
"string_view": "cpp"
},
"files.exclude": {
"Binaries/*build*": true,

View File

@@ -37,9 +37,7 @@ IF (NOT EMSCRIPTEN)
ADD_SUBDIRECTORY(PathBehavior)
ENDIF()
ADD_SUBDIRECTORY(PathfindingBehavior)
IF (NOT EMSCRIPTEN)
ADD_SUBDIRECTORY(PhysicsBehavior)
ENDIF()
ADD_SUBDIRECTORY(PlatformBehavior)
ADD_SUBDIRECTORY(PrimitiveDrawing)
ADD_SUBDIRECTORY(Shopify)

View File

@@ -592,8 +592,7 @@ void DeclarePathfindingBehaviorExtension(gd::PlatformExtension &extension)
/**
* \brief This class declares information about the extension.
*/
class PathfindingBehaviorCppExtension : public ExtensionBase
{
class PathfindingBehaviorCppExtension : public ExtensionBase {
public:
/**
* Constructor of an extension declares everything the extension contains: objects, actions, conditions and expressions.

View File

@@ -7,7 +7,6 @@ This project is released under the MIT License.
#if defined(GD_IDE_ONLY)
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Tools/Localization.h"
#include <iostream>
void DeclarePathfindingBehaviorExtension(gd::PlatformExtension & extension);
@@ -99,6 +98,7 @@ public:
}
StripUnimplementedInstructionsAndExpressions();
GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
};
};

View File

@@ -9,32 +9,20 @@ This project is released under the MIT License.
* Victor Levasseur (Collisions using custom polygons, fixed time step fix)
*/
#include "GDCpp/Extensions/ExtensionBase.h"
#include "PhysicsBehavior.h"
#include "ScenePhysicsDatas.h"
#include "GDCpp/Extensions/ExtensionBase.h"
/**
* \brief This class declares information about the extension.
*/
class PhysicsBehaviorCppExtension : public ExtensionBase
void DeclarePhysicsBehaviorExtension(gd::PlatformExtension& extension)
{
public:
/**
* Constructor of an extension declares everything the extension contains: objects, actions, conditions and expressions.
*/
PhysicsBehaviorCppExtension()
{
SetExtensionInformation("PhysicsBehavior",
extension.SetExtensionInformation("PhysicsBehavior",
_("Physics behavior"),
_("This extension enables the movement of objects as if they are subject to the laws of physics."),
"Florian Rival",
"Open source (MIT License)");
{
gd::BehaviorMetadata & aut = AddBehavior("PhysicsBehavior",
gd::BehaviorMetadata& aut = extension.AddBehavior("PhysicsBehavior",
_("Physics engine"),
_("Physics"),
_("Make objects move as if they are subject to the laws of physics."),
@@ -57,7 +45,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetStatic").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetStatic")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetDynamic",
_("Make the object dynamic"),
@@ -69,7 +58,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetDynamic").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetDynamic")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("IsDynamic",
_("The object is dynamic"),
@@ -81,7 +71,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.SetFunctionName("IsDynamic").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("IsDynamic")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetFixedRotation",
_("Fix rotation"),
@@ -93,7 +84,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetFixedRotation").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetFixedRotation")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("AddRevoluteJoint",
_("Add a hinge"),
@@ -107,7 +99,8 @@ public:
.AddParameter("expression", _("Hinge X position"))
.AddParameter("expression", _("Hinge Y position"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("AddRevoluteJoint").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("AddRevoluteJoint")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("AddRevoluteJointBetweenObjects",
_("Add a hinge between two objects"),
@@ -120,9 +113,12 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("objectPtr", _("Object"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("X position of the hinge, from the first object mass center"), "", true).SetDefaultValue("0")
.AddParameter("expression", _("Y position of the hinge, from the first object mass center"), "", true).SetDefaultValue("0")
.SetFunctionName("AddRevoluteJointBetweenObjects").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.AddParameter("expression", _("X position of the hinge, from the first object mass center"), "", true)
.SetDefaultValue("0")
.AddParameter("expression", _("Y position of the hinge, from the first object mass center"), "", true)
.SetDefaultValue("0")
.SetFunctionName("AddRevoluteJointBetweenObjects")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ActAddGearJointBetweenObjects",
_("Add a gear between two objects"),
@@ -134,9 +130,11 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("objectPtr", _("Object"))
.AddParameter("expression", _("Ratio"), "", true).SetDefaultValue("1")
.AddParameter("expression", _("Ratio"), "", true)
.SetDefaultValue("1")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("AddGearJointBetweenObjects").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("AddGearJointBetweenObjects")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetFreeRotation",
_("Make object's rotation free"),
@@ -148,7 +146,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetFreeRotation").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetFreeRotation")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("IsFixedRotation",
_("Fixed rotation"),
@@ -160,7 +159,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("IsFixedRotation").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("IsFixedRotation")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetAsBullet",
_("Treat object like a bullet."),
@@ -172,7 +172,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetAsBullet").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetAsBullet")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("DontSetAsBullet",
_("Do not treat object like a bullet"),
@@ -184,7 +185,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("DontSetAsBullet").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("DontSetAsBullet")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("IsBullet",
_("Object is treated like a bullet"),
@@ -196,7 +198,8 @@ public:
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("IsBullet").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("IsBullet")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyImpulse",
_("Apply an impulse"),
@@ -210,7 +213,8 @@ public:
.AddParameter("expression", _("X component ( Newtons/Seconds )"))
.AddParameter("expression", _("Y component ( Newtons/Seconds )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyImpulse").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyImpulse")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyImpulseUsingPolarCoordinates",
_("Apply an impulse (angle)"),
@@ -224,7 +228,8 @@ public:
.AddParameter("expression", _("Angle"))
.AddParameter("expression", _("Impulse value ( Newton/seconds )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyImpulseUsingPolarCoordinates").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyImpulseUsingPolarCoordinates")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyImpulseTowardPosition",
_("Apply an impulse toward a position"),
@@ -239,7 +244,8 @@ public:
.AddParameter("expression", _("Y position"))
.AddParameter("expression", _("Impulse value ( Newton/seconds )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyImpulseTowardPosition").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyImpulseTowardPosition")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyForce",
_("Add a force"),
@@ -253,7 +259,8 @@ public:
.AddParameter("expression", _("X component ( Newtons )"))
.AddParameter("expression", _("Y component ( Newtons )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyForce").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyForce")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyForceUsingPolarCoordinates",
_("Apply a force ( angle )"),
@@ -267,7 +274,8 @@ public:
.AddParameter("expression", _("Angle"))
.AddParameter("expression", _("Length of the force ( Newtons )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyForceUsingPolarCoordinates").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyForceUsingPolarCoordinates")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyForceTowardPosition",
_("Apply a force toward a position"),
@@ -282,7 +290,8 @@ public:
.AddParameter("expression", _("Y position"))
.AddParameter("expression", _("Length of the force ( Newtons )"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyForceTowardPosition").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyForceTowardPosition")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("ApplyTorque",
_("Add a torque (a rotation)"),
@@ -295,7 +304,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("Torque value"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("ApplyTorque").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("ApplyTorque")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetLinearVelocity",
_("Linear velocity"),
@@ -309,7 +319,8 @@ public:
.AddParameter("expression", _("X Coordinate"))
.AddParameter("expression", _("Y Coordinate"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetLinearVelocity").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetLinearVelocity")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("LinearVelocityX",
_("X component"),
@@ -323,7 +334,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocityX").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocityX")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("LinearVelocityY",
_("Y component"),
@@ -337,7 +350,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocityY").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocityY")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("LinearVelocity",
_("Linear speed"),
@@ -351,7 +366,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocity").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocity")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetAngularVelocity",
_("Angular speed"),
@@ -364,7 +381,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("New value"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetAngularVelocity").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetAngularVelocity")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("AngularVelocity",
_("Angular speed"),
@@ -378,7 +396,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetAngularVelocity").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetAngularVelocity")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("LinearDamping",
_("Linear damping"),
@@ -392,7 +412,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearDamping").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearDamping")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("CollisionWith",
_("Collision"),
@@ -405,7 +427,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("objectList", _("Object"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("CollisionWith").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("CollisionWith")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetLinearDamping",
_("Linear damping"),
@@ -418,7 +441,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("Value"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetLinearDamping").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetLinearDamping")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("AngularDamping",
_("Angular damping"),
@@ -432,7 +456,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetAngularDamping").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetAngularDamping")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetAngularDamping",
_("Angular damping"),
@@ -445,7 +471,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("Value"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetAngularDamping").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetAngularDamping")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetGravity",
_("Gravity"),
@@ -459,7 +486,8 @@ public:
.AddParameter("expression", _("X Coordinate"))
.AddParameter("expression", _("Y Coordinate"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetGravity").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetGravity")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetPolygonScaleX",
_("Change the X scale of a collision polygon"),
@@ -472,7 +500,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("Scale"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetPolygonScaleX").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetPolygonScaleX")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddAction("SetPolygonScaleY",
_("Change the Y scale of a collision polygon"),
@@ -485,7 +514,8 @@ public:
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddParameter("expression", _("Scale"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("SetPolygonScaleY").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("SetPolygonScaleY")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("GetPolygonScaleX",
_("Collision polygon X scale"),
@@ -499,7 +529,9 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetPolygonScaleX").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetPolygonScaleX")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddCondition("GetPolygonScaleY",
_("Collision polygon Y scale"),
@@ -513,66 +545,88 @@ public:
.AddParameter("relationalOperator", _("Comparison sign"))
.AddParameter("expression", _("Value to test"))
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetPolygonScaleY").SetManipulatedType("number").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetPolygonScaleY")
.SetManipulatedType("number")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("PolygonScaleX", _("Collision polygon X scale"), _("Collision polygon X scale"), _("Collision polygon"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetPolygonScaleX").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetPolygonScaleX")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("PolygonScaleY", _("Collision polygon Y scale"), _("Collision polygon Y scale"), _("Collision polygon"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetPolygonScaleY").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetPolygonScaleY")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("LinearVelocity", _("Linear speed"), _("Linear speed"), _("Displacement"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocity").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocity")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("LinearVelocityX", _("X component"), _("X component"), _("Displacement"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocityX").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocityX")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("LinearVelocityY", _("Y component"), _("Y component"), _("Displacement"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearVelocityY").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearVelocityY")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("AngularVelocity", _("Angular speed"), _("Angular speed"), _("Rotation"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetAngularVelocity").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetAngularVelocity")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("LinearDamping", _("Linear damping"), _("Linear damping"), _("Displacement"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetLinearDamping").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetLinearDamping")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
aut.AddExpression("AngularDamping", _("Angular damping"), _("Angular damping"), _("Rotation"), "res/physics16.png")
.AddParameter("object", _("Object"))
.AddParameter("behavior", _("Behavior"), "PhysicsBehavior")
.AddCodeOnlyParameter("currentScene", "")
.SetFunctionName("GetAngularDamping").SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
.SetFunctionName("GetAngularDamping")
.SetIncludeFile("PhysicsBehavior/PhysicsBehavior.h");
#endif
}
}
/**
* \brief This class declares information about the extension.
*/
class PhysicsBehaviorCppExtension : public ExtensionBase {
public:
/**
* Constructor of an extension declares everything the extension contains: objects, actions, conditions and expressions.
*/
PhysicsBehaviorCppExtension()
{
DeclarePhysicsBehaviorExtension(*this);
GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
};
};
#if defined(ANDROID)
extern "C" ExtensionBase * CreateGDCppPhysicsBehaviorExtension() {
extern "C" ExtensionBase* CreateGDCppPhysicsBehaviorExtension()
{
return new PhysicsBehaviorCppExtension;
}
#elif !defined(EMSCRIPTEN)
@@ -580,7 +634,8 @@ extern "C" ExtensionBase * CreateGDCppPhysicsBehaviorExtension() {
* Used by GDevelop to create the extension class
* -- Do not need to be modified. --
*/
extern "C" ExtensionBase * GD_EXTENSION_API CreateGDExtension() {
extern "C" ExtensionBase* GD_EXTENSION_API CreateGDExtension()
{
return new PhysicsBehaviorCppExtension;
}
#endif

View File

@@ -6,29 +6,23 @@ This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#include "GDCore/Extensions/PlatformExtension.h"
#include <iostream>
#include "GDCore/Tools/Localization.h"
void DeclarePhysicsBehaviorExtension(gd::PlatformExtension & extension);
/**
* \brief This class declares information about the JS extension.
*/
class JsExtension : public gd::PlatformExtension
class PhysicsBehaviorJsExtension : public gd::PlatformExtension
{
public:
/**
* \brief Constructor of an extension declares everything the extension contains: objects, actions, conditions and expressions.
*/
JsExtension()
PhysicsBehaviorJsExtension()
{
SetExtensionInformation("PhysicsBehavior",
_("Physics behavior"),
_("Behavior allowing to move objects as if they were subject to the laws of physics."),
"Florian Rival",
"Open source (MIT License)");
CloneExtension("GDevelop C++ platform", "PhysicsBehavior");
DeclarePhysicsBehaviorExtension(*this);
GetBehaviorMetadata("PhysicsBehavior::PhysicsBehavior")
.SetIncludeFile("Extensions/PhysicsBehavior/box2djs/box2d.js")
@@ -145,14 +139,21 @@ public:
*/
StripUnimplementedInstructionsAndExpressions();
GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
};
};
#if defined(EMSCRIPTEN)
extern "C" gd::PlatformExtension * CreateGDJSPhysicsBehaviorExtension() {
return new PhysicsBehaviorJsExtension;
}
#else
/**
* Used by GDevelop to create the extension class
* -- Do not need to be modified. --
*/
extern "C" gd::PlatformExtension * GD_EXTENSION_API CreateGDJSExtension() {
return new JsExtension;
return new PhysicsBehaviorJsExtension;
}
#endif
#endif

View File

@@ -7,6 +7,7 @@ This project is released under the MIT License.
#include "PhysicsBehavior.h"
#include <string>
#include "GDCore/Tools/Localization.h"
#include "Box2D/Box2D.h"
#include "Triangulation/triangulate.h"
#include "GDCpp/Runtime/RuntimeScene.h"
@@ -17,6 +18,10 @@ This project is released under the MIT License.
#include "GDCpp/Runtime/Project/Project.h"
#include "GDCpp/Runtime/Project/Layout.h"
#include "RuntimeScenePhysicsDatas.h"
#if defined(GD_IDE_ONLY)
#include <map>
#include "GDCore/IDE/Dialogs/PropertyDescriptor.h"
#endif
#undef GetObject
@@ -100,10 +105,6 @@ void PhysicsBehavior::DoStepPostEvents(RuntimeScene & scene)
float newHeight = object->GetHeight();
if ( (int)objectOldWidth != (int)newWidth || (int)objectOldHeight != (int)newHeight )
{
/*std::cout << "Changed:" << (int)objectOldWidth << "!=" << (int)newWidth << std::endl;
std::cout << "Changed:" << (int)objectOldHeight << "!=" << (int)newHeight << std::endl;
std::cout << "( Object name:" << object->GetName() << std::endl;*/
double oldAngularVelocity = body->GetAngularVelocity();
b2Vec2 oldVelocity = body->GetLinearVelocity();
@@ -700,6 +701,76 @@ void PhysicsBehavior::UnserializeFrom(const gd::SerializerElement & element)
SetPolygonCoords(PhysicsBehavior::GetCoordsVectorFromString(coordsStr, '/', ';'));
}
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::PropertyDescriptor> PhysicsBehavior::GetProperties(gd::Project & project) const
{
std::map<gd::String, gd::PropertyDescriptor> properties;
gd::String shapeTypeStr = _("Box (rectangle)");
if (shapeType == Box) shapeTypeStr = _("Box (rectangle)");
else if (shapeType == Circle) shapeTypeStr = _("Circle");
else if (shapeType == CustomPolygon) shapeTypeStr = _("Custom polygon");
properties[_("Shape")]
.SetValue(shapeTypeStr)
.SetType("Choice")
.AddExtraInfo(_("Box (rectangle)"))
.AddExtraInfo(_("Circle"));
properties[_("Dynamic object")].SetValue(dynamic ? "true" : "false").SetType("Boolean");
properties[_("Fixed rotation")].SetValue(fixedRotation ? "true" : "false").SetType("Boolean");
properties[_("Consider as bullet (better collision handling)")].SetValue(isBullet ? "true" : "false").SetType("Boolean");
properties[_("Mass density")].SetValue(gd::String::From(massDensity));
properties[_("Friction")].SetValue(gd::String::From(averageFriction));
properties[_("Restitution (elasticity)")].SetValue(gd::String::From(averageRestitution));
properties[_("Linear Damping")].SetValue(gd::String::From(linearDamping));
properties[_("Angular Damping")].SetValue(gd::String::From(angularDamping));
properties[_("PLEASE_ALSO_SHOW_EDIT_BUTTON_THANKS")].SetValue("");
return properties;
}
bool PhysicsBehavior::UpdateProperty(const gd::String & name, const gd::String & value, gd::Project & project)
{
if (name == _("Shape"))
{
if (value == _("Box (rectangle)"))
shapeType = Box;
else if (value == _("Circle"))
shapeType = Circle;
else if (value == _("Custom polygon"))
shapeType = CustomPolygon;
}
if ( name == _("Dynamic object") ) {
dynamic = (value != "0");
}
if ( name == _("Fixed rotation") ) {
fixedRotation = (value != "0");
}
if ( name == _("Consider as bullet (better collision handling)") ) {
isBullet = (value != "0");
}
if ( name == _("Mass density") ) {
massDensity = value.To<float>();
}
if ( name == _("Friction") ) {
averageFriction = value.To<float>();
}
if ( name == _("Restitution (elasticity)") ) {
averageRestitution = value.To<float>();
}
if ( name == _("Linear Damping") ) {
if ( value.To<float>() < 0 ) return false;
linearDamping = value.To<float>();
}
if ( name == _("Angular Damping") ) {
if ( value.To<float>() < 0 ) return false;
angularDamping = value.To<float>();
}
return true;
}
#endif
gd::String PhysicsBehavior::GetStringFromCoordsVector(const std::vector<sf::Vector2f> &vec, char32_t coordsSep, char32_t composantSep)
{

View File

@@ -56,6 +56,9 @@ public:
* Called when user wants to edit the behavior.
*/
virtual void EditBehavior( wxWindow* parent, gd::Project & project_, gd::Layout * layout_, gd::MainFrameWrapper & mainFrameWrapper_ );
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(gd::Project & project) const;
virtual bool UpdateProperty(const gd::String & name, const gd::String & value, gd::Project & project);
#endif
/**

View File

@@ -138,6 +138,7 @@ gd::PlatformExtension * CreateGDJSLinkedObjectsExtension();
gd::PlatformExtension * CreateGDJSSystemInfoExtension();
gd::PlatformExtension * CreateGDJSShopifyExtension();
gd::PlatformExtension * CreateGDJSPathfindingBehaviorExtension();
gd::PlatformExtension * CreateGDJSPhysicsBehaviorExtension();
}
#endif
@@ -185,6 +186,7 @@ JsPlatform::JsPlatform() :
AddExtension(std::shared_ptr<gd::PlatformExtension>(CreateGDJSSystemInfoExtension())); std::cout.flush();
AddExtension(std::shared_ptr<gd::PlatformExtension>(CreateGDJSShopifyExtension())); std::cout.flush();
AddExtension(std::shared_ptr<gd::PlatformExtension>(CreateGDJSPathfindingBehaviorExtension())); std::cout.flush();
AddExtension(std::shared_ptr<gd::PlatformExtension>(CreateGDJSPhysicsBehaviorExtension())); std::cout.flush();
#endif
std::cout << "done." << std::endl;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -503,6 +503,78 @@ Object {
},
},
},
"Physics behavior": Object {
"Collision": Object {
"displayedName": "Collision",
"fullGroupName": "Physics behavior/",
"type": "PhysicsBehavior::CollisionWith",
},
"Collision polygon": Object {
"Collision polygon X scale": Object {
"displayedName": "Collision polygon X scale",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::GetPolygonScaleX",
},
"Collision polygon Y scale": Object {
"displayedName": "Collision polygon Y scale",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::GetPolygonScaleY",
},
},
"Displacement": Object {
"Angular damping": Object {
"displayedName": "Angular damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::AngularDamping",
},
"Linear damping": Object {
"displayedName": "Linear damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearDamping",
},
"Linear speed": Object {
"displayedName": "Linear speed",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocity",
},
"X component": Object {
"displayedName": "X component",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocityX",
},
"Y component": Object {
"displayedName": "Y component",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocityY",
},
},
"Movement": Object {
"The object is dynamic": Object {
"displayedName": "The object is dynamic",
"fullGroupName": "Physics behavior/Movement",
"type": "PhysicsBehavior::IsDynamic",
},
},
"Other": Object {
"Object is treated like a bullet": Object {
"displayedName": "Object is treated like a bullet",
"fullGroupName": "Physics behavior/Other",
"type": "PhysicsBehavior::IsBullet",
},
},
"Rotation": Object {
"Angular speed": Object {
"displayedName": "Angular speed",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::AngularVelocity",
},
"Fixed rotation": Object {
"displayedName": "Fixed rotation",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::IsFixedRotation",
},
},
},
"Platform Behavior": Object {
"Is falling": Object {
"displayedName": "Is falling",
@@ -1846,6 +1918,121 @@ Array [
"fullGroupName": "Pathfinding behavior/Obstacles",
"type": "PathfindingBehavior::SetImpassable",
},
Object {
"displayedName": "Add a gear between two objects",
"fullGroupName": "Physics behavior/Joints",
"type": "PhysicsBehavior::ActAddGearJointBetweenObjects",
},
Object {
"displayedName": "Add a hinge",
"fullGroupName": "Physics behavior/Joints",
"type": "PhysicsBehavior::AddRevoluteJoint",
},
Object {
"displayedName": "Add a hinge between two objects",
"fullGroupName": "Physics behavior/Joints",
"type": "PhysicsBehavior::AddRevoluteJointBetweenObjects",
},
Object {
"displayedName": "Add a force",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyForce",
},
Object {
"displayedName": "Apply a force toward a position",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyForceTowardPosition",
},
Object {
"displayedName": "Apply a force ( angle )",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyForceUsingPolarCoordinates",
},
Object {
"displayedName": "Apply an impulse",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyImpulse",
},
Object {
"displayedName": "Apply an impulse toward a position",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyImpulseTowardPosition",
},
Object {
"displayedName": "Apply an impulse (angle)",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::ApplyImpulseUsingPolarCoordinates",
},
Object {
"displayedName": "Add a torque (a rotation)",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::ApplyTorque",
},
Object {
"displayedName": "Do not treat object like a bullet",
"fullGroupName": "Physics behavior/Other",
"type": "PhysicsBehavior::DontSetAsBullet",
},
Object {
"displayedName": "Angular damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::SetAngularDamping",
},
Object {
"displayedName": "Angular speed",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::SetAngularVelocity",
},
Object {
"displayedName": "Treat object like a bullet.",
"fullGroupName": "Physics behavior/Other",
"type": "PhysicsBehavior::SetAsBullet",
},
Object {
"displayedName": "Make the object dynamic",
"fullGroupName": "Physics behavior/Movement",
"type": "PhysicsBehavior::SetDynamic",
},
Object {
"displayedName": "Fix rotation",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::SetFixedRotation",
},
Object {
"displayedName": "Make object's rotation free",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::SetFreeRotation",
},
Object {
"displayedName": "Gravity",
"fullGroupName": "Physics behavior/Global options",
"type": "PhysicsBehavior::SetGravity",
},
Object {
"displayedName": "Linear damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::SetLinearDamping",
},
Object {
"displayedName": "Linear velocity",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::SetLinearVelocity",
},
Object {
"displayedName": "Change the X scale of a collision polygon",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::SetPolygonScaleX",
},
Object {
"displayedName": "Change the Y scale of a collision polygon",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::SetPolygonScaleY",
},
Object {
"displayedName": "Make the object static",
"fullGroupName": "Physics behavior/Movement",
"type": "PhysicsBehavior::SetStatic",
},
]
`;
@@ -2591,5 +2778,65 @@ Array [
"fullGroupName": "Pathfinding behavior/Obstacles",
"type": "PathfindingBehavior::IsImpassable",
},
Object {
"displayedName": "Angular damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::AngularDamping",
},
Object {
"displayedName": "Angular speed",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::AngularVelocity",
},
Object {
"displayedName": "Collision",
"fullGroupName": "Physics behavior/",
"type": "PhysicsBehavior::CollisionWith",
},
Object {
"displayedName": "Collision polygon X scale",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::GetPolygonScaleX",
},
Object {
"displayedName": "Collision polygon Y scale",
"fullGroupName": "Physics behavior/Collision polygon",
"type": "PhysicsBehavior::GetPolygonScaleY",
},
Object {
"displayedName": "Object is treated like a bullet",
"fullGroupName": "Physics behavior/Other",
"type": "PhysicsBehavior::IsBullet",
},
Object {
"displayedName": "The object is dynamic",
"fullGroupName": "Physics behavior/Movement",
"type": "PhysicsBehavior::IsDynamic",
},
Object {
"displayedName": "Fixed rotation",
"fullGroupName": "Physics behavior/Rotation",
"type": "PhysicsBehavior::IsFixedRotation",
},
Object {
"displayedName": "Linear damping",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearDamping",
},
Object {
"displayedName": "Linear speed",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocity",
},
Object {
"displayedName": "X component",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocityX",
},
Object {
"displayedName": "Y component",
"fullGroupName": "Physics behavior/Displacement",
"type": "PhysicsBehavior::LinearVelocityY",
},
]
`;

View File

@@ -46,6 +46,19 @@ export default class LocalCreateDialog extends Component {
}}
/>
<Subheader>Examples</Subheader>
<ListItem
primaryText="Physics"
secondaryText={
<p>
Example showing how to configure physics behavior on objects and use events to detect collisions.
</p>
}
secondaryTextLines={2}
onClick={() => {
sendNewGameCreated('physics');
this.props.onOpen('internal://physics');
}}
/>
<ListItem
primaryText="Pathfinding"
secondaryText={

View File

@@ -105,6 +105,12 @@ export default class LocalCreateDialog extends Component {
onClick={() => this.createEmptyGame()}
/>
<Subheader>Examples</Subheader>
<ListItem
primaryText="Physics"
secondaryText={<p>Example showing how to configure physics behavior on objects and use events to detect collisions.</p>}
secondaryTextLines={2}
onClick={() => this.createFromExample('physics')}
/>
<ListItem
primaryText="Pathfinding"
secondaryText={<p>Example showing how to move a tank avoiding obstacles on the battlefield.</p>}

View File

@@ -1,6 +1,7 @@
import platformer from '../fixtures/platformer/platformer.json';
import spaceShooter from '../fixtures/space-shooter/space-shooter.json';
import pathfinding from '../fixtures/pathfinding/pathfinding.json';
import physics from '../fixtures/physics/physics.json';
export default class BrowserProjectOpener {
static readInternalFile(url) {
@@ -10,6 +11,8 @@ export default class BrowserProjectOpener {
return Promise.resolve(spaceShooter);
} else if (url === 'internal://pathfinding') {
return Promise.resolve(pathfinding);
} else if (url === 'internal://physics') {
return Promise.resolve(physics);
}
return Promise.reject(`Unknown built-in game with URL ${url}`);

View File

@@ -35,6 +35,8 @@ export default class PropertiesEditor extends Component {
}
_renderEditField = field => {
if (field.name === 'PLEASE_ALSO_SHOW_EDIT_BUTTON_THANKS') return null; // This special property was used in GDevelop 4 IDE to ask for a Edit button to be shown, ignore it.
if (field.valueType === 'boolean') {
return (
<Checkbox

File diff suppressed because it is too large Load Diff