Skip to content

Instantly share code, notes, and snippets.

@Swyter
Last active July 8, 2022 03:28
Show Gist options
  • Save Swyter/28166c9aa440b03c82705a2ca0be9a35 to your computer and use it in GitHub Desktop.
Save Swyter/28166c9aa440b03c82705a2ca0be9a35 to your computer and use it in GitHub Desktop.
PC game port best practices
  • Always use scancodes for keyboard game input to make WASD work even under DVORAK or AZERTY layouts; you care about the key position, not the meaning.

    • Use keycodes to retrieve the actual key meaning/value when you need actual text input.
  • Support paths bigger than 256 characters (MAX_PATH), this should no longer be a limitation. Launch your game from a folder or symlink with hundreds of characters; this can be combined with the next point.

  • Try your game with a special username/user account that has international characters and spaces, like Ñame áôeÓ®他の詩っステム 元バ to ensure you are handling Unicode paths correctly. This is especially tricky on Windows, where you will have to wrap fopen() with the UTF-16 version because the normal version does not understand UTF-8.

    • Very often players with non-English names won't be able to save under AppData or their home directory otherwise.
  • On Windows you should store your savegames under the special %USERPROFILE%\Saved Games folder, use a dynamically-loaded SHGetKnownFolderPath(FOLDERID_SavedGames, ...) function to find it, because the user can move it, and fall back to a getenv("USERPROFILE") otherwise.

    • Your game configuration files should still reside under %AppData%; ensure there is separation between savegames and per-user settings.
  • On Linux you should not pollute the main user folder (do not use $HOME) and stick to getenv("XDG_CONFIG_HOME"), falling back to $HOME/.config when the environment variable is missing.

    • Follow the XDG Base Directory spec; there is also $XDG_DATA_HOME and $XDG_CACHE_HOME; I would use the DATA for savegames, CONFIG for settings, and CACHE for temporary/downloaded files.
  • Have a nice 256px icon (or even bigger) in your executable, players will often see that in their desktops. On Linux include one or more PNG files in your install folder so that players can use them for shortcut icons.

    • Many AAA games still only include ugly low-res icons in their executables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment