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:
authorCampbell Barton <ideasman42@gmail.com>2008-10-08 07:16:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-10-08 07:16:19 +0400
commitce4162c9a13f8d147e898c625ffe1e10bca3b48d (patch)
treee178b605ed574fe8fcf24532f26ce13e24fe2144 /source/gameengine
parentb8c294d323551591a1140e3b73e03b996303eb81 (diff)
* Joystick sensor is now only triggered from events of the selected type.
* Keyboard sensor - added (back?) support for qualifiers (Hold buttons in the UI)
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp4
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp24
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.h20
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp10
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.cpp27
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.cpp68
6 files changed, 119 insertions, 34 deletions
diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp
index e538afb69a2..13b7f43195d 100644
--- a/source/gameengine/Converter/KX_ConvertSensors.cpp
+++ b/source/gameengine/Converter/KX_ConvertSensors.cpp
@@ -433,8 +433,8 @@ void BL_ConvertSensors(struct Object* blenderobject,
{
gamesensor = new SCA_KeyboardSensor(eventmgr,
gReverseKeyTranslateTable[blenderkeybdsensor->key],
- blenderkeybdsensor->qual,
- blenderkeybdsensor->qual2,
+ gReverseKeyTranslateTable[blenderkeybdsensor->qual],
+ gReverseKeyTranslateTable[blenderkeybdsensor->qual2],
(blenderkeybdsensor->type == SENS_ALL_KEYS),
blenderkeybdsensor->targetName,
blenderkeybdsensor->toggleName,
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index b50cfe812a9..f271baeed16 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -42,7 +42,9 @@ SCA_Joystick::SCA_Joystick(short int index)
m_buttonnum(-2),
m_hatdir(-2),
m_isinit(0),
- m_istrig(0),
+ m_istrig_axis(0),
+ m_istrig_button(0),
+ m_istrig_hat(0),
m_axismax(-1),
m_buttonmax(-1),
m_hatmax(-1)
@@ -310,13 +312,25 @@ int SCA_Joystick::pGetAxis(int axisnum, int udlr)
return 0;
}
-#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
int SCA_Joystick::pAxisTest(int axisnum)
{
#ifndef DISABLE_SDL
- if(axisnum == 1)return MAX2(abs(m_axis10), abs(m_axis11));
- if(axisnum == 2)return MAX2(abs(m_axis20), abs(m_axis21));
-#endif
+ short i1,i2;
+ if(axisnum == 1) {
+ i1 = m_axis10; i2 = m_axis11;
+ }
+ else if(axisnum == 2) {
+ i1 = m_axis20; i2 = m_axis21;
+ }
+ /* long winded way to do
+ * return MAX2(abs(i1), abs(i2))
+ * avoid abs from math.h */
+ if (i1 < 0) i1 = -i1;
+ if (i2 < 0) i2 = -i2;
+ if (i1 <i2) return i2;
+ else return i1;
+#else
return 0;
+#endif
}
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
index 33cfbd74d05..8335d5538ad 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
@@ -90,7 +90,7 @@ class SCA_Joystick
int m_buttonmax;
int m_hatmax;
- /*
+ /*
* hat values stored here
*/
int m_hatnum;
@@ -106,8 +106,10 @@ class SCA_Joystick
bool m_isinit;
- /* is triggered */
- bool m_istrig;
+ /* is triggered for each event type */
+ bool m_istrig_axis;
+ bool m_istrig_button;
+ bool m_istrig_hat;
#ifndef DISABLE_SDL
/*
@@ -212,8 +214,16 @@ public:
return m_prec;
}
- bool IsTrig(void){
- return m_istrig;
+ bool IsTrigAxis(void){
+ return m_istrig_axis;
+ }
+
+ bool IsTrigButton(void){
+ return m_istrig_button;
+ }
+
+ bool IsTrigHat(void){
+ return m_istrig_hat;
}
/*
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
index 7a2ec5b3dea..89e2420f822 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
@@ -38,7 +38,7 @@ void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event)
pFillAxes();
m_axisnum = sdl_event->jaxis.axis;
m_axisvalue = sdl_event->jaxis.value;
- m_istrig = 1;
+ m_istrig_axis = 1;
}
@@ -46,12 +46,12 @@ void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
{
m_hatdir = sdl_event->jhat.value;
m_hatnum = sdl_event->jhat.hat;
- m_istrig = 1;
+ m_istrig_hat = 1;
}
void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
{
- m_istrig = 1;
+ m_istrig_button = 1;
/* this is needed for the "all events" option
* so we know if there are no buttons pressed */
@@ -70,7 +70,7 @@ void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
{
if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax)
{
- m_istrig = 1;
+ m_istrig_button = 1;
m_buttonnum = sdl_event->jbutton.button;
}
}
@@ -78,7 +78,7 @@ void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
{
- m_istrig = 0;
+ m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
}
/* only handle events for 1 joystick */
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
index 2e9db5fb20a..bcd3aa842b7 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
@@ -110,9 +110,6 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
if(js==NULL) /* no joystick - dont do anything */
return false;
- if (!js->IsTrig()) /* No events from SDL? - dont bother */
- return reset ? true : false;
-
m_reset = false;
switch(m_joymode)
{
@@ -125,6 +122,10 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
m_axisf == 3 == down
numberof== m_axis -- max 2
*/
+
+ if (!js->IsTrigAxis()) /* No events from SDL? - dont bother */
+ return reset ? true : false;
+
js->cSetPrecision(m_precision);
if (m_bAllEvents) {
if(js->aAnyAxisIsPositive(m_axis)){
@@ -188,6 +189,9 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
/* what is what!
m_button = the actual button in question
*/
+ if (!js->IsTrigButton()) /* No events from SDL? - dont bother */
+ return reset ? true : false;
+
if(( m_bAllEvents && js->aAnyButtonPressIsPositive()) || (!m_bAllEvents && js->aButtonPressIsPositive(m_button))) {
m_istrig = 1;
result = true;
@@ -205,6 +209,10 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
numberof = m_hat -- max 2
direction= m_hatf -- max 12
*/
+
+ if (!js->IsTrigHat()) /* No events from SDL? - dont bother */
+ return reset ? true : false;
+
if(m_hat == 1){
if(js->aHatIsPositive(m_hatf)){
m_istrig = 1;
@@ -227,19 +235,6 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
}
}
}
- /*
- if(m_hat == 3){
- if(js->aHatIsPositive(m_hatf)){
- m_istrig = 1;
- result = true;
- }else{
- if(m_istrig){
- m_istrig = 0;
- result = true;
- }
- }
- }
- */
break;
}
/* test for ball anyone ?*/
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
index d09a5394965..fa39a13679f 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
@@ -122,6 +122,10 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
{
bool result = false;
bool reset = m_reset && m_level;
+ bool qual = true;
+ bool qual_change = false;
+ short int m_val_orig = m_val;
+
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
// cerr << "SCA_KeyboardSensor::Eval event, sensing for "<< m_hotkey << " at device " << inputdev << "\n";
@@ -202,7 +206,43 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
(SCA_IInputDevice::KX_EnumInputs) m_hotkey);
// cerr << "======= SCA_KeyboardSensor::Evaluate:: status: " << inevent.m_status << endl;
-
+
+
+ /* Check qualifier keys
+ * - see if the qualifiers we request are pressed - 'qual' true/false
+ * - see if the qualifiers we request changed their state - 'qual_change' true/false
+ */
+ if (m_qual > 0) {
+ const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual);
+ switch(qualevent.m_status) {
+ case SCA_InputEvent::KX_NO_INPUTSTATUS:
+ qual = false;
+ break;
+ case SCA_InputEvent::KX_JUSTRELEASED:
+ qual_change = true;
+ qual = false;
+ break;
+ case SCA_InputEvent::KX_JUSTACTIVATED:
+ qual_change = true;
+ }
+ }
+ if (m_qual2 > 0 && qual==true) {
+ const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual2);
+ /* copy of above */
+ switch(qualevent.m_status) {
+ case SCA_InputEvent::KX_NO_INPUTSTATUS:
+ qual = false;
+ break;
+ case SCA_InputEvent::KX_JUSTRELEASED:
+ qual_change = true;
+ qual = false;
+ break;
+ case SCA_InputEvent::KX_JUSTACTIVATED:
+ qual_change = true;
+ }
+ }
+ /* done reading qualifiers */
+
if (inevent.m_status == SCA_InputEvent::KX_NO_INPUTSTATUS)
{
if (m_val == 1)
@@ -240,7 +280,33 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
}
}
}
+
+ /* Modify the key state based on qual(s)
+ * Tested carefuly. dont touch unless your really sure.
+ * note, this will only change the results if key modifiers are set.
+ *
+ * When all modifiers and keys are positive
+ * - pulse true
+ *
+ * When ANY of the modifiers or main key become inactive,
+ * - pulse false
+ */
+ if (qual==false) { /* one of the qualifiers are not pressed */
+ if (m_val_orig && qual_change) { /* we were originally enabled, but a qualifier changed */
+ result = true;
+ } else {
+ result = false;
+ }
+ m_val = 0; /* since one of the qualifiers is not on, set the state to false */
+ } else { /* we done have any qualifiers or they are all pressed */
+ if (m_val && qual_change) { /* the main key state is true and our qualifier just changed */
+ result = true;
+ }
+ }
+ /* done with key quals */
+
}
+
if (reset)
// force an event
result = true;