Esempio n. 1
0
int MFInput_Thread(void *)
{
	// poll input at high frequency...
	uint64 freq = MFSystem_GetRTCFrequency();
	uint64 interval = freq / gInputFrequency;

	uint64 now = MFSystem_ReadRTC();
	uint64 nextSample = now + interval;

	while(!bInputTerminate)
	{
		MFThread_LockMutex(gInputMutex);
		bThreadUpdate = true;
		MFInput_Update();
		bThreadUpdate = false;

		// build events
		for(uint32 i=0; i<MFInput_MaxInputID; ++i)
		{
			if(!gDeviceStatus[IDD_Gamepad][i] == IDS_Ready)
				continue;

			for(uint32 j=0; j<GamepadType_Max; ++j)
			{
				if(gNumEvents[IDD_Gamepad][i] >= MaxEvents)
					break;

				MFGamepadState &state = gGamepadStates[i];
				MFGamepadState &prev = gPrevGamepadStates[i];
				if(state.values[j] == prev.values[j])
					continue;

				MFInputEvent &e = gInputEvents[IDD_Gamepad][i][gNumEvents[IDD_Gamepad][i]++];
				e.timestamp = now;
				e.event = MFIE_Change;
				e.input = j;
				e.state = state.values[j];
				e.prevState = prev.values[j];
			}
		}

		MFThread_ReleaseMutex(gInputMutex);

//		uint64 updateTime = MFSystem_ReadRTC();
//		MFDebug_Log(0, MFStr("Input update: %dus", (uint32)((updateTime - now) * 1000000LL / MFSystem_GetRTCFrequency())));

		uint32 ms = (uint32)((nextSample - now) * 1000LL / freq);
		MFThread_Sleep(ms);

		now = MFSystem_ReadRTC();
		do
			nextSample += interval;
		while(now >= nextSample);
	}

	bInputTerminate = false;
	return 0;
}
Esempio n. 2
0
// Functions
MFInitStatus MFInput_InitModule()
{
	MFZeroMemory(gGamepadStates, sizeof(gGamepadStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gKeyStates, sizeof(gKeyStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gMouseStates, sizeof(gMouseStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gAccelerometerStates, sizeof(gAccelerometerStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gTouchPanelStates, sizeof(gTouchPanelStates[0])*MFInput_MaxInputID);

	MFInput_InitModulePlatformSpecific();
	MFInput_Update();

	return MFAIC_Succeeded;
}
Esempio n. 3
0
// Functions
MFInitStatus MFInput_InitModule(int moduleId, bool bPerformInitialisation)
{
	MFZeroMemory(gGamepadStates, sizeof(gGamepadStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gKeyStates, sizeof(gKeyStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gMouseStates, sizeof(gMouseStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gAccelerometerStates, sizeof(gAccelerometerStates[0])*MFInput_MaxInputID);
	MFZeroMemory(gTouchPanelStates, sizeof(gTouchPanelStates[0])*MFInput_MaxInputID);

	MFInput_InitModulePlatformSpecific();
	MFInput_Update();

	return MFIS_Succeeded;
}