• Partagez
  • E-mail
  • Intégrer
  • J'aime
  • Télécharger
  • Contenu privé
 

Linux as a gaming platform, ideology aside

on

  • 21,449 vues

Linux commonly connotes with open-source zealots and a small PC market ...

Linux commonly connotes with open-source zealots and a small PC market
share, not blockbuster video games. However, the arrival of Steam on
the platform might change the outlook quite dramatically, and Linux
support may soon become a must-have feature for your game. Setting the
open-source ideology aside, this lecture is an overview of the
technical challenges a game developer may face while porting their
game to this platform, along with solutions.

Statistiques

Vues

Total des vues
21,449
Vues sur SlideShare
4,821
Vues externes
16,628

Actions

J'aime
0
Téléchargements
32
Commentaires
1

15 Ajouts 16,628

http://www.phoronix.com 13083
http://www.benchmark.pl 3341
http://www.redditmedia.com 168
http://translate.googleusercontent.com 11
http://forums.uberent.com 8
http://phoronix.com 6
http://plus.url.google.com 2
http://www.reddit.com 2
https://twitter.com 1
http://www.phoronix.com&_=1372572223283 HTTP 1
http://131.253.14.66 1
https://www.google.com 1
http://localhost 1
http://newspointview.opoint.com 1
http://news.google.com 1
Plus...

Accessibilité

Catégories

Détails de l'import

Uploaded via as Adobe PDF

Droits d'utilisation

© Tous droits réservés

Report content

Signalé comme inapproprié Signaler comme inapproprié
Signaler comme inapproprié

Indiquez la raison pour laquelle vous avez signalé cette présentation comme n'étant pas appropriée.

Annuler

11 sur 1 précédent suivant

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Votre message apparaîtra ici
    Processing...
  • Leszek also posted a few corrections: http://slideshare.net/LeszekGodlewski/linuxgames-errata
    Are you sure you want to
    Votre message apparaîtra ici
    Processing...
Poster un commentaire
Modifier votre commentaire

    Linux as a gaming platform, ideology aside Linux as a gaming platform, ideology aside Presentation Transcript

    • Linux as a gaming platformIdeology asideDigital Dragons · 19-04-2013Leszek GodlewskiProgrammerleszek.godlewski@thefarm51.comwww.thefarm51.com
    • 2What is this talk about?www.thefarm51.comIts NOT about:● Free software● Ideology● BusinessIt is about:● Linux 101● Development● Deployment2
    • 3Who is this guy?www.thefarm51.comCross-platform work(→ de facto – Linux)● github.com/inequation● Toy projects, personal utilities,university stuff● Games as well!● AC-130● Crystal Space● idTech 3-based games● Painkiller Hell & Damnation● Linux as preferred OS for 7+ years● Former open-source evangelist● Not anymore – lost interest3
    • 4Who is this guy?www.thefarm51.com4WHAT IF I TOLD YOUWE PREACHED FREE SOFTWARE
    • 5Who is this guy?www.thefarm51.com5
    • 6www.thefarm51.comLinux 1016
    • 7OMG LINUX!!11www.thefarm51.com7
    • 8OMG LINUX!!11www.thefarm51.comRichard M. StallmanSource: http://commons.wikimedia.org/wiki/File:RMS_iGNUcius_techfest_iitb.JPG8
    • 9OMG LINUX!!11www.thefarm51.com“F**k you, NVIDIA!” - Linus TorvalsSource: http://www.youtube.com/watch?v=iYWzMvlj2RQ9
    • 10Kernel and the distroswww.thefarm51.com10Linux distro(Ubuntu, Debian, Fedora...)Linux distro(Ubuntu, Debian, Fedora...)LinuxkernelLinuxkernelFreesoftwareFreesoftwareProprietarysoftwareProprietarysoftware27+ supported CPU architectures!http://en.wikipedia.org/wiki/List_of_Linux_supported_architecturesWe usually mean i386/amd64
    • 11Who and why uses Linux?www.thefarm51.com11Who:● Scientists (TOP500)● IT companies● Hackers andpower usersWhy:● Its free (well, duh...)● Its robust● Its customizable● Long, intrinsic traditions of free software● No established channels of proprietarysoftware distribution● But Steam can become a gamechanger!
    • 12Standardswww.thefarm51.com● Linux adheres to ISO/IEC standards, suchas POSIX and Single Unix Specification...● System API – file system access, threading,access control, IPC etc.● Command-line shell utilities● ...which also happen to be supported byMacOS X, Android, iOS (yes, really!) anda handful of other OSes12
    • 13Standardswww.thefarm51.com● Linux has OpenGL (ES) for 3D graphicsrendering● Linux has OpenAL for 3D audio with DSP● Linux has BSD sockets for networking● Linux has lots of other portable libraries● And all of these things are also availableon other platforms – Android, MacOS X,iOS, Windows!13
    • 14What does that mean?www.thefarm51.com14MacOS XLinux Mobile** not to scale; actualoverlap is greater
    • 15There are issues, toowww.thefarm51.com● Open source legacy → unstable ABIs● Why need a stable one when you can justrecompile the source?● This is why NVIDIA distributes glue code withtheir drivers● Extreme heterogeneity● Package managers (software distributionmechanisms)● Patches applied to upstream code → potentialdifferences in functionality● Highly customized system configurations15
    • 16There are issues, toowww.thefarm51.com● Proprietary vs free GPU drivers● Rule of thumb: free drivers perform morepoorly than proprietary ones● Intel only has free, but the hardware is bad anyway ☺● Legacy AMD/ATI GPUs only have free, and its quitegood actually● NVIDIA drivers are equally good as theWindows ones● AMD/ATI drivers are a bit worse than theWindows ones ☹16
    • 17Solution?www.thefarm51.com17Assume Ubuntu.● For development and testing alike● Probably the most popular desktopdistro*● This is what Valve does- Bonus points: Steam compatiblity!● Power users will get your game runningon others anyway* there are claims its Linux Mint now, but its still based on Ubuntu
    • 18www.thefarm51.comDevelopment18
    • 19Getting startedwww.thefarm51.com● Virtual machine● Fair enough for building● No such luck with testing(unless you can virtualise your GPU)● Native installation● Painless dual boot● Which disc image to download?● Get whatever Valve recommends forSteam(the Most recent LTS release is a good bet)19
    • 20Toolswww.thefarm51.com● Tons and tons of IDEs, mostly average- Code::Blocks, Codelite are OK- Theres also Eclipse if you can stand it● Tried & tested native code toolchains- GCC, LLVM (clang)- gold – the new multithreaded linker by Google- GNU binutils – objcopy, objdump etc.● VM toolchains- Mono, OpenJDK/Oracle JDK● Build tools- GNU make, Cmake, SCons, GNU autotools20
    • 21Debuggingwww.thefarm51.comCPU● Classic command-line gdb, gdbserver● Tons of front-ends- cgdb (command-line)- Nemiver, DDD (GUI)Graphics● gDEBugger/CodeXL● NVIDIA Nsight forEclipse● apitrace21
    • 22SDL – the cross-platform “DirectX”www.thefarm51.com● Provides:- API in C with mappings to other languages- Timers and threads- Input – mouse, keyboard, joysticks/pads (incl.Unicode characters)- Window management (incl. GL context)- Audio (very barebone)- 2D graphics (hardware blitting)● Be sure to use 2.0 for new projects!- Support for OpenGL 3+- Support for multi-viewport apps22
    • 23SDL – the cross-platform “DirectX”www.thefarm51.com● SDL hides away most platform-specific code- Thats right, no need to even use POSIX!23int main (int argc, char *argv[]){// initialize SDLif (SDL_Init(SDL_INIT_VIDEO| SDL_INIT_TIMER) < 0)return 1;// set window captionSDL_WM_SetCaption("My SDL Game","MySDLGame");// hide mouse, grab inputSDL_ShowCursor(0);SDL_WM_GrabInput(SDL_GRAB_ON);// make SDL clean up on exitatexit(SDL_Quit);// main game loopwhile (1) {// dispatch eventswhile (SDL_PollEvent(&ev)){switch (event.type) {// ...}}}SDL_ShowCursor(1);SDL_WM_GrabInput(SDL_GRAB_OFF);return 0;}
    • 24What if SDL doesnt cut it?www.thefarm51.comDespite its awesomeness, SDL has itsshortcomings● No explicit GLX/WGL context data sharingand no direct context access→ no threaded rendering ☹(hit this corner while porting Painkiller HD)● No 3D positioning or DSP support in thestock SDL audio subsystem- Partially remedied by SDL_mixerBut we need those! Now what?!24
    • 25Just DIY – POSIX APIwww.thefarm51.com● Most WinAPI features map to POSIX- Threading (pthreads)- Advanced file I/O, incl. memory-mapped- Advanced memory allocation, incl. paging- IP sockets25#if defined(WIN32) || defined(__WIN32__)Emitter->InternalPtr = VirtualAlloc(NULL,Size, MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE_READWRITE);// ...#else // Its a UNIX system! I know this!Emitter->InternalPtr = mmap(NULL, Size,PROT_READ | PROT_WRITE | PROT_EXEC,MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);// ...#endif
    • 26POSIX APIwww.thefarm51.comThere is an extensive, centralised referencemanual in the manpages-dev package● Type in a shell to access:man <section number> <subject>● Section number cheat sheet1. General console commands2. System calls3. C standard library calls4. Special files (/dev/*) and drivers5. File formats and conventions26
    • 27X11 client APIwww.thefarm51.com● Windows graphical mode maps to X11- Xlib is a popular client library for the X(11) WindowSystem server- XCB is a more modern replacement (often a back-end for Xlib)- Raw event pump, window management- OpenGL interoperability via the GLX extension27// event loopXEvent Event;while (XPending(GX11Display)) {XNextEvent(GX11Display, &Event);switch (Event.type) {// ...}}
    • 28Joystick/gamepad APIwww.thefarm51.com● Not part of X11 input event framework● Kernel block devices- Created as /dev/input/js*- Hotplug events via libudev (also in SteamLinux Runtime)- Handled via open() and ioctl()- Detailed documentation in the kernelhttp://kernel.org/doc/Documentation/input/joystick-api.txt28
    • 29Porting a D3D renderer to OpenGLwww.thefarm51.com29
    • 30Porting a D3D renderer to OpenGLwww.thefarm51.com30Porting Source To Linux:Valves Lessons LearnedValve & NVIDIA, GTC 2013Video: http://goo.gl/jMX9ASlides: http://goo.gl/FtA5k
    • 31How to deal with heterogeneity?www.thefarm51.com● As mentioned earlier, library ABIs tend tobe unstable- Glibc tags its symbols with version → multipleversions for backwards compatibility- Compile with newest version → binary might notrun on older versions● The ELF format is constant; but even then:- Dynamic libraries “sonames” (including versionnumbers) are baked in at link time → binary mightnot run if system provides a different version31
    • 32How to deal with heterogeneity?www.thefarm51.com32How?Static linking+ will work forever- binary bloatDistribute with libs+ will work forever- redundant to othergames (also a form ofbloat)- potential licensingissues
    • 33How to deal with heterogeneity?www.thefarm51.com33Or use the Steam Linux Runtimehttps://github.com/ValveSoftware/steam-runtime● Collection of essential packages “ripped”from Ubuntu repos + patches- freetype, glew, gtk+2.0, libgsm, libogg, libopenal1, libsdl1.2,libsdl2, libvorbis, libtheora, libx11, libxcb, pulseaudio...- Release and debug versions of all libs● Ready-to-use GCC-based toolchains fori386 and amd64● Ships with Steam, so every (non-orthodox)Linux gamer has it
    • 34Steam Runtime for non-Steam gameswww.thefarm51.com● Start-up shell scripts are common practice- Search for an installed Steam Runtimeinstance- If not found, install your private copy- Only when the SLR is available, run theactual binary34
    • 35Steam Runtime for non-Steam gameswww.thefarm51.com35#!/bin/shif [ -z $STEAM_RUNTIME ]; thenSTEAM_RUNTIME=$HOME/.steam/steam/ubuntu12_32/steam-runtimefiif [ ! -d $STEAM_RUNTIME ]; then# install private copy of Steam Runtimefiexport LD_LIBRARY_PATH="$STEAM_RUNTIME/i386/lib/i386-linux-gnu:""$STEAM_RUNTIME/i386/lib:""$STEAM_RUNTIME/i386/usr/lib/i386-linux-gnu:""$STEAM_RUNTIME/i386/usr/lib:""$STEAM_RUNTIME/amd64/lib/x86_64-linux-gnu:""$STEAM_RUNTIME/amd64/lib:""$STEAM_RUNTIME/amd64/usr/lib/x86_64-linux-gnu:""$STEAM_RUNTIME/amd64/usr/lib:""$LD_LIBRARY_PATH"# launch the actual game here
    • 36Localeswww.thefarm51.com● The C standard defines locales for languageand regional settings (see man setlocale)● They affect *printf()/*scanf() and more● Xlib can modify locale categories for GUIapps (see man XSetLocaleModifiers)● Example POSIX locales: pl_PL.UTF8,en_GB.ISO-8859-1, ru_RU.KOI8-R● The Linux manual might make it seem likeretrieving current locale is as easy as callingchar *locale = setlocale(LC_ALL, NULL);36
    • 37Localeswww.thefarm51.comNo such luck!// backup the original application localechar *Locale = setlocale(LC_ALL, NULL);char *OriginalLocale = NULL;if (Locale && *Locale)OriginalLocale = strdup(Locale);// reset locale to system (user) defaultsetlocale(LC_ALL, "");// retrieve the default localeLocale = setlocale(LC_ALL, NULL);// process locale here// restore original localeif (OriginalLocale){setlocale(LC_ALL, OrigLocale);free(OriginalLocale);}37
    • 38Extracting debugging symbolswww.thefarm51.com● We often want to keep symbols forshipping binaries● On Windows – keep the .pdb files● On Linuxobjcopy --only-keep-debug "${tostripfile}" "${debugdir}/${debugfile}"strip --strip-debug --strip-unneeded "${tostripfile}"objcopy --add-gnu-debuglink= "${debugdir}/${debugfile}" "${tostripfile}"38
    • 39Crash handlerwww.thefarm51.com● On POSIX this is called a signal handler● Signals are a primitive IPC mechanism usednot only for crashes- Debugger traps, floating point exceptions, terminalhangup, exit requests... See the output of kill -l● You can take a shortcut by using:- libSegFault – part of glibc, try:$ LD_PRELOAD=/lib/libSegFault.so /lib/libSegFault.so- Andrew Tridgells segv_handlerhttp://www.samba.org/junkcode/#segv_handler39
    • 40A word on licensingwww.thefarm51.comWhenever you use a library, check itslicensing terms!● GPL is restrictive- Requires derivative works to use GPL→ sharing the source code● LGPL is restrictive with linking exception- Allows linking to an LGPL library withoutsharing the source code● MIT, BSD and Zlib licenses are generallypermissive, some might require advertising40
    • 41www.thefarm51.comDeployment41
    • 42Where do I put the files?www.thefarm51.com● Windows- Game data and binaries: C:Program Files- User data: %APPDATA%, Documents...- AoS-like organization● Linux (conventional)- Game binaries: /usr/bin/, /usr/games/- Game data: /usr/share/games/- User data: $HOME/.config/($XDG_CONFIG_HOME environment variable)- SoA-like organization- Filesystem Hierarchy Standard42
    • 43Where do I put the files?www.thefarm51.com● FHS mainly concerns distro packages● Proprietary software often installs into/opt/<package name>/(“Add-on application software packages”)● Proprietary software also often installs“wherever”● Steam games live in~/.steam/steam/SteamApps/● Just put game data and binaries in oneplace, and save user data to ~/.config/43
    • 44Creating installation bundleswww.thefarm51.com● Not relevant for Steam games (duh)● Simple .tar.gz archives$ tar czvf <archive name> <input files...>● Distro packages (.rpm, .deb...)● Self-extracting command-line installers asshell scriptshttps://coderwall.com/p/y3upqw● MojoSetuphttp://icculus.org/mojosetup/44
    • 45www.thefarm51.comSummary45
    • 46Summarywww.thefarm51.com● Engineering costs of a Linux port for analready multiplatfrom game engine are low- “Its just an API”™● SDL covers a lot of boilerplate for you● Overcoming heterogeneity is essential- Steam Linux Runtime is helping to fix it● Watch out for those licenses!● When in doubt:- Use Ubuntu- Do whatever Valve does46
    • 47www.thefarm51.comQuestions?leszek.godlewski@thefarm51.com47
    • 48Special thankswww.thefarm51.comRyan “Icculus” GordonInspiration & software contributionsMichał WielgusCritical review & free software comradeReinhard PolliceGetting stuff done for me on the PKHD port48
    • 49Thank you!Like us on Facebook!http://www.facebook.com/farm51http://www.facebook.com/deadfalladventureshttp://www.facebook.com/PainkillerGameleszek.godlewski@thefarm51.comwww.thefarm51.com