void CInputDeviceState::UpdateRestEvents(CInputDeviceValues* pcEvents, unsigned int uiSequence)
{
	int					i;
	SInputSourceState*	psState;
	CInputSourceDesc*	pcSourceDesc;
	BOOL				bNewValue;
	float				fValue;

	for (i = 0; i < macSourceStates.NumElements(); i++)
	{
		psState = macSourceStates.Get(i);
		pcSourceDesc = psState->pcDesc;
		if (!(psState->iFlags & SOURCE_STATE_EMITTED_EVENT))
		{
			if (psState->pcDesc->GetEmitRestEvent())
			{
				fValue = pcSourceDesc->GetRestValue();
				bNewValue = SetValue(psState, fValue);
				if (bNewValue)
				{
					pcEvents->Add(mpcDevice, pcSourceDesc, fValue, uiSequence, TRUE, 0);
				}
			}
		}

		if (psState->fValue == pcSourceDesc->GetRestValue())
		{
			psState->iFlags |= SOURCE_STATE_RESTING;
		}
	}
}
void CInputDeviceDesc::CopySources(CInputDeviceCopyContext* pcContext)
{
	CInputSourceDesc*	pcInputSourceDesc;
	CInputSourceDesc*	pcInputDestDesc;
	int					iNumInputs;
	SSetIterator		sIter;

	iNumInputs = mlcInputs.NumElements();
	pcInputSourceDesc = pcContext->mpcSourceDeviceDesc->mlcInputs.StartIteration(&sIter);
	while (pcInputSourceDesc)
	{
		pcInputDestDesc = mlcInputs.Add();
		pcInputDestDesc->Init(this, pcInputSourceDesc->GetType(), pcInputSourceDesc->GetFriendlyName(), pcInputSourceDesc->GetStateIndex() + iNumInputs);
		pcInputDestDesc->SetRest(pcInputSourceDesc->GetRestValue(), pcInputSourceDesc->GetEmitRestEvent(), pcInputSourceDesc->HasRestValue());
		pcInputDestDesc->CopyValues(pcInputSourceDesc);
		pcInputDestDesc->CopyActions(pcInputSourceDesc);
		pcContext->mmppSources.Put(pcInputSourceDesc, pcInputDestDesc);
		pcInputSourceDesc = pcContext->mpcSourceDeviceDesc->mlcInputs.Iterate(&sIter);
	}
}
BOOL CInputDeviceState::Rest(CInputDevice* pcDevice)
{
	int					i;
	CInputSourceDesc*	pcSourceDesc;
	SInputSourceState*	psSourceState;
	SSetIterator		sIter;

	mpcDevice = pcDevice;
	macSourceStates.Kill();
	macSourceStates.Allocate(&gcSystemAllocator, pcDevice->GetDesc()->NumInputs());
	pcSourceDesc = pcDevice->GetDesc()->StartInputsIteration(&sIter);
	i = 0;
	while (pcSourceDesc)
	{
		psSourceState = macSourceStates.Get(i);
		psSourceState->pcDesc = pcSourceDesc;
		if (psSourceState->pcDesc->HasRestValue())
		{
			psSourceState->iFlags = SOURCE_STATE_RESTING | SOURCE_STATE_VALID;
			psSourceState->fValue = pcSourceDesc->GetRestValue();
		}
		else
		{
			psSourceState->iFlags = 0;
			psSourceState->fValue = 0.0f;
		}

		if (pcSourceDesc->GetStateIndex() != i)
		{
			return FALSE;
		}

		pcSourceDesc = pcDevice->GetDesc()->IterateInputs(&sIter);
		i++;
	}
	return TRUE;
}