int CreateEffectBinding()

in Lilypad/Config.cpp [1125:1156]


int CreateEffectBinding(Device *dev, wchar_t *effectID, unsigned int port, unsigned int slot, unsigned int motor, ForceFeedbackBinding **binding) {
	// Checks needed because I use this directly when loading bindings.
	// Note: dev->numFFAxes *can* be 0, for loading from file.
	*binding = 0;
	if (port > 1 || slot>3 || motor > 1 || !dev->numFFEffectTypes) {
		return -1;
	}
	ForceFeedbackEffectType *eff = 0;
	if (effectID) {
		eff = dev->GetForcefeedbackEffect(effectID);
	}
	if (!eff) {
		eff = dev->ffEffectTypes;
	}
	if (!eff) {
		return -1;
	}
	int effectIndex = eff - dev->ffEffectTypes;
	dev->pads[port][slot].ffBindings = (ForceFeedbackBinding*) realloc(dev->pads[port][slot].ffBindings, (dev->pads[port][slot].numFFBindings+1) * sizeof(ForceFeedbackBinding));
	int newIndex = dev->pads[port][slot].numFFBindings;
	while (newIndex && dev->pads[port][slot].ffBindings[newIndex-1].motor >= motor) {
		dev->pads[port][slot].ffBindings[newIndex] = dev->pads[port][slot].ffBindings[newIndex-1];
		newIndex--;
	}
	ForceFeedbackBinding *b = dev->pads[port][slot].ffBindings + newIndex;
	b->axes = (AxisEffectInfo*) calloc(dev->numFFAxes, sizeof(AxisEffectInfo));
	b->motor = motor;
	b->effectIndex = effectIndex;
	dev->pads[port][slot].numFFBindings++;
	if (binding) *binding = b;
	return ListBoundEffect(port, slot, dev, b);
}