Exemplo n.º 1
0
void InitAxisBinding(AxisBinding &ab, const std::string &bindName, const std::string &defaultAxis) {
	std::string axisName = Pi::config->String(bindName.c_str());
	if (axisName.length() == 0) {
		axisName = defaultAxis;
		Pi::config->SetString(bindName.c_str(), axisName.c_str());
	}

	// set the binding from the configured or default value
	if (!AxisBinding::FromString(axisName.c_str(), ab)) {
		Output("invalid axis binding '%s' in config file for %s\n", axisName.c_str(), bindName.c_str());
		ab.Clear();
	}
}
Exemplo n.º 2
0
bool AxisBinding::FromString(const char *str, AxisBinding &ab) {
	if (strcmp(str, "disabled") == 0) {
		ab.Clear();
		return true;
	}

	const char *p = str;

	if (p[0] == '-') {
		ab.direction = NEGATIVE;
		p++;
	}
	else
		ab.direction = POSITIVE;

	if (strncmp(p, "Joy", 3) != 0)
		return false;
	p += 3;

	const int JoyUUIDLength = 33;
	char joyUUIDBuf[JoyUUIDLength];

	// read the UUID
	if (!ReadToTok('/', &p, joyUUIDBuf, JoyUUIDLength)) {
		return false;
	}
	// force terminate
	joyUUIDBuf[JoyUUIDLength-1] = '\0';
	// now, map the GUID to a joystick number
	const int joystick = Pi::JoystickFromGUIDString(joyUUIDBuf);
	if (joystick == -1) {
		return false;
	}
	// found a joystick
	assert(joystick < 256);
	ab.joystick = Uint8(joystick);

	if (strncmp(p, "Axis", 4) != 0)
		return false;

	p += 4;
	ab.axis = atoi(p);

	return true;
}
Exemplo n.º 3
0
AxisBinding AxisBinding::FromString(const char *str) {
	AxisBinding ab;
	if (!AxisBinding::FromString(str, ab))
		ab.Clear();
	return ab;
}