Mono for Game Developers Miguel de Icaza - - PowerPoint PPT Presentation

mono for game developers
SMART_READER_LITE
LIVE PREVIEW

Mono for Game Developers Miguel de Icaza - - PowerPoint PPT Presentation

Mono for Game Developers Miguel de Icaza miguel@xamarin.com, @migueldeicaza Xamarin Inc Agenda Mono in Games Using Mono for Games Performance


slide-1
SLIDE 1

Mono ¡for ¡Game ¡Developers ¡

Miguel ¡de ¡Icaza ¡

miguel@xamarin.com, ¡@migueldeicaza ¡ ¡

Xamarin ¡Inc ¡

slide-2
SLIDE 2

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Agenda ¡

  • Mono ¡in ¡Games ¡
  • Using ¡Mono ¡for ¡Games ¡
  • Performance ¡
  • Garbage ¡CollecKon ¡
  • Co-­‑rouKnes, ¡Asynchronous ¡Programming ¡
slide-3
SLIDE 3

MONO ¡IN ¡GAMES ¡

slide-4
SLIDE 4

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

C# ¡ Java ¡ JavaScript ¡ Ruby ¡ Python ¡ Visual ¡Basic ¡ F# ¡

slide-5
SLIDE 5

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

C# ¡ Java ¡ JavaScript ¡ Ruby ¡ Python ¡ Visual ¡Basic ¡ F# ¡

slide-6
SLIDE 6

Sims ¡3 ¡

  • Mixed ¡Code: ¡

– C/C++ ¡engine ¡ – C# ¡scripKng/AI ¡ – C# ¡high-­‑level ¡

  • Visual ¡Studio ¡+ ¡Mono ¡
  • X86, ¡PS3, ¡Xbox360 ¡

¡

Credit: ¡ ¡www.thesims3facts.webs.com ¡
slide-7
SLIDE 7

BasKon ¡– ¡on ¡Google ¡Chrome ¡NaCl ¡

  • C# ¡XNA ¡codebase ¡
  • Originally ¡on ¡Xbox ¡
  • Ported ¡to ¡NaKveClient ¡

– Mono ¡ – MonoGame ¡(XNA) ¡

  • Mac, ¡Windows, ¡Linux ¡
slide-8
SLIDE 8

Pure ¡C# ¡-­‑ ¡SoulCra_ ¡

  • DeltaEngine ¡

– Pure ¡C# ¡engine ¡ – Open ¡source ¡ – Android, ¡iOS, ¡Mac, ¡Win ¡

slide-9
SLIDE 9

Unity ¡3D ¡

  • Unity ¡Engine ¡

– C/C++ ¡game ¡engine ¡ – Embedded ¡Mono ¡

  • User ¡code ¡

– C# ¡or ¡UnityScript ¡ – Extends ¡Unity ¡itself ¡ ¡

¡

Shadow ¡Gun, ¡built ¡with ¡Unity ¡

slide-10
SLIDE 10

SecondLife ¡

  • Mono ¡on ¡the ¡server ¡
  • Powers ¡LSL ¡scripts ¡
  • Nice ¡200x ¡perf ¡boost ¡
  • Code ¡InjecKon ¡
slide-11
SLIDE 11

Infinite ¡Flight ¡

  • Subject ¡of ¡the ¡second ¡

part ¡of ¡this ¡session ¡

slide-12
SLIDE 12

WHY ¡MONO? ¡

slide-13
SLIDE 13

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Because ¡Life ¡is ¡too ¡Short ¡

  • To ¡debug ¡another ¡memory ¡leak ¡
  • To ¡track ¡another ¡memory ¡corrupKon ¡bug ¡
  • Because ¡you ¡deserve ¡be=er ¡
slide-14
SLIDE 14

The ¡Quest ¡for ¡ProducKvity ¡

System ¡Languages ¡

Pros: ¡

  • Low-­‑level ¡
  • Good ¡control ¡of ¡hardware ¡
  • Typed ¡
  • Fast ¡code ¡

Cons: ¡

  • Easy ¡to ¡corrupt ¡state ¡
  • Low ¡producKvity ¡
  • Crash ¡o_en ¡
  • Complex ¡for ¡newcomers ¡

Scrip<ng ¡Languages ¡

Pros: ¡

  • High-­‑level, ¡good ¡producKvity ¡
  • Easy ¡to ¡write ¡
  • Safe, ¡prevent ¡crashes ¡
  • Loosely ¡typed ¡

¡ Cons: ¡

  • Poor ¡control ¡of ¡hardware ¡
  • Slow ¡(interpreted) ¡
slide-15
SLIDE 15

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

John ¡Ousterhout ¡ScripKng ¡Quest ¡ IEEE ¡1998 ¡Summary ¡Paper ¡ ¡

h=p://www.stanford.edu/~ouster/cgi-­‑bin/papers/scripKng.pdf ¡

slide-16
SLIDE 16

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

John ¡was ¡always ¡ahead ¡of ¡his ¡Kme ¡

  • Professional ¡workstaKons ¡in ¡1998 ¡

– SPARC, ¡HP-­‑PA ¡

  • Not ¡achievable ¡on ¡PCs ¡of ¡the ¡Kme ¡
slide-17
SLIDE 17

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

2000 ¡– ¡Desktop ¡Development ¡

  • Building ¡desktop ¡apps ¡with ¡C ¡and ¡C++ ¡

– Slow ¡progress, ¡error ¡prone, ¡frequent ¡crashes ¡

  • Windows ¡2000 ¡Requirements: ¡

– 133 ¡Mhz ¡or ¡more ¡ – 64 ¡megs ¡for ¡desktop, ¡256 ¡for ¡server ¡

  • Windows ¡XP ¡Requirements ¡(one ¡year ¡later) ¡

– 233Mhz ¡or ¡more ¡ – 128 ¡megs ¡for ¡desktop ¡

  • Development ¡desktops ¡at ¡the ¡Kme: ¡

– ~1Ghz ¡speed ¡ – ~1 ¡GB ¡of ¡memory ¡

slide-18
SLIDE 18

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

C# ¡Introduced ¡in ¡2000 ¡

  • C# ¡1.0 ¡was ¡a ¡Java-­‑like ¡system ¡
  • With ¡many ¡design ¡fixes ¡

– 10 ¡years ¡of ¡experience ¡ – Change ¡defaults ¡(all ¡virtual, ¡vs ¡opt-­‑in ¡virtual) ¡ – Introduce ¡structs ¡(help ¡GC, ¡no ¡boxing) ¡ – Direct ¡access ¡to ¡naKve ¡libraries ¡(P/Invoke) ¡ – Delegates ¡(foundaKon ¡for ¡lambdas) ¡

slide-19
SLIDE 19

Language ¡Choices ¡ ¡

ProducKvity ¡ Performance ¡

Assembly ¡Language ¡ C/C++ ¡ Fully ¡Dynamic ¡ C#/Java ¡ Fast ¡ Slow ¡ Difficult ¡ Easy ¡

slide-20
SLIDE 20

Game ¡So_ware ¡Components ¡

. ¡

  • Rendering ¡
  • Shading ¡
  • Scene ¡
  • AnimaKon ¡
  • Geometry ¡
  • GUI ¡

Display ¡

  • Physics ¡
  • Collision ¡
  • ParKcles ¡
  • Terrain ¡

SimulaKon ¡

  • World ¡rules ¡
  • Enemy ¡AI ¡
  • User ¡

control ¡

  • Camera ¡
  • Behavior ¡

Game ¡Logic ¡

  • Audio ¡
  • Input ¡
  • Networking ¡

Support ¡

slide-21
SLIDE 21

The ¡Problem ¡

Games ¡are ¡real-­‑Kme ¡programs ¡

  • 30 ¡to ¡60 ¡frames ¡per ¡second ¡(0.016 ¡seconds) ¡

¡

  • User ¡control ¡
  • Network ¡

events ¡

Input ¡

¡

  • Scripted, ¡slow ¡
  • React ¡to ¡

change ¡

  • Update ¡scene ¡

AI ¡

¡

  • Render ¡Graphics ¡
  • Play ¡audio ¡

Updates ¡

slide-22
SLIDE 22

Problem: ¡ ¡ScripKng ¡Is ¡A ¡Bo=leneck ¡

Gaming's ¡Achilles' ¡Heel ¡

  • Rendering ¡
  • Shading ¡
  • Scene ¡
  • AnimaKon ¡
  • Geometry ¡
  • GUI ¡

Display ¡

  • Physics ¡
  • Collision ¡
  • ParKcles ¡
  • Terrain ¡

SimulaKon ¡

  • World ¡rules ¡
  • Enemy ¡AI ¡
  • User ¡

control ¡

  • Camera ¡
  • Behavior ¡

Game ¡Logic ¡

  • Audio ¡
  • Input ¡
  • Networking ¡

Support ¡

C/C++ ¡ C/C++ ¡ C/C++ ¡ Script ¡

slide-23
SLIDE 23

Problem: ¡ ¡ScripKng ¡Is ¡A ¡Bo=leneck ¡

Gaming's ¡Achilles' ¡Heel ¡

  • Rendering ¡
  • Shading ¡
  • Scene ¡
  • AnimaKon ¡
  • Geometry ¡
  • GUI ¡

Display ¡

  • Physics ¡
  • Collision ¡
  • ParKcles ¡
  • Terrain ¡

SimulaKon ¡

  • World ¡rules ¡
  • Enemy ¡AI ¡
  • User ¡

control ¡

  • Camera ¡
  • Behavior ¡

Game ¡Logic ¡

  • Audio ¡
  • Input ¡
  • Networking ¡

Support ¡

C/C++ ¡ C/C++ ¡ C/C++ ¡ Script ¡ C# ¡

slide-24
SLIDE 24

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

What ¡C# ¡Offers ¡

  • Close ¡to ¡naKve ¡performance ¡

– 50%-­‑90% ¡of ¡naKve ¡performance ¡

  • Safe ¡ExecuKon ¡Environment ¡

– With ¡opKonal ¡support ¡to ¡shoot ¡yourself ¡in ¡the ¡

  • foot. ¡
slide-25
SLIDE 25

C# ¡-­‑ ¡An ¡Evolving ¡Language ¡

1.0 ¡ 2.0 ¡ 3.0 ¡ 4.0 ¡ 5.0 ¡ 2002 ¡ 2005 ¡ 2007 ¡ 2010 ¡ 2012 ¡ Managed ¡Code, ¡strongly ¡typed ¡ Generics, ¡Iterators, ¡Lambdas ¡ Language ¡Integrated ¡Query, ¡FuncKonal ¡ Dynamic ¡extensions ¡ Asynchronous ¡Programming ¡

slide-26
SLIDE 26

USING ¡MONO ¡

slide-27
SLIDE 27

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Designing ¡Mono ¡ApplicaKons ¡

  • Provided: ¡

– C# ¡Language ¡ – Base ¡Class ¡Libraries ¡

  • Not ¡Provided: ¡

– User ¡Interface, ¡Graphics, ¡Audio ¡ – These ¡are ¡all ¡plaqorm ¡specific ¡

slide-28
SLIDE 28

Code ¡Sharing ¡and ¡NaKve ¡Experience ¡

Windows ¡ Xbox ¡ WinPhone ¡

iOS ¡ C# ¡

Plus ¡ECMA ¡languages ¡

.NET ¡ Mac ¡

Android ¡

Mono ¡ Core ¡Engine, ¡Shared ¡Logic, ¡Business ¡Logic ¡ RunKme ¡ OS ¡

Not ¡a ¡comprehensive ¡list ¡

slide-29
SLIDE 29

Code ¡Sharing ¡and ¡NaKve ¡Experience ¡

Windows ¡ Xbox ¡ WinPhone ¡

XAML ¡ XNA ¡

iOS ¡

MonoTouch ¡

C# ¡

Plus ¡ECMA ¡languages ¡

.NET ¡ Mac ¡

MonoMac ¡ Android ¡ MonoDroid ¡

Mono ¡ Core ¡Engine, ¡Shared ¡Logic, ¡Business ¡Logic ¡ NaKve ¡UI ¡ APIs ¡ RunKme ¡ OS ¡

Not ¡a ¡comprehensive ¡list ¡

slide-30
SLIDE 30

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Modes ¡of ¡Use ¡

  • Drive ¡the ¡applicaKon ¡
  • ScripKng ¡engine ¡

– Sandboxed ¡ – Full ¡access ¡

slide-31
SLIDE 31

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Run ¡on ¡Mono ¡

slide-32
SLIDE 32

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Run ¡on ¡Mono ¡

Game ¡– ¡Your ¡C# ¡Code ¡

Mono ¡ RunKme ¡

OperaKng ¡ System ¡

C#/.NET ¡Libraries ¡

MonoGame ¡ OpenAL ¡ OpenTK ¡ OpenGL ¡ Physics ¡ Networking ¡

slide-33
SLIDE 33

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Using ¡Mono ¡as ¡a ¡Library ¡

slide-34
SLIDE 34

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Use ¡Mono ¡as ¡a ¡Library ¡

Game ¡Engine ¡

Game ¡Engine ¡Libraries ¡

Audio ¡ Graphics ¡

Mono ¡

Game ¡– ¡Your ¡ C# ¡Code ¡

slide-35
SLIDE 35

TIPS ¡ON ¡USING ¡MONO ¡

slide-36
SLIDE 36

Two ¡Code ¡GeneraKon ¡Backends ¡

Mono’s ¡Na<ve ¡Backend ¡

  • Very ¡fast ¡codegen ¡

– .3 ¡seconds ¡bootstrap ¡

  • Not ¡great ¡code ¡output ¡
  • JIT’s ¡default ¡engine ¡

LLVM ¡Backend ¡

  • Very ¡slow ¡codegen ¡

– 7 ¡second ¡bootstrap ¡

  • Great ¡output ¡quality ¡
  • Opt-­‑in: ¡

– mono ¡-­‑-­‑llvm

slide-37
SLIDE 37

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Just ¡in ¡Time ¡vs ¡Ahead ¡of ¡Time ¡

  • Just ¡in ¡Time ¡CompilaKon ¡

– Default ¡Mode ¡of ¡OperaKon ¡ – Very ¡fast ¡at ¡compiling ¡code ¡ – Not ¡great ¡quality ¡of ¡code ¡generaKon ¡

  • Ahead ¡of ¡Time ¡CompilaKon ¡

– Mandatory ¡on ¡some ¡plaqorms ¡

  • PS3, ¡XBox360, ¡iOS ¡ ¡

– Can ¡afford ¡expensive ¡compiler ¡opKmizaKons ¡

slide-38
SLIDE 38

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Arrays ¡Bounds ¡Checking ¡

Mono ¡RunKme ¡translates ¡this ¡to: ¡

slide-39
SLIDE 39

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Disabling ¡Arrays ¡Bounds ¡Checking ¡

  • Very ¡unsafe ¡

– GC ¡depends ¡on ¡system ¡integrity ¡ – But ¡admissible ¡if ¡no ¡error ¡ever ¡found ¡on ¡tesKng ¡

  • We ¡give ¡you ¡the ¡tools ¡to ¡shoot ¡your ¡feet ¡

– mono ¡–O=unsafe

  • Ask ¡your ¡QA ¡team ¡
slide-40
SLIDE 40

GARBAGE ¡COLLECTION ¡

slide-41
SLIDE 41

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Mono’s ¡Garbage ¡Collectors ¡

  • Boehm ¡GC: ¡

– TradiKonal ¡Mono ¡GC ¡ – Mostly-­‑precise, ¡stack ¡conservaKve ¡ – Scans ¡everything ¡on ¡each ¡GC ¡

  • GeneraKonal ¡Collector ¡(SGen) ¡

– New ¡(default ¡on ¡Android) ¡ – GeneraKonal ¡(Old ¡generaKon, ¡nurseries) ¡ – Copying ¡(plus ¡mark+sweep ¡for ¡large ¡objects) ¡

slide-42
SLIDE 42

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

SGen ¡

Nursery ¡

  • New ¡objects ¡
  • Small ¡size ¡(4MB) ¡
  • Per ¡thread ¡regions ¡
  • Very ¡fast ¡

collecKon ¡ Old ¡ GeneraKon ¡

  • Aged ¡objects ¡
  • Slower ¡collecKon ¡
  • Fixed ¡or ¡variable ¡

heaps ¡

  • Parallel ¡collecKon ¡
slide-43
SLIDE 43

Garbage ¡CollecKon ¡

Memory ¡Allocated ¡ Released ¡later ¡ Garbage ¡Collector ¡determines ¡when ¡to ¡run ¡and ¡release ¡memory ¡

  • HeurisKcs ¡are ¡plaqorm-­‑specific ¡
  • GC.Collect() ¡is ¡the ¡only ¡determinisKc ¡opKon ¡

¡

slide-44
SLIDE 44

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Best ¡PracKces ¡

  • Pre-­‑allocate ¡major ¡objects ¡before ¡Game ¡Loop ¡

– Managed ¡objects ¡ – Or ¡unmanaged ¡buffers ¡ – Try ¡to ¡only ¡use ¡the ¡nursery ¡(stay ¡under ¡4M) ¡ – If ¡you ¡must ¡collect, ¡only ¡collect ¡the ¡nursery: ¡

  • GC.Collect ¡(0) ¡– ¡Performs ¡only ¡a ¡nursery ¡collecKon ¡
  • GC.Collect ¡() ¡– ¡Performs ¡a ¡complete ¡GC ¡on ¡the ¡heap ¡
  • On ¡Main ¡loop: ¡

– Use ¡structs ¡instead ¡of ¡classes ¡

slide-45
SLIDE 45

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Schedule ¡GC ¡CollecKon ¡

Physics ¡ Game ¡ Logic ¡1 ¡ Game ¡ Logic ¡2 ¡ Game ¡ Logic ¡3 ¡ Network ¡ Checks ¡ Audio ¡ Updates ¡

Physics ¡ Game ¡ Logic ¡1 ¡ Game ¡ Logic ¡2 ¡ Game ¡ Logic ¡3 ¡ GC ¡ Collect ¡ Network ¡ Checks ¡ Audio ¡ Updates ¡

GC.Collect ¡(0) ¡ ¡ Limit ¡CollecKon ¡to ¡Nursery ¡

slide-46
SLIDE 46

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Render ¡ Scene ¡

Mono ¡ Game ¡ Thread ¡ Network ¡ Thread ¡ IO ¡Thread ¡ Render ¡ Thread ¡ Real ¡Time ¡ Thread ¡1 ¡

Mono’s ¡GC ¡Thread ¡Control ¡

  • Garbage ¡CollecKon ¡Stops ¡all ¡Mono ¡Threads ¡
  • Non-­‑Mono ¡threads ¡are ¡not ¡affected ¡
  • AlternaKve: ¡
  • Use ¡a ¡Render ¡Scene ¡+ ¡Render ¡Thread ¡ ¡
  • Like ¡Apple’s ¡CoreAnimaKon ¡or ¡Microso_ ¡WPF ¡

Mono ¡Thread ¡ NaKve ¡Thread ¡

slide-47
SLIDE 47

COROUTINES ¡

slide-48
SLIDE 48

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

State-­‑based ¡programming ¡

slide-49
SLIDE 49

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Problems ¡with ¡Callbacks ¡and ¡State-­‑Machines ¡Systems ¡

  • RepeKKve ¡
  • Cumbersome ¡
  • Error ¡Prone ¡
  • Poor ¡Error ¡PropagaKon ¡protocols/pracKces ¡
  • Life ¡is ¡too ¡short ¡
slide-50
SLIDE 50

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Co-­‑rouKnes ¡

  • Popular ¡soluKon ¡to ¡simplify ¡AI ¡code ¡
  • Each ¡Game ¡Object ¡has ¡a ¡script ¡a=ached ¡

– Runs ¡Game ¡Logic ¡ – AI ¡bits ¡

  • Many ¡soluKons ¡

– longjmp/setjmp ¡for ¡unmanaged ¡code ¡ – Stack ¡fiddling ¡(Mono.Tasklets) ¡ – Interpreted ¡languages ¡with ¡VM ¡support ¡

slide-51
SLIDE 51

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

C# ¡5.0 ¡and ¡Async ¡Programming ¡

  • Mono ¡master ¡has ¡a ¡complete ¡C# ¡5 ¡Compiler ¡
  • Turns ¡repeKKve ¡callback-­‑based ¡async ¡

programming ¡into ¡linear ¡programming ¡

– Compiler ¡rewrites ¡the ¡code ¡into ¡a ¡state ¡machine ¡ – Tasks ¡are ¡scheduled ¡on ¡the ¡main ¡thread ¡ – Scheduling ¡is ¡customizable ¡

  • Originally ¡designed ¡for ¡interacKve ¡UIs ¡
slide-52
SLIDE 52

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Using ¡Await ¡

slide-53
SLIDE 53

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

The ¡Magic ¡

  • Await ¡lets ¡you ¡write ¡linear ¡code ¡
  • Lets ¡you ¡focus ¡on ¡the ¡problem ¡

– The ¡compiler ¡is ¡at ¡your ¡service ¡

  • Microso_ ¡convenKons ¡for ¡responsive ¡UIs: ¡

– If ¡it ¡takes ¡more ¡than ¡50ms, ¡make ¡it ¡async ¡

slide-54
SLIDE 54

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

More ¡on ¡await

  • await ¡introduces ¡a ¡suspension ¡point ¡

– Code ¡returns ¡to ¡caller ¡ – ExecuKon ¡resumes ¡a_er ¡“await” ¡instrucKon ¡ – Very ¡cheap ¡memory-­‑wise ¡

  • Works ¡with ¡IO, ¡Networking ¡stacks, ¡slow ¡code ¡

– System.IO, ¡System.Net, ¡Database ¡access ¡ – Slow ¡processing: ¡XML, ¡Json ¡data ¡ – Blends ¡transparently ¡with ¡Threads ¡on ¡mulK-­‑cores ¡

slide-55
SLIDE 55

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Li=le ¡more ¡interesKng ¡

slide-56
SLIDE 56

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Current ¡Trends ¡in ¡Async ¡Programming ¡

Callback ¡based ¡ ¡ Where: ¡

  • GUI ¡programming ¡
  • Scalable ¡web ¡servers ¡
  • Responsive ¡mobile ¡and ¡desktop ¡applicaKons ¡
slide-57
SLIDE 57

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

With ¡some ¡error ¡handling. ¡

slide-58
SLIDE 58

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

C# ¡5.0 ¡Async ¡Support ¡

slide-59
SLIDE 59

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Q&A ¡

  • Mono, ¡ISO ¡Standard, ¡C# ¡Async ¡

– h=p://www.mono-­‑project.com ¡ – ISO ¡Standard: ¡h=p://bit.ly/cli-­‑iso-­‑standard ¡ – C# ¡Async: ¡h=p://msdn.microso_.com/en-­‑us/vstudio/gg316360 ¡

  • Xamarin, ¡Mono ¡on ¡iOS, ¡Android: ¡

– Discount ¡for ¡AltDevConf ¡a=endees: ¡ ¡ – h=p://www.xamarin.com/altdevconf ¡

  • Contact: ¡

– miguel@xamarin.com, ¡@migueldeicaza ¡

  • Resources: ¡

– @MonoGameTeam, ¡@Unity3D ¡

  • Live ¡Chat ¡on ¡IRC: ¡irc.gnome.org ¡ ¡

– #mono, ¡#monotouch, ¡#monodroid, ¡#monogame ¡

slide-60
SLIDE 60

BACKUP ¡SLIDES ¡

slide-61
SLIDE 61

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Iterators ¡

  • C# ¡compiler ¡provided ¡assistance ¡

– Built ¡on ¡top ¡of ¡C# ¡IEnumerable ¡ – C# ¡compiler ¡rewrites ¡iterators ¡into ¡state ¡machines ¡

  • Developers ¡build ¡on ¡top ¡of ¡convenKons ¡
  • Unity3D ¡uses ¡this ¡approach ¡
  • Open ¡Source ¡Iterator ¡game ¡framework: ¡

– http://mjhutchinson.com/journal/2010/02/01/iteratorbased_microthreading

slide-62
SLIDE 62

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Iterator ¡based ¡code ¡

slide-63
SLIDE 63

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Mono.Tasklets ¡

  • Pros: ¡

– No ¡need ¡to ¡rewrite ¡code ¡ – You ¡can ¡suspend ¡execuKon/resume ¡without ¡new ¡

  • convenKons. ¡
  • Cons: ¡

– Not ¡available ¡on ¡every ¡plaqorm ¡– ¡Stack ¡Fiddling ¡ – Does ¡not ¡work ¡with ¡Mono’s ¡new ¡Precise ¡GC ¡ – In ¡parKcular, ¡wont ¡work ¡with ¡Microso_ ¡.NET ¡

slide-64
SLIDE 64

GAME ¡ENGINES ¡USING ¡C# ¡

Not ¡a ¡comprehensive ¡list ¡

slide-65
SLIDE 65

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Unity ¡3D ¡

  • Commercial ¡Engine ¡
  • Very ¡extensive ¡support: ¡

– Consoles: ¡XBox360, ¡PS3, ¡Wii ¡ – iOS, ¡Android ¡ – Mac, ¡Windows ¡ – Google ¡NaKve ¡Client ¡ – Flash ¡target ¡

slide-66
SLIDE 66

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

MonoGame ¡– ¡Open ¡Source ¡XNA ¡

  • Open ¡Source ¡XNA ¡implementaKon ¡

– Currently ¡2D-­‑based ¡ – 3D ¡support ¡coming ¡

  • Runs ¡on ¡many ¡plaqorms: ¡

– iOS ¡(iPhone, ¡iPad) ¡ – Android ¡(phones ¡and ¡tablets) ¡ – Linux ¡ – Mac ¡ – Windows ¡

slide-67
SLIDE 67

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Delta ¡Engine ¡

  • Open ¡Source ¡Game ¡Engine ¡
  • Wri=en ¡100% ¡in ¡C# ¡
  • Runs ¡on: ¡

– Android ¡ – Windows ¡Phone ¡ – iOS ¡ – Mac ¡ – Windows ¡

slide-68
SLIDE 68

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Axiom ¡

  • Open ¡source ¡
  • Based ¡on ¡the ¡OGRE ¡C++ ¡Engine ¡
  • Windows, ¡Linux ¡
  • XNA, ¡DirectX ¡and ¡OpenGL ¡support ¡ ¡
slide-69
SLIDE 69

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

F# ¡-­‑ ¡FascinaKng ¡Language ¡

  • h=p://sharp-­‑gamedev.blogspot.com/ ¡

– Blog ¡tracking ¡the ¡experiences ¡of ¡game ¡ development ¡using ¡F# ¡

  • F# ¡introduced ¡Async ¡

– Later ¡adopted ¡by ¡C# ¡

slide-70
SLIDE 70

h=p://www.xamarin.com ¡ Mono ¡for ¡Game ¡Developers ¡– ¡AltDevConf ¡2012 ¡

Architecture ¡

  • Computer ¡Architecture ¡– ¡A ¡QuanKtaKve ¡

Approach ¡

  • Unix ¡Systems ¡for ¡Modern ¡Architectures ¡

– It ¡says ¡“Unix” ¡ – But ¡applies ¡to ¡low-­‑level ¡systems ¡engineering ¡ – Caches, ¡MMUs, ¡performance ¡ – Hardware ¡Architectures ¡design ¡