[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20052] trunk/blender/source/gameengine: print BGE Py api warnings only once to avoid flooding the terminal and slowing the game down too much , resets on loading scenes/blendfiles and restarting the game engine.

Campbell Barton ideasman42 at gmail.com
Mon May 4 10:55:54 CEST 2009


Revision: 20052
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20052
Author:   campbellbarton
Date:     2009-05-04 10:55:54 +0200 (Mon, 04 May 2009)

Log Message:
-----------
print BGE Py api warnings only once to avoid flooding the terminal and slowing the game down too much, resets on loading scenes/blendfiles and restarting the game engine.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-05-04 08:17:18 UTC (rev 20051)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-05-04 08:55:54 UTC (rev 20052)
@@ -908,15 +908,16 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////
 /* deprecation warning management */
+
 bool PyObjectPlus::m_ignore_deprecation_warnings(false);
 void PyObjectPlus::SetDeprecationWarnings(bool ignoreDeprecationWarnings)
 {
 	m_ignore_deprecation_warnings = ignoreDeprecationWarnings;
 }
 
-void PyObjectPlus::ShowDeprecationWarning(const char* old_way,const char* new_way)
+void PyObjectPlus::ShowDeprecationWarning_func(const char* old_way,const char* new_way)
 {
-	if (!m_ignore_deprecation_warnings) {
+	{
 		printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way);
 		
 		// import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno)
@@ -955,6 +956,30 @@
 	}
 }
 
+void PyObjectPlus::ClearDeprecationWarning()
+{
+	WarnLink *wlink_next;
+	WarnLink *wlink = GetDeprecationWarningLinkFirst();
+	
+	while(wlink)
+	{
+		wlink->warn_done= false; /* no need to NULL the link, its cleared before adding to the list next time round */
+		wlink_next= reinterpret_cast<WarnLink *>(wlink->link);
+		wlink->link= NULL;
+		wlink= wlink_next;
+	}
+	NullDeprecationWarning();
+}
 
+WarnLink*		m_base_wlink_first= NULL;
+WarnLink*		m_base_wlink_last= NULL;
+
+WarnLink*		PyObjectPlus::GetDeprecationWarningLinkFirst(void) {return m_base_wlink_first;}
+WarnLink*		PyObjectPlus::GetDeprecationWarningLinkLast(void) {return m_base_wlink_last;}
+void			PyObjectPlus::SetDeprecationWarningFirst(WarnLink* wlink) {m_base_wlink_first= wlink;}
+void			PyObjectPlus::SetDeprecationWarningLinkLast(WarnLink* wlink) {m_base_wlink_last= wlink;}
+void			PyObjectPlus::NullDeprecationWarning() {m_base_wlink_first= m_base_wlink_last= NULL;}
+
+
 #endif //NO_EXP_PYTHON_EMBEDDING
 

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-05-04 08:17:18 UTC (rev 20051)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-05-04 08:55:54 UTC (rev 20052)
@@ -81,7 +81,37 @@
 	exit(-1);
 };
 
+
+/* Use with ShowDeprecationWarning macro */
 typedef struct {
+	bool warn_done;
+	void *link;
+} WarnLink;
+
+#define ShowDeprecationWarning(old_way, new_way) \
+{ \
+	static WarnLink wlink = {false, NULL}; \
+	if ((m_ignore_deprecation_warnings || wlink.warn_done)==0) \
+	{ \
+		ShowDeprecationWarning_func(old_way, new_way); \
+		WarnLink *wlink_last= GetDeprecationWarningLinkLast(); \
+		ShowDeprecationWarning_func(old_way, new_way); \
+		wlink.warn_done = true; \
+		wlink.link = NULL; \
+	 \
+		if(wlink_last) { \
+			wlink_last->link= (void *)&(wlink); \
+			SetDeprecationWarningLinkLast(&(wlink)); \
+		} else { \
+			SetDeprecationWarningFirst(&(wlink)); \
+			SetDeprecationWarningLinkLast(&(wlink)); \
+		} \
+	} \
+} \
+
+
+
+typedef struct {
 	PyObject_HEAD		/* required python macro   */
 	class PyObjectPlus *ref;
 	bool py_owns;
@@ -461,13 +491,21 @@
 	
 	static bool			m_ignore_deprecation_warnings;
 	
+	static	WarnLink*		GetDeprecationWarningLinkFirst(void);
+	static	WarnLink*		GetDeprecationWarningLinkLast(void);
+	static	void			SetDeprecationWarningFirst(WarnLink* wlink);
+	static	void			SetDeprecationWarningLinkLast(WarnLink* wlink);
+	static void			NullDeprecationWarning();
+	
 	/** enable/disable display of deprecation warnings */
 	static void			SetDeprecationWarnings(bool ignoreDeprecationWarnings);
  	/** Shows a deprecation warning */
-	static void			ShowDeprecationWarning(const char* method,const char* prop);
+	static void			ShowDeprecationWarning_func(const char* method,const char* prop);
+	static void			ClearDeprecationWarning();
 	
 };
 
+
 PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict);
 
 #endif //  _adr_py_lib_h_

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2009-05-04 08:17:18 UTC (rev 20051)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2009-05-04 08:55:54 UTC (rev 20052)
@@ -1123,9 +1123,9 @@
 	gp_KetsjiScene = scene;
 
 	gUseVisibilityTemp=false;
-
-
 	
+	PyObjectPlus::ClearDeprecationWarning(); /* Not that nice to call here but makes sure warnings are reset between loading scenes */
+	
 	/* Use existing module where possible
 	 * be careful not to init any runtime vars after this */
 	m = PyImport_ImportModule( "GameLogic" );
@@ -1697,6 +1697,8 @@
 	
 	first_time = false;
 	
+	PyObjectPlus::ClearDeprecationWarning();
+	
 	PyObject* moduleobj = PyImport_AddModule("__main__");
 	return PyModule_GetDict(moduleobj);
 }
@@ -1710,6 +1712,7 @@
 	
 	Py_Finalize();
 	bpy_import_main_set(NULL);
+	PyObjectPlus::ClearDeprecationWarning();
 }
 
 
@@ -1736,6 +1739,8 @@
 	/* clear user defined modules that may contain data from the last run */
 	clearGameModules();
 
+	PyObjectPlus::NullDeprecationWarning();
+	
 	PyObject* moduleobj = PyImport_AddModule("__main__");
 	return PyModule_GetDict(moduleobj);
 }
@@ -1781,6 +1786,7 @@
 	clearGameModules();
 	restorePySysPath(); /* get back the original sys.path and clear the backup */
 	bpy_import_main_set(NULL);
+	PyObjectPlus::ClearDeprecationWarning();
 }
 
 





More information about the Bf-blender-cvs mailing list