By background thread do you mean simply spawning a thread at the start of the application and using that to make API calls while the rest of the application runs? That would still be multithreading though right, The things I've been hearing horror stories about?
Yeah. Don't worry about it in this case though. It won't be too hard for this purpose.
As long as you carefully manage how you access data on each thread, it's unlikely that anything bad would happen. There are only two things you're dealing with in this case: a queue of input, and a flag to exit the background thread when the main thread wants it to shut down.
A simple pseudocode implementation would be:
// start this function as a thread during app startup
void InputReadingThreadFunction()
{
while (main thread has not requested that the input thread terminate) // probably OK with a normal bool with no special synchronization
{
if input is available in XInput
{
put that input into a synchronized queue
}
}
}
void MainThreadInputPollingFunction()
{
// Do this instead of reading from XInput on your main thread
while (input is available in synchronized queue)
{
Process that input
}
}
The type of queue, variables, etc depend on the language and APIs you have available.