diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-05-05 02:21:02 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-05-05 02:21:02 +0400 |
commit | be2c21bcdb2a05fa238cb637940269941a5fc12c (patch) | |
tree | b5de269198fa9e5ad15e677067666e9e9f38d037 /source/blender | |
parent | e29e329885aa582316b70e13be2e4a05fe32fefc (diff) |
BGE logic: new sensor "tap" option to generate automatically on/off pulses
When enabled, this option converts any positive trigger from the sensor
into a pair of positive+negative trigger, with the negative trigger sent
in the next frame. The negative trigger from the sensor are not passed
to the controller as the option automatically generates the negative triggers.
From the controller point of view, the sensor is positive only for 1 frame,
even if the underlying sensor state remains positive.
The option interacts with the other sensor option in this way:
- Level option: tap option is mutually exclusive with level option. Both
cannot be enabled at the same time.
- Invert option: tap option operates on the negative trigger of the
sensor, which are converted to positive trigger by the invert option.
Hence, the controller will see the sensor positive for 1 frame when
the underlying sensor state turns negative.
- Positive pulse option: tap option adds a negative trigger after each
repeated positive pulse, unless the frequency option is 0, in which case
positive pulse are generated on every frame as before, as long as the
underlying sensor state is positive.
- Negative pulse option: this option is not compatible with tap option
and is ignored when tap option is enabled.
Notes:
- Keyboard "All keys" is handled specially when tap option is set:
There will be one pair of positive/negative trigger for each new
key press, regardless on how many keys are already pressed and there
is no trigger when keys are released, regardless if keys are still
pressed.
In case two keys are pressed in succesive frames, there will
be 2 positive triggers and 1 negative trigger in the following frame.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesdna/DNA_sensor_types.h | 3 | ||||
-rw-r--r-- | source/blender/src/buttons_logic.c | 36 |
2 files changed, 31 insertions, 8 deletions
diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h index 7a358ad0694..8b29ce1338d 100644 --- a/source/blender/makesdna/DNA_sensor_types.h +++ b/source/blender/makesdna/DNA_sensor_types.h @@ -158,7 +158,8 @@ typedef struct bSensor { /* just add here, to avoid align errors... */ short invert; /* Whether or not to invert the output. */ short level; /* Whether the sensor is level base (edge by default) */ - int pad; + short tap; + short pad; } bSensor; typedef struct bJoystickSensor { diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index 941ed5ebe12..dccbc73787d 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -1026,6 +1026,19 @@ static void set_col_sensor(int type, int medium) BIF_ThemeColorShade(col, medium?30:0); } + +static void verify_logicbutton_func(void *data1, void *data2) +{ + bSensor *sens= (bSensor*)data1; + + if(sens->level && sens->tap) { + if(data2 == &(sens->level)) sens->tap= 0; + else sens->level= 0; + allqueue(REDRAWBUTSLOGIC, 0); + } +} + + /** * Draws a toggle for pulse mode, a frequency field and a toggle to invert * the value of this sensor. Operates on the shared data block of sensors. @@ -1036,30 +1049,39 @@ static void draw_default_sensor_header(bSensor *sens, short y, short w) { + uiBut *but; + /* Pulsing and frequency */ uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP, - (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19, + (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19, &sens->pulse, 0.0, 0.0, 0, 0, "Activate TRUE level triggering (pulse mode)"); uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN, - (short)(x + 10 + 0.15 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19, + (short)(x + 10 + 0.1 * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19, &sens->pulse, 0.0, 0.0, 0, 0, "Activate FALSE level triggering (pulse mode)"); uiDefButS(block, NUM, 1, "f:", - (short)(x + 10 + 0.3 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19, + (short)(x + 10 + 0.2 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19, &sens->freq, 0.0, 10000.0, 0, 0, "Delay between repeated pulses (in logic tics, 0 = no delay)"); /* value or shift? */ + but= uiDefButS(block, TOG, 1, "Level", + (short)(x + 10 + 0.5 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19, + &sens->level, 0.0, 0.0, 0, 0, + "Level detector, trigger controllers of new states (only applicable upon logic state transition)"); + uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->level)); + but= uiDefButS(block, TOG, 1, "Tap", + (short)(x + 10 + 0.702 * (w-20)), (short)(y - 21), (short)(0.12 * (w-20)), 19, + &sens->tap, 0.0, 0.0, 0, 0, + "Trigger controllers only for an instant, even while the sensor remains true"); + uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->tap)); + uiDefButS(block, TOG, 1, "Inv", (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19, &sens->invert, 0.0, 0.0, 0, 0, "Invert the level (output) of this sensor"); - uiDefButS(block, TOG, 1, "Level", - (short)(x + 10 + 0.65 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19, - &sens->level, 0.0, 0.0, 0, 0, - "Level detector, trigger controllers of new states (only applicable upon logic state transition)"); } static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname) |