A Multiplatform Architecture for Games – FISL 14 – Multiplatform development



A Multiplatform Architecture for Games – FISL 14 – Multiplatform development

0 0


fisl14

FISL 14 presentation

On Github figueredo / fisl14

A Multiplatform Architecture for Games

FISL 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 path

We 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) and behavior (platform-independent)

What kinds of problems do we face with this kind of architecture?

1. Physics parameters change when 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): Play

The velocity needs to be scaled

Before setting the sprite parameter:
                        
var rect = new RectSprite();
rect.velocity = config.velocity / UI.SCALE;
                        
                      
Inside the sprite's update:
                        
RectSprite.prototype.update = function (delta) {
    this.x += (this.velocity / UI.SCALE) * delta;
};
                        
                      

2. Scaling can introduce rounding 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 v2

Implementation of classes/functionalities of the Qt framework in C#:

  • QtPropertyAnimation
  • Rotation
  • Object tree
  • Collision

Problems with Circus v2

No testing framework

Step-by-step debugging in many cases

Circus v3?

Oh, please, let's start from scratch!

A multiplatform architecture for Circus

Three layer architecture, separation of concerns

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

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 is represented?

Physics

Elements are bodies, interactions are collisions

Core

Elements are entities that have a group of bodies

Interactions are input events and collisions between entities

UI

Elements are sprites that display an entity

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

How do we use it in multiple platforms?

Rewrite only the Platform layer

Summary

  • Behavior consistency guaranteed by having only one code for behavior
  • No framework dependency, making it easy to translate to other languages (C++?)
  • Tests are easier to write (no frameworks) and need to be written once (one code)
  • Porting effort is clear

Let's try it!

INdT @ FISL

Workshop de Jogos HTML5 - Sala 714 - 14h

A Multiplatform Architecture for Games

FISL 14

Thiago Figueredo Cardoso, Thiago de Barros Lacerda