Skip to content

Instantly share code, notes, and snippets.

@Kangz
Created December 30, 2014 03:52
Show Gist options
  • Save Kangz/69c63d045191e885dcda to your computer and use it in GitHub Desktop.
Save Kangz/69c63d045191e885dcda to your computer and use it in GitHub Desktop.

Constraints

  • SDL_Init(SDL_VIDEO) mustbe made on the main thread (same thing for SDL_Shutdown?)
  • SDL_PumpEvents and SDL_PollEvent must be made on the thread that did SDL_Init(SDL_VIDEO)
  • We want to show a splash screen as soon as the game starts and continue pumping events while the game starts (if we do not pump events, some window managers will believe the program froze and make a popup appear).
  • Same thing, when the map loads we want to continue pumping events
  • Functions used outside of sdl_input.cpp: IN_Frame IN_Init IN_Shutdown In_Restart_f

Ideas of how to make it

It seems the main file that will change will be sdl_input.cpp, its role is to fill the event queue Q that is consumed in Com_Frame. The input thread will instead of filling directly Q, put events in a shared mutexed queue S whose content is dequeued in Com_Frame to go in Q. However IN_Frame and potentially other functions will need to be synchronous. SDL supports inserting custom events in the queue, we can use that to insert functions pointers that will be ran on the input thread.

Future work ideas

  • Put the mouse coordinates in a global variable so that the renderer can sample it just before it starts rendering and shift the frustum by the right amount? (what about 2d things that follow 3d things?)
  • Make it handle the network as well?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment