FISL14 - A Multiplatform Architecture for Games

38
A Multiplatform Architecture for Games FISL 14 Thiago Figueredo Cardoso, Thiago de Barros Lacerda

description

Presented at FISL14 (http://fisl.org.br). The original HTML5 version can be found at http://figueredo.github.io/fisl14

Transcript of FISL14 - A Multiplatform Architecture for Games

Page 1: FISL14 - A Multiplatform Architecture for Games

A MultiplatformArchitecture for

GamesFISL 14

Thiago Figueredo Cardoso, Thiago de Barros Lacerda

Page 2: FISL14 - A Multiplatform Architecture for Games

Multiplatform development

Page 3: FISL14 - A Multiplatform Architecture for Games

At one extreme...... one code per platform/device

Expensive

Hard to mantain

Page 4: FISL14 - A Multiplatform Architecture for Games

At the other extreme...... same code for all platforms/devices

Needs a framework

Not every aspect of the code can be easily adapted

Page 5: FISL14 - A Multiplatform Architecture for Games

The intermediate pathWe need to split platform-dependent from platform-independent

code and rewrite only the former

Page 6: FISL14 - A Multiplatform Architecture for Games

Game development

Page 7: FISL14 - A Multiplatform Architecture for Games

Architeture

Sprite.prototype.update = function (delta) { // update position, animation, ...};

Sprite.prototype.draw = function (context) {< // draw on the screen};

function mainLoop () { for (var i in sprites) { sprites[i].update(); sprites[i].draw(); }}

Sprite's update deals with UI (platform-dependent) andbehavior (platform-independent)

Page 8: FISL14 - A Multiplatform Architecture for Games

What kinds of problems do weface with this kind of

architecture?

Page 9: FISL14 - A Multiplatform Architecture for Games

1. Physics parameters changewhen resolution changes

RectSprite.prototype.update = function (delta) { this.x += this.velocity * delta;};

RectSprite.prototype.draw = function (context) { context.fillStyle = "black"; context.fillRect(this.x, this.y, this.width, this.height);};

Page 10: FISL14 - A Multiplatform Architecture for Games

Velocity (pixel/sec): 10 Play

Page 11: FISL14 - A Multiplatform Architecture for Games

The velocity needs to bescaled

1. Before setting the sprite parameter:

2. Inside the sprite's update:

var rect = new RectSprite();rect.velocity = config.velocity / UI.SCALE;

RectSprite.prototype.update = function (delta) { this.x += (this.velocity / UI.SCALE) * delta;};

Page 12: FISL14 - A Multiplatform Architecture for Games

2. Scaling can introducerounding errors

Page 13: FISL14 - A Multiplatform Architecture for Games

3. Testing can become harder

Page 14: FISL14 - A Multiplatform Architecture for Games
Page 15: FISL14 - A Multiplatform Architecture for Games

Circus v1

It wasn't modeled for multiple platforms

Page 16: FISL14 - A Multiplatform Architecture for Games

Problems with Circus v1

class Sprite : public QGraphicsObject{ Q_OBJECT ...};

Elements are implemented as objects of the graphic system

Page 17: FISL14 - A Multiplatform Architecture for Games

Problems with Circus v1

Behavior and UI mixed

Page 18: FISL14 - A Multiplatform Architecture for Games

Problems with Circus v1

void GameWorld::step(qreal dt){ ... const QPointF &ds = dt * sprite->velocity() * worldScaleFactor; ...}

Multiple resolutions handled with scales in the physics

Page 19: FISL14 - A Multiplatform Architecture for Games

Circus v1 on Windows Phone

No Qt, no C++, no reuse :(

On top on the Sparta engine

Page 20: FISL14 - A Multiplatform Architecture for Games

Circus v2

New elements

Bug fixes

Page 21: FISL14 - A Multiplatform Architecture for Games

Problems with Circus v2Implementation of classes/functionalities of the Qt framework in C#:

QtPropertyAnimationRotationObject treeCollision

Page 22: FISL14 - A Multiplatform Architecture for Games

Problems with Circus v2No testing framework

Step-by-step debugging in many cases

Page 23: FISL14 - A Multiplatform Architecture for Games

Circus v3?Oh, please, let's start from scratch!

Page 24: FISL14 - A Multiplatform Architecture for Games

A multiplatform architecturefor Circus

Three layer architecture, separation of concerns

Page 25: FISL14 - A Multiplatform Architecture for Games
Page 26: FISL14 - A Multiplatform Architecture for Games

Platform deals with platform-dependent issues (UI, audio andfilesystem)

Page 27: FISL14 - A Multiplatform Architecture for Games

Tests uses the Core directly

Page 28: FISL14 - A Multiplatform Architecture for Games

Core deals with the behavior of the elements and game logic (score,world)

Page 29: FISL14 - A Multiplatform Architecture for Games

Physics deals with collisions and its resolution

Page 30: FISL14 - A Multiplatform Architecture for Games

How a game element isrepresented?

Page 31: FISL14 - A Multiplatform Architecture for Games

Physics

Elements are bodies, interactions are collisions

Page 32: FISL14 - A Multiplatform Architecture for Games

CoreElements are entities that have a group of bodies

Interactions are input events and collisions between entities

Page 33: FISL14 - A Multiplatform Architecture for Games

UIElements are sprites that display an entity

No interactions, only forwarding of events (the UI doesn't alter thegame)

Page 34: FISL14 - A Multiplatform Architecture for Games

How do we use it in multipleplatforms?

Rewrite only the Platform layer

Page 35: FISL14 - A Multiplatform Architecture for Games

SummaryBehavior consistency guaranteed by having only one code forbehaviorNo framework dependency, making it easy to translate to otherlanguages (C++?)Tests are easier to write (no frameworks) and need to be writtenonce (one code)Porting effort is clear

Page 36: FISL14 - A Multiplatform Architecture for Games

Let's try it!

Page 37: FISL14 - A Multiplatform Architecture for Games

INdT @ FISLWorkshop de Jogos HTML5 - Sala 714 - 14h

Page 38: FISL14 - A Multiplatform Architecture for Games

A MultiplatformArchitecture for

GamesFISL 14

Thiago Figueredo Cardoso, Thiago de Barros Lacerda