Example #1
0
void processTrigger(const uint8_t trigger_index) {
	static uint32_t oldState=0;
	if (
	inputOffVerified(trigger_index) &&
	inputOnVerified(trigger_index) &&
	outputOffVerified(trigger_index) &&
	outputOnVerified(trigger_index) &&
	stateOffVerified(trigger_index) &&
	stateOnVerified(trigger_index)
	) {
		//all condition satisfied, check if action should be triggered
		if (triggers[trigger_index].timer.time_current == triggers[trigger_index].timer.time_preload) {
			//already count down and new state should be activated
			activateTrigger(&triggers[trigger_index].actuator);
			usartSendAction(&triggers[trigger_index], BUS_MASTER_ADDRESS);
			triggers[trigger_index].timer.time_current++;
		}
		//check if should count down to activate new output state
		if (triggers[trigger_index].timer.time_current < triggers[trigger_index].timer.time_preload)
		{
			triggers[trigger_index].timer.time_current++;
		}
		oldState |=((uint32_t)1)<<trigger_index;
	}
	else
	{
		//condition not valid, set countdown counter to 0
		if (!(oldState&(((uint32_t)1)<<trigger_index))) {
			triggers[trigger_index].timer.time_current = 0;
		}
		oldState &=~(((uint32_t)1)<<trigger_index);
	}

}
Example #2
0
void Player::changeFacing() {
	int dirIndex = 0, dirIndex2 = 0;
	int newDir = 0, newDir2 = 0;

	if (_facing != _turnToFacing) {
		// Find the index for the given direction in the player direction list
		int tempDir = _facing;
		do {
			++dirIndex;
			newDir += tempDir;
			tempDir = _directionListIndexes[tempDir + 10];
		} while (tempDir != _turnToFacing);
	}


	if (_facing != _turnToFacing) {
		// Find the index for the given direction in the player direction list
		int tempDir = _facing;
		do {
			++dirIndex2;
			newDir2 += tempDir;
			tempDir = _directionListIndexes[tempDir + 20];
		} while (tempDir != _turnToFacing);
	}

	int diff = dirIndex - dirIndex2;
	if (diff == 0)
		diff = newDir - newDir2;

	_facing = (diff >= 0) ? (Facing)_directionListIndexes[_facing + 20] :
		(Facing)_directionListIndexes[_facing + 10];
	selectSeries();

	if ((_facing == _turnToFacing) && !_moving) {
		updateFrame();
		activateTrigger();
	}

	_priorTimer += 1;
}
Example #3
0
void Player::move() {
	Scene &scene = _vm->_game->_scene;
	Rails &rails = scene._rails;
	bool newFacing = false;

	if (_moving) {
		while (!_walkOffScreen && _playerPos == _targetPos) {
			bool isRouteEmpty = rails.empty();
			if (!isRouteEmpty) {
				const WalkNode &node = rails.popNode();

				_targetPos = node._walkPos;
				newFacing = true;
			} else if (!_walkOffScreenSceneId) {
				// End of walking path
				rails.resetRoute();
				_moving = false;
				setFinalFacing();
				newFacing = true;
			} else {
				_walkOffScreen = _walkOffScreenSceneId;
				_walkAnywhere = true;
				_walkOffScreenSceneId = 0;
				_stepEnabled = false;
				newFacing = false;
			}

			if (!_moving)
				break;
		}
	}

	if (newFacing && _moving)
		startMovement();

	if (_turnToFacing != _facing) {
		changeFacing();
	} else if (!_moving) {
		updateFrame();
		activateTrigger();
	}

	int velocity = _velocity;
	if (_scalingVelocity && (_totalDistance > 0)) {
		int angleRange = 100 - _currentScale;
		int angleScale = angleRange * (_posDiff.x - 1) / _totalDistance + _currentScale;
		velocity = MAX(1L, (angleScale * _currentScale * velocity) / 10000L);
	}

	if (!_moving || (_facing != _turnToFacing))
		return;

	Common::Point newPos = _playerPos;
	newFacing = false;
	_special = 0;

	if (_distAccum < velocity) {
		do {
			if (_pixelAccum < _posDiff.x)
				_pixelAccum += _posDiff.y;
			if (_pixelAccum >= _posDiff.x) {
				if ((_posChange.y > 0) || _walkOffScreen)
					newPos.y += _yDirection;
				--_posChange.y;
				_pixelAccum -= _posDiff.x;
			}

			if (_pixelAccum < _posDiff.x) {
				if ((_posChange.x > 0) || _walkOffScreen)
					newPos.x += _xDirection;
				--_posChange.x;
			}

			if (!_walkAnywhere && !_walkOffScreen && (_walkOffScreenSceneId == 0)) {
				newFacing = scene._depthSurface.getDepthHighBit(newPos);

				if (_special == 0)
					_special = scene.getDepthHighBits(newPos);
			}

			_distAccum += _deltaDistance;

		} while ((_distAccum < velocity) && !newFacing && ((_posChange.x > 0) || (_posChange.y > 0) || (_walkOffScreen != 0)));
	}

	_distAccum -= velocity;

	if (newFacing) {
		cancelCommand();
	} else {
		if (!_walkOffScreen) {
			// If the move is complete, make sure the position is exactly on the given destination
			if (_posChange.x == 0)
				newPos.x = _targetPos.x;
			if (_posChange.y == 0)
				newPos.y = _targetPos.y;
		}

		_playerPos = newPos;
	}
}