Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dart for Game Developers

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Dart for Game Developers

Avatar for Don Olmstead

Don Olmstead

May 22, 2014

More Decks by Don Olmstead

Other Decks in Programming

Transcript

  1. I’m a native programmer working on the web platform for

    the PS4 And I want games on the web
  2. C Java Objective-C C++ Basic C# Pascal Ada Fortran Forth

    D Go Haskell Scala Erlang Delphi Smalltalk Oberon ML Eiffel Icon PL/I Caml/F# Rust PHP Python Perl Ruby R Lisp/Scheme MATLAB APL NXT-G Lua ABC Scratch J Oz Groovy ActionScript Awk ...
  3. Virtual Machine (dart) Code analysis (dartanalyzer) JS compilation (dart2js) Package

    management (pub) Documentation generation (docgen) Profiling (Observatory) Editing (Dart Editor)
  4. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  5. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  6. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  7. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  8. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  9. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  10. library math3d; import ‘dart:math’ as Math; class Vector2 { double

    x; double y; Vector2(this.x, this.y); Vector2 operator +(Vector2 rhs) { return new Vector2(x + rhs.x, y + rhs.y); } double get length => Math.sqrt(x * x + y * y); }
  11. abstract class Disposable { bool get isDisposed; void dispose(); }

    class GraphicsResource implements Disposable { GraphicsDevice _graphicsDevice; bool get isDisposed => _graphicsDevice == null; void dispose() { _graphicsDevice._destroyWithoutBinding(this); } }
  12. abstract class Disposable { bool get isDisposed; void dispose(); }

    class GraphicsResource implements Disposable { GraphicsDevice _graphicsDevice; bool get isDisposed => _graphicsDevice == null; void dispose() { _graphicsDevice._destroyWithoutBinding(this); } }
  13. abstract class Disposable { bool get isDisposed; void dispose(); }

    class GraphicsResource implements Disposable { GraphicsDevice _graphicsDevice; bool get isDisposed => _graphicsDevice == null; void dispose() { _graphicsDevice._destroyWithoutBinding(this); } }
  14. abstract class Disposable { bool get isDisposed; void dispose(); }

    class GraphicsResource implements Disposable { GraphicsDevice _graphicsDevice; bool get isDisposed => _graphicsDevice == null; void dispose() { _graphicsDevice._destroyWithoutBinding(this); } }
  15. class GraphicsResource implements Disposable { void dispose() { _graphicsDevice._destroyWithoutBinding(this); }

    } class VertexBuffer extends GraphicsResource { @override void dispose() { _graphicsDevice._destroyVertexBuffer(this); } }
  16. class GraphicsResource implements Disposable { void dispose() { _graphicsDevice._destroyWithoutBinding(this); }

    } class VertexBuffer extends GraphicsResource { @override void dispose() { _graphicsDevice._destroyVertexBuffer(this); } }
  17. class GraphicsResource implements Disposable { void dispose() { _graphicsDevice._destroyWithoutBinding(this); }

    } class VertexBuffer extends GraphicsResource { @override void dispose() { _graphicsDevice._destroyVertexBuffer(this); } }
  18. typedef T Init<T>(); typedef void Term<T>(T value); class ObjectPool<T> {

    List<T> _objects; ObjectPool(int size, Init<T> initializer, Term<T> terminator) { _objects = new List<T>(size); for (var i = 0; i < size; ++i) { var object = initializer(); terminator(object); _objects[i] = object; } } }
  19. typedef T Init<T>(); typedef void Term<T>(T value); class ObjectPool<T> {

    List<T> _objects; ObjectPool(int size, Init<T> initializer, Term<T> terminator) { _objects = new List<T>(size); for (var i = 0; i < size; ++i) { var object = initializer(); terminator(object); _objects[i] = object; } } }
  20. typedef T Init<T>(); typedef void Term<T>(T value); class ObjectPool<T> {

    List<T> _objects; ObjectPool(int size, Init<T> initializer, Term<T> terminator) { _objects = new List<T>(size); for (var i = 0; i < size; ++i) { var object = initializer(); terminator(object); _objects[i] = object; } } }
  21. abstract class Selectable { bool _selected = false; bool get

    selected => _selected; set selected(bool value) { setSelected(value); } } @CustomTag(‘px-tree-node’) class TreeViewNode extends PolymerElement with Expandable, Customizable, Selectable { ... }
  22. abstract class Selectable { bool _selected = false; bool get

    selected => _selected; set selected(bool value) { setSelected(value); } } @CustomTag(‘px-tree-node’) class TreeViewNode extends PolymerElement with Expandable, Customizable, Selectable { ... }
  23. abstract class Selectable { bool _selected = false; bool get

    selected => _selected; set selected(bool value) { setSelected(value); } } @CustomTag(‘px-tree-node’) class TreeViewNode extends PolymerElement with Expandable, Customizable, Selectable { ... }
  24. class DebugRenderingContext implements WebGL.RenderingContext { dynamic noSuchMethod(Invocation invocation) { var

    mirror = reflect(_gl); var result = mirror.delegate(invocation); int errorCode = _gl.getError(); while (errorCode != WebGL.NO_ERROR) { if (!_onErrorController.isPaused) { var methodName = MirrorSystem.getName(invocation.memberName); _onErrorController.add( new RenderingErrorEvent._internal(errorCode, methodName)); errorCode = _gl.getError(); } } return result; } }
  25. class BlendState extends GraphicsResource { BlendState(GraphicsDevice device) : super._internalWithoutBinding(device); BlendState.additive(String

    name, GraphicsDevice device) : super._internalWithoutBinding(device) , alphaDestinationBlend = Blend.One , alphaSourceBlend = Blend.SourceAlpha , colorDestinationBlend = Blend.One , colorSourceBlend = Blend.SourceAlpha; } var blendState = new BlendState.additive();
  26. BlendState createBlendState() { var state = new BlendState(device); state..enabled =

    true ..alphaDestinationBlend = Blend.One ..alphaSourceBlend = Blend.One ..colorBlendOperation = BlendOperation.Add ..colorDestinationBlend = Blend.One ..blendFactorRed = 1.0 ..blendFactorGreen = 1.0 ..blendFactorBlue = 1.0 ..blendFactorAlpha = 1.0; return state; }
  27. class TextureManager { Future<Texture> loadTexture(String path) { ... } }

    void initTextures() { textureManager.loadTexture('uv.jpg').then((texture) { effect.parameters['uTexture'] = texture; }); }
  28. class GraphicsDevice { StreamController<ResourceCreatedEvent> _onResourceCreatedController; Stream<ResourceCreatedEvent> _onResourceCreated; Stream<ResourceCreatedEvent> get onResourceCreated

    => _onResourceCreated; void _notifyResourceCreated(GraphicsResource graphicsResource) { if (!_onResourceCreatedController.isPaused) { _onResourceCreatedController.add( new ResourceCreatedEvent._internal(graphicsResource) ); } } }
  29. @lazy import 'foo.dart' as foo; const lazy = const DeferredLibrary('com.example.foo');

    void main() { foo.method(); // Throws a NoSuchMethodError, foo is not loaded yet. lazy.load().then(onFooLoaded); } void onFooLoaded(_) { foo.method(); }
  30. async Future<int> foo() { var longRunningTask = longRunningOperation(); // Wait

    for result var result = await longRunningTask; print(result); } async Future<int> longRunningOperation() { .. }