svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22701:22704
authorCampbell Barton <ideasman42@gmail.com>
Sat, 22 Aug 2009 14:23:54 +0000 (14:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 22 Aug 2009 14:23:54 +0000 (14:23 +0000)
1  2 
source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
source/gameengine/GameLogic/SCA_KeyboardSensor.h

index f065452f8c60152ae170ca737092313ee5571939,a5581f0d9876f1b97ca7702356a1d1235e4e7056..13b32b5446c94dfa60a1b3ceabd4f4e71a65b86f
@@@ -48,9 -48,9 +48,8 @@@ SCA_KeyboardSensor::SCA_KeyboardSensor(
                                                                           bool bAllKeys,
                                                                           const STR_String& targetProp,
                                                                           const STR_String& toggleProp,
 -                                                                         SCA_IObject* gameobj,
 -                                                                         PyTypeObject* T )
 -      :SCA_ISensor(gameobj,keybdmgr,T),
 +                                                                         SCA_IObject* gameobj)
 +      :SCA_ISensor(gameobj,keybdmgr),
-        m_pKeyboardMgr(keybdmgr),
         m_hotkey(hotkey),
         m_qual(qual),
         m_qual2(qual2),
@@@ -125,7 -125,7 +124,7 @@@ bool SCA_KeyboardSensor::Evaluate(
        bool qual_change = false;
        short int m_val_orig = m_val;
        
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
        //      cerr << "SCA_KeyboardSensor::Eval event, sensing for "<< m_hotkey << " at device " << inputdev << "\n";
  
        /* See if we need to do logging: togPropState exists and is
@@@ -360,7 -360,7 +359,7 @@@ void SCA_KeyboardSensor::AddToTargetPro
   */   
  bool SCA_KeyboardSensor::IsShifted(void)
  {
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
        
        if ( (inputdev->GetEventValue(SCA_IInputDevice::KX_RIGHTSHIFTKEY).m_status 
                  == SCA_InputEvent::KX_ACTIVE)
  
  void SCA_KeyboardSensor::LogKeystrokes(void) 
  {
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
        int num = inputdev->GetNumActiveEvents();
  
        /* weird loop, this one... */
@@@ -417,7 -417,7 +416,7 @@@ const char SCA_KeyboardSensor::GetKey_d
  PyObject* SCA_KeyboardSensor::PyGetKey()
  {
        ShowDeprecationWarning("getKey()", "the key property");
 -      return PyInt_FromLong(m_hotkey);
 +      return PyLong_FromSsize_t(m_hotkey);
  }
  
  /** 2. SetKey: change the key to look at */
@@@ -449,7 -449,7 +448,7 @@@ const char SCA_KeyboardSensor::GetHold1
  PyObject* SCA_KeyboardSensor::PyGetHold1()
  {
        ShowDeprecationWarning("getHold1()", "the hold1 property");
 -      return PyInt_FromLong(m_qual);
 +      return PyLong_FromSsize_t(m_qual);
  }
  
  /** 4. SetHold1: change the first bucky bit */
@@@ -481,7 -481,7 +480,7 @@@ const char SCA_KeyboardSensor::GetHold2
  PyObject* SCA_KeyboardSensor::PyGetHold2()
  {
        ShowDeprecationWarning("getHold2()", "the hold2 property");
 -      return PyInt_FromLong(m_qual2);
 +      return PyLong_FromSsize_t(m_qual2);
  }
  
  /** 6. SetHold2: change the second bucky bit */
@@@ -514,7 -514,7 +513,7 @@@ PyObject* SCA_KeyboardSensor::PyGetPres
  {
        ShowDeprecationWarning("getPressedKeys()", "events");
  
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
  
        int num = inputdev->GetNumJustEvents();
        PyObject* resultlist = PyList_New(num);
                                || (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED))
                        {
                                PyObject* keypair = PyList_New(2);
 -                              PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
 -                              PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
 +                              PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
 +                              PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                                PyList_SET_ITEM(resultlist,index,keypair);
                                index++;
                                
@@@ -555,7 -555,7 +554,7 @@@ PyObject* SCA_KeyboardSensor::PyGetCurr
  {
        ShowDeprecationWarning("getCurrentlyPressedKeys()", "events");
  
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
  
        int num = inputdev->GetNumActiveEvents();
        PyObject* resultlist = PyList_New(num);
                                 || (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED))
                        {
                                PyObject* keypair = PyList_New(2);
 -                              PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
 -                              PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
 +                              PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
 +                              PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                                PyList_SET_ITEM(resultlist,index,keypair);
                                index++;
                                
@@@ -591,12 -591,12 +590,12 @@@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor
  "getKeyStatus(keycode)\n"
  "\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
  {
 -      if (!PyInt_Check(value)) {
 +      if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int");
                return NULL;
        }
        
 -      int keycode = PyInt_AsLong(value);
 +      int keycode = PyLong_AsSsize_t(value);
        
        if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
                || (keycode > SCA_IInputDevice::KX_ENDKEY)){
                return NULL;
        }
        
-       SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
        const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
 -      return PyInt_FromLong(inevent.m_status);
 +      return PyLong_FromSsize_t(inevent.m_status);
  }
  
  /* ------------------------------------------------------------------------- */
  /* ------------------------------------------------------------------------- */
  
  PyTypeObject SCA_KeyboardSensor::Type = {
 -#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
 -#else
 -      /* python 2.5 and below */
 -      PyObject_HEAD_INIT( NULL )  /* required py macro */
 -      0,                          /* ob_size */
 -#endif
        "SCA_KeyboardSensor",
        sizeof(PyObjectPlus_Proxy),
        0,
        0,
        0,
        py_base_repr,
 -      0,0,0,0,0,0,
 -      py_base_getattro,
 -      py_base_setattro,
        0,0,0,0,0,0,0,0,0,
 -      Methods
 -};
 -
 -PyParentObject SCA_KeyboardSensor::Parents[] = {
 -      &SCA_KeyboardSensor::Type,
 +      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
 +      0,0,0,0,0,0,0,
 +      Methods,
 +      0,
 +      0,
        &SCA_ISensor::Type,
 -      &SCA_ILogicBrick::Type,
 -      &CValue::Type,
 -      NULL
 +      0,0,0,0,0,0,
 +      py_base_new
  };
  
  PyMethodDef SCA_KeyboardSensor::Methods[] = {
        //Deprecated functions ------>
 -      {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (PY_METHODCHAR)GetKey_doc},
 -      {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (PY_METHODCHAR)SetKey_doc},
 -      {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (PY_METHODCHAR)GetHold1_doc},
 -      {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (PY_METHODCHAR)SetHold1_doc},
 -      {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (PY_METHODCHAR)GetHold2_doc},
 -      {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (PY_METHODCHAR)SetHold2_doc},
 -      {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetPressedKeys_doc},
 -      {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
 +      {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (const char *)GetKey_doc},
 +      {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (const char *)SetKey_doc},
 +      {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (const char *)GetHold1_doc},
 +      {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (const char *)SetHold1_doc},
 +      {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (const char *)GetHold2_doc},
 +      {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (const char *)SetHold2_doc},
 +      {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (const char *)GetPressedKeys_doc},
 +      {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (const char *)GetCurrentlyPressedKeys_doc},
        //<----- Deprecated
        KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus),
        {NULL,NULL} //Sentinel
@@@ -661,12 -671,26 +660,12 @@@ PyAttributeDef SCA_KeyboardSensor::Attr
        { NULL }        //Sentinel
  };
  
 -PyObject* SCA_KeyboardSensor::py_getattro(PyObject *attr)
 -{
 -  py_getattro_up(SCA_ISensor);
 -}
 -
 -PyObject* SCA_KeyboardSensor::py_getattro_dict() {
 -      py_getattro_dict_up(SCA_ISensor);
 -}
 -
 -int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
 -{
 -      py_setattro_up(SCA_ISensor);
 -}
 -
  
  PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
  {
        SCA_KeyboardSensor* self= static_cast<SCA_KeyboardSensor*>(self_v);
        
-       SCA_IInputDevice* inputdev = self->m_pKeyboardMgr->GetInputDevice();
+       SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)self->m_eventmgr)->GetInputDevice();
  
        PyObject* resultlist = PyList_New(0);
        
                if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
                {
                        PyObject* keypair = PyList_New(2);
 -                      PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
 -                      PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
 +                      PyList_SET_ITEM(keypair,0,PyLong_FromSsize_t(i));
 +                      PyList_SET_ITEM(keypair,1,PyLong_FromSsize_t(inevent.m_status));
                        PyList_Append(resultlist,keypair);
                }
        }       
index 3185b386d41e3435edbfd7b2c2fc45d50a8b1e12,13fcc21ab7be54ed365fab31c272232b4efc59ca..bce56b800e6758abaea6ca989cd96548eac64ddf
@@@ -43,8 -43,6 +43,6 @@@
  class SCA_KeyboardSensor : public SCA_ISensor
  {
        Py_Header;
-       class SCA_KeyboardManager*      m_pKeyboardMgr;
  
        /**
         * the key this sensor is sensing for
@@@ -94,7 -92,8 +92,7 @@@ public
                                           bool bAllKeys,
                                           const STR_String& targetProp,
                                           const STR_String& toggleProp,
 -                                         SCA_IObject* gameobj,
 -                                         PyTypeObject* T=&Type );
 +                                         SCA_IObject* gameobj);
        virtual ~SCA_KeyboardSensor();
        virtual CValue* GetReplica();
        virtual void Init();
        /* Python interface ---------------------------------------------------- */
        /* --------------------------------------------------------------------- */
  
 -      virtual PyObject* py_getattro(PyObject *attr);
 -      virtual PyObject* py_getattro_dict();
 -      virtual int py_setattro(PyObject *attr, PyObject *value);
 -
        //Deprecated functions ----->
        /** 1. GetKey : check which key this sensor looks at */
        KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetKey);