Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-20 19:06:46 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-20 19:06:46 +0400
commit874c29cea8e6f9bc411fccf2d6f4cb07e94328d0 (patch)
tree5971e577cf7c02e05a1e37b5ad058c71a6744877 /source/gameengine/GameLogic
parent7555bfa793a2b0fc187c6211c56986f35b2d7b09 (diff)
parentc5bc4e4fb1a33eda8c31f2ea02e91f32f74c8fa5 (diff)
2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323:HEAD
Notes: * blenderbuttons and ICON_SNAP_PEEL_OBJECT were not merged.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp91
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.h41
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h6
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.cpp92
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.h37
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.cpp42
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.h6
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.cpp50
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.h10
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.cpp67
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h10
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.cpp101
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.h19
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.cpp244
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.h13
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.cpp478
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.h58
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.cpp46
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.h8
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.cpp67
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.h5
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.cpp58
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h16
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp152
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.h8
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.cpp218
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.h64
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.cpp76
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.h15
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.h2
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.h2
48 files changed, 1175 insertions, 1123 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index c21e5db1410..c300baa9bd4 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -29,6 +29,7 @@
#endif
#include <stdio.h>
+#include <stdlib.h>
#include "SCA_Joystick.h"
#include "SCA_JoystickPrivate.h"
@@ -36,21 +37,19 @@
SCA_Joystick::SCA_Joystick(short int index)
:
m_joyindex(index),
- m_axis10(0),
- m_axis11(0),
- m_axis20(0),
- m_axis21(0),
m_prec(3200),
m_buttonnum(-2),
m_axismax(-1),
- m_hatdir(-2),
m_buttonmax(-1),
m_hatmax(-1),
+ m_hatdir(-2),
m_isinit(0),
m_istrig_axis(0),
m_istrig_button(0),
m_istrig_hat(0)
{
+ for(int i=0; i<JOYAXIS_MAX; i++)
+ m_axis_array[i]= 0;
#ifndef DISABLE_SDL
m_private = new PrivateData();
#endif
@@ -125,47 +124,30 @@ void SCA_Joystick::cSetPrecision(int val)
}
-bool SCA_Joystick::aAnyAxisIsPositive(int axis)
+bool SCA_Joystick::aAxisPairIsPositive(int axis)
{
- bool result;
- int res = pAxisTest(axis);
- res > m_prec? result = true: result = false;
- return result;
+ return (pAxisTest(axis) > m_prec) ? true:false;
}
-bool SCA_Joystick::aRightAxisIsPositive(int axis)
+bool SCA_Joystick::aAxisPairDirectionIsPositive(int axis, int dir)
{
- bool result;
- int res = pGetAxis(axis,1);
- res > m_prec? result = true: result = false;
- return result;
-}
-
-bool SCA_Joystick::aUpAxisIsPositive(int axis)
-{
- bool result;
- int res = pGetAxis(axis,0);
- res < -m_prec? result = true : result = false;
- return result;
+ int res;
+
+ if (dir==JOYAXIS_UP || dir==JOYAXIS_DOWN)
+ res = pGetAxis(axis, 1);
+ else /* JOYAXIS_LEFT || JOYAXIS_RIGHT */
+ res = pGetAxis(axis, 0);
+
+ if (dir==JOYAXIS_DOWN || dir==JOYAXIS_RIGHT)
+ return (res > m_prec) ? true : false;
+ else /* JOYAXIS_UP || JOYAXIS_LEFT */
+ return (res < -m_prec) ? true : false;
}
-
-bool SCA_Joystick::aLeftAxisIsPositive(int axis)
+bool SCA_Joystick::aAxisIsPositive(int axis_single)
{
- bool result;
- int res = pGetAxis(axis,1);
- res < -m_prec ? result = true : result = false;
- return result;
-}
-
-
-bool SCA_Joystick::aDownAxisIsPositive(int axis)
-{
- bool result;
- int res = pGetAxis(axis,0);
- res > m_prec ? result = true:result = false;
- return result;
+ return abs(m_axis_array[axis_single]) > m_prec ? true:false;
}
bool SCA_Joystick::aAnyButtonPressIsPositive(void)
@@ -255,8 +237,12 @@ bool SCA_Joystick::CreateJoystickDevice(void)
/* must run after being initialized */
m_axismax = SDL_JoystickNumAxes(m_private->m_joystick);
+ if (m_axismax > JOYAXIS_MAX) m_axismax= JOYAXIS_MAX; /* very unlikely */
+
m_buttonmax = SDL_JoystickNumButtons(m_private->m_joystick);
m_hatmax = SDL_JoystickNumHats(m_private->m_joystick);
+
+
}
return true;
#endif
@@ -288,17 +274,8 @@ int SCA_Joystick::Connected(void)
void SCA_Joystick::pFillAxes()
{
#ifndef DISABLE_SDL
- if(m_axismax == 1){
- m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0);
- m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1);
- }else if(m_axismax > 1){
- m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0);
- m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1);
- m_axis20 = SDL_JoystickGetAxis(m_private->m_joystick, 2);
- m_axis21 = SDL_JoystickGetAxis(m_private->m_joystick, 3);
- }else{
- m_axis10 = m_axis11 = m_axis20 = m_axis21 = 0;
- }
+ for(int i=0; i<m_axismax; i++)
+ m_axis_array[i]= SDL_JoystickGetAxis(m_private->m_joystick, i);
#endif
}
@@ -306,10 +283,7 @@ void SCA_Joystick::pFillAxes()
int SCA_Joystick::pGetAxis(int axisnum, int udlr)
{
#ifndef DISABLE_SDL
- if(axisnum == 1 && udlr == 1)return m_axis10; //u/d
- if(axisnum == 1 && udlr == 0)return m_axis11; //l/r
- if(axisnum == 2 && udlr == 0)return m_axis20; //...
- if(axisnum == 2 && udlr == 1)return m_axis21;
+ return m_axis_array[(axisnum*2)+udlr];
#endif
return 0;
}
@@ -317,13 +291,9 @@ int SCA_Joystick::pGetAxis(int axisnum, int udlr)
int SCA_Joystick::pAxisTest(int axisnum)
{
#ifndef DISABLE_SDL
- short i1,i2;
- if(axisnum == 1) {
- i1 = m_axis10; i2 = m_axis11;
- }
- else if(axisnum == 2) {
- i1 = m_axis20; i2 = m_axis21;
- }
+ short i1= m_axis_array[(axisnum*2)];
+ short i2= m_axis_array[(axisnum*2)+1];
+
/* long winded way to do
* return MAX2(abs(i1), abs(i2))
* avoid abs from math.h */
@@ -335,4 +305,3 @@ int SCA_Joystick::pAxisTest(int axisnum)
return 0;
#endif
}
-
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
index 8335d5538ad..53cd65cd495 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
@@ -55,10 +55,8 @@ class SCA_Joystick
/*
*support for 2 axes
*/
-
- int m_axis10,m_axis11;
- int m_axis20,m_axis21;
-
+ int m_axis_array[JOYAXIS_MAX];
+
/*
* Precision or range of the axes
*/
@@ -120,8 +118,11 @@ class SCA_Joystick
void OnButtonUp(SDL_Event *sdl_event);
void OnButtonDown(SDL_Event *sdl_event);
void OnNothing(SDL_Event *sdl_event);
+#if 0 /* not used yet */
void OnBallMotion(SDL_Event *sdl_event){}
#endif
+
+#endif
/*
* Open the joystick
*/
@@ -139,12 +140,12 @@ class SCA_Joystick
void pFillButtons(void);
/*
- * returns m_axis10,m_axis11...
+ * returns m_axis_array
*/
int pAxisTest(int axisnum);
/*
- * returns m_axis10,m_axis11...
+ * returns m_axis_array
*/
int pGetAxis(int axisnum, int udlr);
@@ -166,11 +167,9 @@ public:
/*
*/
- bool aAnyAxisIsPositive(int axis);
- bool aUpAxisIsPositive(int axis);
- bool aDownAxisIsPositive(int axis);
- bool aLeftAxisIsPositive(int axis);
- bool aRightAxisIsPositive(int axis);
+ bool aAxisPairIsPositive(int axis);
+ bool aAxisPairDirectionIsPositive(int axis, int dir); /* function assumes joysticks are in axis pairs */
+ bool aAxisIsPositive(int axis_single); /* check a single axis only */
bool aAnyButtonPressIsPositive(void);
bool aAnyButtonReleaseIsPositive(void);
@@ -184,24 +183,10 @@ public:
void cSetPrecision(int val);
- int GetAxis10(void){
-
- return m_axis10;
-
- }
-
- int GetAxis11(void){
- return m_axis11;
- }
-
- int GetAxis20(void){
- return m_axis20;
+ int GetAxisPosition(int index){
+ return m_axis_array[index];
}
-
- int GetAxis21(void){
- return m_axis21;
- }
-
+
int GetButton(void){
return m_buttonnum;
}
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
index 73ffe1406d9..636c4dd5a42 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
@@ -39,5 +39,11 @@
#endif
#define JOYINDEX_MAX 8
+#define JOYAXIS_MAX 16
+
+#define JOYAXIS_RIGHT 0
+#define JOYAXIS_UP 1
+#define JOYAXIS_DOWN 3
+#define JOYAXIS_LEFT 2
#endif
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
index 73ca288861d..8e190060e95 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
@@ -68,7 +68,7 @@ void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
{
- if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax)
+ if(sdl_event->jbutton.button <= m_buttonmax) /* unsigned int so always above 0 */
{
m_istrig_button = 1;
m_buttonnum = sdl_event->jbutton.button;
@@ -111,9 +111,11 @@ void SCA_Joystick::HandleEvents(void)
case SDL_JOYBUTTONDOWN:
SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event);
break;
+#if 0 /* Not used yet */
case SDL_JOYBALLMOTION:
SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event);
break;
+#endif
default:
printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n");
break;
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
index 7bf051f2b5c..251a586308e 100644
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
@@ -1,5 +1,29 @@
-#include "SCA_IActuator.h"
+/**
+ * SCA_2DFilterActuator.cpp
+ *
+ * $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.
+ *
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include "SCA_IActuator.h"
#include "SCA_2DFilterActuator.h"
#ifdef HAVE_CONFIG_H
@@ -22,7 +46,7 @@ SCA_2DFilterActuator::SCA_2DFilterActuator(
PyTypeObject* T)
: SCA_IActuator(gameobj, T),
m_type(type),
- m_flag(flag),
+ m_disableMotionBlur(flag),
m_float_arg(float_arg),
m_int_arg(int_arg),
m_rasterizer(rasterizer),
@@ -35,12 +59,6 @@ SCA_2DFilterActuator::SCA_2DFilterActuator(
}
}
-void SCA_2DFilterActuator::SetShaderText(STR_String text)
-{
- m_shaderText = text;
-}
-
-
CValue* SCA_2DFilterActuator::GetReplica()
{
@@ -63,7 +81,7 @@ bool SCA_2DFilterActuator::Update()
if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
{
- if(!m_flag)
+ if(!m_disableMotionBlur)
m_rasterizer->EnableMotionBlur(m_float_arg);
else
m_rasterizer->DisableMotionBlur();
@@ -79,23 +97,35 @@ bool SCA_2DFilterActuator::Update()
}
+void SCA_2DFilterActuator::SetShaderText(STR_String text)
+{
+ m_shaderText = text;
+}
+
+/* ------------------------------------------------------------------------- */
+/* Python functions */
+/* ------------------------------------------------------------------------- */
+
+
+
+/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_2DFilterActuator::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_2DFilterActuator",
- sizeof(SCA_2DFilterActuator),
- 0,
- PyDestructor,
- 0,
- __getattr,
- __setattr,
- 0,
- __repr,
- 0,
- 0,
+ sizeof(PyObjectPlus_Proxy),
0,
- 0,
- 0
+ py_base_dealloc,
+ 0,
+ 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
};
@@ -109,14 +139,26 @@ PyParentObject SCA_2DFilterActuator::Parents[] = {
PyMethodDef SCA_2DFilterActuator::Methods[] = {
- /* add python functions to deal with m_msg... */
+ /* add python functions to deal with m_msg... */
{NULL,NULL}
};
PyAttributeDef SCA_2DFilterActuator::Attributes[] = {
+ KX_PYATTRIBUTE_STRING_RW("shaderText", 0, 64000, false, SCA_2DFilterActuator, m_shaderText),
+ KX_PYATTRIBUTE_SHORT_RW("disableMotionBlur", 0, 1, true, SCA_2DFilterActuator, m_disableMotionBlur),
+ KX_PYATTRIBUTE_ENUM_RW("type",RAS_2DFilterManager::RAS_2DFILTER_ENABLED,RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS,false,SCA_2DFilterActuator,m_type),
+ KX_PYATTRIBUTE_INT_RW("passNb", 0, 100, true, SCA_2DFilterActuator, m_int_arg),
+ KX_PYATTRIBUTE_FLOAT_RW("value", 0.0, 100.0, SCA_2DFilterActuator, m_float_arg),
{ NULL } //Sentinel
};
-PyObject* SCA_2DFilterActuator::_getattr(const char *attr) {
- _getattr_up(SCA_IActuator);
+PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr)
+{
+ py_getattro_up(SCA_IActuator);
+}
+
+int SCA_2DFilterActuator::py_setattro(PyObject *attr, PyObject* value)
+{
+ py_setattro_up(SCA_IActuator);
}
+
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
index 9da0500afff..de0201a4b19 100644
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h
+++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
@@ -1,3 +1,30 @@
+/**
+ * SCA_2DFilterActuator.h
+ *
+ * $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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
#ifndef __SCA_2DFILETRACTUATOR_H__
#define __SCA_2DFILETRACTUATOR_H__
@@ -13,7 +40,7 @@ private:
vector<STR_String> m_propNames;
void * m_gameObj;
RAS_2DFilterManager::RAS_2DFILTER_MODE m_type;
- short m_flag;
+ short m_disableMotionBlur;
float m_float_arg;
int m_int_arg;
STR_String m_shaderText;
@@ -38,7 +65,13 @@ public:
virtual bool Update();
virtual CValue* GetReplica();
- virtual PyObject* _getattr(const char *attr);
+
+ /* --------------------------------------------------------------------- */
+ /* Python interface ---------------------------------------------------- */
+ /* --------------------------------------------------------------------- */
+
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject* value);
};
#endif
diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp
index b67ef7dabaf..1cb03f375cb 100644
--- a/source/gameengine/GameLogic/SCA_ANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_ANDController.cpp
@@ -107,22 +107,22 @@ CValue* SCA_ANDController::GetReplica()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ANDController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_ANDController",
- sizeof(SCA_ANDController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_ANDController::Parents[] = {
@@ -141,8 +141,8 @@ PyAttributeDef SCA_ANDController::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_ANDController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_ANDController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ANDController.h b/source/gameengine/GameLogic/SCA_ANDController.h
index eba7e1b545a..fdb93d0fc42 100644
--- a/source/gameengine/GameLogic/SCA_ANDController.h
+++ b/source/gameengine/GameLogic/SCA_ANDController.h
@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
index 7f8dbef7758..acd906ef9dd 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
@@ -122,22 +122,22 @@ void SCA_ActuatorSensor::Update()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ActuatorSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_ActuatorSensor",
- sizeof(SCA_ActuatorSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_ActuatorSensor::Parents[] = {
@@ -161,11 +161,12 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_ActuatorSensor::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor); /* implicit return! */
+PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_ISensor);
+}
+
+int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) {
+ py_setattro_up(SCA_ISensor);
}
int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
@@ -180,18 +181,11 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
return 1;
}
-int SCA_ActuatorSensor::_setattr(const char *attr, PyObject *value) {
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
-}
-
/* 3. getActuator */
const char SCA_ActuatorSensor::GetActuator_doc[] =
"getActuator()\n"
"\tReturn the Actuator with which the sensor operates.\n";
-PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self)
+PyObject* SCA_ActuatorSensor::PyGetActuator()
{
ShowDeprecationWarning("getActuator()", "the actuator property");
return PyString_FromString(m_checkactname);
@@ -203,14 +197,14 @@ const char SCA_ActuatorSensor::SetActuator_doc[] =
"\t- name: string\n"
"\tSets the Actuator with which to operate. If there is no Actuator\n"
"\tof this name, the call is ignored.\n";
-PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* args)
{
ShowDeprecationWarning("setActuator()", "the actuator property");
/* We should query whether the name exists. Or should we create a prop */
/* on the fly? */
char *actNameArg = NULL;
- if (!PyArg_ParseTuple(args, "s", &actNameArg)) {
+ if (!PyArg_ParseTuple(args, "s:setActuator", &actNameArg)) {
return NULL;
}
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
index 75ee08f42d6..21960993497 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h
+++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
@@ -61,11 +61,11 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
/* 3. setProperty */
- KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ActuatorSensor,SetActuator);
/* 4. getProperty */
KX_PYMETHOD_DOC_NOARGS(SCA_ActuatorSensor,GetActuator);
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
index 154f0ad8cef..b7ecb0233a1 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
@@ -105,22 +105,22 @@ bool SCA_AlwaysSensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_AlwaysSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_AlwaysSensor",
- sizeof(SCA_AlwaysSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_AlwaysSensor::Parents[] = {
@@ -139,8 +139,8 @@ PyAttributeDef SCA_AlwaysSensor::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_AlwaysSensor::_getattr(const char *attr) {
- _getattr_up(SCA_ISensor);
+PyObject* SCA_AlwaysSensor::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_ISensor);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h
index ebe6ba80208..87949babf59 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.h
+++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.h
@@ -52,7 +52,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
index 31a620b939d..44a0175d916 100644
--- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
@@ -131,22 +131,22 @@ bool SCA_DelaySensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_DelaySensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_DelaySensor",
- sizeof(SCA_DelaySensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_DelaySensor::Parents[] = {
@@ -178,18 +178,12 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_DelaySensor::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor);
+PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_ISensor);
}
-int SCA_DelaySensor::_setattr(const char *attr, PyObject *value) {
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
+int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) {
+ py_setattro_up(SCA_ISensor);
}
@@ -198,12 +192,12 @@ const char SCA_DelaySensor::SetDelay_doc[] =
"\t- delay: length of the initial OFF period as number of frame\n"
"\t 0 for immediate trigger\n"
"\tSet the initial delay before the positive trigger\n";
-PyObject* SCA_DelaySensor::PySetDelay(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_DelaySensor::PySetDelay(PyObject* args)
{
ShowDeprecationWarning("setDelay()", "the delay property");
int delay;
- if(!PyArg_ParseTuple(args, "i", &delay)) {
+ if(!PyArg_ParseTuple(args, "i:setDelay", &delay)) {
return NULL;
}
if (delay < 0) {
@@ -220,12 +214,12 @@ const char SCA_DelaySensor::SetDuration_doc[] =
"\t 0 for no ON period\n"
"\tSet the duration of the ON pulse after initial delay.\n"
"\tIf > 0, a negative trigger is fired at the end of the ON pulse.\n";
-PyObject* SCA_DelaySensor::PySetDuration(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_DelaySensor::PySetDuration(PyObject* args)
{
ShowDeprecationWarning("setDuration()", "the duration property");
int duration;
- if(!PyArg_ParseTuple(args, "i", &duration)) {
+ if(!PyArg_ParseTuple(args, "i:setDuration", &duration)) {
return NULL;
}
if (duration < 0) {
@@ -241,12 +235,12 @@ const char SCA_DelaySensor::SetRepeat_doc[] =
"\t- repeat: 1 if the initial OFF-ON cycle should be repeated indefinately\n"
"\t 0 if the initial OFF-ON cycle should run only once\n"
"\tSet the sensor repeat mode\n";
-PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_DelaySensor::PySetRepeat(PyObject* args)
{
ShowDeprecationWarning("setRepeat()", "the repeat property");
int repeat;
- if(!PyArg_ParseTuple(args, "i", &repeat)) {
+ if(!PyArg_ParseTuple(args, "i:setRepeat", &repeat)) {
return NULL;
}
m_repeat = (repeat != 0);
@@ -256,7 +250,7 @@ PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject*
const char SCA_DelaySensor::GetDelay_doc[] =
"getDelay()\n"
"\tReturn the delay parameter value\n";
-PyObject* SCA_DelaySensor::PyGetDelay(PyObject* self)
+PyObject* SCA_DelaySensor::PyGetDelay()
{
ShowDeprecationWarning("getDelay()", "the delay property");
return PyInt_FromLong(m_delay);
@@ -265,7 +259,7 @@ PyObject* SCA_DelaySensor::PyGetDelay(PyObject* self)
const char SCA_DelaySensor::GetDuration_doc[] =
"getDuration()\n"
"\tReturn the duration parameter value\n";
-PyObject* SCA_DelaySensor::PyGetDuration(PyObject* self)
+PyObject* SCA_DelaySensor::PyGetDuration()
{
ShowDeprecationWarning("getDuration()", "the duration property");
return PyInt_FromLong(m_duration);
@@ -274,7 +268,7 @@ PyObject* SCA_DelaySensor::PyGetDuration(PyObject* self)
const char SCA_DelaySensor::GetRepeat_doc[] =
"getRepeat()\n"
"\tReturn the repeat parameter value\n";
-PyObject* SCA_DelaySensor::PyGetRepeat(PyObject* self)
+PyObject* SCA_DelaySensor::PyGetRepeat()
{
ShowDeprecationWarning("getRepeat()", "the repeat property");
return BoolToPyArg(m_repeat);
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h
index 491eee61da8..8da76ff7189 100644
--- a/source/gameengine/GameLogic/SCA_DelaySensor.h
+++ b/source/gameengine/GameLogic/SCA_DelaySensor.h
@@ -60,13 +60,13 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
/* setProperty */
- KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay);
- KX_PYMETHOD_DOC(SCA_DelaySensor,SetDuration);
- KX_PYMETHOD_DOC(SCA_DelaySensor,SetRepeat);
+ KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetDelay);
+ KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetDuration);
+ KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetRepeat);
/* getProperty */
KX_PYMETHOD_DOC_NOARGS(SCA_DelaySensor,GetDelay);
KX_PYMETHOD_DOC_NOARGS(SCA_DelaySensor,GetDuration);
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
index 8ed46beb7f3..352a39a6fea 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
@@ -109,7 +109,7 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
printf(value->GetText());
} else
{
- float num = value->GetNumber();
+ float num = (float)value->GetNumber();
expressionresult = !MT_fuzzyZero(num);
}
value->Release();
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h
index 79c26eea1e7..2936742be19 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.h
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.h
@@ -59,7 +59,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
-// virtual PyObject* _getattr(const char *attr);
+// virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
index 49d39f75814..3cd750ff63b 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
@@ -123,7 +123,7 @@ const STR_String& SCA_ILogicBrick::GetText()
-float SCA_ILogicBrick::GetNumber()
+double SCA_ILogicBrick::GetNumber()
{
return -1;
}
@@ -217,22 +217,22 @@ CValue* SCA_ILogicBrick::GetEvent()
/* python stuff */
PyTypeObject SCA_ILogicBrick::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_ILogicBrick",
- sizeof(SCA_ILogicBrick),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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
};
@@ -246,8 +246,8 @@ PyParentObject SCA_ILogicBrick::Parents[] = {
PyMethodDef SCA_ILogicBrick::Methods[] = {
+ // --> Deprecated
{"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS},
- // --> Deprecated
{"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS},
{"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS},
// <-- Deprecated
@@ -255,6 +255,7 @@ PyMethodDef SCA_ILogicBrick::Methods[] = {
};
PyAttributeDef SCA_ILogicBrick::Attributes[] = {
+ KX_PYATTRIBUTE_RO_FUNCTION("owner", SCA_ILogicBrick, pyattr_get_owner),
KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority),
{NULL} //Sentinel
};
@@ -278,30 +279,25 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
}
PyObject*
-SCA_ILogicBrick::_getattr(const char *attr)
+SCA_ILogicBrick::py_getattro(PyObject *attr)
{
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(CValue);
+ py_getattro_up(CValue);
}
-int SCA_ILogicBrick::_setattr(const char *attr, PyObject *value)
+int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return CValue::_setattr(attr, value);
+ py_setattro_up(CValue);
}
-PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self)
+PyObject* SCA_ILogicBrick::PyGetOwner()
{
+ ShowDeprecationWarning("getOwner()", "the owner property");
+
CValue* parent = GetParent();
if (parent)
{
- parent->AddRef();
- return parent;
+ return parent->GetProxy();
}
printf("ERROR: Python scriptblock without owner\n");
@@ -310,15 +306,13 @@ PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self)
-PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* args)
{
ShowDeprecationWarning("setExecutePriority()", "the executePriority property");
int priority=0;
- if (!PyArg_ParseTuple(args, "i", &priority)) {
+ if (!PyArg_ParseTuple(args, "i:setExecutePriority", &priority)) {
return NULL;
}
@@ -329,13 +323,26 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
-PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self)
+PyObject* SCA_ILogicBrick::PyGetExecutePriority()
{
ShowDeprecationWarning("getExecutePriority()", "the executePriority property");
return PyInt_FromLong(m_Execute_Ueber_Priority);
}
+/*Attribute functions */
+PyObject* SCA_ILogicBrick::pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_ILogicBrick* self= static_cast<SCA_ILogicBrick*>(self_v);
+ CValue* parent = self->GetParent();
+
+ if (parent)
+ return parent->GetProxy();
+
+ Py_RETURN_NONE;
+}
+
+
/* Conversions for making life better. */
bool SCA_ILogicBrick::PyArgToBool(int boolArg)
@@ -347,8 +354,6 @@ bool SCA_ILogicBrick::PyArgToBool(int boolArg)
}
}
-
-
PyObject* SCA_ILogicBrick::BoolToPyArg(bool boolarg)
{
return PyInt_FromLong(boolarg? KX_TRUE: KX_FALSE);
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
index 70d49941613..e59d05ea051 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h
@@ -69,7 +69,7 @@ public:
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
virtual const STR_String & GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
virtual STR_String GetName();
virtual void SetName(STR_String name);
virtual void ReplicaSetName(STR_String name);
@@ -79,8 +79,8 @@ public:
virtual bool LessComparedTo(SCA_ILogicBrick* other);
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
static class SCA_LogicManager* m_sCurrentLogicManager;
@@ -88,8 +88,10 @@ public:
// python methods
KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetOwner);
- KX_PYMETHOD(SCA_ILogicBrick,SetExecutePriority);
+ KX_PYMETHOD_VARARGS(SCA_ILogicBrick,SetExecutePriority);
KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetExecutePriority);
+
+ static PyObject* pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
// check that attribute is a property
static int CheckProperty(void *self, const PyAttributeDef *attrdef);
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
index debd62d44e6..75804525e7a 100644
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ b/source/gameengine/GameLogic/SCA_IObject.cpp
@@ -375,22 +375,22 @@ void SCA_IObject::SetState(unsigned int state)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_IObject::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_IObject",
- sizeof(SCA_IObject),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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
};
@@ -414,7 +414,7 @@ PyAttributeDef SCA_IObject::Attributes[] = {
};
-PyObject* SCA_IObject::_getattr(const char *attr) {
- _getattr_up(CValue);
+PyObject* SCA_IObject::py_getattro(PyObject *attr) {
+ py_getattro_up(CValue);
}
diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h
index d47353b1ac0..44ed3c8f3fe 100644
--- a/source/gameengine/GameLogic/SCA_IObject.h
+++ b/source/gameengine/GameLogic/SCA_IObject.h
@@ -145,7 +145,7 @@ public:
// const class MT_Point3& ConvertPythonPylist(PyObject* pylist);
// here come the python forwarded methods
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
virtual int GetGameObjectType() {return -1;}
diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp
index e8a072f4c46..68f5653d53a 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ISensor.cpp
@@ -105,7 +105,7 @@ void SCA_ISensor::SetLevel(bool lvl) {
}
-float SCA_ISensor::GetNumber() {
+double SCA_ISensor::GetNumber() {
return IsPositiveTrigger();
}
@@ -218,7 +218,7 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
const char SCA_ISensor::IsPositive_doc[] =
"isPositive()\n"
"\tReturns whether the sensor is in an active state.\n";
-PyObject* SCA_ISensor::PyIsPositive(PyObject* self)
+PyObject* SCA_ISensor::PyIsPositive()
{
ShowDeprecationWarning("isPositive()", "the read-only positive property");
int retval = IsPositiveTrigger();
@@ -228,7 +228,7 @@ PyObject* SCA_ISensor::PyIsPositive(PyObject* self)
const char SCA_ISensor::IsTriggered_doc[] =
"isTriggered()\n"
"\tReturns whether the sensor has triggered the current controller.\n";
-PyObject* SCA_ISensor::PyIsTriggered(PyObject* self)
+PyObject* SCA_ISensor::PyIsTriggered()
{
ShowDeprecationWarning("isTriggered()", "the read-only triggered property");
// check with the current controller
@@ -244,7 +244,7 @@ PyObject* SCA_ISensor::PyIsTriggered(PyObject* self)
const char SCA_ISensor::GetUsePosPulseMode_doc[] =
"getUsePosPulseMode()\n"
"\tReturns whether positive pulse mode is active.\n";
-PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self)
+PyObject* SCA_ISensor::PyGetUsePosPulseMode()
{
ShowDeprecationWarning("getUsePosPulseMode()", "the usePosPulseMode property");
return BoolToPyArg(m_pos_pulsemode);
@@ -258,11 +258,11 @@ const char SCA_ISensor::SetUsePosPulseMode_doc[] =
"\t - pulse? : Pulse when a positive event occurs?\n"
"\t (KX_TRUE, KX_FALSE)\n"
"\tSet whether to do pulsing when positive pulses occur.\n";
-PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* args)
{
ShowDeprecationWarning("setUsePosPulseMode()", "the usePosPulseMode property");
int pyarg = 0;
- if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
+ if(!PyArg_ParseTuple(args, "i:setUsePosPulseMode", &pyarg)) { return NULL; }
m_pos_pulsemode = PyArgToBool(pyarg);
Py_RETURN_NONE;
}
@@ -273,7 +273,7 @@ PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyOb
const char SCA_ISensor::GetFrequency_doc[] =
"getFrequency()\n"
"\tReturns the frequency of the updates in pulse mode.\n" ;
-PyObject* SCA_ISensor::PyGetFrequency(PyObject* self)
+PyObject* SCA_ISensor::PyGetFrequency()
{
ShowDeprecationWarning("getFrequency()", "the frequency property");
return PyInt_FromLong(m_pulse_frequency);
@@ -287,12 +287,12 @@ const char SCA_ISensor::SetFrequency_doc[] =
"\t- pulse_frequency: The frequency of the updates in pulse mode (integer)"
"\tSet the frequency of the updates in pulse mode.\n"
"\tIf the frequency is negative, it is set to 0.\n" ;
-PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ISensor::PySetFrequency(PyObject* args)
{
ShowDeprecationWarning("setFrequency()", "the frequency property");
int pulse_frequencyArg = 0;
- if(!PyArg_ParseTuple(args, "i", &pulse_frequencyArg)) {
+ if(!PyArg_ParseTuple(args, "i:setFrequency", &pulse_frequencyArg)) {
return NULL;
}
@@ -310,7 +310,7 @@ PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject*
const char SCA_ISensor::GetInvert_doc[] =
"getInvert()\n"
"\tReturns whether or not pulses from this sensor are inverted.\n" ;
-PyObject* SCA_ISensor::PyGetInvert(PyObject* self)
+PyObject* SCA_ISensor::PyGetInvert()
{
ShowDeprecationWarning("getInvert()", "the invert property");
return BoolToPyArg(m_invert);
@@ -320,11 +320,11 @@ const char SCA_ISensor::SetInvert_doc[] =
"setInvert(invert?)\n"
"\t- invert?: Invert the event-values? (KX_TRUE, KX_FALSE)\n"
"\tSet whether to invert pulses.\n";
-PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ISensor::PySetInvert(PyObject* args)
{
ShowDeprecationWarning("setInvert()", "the invert property");
int pyarg = 0;
- if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
+ if(!PyArg_ParseTuple(args, "i:setInvert", &pyarg)) { return NULL; }
m_invert = PyArgToBool(pyarg);
Py_RETURN_NONE;
}
@@ -336,7 +336,7 @@ const char SCA_ISensor::GetLevel_doc[] =
"\tA level detector will immediately generate a pulse, negative or positive\n"
"\tdepending on the sensor condition, as soon as the state is activated.\n"
"\tA edge detector will wait for a state change before generating a pulse.\n";
-PyObject* SCA_ISensor::PyGetLevel(PyObject* self)
+PyObject* SCA_ISensor::PyGetLevel()
{
ShowDeprecationWarning("getLevel()", "the level property");
return BoolToPyArg(m_level);
@@ -346,11 +346,11 @@ const char SCA_ISensor::SetLevel_doc[] =
"setLevel(level?)\n"
"\t- level?: Detect level instead of edge? (KX_TRUE, KX_FALSE)\n"
"\tSet whether to detect level or edge transition when entering a state.\n";
-PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ISensor::PySetLevel(PyObject* args)
{
ShowDeprecationWarning("setLevel()", "the level property");
int pyarg = 0;
- if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
+ if(!PyArg_ParseTuple(args, "i:setLevel", &pyarg)) { return NULL; }
m_level = PyArgToBool(pyarg);
Py_RETURN_NONE;
}
@@ -358,7 +358,7 @@ PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds
const char SCA_ISensor::GetUseNegPulseMode_doc[] =
"getUseNegPulseMode()\n"
"\tReturns whether negative pulse mode is active.\n";
-PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self)
+PyObject* SCA_ISensor::PyGetUseNegPulseMode()
{
ShowDeprecationWarning("getUseNegPulseMode()", "the useNegPulseMode property");
return BoolToPyArg(m_neg_pulsemode);
@@ -369,11 +369,11 @@ const char SCA_ISensor::SetUseNegPulseMode_doc[] =
"\t - pulse? : Pulse when a negative event occurs?\n"
"\t (KX_TRUE, KX_FALSE)\n"
"\tSet whether to do pulsing when negative pulses occur.\n";
-PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* args)
{
ShowDeprecationWarning("setUseNegPulseMode()", "the useNegPulseMode property");
int pyarg = 0;
- if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
+ if(!PyArg_ParseTuple(args, "i:setUseNegPulseMode", &pyarg)) { return NULL; }
m_neg_pulsemode = PyArgToBool(pyarg);
Py_RETURN_NONE;
}
@@ -393,22 +393,22 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset,
/* ----------------------------------------------- */
PyTypeObject SCA_ISensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_ISensor",
- sizeof(SCA_ISensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_ISensor::Parents[] = {
@@ -454,38 +454,35 @@ PyAttributeDef SCA_ISensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency),
KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert),
KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level),
- // make these properties read-only in _setaddr, must still implement them in _getattr
- KX_PYATTRIBUTE_DUMMY("triggered"),
- KX_PYATTRIBUTE_DUMMY("positive"),
+ KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered),
+ KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive),
{ NULL } //Sentinel
};
PyObject*
-SCA_ISensor::_getattr(const char *attr)
+SCA_ISensor::py_getattro(PyObject *attr)
{
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- if (!strcmp(attr, "triggered"))
- {
- int retval = 0;
- if (SCA_PythonController::m_sCurrentController)
- retval = SCA_PythonController::m_sCurrentController->IsTriggered(this);
- return PyInt_FromLong(retval);
- }
- if (!strcmp(attr, "positive"))
- {
- int retval = IsPositiveTrigger();
- return PyInt_FromLong(retval);
- }
- _getattr_up(SCA_ILogicBrick);
+ py_getattro_up(SCA_ILogicBrick);
}
-int SCA_ISensor::_setattr(const char *attr, PyObject *value)
+int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ILogicBrick::_setattr(attr, value);
+ py_setattro_up(SCA_ILogicBrick);
}
+
+PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v);
+ int retval = 0;
+ if (SCA_PythonController::m_sCurrentController)
+ retval = SCA_PythonController::m_sCurrentController->IsTriggered(self);
+ return PyInt_FromLong(retval);
+}
+
+PyObject* SCA_ISensor::pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_ISensor* self= static_cast<SCA_ISensor*>(self_v);
+ return PyInt_FromLong(self->IsPositiveTrigger());
+}
+
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h
index 23f2c76c19f..6b1c8cca104 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.h
+++ b/source/gameengine/GameLogic/SCA_ISensor.h
@@ -113,7 +113,7 @@ public:
virtual void RegisterToManager();
virtual void UnregisterToManager();
- virtual float GetNumber();
+ virtual double GetNumber();
/** Stop sensing for a while. */
void Suspend();
@@ -136,24 +136,27 @@ public:
/* Python functions: */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions ----->
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsTriggered);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUsePosPulseMode);
- KX_PYMETHOD_DOC(SCA_ISensor,SetUsePosPulseMode);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetUsePosPulseMode);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetFrequency);
- KX_PYMETHOD_DOC(SCA_ISensor,SetFrequency);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetFrequency);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUseNegPulseMode);
- KX_PYMETHOD_DOC(SCA_ISensor,SetUseNegPulseMode);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetUseNegPulseMode);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetInvert);
- KX_PYMETHOD_DOC(SCA_ISensor,SetInvert);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetInvert);
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetLevel);
- KX_PYMETHOD_DOC(SCA_ISensor,SetLevel);
+ KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetLevel);
//<------
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset);
+
+ static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
};
#endif //__SCA_ISENSOR
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
index c2d90c830cf..1c601eded81 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
@@ -117,11 +117,15 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
case KX_JOYSENSORMODE_AXIS:
{
/* what is what!
- m_axisf == 0 == right
+ m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT
m_axisf == 1 == up
m_axisf == 2 == left
m_axisf == 3 == down
- numberof== m_axis -- max 2
+
+ numberof== m_axis (1-4), range is half of JOYAXIS_MAX since
+ it assumes the axis joysticks are axis parirs (0,1), (2,3), etc
+ also note that this starts at 1 where functions its used
+ with expect a zero index.
*/
if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */
@@ -129,18 +133,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
js->cSetPrecision(m_precision);
if (m_bAllEvents) {
- if(js->aAnyAxisIsPositive(m_axis)){
- m_istrig = 1;
- result = true;
- }else{
- if(m_istrig){
- m_istrig = 0;
- result = true;
- }
- }
- }
- else if(m_axisf == 1){
- if(js->aUpAxisIsPositive(m_axis)){
+ if(js->aAxisPairIsPositive(m_axis-1)){ /* use zero based axis index internally */
m_istrig = 1;
result = true;
}else{
@@ -150,8 +143,8 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
}
}
}
- else if(m_axisf == 3){
- if(js->aDownAxisIsPositive(m_axis)){
+ else {
+ if(js->aAxisPairDirectionIsPositive(m_axis-1, m_axisf)){ /* use zero based axis index internally */
m_istrig = 1;
result = true;
}else{
@@ -161,30 +154,28 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
}
}
}
- else if(m_axisf == 2){
- if(js->aLeftAxisIsPositive(m_axis)){
- m_istrig = 1;
- result = true;
- }else{
- if(m_istrig){
- m_istrig = 0;
- result = true;
- }
- }
- }
- else if(m_axisf == 0){
- if(js->aRightAxisIsPositive(m_axis)){
- m_istrig = 1;
+ break;
+ }
+ case KX_JOYSENSORMODE_AXIS_SINGLE:
+ {
+ /* Like KX_JOYSENSORMODE_AXIS but dont pair up axis */
+ if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */
+ return false;
+
+ /* No need for 'm_bAllEvents' check here since were only checking 1 axis */
+ js->cSetPrecision(m_precision);
+ if(js->aAxisIsPositive(m_axis-1)){ /* use zero based axis index internally */
+ m_istrig = 1;
+ result = true;
+ }else{
+ if(m_istrig){
+ m_istrig = 0;
result = true;
- }else{
- if(m_istrig){
- m_istrig = 0;
- result = true;
- }
}
}
break;
}
+
case KX_JOYSENSORMODE_BUTTON:
{
/* what is what!
@@ -275,22 +266,22 @@ bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_JoystickSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_JoystickSensor",
- sizeof(SCA_JoystickSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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
};
@@ -333,48 +324,24 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button),
KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis),
KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat),
- // dummy attributes will just be read-only in _setattr
- // you still need to defined them in _getattr
- KX_PYATTRIBUTE_DUMMY("axisPosition"),
- KX_PYATTRIBUTE_DUMMY("numAxis"),
- KX_PYATTRIBUTE_DUMMY("numButtons"),
- KX_PYATTRIBUTE_DUMMY("numHats"),
- KX_PYATTRIBUTE_DUMMY("connected"),
+ KX_PYATTRIBUTE_RO_FUNCTION("axisValues", SCA_JoystickSensor, pyattr_get_axis_values),
+ KX_PYATTRIBUTE_RO_FUNCTION("axisSingle", SCA_JoystickSensor, pyattr_get_axis_single),
+ KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_JoystickSensor, pyattr_get_num_axis),
+ KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons),
+ KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats),
+ KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected),
+
{ NULL } //Sentinel
};
-PyObject* SCA_JoystickSensor::_getattr(const char *attr) {
- SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
- if (!strcmp(attr, "axisPosition")) {
- if(joy)
- return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21());
- else
- return Py_BuildValue("[iiii]", 0, 0, 0, 0);
- }
- if (!strcmp(attr, "numAxis")) {
- return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
- }
- if (!strcmp(attr, "numButtons")) {
- return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
- }
- if (!strcmp(attr, "numHats")) {
- return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
- }
- if (!strcmp(attr, "connected")) {
- return PyBool_FromLong( joy ? joy->Connected() : 0 );
- }
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor);
+PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr)
+{
+ py_getattro_up(SCA_ISensor);
}
-int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value)
+int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
+ py_setattro_up(SCA_ISensor);
}
@@ -382,7 +349,7 @@ int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value)
const char SCA_JoystickSensor::GetIndex_doc[] =
"getIndex\n"
"\tReturns the joystick index to use.\n";
-PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyGetIndex( ) {
ShowDeprecationWarning("getIndex()", "the index property");
return PyInt_FromLong(m_joyindex);
}
@@ -392,7 +359,7 @@ PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) {
const char SCA_JoystickSensor::SetIndex_doc[] =
"setIndex\n"
"\tSets the joystick index to use.\n";
-PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) {
+PyObject* SCA_JoystickSensor::PySetIndex( PyObject* value ) {
ShowDeprecationWarning("setIndex()", "the index property");
int index = PyInt_AsLong( value ); /* -1 on error, will raise an error in this case */
if (index < 0 || index >= JOYINDEX_MAX) {
@@ -408,7 +375,7 @@ PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) {
const char SCA_JoystickSensor::GetAxis_doc[] =
"getAxis\n"
"\tReturns the current axis this sensor reacts to.\n";
-PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetAxis( ) {
ShowDeprecationWarning("getAxis()", "the axis property");
return Py_BuildValue("[ii]",m_axis, m_axisf);
}
@@ -418,11 +385,11 @@ PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) {
const char SCA_JoystickSensor::SetAxis_doc[] =
"setAxis\n"
"\tSets the current axis this sensor reacts to.\n";
-PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) {
+PyObject* SCA_JoystickSensor::PySetAxis( PyObject* args ) {
ShowDeprecationWarning("setAxis()", "the axis property");
int axis,axisflag;
- if(!PyArg_ParseTuple(args, "ii", &axis, &axisflag)){
+ if(!PyArg_ParseTuple(args, "ii:setAxis", &axis, &axisflag)){
return NULL;
}
m_axis = axis;
@@ -435,13 +402,18 @@ PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) {
const char SCA_JoystickSensor::GetAxisValue_doc[] =
"getAxisValue\n"
"\tReturns a list of the values for the current state of each axis.\n";
-PyObject* SCA_JoystickSensor::PyGetAxisValue( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetAxisValue( ) {
ShowDeprecationWarning("getAxisValue()", "the axisPosition property");
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
- if(joy)
- return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21());
- else
- return Py_BuildValue("[iiii]", 0, 0, 0, 0);
+
+ int axis_index= joy->GetNumberOfAxes();
+ PyObject *list= PyList_New(axis_index);
+
+ while(axis_index--) {
+ PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index)));
+ }
+
+ return list;
}
@@ -449,7 +421,7 @@ PyObject* SCA_JoystickSensor::PyGetAxisValue( PyObject* self) {
const char SCA_JoystickSensor::GetThreshold_doc[] =
"getThreshold\n"
"\tReturns the threshold of the axis.\n";
-PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetThreshold( ) {
ShowDeprecationWarning("getThreshold()", "the threshold property");
return PyInt_FromLong(m_precision);
}
@@ -459,10 +431,10 @@ PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) {
const char SCA_JoystickSensor::SetThreshold_doc[] =
"setThreshold\n"
"\tSets the threshold of the axis.\n";
-PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) {
+PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* args ) {
ShowDeprecationWarning("setThreshold()", "the threshold property");
int thresh;
- if(!PyArg_ParseTuple(args, "i", &thresh)){
+ if(!PyArg_ParseTuple(args, "i:setThreshold", &thresh)){
return NULL;
}
m_precision = thresh;
@@ -473,7 +445,7 @@ PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) {
const char SCA_JoystickSensor::GetButton_doc[] =
"getButton\n"
"\tReturns the current button this sensor is checking.\n";
-PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetButton( ) {
ShowDeprecationWarning("getButton()", "the button property");
return PyInt_FromLong(m_button);
}
@@ -482,7 +454,7 @@ PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) {
const char SCA_JoystickSensor::SetButton_doc[] =
"setButton\n"
"\tSets the button the sensor reacts to.\n";
-PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) {
+PyObject* SCA_JoystickSensor::PySetButton( PyObject* value ) {
ShowDeprecationWarning("setButton()", "the button property");
int button = PyInt_AsLong(value);
if(button==-1 && PyErr_Occurred()) {
@@ -497,16 +469,16 @@ PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) {
const char SCA_JoystickSensor::GetButtonValue_doc[] =
"getButtonValue\n"
"\tReturns a list containing the indicies of the current pressed state of each button.\n";
-PyObject* SCA_JoystickSensor::PyGetButtonValue( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetButtonValue( ) {
ShowDeprecationWarning("getButtonValue()", "getButtonActiveList");
- return PyGetButtonActiveList(self);
+ return PyGetButtonActiveList( );
}
/* get button active list -------------------------------------------------- */
const char SCA_JoystickSensor::GetButtonActiveList_doc[] =
"getButtonActiveList\n"
"\tReturns a list containing the indicies of the button currently pressed.\n";
-PyObject* SCA_JoystickSensor::PyGetButtonActiveList( PyObject* self) {
+PyObject* SCA_JoystickSensor::PyGetButtonActiveList( ) {
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
PyObject *ls = PyList_New(0);
PyObject *value;
@@ -528,12 +500,11 @@ PyObject* SCA_JoystickSensor::PyGetButtonActiveList( PyObject* self) {
const char SCA_JoystickSensor::GetButtonStatus_doc[] =
"getButtonStatus(buttonIndex)\n"
"\tReturns a bool of the current pressed state of the specified button.\n";
-PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args ) {
+PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* args ) {
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
- PyObject *value;
int index;
- if(!PyArg_ParseTuple(args, "i", &index)){
+ if(!PyArg_ParseTuple(args, "i:getButtonStatus", &index)){
return NULL;
}
if(joy && index >= 0 && index < joy->GetNumberOfButtons()) {
@@ -546,7 +517,7 @@ PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args
const char SCA_JoystickSensor::GetHat_doc[] =
"getHat\n"
"\tReturns the current direction of the hat.\n";
-PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyGetHat( ) {
ShowDeprecationWarning("getHat()", "the hat property");
return Py_BuildValue("[ii]",m_hat, m_hatf);
}
@@ -556,10 +527,10 @@ PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) {
const char SCA_JoystickSensor::SetHat_doc[] =
"setHat\n"
"\tSets the hat the sensor reacts to.\n";
-PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) {
+PyObject* SCA_JoystickSensor::PySetHat( PyObject* args ) {
ShowDeprecationWarning("setHat()", "the hat property");
int hat,hatflag;
- if(!PyArg_ParseTuple(args, "ii", &hat, &hatflag)){
+ if(!PyArg_ParseTuple(args, "ii:setHat", &hat, &hatflag)){
return NULL;
}
m_hat = hat;
@@ -572,7 +543,7 @@ PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) {
const char SCA_JoystickSensor::NumberOfAxes_doc[] =
"getNumAxes\n"
"\tReturns the number of axes .\n";
-PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyNumberOfAxes( ) {
ShowDeprecationWarning("getNumAxes()", "the numAxis property");
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
// when the joystick is null their is 0 exis still. dumb but scripters should use isConnected()
@@ -583,7 +554,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) {
const char SCA_JoystickSensor::NumberOfButtons_doc[] =
"getNumButtons\n"
"\tReturns the number of buttons .\n";
-PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyNumberOfButtons( ) {
ShowDeprecationWarning("getNumButtons()", "the numButtons property");
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
@@ -593,7 +564,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) {
const char SCA_JoystickSensor::NumberOfHats_doc[] =
"getNumHats\n"
"\tReturns the number of hats .\n";
-PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyNumberOfHats( ) {
ShowDeprecationWarning("getNumHats()", "the numHats property");
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
@@ -602,8 +573,65 @@ PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) {
const char SCA_JoystickSensor::Connected_doc[] =
"getConnected\n"
"\tReturns True if a joystick is connected at this joysticks index.\n";
-PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) {
+PyObject* SCA_JoystickSensor::PyConnected( ) {
ShowDeprecationWarning("getConnected()", "the connected property");
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
return PyBool_FromLong( joy ? joy->Connected() : 0 );
}
+
+
+PyObject* SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+
+ int axis_index= joy->GetNumberOfAxes();
+ PyObject *list= PyList_New(axis_index);
+
+ while(axis_index--) {
+ PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index)));
+ }
+
+ return list;
+}
+
+PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+
+ if(self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) {
+ PyErr_SetString(PyExc_TypeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type");
+ return NULL;
+ }
+
+ return PyInt_FromLong(joy->GetAxisPosition(self->m_axis-1));
+}
+
+PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+ return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
+}
+
+PyObject* SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+ return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
+}
+
+PyObject* SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+ return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
+}
+
+PyObject* SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
+ SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
+ return PyBool_FromLong( joy ? joy->Connected() : 0 );
+}
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h
index 49d220c056d..cf3e7e74414 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.h
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h
@@ -93,6 +93,7 @@ class SCA_JoystickSensor :public SCA_ISensor
KX_JOYSENSORMODE_AXIS,
KX_JOYSENSORMODE_BUTTON,
KX_JOYSENSORMODE_HAT,
+ KX_JOYSENSORMODE_AXIS_SINGLE,
KX_JOYSENSORMODE_MAX
};
bool isValid(KX_JOYSENSORMODE);
@@ -121,8 +122,8 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
/* Joystick Index */
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex);
@@ -148,6 +149,14 @@ public:
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats);
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected);
+ static PyObject* pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+
+
/* attribute check */
static int CheckAxis(void *self, const PyAttributeDef*)
{
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
index ca30382b8c0..c946156283f 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
@@ -352,148 +352,7 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex)
}
}
-
-/**
- * Determine whether this character can be printed. We cannot use
- * the library functions here, because we need to test our own
- * keycodes. */
-bool SCA_KeyboardSensor::IsPrintable(int keyIndex)
-{
- /* only print
- * - numerals: KX_ZEROKEY to KX_NINEKEY
- * - alphas: KX_AKEY to KX_ZKEY.
- * - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY,
- * KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY,
- * KX_PAD2 to KX_PADPLUSKEY
- * - delete and backspace: also printable in the sense that they modify
- * the string
- * - retkey: should this be printable?
- * - virgule: prints a space... don't know which key that's supposed
- * to be...
- */
- if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
- && (keyIndex <= SCA_IInputDevice::KX_NINEKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_AKEY)
- && (keyIndex <= SCA_IInputDevice::KX_ZKEY))
- || (keyIndex == SCA_IInputDevice::KX_SPACEKEY)
-/* || (keyIndex == KX_RETKEY) */
- || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY)
- || (keyIndex == SCA_IInputDevice::KX_TABKEY)
- || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY)
- && (keyIndex <= SCA_IInputDevice::KX_PERIODKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
- && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_PAD2)
- && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY))
- || (keyIndex == SCA_IInputDevice::KX_DELKEY)
- || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY)
- )
- {
- return true;
- } else {
- return false;
- }
-}
-
-// this code looks ugly, please use an ordinary hashtable
-
-char SCA_KeyboardSensor::ToCharacter(int keyIndex, bool shifted)
-{
- /* numerals */
- if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
- && (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) {
- if (shifted) {
- char numshift[] = ")!@#$%^&*(";
- return numshift[keyIndex - '0'];
- } else {
- return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0';
- }
- }
-
- /* letters... always lowercase... is that desirable? */
- if ( (keyIndex >= SCA_IInputDevice::KX_AKEY)
- && (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) {
- if (shifted) {
- return keyIndex - SCA_IInputDevice::KX_AKEY + 'A';
- } else {
- return keyIndex - SCA_IInputDevice::KX_AKEY + 'a';
- }
- }
-
- if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) {
- return ' ';
- }
-
-/* || (keyIndex == SCA_IInputDevice::KX_RETKEY) */
-
- if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) {
- return '*';
- }
-
- if (keyIndex == SCA_IInputDevice::KX_TABKEY) {
- return '\t';
- }
-
- /* comma to period */
- char commatoperiod[] = ",-.";
- char commatoperiodshifted[] = "<_>";
- if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) {
- if (shifted) {
- return commatoperiodshifted[0];
- } else {
- return commatoperiod[0];
- }
- }
- if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) {
- if (shifted) {
- return commatoperiodshifted[1];
- } else {
- return commatoperiod[1];
- }
- }
- if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) {
- if (shifted) {
- return commatoperiodshifted[2];
- } else {
- return commatoperiod[2];
- }
- }
-
- /* semicolon to rightbracket */
- char semicolontorightbracket[] = ";\'` /\\=[]";
- char semicolontorightbracketshifted[] = ":\"~ \?|+{}";
- if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
- && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) {
- if (shifted) {
- return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
- } else {
- return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
- }
- }
- /* keypad2 to padplus */
- char pad2topadplus[] = "246813579. 0- +";
- if ((keyIndex >= SCA_IInputDevice::KX_PAD2)
- && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) {
- return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2];
- }
-
- return '!';
-}
-
-/**
- * Tests whether this is a delete key.
- */
-bool SCA_KeyboardSensor::IsDelete(int keyIndex)
-{
- if ( (keyIndex == SCA_IInputDevice::KX_DELKEY)
- || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) {
- return true;
- } else {
- return false;
- }
-}
-
/**
* Tests whether shift is pressed
*/
@@ -553,7 +412,7 @@ void SCA_KeyboardSensor::LogKeystrokes(void)
const char SCA_KeyboardSensor::GetKey_doc[] =
"getKey()\n"
"\tReturn the code of the key this sensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetKey(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetKey()
{
ShowDeprecationWarning("getKey()", "the key property");
return PyInt_FromLong(m_hotkey);
@@ -564,12 +423,12 @@ const char SCA_KeyboardSensor::SetKey_doc[] =
"setKey(keycode)\n"
"\t- keycode: any code from GameKeys\n"
"\tSet the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetKey(PyObject* args)
{
ShowDeprecationWarning("setKey()", "the key property");
int keyCode;
- if(!PyArg_ParseTuple(args, "i", &keyCode)) {
+ if(!PyArg_ParseTuple(args, "i:setKey", &keyCode)) {
return NULL;
}
@@ -585,7 +444,7 @@ const char SCA_KeyboardSensor::GetHold1_doc[] =
"getHold1()\n"
"\tReturn the code of the first key modifier to the key this \n"
"\tsensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetHold1(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetHold1()
{
ShowDeprecationWarning("getHold1()", "the hold1 property");
return PyInt_FromLong(m_qual);
@@ -596,12 +455,12 @@ const char SCA_KeyboardSensor::SetHold1_doc[] =
"setHold1(keycode)\n"
"\t- keycode: any code from GameKeys\n"
"\tSet the first modifier to the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* args)
{
ShowDeprecationWarning("setHold1()", "the hold1 property");
int keyCode;
- if(!PyArg_ParseTuple(args, "i", &keyCode)) {
+ if(!PyArg_ParseTuple(args, "i:setHold1", &keyCode)) {
return NULL;
}
@@ -617,7 +476,7 @@ const char SCA_KeyboardSensor::GetHold2_doc[] =
"getHold2()\n"
"\tReturn the code of the second key modifier to the key this \n"
"\tsensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetHold2(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetHold2()
{
ShowDeprecationWarning("getHold2()", "the hold2 property");
return PyInt_FromLong(m_qual2);
@@ -628,12 +487,12 @@ const char SCA_KeyboardSensor::SetHold2_doc[] =
"setHold2(keycode)\n"
"\t- keycode: any code from GameKeys\n"
"\tSet the first modifier to the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* args)
{
ShowDeprecationWarning("setHold2()", "the hold2 property");
int keyCode;
- if(!PyArg_ParseTuple(args, "i", &keyCode)) {
+ if(!PyArg_ParseTuple(args, "i:setHold2", &keyCode)) {
return NULL;
}
@@ -649,9 +508,9 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] =
"getPressedKeys()\n"
"\tGet a list of pressed keys that have either been pressed, or just released this frame.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetPressedKeys()
{
- ShowDeprecationWarning("getPressedKeys()", "getEventList()");
+ ShowDeprecationWarning("getPressedKeys()", "events");
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
@@ -669,20 +528,19 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, P
if ((inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
|| (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED))
{
- if (index < num)
- {
- PyObject* keypair = PyList_New(2);
- PyList_SetItem(keypair,0,PyInt_FromLong(i));
- PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
- PyList_SetItem(resultlist,index,keypair);
- index++;
- }
+ 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(resultlist,index,keypair);
+ index++;
+
+ if (index >= num) /* should not happen */
+ break;
}
- }
- if (index>0) return resultlist;
+ }
}
- Py_RETURN_NONE;
+ return resultlist;
}
@@ -691,11 +549,11 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] =
"getCurrentlyPressedKeys()\n"
"\tGet a list of keys that are currently pressed.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys()
{
-ShowDeprecationWarning("getCurrentlyPressedKeys()", "getEventList()");
+ ShowDeprecationWarning("getCurrentlyPressedKeys()", "events");
-SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
int num = inputdev->GetNumActiveEvents();
PyObject* resultlist = PyList_New(num);
@@ -710,67 +568,43 @@ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
if ( (inevent.m_status == SCA_InputEvent::KX_ACTIVE)
|| (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED))
{
- if (index < num)
- {
- PyObject* keypair = PyList_New(2);
- PyList_SetItem(keypair,0,PyInt_FromLong(i));
- PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
- PyList_SetItem(resultlist,index,keypair);
- index++;
- }
+ 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(resultlist,index,keypair);
+ index++;
+
+ if (index >= num) /* should never happen */
+ break;
}
}
-
- /* why?*/
- if (index > 0) return resultlist;
}
- Py_RETURN_NONE;
-}
-//<---- Deprecated
-
-KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList,
-"getEventList()\n"
-"\tGet the list of the keyboard events in this frame.\n")
-{
- SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
-
- PyObject* resultlist = PyList_New(0);
-
- for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++)
- {
- const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
- if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
- {
- PyObject* keypair = PyList_New(2);
- PyList_SetItem(keypair,0,PyInt_FromLong(i));
- PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
- PyList_Append(resultlist,keypair);
- }
- }
return resultlist;
}
+//<---- Deprecated
+
KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
"getKeyStatus(keycode)\n"
"\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
{
- if (PyInt_Check(value))
- {
- int keycode = PyInt_AsLong(value);
-
- if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
- || (keycode > SCA_IInputDevice::KX_ENDKEY)){
- PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!");
- return NULL;
- }
-
- SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
- const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
- return PyInt_FromLong(inevent.m_status);
+ if (!PyInt_Check(value)) {
+ PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int");
+ return NULL;
}
- Py_RETURN_NONE;
+ int keycode = PyInt_AsLong(value);
+
+ if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
+ || (keycode > SCA_IInputDevice::KX_ENDKEY)){
+ PyErr_SetString(PyExc_AttributeError, "sensor.getKeyStatus(int): Keyboard Sensor, invalid keycode specified!");
+ return NULL;
+ }
+
+ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
+ const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
+ return PyInt_FromLong(inevent.m_status);
}
/* ------------------------------------------------------------------------- */
@@ -778,22 +612,22 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
/* ------------------------------------------------------------------------- */
PyTypeObject SCA_KeyboardSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_KeyboardSensor",
- sizeof(SCA_KeyboardSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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[] = {
@@ -806,21 +640,21 @@ PyParentObject SCA_KeyboardSensor::Parents[] = {
PyMethodDef SCA_KeyboardSensor::Methods[] = {
//Deprecated functions ------>
- {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_VARARGS, (PY_METHODCHAR)GetKey_doc},
+ {"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_VARARGS, (PY_METHODCHAR)GetHold1_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_VARARGS, (PY_METHODCHAR)GetHold2_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_VARARGS, (PY_METHODCHAR)GetPressedKeys_doc},
- {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
+ {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetPressedKeys_doc},
+ {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
//<----- Deprecated
- KX_PYMETHODTABLE_NOARGS(SCA_KeyboardSensor, getEventList),
KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus),
{NULL,NULL} //Sentinel
};
PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
+ KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_KeyboardSensor, pyattr_get_events),
KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys),
KX_PYATTRIBUTE_INT_RW("key",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_hotkey),
KX_PYATTRIBUTE_SHORT_RW("hold1",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual),
@@ -831,18 +665,184 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
};
PyObject*
-SCA_KeyboardSensor::_getattr(const char *attr)
+SCA_KeyboardSensor::py_getattro(PyObject *attr)
{
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor);
+ py_getattro_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();
+
+ PyObject* resultlist = PyList_New(0);
+
+ for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++)
+ {
+ const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
+ if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
+ {
+ PyObject* keypair = PyList_New(2);
+ PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
+ PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
+ PyList_Append(resultlist,keypair);
+ }
+ }
+ return resultlist;
}
-int SCA_KeyboardSensor::_setattr(const char *attr, PyObject *value)
+
+/* Accessed from python */
+
+// this code looks ugly, please use an ordinary hashtable
+
+char ToCharacter(int keyIndex, bool shifted)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
+ /* numerals */
+ if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) {
+ if (shifted) {
+ char numshift[] = ")!@#$%^&*(";
+ return numshift[keyIndex - '0'];
+ } else {
+ return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0';
+ }
+ }
+
+ /* letters... always lowercase... is that desirable? */
+ if ( (keyIndex >= SCA_IInputDevice::KX_AKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) {
+ if (shifted) {
+ return keyIndex - SCA_IInputDevice::KX_AKEY + 'A';
+ } else {
+ return keyIndex - SCA_IInputDevice::KX_AKEY + 'a';
+ }
+ }
+
+ if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) {
+ return ' ';
+ }
+ if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) {
+ return '\n';
+ }
+
+
+ if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) {
+ return '*';
+ }
+
+ if (keyIndex == SCA_IInputDevice::KX_TABKEY) {
+ return '\t';
+ }
+
+ /* comma to period */
+ char commatoperiod[] = ",-.";
+ char commatoperiodshifted[] = "<_>";
+ if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) {
+ if (shifted) {
+ return commatoperiodshifted[0];
+ } else {
+ return commatoperiod[0];
+ }
+ }
+ if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) {
+ if (shifted) {
+ return commatoperiodshifted[1];
+ } else {
+ return commatoperiod[1];
+ }
+ }
+ if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) {
+ if (shifted) {
+ return commatoperiodshifted[2];
+ } else {
+ return commatoperiod[2];
+ }
+ }
+
+ /* semicolon to rightbracket */
+ char semicolontorightbracket[] = ";\'`/\\=[]";
+ char semicolontorightbracketshifted[] = ":\"~\?|+{}";
+ if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) {
+ if (shifted) {
+ return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
+ } else {
+ return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
+ }
+ }
+
+ /* keypad2 to padplus */
+ char pad2topadplus[] = "246813579. 0- +";
+ if ((keyIndex >= SCA_IInputDevice::KX_PAD2)
+ && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) {
+ return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2];
+ }
+
+ return '!';
+}
+
+
+
+/**
+ * Determine whether this character can be printed. We cannot use
+ * the library functions here, because we need to test our own
+ * keycodes. */
+bool IsPrintable(int keyIndex)
+{
+ /* only print
+ * - numerals: KX_ZEROKEY to KX_NINEKEY
+ * - alphas: KX_AKEY to KX_ZKEY.
+ * - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY,
+ * KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY,
+ * KX_PAD2 to KX_PADPLUSKEY
+ * - delete and backspace: also printable in the sense that they modify
+ * the string
+ * - retkey: should this be printable?
+ * - virgule: prints a space... don't know which key that's supposed
+ * to be...
+ */
+ if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_NINEKEY))
+ || ((keyIndex >= SCA_IInputDevice::KX_AKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_ZKEY))
+ || (keyIndex == SCA_IInputDevice::KX_SPACEKEY)
+ || (keyIndex == SCA_IInputDevice::KX_RETKEY)
+ || (keyIndex == SCA_IInputDevice::KX_PADENTER)
+ || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY)
+ || (keyIndex == SCA_IInputDevice::KX_TABKEY)
+ || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_PERIODKEY))
+ || ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
+ && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY))
+ || ((keyIndex >= SCA_IInputDevice::KX_PAD2)
+ && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY))
+ || (keyIndex == SCA_IInputDevice::KX_DELKEY)
+ || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY)
+ )
+ {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Tests whether this is a delete key.
+ */
+bool IsDelete(int keyIndex)
+{
+ if ( (keyIndex == SCA_IInputDevice::KX_DELKEY)
+ || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) {
+ return true;
+ } else {
+ return false;
+ }
}
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
index bc2f86327a5..073b3e6dbe0 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
@@ -82,22 +82,6 @@ class SCA_KeyboardSensor : public SCA_ISensor
void AddToTargetProp(int keyIndex);
/**
- * Determine whether this character can be printed. We cannot use
- * the library functions here, because we need to test our own
- * keycodes. */
- bool IsPrintable(int keyIndex);
-
- /**
- * Transform keycodes to something printable.
- */
- char ToCharacter(int keyIndex, bool shifted);
-
- /**
- * Tests whether this is a delete key.
- */
- bool IsDelete(int keyIndex);
-
- /**
* Tests whether shift is pressed.
*/
bool IsShifted(void);
@@ -126,33 +110,55 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions ----->
/** 1. GetKey : check which key this sensor looks at */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetKey);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetKey);
/** 2. SetKey: change the key to look at */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetKey);
+ KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetKey);
/** 3. GetHold1 : set the first bucky bit */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetHold1);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetHold1);
/** 4. SetHold1: change the first bucky bit */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetHold1);
+ KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetHold1);
/** 5. GetHold2 : set the second bucky bit */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetHold2);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetHold2);
/** 6. SetHold2: change the second bucky bit */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetHold2);
+ KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetHold2);
/** 9. GetPressedKeys: */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetPressedKeys);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetPressedKeys);
/** 9. GetCurrrentlyPressedKeys: */
- KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetCurrentlyPressedKeys);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetCurrentlyPressedKeys);
// <------
// KeyEvents:
KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList);
// KeyStatus:
KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus);
+
+ static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
};
+
+/**
+ * Transform keycodes to something printable.
+ */
+char ToCharacter(int keyIndex, bool shifted);
+
+/**
+ * Determine whether this character can be printed. We cannot use
+ * the library functions here, because we need to test our own
+ * keycodes. */
+bool IsPrintable(int keyIndex);
+
+/**
+ * Tests whether this is a delete key.
+ */
+bool IsDelete(int keyIndex);
+
+
#endif //__KX_KEYBOARDSENSOR
+
+
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
index 57535b29f32..4dbeb156e63 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
@@ -102,7 +102,7 @@ int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*)
default:
; /* ignore, no hotkey */
}
- // return value is used in _setattr(),
+ // return value is used in py_setattro(),
// 0=attribute checked ok (see Attributes array definition)
return 0;
}
@@ -252,9 +252,7 @@ const char SCA_MouseSensor::GetXPosition_doc[] =
"\tReturns the x-coordinate of the mouse sensor, in frame coordinates.\n"
"\tThe lower-left corner is the origin. The coordinate is given in\n"
"\tpixels\n";
-PyObject* SCA_MouseSensor::PyGetXPosition(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+PyObject* SCA_MouseSensor::PyGetXPosition() {
ShowDeprecationWarning("getXPosition()", "the position property");
return PyInt_FromLong(m_x);
}
@@ -265,9 +263,7 @@ const char SCA_MouseSensor::GetYPosition_doc[] =
"\tReturns the y-coordinate of the mouse sensor, in frame coordinates.\n"
"\tThe lower-left corner is the origin. The coordinate is given in\n"
"\tpixels\n";
-PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+PyObject* SCA_MouseSensor::PyGetYPosition() {
ShowDeprecationWarning("getYPosition()", "the position property");
return PyInt_FromLong(m_y);
}
@@ -275,7 +271,7 @@ PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self,
KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
"getButtonStatus(button)\n"
-"\tGet the given button's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
+"\tGet the given button's status (KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED).\n")
{
if (PyInt_Check(value))
{
@@ -283,7 +279,7 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
if ((button < SCA_IInputDevice::KX_LEFTMOUSE)
|| (button > SCA_IInputDevice::KX_RIGHTMOUSE)){
- PyErr_SetString(PyExc_ValueError, "invalid button specified!");
+ PyErr_SetString(PyExc_ValueError, "sensor.getButtonStatus(int): Mouse Sensor, invalid button specified!");
return NULL;
}
@@ -300,22 +296,22 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
/* ------------------------------------------------------------------------- */
PyTypeObject SCA_MouseSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_MouseSensor",
- sizeof(SCA_MouseSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_MouseSensor::Parents[] = {
@@ -341,20 +337,14 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_MouseSensor::_getattr(const char *attr)
+PyObject* SCA_MouseSensor::py_getattro(PyObject *attr)
{
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor);
+ py_getattro_up(SCA_ISensor);
}
-int SCA_MouseSensor::_setattr(const char *attr, PyObject *value)
+int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
+ py_setattro_up(SCA_ISensor);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h
index 30b43fe53cc..2d1c496029d 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.h
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.h
@@ -109,14 +109,14 @@ class SCA_MouseSensor : public SCA_ISensor
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions ----->
/* read x-coordinate */
- KX_PYMETHOD_DOC(SCA_MouseSensor,GetXPosition);
+ KX_PYMETHOD_DOC_NOARGS(SCA_MouseSensor,GetXPosition);
/* read y-coordinate */
- KX_PYMETHOD_DOC(SCA_MouseSensor,GetYPosition);
+ KX_PYMETHOD_DOC_NOARGS(SCA_MouseSensor,GetYPosition);
//<----- deprecated
// get button status
diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp
index 18426d75582..703c9c1bbaf 100644
--- a/source/gameengine/GameLogic/SCA_NANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_NANDController.cpp
@@ -107,22 +107,22 @@ CValue* SCA_NANDController::GetReplica()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_NANDController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_NANDController",
- sizeof(SCA_NANDController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_NANDController::Parents[] = {
@@ -141,8 +141,8 @@ PyAttributeDef SCA_NANDController::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_NANDController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_NANDController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_NANDController.h b/source/gameengine/GameLogic/SCA_NANDController.h
index d88504cfc0d..11600914a1a 100644
--- a/source/gameengine/GameLogic/SCA_NANDController.h
+++ b/source/gameengine/GameLogic/SCA_NANDController.h
@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp
index 1de6a641c3d..06acae5a81a 100644
--- a/source/gameengine/GameLogic/SCA_NORController.cpp
+++ b/source/gameengine/GameLogic/SCA_NORController.cpp
@@ -107,22 +107,22 @@ CValue* SCA_NORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_NORController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_NORController",
- sizeof(SCA_NORController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_NORController::Parents[] = {
@@ -141,8 +141,8 @@ PyAttributeDef SCA_NORController::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_NORController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_NORController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_NORController.h b/source/gameengine/GameLogic/SCA_NORController.h
index 45b639f3f3f..fc814e28d37 100644
--- a/source/gameengine/GameLogic/SCA_NORController.h
+++ b/source/gameengine/GameLogic/SCA_NORController.h
@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp
index 61fbc889d90..319ff04f776 100644
--- a/source/gameengine/GameLogic/SCA_ORController.cpp
+++ b/source/gameengine/GameLogic/SCA_ORController.cpp
@@ -99,22 +99,22 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ORController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_ORController",
- sizeof(SCA_ORController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_ORController::Parents[] = {
@@ -134,8 +134,8 @@ PyAttributeDef SCA_ORController::Attributes[] = {
};
-PyObject* SCA_ORController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_ORController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ORController.h b/source/gameengine/GameLogic/SCA_ORController.h
index 9a6e9e75022..fdc81486e74 100644
--- a/source/gameengine/GameLogic/SCA_ORController.h
+++ b/source/gameengine/GameLogic/SCA_ORController.h
@@ -49,7 +49,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
#endif //__KX_ORCONTROLLER
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
index c9ace081bae..c4db723ee89 100644
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
@@ -77,11 +77,25 @@ bool SCA_PropertyActuator::Update()
CParser parser;
parser.SetContext( propowner->AddRef());
- CExpression* userexpr = parser.ProcessText(m_exprtxt);
- if (userexpr)
+ CExpression* userexpr= NULL;
+
+ if (m_type==KX_ACT_PROP_TOGGLE)
{
-
-
+ /* dont use */
+ CValue* newval;
+ CValue* oldprop = propowner->GetProperty(m_propname);
+ if (oldprop)
+ {
+ newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false);
+ oldprop->SetValue(newval);
+ } else
+ { /* as not been assigned, evaluate as false, so assign true */
+ newval = new CBoolValue(true);
+ propowner->SetProperty(m_propname,newval);
+ }
+ newval->Release();
+ }
+ else if ((userexpr = parser.ProcessText(m_exprtxt))) {
switch (m_type)
{
@@ -135,6 +149,7 @@ bool SCA_PropertyActuator::Update()
}
break;
}
+ /* case KX_ACT_PROP_TOGGLE: */ /* accounted for above, no need for userexpr */
default:
{
@@ -218,22 +233,22 @@ void SCA_PropertyActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_PropertyActuator::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_PropertyActuator",
- sizeof(SCA_PropertyActuator),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_PropertyActuator::Parents[] = {
@@ -260,18 +275,12 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_PropertyActuator::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_IActuator);
+PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IActuator);
}
-int SCA_PropertyActuator::_setattr(const char *attr, PyObject *value) {
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_IActuator::_setattr(attr, value);
+int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) {
+ py_setattro_up(SCA_IActuator);
}
/* 1. setProperty */
@@ -280,12 +289,12 @@ const char SCA_PropertyActuator::SetProperty_doc[] =
"\t- name: string\n"
"\tSet the property on which to operate. If there is no property\n"
"\tof this name, the call is ignored.\n";
-PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertyActuator::PySetProperty(PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("setProperty()", "the 'property' property");
/* Check whether the name exists first ! */
char *nameArg;
- if (!PyArg_ParseTuple(args, "s", &nameArg)) {
+ if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) {
return NULL;
}
@@ -305,7 +314,7 @@ PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, Py
const char SCA_PropertyActuator::GetProperty_doc[] =
"getProperty(name)\n"
"\tReturn the property on which the actuator operates.\n";
-PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("getProperty()", "the 'property' property");
return PyString_FromString(m_propname);
@@ -318,11 +327,11 @@ const char SCA_PropertyActuator::SetValue_doc[] =
"\tSet the value with which the actuator operates. If the value\n"
"\tis not compatible with the type of the property, the subsequent\n"
"\t action is ignored.\n";
-PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertyActuator::PySetValue(PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("setValue()", "the value property");
char *valArg;
- if(!PyArg_ParseTuple(args, "s", &valArg)) {
+ if(!PyArg_ParseTuple(args, "s:setValue", &valArg)) {
return NULL;
}
@@ -335,7 +344,7 @@ PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObj
const char SCA_PropertyActuator::GetValue_doc[] =
"getValue()\n"
"\tReturns the value with which the actuator operates.\n";
-PyObject* SCA_PropertyActuator::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertyActuator::PyGetValue(PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("getValue()", "the value property");
return PyString_FromString(m_exprtxt);
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h
index 444d9285796..bb841cf88ad 100644
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.h
+++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h
@@ -43,6 +43,7 @@ class SCA_PropertyActuator : public SCA_IActuator
KX_ACT_PROP_ASSIGN,
KX_ACT_PROP_ADD,
KX_ACT_PROP_COPY,
+ KX_ACT_PROP_TOGGLE,
KX_ACT_PROP_MAX
};
@@ -85,8 +86,8 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
// python wrapped methods
KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty);
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
index d683c8bb3e7..de8a9fcf03e 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
@@ -306,22 +306,22 @@ int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_PropertySensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_PropertySensor",
- sizeof(SCA_PropertySensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_PropertySensor::Parents[] = {
@@ -334,11 +334,11 @@ PyParentObject SCA_PropertySensor::Parents[] = {
PyMethodDef SCA_PropertySensor::Methods[] = {
//Deprecated functions ------>
- {"getType", (PyCFunction) SCA_PropertySensor::sPyGetType, METH_VARARGS, (PY_METHODCHAR)GetType_doc},
+ {"getType", (PyCFunction) SCA_PropertySensor::sPyGetType, METH_NOARGS, (PY_METHODCHAR)GetType_doc},
{"setType", (PyCFunction) SCA_PropertySensor::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc},
- {"getProperty", (PyCFunction) SCA_PropertySensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
+ {"getProperty", (PyCFunction) SCA_PropertySensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
{"setProperty", (PyCFunction) SCA_PropertySensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
- {"getValue", (PyCFunction) SCA_PropertySensor::sPyGetValue, METH_VARARGS, (PY_METHODCHAR)GetValue_doc},
+ {"getValue", (PyCFunction) SCA_PropertySensor::sPyGetValue, METH_NOARGS, (PY_METHODCHAR)GetValue_doc},
{"setValue", (PyCFunction) SCA_PropertySensor::sPySetValue, METH_VARARGS, (PY_METHODCHAR)SetValue_doc},
//<----- Deprecated
{NULL,NULL} //Sentinel
@@ -352,25 +352,19 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = {
};
-PyObject* SCA_PropertySensor::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- _getattr_up(SCA_ISensor); /* implicit return! */
+PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_ISensor);
}
-int SCA_PropertySensor::_setattr(const char *attr, PyObject *value) {
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- return SCA_ISensor::_setattr(attr, value);
+int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) {
+ py_setattro_up(SCA_ISensor);
}
/* 1. getType */
const char SCA_PropertySensor::GetType_doc[] =
"getType()\n"
"\tReturns the type of check this sensor performs.\n";
-PyObject* SCA_PropertySensor::PyGetType(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PyGetType()
{
ShowDeprecationWarning("getType()", "the type property");
return PyInt_FromLong(m_checktype);
@@ -383,12 +377,12 @@ const char SCA_PropertySensor::SetType_doc[] =
"\t KX_PROPSENSOR_INTERVAL, KX_PROPSENSOR_CHANGED,\n"
"\t or KX_PROPSENSOR_EXPRESSION.\n"
"\tSet the type of check to perform.\n";
-PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PySetType(PyObject* args)
{
ShowDeprecationWarning("setType()", "the type property");
int typeArg;
- if (!PyArg_ParseTuple(args, "i", &typeArg)) {
+ if (!PyArg_ParseTuple(args, "i:setType", &typeArg)) {
return NULL;
}
@@ -404,7 +398,7 @@ PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject
const char SCA_PropertySensor::GetProperty_doc[] =
"getProperty()\n"
"\tReturn the property with which the sensor operates.\n";
-PyObject* SCA_PropertySensor::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PyGetProperty()
{
ShowDeprecationWarning("getProperty()", "the 'property' property");
return PyString_FromString(m_checkpropname);
@@ -416,14 +410,14 @@ const char SCA_PropertySensor::SetProperty_doc[] =
"\t- name: string\n"
"\tSets the property with which to operate. If there is no property\n"
"\tof this name, the call is ignored.\n";
-PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PySetProperty(PyObject* args)
{
ShowDeprecationWarning("setProperty()", "the 'property' property");
/* We should query whether the name exists. Or should we create a prop */
/* on the fly? */
char *propNameArg = NULL;
- if (!PyArg_ParseTuple(args, "s", &propNameArg)) {
+ if (!PyArg_ParseTuple(args, "s:setProperty", &propNameArg)) {
return NULL;
}
@@ -441,7 +435,7 @@ PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyOb
const char SCA_PropertySensor::GetValue_doc[] =
"getValue()\n"
"\tReturns the value with which the sensor operates.\n";
-PyObject* SCA_PropertySensor::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PyGetValue()
{
ShowDeprecationWarning("getValue()", "the value property");
return PyString_FromString(m_checkpropval);
@@ -454,19 +448,19 @@ const char SCA_PropertySensor::SetValue_doc[] =
"\tSet the value with which the sensor operates. If the value\n"
"\tis not compatible with the type of the property, the subsequent\n"
"\t action is ignored.\n";
-PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_PropertySensor::PySetValue(PyObject* args)
{
ShowDeprecationWarning("setValue()", "the value property");
/* Here, we need to check whether the value is 'valid' for this property.*/
/* We know that the property exists, or is NULL. */
char *propValArg = NULL;
- if(!PyArg_ParseTuple(args, "s", &propValArg)) {
+ if(!PyArg_ParseTuple(args, "s:setValue", &propValArg)) {
return NULL;
}
STR_String oldval = m_checkpropval;
m_checkpropval = propValArg;
- if (validValueForProperty(self, NULL)) {
+ if (validValueForProperty(m_proxy, NULL)) {
m_checkpropval = oldval;
return NULL;
}
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h
index 2594e3fca9d..e1e378a973c 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.h
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.h
@@ -89,21 +89,21 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
/* 1. getType */
- KX_PYMETHOD_DOC(SCA_PropertySensor,GetType);
+ KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetType);
/* 2. setType */
- KX_PYMETHOD_DOC(SCA_PropertySensor,SetType);
+ KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetType);
/* 3. setProperty */
- KX_PYMETHOD_DOC(SCA_PropertySensor,SetProperty);
+ KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetProperty);
/* 4. getProperty */
- KX_PYMETHOD_DOC(SCA_PropertySensor,GetProperty);
+ KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetProperty);
/* 5. getValue */
- KX_PYMETHOD_DOC(SCA_PropertySensor,GetValue);
+ KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetValue);
/* 6. setValue */
- KX_PYMETHOD_DOC(SCA_PropertySensor,SetValue);
+ KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetValue);
/**
* Test whether this is a sensible value (type check)
*/
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index c75e36acab2..b8052555528 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -154,10 +154,10 @@ int SCA_PythonController::IsTriggered(class SCA_ISensor* sensor)
static const char* sPyGetCurrentController__doc__;
#endif
-
-PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self)
+/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */
+PyObject* SCA_PythonController::sPyGetCurrentController(PyObject *self)
{
- return m_sCurrentController->AddRef();
+ return m_sCurrentController->GetProxy();
}
SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
@@ -176,10 +176,10 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
}
}
}
- else {
- /* Expecting an actuator type */
+ else if (BGE_PROXY_CHECK_TYPE(value)) {
+ PyObjectPlus *value_plus= BGE_PROXY_REF(value); /* Expecting an actuator type */ // XXX TODO - CHECK TYPE
for(it = lacts.begin(); it!= lacts.end(); it++) {
- if( static_cast<SCA_IActuator*>(value) == (*it) ) {
+ if( static_cast<SCA_IActuator*>(value_plus) == (*it) ) {
return *it;
}
}
@@ -187,7 +187,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
/* set the exception */
PyObject *value_str = PyObject_Repr(value); /* new ref */
- PyErr_Format(PyExc_ValueError, "'%s' not in this controllers actuator list", PyString_AsString(value_str));
+ PyErr_Format(PyExc_ValueError, "'%s' not in this python controllers actuator list", PyString_AsString(value_str));
Py_DECREF(value_str);
return false;
@@ -197,15 +197,12 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
static const char* sPyAddActiveActuator__doc__;
#endif
-PyObject* SCA_PythonController::sPyAddActiveActuator(
-
- PyObject* self,
- PyObject* args)
+/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */
+PyObject* SCA_PythonController::sPyAddActiveActuator(PyObject* self, PyObject* args)
{
-
PyObject* ob1;
int activate;
- if (!PyArg_ParseTuple(args, "Oi", &ob1,&activate))
+ if (!PyArg_ParseTuple(args, "Oi:addActiveActuator", &ob1,&activate))
return NULL;
SCA_IActuator* actu = LinkedActuatorFromPy(ob1);
@@ -224,22 +221,22 @@ const char* SCA_PythonController::sPyAddActiveActuator__doc__= "addActiveActuato
const char SCA_PythonController::GetActuators_doc[] = "getActuator";
PyTypeObject SCA_PythonController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_PythonController",
- sizeof(SCA_PythonController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_PythonController::Parents[] = {
@@ -265,6 +262,8 @@ PyMethodDef SCA_PythonController::Methods[] = {
};
PyAttributeDef SCA_PythonController::Attributes[] = {
+ KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_PythonController, pyattr_get_state),
+ KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script),
{ NULL } //Sentinel
};
@@ -298,7 +297,7 @@ bool SCA_PythonController::Compile()
* their user count. Not to mention holding references to wrapped data.
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
- PySys_SetObject( (char *)"last_traceback", Py_None);
+ PySys_SetObject( (char *)"last_traceback", NULL);
PyErr_Clear(); /* just to be sure */
return false;
@@ -356,7 +355,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
* their user count. Not to mention holding references to wrapped data.
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
- PySys_SetObject( (char *)"last_traceback", Py_None);
+ PySys_SetObject( (char *)"last_traceback", NULL);
PyErr_Clear(); /* just to be sure */
//PyRun_SimpleString(m_scriptText.Ptr());
@@ -372,41 +371,17 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
-PyObject* SCA_PythonController::_getattr(const char *attr)
+PyObject* SCA_PythonController::py_getattro(PyObject *attr)
{
- if (!strcmp(attr,"state")) {
- return PyInt_FromLong(m_statemask);
- }
- if (!strcmp(attr,"script")) {
- return PyString_FromString(m_scriptText);
- }
- _getattr_up(SCA_IController);
+ py_getattro_up(SCA_IController);
}
-int SCA_PythonController::_setattr(const char *attr, PyObject *value)
+int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value)
{
- if (!strcmp(attr,"state")) {
- PyErr_SetString(PyExc_AttributeError, "state is read only");
- return 1;
- }
- if (!strcmp(attr,"script")) {
- char *scriptArg = PyString_AsString(value);
-
- if (scriptArg==NULL) {
- PyErr_SetString(PyExc_TypeError, "expected a string (script name)");
- return -1;
- }
-
- /* set scripttext sets m_bModified to true,
- so next time the script is needed, a reparse into byte code is done */
- this->SetScriptText(scriptArg);
-
- return 1;
- }
- return SCA_IController::_setattr(attr, value);
+ py_setattro_up(SCA_IController);
}
-PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
+PyObject* SCA_PythonController::PyActivate(PyObject *value)
{
SCA_IActuator* actu = LinkedActuatorFromPy(value);
if(actu==NULL)
@@ -418,7 +393,7 @@ PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
Py_RETURN_NONE;
}
-PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value)
+PyObject* SCA_PythonController::PyDeActivate(PyObject *value)
{
SCA_IActuator* actu = LinkedActuatorFromPy(value);
if(actu==NULL)
@@ -430,26 +405,26 @@ PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value)
Py_RETURN_NONE;
}
-PyObject* SCA_PythonController::PyGetActuators(PyObject* self)
+PyObject* SCA_PythonController::PyGetActuators()
{
PyObject* resultlist = PyList_New(m_linkedactuators.size());
for (unsigned int index=0;index<m_linkedactuators.size();index++)
{
- PyList_SET_ITEM(resultlist,index,m_linkedactuators[index]->AddRef());
+ PyList_SET_ITEM(resultlist,index, m_linkedactuators[index]->GetProxy());
}
return resultlist;
}
const char SCA_PythonController::GetSensor_doc[] =
-"GetSensor (char sensorname) return linked sensor that is named [sensorname]\n";
+"getSensor (char sensorname) return linked sensor that is named [sensorname]\n";
PyObject*
-SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value)
+SCA_PythonController::PyGetSensor(PyObject* value)
{
char *scriptArg = PyString_AsString(value);
if (scriptArg==NULL) {
- PyErr_SetString(PyExc_TypeError, "expected a string (sensor name)");
+ PyErr_SetString(PyExc_TypeError, "controller.getSensor(string): Python Controller, expected a string (sensor name)");
return NULL;
}
@@ -459,27 +434,25 @@ SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value)
STR_String realname = sensor->GetName();
if (realname == scriptArg)
{
- return sensor->AddRef();
+ return sensor->GetProxy();
}
}
- char emsg[96];
- PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested sensor \"%s\"", scriptArg );
- PyErr_SetString(PyExc_AttributeError, emsg);
+ PyErr_Format(PyExc_AttributeError, "controller.getSensor(string): Python Controller, unable to find requested sensor \"%s\"", scriptArg);
return NULL;
}
const char SCA_PythonController::GetActuator_doc[] =
-"GetActuator (char sensorname) return linked actuator that is named [actuatorname]\n";
+"getActuator (char sensorname) return linked actuator that is named [actuatorname]\n";
PyObject*
-SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
+SCA_PythonController::PyGetActuator(PyObject* value)
{
char *scriptArg = PyString_AsString(value);
if (scriptArg==NULL) {
- PyErr_SetString(PyExc_TypeError, "expected a string (actuator name)");
+ PyErr_SetString(PyExc_TypeError, "controller.getActuator(string): Python Controller, expected a string (actuator name)");
return NULL;
}
@@ -488,39 +461,37 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
SCA_IActuator* actua = m_linkedactuators[index];
if (actua->GetName() == scriptArg)
{
- return actua->AddRef();
+ return actua->GetProxy();
}
}
- char emsg[96];
- PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested actuator \"%s\"", scriptArg );
- PyErr_SetString(PyExc_AttributeError, emsg);
+ PyErr_Format(PyExc_AttributeError, "controller.getActuator(string): Python Controller, unable to find requested actuator \"%s\"", scriptArg);
return NULL;
}
const char SCA_PythonController::GetSensors_doc[] = "getSensors returns a list of all attached sensors";
PyObject*
-SCA_PythonController::PyGetSensors(PyObject* self)
+SCA_PythonController::PyGetSensors()
{
PyObject* resultlist = PyList_New(m_linkedsensors.size());
for (unsigned int index=0;index<m_linkedsensors.size();index++)
{
- PyList_SET_ITEM(resultlist,index,m_linkedsensors[index]->AddRef());
+ PyList_SET_ITEM(resultlist,index, m_linkedsensors[index]->GetProxy());
}
return resultlist;
}
/* 1. getScript */
-PyObject* SCA_PythonController::PyGetScript(PyObject* self)
+PyObject* SCA_PythonController::PyGetScript()
{
ShowDeprecationWarning("getScript()", "the script property");
return PyString_FromString(m_scriptText);
}
/* 2. setScript */
-PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
+PyObject* SCA_PythonController::PySetScript(PyObject* value)
{
char *scriptArg = PyString_AsString(value);
@@ -540,10 +511,41 @@ PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
}
/* 1. getScript */
-PyObject* SCA_PythonController::PyGetState(PyObject* self)
+PyObject* SCA_PythonController::PyGetState()
{
ShowDeprecationWarning("getState()", "the state property");
return PyInt_FromLong(m_statemask);
}
+PyObject* SCA_PythonController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
+ return PyInt_FromLong(self->m_statemask);
+}
+
+PyObject* SCA_PythonController::pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
+ return PyString_FromString(self->m_scriptText);
+}
+
+int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
+
+ char *scriptArg = PyString_AsString(value);
+
+ if (scriptArg==NULL) {
+ PyErr_SetString(PyExc_TypeError, "controller.script = string: Python Controller, expected a string script text");
+ return -1;
+ }
+
+ /* set scripttext sets m_bModified to true,
+ so next time the script is needed, a reparse into byte code is done */
+ self->SetScriptText(scriptArg);
+
+ return 0;
+}
+
+
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h
index 4ec18f32c23..f10c4e47ebb 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.h
+++ b/source/gameengine/GameLogic/SCA_PythonController.h
@@ -78,8 +78,8 @@ class SCA_PythonController : public SCA_IController
static PyObject* sPyAddActiveActuator(PyObject* self,
PyObject* args);
static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
KX_PYMETHOD_O(SCA_PythonController,Activate);
@@ -92,6 +92,10 @@ class SCA_PythonController : public SCA_IController
KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript);
KX_PYMETHOD_NOARGS(SCA_PythonController,GetState);
+ static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
};
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
index d6c73f21f37..3a72d9b7652 100644
--- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
@@ -312,22 +312,22 @@ void SCA_RandomActuator::enforceConstraints() {
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_RandomActuator::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_RandomActuator",
- sizeof(SCA_RandomActuator),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_RandomActuator::Parents[] = {
@@ -341,23 +341,25 @@ PyParentObject SCA_RandomActuator::Parents[] = {
PyMethodDef SCA_RandomActuator::Methods[] = {
//Deprecated functions ------>
{"setSeed", (PyCFunction) SCA_RandomActuator::sPySetSeed, METH_VARARGS, (PY_METHODCHAR)SetSeed_doc},
- {"getSeed", (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_VARARGS, (PY_METHODCHAR)GetSeed_doc},
- {"getPara1", (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_VARARGS, (PY_METHODCHAR)GetPara1_doc},
- {"getPara2", (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_VARARGS, (PY_METHODCHAR)GetPara2_doc},
- {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_VARARGS, (PY_METHODCHAR)GetDistribution_doc},
+ {"getSeed", (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_NOARGS, (PY_METHODCHAR)GetSeed_doc},
+ {"getPara1", (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_NOARGS, (PY_METHODCHAR)GetPara1_doc},
+ {"getPara2", (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_NOARGS, (PY_METHODCHAR)GetPara2_doc},
+ {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_NOARGS, (PY_METHODCHAR)GetDistribution_doc},
{"setProperty", (PyCFunction) SCA_RandomActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
- {"getProperty", (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
+ {"getProperty", (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
//<----- Deprecated
- {"setBoolConst", (PyCFunction) SCA_RandomActuator::sPySetBoolConst, METH_VARARGS, (PY_METHODCHAR)SetBoolConst_doc},
- {"setBoolUniform", (PyCFunction) SCA_RandomActuator::sPySetBoolUniform, METH_VARARGS, (PY_METHODCHAR)SetBoolUniform_doc},
- {"setBoolBernouilli",(PyCFunction) SCA_RandomActuator::sPySetBoolBernouilli, METH_VARARGS, (PY_METHODCHAR)SetBoolBernouilli_doc},
- {"setIntConst", (PyCFunction) SCA_RandomActuator::sPySetIntConst, METH_VARARGS, (PY_METHODCHAR)SetIntConst_doc},
- {"setIntUniform", (PyCFunction) SCA_RandomActuator::sPySetIntUniform, METH_VARARGS, (PY_METHODCHAR)SetIntUniform_doc},
- {"setIntPoisson", (PyCFunction) SCA_RandomActuator::sPySetIntPoisson, METH_VARARGS, (PY_METHODCHAR)SetIntPoisson_doc},
- {"setFloatConst", (PyCFunction) SCA_RandomActuator::sPySetFloatConst, METH_VARARGS, (PY_METHODCHAR)SetFloatConst_doc},
- {"setFloatUniform", (PyCFunction) SCA_RandomActuator::sPySetFloatUniform, METH_VARARGS, (PY_METHODCHAR)SetFloatUniform_doc},
- {"setFloatNormal", (PyCFunction) SCA_RandomActuator::sPySetFloatNormal, METH_VARARGS, (PY_METHODCHAR)SetFloatNormal_doc},
- {"setFloatNegativeExponential", (PyCFunction) SCA_RandomActuator::sPySetFloatNegativeExponential, METH_VARARGS, (PY_METHODCHAR)SetFloatNegativeExponential_doc},
+ KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst),
+ KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setBoolBernouilli),
+
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntConst),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setIntPoisson),
+
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatConst),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatUniform),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNormal),
+ KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNegativeExponential),
{NULL,NULL} //Sentinel
};
@@ -366,35 +368,36 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
+ KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
{ NULL } //Sentinel
};
-PyObject* SCA_RandomActuator::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- if (!strcmp(attr, "seed")) {
- return PyInt_FromLong(m_base->GetSeed());
- }
- _getattr_up(SCA_IActuator);
+PyObject* SCA_RandomActuator::pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
+ return PyInt_FromLong(act->m_base->GetSeed());
}
-int SCA_RandomActuator::_setattr(const char *attr, PyObject *value)
+int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- if (!strcmp(attr, "seed")) {
- if (PyInt_Check(value)) {
- int ival = PyInt_AsLong(value);
- m_base->SetSeed(ival);
- return 0;
- } else {
- PyErr_SetString(PyExc_TypeError, "expected an integer");
- return 1;
- }
+ SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
+ if (PyInt_Check(value)) {
+ int ival = PyInt_AsLong(value);
+ act->m_base->SetSeed(ival);
+ return 0;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "actuator.seed = int: Random Actuator, expected an integer");
+ return 1;
}
- return SCA_IActuator::_setattr(attr, value);
+}
+
+PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IActuator);
+}
+
+int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value)
+{
+ py_setattro_up(SCA_IActuator);
}
/* 1. setSeed */
@@ -404,10 +407,10 @@ const char SCA_RandomActuator::SetSeed_doc[] =
"\tSet the initial seed of the generator. Equal seeds produce\n"
"\tequal series. If the seed is 0, the generator will produce\n"
"\tthe same value on every call.\n";
-PyObject* SCA_RandomActuator::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PySetSeed(PyObject* args) {
ShowDeprecationWarning("setSeed()", "the seed property");
long seedArg;
- if(!PyArg_ParseTuple(args, "i", &seedArg)) {
+ if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) {
return NULL;
}
@@ -420,7 +423,8 @@ const char SCA_RandomActuator::GetSeed_doc[] =
"getSeed()\n"
"\tReturns the initial seed of the generator. Equal seeds produce\n"
"\tequal series.\n";
-PyObject* SCA_RandomActuator::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetSeed()
+{
ShowDeprecationWarning("getSeed()", "the seed property");
return PyInt_FromLong(m_base->GetSeed());
}
@@ -431,7 +435,8 @@ const char SCA_RandomActuator::GetPara1_doc[] =
"\tReturns the first parameter of the active distribution. Refer\n"
"\tto the documentation of the generator types for the meaning\n"
"\tof this value.";
-PyObject* SCA_RandomActuator::PyGetPara1(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetPara1()
+{
ShowDeprecationWarning("getPara1()", "the para1 property");
return PyFloat_FromDouble(m_parameter1);
}
@@ -442,7 +447,8 @@ const char SCA_RandomActuator::GetPara2_doc[] =
"\tReturns the first parameter of the active distribution. Refer\n"
"\tto the documentation of the generator types for the meaning\n"
"\tof this value.";
-PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetPara2()
+{
ShowDeprecationWarning("getPara2()", "the para2 property");
return PyFloat_FromDouble(m_parameter2);
}
@@ -451,7 +457,8 @@ PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObjec
const char SCA_RandomActuator::GetDistribution_doc[] =
"getDistribution()\n"
"\tReturns the type of the active distribution.\n";
-PyObject* SCA_RandomActuator::PyGetDistribution(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetDistribution()
+{
ShowDeprecationWarning("getDistribution()", "the distribution property");
return PyInt_FromLong(m_distribution);
}
@@ -462,10 +469,10 @@ const char SCA_RandomActuator::SetProperty_doc[] =
"\t- name: string\n"
"\tSet the property to which the random value is assigned. If the \n"
"\tgenerator and property types do not match, the assignment is ignored.\n";
-PyObject* SCA_RandomActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PySetProperty(PyObject* args) {
ShowDeprecationWarning("setProperty()", "the 'property' property");
char *nameArg;
- if (!PyArg_ParseTuple(args, "s", &nameArg)) {
+ if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) {
return NULL;
}
@@ -485,21 +492,20 @@ const char SCA_RandomActuator::GetProperty_doc[] =
"getProperty(name)\n"
"\tReturn the property to which the random value is assigned. If the \n"
"\tgenerator and property types do not match, the assignment is ignored.\n";
-PyObject* SCA_RandomActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomActuator::PyGetProperty()
+{
ShowDeprecationWarning("getProperty()", "the 'property' property");
return PyString_FromString(m_propname);
}
/* 11. setBoolConst */
-const char SCA_RandomActuator::SetBoolConst_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolConst,
"setBoolConst(value)\n"
"\t- value: 0 or 1\n"
-"\tSet this generator to produce a constant boolean value.\n";
-PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tSet this generator to produce a constant boolean value.\n")
+{
int paraArg;
- if(!PyArg_ParseTuple(args, "i", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "i:setBoolConst", &paraArg)) {
return NULL;
}
@@ -509,27 +515,23 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self,
Py_RETURN_NONE;
}
/* 12. setBoolUniform, */
-const char SCA_RandomActuator::SetBoolUniform_doc[] =
+KX_PYMETHODDEF_DOC_NOARGS(SCA_RandomActuator, setBoolUniform,
"setBoolUniform()\n"
-"\tSet this generator to produce true and false, each with 50%% chance of occuring\n";
-PyObject* SCA_RandomActuator::PySetBoolUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tSet this generator to produce true and false, each with 50%% chance of occuring\n")
+{
/* no args */
m_distribution = KX_RANDOMACT_BOOL_UNIFORM;
enforceConstraints();
Py_RETURN_NONE;
}
/* 13. setBoolBernouilli, */
-const char SCA_RandomActuator::SetBoolBernouilli_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli,
"setBoolBernouilli(value)\n"
"\t- value: a float between 0 and 1\n"
-"\tReturn false value * 100%% of the time.\n";
-PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tReturn false value * 100%% of the time.\n")
+{
float paraArg;
- if(!PyArg_ParseTuple(args, "f", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "f:setBoolBernouilli", &paraArg)) {
return NULL;
}
@@ -539,15 +541,13 @@ PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self,
Py_RETURN_NONE;
}
/* 14. setIntConst,*/
-const char SCA_RandomActuator::SetIntConst_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntConst,
"setIntConst(value)\n"
"\t- value: integer\n"
-"\tAlways return value\n";
-PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tAlways return value\n")
+{
int paraArg;
- if(!PyArg_ParseTuple(args, "i", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "i:setIntConst", &paraArg)) {
return NULL;
}
@@ -557,17 +557,15 @@ PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self,
Py_RETURN_NONE;
}
/* 15. setIntUniform,*/
-const char SCA_RandomActuator::SetIntUniform_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntUniform,
"setIntUniform(lower_bound, upper_bound)\n"
"\t- lower_bound: integer\n"
"\t- upper_bound: integer\n"
"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound. The boundaries are included.\n";
-PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tupper_bound. The boundaries are included.\n")
+{
int paraArg1, paraArg2;
- if(!PyArg_ParseTuple(args, "ii", &paraArg1, &paraArg2)) {
+ if(!PyArg_ParseTuple(args, "ii:setIntUniform", &paraArg1, &paraArg2)) {
return NULL;
}
@@ -578,17 +576,15 @@ PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self,
Py_RETURN_NONE;
}
/* 16. setIntPoisson, */
-const char SCA_RandomActuator::SetIntPoisson_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntPoisson,
"setIntPoisson(value)\n"
"\t- value: float\n"
"\tReturn a Poisson-distributed number. This performs a series\n"
"\tof Bernouilli tests with parameter value. It returns the\n"
-"\tnumber of tries needed to achieve succes.\n";
-PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tnumber of tries needed to achieve succes.\n")
+{
float paraArg;
- if(!PyArg_ParseTuple(args, "f", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "f:setIntPoisson", &paraArg)) {
return NULL;
}
@@ -597,16 +593,14 @@ PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self,
enforceConstraints();
Py_RETURN_NONE;
}
-/* 17. setFloatConst,*/
-const char SCA_RandomActuator::SetFloatConst_doc[] =
+/* 17. setFloatConst */
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatConst,
"setFloatConst(value)\n"
"\t- value: float\n"
-"\tAlways return value\n";
-PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tAlways return value\n")
+{
float paraArg;
- if(!PyArg_ParseTuple(args, "f", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "f:setFloatConst", &paraArg)) {
return NULL;
}
@@ -616,17 +610,15 @@ PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self,
Py_RETURN_NONE;
}
/* 18. setFloatUniform, */
-const char SCA_RandomActuator::SetFloatUniform_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatUniform,
"setFloatUniform(lower_bound, upper_bound)\n"
"\t- lower_bound: float\n"
"\t- upper_bound: float\n"
"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound.\n";
-PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tupper_bound.\n")
+{
float paraArg1, paraArg2;
- if(!PyArg_ParseTuple(args, "ff", &paraArg1, &paraArg2)) {
+ if(!PyArg_ParseTuple(args, "ff:setFloatUniform", &paraArg1, &paraArg2)) {
return NULL;
}
@@ -637,17 +629,15 @@ PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self,
Py_RETURN_NONE;
}
/* 19. setFloatNormal, */
-const char SCA_RandomActuator::SetFloatNormal_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNormal,
"setFloatNormal(mean, standard_deviation)\n"
"\t- mean: float\n"
"\t- standard_deviation: float\n"
"\tReturn normal-distributed numbers. The average is mean, and the\n"
-"\tdeviation from the mean is characterized by standard_deviation.\n";
-PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tdeviation from the mean is characterized by standard_deviation.\n")
+{
float paraArg1, paraArg2;
- if(!PyArg_ParseTuple(args, "ff", &paraArg1, &paraArg2)) {
+ if(!PyArg_ParseTuple(args, "ff:setFloatNormal", &paraArg1, &paraArg2)) {
return NULL;
}
@@ -658,16 +648,14 @@ PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self,
Py_RETURN_NONE;
}
/* 20. setFloatNegativeExponential, */
-const char SCA_RandomActuator::SetFloatNegativeExponential_doc[] =
+KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential,
"setFloatNegativeExponential(half_life)\n"
"\t- half_life: float\n"
"\tReturn negative-exponentially distributed numbers. The half-life 'time'\n"
-"\tis characterized by half_life.\n";
-PyObject* SCA_RandomActuator::PySetFloatNegativeExponential(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+"\tis characterized by half_life.\n")
+{
float paraArg;
- if(!PyArg_ParseTuple(args, "f", &paraArg)) {
+ if(!PyArg_ParseTuple(args, "f:setFloatNegativeExponential", &paraArg)) {
return NULL;
}
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h
index 0d404fa8a9f..8f58ed0dcec 100644
--- a/source/gameengine/GameLogic/SCA_RandomActuator.h
+++ b/source/gameengine/GameLogic/SCA_RandomActuator.h
@@ -96,46 +96,32 @@ class SCA_RandomActuator : public SCA_IActuator
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
- /* 1. setSeed */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed);
- /* 2. getSeed */
- KX_PYMETHOD_DOC(SCA_RandomActuator,GetSeed);
- /* 3. setPara1 -removed- */
- /* 4. getPara1 */
- KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara1);
- /* 5. setPara2 -removed- */
- /* 6. getPara2 */
- KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara2);
- /* 7. setDistribution -removed- */
- /* 8. getDistribution */
- KX_PYMETHOD_DOC(SCA_RandomActuator,GetDistribution);
- /* 9. setProperty */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetProperty);
- /* 10. getProperty */
- KX_PYMETHOD_DOC(SCA_RandomActuator,GetProperty);
- /* 11. setBoolConst */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolConst);
- /* 12. setBoolUniform, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolUniform);
- /* 13. setBoolBernouilli, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolBernouilli);
- /* 14. setIntConst,*/
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntConst);
- /* 15. setIntUniform,*/
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntUniform);
- /* 16. setIntPoisson, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntPoisson);
- /* 17. setFloatConst,*/
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatConst);
- /* 18. setFloatUniform, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatUniform);
- /* 19. setFloatNormal, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNormal);
- /* 20. setFloatNegativeExponential, */
- KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNegativeExponential);
+ static PyObject* pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
+ // Deprecated methods ----->
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator,SetSeed);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetSeed);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetPara1);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetPara2);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetDistribution);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator,SetProperty);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetProperty);
+ // <-----
+
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolConst);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator, setBoolUniform);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntConst);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntUniform);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntPoisson);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatConst);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatUniform);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNormal);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential);
}; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */
#endif
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
index 5354c120f52..5ead82db428 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
@@ -127,22 +127,22 @@ bool SCA_RandomSensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_RandomSensor::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_RandomSensor",
- sizeof(SCA_RandomSensor),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_RandomSensor::Parents[] = {
@@ -155,42 +155,24 @@ PyParentObject SCA_RandomSensor::Parents[] = {
PyMethodDef SCA_RandomSensor::Methods[] = {
{"setSeed", (PyCFunction) SCA_RandomSensor::sPySetSeed, METH_VARARGS, (PY_METHODCHAR)SetSeed_doc},
- {"getSeed", (PyCFunction) SCA_RandomSensor::sPyGetSeed, METH_VARARGS, (PY_METHODCHAR)GetSeed_doc},
- {"getLastDraw", (PyCFunction) SCA_RandomSensor::sPyGetLastDraw, METH_VARARGS, (PY_METHODCHAR)GetLastDraw_doc},
+ {"getSeed", (PyCFunction) SCA_RandomSensor::sPyGetSeed, METH_NOARGS, (PY_METHODCHAR)GetSeed_doc},
+ {"getLastDraw", (PyCFunction) SCA_RandomSensor::sPyGetLastDraw, METH_NOARGS, (PY_METHODCHAR)GetLastDraw_doc},
{NULL,NULL} //Sentinel
};
PyAttributeDef SCA_RandomSensor::Attributes[] = {
KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw),
+ KX_PYATTRIBUTE_RW_FUNCTION("seed", SCA_RandomSensor, pyattr_get_seed, pyattr_set_seed),
{NULL} //Sentinel
};
-PyObject* SCA_RandomSensor::_getattr(const char *attr) {
- PyObject* object = _getattr_self(Attributes, this, attr);
- if (object != NULL)
- return object;
- if (!strcmp(attr,"seed")) {
- return PyInt_FromLong(m_basegenerator->GetSeed());
- }
- _getattr_up(SCA_ISensor);
+PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_ISensor);
}
-int SCA_RandomSensor::_setattr(const char *attr, PyObject *value)
+int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value)
{
- int ret = _setattr_self(Attributes, this, attr, value);
- if (ret >= 0)
- return ret;
- if (!strcmp(attr,"seed")) {
- if (PyInt_Check(value)) {
- int ival = PyInt_AsLong(value);
- m_basegenerator->SetSeed(ival);
- return 0;
- } else {
- PyErr_SetString(PyExc_TypeError, "expected an integer");
- return 1;
- }
- }
- return SCA_ISensor::_setattr(attr, value);
+ py_setattro_up(SCA_ISensor);
}
/* 1. setSeed */
@@ -200,10 +182,10 @@ const char SCA_RandomSensor::SetSeed_doc[] =
"\tSet the initial seed of the generator. Equal seeds produce\n"
"\tequal series. If the seed is 0, the generator will produce\n"
"\tthe same value on every call.\n";
-PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomSensor::PySetSeed(PyObject* args) {
ShowDeprecationWarning("setSeed()", "the seed property");
long seedArg;
- if(!PyArg_ParseTuple(args, "i", &seedArg)) {
+ if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) {
return NULL;
}
@@ -217,7 +199,7 @@ const char SCA_RandomSensor::GetSeed_doc[] =
"getSeed()\n"
"\tReturns the initial seed of the generator. Equal seeds produce\n"
"\tequal series.\n";
-PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomSensor::PyGetSeed() {
ShowDeprecationWarning("getSeed()", "the seed property");
return PyInt_FromLong(m_basegenerator->GetSeed());
}
@@ -226,9 +208,27 @@ PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject*
const char SCA_RandomSensor::GetLastDraw_doc[] =
"getLastDraw()\n"
"\tReturn the last value that was drawn.\n";
-PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObject* kwds) {
+PyObject* SCA_RandomSensor::PyGetLastDraw() {
ShowDeprecationWarning("getLastDraw()", "the lastDraw property");
return PyInt_FromLong(m_lastdraw);
}
+
+PyObject* SCA_RandomSensor::pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_RandomSensor* self= static_cast<SCA_RandomSensor*>(self_v);
+ return PyInt_FromLong(self->m_basegenerator->GetSeed());
+}
+
+int SCA_RandomSensor::pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ SCA_RandomSensor* self= static_cast<SCA_RandomSensor*>(self_v);
+ if (!PyInt_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "sensor.seed = int: Random Sensor, expected an integer");
+ return -1;
+ }
+ self->m_basegenerator->SetSeed(PyInt_AsLong(value));
+ return 0;
+}
+
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h
index d808db07536..764692600c3 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.h
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.h
@@ -60,15 +60,18 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
- virtual int _setattr(const char *attr, PyObject *value);
+ virtual PyObject* py_getattro(PyObject *attr);
+ virtual int py_setattro(PyObject *attr, PyObject *value);
/* 1. setSeed */
- KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed);
+ KX_PYMETHOD_DOC_VARARGS(SCA_RandomSensor,SetSeed);
/* 2. getSeed */
- KX_PYMETHOD_DOC(SCA_RandomSensor,GetSeed);
- /* 3. getSeed */
- KX_PYMETHOD_DOC(SCA_RandomSensor,GetLastDraw);
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomSensor,GetSeed);
+ /* 3. getLastDraw */
+ KX_PYMETHOD_DOC_NOARGS(SCA_RandomSensor,GetLastDraw);
+
+ static PyObject* pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
};
diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp
index b2734dd1b33..e9bb37ee958 100644
--- a/source/gameengine/GameLogic/SCA_XNORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XNORController.cpp
@@ -111,22 +111,22 @@ CValue* SCA_XNORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_XNORController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_XNORController",
- sizeof(SCA_XNORController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_XNORController::Parents[] = {
@@ -145,8 +145,8 @@ PyAttributeDef SCA_XNORController::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_XNORController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_XNORController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_XNORController.h b/source/gameengine/GameLogic/SCA_XNORController.h
index a431a72c177..c992d5f1834 100644
--- a/source/gameengine/GameLogic/SCA_XNORController.h
+++ b/source/gameengine/GameLogic/SCA_XNORController.h
@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};
diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp
index 662ef523d56..791a139975f 100644
--- a/source/gameengine/GameLogic/SCA_XORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XORController.cpp
@@ -111,22 +111,22 @@ CValue* SCA_XORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_XORController::Type = {
- PyObject_HEAD_INIT(&PyType_Type)
+ PyObject_HEAD_INIT(NULL)
0,
"SCA_XORController",
- sizeof(SCA_XORController),
+ sizeof(PyObjectPlus_Proxy),
0,
- PyDestructor,
+ py_base_dealloc,
0,
- __getattr,
- __setattr,
- 0, //&MyPyCompare,
- __repr,
- 0, //&cvalue_as_number,
0,
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_XORController::Parents[] = {
@@ -145,8 +145,8 @@ PyAttributeDef SCA_XORController::Attributes[] = {
{ NULL } //Sentinel
};
-PyObject* SCA_XORController::_getattr(const char *attr) {
- _getattr_up(SCA_IController);
+PyObject* SCA_XORController::py_getattro(PyObject *attr) {
+ py_getattro_up(SCA_IController);
}
/* eof */
diff --git a/source/gameengine/GameLogic/SCA_XORController.h b/source/gameengine/GameLogic/SCA_XORController.h
index 2fbc7866ecf..065b31fd901 100644
--- a/source/gameengine/GameLogic/SCA_XORController.h
+++ b/source/gameengine/GameLogic/SCA_XORController.h
@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
- virtual PyObject* _getattr(const char *attr);
+ virtual PyObject* py_getattro(PyObject *attr);
};