[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16685] trunk/blender/source/gameengine/ Ketsji/KX_PythonInit.cpp: BGE patch: KX_STATEx constant to allow simple state manipulation in setState()

Benoit Bolsee benoit.bolsee at online.be
Mon Sep 22 21:54:30 CEST 2008


Revision: 16685
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16685
Author:   ben2610
Date:     2008-09-22 21:54:30 +0200 (Mon, 22 Sep 2008)

Log Message:
-----------
BGE patch: KX_STATEx constant to allow simple state manipulation in setState()

The constants KX_STATE1 to KX_STATE30 can be used 
with setState() to change the object state in a 
python controller. The constants are defined in the 
GameLogic module so that the full name is 
GameLogic.KX_STATE1 to GameLogic.KX_STATE30 but you
can simplify this with the import statement:

from GameLogic import *
cont = getCurrentController()
ob = cont.getOwner()
ob.setState(KX_STATE2)		#go to state 2

KX_STATEx constants are defined as (1<<(x-1))
Binary operators |, &, ^ and ~ can be used to combine states:

You can activate more than one state at a time with the | operator:

ob.setState(KX_STATE1|KX_STATE2)  #activate state 1 and 2, stop all others

You can add a state to the current state mask with:

state = ob.getState()
ob.setState(state|KX_STATE3)      #activate state 3, keep others

You can substract a state to the current state mask with the & and operator:

state = ob.getState()
ob.setState(state&~KX_STATE2)     #stop state 2, keep others

You can invert a state with the ^ operator:

state = ob.getState()
ob.setState(state^KX_STATE2)     #invert state 2, keep others

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

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2008-09-22 19:37:30 UTC (rev 16684)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2008-09-22 19:54:30 UTC (rev 16685)
@@ -975,6 +975,38 @@
 	KX_MACRO_addTypesToDict(d, CAM_POS, BL_Shader::CAM_POS);
 	KX_MACRO_addTypesToDict(d, CONSTANT_TIMER, BL_Shader::CONSTANT_TIMER);
 
+	/* 10 state actuator */
+	KX_MACRO_addTypesToDict(d, KX_STATE1, (1<<0));
+	KX_MACRO_addTypesToDict(d, KX_STATE2, (1<<1));
+	KX_MACRO_addTypesToDict(d, KX_STATE3, (1<<2));
+	KX_MACRO_addTypesToDict(d, KX_STATE4, (1<<3));
+	KX_MACRO_addTypesToDict(d, KX_STATE5, (1<<4));
+	KX_MACRO_addTypesToDict(d, KX_STATE6, (1<<5));
+	KX_MACRO_addTypesToDict(d, KX_STATE7, (1<<6));
+	KX_MACRO_addTypesToDict(d, KX_STATE8, (1<<7));
+	KX_MACRO_addTypesToDict(d, KX_STATE9, (1<<8));
+	KX_MACRO_addTypesToDict(d, KX_STATE10, (1<<9));
+	KX_MACRO_addTypesToDict(d, KX_STATE11, (1<<10));
+	KX_MACRO_addTypesToDict(d, KX_STATE12, (1<<11));
+	KX_MACRO_addTypesToDict(d, KX_STATE13, (1<<12));
+	KX_MACRO_addTypesToDict(d, KX_STATE14, (1<<13));
+	KX_MACRO_addTypesToDict(d, KX_STATE15, (1<<14));
+	KX_MACRO_addTypesToDict(d, KX_STATE16, (1<<15));
+	KX_MACRO_addTypesToDict(d, KX_STATE17, (1<<16));
+	KX_MACRO_addTypesToDict(d, KX_STATE18, (1<<17));
+	KX_MACRO_addTypesToDict(d, KX_STATE19, (1<<18));
+	KX_MACRO_addTypesToDict(d, KX_STATE20, (1<<19));
+	KX_MACRO_addTypesToDict(d, KX_STATE21, (1<<20));
+	KX_MACRO_addTypesToDict(d, KX_STATE22, (1<<21));
+	KX_MACRO_addTypesToDict(d, KX_STATE23, (1<<22));
+	KX_MACRO_addTypesToDict(d, KX_STATE24, (1<<23));
+	KX_MACRO_addTypesToDict(d, KX_STATE25, (1<<24));
+	KX_MACRO_addTypesToDict(d, KX_STATE26, (1<<25));
+	KX_MACRO_addTypesToDict(d, KX_STATE27, (1<<26));
+	KX_MACRO_addTypesToDict(d, KX_STATE28, (1<<27));
+	KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28));
+	KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29));
+
 	// Check for errors
 	if (PyErr_Occurred())
     {





More information about the Bf-blender-cvs mailing list