Monthly Archives: July 2011

Social Online Games Programming (Part 3) Tankster, Blob Storage and JSONP

Previous Post
Next Post

In my previous post I wrote about the Windows Azure Social Gaming Toolkit, and its example multi-player online game Tankster. See:

http://watgames.codeplex.com/
http://www.tankster.net/

There are two interesting posts by @ntotten about the inner guts of the game:

Architecture of Tankster – Introduction to Game Play (Part 1)
Architecture of Tankster– Scale (Part 2)

It’s worth to mention Nathan’s text here:

Before we begin with an explanation of the implementation, it is important to know what our goals where for this game. We had three primary goals when building this game.

  1. The game must scale to handle several hundred thousand concurrent users.*
  2. The architecture must be cost effective.
  3. The architecture must be flexible enough for different types of games.

* This is the goal, but there are still some known limitations in the current version that would prevent this. I will be writing more about that later.

Now, I want to write about the use and implementation of blob storage in Tankster.

Why to use blob storage? If you play Tankster in practice mode, the Javascript client doesn’t use the Azure backend. Javascript can access web role and blob storage via Ajax/JSON calls. But in multi-player game (there is one kind of game, named Skirmish), each player client code polls the blob storage to get the game status (tank shots, chat messages, other status). But again, why blob storage? There are money reasons (cost of each access to Web Role service API vs. cost of read a blob), but I don’t know about Azure prices (you know, MVPs don’t touch the money ;-). But there is another reason: to spread the workload, given some air to web role instances.

There is an AzureBlobContainer class in Tankster.Common library project:

public class AzureBlobContainer<T> : IAzureBlobContainer<T>
{
    private readonly CloudBlobContainer container;
    private readonly bool jsonpSupport;
    private static JavaScriptSerializer serializer;
    public AzureBlobContainer(CloudStorageAccount account)
        : this(account, typeof(T).Name.ToLowerInvariant(), false)
    {
    }
    public AzureBlobContainer(CloudStorageAccount account, bool jsonpSupport)
        : this(account, typeof(T).Name.ToLowerInvariant(), false)
    {
    }
    public AzureBlobContainer(CloudStorageAccount account, string containerName)
        : this(account, containerName.ToLowerInvariant(), false)
    {
    }
	//....

 

The class use generics. Type T could be a Game, GameQueue or another .NET type. You can reuse this class in other projects: it’s “game agnostic” code. The many constructors add flexibility for testing purpose.

This is the code to save a typed object to a blob:

public void Save(string objId, T obj)
{
    CloudBlob blob = this.container.GetBlobReference(objId);
    blob.Properties.ContentType = "application/json";
    var serialized = string.Empty;
    serialized = serializer.Serialize(obj);
    if (this.jsonpSupport)
    {
		serialized = this.container.Name + "Callback(" + serialized + ")";
    }
    blob.UploadText(serialized);
}

The object (type T) is serialized to JSON. AND not only JSON: note that a there is a Callback (you could remove this part if you don’t need this feature in your project). Then, a game object is saved as (I stolen …errr… borrowed 😉 this code from Nathan’s post):

gamesCallback(
    {"Id":"620f6257-83e6-4fdc-99e3-3109718934a6"
    ,"CreationTime":"\/Date(1311617527935)\/"
    ,"Seed":1157059416
    ,"Status":0
    ,"Users":[
        {"UserId":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
        ,"UserName":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
        ,"Weapons":[]
        },
        {"UserId":"ZXjeyzvw7WTdP8/Uio4P6cDZ8jmKvCXCDp7JjWolAOY="
        ,"UserName":"ZXjeyzvw7WTdP8/Uio4P6cDZ8jmKvCXCDp7JjWolAOY="
        ,"Weapons":[]
        }]
    ,"ActiveUser":"MxAb1iZtey732BGsWsoMcwx3JbklW1xSnsxJX9+KanI="
    ,"GameRules":[]
    ,"GameActions":[]
    })

Why the callback? To support JSONP:

http://en.wikipedia.org/wiki/JSONP

JSONP or “JSON with padding” is a complement to the base JSON data format, a pattern of usage that allows a page to request data from a server in a different domain. As a solution to this problem, JSONP is an alternative to a more recent method called Cross-Origin Resource Sharing.

Under the same origin policy, a web page served from server1.example.com cannot normally connect to or communicate with a server other than server1.example.com. An exception is the HTML <script> element. Taking advantage of the open policy for <script> elements, some pages use them to retrieve Javascript code that operates on dynamically-generated JSON-formatted data from other origins. This usage pattern is known as JSONP. Requests for JSONP retrieve not JSON, but arbitrary JavaScript code. They are evaluated by the JavaScript interpreter, not parsed by a JSON parser.

If you are a newbie to JSON and JSONP, this is a short tutorial/example using JQuery (the same library used by Tankster client code):

Cross-domain communications with JSONP, Part 1: Combine JSONP and jQuery to quickly build powerful mashup

But (you know, there is a “but” in every software project 😉 Azure blob storage doesn’t support the JSONP URL (that has a randomly generated callback id):

Query JSON data from Azure Blob Storage with jQuery

There is a proposed solution in that Stack Overflow thread. Agent Maxwell Smart would say: ah! the “old trick” of having the callback in the blob!

dataCallback({"Name":"Valeriano","Surname":"Tortola"})

You can read a more detailed description of problem/solution with example code at @woloski’s post (good practice Matthew! write a post!):

Ajax, Cross Domain, jQuery, WCF Web API or MVC, Windows Azure

One problem to point: note that the callback name is “hardcoded” in blob storage. The gamesCallback present in game status blob should be the name of a global function. But you can change the blob text to whatever valid Javascript code.

And the client code? You can study the gskinner code at Tankster.GamePlay web project, under src\ui\net\ServerDelegate.js:

(function (window) {
    goog.provide('net.ServerDelegate');
    goog.require('net.ServerRequest');

    var ServerDelegate = function () {
        throw new Error('ServerDelegate cannot be instantiated.');
    };

    var p = ServerDelegate;

    p.BASE_API_URL = "/";
    p.BASE_BLOB_URL = "http://tankster.blob.core.windows.net/";
    p.BASE_ASSETS_URL = "";
    p.load = function (type, data, loadNow) {
        var req;
        if (p.CLIENT_URL == null) {
            p.CLIENT_URL = window.location.toString();
        }
//....

There is an interesting switch:

switch (type) {
    //Local / config calls
    case 'strings':
        req = new ServerRequest('locale/en_US/strings.js',
		   null, 'jsonp', null, 'stringsCallback'); break;
    //Game calls
    case 'endTurn':
        req = new ServerRequest(apiURL+'Game/EndTurn/',
		    null, 'xml'); break;
    case 'leaveGame':
        req = new ServerRequest(apiURL+'Game/Leave/'+data.id,
		    {reason:data.reason}, 'xml', ServerRequest.POST); break;
    case 'playerDead':
        req = new ServerRequest(apiURL+'Game/PlayerDead/',
		    null, 'json'); break;
    case 'gameCreate':
        req = new ServerRequest(apiURL+'Game/Queue', data,
		    'xml', ServerRequest.POST); break;
    case 'usersGame':
        req = new ServerRequest(blobURL+'sessions/'+data,
		    null, 'jsonp', null, 'sessionsCallback'); break;
    case 'gameStatus':
        req = new ServerRequest(blobURL+'games/'+data,
		    null, 'jsonp', null, 'gamesCallback'); break;
    case 'gameQueueStatus':
        req = new ServerRequest(blobURL+'gamesqueues/'+data,
		    null, 'jsonp', null, 'gamesqueuesCallback'); break;
    case 'notifications':
        req = new ServerRequest(blobURL+'notifications/'+data,
		    null, 'jsonp'); break;

    //User calls
    case 'verifyUser':
//...

See the ‘gameStatus’ polling: it uses ‘jsonp’ as format. My guess: the ‘gamesCallback’ parameter is not needed: you can use any other name, the function to call resides in the blob content.

I think there are alternatives to game status. The blob reflects the Game entity (see Tankster.Core\Entities\Game.cs). But it could be implemented in two blobs by game:

– One, having the initial status (players, positions,etc…) and the list of ALL the history of the game (think about to implement a chess or go game, you need to save the history).

– Another one, having the “news” (last 10 seconds of game actions). So, the data to poll should be shorter.

The price to pay: web role service should update both. But that update only occurs when a player sends a move (shot, chat…). The poll of game status occurs in every client, triggered by a repeated timeout. Actually, the game blob keeps the last 10 seconds actions AND initial status, weapons, etc…. Each client polls that info. In case a client disconnects and reconnects, it could poll the “complete game” blob to be in sync again.

The separation of that info in two blobs should improve the scalability of the solution. But you know: premature optimization is the root of all evil ;-). If you take that way of store and retrieve games, you should run some stress or/and load tests to have a really measure of such decision impact.

More Tankster code analysis, patterns, and social game dev in general: coming soon.

Some links:

WAT is to Social Gaming, as Windows Azure is to… | Coding4Fun Blog | Channel 9

Thanks! They mention my post 😉

Episode 52 – Tankster and the Windows Azure Toolkit for Social Games | Cloud Cover | Channel 9

Microsoft tailors Azure cloud services to social game developers | VentureBeat

Windows Azure Toolkit for Social Games Released to CodePlex – ‘Tankster’ Social Game Built for Windows Azure

Tankster, a Social Game Built for Windows Azure | Social Gaming on Windows Azure | Channel 9

Social Gaming on Windows Azure | Channel 9

Build Your next Game with the Windows Azure Toolkit for Social Games

Microsoft delivers early build of Windows Azure toolkit for social-game developers | ZDNet

http://www.delicious.com/ajlopez/tankster

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Git: Links, News, Resources (1)

I’m used to be an SVN guy. This year, I started to use Git in customer projects, and now I have some of my personal projects at GitHub. These are some of the links I collected about Git.

http://en.wikipedia.org/wiki/Git_%28software%29

Git is a distributed revision control system with an emphasis on speed.[3] Git was initially designed and developed by Linus Torvalds for Linux kernel development. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Git’s current software maintenance is overseen by Junio Hamano. Git is free software distributed under the terms of the GNU General Public License version 2.

Pro Git – Pro Git Book
http://progit.org/
How to use git without rage
http://www.slideshare.net/eLafo/how-to-use-git-without-rage

C# Development and TDD: Combining TDD kata with git branching and merging
http://codingsolutions.blogspot.com/2010/08/combining-tdd-calculator-kata-with-git.html

A few git tips you didn’t know about
http://mislav.uniqpath.com/2010/07/git-tips/

An Intro to Distributed Version Control | I am Zef
http://zef.me/2871/an-intro-to-distributed-version-control

If Version Control Systems were Airlines | The Changelog
http://changelog.complete.org/archives/698-if-version-control-systems-were-airlines

Git Community Book
http://book.git-scm.com/index.html

Easy version control with git
http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/

Persistent Trees in git, Clojure and CouchDB « EclipseSource Blog
http://eclipsesource.com/blogs/2009/12/13/persistent-trees-in-git-clojure-and-couchdb-data-structure-convergence/

Git’s guts: Branches, HEAD, and fast-forwards
http://www.lostechies.com/blogs/jagregory/archive/2009/11/25/git-s-guts-branches-head-and-fast-forwards.aspx

Git guts: Merging and rebasing
http://www.lostechies.com/blogs/jagregory/archive/2009/11/27/git-guts-merging-and-rebasing.aspx

YouTube – Tech Talk: Linus Torvalds on git
http://www.youtube.com/watch?v=4XpnKHJAok8

Git Evangelism
http://gitevangelism.blogspot.com/

git-fundamentals-in-30-minutes-or-less.pdf (application/pdf Object)
http://maymay.net/blog/wp-content/uploads/2008/11/git-fundamentals-in-30-minutes-or-less.pdf

Git for Computer Scientists
http://eagain.net/articles/git-for-computer-scientists/

Git Evangelism: Branch remotos en git, dos pasos
http://gitevangelism.blogspot.com/2011/07/branch-remotos-en-git-dos-pasos.html

Start a New Branch on your Remote Git Repository | Zorched / One-Line Fix
http://www.zorched.net/2008/04/14/start-a-new-branch-on-your-remote-git-repository/

Help.GitHub – Import from Subversion
http://help.github.com/import-from-subversion/

Git for Personal Projects | Javalobby
http://java.dzone.com/articles/git-personal-projects

Trabajando con GIT, introducción al uso de los branch y git-completion.bash
http://www.adictosaltrabajo.com/tutoriales/tutoriales.php?pagina=git-branch-bash

Git On Windows Plain Introduction
http://www.slideshare.net/testrus/git-on-windows-plain-introduction

Fukyo’s Blog: Git For Windows Developers
http://fukyo-it.blogspot.com/2011/04/git-for-windows-developers.html

How I Turned Down $300,000 from Microsoft to go Full-Time on GitHub
http://tom.preston-werner.com/2008/10/18/how-i-turned-down-300k.html

Git is Inconsistent
http://r6.ca/blog/20110416T204742Z.html

Git tooling for .NET developers – Krzysztof Kozmic – Devlicio.us – Just the Tasty Bits
http://devlicio.us/blogs/krzysztof_kozmic/archive/2011/01/26/git-tooling-for-net-developers.aspx

A successful Git branching model
http://nvie.com/git-model

Mercurial as a Git client | IDisposable Thoughts
http://www.cprieto.com/index.php/2010/06/03/mercurial-as-a-git-client/

Git vs. Mercurial
http://gitvsmercurial.com/

Working with Remote Branches on GitHub
http://howard.vanrooijen.co.uk/blog/2010/04/03/working-with-remote-branches-on-github/

Why is Git telling me “Your branch is ahead of ‘origin/master’ by 11 commits.” and how do I get it to stop?
http://stackoverflow.com/questions/277077/why-is-git-telling-me-your-branch-is-ahead-of-origin-master-by-11-commits-an

My Links
http://www.delicious.com/ajlopez/git
http://www.delicious.com/ajlopez/git+tutorial

Keep tuned!

Angel "Java" Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Domain-Driven Design: Links, News, Resources (1)

More than four years (!) ago, I wrote down a list of DDD resources:

Domain-Driven Design Resources

Now, it’s time to publish a new (partial) list of resources. First, Wikipedia definition:

Domain-Driven Design
http://en.wikipedia.org/wiki/Domain-driven_design

Domain-driven design (DDD) is an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.[1] The premise of domain-driven design is the following:

  • Placing the project’s primary focus on the core domain and domain logic
  • Basing complex designs on a model
  • Initiating a creative collaboration between technical and domain experts to iteratively cut ever closer to the conceptual heart of the problem.

Domain-driven design is not a technology or a methodology. DDD provides a structure of practices and terminology for making design decisions that focus and accelerate software projects dealing with complicated domains.

The term was coined by Eric Evans in his book of the same title.[2]

My recent links:

Domain-Driven Design Community
http://domaindrivendesign.org/

Skills Matter : DDD eXchange 2011: Udi Dahan on Domain Model
http://skillsmatter.com/podcast/design-architecture/talk-from-udi-dahan

RESTful SOA or Domain-Driven Design – A Compromise?
http://www.infoq.com/presentations/RESTful-SOA-DDD

Review: Microsoft N Layer App Sample, Part IV-IoC FTW – Ayende @ Rahien
http://ayende.com/blog/29697/review-microsoft-n-layer-app-sample-part-iv-ioc-ftw

Aggregate | Domain-Driven Design Community
http://domaindrivendesign.org/node/88

Services in Domain-Driven Design | Jimmy Bogard’s Blog
http://lostechies.com/jimmybogard/2008/08/21/services-in-domain-driven-design/

Sample Application First Steps
http://thinkddd.com/blog/2009/03/09/sample-application-first-steps/

Composition Patterns « Caminao’s Ways
http://caminao.wordpress.com/how-to-implement-symbolic-representations/patterns/representation-patterns/composition-patterns/

Skills Matter : DDD eXchange 2011: Patrik Fredriksson on DDD
http://skillsmatter.com/podcast/scala/talk-by-patrick-fredriksson

Skills Matter : DDD eXchange 2011 10-06-11
http://skillsmatter.com/event/design-architecture/ddd-exchange-2011

Skills Matter : In The Brain of Greg Young: CQRS, not just f
http://skillsmatter.com/podcast/open-source-dot-net/cqrs-not-just-for-server-systems

Domain Drive Design N-Layered .NET 4.0 Architecture Guide
http://blogs.msdn.com/b/marblogging/archive/2011/05/23/domain-drive-design-n-layered-net-4-0-architecture-guide.aspx

What is Domain Driven Design? – Jak Charlton – Insane World – Devlicio.us – Just the Tasty Bits
http://devlicio.us/blogs/casey/archive/2011/05/16/what-is-domain-driven-design.aspx

Eben Roux | Aggregate Roots vs. Single Responsibility (and other issues)
http://www.ebenroux.co.za/post/2010/07/27/Aggregate-Roots-vs-Single-Responsibility-(and-other-issues).aspx

Eben Roux | DDD != Aggregate Root
http://www.ebenroux.co.za/post/2009/11/24/DDD-!3d-AR.aspx

Eben Roux | Natural Aggregates vs Synthetic Aggregates
http://www.ebenroux.co.za/post/2010/08/20/Natrual-Aggregates-vs-Synthetic-Aggregates.aspx

Coding Instinct: Queries & Aggregates & DDD
http://www.codinginstinct.com/2011/04/queries-aggregates-ddd.html

Repository is Dead: Long Live Repository | Greg Young
http://codebetter.com/gregyoung/2009/04/23/repository-is-dead-long-live-repository/

domaindrivendesign : Message: What is wrong with aggregate roots?
http://tech.groups.yahoo.com/group/domaindrivendesign/message/21445

DDD: Specifications, Language, and Locality | Greg Young
http://codebetter.com/gregyoung/2008/12/21/ddd-specifications-language-and-locality/

Domain Driven Design with Spring and AspectJ – Java Code Geeks
http://www.javacodegeeks.com/2011/02/domain-driven-design-spring-aspectj.html

Objects_of_Value_KevlinHenney.pdf (application/pdf Object)
http://accu.org/content/conf2010/Objects_of_Value_KevlinHenney.pdf

DDDSample.Net
http://dddsamplenet.codeplex.com/

HunabKu: Repository or DAO?: Repository
http://fabiomaulo.blogspot.com/2009/09/repository-or-dao-repository.html

Abacus
http://www.ebenroux.co.za/page/Abacus.aspx
Example: TDD, DDD, CQRS, Service Bus, Dependecy Injection, Logging, HTTP RPC, Data Access Abstraction, Custom ORM, Composite UI

JavATE – Welcome to JavATE The domain driven framework
http://www.javate.amattioli.it/mainsite/description.html

ndddsample – Google Code
http://code.google.com/p/ndddsample/

http://www.qi4j.orghttp://www.qi4j.org
http://www.qi4j.org/

Bastion DDD Java Framework
http://bastionframework.org/

Sharp Architecture – S#arp Architecture
http://wiki.sharparchitecture.net/default.aspx?AspxAutoDetectCookieSupport=1

NerdDinner with Fluent NHibernate Part 1 – The domain model
http://www.bengtbe.com/blog/post/2009/08/10/NerdDinner-with-Fluent-NHibernate-Part-1-The-domain-model.aspx

From CRUD to Domain-Driven Fluency
http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/

Think DDD
http://thinkddd.com/

My links:

http://www.delicious.com/ajlopez/ddd
http://www.delicious.com/ajlopez/ddd+tutorial
http://www.delicious.com/ajlopez/ddd+video
http://www.delicious.com/ajlopez/ddd+example

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Game Development: Links, News, Resources (1)

Next Post

Recently, I posted about social games programming:

Social Online Games Programming (Part 1) Introduction
Social Online Games Programming (Part 2) Tankster and Windows Azure Toolkit For Social Games

I’m a link collector (a curator?). These are my recent game development related resources discoveries:

Windows Azure Toolkit for Social Games
http://watgames.codeplex.com/

Tankster, a Social Game Built for Windows Azure | Social Gaming on Windows Azure | Channel 9
http://channel9.msdn.com/Series/Social-Gaming-on-Windows-Azure/Tankster-a-Social-Game-Built-for-Windows-Azure

Social Gaming on Windows Azure | Channel 9
http://channel9.msdn.com/Series/Social-Gaming-on-Windows-Azure

Build Your next Game with the Windows Azure Toolkit for Social Games
http://blogs.msdn.com/b/windowsazure/archive/2011/07/20/build-your-next-game-with-the-windows-azure-toolkit-for-social-games.aspx

Microsoft delivers early build of Windows Azure toolkit for social-game developers | ZDNet
http://www.zdnet.com/blog/microsoft/microsoft-delivers-early-build-of-windows-azure-toolkit-for-social-game-developers/10115

Zynga, the Latest Cloud Computing Success | CloudTweaks.com – Cloud Computing Community
http://www.cloudtweaks.com/2011/07/zynga-the-latest-cloud-computing-gaming-success/

YouTube – ‪T-Mobile Angry Birds Live – Behind The Scenes
http://www.youtube.com/watch?v=uYSzff245dk&feature=relmfu

YouTube – ‪T-Mobile Angry Birds Live
http://www.youtube.com/watch?v=jzIBZQkj6SY

Gamasutra – News – Hawkins: ‘The Browser Is The Platform Of The Future’
http://www.gamasutra.com/view/news/33406/Hawkins_The_Browser_Is_The_Platform_Of_The_Future.php

HTML5 canvas awesomeness – games roundup – Red Team Design
http://www.red-team-design.com/html5-canvas-awesomeness-games-roundup

La industria IT y de videojuegos porteños viajan a San Francisco buscando negocios
http://www.emprendedoresnews.com/emprendedores/la-industria-it-y-de-videojuegos-portenos-viajan-a-san-francisco-buscando-negocios.html

Games are an Abstraction of Concepts and Reality | Kapp Notes
http://www.kaplaneduneering.com/kappnotes/index.php/2011/06/games-are-an-abstraction-of-concepts-and-reality/

Which game engine is compatiable with Visual Studio 2010 Ultimate and Silverlight? – Game Development – Stack Exchange
http://gamedev.stackexchange.com/questions/11803/which-game-engine-is-compatiable-with-visual-studio-2010-ultimate-and-silverlight

tools – How can I develop Flash games without expensive software? – Game Development – Stack Exchange
http://gamedev.stackexchange.com/questions/325/how-can-i-develop-flash-games-without-expensive-software

isometric – ActionScript 3 framework / engine for building social game like FarmVille – Stack Overflow
http://stackoverflow.com/questions/3667400/actionscript-3-framework-engine-for-building-social-game-like-farmville

Implementing a timer thread Silverlight Tools and Features
http://www.visiblegrain.com/tools-features/implementing-a-timer-thread.html

Hello World – FlashDevelop (Flixel) – Flash Game Dojo
http://flashgamedojo.com/wiki/index.php?title=Hello_World_-_FlashDevelop(Flixel

PushButton Engine – Modular Flash Game Development
http://pushbuttonengine.com/

haXe – Welcome to haXe !
http://haxe.org/

FlatRedBall
http://www.flatredball.com/frb/blog/

11 Flash isometric engines you can use in your games
http://www.emanueleferonato.com/2010/02/23/11-flash-isometric-engines-you-can-use-in-your-games/

List of game engines – Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/List_of_game_engines

3d – isometric perspective in silverlight – Stack Overflow
http://stackoverflow.com/questions/5168954/isometric-perspective-in-silverlight

2d – Drawing Isometric game worlds – Stack Overflow
http://stackoverflow.com/questions/892811/drawing-isometric-game-worlds

GameSalad – Game creation for everyone ™ – GameSalad Arcade
http://gamesalad.com/

WAR! Zynga Sues The Hell Out Of Brazilian Clone Vostu
http://techcrunch.com/2011/06/16/war-zynga-sues-the-hell-out-of-brazilian-clone-vostu/

Worms Reloaded | Team17.com
http://www.team17.com/?page_id=670

How to make Angry Birds – part 1 | Paul’s blog@Wildbunny
http://www.wildbunny.co.uk/blog/2011/05/12/how-to-make-angry-birds-part-1/

How to make Angry Birds – part 2 | Paul’s blog@Wildbunny
http://www.wildbunny.co.uk/blog/2011/06/07/how-to-make-angry-birds-part-2/

Un juego online infantil con 50 millones de usuarios | TICbeat
http://www.ticbeat.com/tecnologias/juego-online-infantil-50-millones-usuarios/

Imagine Cup 2011 Game Design Competitor Showcase Part 4
http://blogs.msdn.com/b/andrewparsons/archive/2011/06/04/imagine-cup-2011-game-design-competitor-showcase-part-4.aspx

RPG JS: Your online RPG on your browser
http://rpgjs.com/

Start Coding For Windows Phone and XBox Live Indie Games
http://create.msdn.com/en-us/home/getting_started

Lessons From FarmVille: How Zynga Uses The Cloud — InformationWeek
http://www.informationweek.com/news/global-cio/interviews/229402805

High Scalability – High Scalability – Zynga’s Z Cloud – Scale Fast or Fail Fast by Merging Private and Public Clouds
http://highscalability.com/blog/2011/5/19/zyngas-z-cloud-scale-fast-or-fail-fast-by-merging-private-an.html

RedUSERS | Los videojuegos: un mercado en crecimiento para jóvenes desarrolladores
http://www.redusers.com/noticias/los-videojuegos-un-mercado-en-crecimiento-para-jovenes-desarrolladores/

Augmented Reality RPG « I am Zef
http://zef.me/3872/augmented-reality-rpg

MetaEdit+ Forum: Can I generate 2D games for iPhone from models?
http://www.metacase.com/forums/forum_posts.asp?TID=211&PID=693#693

Sid Meier’s Civilization Migrates To Facebook This Summer, Starts Going By Civ World
http://techcrunch.com/2011/05/11/sid-meiers-civilization-migrates-to-facebook-this-summer-starts-going-by-civ-world/

Creating 2D Games with JavaScript & HTML5 – The official Google Code blog
http://googlecode.blogspot.com/2011/05/creating-2d-games-with-javascript-html5.html

The second official clj3D screencast is out! « Web life between Python and lambda calculus
http://alfredodinapoli.wordpress.com/2011/04/10/the-second-official-clj3d-screencast-is-out/

A look inside Origin’s amazing custom gaming PC factory
http://windowsteamblog.com/windows/b/windowsexperience/archive/2011/04/05/a-look-inside-origin-s-amazing-custom-gaming-pc-factory.aspx

jMonkeyEngine 3.0 | Java OpenGL Game Engine
http://jmonkeyengine.com/

Joyride Laboratories
http://joyridelabs.de/game/

Tron clone in Clojure – tzachlivyatan
https://sites.google.com/site/tzachlivyatan/tron-clone-in-clojure

Playdom Social Games – Play Deep Realms
http://www.playdom.com/games/deeprealms

gameandgraphics: Development docs for the…
http://francoaceruti.tumblr.com/post/4064037489/gameandgraphics-development-docs-for-the

The Real Art of Video Games
http://wwww.bliipstudio.com/articles/real-art-video-games/

Bliip Studio
http://bliipstudio.com/

Hello | resatori
http://resatori.com/hello

Clojure Entity Component System | resatori
http://resatori.com/clojure-entity-component-system

Slick – 2D Game Library based on LWJGL
http://slick.cokeandcode.com/

Ruby For Kids – Teach Children Programming By Creating Games
http://davidhayden.com/blog/dave/archive/2011/02/20/RubyForKids.aspx

Box2D – Home
http://box2d.org/

My Links
http://www.delicious.com/ajlopez/gamedevelopment

More Social Games Programming series is coming. I should write about game development in Argentina, too.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Social Online Games Programming (Part 2) Tankster and Windows Azure Toolkit For Social Games

Previous post
Next post

Yesterday, July 20th, Microsoft released a preview version of Windows Azure Toolkit for Social Games, and published a beta version (with code) of a first demo game.

You can download the code from Codeplex: http://watgames.codeplex.com/

You can play the game at: http://www.tankster.net/

The current solution main projects:

Tankster.GamePlay is a Web Role. The only worker role is Tankster.WorkerRole. Tankster.Core is a class library. There are interesting code at Tankster.Common: Azure utilities to access repositories, a job engine; all its code is game-agnostic.

These are my first short comments about the code and implemented features (remember, is a beta! Some of these features/implementations could change in the next release):

– Client technology: HTML5, Javascript, EaselJs (for canvas programming).
– Server technology: ASP.NET MVC 3, some Razor test views (interesting topic: how to test the game without the REAL game), WCF Web API (another interesting topic to discuss: alternative technologies to received the game activity)
– There is a client game model and entities in Javascript. See src/model, src/game.

– There is a server game model (see Tankster.Core class library project)

– You can play in single player mode, but you can choose multi-player online. Then, the game uses ACS Portal to login using Federated Authentication:

– The client code resides in a single page: index.html (with lot of referenced javascript files)
– Client code sends JSON data (commands) to WCF Web API endpoints, using Ajax/JQuery. There are services published, exposing a REST-like interface

routes.MapServiceRoute<GameService>("game");
routes.MapServiceRoute<AuthService>("auth");
routes.MapServiceRoute<UserService>("user");
routes.MapServiceRoute<TestService>("test");

– Most of the game activity is send to game/command service. The service updates the game status residing in a blob at Azure Storage. Code excerpt:

// Add gameAction
var gameAction = new GameAction
{
    Id = Guid.NewGuid(),
    Type = commandType,
    CommandData = commandData,
    UserId = this.CurrentUserId,
    Timestamp = DateTime.UtcNow
};
// Cleanup game actions lists
for (int i = 0; i < game.GameActions.Count(); i++)
{
    if (game.GameActions[i].Timestamp < DateTime.UtcNow.AddSeconds(-10))
    {
        game.GameActions.RemoveAt(i);
        i--;
    }
}
game.GameActions.Add(gameAction);
this.gameRepository.AddOrUpdateGame(game);

– The game status is polled by javascript clients from blob storage. In this way, the ASP.NET MVC web role has less workload.

– The blob resides in the same domain, so no cross-domain JSON call is needed. But the game is prepared to use cross-domain Ajax call, replacing the XmlHttpRequest object by a Flash component.

– The Skirmish game mode (five players in a game) is made queuing the new players in a Game Queue, managed at worker role.

– The Statistics are processed at worker role: some game actions are sent to Azure queue, so the statistics process doesn’t disturb the client game.

– User status, Game status, Skirmish Game Queue status are blobs.

– Statistics data uses SQL Azure.

– There only worker role use a Job Engine to process many tasks, example:

// Game Queue for Skirmish game
Task.TriggeredBy(Message.OfType<SkirmishGameQueueMessage>())
    .SetupContext((message, context) =>
    {
         context.Add("userId", message.UserId);
    })
    .Do(
        new SkirmishGameQueueCommand(userRepository,
            gameRepository, workerContext))
    .OnError(logException)
    .Start();

There are a lot of points to comment and discuss, feed for upcoming posts. Surely, the solution will evolve and new versions will be published (this week? next week?). But it is interesting to have a published game online AND the code to analyzes it.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Social Online Games Programming (Part 1) Introduction

Next Post

You know, I’m a big fan of Farmville. It pushed me to organize my days, using the rhythms of harvests. It’s a control of my daily agenda: if I seed in my farm, then I reserved the time to harvest. And it’s a game you can play alone, without bothering other players.

But I digress, the topic is game programming, not Farmville ;-):  the problems and challenges of programming social games. Curiously, the most successful games in industry are online games and not the most sophisticated ones: instead of 3D real time games, Farmville is a one-player, with a simple 2D rendering. The social game challenges are not in graphics and user experiences.

In this series, I want to enumerate the patterns and solutions we can use in social/online games. I’m not an expert in the topic: game development is not in my expertise (yet ;-). But for me, it’s a way to gain understanding of the problems and possible ways to solve them in such kind of development. It pushes me to learn new technologies, libraries, tools, and concepts.

Some subtopics I’m going to visit (commenting links, examples, maybe some simple code):

– Client technologies
– Server technologies
– Communication, messaging
– Cloud Computing (to assure scalability, performance, availability)
– Architectural styles and patterns to use (my preferred subtopic)
– Kind of games: single player, turn-based, real time
– Testing (TDD, other kind of tests)

Maybe I could write two simple examples (one-player,  turn-based), but I should review my schedule to have enough time for that activity. It would be a good excuse to exercise REST, Javascript, JQuery, PHP, Azure, artificial intelligence? 😉

It could be a long journey, but this is the first step 😉

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

REST: Links, News and resources (1)

Recently, I posted links with tutorials, examples, resources about Javascript and HTML5:

Javascript: Links, News and Resources (1)
HTML5: Links, News and Resources (1)

Now, a third important leg: REST at server. My recent links:

InfoQ: RESTful SOA or Domain-Driven Design – A Compromise?
http://www.infoq.com/presentations/RESTful-SOA-DDD

REST en Te lo dije (Spanish blog)
http://eamodeorubio.wordpress.com/category/webservices/rest/

Literate Programming – Nobody Understands REST or HTTP
http://blog.steveklabnik.com/2011/07/03/nobody-understands-rest-or-http.html

REST using the WCF Web API – Basics (Part2)
http://blog.alexonasp.net/post/2011/04/16/REST-using-the-WCF-Web-API-e28093-Basics-(Part2).aspx

Getting started with the WCF Web API – The Problem Solver
http://msmvps.com/blogs/theproblemsolver/archive/2011/05/31/getting-started-with-the-wcf-web-api.aspx

Using the WCF Web API in an ASP.NET MVC application – The Problem Solver
http://msmvps.com/blogs/theproblemsolver/archive/2011/06/13/using-the-wcf-web-api-in-an-asp-net-mvc-application.aspx

Windows Azure Storage : REST API (part 2) – Storage Client APIs – Microsoft Certification Examples, exercises, practises, tutorials, solutions about Windows
http://mscerts.programming4.us/windows/windows%20azure%20storage%20%20%20rest%20api%20(part%202)%20-%20storage%20client%20apis.aspx

REST Services y WCF’s Web Api – ALT.NET Hispano Wiki
http://altnethispano.org/wiki/van-2010-05-27-rest-wcf-web-api.ashx

RestBucks on .Net; paying the order
http://joseoncode.com/2011/06/15/restbucks-on-net-paying-the-order/

iWork.com – LessonsLearnedFromFailureOfSOAP
http://public.iwork.com/document/?d=LessonsLearnedFromFailureOfSOAP.key&a=p1355173147

RestBucks on .Net: Ordering Coffee
http://joseoncode.com/2011/06/01/restbucks-on-net-ordering-coffee/

REST in Practice
http://restinpractice.com/default.aspx

Introducing RestBucks on .Net
http://joseoncode.com/2011/05/31/introducing-restbucks-on-net/

Distributed computing fallacies and REST | Jimmy Bogard’s Blog
http://lostechies.com/jimmybogard/2011/05/27/distributed-computing-fallacies-and-rest/

Writing REST services
http://www.ibm.com/developerworks/xml/tutorials/x-restatompp/

Learn REST: A Tutorial
http://rest.elkstein.org/

InfoQ: How to GET a Cup of Coffee
http://www.infoq.com/articles/webber-rest-workflow

REST services with MVC « G# blog
http://thegsharp.wordpress.com/2011/05/02/rest-services-with-mvc/

Microsoft remakes WCF for REST and the web « Tim Anderson’s ITWriting
http://www.itwriting.com/blog/4002-microsoft-remakes-wcf-for-rest-and-the-web.html

mvcConf 2 – Glenn Block: Take some REST with WCF | mvcConf | Channel 9
http://channel9.msdn.com/Series/mvcConf/mvcConf-2-Glenn-Block-Take-some-REST-with-WCF

As usual, my links at delicious:

http://delicious.com/ajlopez/rest
http://delicious.com/ajlopez/rest+tutorial
http://delicious.com/ajlopez/rest+video
http://delicious.com/ajlopez/rest+presentation
http://delicious.com/ajlopez/rest+example
http://delicious.com/ajlopez/restful

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez