示例#1
0
    bool NextStep() {
        if(actions_.Count() == 0) return false;
        List<Point>* prevPoints = points_[points_.Count() - 1];

        // Check if the next action should be executed.
        if(currentStep_ == currentAction_->Steps()) {
            // Skip over all connected actions.
            size_t nextPosition = currentPosition_ + 1;
            while(nextPosition < actions_.Count() && actions_[nextPosition]->WithPrevious()) {
                nextPosition++;
            }

            size_t i = nextPosition + 1;
            while((i < actions_.Count()) && actions_[i]->WithPrevious()) {
                actions_[i]->Initialize(*prevPoints);
                i++;
            }

            if(nextPosition < actions_.Count()) {
                // Advance to the next action.
                currentAction_ = actions_[nextPosition];
                currentAction_->Initialize(*prevPoints);
                currentPosition_ = nextPosition;
                currentStep_ = 0;
            }
            else {
                // All actions have been executed.
                return false; 
            }
        }

        // Compute the next state of the shape.
        // The generated points depend directly on the previous ones.
        List<Point>* newPoints = new List<Point>(*prevPoints);
        points_.Add(newPoints);

        // Apply to the points the current action and all actions liked with it.
        currentAction_->Execute(currentStep_, *newPoints);

        for(size_t i = currentPosition_ + 1; i < actions_.Count(); i++) {
            if(actions_[i]->WithPrevious()) {
                actions_[i]->Execute(currentStep_, *newPoints);
            }
            else break;
        }

        currentStep_++;
        return true;
    }
示例#2
0
void CAxis::Update(short currentValue)
{
	// This whole thing goes in a do/while, so it happens once, but we can bail out of the block
	// and perform our cleanup code at the end.
	do
	{
		// Reset the binary flag if we've gotten back inside the threshold bounds.
		if(_lastValue < _threshold && _lastValue > (_threshold * -1))
		{
			if(!_triggerBinary && _centerMotion && _gestures && _processor->_gestures.size() != 0)
			{
				_processor->newMotion(new CMotion(_centerMotion));
			}
			_triggerBinary = true;
		}

		IAction* actionToPerform = NULL;
		// Determine if we're beyond the threshold, and if so, which action to take
		if(currentValue > _threshold )
		{
			if(_gestures && !_triggerBinary)
			{
				if(::GetTickCount() - _lastGestureSent > 1000)
				{					
					_processor->newMotion(new CMotion(_posMotion));
					_lastGestureSent = ::GetTickCount();
					_triggerBinary = false;
					continue;
				}
			}
			if(_gestures && _triggerBinary)
			{
				_processor->newMotion(new CMotion(_posMotion));
				_lastGestureSent = ::GetTickCount();
				_triggerBinary = false;
				continue;
			}
			else
				actionToPerform = _positiveAction;
		}
		else if (currentValue < (_threshold *-1))
		{
			if(_gestures && !_triggerBinary)
			{
				if(::GetTickCount() - _lastGestureSent > 1000)
				{					
					_processor->newMotion(new CMotion(_negMotion));
					_lastGestureSent = ::GetTickCount();
					_triggerBinary = false;
					continue;
				}
			}
			if(_gestures && _triggerBinary)
			{
				_processor->newMotion(new CMotion(_negMotion));				
				_lastGestureSent = ::GetTickCount();
				_triggerBinary = false;
				continue;
			}
			else
				actionToPerform = _negativeAction;
		}

		// Should bail out of the do/while
		if(actionToPerform == NULL)
			continue;

		if(_pulse)
		{
			// Determine the frequency
			int currentMotionRange = 512 - _threshold;
			double multiplier = currentValue * (1.0 / currentMotionRange);
			// Normalize the multiplier to a positive value
			multiplier = multiplier < 0 ? multiplier * -1.0 : multiplier;
			int currentFrequencyRange = _maximumPulseRate - _minimumPulseRate;
			double frequency = (currentFrequencyRange * multiplier) + _minimumPulseRate;
			unsigned int requiredTicksSinceLast = 1000 / frequency;
			DWORD currentTickCount = GetTickCount();
			DWORD tickDelta = currentTickCount - _lastPulseExecute;
			if(requiredTicksSinceLast < tickDelta)
			{
				actionToPerform->Execute();
				_lastPulseExecute = currentTickCount;
			}
		}
		else if(_triggerBinary)
		{
			actionToPerform->Execute();
			_triggerBinary = false;
		}
	} while(false);

	_lastValue = currentValue;
}