[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15327] trunk/blender/source: BGE patch #14386: Action Actuator Current Frame Prop.

Benoit Bolsee benoit.bolsee at online.be
Mon Jun 23 17:32:48 CEST 2008


Revision: 15327
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15327
Author:   ben2610
Date:     2008-06-23 17:32:44 +0200 (Mon, 23 Jun 2008)

Log Message:
-----------
BGE patch #14386: Action Actuator Current Frame Prop.  This patch is very usefull for action feedback logic: a sensor on the property can be used to detect a certain moment in the action and trigger more stuff. The property must be on float type for best results

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_actuator_types.h
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp

Modified: trunk/blender/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2008-06-23 14:12:22 UTC (rev 15326)
+++ trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2008-06-23 15:32:44 UTC (rev 15327)
@@ -50,6 +50,7 @@
 	short	type, flag;		/* Playback type */					
 	int	sta, end;		/* Start & End frames */			
 	char	name[32];		/* For property-driven playback */	
+	char	frameProp[32];	/* Set this property to the actions current frame */
 	int	blendin;		/* Number of frames of blending */	
 	short	priority;		/* Execution priority */			
 	short	strideaxis;		/* Displacement axis */

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c	2008-06-23 14:12:22 UTC (rev 15326)
+++ trunk/blender/source/blender/src/buttons_logic.c	2008-06-23 15:32:44 UTC (rev 15327)
@@ -1673,31 +1673,34 @@
 #else
 			str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
 #endif
-			uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, width-60, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
-			uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30, yco-44, width-60, 19, &aa->act, "Action name");
+			uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, (width-60)/2, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
+			uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30 + ((width-60)/2), yco-24, (width-60)/2, 19, &aa->act, "Action name");
 			
 			if(aa->type == ACT_ACTION_FROM_PROP)
 			{
-				uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-64, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
+				uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-44, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
 			}
 			else
 			{
-				uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-64, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
-				uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
+				uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-44, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
+				uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-44, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
 			}
+						
+			uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-64, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
+			uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers");
 			
+			uiDefBut(block, TEX, 0, "FrameProp: ",xco+30, yco-84, width-60, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");			
+
 			
-			
-			uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-84, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
-			uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-84, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers");
-			
 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
 			if(aa->type == ACT_ACTION_MOTION)
 			{
-				uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-104, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
+				uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-84, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
 			}
 #endif
 			
+			
+			
 			yco-=ysize;
 			break;
 		}

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2008-06-23 14:12:22 UTC (rev 15326)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2008-06-23 15:32:44 UTC (rev 15327)
@@ -49,6 +49,7 @@
 #include "BLI_arithb.h"
 #include "MT_Matrix4x4.h"
 #include "BKE_utildefines.h"
+#include "FloatValue.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -348,6 +349,18 @@
 		break;
 	}
 	
+	/* Set the property if its defined */
+	if (m_framepropname) {
+		CValue* propowner = GetParent();
+		CValue* oldprop = propowner->GetProperty(m_framepropname);
+		CValue* newval = new CFloatValue(m_localtime);
+		if (oldprop) {
+			oldprop->SetValue(newval);
+		} else {
+			propowner->SetProperty(m_framepropname, newval);
+		}
+		newval->Release();
+	}
 	
 	if (bNegativeEvent)
 		m_blendframe=0.0;
@@ -446,6 +459,7 @@
 	{"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, SetPriority_doc},
 	{"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, SetFrame_doc},
 	{"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, SetProperty_doc},
+	{"setFrameProperty", (PyCFunction) BL_ActionActuator::sPySetFrameProperty, METH_VARARGS, SetFrameProperty_doc},
 	{"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, SetBlendtime_doc},
 
 	{"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, GetAction_doc},
@@ -455,6 +469,7 @@
 	{"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, GetPriority_doc},
 	{"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, GetFrame_doc},
 	{"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
+	{"getFrameProperty", (PyCFunction) BL_ActionActuator::sPyGetFrameProperty, METH_VARARGS, GetFrameProperty_doc},
 	{"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
 //	{"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
 	{"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},	
@@ -502,6 +517,21 @@
 	return result;
 }
 
+/*     getProperty                                                             */
+char BL_ActionActuator::GetFrameProperty_doc[] = 
+"getFrameProperty()\n"
+"\tReturns the name of the property, that is set to the current frame number.\n";
+
+PyObject* BL_ActionActuator::PyGetFrameProperty(PyObject* self, 
+										   PyObject* args, 
+										   PyObject* kwds) {
+	PyObject *result;
+	
+	result = Py_BuildValue("s", (const char *)m_framepropname);
+	
+	return result;
+}
+
 /*     getFrame                                                              */
 char BL_ActionActuator::GetFrame_doc[] = 
 "getFrame()\n"
@@ -763,6 +793,25 @@
 	return Py_None;
 }
 
+/*     setFrameProperty                                                          */
+char BL_ActionActuator::SetFrameProperty_doc[] = 
+"setFrameProperty(prop)\n"
+"\t - prop      : A string specifying the property of the frame set up update.\n";
+
+PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* self, 
+										   PyObject* args, 
+										   PyObject* kwds) {
+	char *string;
+	
+	if (PyArg_ParseTuple(args,"s",&string))
+	{
+		m_framepropname = string;
+	}
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 /*
 PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, 
 										   PyObject* args, 

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2008-06-23 14:12:22 UTC (rev 15326)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.h	2008-06-23 15:32:44 UTC (rev 15327)
@@ -40,6 +40,7 @@
 	Py_Header;
 	BL_ActionActuator(SCA_IObject* gameobj,
 						const STR_String& propname,
+						const STR_String& framepropname,
 						float starttime,
 						float endtime,
 						struct bAction *action,
@@ -67,7 +68,8 @@
 		m_blendpose(NULL),
 		m_userpose(NULL),
 		m_action(action),
-		m_propname(propname)
+		m_propname(propname),
+		m_framepropname(framepropname)		
 	{
 	};
 	virtual ~BL_ActionActuator();
@@ -84,6 +86,7 @@
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetEnd);
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetFrame);
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetProperty);
+	KX_PYMETHOD_DOC(BL_ActionActuator,SetFrameProperty);
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendtime);
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetChannel);
 
@@ -94,6 +97,7 @@
 	KX_PYMETHOD_DOC(BL_ActionActuator,GetEnd);
 	KX_PYMETHOD_DOC(BL_ActionActuator,GetFrame);
 	KX_PYMETHOD_DOC(BL_ActionActuator,GetProperty);
+	KX_PYMETHOD_DOC(BL_ActionActuator,GetFrameProperty);
 //	KX_PYMETHOD(BL_ActionActuator,GetChannel);
 	KX_PYMETHOD_DOC(BL_ActionActuator,GetType);
 	KX_PYMETHOD_DOC(BL_ActionActuator,SetType);
@@ -138,6 +142,7 @@
 	struct bPose* m_userpose;
 	struct bAction *m_action;
 	STR_String	m_propname;
+	STR_String	m_framepropname;
 };
 
 enum {

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-06-23 14:12:22 UTC (rev 15326)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-06-23 15:32:44 UTC (rev 15327)
@@ -178,10 +178,12 @@
 				if (blenderobject->type==OB_ARMATURE){
 					bActionActuator* actact = (bActionActuator*) bact->data;
 					STR_String propname = (actact->name ? actact->name : "");
+					STR_String propframe = (actact->frameProp ? actact->frameProp : "");
 					
 					BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
 						gameobj,
 						propname,
+						propframe,
 						actact->sta,
 						actact->end,
 						actact->act,





More information about the Bf-blender-cvs mailing list