BGE patch 15044 approved: Edit Object Dynamics Actuator.
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 25 Jun 2008 14:09:15 +0000 (14:09 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 25 Jun 2008 14:09:15 +0000 (14:09 +0000)
Add enable/disable dynamics actuator under the "Edit Object" category.
The Enable/disable rigid body option is also availale but not implemented.

projectfiles_vc7/gameengine/ketsji/KX_ketsji.vcproj
source/blender/makesdna/DNA_actuator_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp [new file with mode: 0644]
source/gameengine/Ketsji/KX_SCA_DynamicActuator.h [new file with mode: 0644]

index af0ba74497a8829c1f9fc41dd6e40eea2f98d1cb..9d5a9f55074877e6aef998625fcd89a6d01b0e93 100644 (file)
                                <File
                                        RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_AddObjectActuator.cpp">
                                </File>
+                               <File
+                                       RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_DynamicActuator.cpp">
+                               </File>
                                <File
                                        RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_EndObjectActuator.cpp">
                                </File>
                                <File
                                        RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_AddObjectActuator.h">
                                </File>
+                               <File
+                                       RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_DynamicActuator.h">
+                               </File>
                                <File
                                        RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_EndObjectActuator.h">
                                </File>
index 3f08ea05705acb968acc208fcb6d868b877448b0..20316f2680458b9395374d43b93844f94e6d938c 100644 (file)
@@ -81,7 +81,7 @@ typedef struct bEditObjectActuator {
        char name[32];
        float linVelocity[3]; /* initial lin. velocity on creation */
        short localflag; /* flag for the lin. vel: apply locally   */
-       short pad;
+       short dyn_operation;
 } bEditObjectActuator;
 
 typedef struct bSceneActuator {
@@ -360,10 +360,11 @@ typedef struct FreeCamera {
 /* editObjectActuator->type */
 #define ACT_EDOB_ADD_OBJECT            0
 #define ACT_EDOB_END_OBJECT            1
-#define ACT_EDOB_REPLACE_MESH  2
+#define ACT_EDOB_REPLACE_MESH          2
 #define ACT_EDOB_TRACK_TO              3
-#define ACT_EDOB_MAKE_CHILD            4
-#define ACT_EDOB_END_CHILD             5
+#define ACT_EDOB_DYNAMICS              4
+
+
 
 /* editObjectActuator->flag */
 #define ACT_TRACK_3D                   1
index ec85952a2f8d843ebca8f219d5cc480b628ee7fc..6cdc1d9b7c1533486724bf2eebb69b8a30905083 100644 (file)
@@ -1940,8 +1940,15 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
                        uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2-40, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the tracking takes");
                        uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
                }
-               
-               str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3";
+               else if(eoa->type==ACT_EDOB_DYNAMICS) {
+                       ysize= 48;
+                       glRects(xco, yco-ysize, xco+width, yco);
+                       uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+                       
+                       str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3";
+                       uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
+               }
+               str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
                uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
 
                yco-= ysize;
index f0b549594f2720f5438b4178e8c96d1da590c03f..a50c072914df8ce3bb401b6d604248516d78498d 100644 (file)
@@ -62,6 +62,7 @@
 #include "KX_SCA_EndObjectActuator.h"
 #include "KX_SCA_ReplaceMeshActuator.h"
 #include "KX_ParentActuator.h"
+#include "KX_SCA_DynamicActuator.h"
 
 #include "KX_Scene.h"
 #include "KX_KetsjiEngine.h"
@@ -602,6 +603,15 @@ void BL_ConvertActuators(char* maggiename,
                                                                blenderobject->upflag
                                                                );
                                                        baseact = tmptrackact;
+                                               break;
+                                       }
+                               case ACT_EDOB_DYNAMICS:
+                                       {
+                                               KX_SCA_DynamicActuator* tmpdynact 
+                                                       = new KX_SCA_DynamicActuator(gameobj, 
+                                                               editobact->dyn_operation
+                                                               );
+                                                       baseact = tmpdynact;
                                        }
                                }
                                break;
index cdbce81d6101ea126ccb1c0d80dc88955df03de0..4b467a229f0d3b1fdf38aab6ce097ab9ba47ce95 100644 (file)
@@ -1283,17 +1283,7 @@ PyObject* KX_GameObject::PySuspendDynamics(PyObject* self,
                                                                                   PyObject* args, 
                                                                                   PyObject* kwds)
 {
-       if (m_bSuspendDynamics)
-       {
-               Py_Return;
-       }
-       
-       if (m_pPhysicsController1)
-       {
-               m_pPhysicsController1->SuspendDynamics();
-       }
-       m_bSuspendDynamics = true;
-       
+       SuspendDynamics();
        Py_Return;
 }
 
@@ -1303,18 +1293,7 @@ PyObject* KX_GameObject::PyRestoreDynamics(PyObject* self,
                                                                                   PyObject* args, 
                                                                                   PyObject* kwds)
 {
-       
-       if (!m_bSuspendDynamics)
-       {
-               Py_Return;
-       }
-       
-       if (m_pPhysicsController1)
-       {
-               m_pPhysicsController1->RestoreDynamics();
-       }
-       m_bSuspendDynamics = false;
-       
+       RestoreDynamics();
        Py_Return;
 }
 
index cab1f3167d53d46c231bff5c88d8fca53f8122bb..a0507cb9dbceeb1adff302e9ef97f98a5a0bb9d6 100644 (file)
@@ -46,7 +46,7 @@
 #include "GEN_HashedPtr.h"
 #include "KX_Scene.h"
 #include "KX_KetsjiEngine.h" /* for m_anim_framerate */
-
+#include "KX_IPhysicsController.h" /* for suspend/resume */
 #define KX_OB_DYNAMIC 1
 
 
@@ -652,6 +652,32 @@ public:
         */
        void Resume(void);
        
+       void SuspendDynamics(void) {
+               if (m_bSuspendDynamics)
+               {
+                       return;
+               }
+       
+               if (m_pPhysicsController1)
+               {
+                       m_pPhysicsController1->SuspendDynamics();
+               }
+               m_bSuspendDynamics = true;
+       }
+       
+       void RestoreDynamics(void) {    
+               if (!m_bSuspendDynamics)
+               {
+                       return;
+               }
+       
+               if (m_pPhysicsController1)
+               {
+                       m_pPhysicsController1->RestoreDynamics();
+               }
+               m_bSuspendDynamics = false;
+       }
+       
        KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
        /**
         * @section Python interface functions.
diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
new file mode 100644 (file)
index 0000000..d44ab47
--- /dev/null
@@ -0,0 +1,206 @@
+//
+// Adjust dynamics settins for this object
+//
+// $Id$
+//
+// ***** BEGIN GPL LICENSE BLOCK *****
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+// All rights reserved.
+//
+// The Original Code is: all of this file.
+//
+// Contributor(s): none yet.
+//
+// ***** END GPL LICENSE BLOCK *****
+
+//
+// Previously existed as:
+
+// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
+
+// Please look here for revision history.
+
+#include "KX_SCA_DynamicActuator.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* ------------------------------------------------------------------------- */
+/* Python functions                                                          */
+/* ------------------------------------------------------------------------- */
+
+/* Integration hooks ------------------------------------------------------- */
+
+       PyTypeObject 
+
+KX_SCA_DynamicActuator::
+
+Type = {
+       PyObject_HEAD_INIT(&PyType_Type)
+       0,
+       "KX_SCA_DynamicActuator",
+       sizeof(KX_SCA_DynamicActuator),
+       0,
+       PyDestructor,
+       0,
+       __getattr,
+       __setattr,
+       0, 
+       __repr,
+       0, 
+       0,
+       0,
+       0,
+       0
+};
+
+PyParentObject KX_SCA_DynamicActuator::Parents[] = {
+       &KX_SCA_DynamicActuator::Type,
+       &SCA_IActuator::Type,
+       &SCA_ILogicBrick::Type,
+       &CValue::Type,
+       NULL
+};
+
+
+PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
+       KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
+       KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
+       {NULL,NULL} //Sentinel
+};
+
+
+
+PyObject* KX_SCA_DynamicActuator::_getattr(const STR_String& attr)
+{
+  _getattr_up(SCA_IActuator);
+}
+
+
+
+/* 1. setOperation */
+KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
+"setOperation(operation?)\n"
+"\t - operation? : type of dynamic operation\n"
+"\t                0 = restore dynamics\n"
+"\t                1 = disable dynamics\n"
+"\t                2 = enable rigid body\n"
+"\t                3 = disable rigid body\n"
+"Change the dynamic status of the parent object.\n")
+{
+       int dyn_operation;
+       
+       if (!PyArg_ParseTuple(args, "i", &dyn_operation))
+       {
+               return NULL;    
+       }
+       if (dyn_operation <0 || dyn_operation>3) {
+               PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
+               return NULL;
+       }
+       m_dyn_operation= dyn_operation;
+       Py_Return;
+}
+
+KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
+"getOperation() -> integer\n"
+"Returns the operation type of this actuator.\n"
+)
+{
+       return PyInt_FromLong((long)m_dyn_operation);
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* Native functions                                                          */
+/* ------------------------------------------------------------------------- */
+
+KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
+                                                                                                          short dyn_operation,
+                                                                                                          PyTypeObject* T) : 
+
+       SCA_IActuator(gameobj, T),
+       m_dyn_operation(dyn_operation)
+{
+} /* End of constructor */
+
+
+KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
+{ 
+       // there's nothing to be done here, really....
+} /* end of destructor */
+
+
+
+bool KX_SCA_DynamicActuator::Update()
+{
+       // bool result = false; /*unused*/
+       KX_GameObject *obj = (KX_GameObject*) GetParent();
+       bool bNegativeEvent = IsNegativeEvent();
+       KX_IPhysicsController* controller;
+       RemoveAllEvents();
+
+       if (bNegativeEvent)
+               return false; // do nothing on negative events
+       
+       if (!obj)
+               return false; // object not accessible, shouldnt happen
+       controller = obj->GetPhysicsController();
+       if (!controller)
+               return false;   // no physic object
+
+       switch (m_dyn_operation)
+       {
+               case 0:                 
+                       obj->RestoreDynamics(); 
+                       break;
+               case 1:
+                       obj->SuspendDynamics();
+                       break;
+               case 2:
+                       controller->setRigidBody(true); 
+                       break;
+               case 3:
+                       controller->setRigidBody(false);
+                       break;
+       }
+
+       return false;
+}
+
+
+
+CValue* KX_SCA_DynamicActuator::GetReplica()
+{
+       KX_SCA_DynamicActuator* replica = 
+               new KX_SCA_DynamicActuator(*this);
+
+       if (replica == NULL)
+               return NULL;
+
+       replica->ProcessReplica();
+
+       // this will copy properties and so on...
+       CValue::AddDataToReplica(replica);
+
+       return replica;
+};
+
+
+/* eof */
diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h
new file mode 100644 (file)
index 0000000..b47c3a5
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Add object to the game world on action of this actuator
+//
+// $Id$
+//
+// ***** BEGIN GPL LICENSE BLOCK *****
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//
+// The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+// All rights reserved.
+//
+// The Original Code is: all of this file.
+//
+// Contributor(s): Campbell Barton
+//
+// ***** END GPL LICENSE BLOCK *****
+//
+
+#ifndef __KX_SCA_DYNAMICACTUATOR
+#define __KX_SCA_DYNAMICACTUATOR
+
+#include "SCA_IActuator.h"
+#include "SCA_PropertyActuator.h"
+#include "SCA_LogicManager.h"
+
+#include "KX_GameObject.h"
+#include "KX_IPhysicsController.h"
+
+class KX_SCA_DynamicActuator : public SCA_IActuator
+{
+       Py_Header;
+
+       // dynamics operation to apply to the game object
+       short m_dyn_operation;
+ public:
+       KX_SCA_DynamicActuator(
+               SCA_IObject* gameobj, 
+               short dyn_operation,
+               PyTypeObject* T=&Type
+       );
+
+       ~KX_SCA_DynamicActuator(
+       );
+
+               CValue* 
+       GetReplica(
+       );
+
+       virtual bool 
+       Update();
+
+       virtual PyObject*  
+       _getattr(
+               const STR_String& attr
+       );
+
+       /* 1. setOperation */
+       KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation);
+       KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,getOperation);
+
+}; 
+
+#endif