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.
This commit is contained in:
Benoit Bolsee
2009-05-04 22:21:02 +00:00
parent e29e329885
commit be2c21bcdb
13 changed files with 126 additions and 30 deletions

View File

@@ -255,6 +255,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
int frequency = 0;
bool invert = false;
bool level = false;
bool tap = false;
while(sens)
{
@@ -268,6 +269,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
frequency = sens->freq;
invert = !(sens->invert == 0);
level = !(sens->level == 0);
tap = !(sens->tap == 0);
switch (sens->type)
{
@@ -755,6 +757,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
frequency);
gamesensor->SetInvert(invert);
gamesensor->SetLevel(level);
gamesensor->SetTap(tap);
gamesensor->SetName(STR_String(sens->name));
gameobj->AddSensor(gamesensor);