0% found this document useful (0 votes)
102 views49 pages

Linux Games PDF

This document discusses using Linux as a gaming platform. It begins by stating the talk will focus on Linux development and deployment, not ideology or business. It then provides biographical information about the speaker, including their experience programming games for Linux. The rest of the document covers various aspects of developing games for Linux, such as tools, debugging, standards, and porting renderers to OpenGL. It also discusses issues like proprietary drivers and heterogeneity between distributions. Throughout, it emphasizes using the Steam Linux Runtime to help address challenges of porting to Linux.

Uploaded by

inequation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views49 pages

Linux Games PDF

This document discusses using Linux as a gaming platform. It begins by stating the talk will focus on Linux development and deployment, not ideology or business. It then provides biographical information about the speaker, including their experience programming games for Linux. The rest of the document covers various aspects of developing games for Linux, such as tools, debugging, standards, and porting renderers to OpenGL. It also discusses issues like proprietary drivers and heterogeneity between distributions. Throughout, it emphasizes using the Steam Linux Runtime to help address challenges of porting to Linux.

Uploaded by

inequation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

www.thefarm51.

com

Linux as a gaming platform


Ideology aside

Leszek Godlewski Programmer [email protected] Digital Dragons 19-04-2013

What is this talk about?

It's NOT about:


Free software Ideology Business

It is about:

Linu 1!1 "e#elo$ment "e$loyment

www.thefarm51.com

Who is this guy?

Cross-platform work
&' de facto ( Linu )

githu*.com+ine,uation -oy $ro.ects/ $ersonal utilities/ uni#ersity stuff 0ames as well1 2341%! 3rystal 5$ace id-ech %4*ased games Painkiller Hell !amnation Linu as $referred 65 for 78 years Former o$en4source e#angelist

Not an"more ( lost interest

www.thefarm51.com

Who is this guy?

WHAT IF I TOLD YOU

WE PREACHED FREE SOFTWARE


9 www.thefarm51.com

Who is this guy?

www.thefarm51.com

Linux 101
: www.thefarm51.com

OMG LINUX!!11

www.thefarm51.com

OMG LINUX!!11

<ichard =. 5tallman
5ource> htt$>++commons.wikimedia.org+wiki+File><=5?i0@Acius?techfest?iit*.BP0

www.thefarm51.com

OMG LINUX!!11

DFEEk you/ @FI"I21G 4 Linus -or#als


5ource> htt$>++www.youtu*e.com+watchH#IiJKz=#l.2<L

www.thefarm51.com

1!

Kernel and the distros

$%buntu& $%buntu&!ebian& !ebian&'edora((() 'edora((()

Linu# Linu# distro distro


'ree 'ree software software

Linu# Linu# kernel kernel

Proprietar" Proprietar" software software

*+, supported CP% ar-.ite-tures/


htt$>++en.wiki$edia.org+wiki+List?of?Linu ?su$$orted?architectures

Ke usually mean i%;:+amd:9

1!

www.thefarm51.com

11

Who and why uses Linu ?

0.o:

5cientists &-6P5!!) I- com$anies Ha-kers and power users

0.":

ItMs free &well/ duh...) ItMs ro*ust It's -ustomizable

Long/ intrinsic traditions of free software @o esta*lished channels of $ro$rietary software distri*ution But 1team can *ecome a 2ame-.an2er/
11 www.thefarm51.com

12

!tandards

Linu adheres to I56+IN3 standards/ such as PO1I3 and 1in2le %ni# 1pe-ifi-ation...
5ystem 2PI ( file system access/ threading/ access control/ IP3 etc. 3ommand4line shell utilities

...which also ha$$en to *e su$$orted *y 4a-O1 3/ 5ndroid/ iO1 &yes/ really1) and a handful of other 65es

12

www.thefarm51.com

1%

!tandards

Linu has OpenGL $61) for %" gra$hics rendering Linu has Open5L for %" audio with "5P Linu has 71! so-kets for networking Linu has lots of other $orta*le li*raries 2nd all of these things are also a#aila*le on other $latforms ( 5ndroid/ 4a-O1 3/ iO1/ 0indows1

1%

www.thefarm51.com

19

What does that "ean?

Linu

=o*ile

=ac65 O
E not to scaleP actual o#erla$ is greater
19 www.thefarm51.com

15

#here are issues$ too

6$en source legacy ' unsta*le 2BIs


Khy need a sta*le one when you can .ust recom$ile the sourceH -his is why @FI"I2 distri*utes glue code with their dri#ers

6#treme heterogeneity

Package managers &software distri*ution mechanisms) Patches a$$lied to u$stream code ' $otential differences in functionality Qighly customized system configurations
15 www.thefarm51.com

1:

#here are issues$ too

Pro$rietary #s free 0PA dri#ers <ule of thum*> free dri#ers $erform more $oorly than $ro$rietary ones

Intel only has free/ *ut the hardware is *ad anyway Legacy 2="+2-I 0PAs only ha#e free/ and itMs ,uite good actually

@FI"I2 dri#ers are e,ually good as the Kindows ones 2="+2-I dri#ers are a *it worse than the Kindows ones

1:

www.thefarm51.com

17

!olution?

5ssume %buntu(
For de#elo$ment and testing alike Pro*a*ly the most $o$ular deskto$ distroE -his is what Fal#e does - Bonus $oints> 5team com$ati*lity1 Power users will get your game running on others anyway

E there are claims itMs Linu =int now/ *ut itMs still *ased on A*untu
17 www.thefarm51.com

1;

Development
1; www.thefarm51.com

1C

Getting started

8irtual ma-.ine Fair enough for *uilding @o such luck with testing

&unless you can #irtualise your 0PA)

Nati9e installation Painless dual *oot 0.i-. dis- ima2e to download: 0et whate#er Fal#e recommends for 5team

&the =ost recent L-5 release is a good *et)


1C www.thefarm51.com

2!

#ools

-ons and tons of I"Ns/ mostly a#erage


- Code::7lo-ks/ Codelite are 6R - -hereMs also 6-lipse if you can stand it

-ried S tested nati#e code toolchains


- GCC/ LL84 &-lan2) - 2old ( the new multithreaded linker *y 0oogle - 0@A binutils ( o*.co$y/ o*.dum$ etc.

F= toolchains
- 4ono/ Open;!<+Ora-le ;!<

Build tools

- 0@A make/ Cmake/ 1Cons/ 0@A autotools


2! www.thefarm51.com

21

%ebugging

3PA 3lassic command4 line 2db/ 2dbser9er -ons of front4ends 0ra$hics 2!67u22er+Code3L N8I!I5 Nsi2.t for Ncli$se apitra-e
21

- -2db &command4line) - Nemi9er/ !!! &0AI)

www.thefarm51.com

22

!%L & the 'ross()lat*or" +%ire'tX,

Pro#ides>
- 2PI in 3 with ma$$ings to other languages - -imers and threads - In$ut ( mouse/ key*oard/ .oysticks+$ads &incl. Anicode characters) - Kindow management &incl. 0L conte t) - 2udio &#ery *are*one) - 2" gra$hics &hardware *litting)

Be sure to use 2.! for new $ro.ects1


- 5u$$ort for 6$en0L %8 - 5u$$ort for multi4#iew$ort a$$s

22

www.thefarm51.com

2%

!%L & the 'ross()lat*or" +%ire'tX,

5"L hides away most $latform4s$ecific code - -hatMs right/ no need to e#en use P65IO1
// main game l--. +hile (() { // ,i*.atch event* +hile (SDL_:-ll vent(;ev)){ *+itch (event<t2.e) { // <<< = = = SDL_Sh-+0'r*-r(()) SDL_/#_3ra4In.'t(SDL_3$56_!>>)) ret'rn &)

int main (int argc, char *argv[]) { // initialize SDL if (SDL_Init(SDL_INIT_VID ! " SDL_INIT_TI# $) % &) ret'rn () // *et +in,-+ ca.ti-n SDL_/#_Set0a.ti-n(1#2 SDL 3ame1, 1#2SDL3ame1)) // hi,e m-'*e, gra4 in.'t SDL_Sh-+0'r*-r(&)) SDL_/#_3ra4In.'t(SDL_3$56_!N)) // ma7e SDL clean '. -n e8it ate8it(SDL_9'it)) 2%

www.thefarm51.com

29

What i* !%L doesn-t 'ut it?

"es$ite its awesomeness/ 5"L has its shortcomings @o e $licit 0LO+K0L conte t data sharing and no direct conte t access ' no threaded rendering

@o %" $ositioning or "5P su$$ort in the stock 5"L audio su*system - Partially remedied *y 5"L?mi er 7ut we need t.ose/ Now w.at:/

&hit this corner while $orting Painkiller Q")

29

www.thefarm51.com

25

.ust %I/ & 0O!IX 10I

=ost Kin2PI features ma$ to P65IO


- -hreading &$threads) - 2d#anced file I+6/ incl. memory4ma$$ed - 2d#anced memory allocation/ incl. $aging - IP sockets
?if ,efine,(/IN@A) "" ,efine,(__/IN@A__) mitterBCInternal:tr D Virt'al5ll-c(NELL, Size, # #_0!##IT " # #_$ S $V , :53 _ F 0ET _$ 5D/$IT )) // <<< ?el*e // ItG* a ENIF *2*temH I 7n-+ thi*H mitterBCInternal:tr D mma.(NELL, Size, :$!T_$ 5D " :$!T_/$IT " :$!T_ F 0, #5:_:$IV5T " #5:_5N!NI#!ES, B(, &)) // <<< ?en,if

25

www.thefarm51.com

2:

0O!IX 10I

-here is an e tensi#e/ centralised reference manual in the man.age*B,ev $ackage -y$e in a shell to access>
man %*ecti-n n'm4erC %*'4JectC

5ection num*er cheat sheet 1. 0eneral console commands 2. 5ystem calls %. 3 standard li*rary calls 9. 5$ecial files &/,ev/*) and dri#ers 5. File formats and con#entions
www.thefarm51.com

2:

27

X11 'lient 10I

Kindows gra$hical mode ma$s to O11


- 3lib is a $o$ular client li*rary for the O&11) Kindow 5ystem ser#er - 3C7 is a more modern re$lacement &often a *ack4 end for Oli*) - <aw e#ent $um$/ window management - 6$en0L intero$era*ility #ia the 0LO e tension
// event l--. F vent vent) +hile (F:en,ing(3F((Di*.la2)) { FNe8t vent(3F((Di*.la2, ; vent)) *+itch ( vent<t2.e) { // <<< = =

27

www.thefarm51.com

2;

.oysti'k2ga"e)ad 10I

@ot $art of O11 in$ut e#ent framework Rernel *lock de#ices - 3reated as /,ev/in.'t/J** - Qot$lug e#ents #ia li*ude# &also in 5team Linu <untime) - Qandled #ia -.en() and i-ctl() - "etailed documentation in the kernel

htt$>++kernel.org+doc+"ocumentation+in$ut+.oystick4a$i.t t

2;

www.thefarm51.com

2C

0orting a %3% renderer to O)enGL

2C

www.thefarm51.com

%!

0orting a %3% renderer to O)enGL

Portin2 1our-e To Linu#: 8al9e's Lessons Learned


Fal#e S @FI"I2/ 0-3 2!1%
Fideo> htt$>++goo.gl+.=OC2 5lides> htt$>++goo.gl+Ft25k

%!

www.thefarm51.com

%1

4ow to deal with heterogeneity?

2s mentioned earlier/ li*rary 2BIs tend to *e unsta*le


- 0li*c tags its sym*ols with #ersion ' multi$le #ersions for *ackwards com$ati*ility - 3om$ile with newest #ersion ' *inary might not run on older #ersions

-he NLF format is constantP *ut e#en then>


- "ynamic li*rariesM DsonamesG &including #ersion num*ers) are *aked in at link time ' *inary might not run if system $ro#ides a different #ersion

%1

www.thefarm51.com

%2

4ow to deal with heterogeneity?

How:
1tati- linkin2
8 will work fore#er 4 *inary *loat

!istribute wit. libs


8 will work fore#er 4 redundant to other games &also a form of *loat) 4 $otential licensing issues
www.thefarm51.com

%2

%%

4ow to deal with heterogeneity?

6r use the 1team Linu# =untime


htt$s>++githu*.com+Fal#e5oftware+steam4runtime

3ollection of essential $ackages Dri$$edG from A*untu re$os 8 $atches


- freety$e/ glew/ gtk82.!/ li*gsm/ li*ogg/ li*o$enal1/ li*sdl1.2/ li*sdl2/ li*#or*is/ li*theora/ li* 11/ li* c*/ $ulseaudio... - <elease and de*ug #ersions of all li*s

<eady4to4use 0334*ased toolchains for i%;: and amd:9 5hi$s with 5team/ so e9er" &non4orthodo ) Linu# 2amer .as it

%%

www.thefarm51.com

%9

!tea" 5unti"e *or non(!tea" ga"es

5tart4u$ shell scri$ts are common $ractice - 5earch for an installed 5team <untime instance - If not found/ install your $ri#ate co$y - 6nly when the 5L< is a#aila*le/ run the actual *inary

%9

www.thefarm51.com

%5

!tea" 5unti"e *or non(!tea" ga"es


?H/4in/*h if [ Bz KST 5#_$ENTI# ]) then ST 5#_$ENTI# DKL!# /<*team/*team/'4'nt'(A_@A/*teamBr'ntime fi if [ H B, KST 5#_$ENTI# ]) then ? in*tall .rivate c-.2 -f Steam $'ntime fi e8.-rt LD_LI6$5$I_:5TLD1KST 5#_$ENTI# /i@MN/li4/i@MNBlin'8Bgn'O1P 1KST 5#_$ENTI# /i@MN/li4O1P 1KST 5#_$ENTI# /i@MN/'*r/li4/i@MNBlin'8Bgn'O1P 1KST 5#_$ENTI# /i@MN/'*r/li4O1P 1KST 5#_$ENTI# /am,NQ/li4/8MN_NQBlin'8Bgn'O1P 1KST 5#_$ENTI# /am,NQ/li4O1P 1KST 5#_$ENTI# /am,NQ/'*r/li4/8MN_NQBlin'8Bgn'O1P 1KST 5#_$ENTI# /am,NQ/'*r/li4O1P 1KLD_LI6$5$I_:5TL1 ? la'nch the act'al game here

%5

www.thefarm51.com

%:

Lo'ales

-he 3 standard defines lo-ales for language and regional settings &see manR*etl-cale) -hey affect *.rintf()+**canf() and more Oli* can modify locale categories for 0AI a$$s &see man FSetL-cale#-,ifier*) N am$le P65IO locales> .l_:L<ET>M/

en_36<IS!BMMSTB(/ r'_$E<U!IMB$

-he Linu manual might make it seem like retrie#ing current locale is as easy as calling
charR*l-caleRDR*etl-cale(L0_5LL, NELL))
www.thefarm51.com

%:

%7

Lo'ales

No su-. lu-k/
// 4ac7'. the -riginal a..licati-n l-cale char *L-cale D *etl-cale(L0_5LL, NELL)) char *!riginalL-cale D NELL) if (L-cale ;; *L-cale) !riginalL-cale D *tr,'.(L-cale)) // re*et l-cale t- *2*tem ('*er) ,efa'lt *etl-cale(L0_5LL, 11)) // retrieve the ,efa'lt l-cale L-cale D *etl-cale(L0_5LL, NELL)) // .r-ce** l-cale here // re*t-re -riginal l-cale if (!riginalL-cale) { *etl-cale(L0_5LL, !rigL-cale)) free(!riginalL-cale)) =
%7 www.thefarm51.com

%;

6 tra'ting debugging sy"bols

Ke often want to kee$ sym*ols for shi$$ing *inaries 6n Kindows ( kee$ the .$d* files 6n Linu

-4Jc-.2 BB-nl2B7ee.B,e4'g 1K{t-*tri.file=1 1K{,e4'g,ir=/K{,e4'gfile=1 *tri. BB*tri.B,e4'g BB*tri.B'nnee,e, 1K{t-*tri.file=1 -4Jc-.2 BBa,,Bgn'B,e4'glin7D 1K{,e4'g,ir=/K{,e4'gfile=1 1K{t-*tri.file="
%;

P P P P P

www.thefarm51.com

%C

7rash handler

6n P65IO this is called a si2nal .andler 5ignals are a $rimiti#e IP3 mechanism used not only for crashes

- "e*ugger tra$s/ floating $oint e ce$tions/ terminal hangu$/ e it re,uests... 5ee the out$ut of 7ill Bl

Jou can take a shortcut *y using>


- li*5egFault ( $art of gli*c/ try>
K LD_:$ L!5DD/li4/li4Seg>a'lt<*/li4/li4Seg>a'lt<*P

- 2ndrew -ridgellMs seg#?handler


htt$>++www.sam*a.org+.unkcode+Tseg#?handler
%C www.thefarm51.com

9!

1 word on li'ensing

Khene#er you use a li*rary/ -.e-k its li-ensin2 terms/ GPL is restri-ti9e - <e,uires deri#ati#e works to use 0PL ' sharing the source code LGPL is restricti#e with linkin2 e#-eption - 2llows linking to an L0PL li*rary without sharing the source code 4IT/ 71! and >lib licenses are generally permissi9e/ some might re,uire ad#ertising
9! www.thefarm51.com

91

Deployment
91 www.thefarm51.com

92

Where do I )ut the *iles?

Kindows - 0ame data and *inaries> 3>UProgram Files - Aser data> V2PP"2-2V/ "ocuments... - 2o54like organization Linu &con#entional) - 0ame *inaries> +usr+*in+/ +usr+games+ - 0ame data> +usr+share+games+ - Aser data> WQ6=N+.config+

- 5o24like organization - 'iles"stem Hierar-." 1tandard


92

&WO"0?36@FI0?Q6=N en#ironment #aria*le)

www.thefarm51.com

9%

Where do I )ut the *iles?

FQ5 mainly concerns distro $ackages Pro$rietary software often installs into +o$t+X$ackage nameY+

&D2dd4on a$$lication software $ackagesG)

Pro$rietary software also often installs Dwhere#erG 5team games li#e in Z+.steam+steam+5team2$$s+ Bust $ut game data and *inaries in one $lace/ and sa#e user data to Z+.config+

9%

www.thefarm51.com

99

7reating installation bundles

@ot rele#ant for 5team games &duh) 5im$le .tar.gz archi#es

"istro $ackages &.r$m/ .de*...) 5elf4e tracting command4line installers as shell scri$ts

$ tar czvf <archive name> \ <input files...>

htt$s>++coderwall.com+$+y%u$,w

=o.o5etu$
htt$>++icculus.org+mo.osetu$+

99

www.thefarm51.com

95

Summary
95 www.thefarm51.com

9:

!u""ary

Nngineering costs of a Linu $ort for an already multi$latfrom game engine are low - DItMs .ust an 2PIG[ 5"L co#ers a lot of *oiler$late for you 6#ercoming heterogeneity is essential - 5team Linu <untime is hel$ing to fi it Katch out for those licenses1 Khen in dou*t> - Ase A*untu - "o whate#er Fal#e does

9:

www.thefarm51.com

97

Questions?
97

[email protected]

www.thefarm51.com

9;

!)e'ial thanks

="an ?I--ulus@ Gordon


Ins$iration S software contri*utions

4i-.aA 0iel2us
3ritical re#iew S free software comrade

0etting stuff done for me on the PRQ" $ort


9; www.thefarm51.com

=ein.ard Polli-e

9C

www.thefarm51.com

Thank you!
Like us on Facebook! http://www.facebook.com/farm51 http://www.facebook.com/deadfalladventures http://www.facebook.com/PainkillerGame

[email protected]

You might also like