forked from bartvdbraak/blender
[#18840] Joystick sensor lag
if(SDL_PollEvent(&sdl_event)) // if -> while fixed it removed 'm_buttonnum' was misleading, wasn't used as you expect. Added gravity to variable to world to be used by collada.
This commit is contained in:
parent
6ac072e1bd
commit
8c4620f3d3
@ -106,6 +106,8 @@ static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
|
||||
static PyObject *World_setCurrent( BPy_World * self );
|
||||
static PyObject *World_getTextures( BPy_World * self );
|
||||
static int World_setTextures( BPy_World * self, PyObject * value );
|
||||
static PyObject *World_getGravity( BPy_World * self );
|
||||
static int World_setGravity( BPy_World * self, PyObject * value );
|
||||
static PyObject *World_copy( BPy_World * self );
|
||||
|
||||
|
||||
@ -259,6 +261,9 @@ static PyGetSetDef BPy_World_getseters[] = {
|
||||
"world ipo", NULL},
|
||||
{"textures", (getter)World_getTextures, (setter)World_setTextures,
|
||||
"The World's texture list as a tuple",
|
||||
NULL},
|
||||
{"gravity", (getter)World_getGravity, (setter)World_setGravity,
|
||||
"Physics gravity setting",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
@ -1136,3 +1141,21 @@ static int World_setTextures( BPy_World * self, PyObject * value )
|
||||
Py_DECREF(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *World_getGravity( BPy_World * self )
|
||||
{
|
||||
return PyFloat_FromDouble(self->world->gravity);
|
||||
}
|
||||
|
||||
static int World_setGravity( BPy_World * self, PyObject * value )
|
||||
{
|
||||
float f = PyFloat_AsDouble(value);
|
||||
if (f==-1 && PyErr_Occurred())
|
||||
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float or int" );
|
||||
|
||||
if (f<0.0f)f= 0.0f;
|
||||
else if (f>25.0f)f= 25.0f;
|
||||
|
||||
self->world->gravity= f;
|
||||
return 0;
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ class World:
|
||||
@ivar ipo: The world type ipo linked to this world object.
|
||||
@type textures: a tuple of Blender MTex objects.
|
||||
@ivar textures: The World's texture list. Empty texture channels contains None.
|
||||
@type gravity: float
|
||||
@ivar gravity: World physics gravity setting between 0.0 and 25.0
|
||||
"""
|
||||
|
||||
def getRange():
|
||||
|
@ -38,7 +38,6 @@ SCA_Joystick::SCA_Joystick(short int index)
|
||||
:
|
||||
m_joyindex(index),
|
||||
m_prec(3200),
|
||||
m_buttonnum(-2),
|
||||
m_axismax(-1),
|
||||
m_buttonmax(-1),
|
||||
m_hatmax(-1),
|
||||
@ -68,6 +67,7 @@ SCA_Joystick::~SCA_Joystick()
|
||||
}
|
||||
|
||||
SCA_Joystick *SCA_Joystick::m_instance[JOYINDEX_MAX];
|
||||
int SCA_Joystick::m_joynum = 0;
|
||||
int SCA_Joystick::m_refCount = 0;
|
||||
|
||||
SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
|
||||
@ -88,6 +88,9 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
|
||||
echo("Error-Initializing-SDL: " << SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m_joynum = SDL_NumJoysticks();
|
||||
|
||||
for (i=0; i<JOYINDEX_MAX; i++) {
|
||||
m_instance[i] = new SCA_Joystick(i);
|
||||
m_instance[i]->CreateJoystickDevice();
|
||||
@ -155,12 +158,13 @@ bool SCA_Joystick::aAxisIsPositive(int axis_single)
|
||||
|
||||
bool SCA_Joystick::aAnyButtonPressIsPositive(void)
|
||||
{
|
||||
return (m_buttonnum==-2) ? false : true;
|
||||
}
|
||||
|
||||
bool SCA_Joystick::aAnyButtonReleaseIsPositive(void)
|
||||
{
|
||||
return (m_buttonnum==-2) ? true : false;
|
||||
/* this is needed for the "all events" option
|
||||
* so we know if there are no buttons pressed */
|
||||
for (int i=0; i<m_buttonmax; i++)
|
||||
if (SDL_JoystickGetButton(m_private->m_joystick, i))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SCA_Joystick::aButtonPressIsPositive(int button)
|
||||
@ -217,7 +221,7 @@ bool SCA_Joystick::CreateJoystickDevice(void)
|
||||
return false;
|
||||
#else
|
||||
if(m_isinit == false){
|
||||
if (m_joyindex>=SDL_NumJoysticks()) {
|
||||
if (m_joyindex>=m_joynum) {
|
||||
// don't print a message, because this is done anyway
|
||||
//echo("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)");
|
||||
|
||||
|
@ -44,6 +44,7 @@ class SCA_Joystick
|
||||
|
||||
{
|
||||
static SCA_Joystick *m_instance[JOYINDEX_MAX];
|
||||
static int m_joynum;
|
||||
static int m_refCount;
|
||||
|
||||
class PrivateData;
|
||||
@ -67,11 +68,6 @@ class SCA_Joystick
|
||||
*/
|
||||
int m_prec;
|
||||
|
||||
/*
|
||||
* button values stored here
|
||||
*/
|
||||
int m_buttonnum;
|
||||
|
||||
/*
|
||||
* max # of buttons avail
|
||||
*/
|
||||
@ -146,7 +142,6 @@ public:
|
||||
bool aAxisIsPositive(int axis_single); /* check a single axis only */
|
||||
|
||||
bool aAnyButtonPressIsPositive(void);
|
||||
bool aAnyButtonReleaseIsPositive(void);
|
||||
bool aButtonPressIsPositive(int button);
|
||||
bool aButtonReleaseIsPositive(int button);
|
||||
bool aHatIsPositive(int hatnum, int dir);
|
||||
@ -160,10 +155,6 @@ public:
|
||||
int GetAxisPosition(int index){
|
||||
return m_axis_array[index];
|
||||
}
|
||||
|
||||
int GetButton(void){
|
||||
return m_buttonnum;
|
||||
}
|
||||
|
||||
int GetHat(int index){
|
||||
return m_hat_array[index];
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#define JOYINDEX_MAX 8
|
||||
#define JOYAXIS_MAX 16
|
||||
#define JOYBUT_MAX 18
|
||||
#define JOYHAT_MAX 4
|
||||
|
||||
#define JOYAXIS_RIGHT 0
|
||||
|
@ -42,7 +42,7 @@ void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event)
|
||||
m_istrig_axis = 1;
|
||||
}
|
||||
|
||||
|
||||
/* See notes below in the event loop */
|
||||
void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
|
||||
{
|
||||
if(sdl_event->jhat.hat >= JOYAXIS_MAX)
|
||||
@ -52,30 +52,20 @@ void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
|
||||
m_istrig_hat = 1;
|
||||
}
|
||||
|
||||
/* See notes below in the event loop */
|
||||
void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
|
||||
{
|
||||
m_istrig_button = 1;
|
||||
|
||||
/* this is needed for the "all events" option
|
||||
* so we know if there are no buttons pressed */
|
||||
int i;
|
||||
for (i=0; i<m_buttonmax; i++) {
|
||||
if (SDL_JoystickGetButton(m_private->m_joystick, i)) {
|
||||
m_buttonnum = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_buttonnum = -2;
|
||||
}
|
||||
|
||||
|
||||
void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
|
||||
{
|
||||
if(sdl_event->jbutton.button <= m_buttonmax) /* unsigned int so always above 0 */
|
||||
{
|
||||
m_istrig_button = 1;
|
||||
m_buttonnum = sdl_event->jbutton.button;
|
||||
}
|
||||
//if(sdl_event->jbutton.button > m_buttonmax) /* unsigned int so always above 0 */
|
||||
// return;
|
||||
// sdl_event->jbutton.button;
|
||||
|
||||
m_istrig_button = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -84,22 +74,27 @@ void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
|
||||
m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
|
||||
}
|
||||
|
||||
/* only handle events for 1 joystick */
|
||||
|
||||
void SCA_Joystick::HandleEvents(void)
|
||||
{
|
||||
SDL_Event sdl_event;
|
||||
|
||||
int i;
|
||||
for (i=0; i<JOYINDEX_MAX; i++) {
|
||||
for (i=0; i<m_joynum; i++) { /* could use JOYINDEX_MAX but no reason to */
|
||||
if(SCA_Joystick::m_instance[i])
|
||||
SCA_Joystick::m_instance[i]->OnNothing(&sdl_event);
|
||||
}
|
||||
|
||||
if(SDL_PollEvent(&sdl_event))
|
||||
while(SDL_PollEvent(&sdl_event))
|
||||
{
|
||||
/* Note! m_instance[sdl_event.jaxis.which]
|
||||
* will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */
|
||||
|
||||
/* Note!, with buttons, this wont care which button is pressed,
|
||||
* only to set 'm_istrig_button', actual pressed buttons are detected by SDL_JoystickGetButton */
|
||||
|
||||
/* Note!, if you manage to press and release a button within 1 logic tick
|
||||
* it wont work as it should */
|
||||
|
||||
switch(sdl_event.type)
|
||||
{
|
||||
case SDL_JOYAXISMOTION:
|
||||
|
Loading…
Reference in New Issue
Block a user