[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19802] trunk/blender/source/gameengine: BGE Python API

Campbell Barton ideasman42 at gmail.com
Sun Apr 19 23:01:14 CEST 2009


Revision: 19802
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19802
Author:   campbellbarton
Date:     2009-04-19 23:01:12 +0200 (Sun, 19 Apr 2009)

Log Message:
-----------
BGE Python API
- More verbose error messages.
- BL_Shader wasnt setting error messages on some errors
- FilterNormal depth attribute was checking for float which is bad because scripts often expect ints assigned to float attributes.
- Added a check to PyVecTo for a tuple rather then always using a generic python sequence. On my system this is over 2x faster with an optmized build.

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/Expressions/ListValue.cpp
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    trunk/blender/source/gameengine/Expressions/Value.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_MouseSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp
    trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp
    trunk/blender/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PolyProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PyMath.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_VertexProxy.cpp
    trunk/blender/source/gameengine/VideoTexture/FilterNormal.cpp
    trunk/blender/source/gameengine/VideoTexture/blendVideoTex.cpp

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-19 21:01:12 UTC (rev 19802)
@@ -1037,7 +1037,7 @@
 	
 	if (!PyString_Check(value))
 	{
-		PyErr_SetString(PyExc_ValueError, "expected the string name of the action");
+		PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
 		return -1;
 	}
 
@@ -1049,7 +1049,7 @@
 		action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
 		if (!action)
 		{
-			PyErr_SetString(PyExc_ValueError, "action not found!");
+			PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
 			return 1;
 		}
 	}

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2009-04-19 21:01:12 UTC (rev 19802)
@@ -154,7 +154,7 @@
 			case ACT_ACTION_FROM_PROP:
 				return 0;
 			default:
-				PyErr_SetString(PyExc_ValueError, "invalid type supplied");
+				PyErr_SetString(PyExc_ValueError, "Action Actuator, invalid play type supplied");
 				return 1;
 		}
 	}

Modified: trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-19 21:01:12 UTC (rev 19802)
@@ -869,7 +869,7 @@
 	/* 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");
+		PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action");
 		return -1;
 	}
 
@@ -881,7 +881,7 @@
 		action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
 		if (action==NULL)
 		{
-			PyErr_SetString(PyExc_ValueError, "action not found!");
+			PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!");
 			return 1;
 		}
 	}

Modified: trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.h	2009-04-19 21:01:12 UTC (rev 19802)
@@ -144,7 +144,7 @@
 			case ACT_ACTION_FROM_PROP:
 				return 0;
 			default:
-				PyErr_SetString(PyExc_ValueError, "invalid type supplied");
+				PyErr_SetString(PyExc_ValueError, "Shape Action Actuator, invalid play type supplied");
 				return 1;
 		}
 

Modified: trunk/blender/source/gameengine/Expressions/ListValue.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/ListValue.cpp	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Expressions/ListValue.cpp	2009-04-19 21:01:12 UTC (rev 19802)
@@ -58,7 +58,7 @@
 			return list->GetValue(index)->GetProxy();
 
 	}
-	PyErr_SetString(PyExc_IndexError, "Python ListIndex out of range");
+	PyErr_SetString(PyExc_IndexError, "list[i]: Python ListIndex out of range in CValueList");
 	return NULL;
 }
 
@@ -85,7 +85,7 @@
 	}
 	
 	PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */
-	PyErr_Format(PyExc_KeyError, "'%s' not in list", PyString_AsString(pyindex_str));
+	PyErr_Format(PyExc_KeyError, "list[key]: '%s' key not in list", PyString_AsString(pyindex_str));
 	Py_DECREF(pyindex_str);
 	return NULL;
 }
@@ -162,7 +162,7 @@
 		}
 
 		if (error) {
-			PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add one or more items to a list");
+			PyErr_SetString(PyExc_SystemError, "list.append(val): couldn't add one or more items to this CValueList");
 			return NULL;
 		}
 
@@ -187,7 +187,7 @@
 				listval->Add(objval);
 			} else
 			{
-				PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add item to a list");  
+				PyErr_SetString(PyExc_SystemError, "list.append(i): couldn't add item to this CValueList");
 				return NULL;
 			}
 		}
@@ -495,7 +495,7 @@
 	checkobj->Release();
 
 	if (result==NULL) {
-		PyErr_SetString(PyExc_ValueError, "ValueError: list.index(x): x not in CListValue");
+		PyErr_SetString(PyExc_ValueError, "list.index(x): x not in CListValue");
 	}
 	return result;
 	
@@ -543,7 +543,7 @@
 		if (reinterpret_cast<uintptr_t>(m_pValueArray[i]->m_proxy) == id)
 			return GetValue(i)->GetProxy();
 	}
-	PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList");
+	PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList");
 	return NULL;	
 
 }

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-04-19 20:09:31 UTC (rev 19801)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-04-19 21:01:12 UTC (rev 19802)
@@ -325,12 +325,12 @@
 	{
 		if (!PySequence_Check(value)) 
 		{
-			PyErr_SetString(PyExc_TypeError, "expected a sequence");
+			PyErr_Format(PyExc_TypeError, "expected a sequence for attribute \"%s\"", attrdef->m_name);
 			return 1;
 		}
 		if (PySequence_Size(value) != attrdef->m_length)
 		{
-			PyErr_SetString(PyExc_TypeError, "incorrect number of elements in sequence");
+			PyErr_Format(PyExc_TypeError, "incorrect number of elements in sequence for attribute \"%s\"", attrdef->m_name);
 			return 1;
 		}
 		switch (attrdef->m_type) 
@@ -338,7 +338,7 @@
 		case KX_PYATTRIBUTE_TYPE_FUNCTION:
 			if (attrdef->m_setFunction == NULL) 
 			{
-				PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
+				PyErr_Format(PyExc_AttributeError, "function attribute without function for attribute \"%s\", report to blender.org", attrdef->m_name);
 				return 1;
 			}
 			return (*attrdef->m_setFunction)(self, attrdef, value);
@@ -357,7 +357,7 @@
 			break;
 		default:
 			// should not happen
-			PyErr_SetString(PyExc_AttributeError, "Unsupported attribute type, report to blender.org");
+			PyErr_Format(PyExc_AttributeError, "Unsupported attribute type for attribute \"%s\", report to blender.org", attrdef->m_name);
 			return 1;
 		}
 		// let's implement a smart undo method
@@ -390,7 +390,7 @@
 					}
 					else
 					{
-						PyErr_SetString(PyExc_TypeError, "expected an integer or a bool");
+						PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name);
 						goto UNDO_AND_ERROR;
 					}
 					break;
@@ -411,14 +411,14 @@
 						}
 						else if (val < attrdef->m_imin || val > attrdef->m_imax)
 						{
-							PyErr_SetString(PyExc_ValueError, "item value out of range");
+							PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
 							goto UNDO_AND_ERROR;
 						}
 						*var = (short int)val;
 					}
 					else
 					{
-						PyErr_SetString(PyExc_TypeError, "expected an integer");
+						PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
 						goto UNDO_AND_ERROR;
 					}
 					break;
@@ -427,7 +427,7 @@
 				// enum are equivalent to int, just make sure that the field size matches:
 				if (sizeof(int) != attrdef->m_size)
 				{
-					PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org");
+					PyErr_Format(PyExc_AttributeError, "Size check error for attribute, \"%s\", report to blender.org", attrdef->m_name);
 					goto UNDO_AND_ERROR;
 				}
 				// walkthrough
@@ -447,14 +447,14 @@
 						}
 						else if (val < attrdef->m_imin || val > attrdef->m_imax)
 						{
-							PyErr_SetString(PyExc_ValueError, "item value out of range");
+							PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
 							goto UNDO_AND_ERROR;
 						}
 						*var = (int)val;
 					}
 					else
 					{
-						PyErr_SetString(PyExc_TypeError, "expected an integer");
+						PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
 						goto UNDO_AND_ERROR;
 					}
 					break;
@@ -466,7 +466,7 @@
 					double val = PyFloat_AsDouble(item);
 					if (val == -1.0 && PyErr_Occurred())
 					{
-						PyErr_SetString(PyExc_TypeError, "expected a float");
+						PyErr_Format(PyExc_TypeError, "expected a float for attribute \"%s\"", attrdef->m_name);
 						goto UNDO_AND_ERROR;
 					}
 					else if (attrdef->m_clamp) 
@@ -478,7 +478,7 @@
 					}
 					else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
 					{
-						PyErr_SetString(PyExc_ValueError, "item value out of range");
+						PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
 						goto UNDO_AND_ERROR;
 					}
 					*var = (float)val;
@@ -486,7 +486,7 @@
 				}
 			default:
 				// should not happen
-				PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org");
+				PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", report to blender.org", attrdef->m_name);
 				goto UNDO_AND_ERROR;
 			}
 		}
@@ -515,7 +515,7 @@
 		{
 			if (attrdef->m_setFunction == NULL)
 			{
-				PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
+				PyErr_Format(PyExc_AttributeError, "function attribute without function \"%s\", report to blender.org", attrdef->m_name);
 				return 1;
 			}
 			return (*attrdef->m_setFunction)(self, attrdef, value);
@@ -545,7 +545,7 @@
 					bufferSize = strlen(reinterpret_cast<char*>(sourceBuffer))+1;
 				break;
 			default:
-				PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org");
+				PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name);
 				return 1;
 			}
 			if (bufferSize)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list