From 18f134304c0c6181668a0a8c22289fcaeb472432 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Sat, 29 Dec 2012 10:22:19 +0000 Subject: [PATCH] BGE: Adding a jumpCount to KX_CharacterWrapper. This can be used to have different logic for a single jump versus a double jump. For example, a different animation for the second jump. --- doc/python_api/rst/bge.types.rst | 6 ++++++ source/gameengine/Ketsji/KX_CharacterWrapper.cpp | 9 +++++++++ source/gameengine/Ketsji/KX_CharacterWrapper.h | 1 + .../gameengine/Physics/Bullet/CcdPhysicsController.cpp | 5 +++++ source/gameengine/Physics/Bullet/CcdPhysicsController.h | 2 ++ .../gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 5 +++++ source/gameengine/Physics/common/PHY_ICharacter.h | 2 ++ 7 files changed, 30 insertions(+) diff --git a/doc/python_api/rst/bge.types.rst b/doc/python_api/rst/bge.types.rst index ae03debb4f8..a86272ddf5c 100644 --- a/doc/python_api/rst/bge.types.rst +++ b/doc/python_api/rst/bge.types.rst @@ -3755,6 +3755,12 @@ Types :type: int + .. attribute:: jumpCount + + The current jump count. This can be used to have different logic for a single jump versus a double jump. For example, a different animation for the second jump. + + :type: int + .. method:: jump() The character jumps based on it's jump speed. diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp index dfd19a0d2bd..64bbbb7d344 100644 --- a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp +++ b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp @@ -46,6 +46,7 @@ PyAttributeDef KX_CharacterWrapper::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("onGround", KX_CharacterWrapper, pyattr_get_onground), KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_CharacterWrapper, pyattr_get_gravity, pyattr_set_gravity), KX_PYATTRIBUTE_RW_FUNCTION("maxJumps", KX_CharacterWrapper, pyattr_get_max_jumps, pyattr_set_max_jumps), + KX_PYATTRIBUTE_RO_FUNCTION("jumpCount", KX_CharacterWrapper, pyattr_get_jump_count), { NULL } //Sentinel }; @@ -99,6 +100,14 @@ int KX_CharacterWrapper::pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE self->m_character->SetMaxJumps((int)param); return PY_SET_ATTR_SUCCESS; } + +PyObject *KX_CharacterWrapper::pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_CharacterWrapper* self = static_cast(self_v); + + return PyLong_FromLong(self->m_character->GetJumpCount()); +} + PyMethodDef KX_CharacterWrapper::Methods[] = { KX_PYMETHODTABLE_NOARGS(KX_CharacterWrapper, jump), {NULL,NULL} //Sentinel diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.h b/source/gameengine/Ketsji/KX_CharacterWrapper.h index 1161be2c611..f1c977f4e5d 100644 --- a/source/gameengine/Ketsji/KX_CharacterWrapper.h +++ b/source/gameengine/Ketsji/KX_CharacterWrapper.h @@ -28,6 +28,7 @@ public: static int pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); #endif // WITH_PYTHON private: diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 66c6d1aa251..cf96f22a345 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -92,6 +92,11 @@ void BlenderBulletCharacterController::setMaxJumps(int maxJumps) m_maxJumps = maxJumps; } +int BlenderBulletCharacterController::getJumpCount() const +{ + return m_jumps; +} + bool BlenderBulletCharacterController::canJump() const { return onGround() || m_jumps < m_maxJumps; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 91b2e558521..b151c2f6b59 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -412,6 +412,8 @@ public: void setMaxJumps(int maxJumps); + int getJumpCount() const; + virtual bool canJump() const; virtual void jump(); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index f1224babcf7..cadba97023e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -305,6 +305,11 @@ public: { m_controller->setMaxJumps(maxJumps); } + + virtual int GetJumpCount() + { + return m_controller->getJumpCount(); + } }; class CcdOverlapFilterCallBack : public btOverlapFilterCallback diff --git a/source/gameengine/Physics/common/PHY_ICharacter.h b/source/gameengine/Physics/common/PHY_ICharacter.h index 92c00949c4d..63f6c0bd18a 100644 --- a/source/gameengine/Physics/common/PHY_ICharacter.h +++ b/source/gameengine/Physics/common/PHY_ICharacter.h @@ -25,6 +25,8 @@ public: virtual int GetMaxJumps()= 0; virtual void SetMaxJumps(int maxJumps)= 0; + virtual int GetJumpCount()= 0; + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter") #endif