fisl14 - a multiplatform architecture for games

Post on 31-May-2015

216 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

A MultiplatformArchitecture for

GamesFISL 14

Thiago Figueredo Cardoso, Thiago de Barros Lacerda

Multiplatform development

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

Expensive

Hard to mantain

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

Needs a framework

Not every aspect of the code can be easily adapted

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

code and rewrite only the former

Game development

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)

What kinds of problems do weface with this kind of

architecture?

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);};

Velocity (pixel/sec): 10 Play

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;};

2. Scaling can introducerounding errors

3. Testing can become harder

Circus v1

It wasn't modeled for multiple platforms

Problems with Circus v1

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

Elements are implemented as objects of the graphic system

Problems with Circus v1

Behavior and UI mixed

Problems with Circus v1

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

Multiple resolutions handled with scales in the physics

Circus v1 on Windows Phone

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

On top on the Sparta engine

Circus v2

New elements

Bug fixes

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

QtPropertyAnimationRotationObject treeCollision

Problems with Circus v2No testing framework

Step-by-step debugging in many cases

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

A multiplatform architecturefor Circus

Three layer architecture, separation of concerns

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

Tests uses the Core directly

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

Physics deals with collisions and its resolution

How a game element isrepresented?

Physics

Elements are bodies, interactions are collisions

CoreElements are entities that have a group of bodies

Interactions are input events and collisions between entities

UIElements are sprites that display an entity

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

How do we use it in multipleplatforms?

Rewrite only the Platform layer

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

Let's try it!

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

A MultiplatformArchitecture for

GamesFISL 14

Thiago Figueredo Cardoso, Thiago de Barros Lacerda

top related