[Bf-blender-cvs] [8372168] master: BGE: Change character jumping to char

Thomas Szepe noreply at git.blender.org
Sun Oct 11 15:43:52 CEST 2015


Commit: 83721682bb12a5b3c277e832241e0752fdb2df2e
Author: Thomas Szepe
Date:   Sun Oct 11 15:41:40 2015 +0200
Branches: master
https://developer.blender.org/rB83721682bb12a5b3c277e832241e0752fdb2df2e

BGE: Change character jumping to char

* Change the character jumping variables and methods from int to char.
* Limit the maxJumps integer value from 0 to 255.
* Allow to set the minimum jump amount to 0.

Reviewers: panzergame, lordloki, moguri

Reviewed By: lordloki, moguri

Subscribers: agoose77

Projects: #game_engine

Differential Revision: https://developer.blender.org/D1305

===================================================================

M	doc/python_api/rst/bge_types/bge.types.KX_CharacterWrapper.rst
M	source/gameengine/Ketsji/KX_CharacterWrapper.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsController.h
M	source/gameengine/Physics/common/PHY_ICharacter.h

===================================================================

diff --git a/doc/python_api/rst/bge_types/bge.types.KX_CharacterWrapper.rst b/doc/python_api/rst/bge_types/bge.types.KX_CharacterWrapper.rst
index e326892..adff6e0 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_CharacterWrapper.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_CharacterWrapper.rst
@@ -25,7 +25,7 @@ base class --- :class:`PyObjectPlus`
 
       The maximum number of jumps a character can perform before having to touch the ground. By default this is set to 1. 2 allows for a double jump, etc.
 
-      :type: int
+      :type: int in [0, 255], default 1
 
    .. attribute:: jumpCount
 
diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp
index fdf4fa0..d777ae7 100644
--- a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp
@@ -25,6 +25,7 @@
 #include "KX_CharacterWrapper.h"
 #include "PHY_ICharacter.h"
 #include "KX_PyMath.h"
+#include "BLI_utildefines.h"
 
 KX_CharacterWrapper::KX_CharacterWrapper(PHY_ICharacter* character) :
 		PyObjectPlus(),
@@ -116,7 +117,9 @@ int KX_CharacterWrapper::pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE
 		return PY_SET_ATTR_FAIL;
 	}
 
-	self->m_character->SetMaxJumps((int)param);
+	CLAMP(param, 0, 255);
+
+	self->m_character->SetMaxJumps((unsigned char)param);
 	return PY_SET_ATTR_SUCCESS;
 }
 
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index ab7097b..6a1e52c 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -81,24 +81,24 @@ void BlenderBulletCharacterController::updateAction(btCollisionWorld *collisionW
 	m_motionState->setWorldTransform(getGhostObject()->getWorldTransform());
 }
 
-int BlenderBulletCharacterController::getMaxJumps() const
+unsigned char BlenderBulletCharacterController::getMaxJumps() const
 {
 	return m_maxJumps;
 }
 
-void BlenderBulletCharacterController::setMaxJumps(int maxJumps)
+void BlenderBulletCharacterController::setMaxJumps(unsigned char maxJumps)
 {
 	m_maxJumps = maxJumps;
 }
 
-int BlenderBulletCharacterController::getJumpCount() const
+unsigned char BlenderBulletCharacterController::getJumpCount() const
 {
 	return m_jumps;
 }
 
 bool BlenderBulletCharacterController::canJump() const
 {
-	return onGround() || m_jumps < m_maxJumps;
+	return (onGround() && m_maxJumps > 0) || m_jumps < m_maxJumps;
 }
 
 void BlenderBulletCharacterController::jump()
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index c49ae8d..2ae1ff8 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -407,19 +407,19 @@ class BlenderBulletCharacterController : public btKinematicCharacterController,
 {
 private:
 	btMotionState* m_motionState;
-	int m_jumps;
-	int m_maxJumps;
+	unsigned char m_jumps;
+	unsigned char m_maxJumps;
 
 public:
 	BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight);
 
 	virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt);
 
-	int getMaxJumps() const;
+	unsigned char getMaxJumps() const;
 
-	void setMaxJumps(int maxJumps);
+	void setMaxJumps(unsigned char maxJumps);
 
-	int getJumpCount() const;
+	unsigned char getJumpCount() const;
 
 	virtual bool canJump() const;
 
@@ -432,9 +432,9 @@ public:
 	virtual bool OnGround(){ return onGround(); }
 	virtual float GetGravity() { return getGravity(); }
 	virtual void SetGravity(float gravity) { setGravity(gravity); }
-	virtual int GetMaxJumps() { return getMaxJumps(); }
-	virtual void SetMaxJumps(int maxJumps) { setMaxJumps(maxJumps); }
-	virtual int GetJumpCount() { return getJumpCount(); }
+	virtual unsigned char GetMaxJumps() { return getMaxJumps(); }
+	virtual void SetMaxJumps(unsigned char maxJumps) { setMaxJumps(maxJumps); }
+	virtual unsigned char GetJumpCount() { return getJumpCount(); }
 	virtual void SetWalkDirection(const MT_Vector3& dir)
 	{
 		btVector3 vec = btVector3(dir[0], dir[1], dir[2]);
diff --git a/source/gameengine/Physics/common/PHY_ICharacter.h b/source/gameengine/Physics/common/PHY_ICharacter.h
index a3d3000..81c567e 100644
--- a/source/gameengine/Physics/common/PHY_ICharacter.h
+++ b/source/gameengine/Physics/common/PHY_ICharacter.h
@@ -23,10 +23,10 @@ public:
 	virtual float GetGravity()= 0;
 	virtual void SetGravity(float gravity)= 0;
 	
-	virtual int GetMaxJumps()= 0;
-	virtual void SetMaxJumps(int maxJumps)= 0;
+	virtual unsigned char GetMaxJumps() = 0;
+	virtual void SetMaxJumps(unsigned char maxJumps) = 0;
 
-	virtual int GetJumpCount()= 0;
+	virtual unsigned char GetJumpCount() = 0;
 
 	virtual void SetWalkDirection(const class MT_Vector3& dir)=0;
 	virtual MT_Vector3 GetWalkDirection()=0;




More information about the Bf-blender-cvs mailing list