[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19530] trunk/blender/source/gameengine: moved more attributes from getattr into PyAttributeDef's

Campbell Barton ideasman42 at gmail.com
Sat Apr 4 04:57:36 CEST 2009


Revision: 19530
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19530
Author:   campbellbarton
Date:     2009-04-04 04:57:35 +0200 (Sat, 04 Apr 2009)

Log Message:
-----------
moved more attributes from getattr into PyAttributeDef's

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
    trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp
    trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h
    trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.h
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.h
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.h
    trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.h
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-04 02:05:57 UTC (rev 19529)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-04 02:57:35 UTC (rev 19530)
@@ -1025,6 +1025,7 @@
 	KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
 	KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
 	KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
+	KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
 	KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
 	KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame),
 	KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ActionActuator, m_propname),
@@ -1036,10 +1037,6 @@
 };
 
 PyObject* BL_ActionActuator::py_getattro(PyObject *attr) {
-	char *attr_str= PyString_AsString(attr);
-	if (!strcmp(attr_str, "action"))
-		return PyString_FromString(m_action->id.name+2);
-
 	PyObject* object = py_getattro_self(Attributes, this, attr);
 	if (object != NULL)
 		return object;
@@ -1047,39 +1044,44 @@
 }
 
 int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) {
-	char *attr_str= PyString_AsString(attr);
-	if (!strcmp(attr_str, "action"))
-	{
-		if (!PyString_Check(value))
-		{
-			PyErr_SetString(PyExc_ValueError, "expected a string");
-			return 1;
-		}
+	int ret = py_setattro_self(Attributes, this, attr, value);
+	if (ret >= 0)
+		return ret;
+	return SCA_IActuator::py_setattro(attr, value);
+}
 
-		STR_String val = PyString_AsString(value);
-		
-		if (val == "")
-		{
-			m_action = NULL;
-			return 0;
-		}
 
-		bAction *action;
-		
-		action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
-		
 
+PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
+	return PyString_FromString(self->GetAction()->id.name+2);
+}
+
+int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
+	
+	if (!PyString_Check(value))
+	{
+		PyErr_SetString(PyExc_ValueError, "expected the string name of the action");
+		return -1;
+	}
+
+	bAction *action= NULL;
+	STR_String val = PyString_AsString(value);
+	
+	if (val != "")
+	{
+		(bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
 		if (!action)
 		{
 			PyErr_SetString(PyExc_ValueError, "action not found!");
 			return 1;
 		}
+	}
+	
+	self->SetAction(action);
+	return 0;
 
-		m_action = action;
-		return 0;
-	}
-	int ret = py_setattro_self(Attributes, this, attr, value);
-	if (ret >= 0)
-		return ret;
-	return SCA_IActuator::py_setattro(attr, value);
-}
\ No newline at end of file
+}

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2009-04-04 02:05:57 UTC (rev 19529)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2009-04-04 02:57:35 UTC (rev 19530)
@@ -81,6 +81,9 @@
 	virtual void ProcessReplica();
 	
 	void SetBlendTime (float newtime);
+	
+	bAction*	GetAction() { return m_action; }
+	void		SetAction(bAction* act) { m_action= act; }
 
 	//Deprecated ----->
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetAction);
@@ -113,6 +116,9 @@
 	virtual PyObject* py_getattro(PyObject* attr);
 	virtual int py_setattro(PyObject* attr, PyObject* value);
 
+	static PyObject*	pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static int			pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
 	/* attribute check */
 	static int CheckFrame(void *self, const PyAttributeDef*)
 	{
@@ -151,8 +157,8 @@
 				PyErr_SetString(PyExc_ValueError, "invalid type supplied");
 				return 1;
 		}
-
 	}
+	
 protected:
 
 	void SetStartTime(float curtime);

Modified: trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-04 02:05:57 UTC (rev 19529)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-04 02:57:35 UTC (rev 19530)
@@ -474,6 +474,7 @@
 	KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe),
 	KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe),
 	KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin),
+	KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action),
 	KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
 	KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
 	KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ShapeActionActuator, m_propname),
@@ -485,9 +486,6 @@
 
 
 PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) {
-	char *attr_str= PyString_AsString(attr);
-	if (!strcmp(attr_str, "action"))
-		return PyString_FromString(m_action->id.name+2);
 	PyObject* object = py_getattro_self(Attributes, this, attr);
 	if (object != NULL)
 		return object;
@@ -495,37 +493,6 @@
 }
 
 int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) {
-	char *attr_str= PyString_AsString(attr);
-	if (!strcmp(attr_str, "action"))
-	{
-		if (!PyString_Check(value))
-		{
-			PyErr_SetString(PyExc_ValueError, "expected a string");
-			return 1;
-		}
-
-		STR_String val = PyString_AsString(value);
-		
-		if (val == "")
-		{
-			m_action = NULL;
-			return 0;
-		}
-
-		bAction *action;
-		
-		action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
-		
-
-		if (!action)
-		{
-			PyErr_SetString(PyExc_ValueError, "action not found!");
-			return 1;
-		}
-
-		m_action = action;
-		return 0;
-	}
 	int ret = py_setattro_self(Attributes, this, attr, value);
 	if (ret >= 0)
 		return ret;
@@ -916,3 +883,36 @@
     Py_RETURN_NONE;
 }
 
+PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v);
+	return PyString_FromString(self->GetAction()->id.name+2);
+}
+
+int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v);
+	/* exact copy of BL_ActionActuator's function from here down */
+	if (!PyString_Check(value))
+	{
+		PyErr_SetString(PyExc_ValueError, "expected the string name of the action");
+		return -1;
+	}
+
+	bAction *action= NULL;
+	STR_String val = PyString_AsString(value);
+	
+	if (val != "")
+	{
+		(bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
+		if (action==NULL)
+		{
+			PyErr_SetString(PyExc_ValueError, "action not found!");
+			return 1;
+		}
+	}
+	
+	self->SetAction(action);
+	return 0;
+
+}

Modified: trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h	2009-04-04 02:05:57 UTC (rev 19529)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h	2009-04-04 02:57:35 UTC (rev 19530)
@@ -79,6 +79,9 @@
 	
 	void SetBlendTime (float newtime);
 	void BlendShape(struct Key* key, float weigth);
+	
+	bAction*	GetAction() { return m_action; }
+	void		SetAction(bAction* act) { m_action= act; }
 
 	KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetAction);
 	KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendin);
@@ -106,6 +109,9 @@
 	virtual PyObject* py_getattro(PyObject* attr);
 	virtual int py_setattro(PyObject* attr, PyObject* value);
 
+	static PyObject*	pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+	static int			pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
 	static int CheckBlendTime(void *self, const PyAttributeDef*)
 	{
 		BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);

Modified: trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp	2009-04-04 02:05:57 UTC (rev 19529)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp	2009-04-04 02:57:35 UTC (rev 19530)
@@ -454,9 +454,8 @@
 	KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency),
 	KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert),
 	KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level),
-	// make these properties read-only in _setaddr, must still implement them in py_getattro
-	KX_PYATTRIBUTE_DUMMY("triggered"),
-	KX_PYATTRIBUTE_DUMMY("positive"),
+	KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered),
+	KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive),
 	{ NULL }	//Sentinel
 };
 
@@ -466,20 +465,6 @@
 	PyObject* object = py_getattro_self(Attributes, this, attr);
 	if (object != NULL)
 		return object;
-	
-	char *attr_str= PyString_AsString(attr);
-	if (!strcmp(attr_str, "triggered"))
-	{
-		int retval = 0;
-		if (SCA_PythonController::m_sCurrentController)
-			retval = SCA_PythonController::m_sCurrentController->IsTriggered(this);
-		return PyInt_FromLong(retval);
-	}
-	if (!strcmp(attr_str, "positive"))
-	{	
-		int retval = IsPositiveTrigger();
-		return PyInt_FromLong(retval);
-	}
 	py_getattro_up(SCA_ILogicBrick);
 }
 
@@ -490,4 +475,20 @@
 		return ret;
 	return SCA_ILogicBrick::py_setattro(attr, value);
 }
+
+PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v);
+	int retval = 0;
+	if (SCA_PythonController::m_sCurrentController)
+		retval = SCA_PythonController::m_sCurrentController->IsTriggered(self);
+	return PyInt_FromLong(retval);
+}
+
+PyObject* SCA_ISensor::pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list