Building Kick Ass Video Games for the Cloud
-
Upload
chris-schalk -
Category
Technology
-
view
4.550 -
download
0
description
Transcript of Building Kick Ass Video Games for the Cloud
![Page 1: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/1.jpg)
How to Build Kick Ass Games for the Cloud
Christian SchalkGoogle Developer Advocate
GDC Online 2011Austin, Texas - October 10, 2011
![Page 2: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/2.jpg)
About the Speaker
Christian Schalk
Day Job● Developer Advocate for Google's Cloud Technology
○ App Engine, Google Storage, Prediction API, BigQuery ...
● Mostly Server-Side Java Background○ "JavaServer Faces: The Complete Reference" Co-Author
● Haven't developed video games since the Commodore-64!
Yes, I'm old school ;-)
![Page 3: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/3.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 4: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/4.jpg)
Let's start with a Demo!
![Page 5: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/5.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 6: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/6.jpg)
Reviewing PlayN!Formerly known as "ForPlay"
● An API for building cross-platform games
● Core game code can be platform agnostic
● Develop games in Java○ Familiar language/toolset
● Leverages Google Web Toolkit○ Compiles to JS/HTML5, (among other platforms)
● Free and Open Source (alpha)○ http://code.google.com/p/playn
![Page 7: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/7.jpg)
Introducing PlayN!A GWT abstraction layer for games
Implementations for Java, HTML5(GWT/JS), Android, Flash
PlayN API
![Page 8: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/8.jpg)
Components of PlayN!
Fully generic gaming components. Core game logic is fully platform independent!
Implements core.Game PlayN.*
![Page 9: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/9.jpg)
PlayN Cross Platform Magic
● Game uses core PlayN abstractions, is unaware of which platform is running
● The only platform-specific code is in the entry point for each platform:
PlayN.run(new MyGame()); PlayN.run(new MyGame());
![Page 10: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/10.jpg)
Other PlayN Benefits
● Built-in physics engine based on proven OpenSource technologies
● Box2D○ C++ 2D Physics engine by Erin Catto
● JBox2D○ A port of Box2D from C++ to Java
● GWTBox2D○ A port of JBox2D from Java to JavaScript
![Page 11: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/11.jpg)
Benefits of GWT Abstraction
● GWT Compiler optimizes code for size○ Removes unused code○ Evaluates when possible at compile time○ Inlines functions○ Heavily obfuscated result code
● Smaller compiled code - faster load time
● Optimized caching, avoids unnecessary network IO
![Page 12: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/12.jpg)
Benefits of HTML5 for Games
● New HTML elements○ 2D canvas○ Audio, Video
● Application Cache
● 3D Canvas (WebGL)○ Open GL ES 2.0 made JavaScript friendly
● CSS3○ Supports hardware accelerated transforms
![Page 13: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/13.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 14: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/14.jpg)
Google App EngineBuild your Apps on Google's cloud
![Page 15: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/15.jpg)
● Easy to build● Easy to maintain● Easy to scale
Introducing App Engine
Focus on building your app, let us wear the pagers!
Build and run your web apps on Google’s Cloud Infrastructure
![Page 16: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/16.jpg)
Cloud Development in a Box
● Development SDK● Local development tools
○ DevServer, admin○ Eclipse plugin
● Language runtimes● Specialized API services ● Cloud-based dashboard● Automatic scaling
○ Built-in fault tolerance○ Automated load balancing
● Continuously evolving...
![Page 17: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/17.jpg)
Language Runtime Options
GO JavaExperimental
![Page 18: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/18.jpg)
Specialized APIs/Services for the Sandbox
BlobstoreImages
Mail XMPP Task Queue
Memcache Datastore URL Fetch
User Service
![Page 19: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/19.jpg)
App Engine Evolution Through The Years
App Engine LaunchPython
DatastoreMemcachelogs export
2008 2009 2010
JavaDB Import
cron
Batch write/readHttps
Status-Dashboard
Task QueuesXMPP
incoming email
MultitenancyInstance Console
Always Onhi-perf imag
10 min tasks
BlobstoreAppstats
cursorsMapper
2011
Hi-ReplicationDatastore
Channel APIFiles API
Remote APIProsp Search
![Page 20: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/20.jpg)
100,000+ Active developers per month
200,000+Active apps per week
App Engine - By the Numbers
![Page 21: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/21.jpg)
App Engine - By the Numbers
1,500,000,000+Page views per day
![Page 22: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/22.jpg)
Gaming - Share data Mobile or Web!
![Page 24: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/24.jpg)
Google Storage for DevelopersStore your data in Google's cloud
![Page 25: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/25.jpg)
What Is Google Storage?
● Store your data in Google's cloud○ any format, any amount, any time
● You control access to your data○ private, shared, or public
● Access via Google APIs or 3rd party tools/libraries
![Page 26: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/26.jpg)
Sample Use Cases
Static content hostinge.g. static html, images, music, video Backup and recoverye.g. personal data, business records Sharinge.g. share data with your customers Data storage for applicationse.g. used as storage backend for Android, AppEngine, Cloud based apps Storage for Computatione.g. BigQuery, Prediction API
![Page 27: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/27.jpg)
Google Storage Benefits
High Performance and Scalability Backed by Google infrastructure
Strong Security and Privacy Control access to your data
Easy to UseGet started fast with Google & 3rd party tools
![Page 28: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/28.jpg)
Google Storage Technical Details● RESTful API
○ Verbs: GET, PUT, POST, HEAD, DELETE ○ Resources: identified by URI○ Compatible with S3
● Buckets ○ Flat containers
● Objects ○ Any type○ Size: 100 GB / object
● Access Control for Google Accounts ○ For individuals and groups
● Two Ways to Authenticate Requests ○ Sign request using access keys ○ Web browser login
![Page 29: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/29.jpg)
Demo
● Tools:○ GSUtil○ GS Manager
● Upload / Download
![Page 31: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/31.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 32: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/32.jpg)
Requirements for getting started with PlayN
● Clone a copy of PlayN○ git clone https://code.google.com/p/playn
● Core Requirements○ Java 6 SDK○ Apache Ant○ Maven○ App Engine SDK○ Android SDK
● Requirements with Eclipse○ Eclipse IDE Indigo 3.7 (Or earlier version w/ Maven)○ Google Plugin for Eclipse○ Android Plugin for Eclipse
![Page 33: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/33.jpg)
Building/Installing PlayN
● After you've cloned a copy of PlayN○ git clone https://code.google.com/p/playn
● And satisfied the core requirements, you can install via:○ cd playn (directory where your copy is location)○ mvn install (or 'ant install')
● Running 'showcase' sample app with Mvn○ cd playn/sample/showcase/core○ mvn compile exec:java
● Running 'showcase' sample app with Ant○ cd playn/sample/showcase○ ant run-java
![Page 35: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/35.jpg)
Building a new project in PlayN
● From the command line:○ mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn
-DarchetypeArtifactId=playn-archetype○ ...
● From Eclipse○ Select File → New → Other..., then select Maven →
Maven Project in the dialog that pops up, then click Next.
■ Click Next again unless you wish to specify a custom workspace location.■ Check Include snapshot archetypes in the dialog and then double click
on the playn-archetype in the list of archetypes○ ...
![Page 36: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/36.jpg)
Demo: Building a new Game in PlayN
![Page 37: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/37.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 38: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/38.jpg)
Deploy your HTML project to the Cloud
● For Google App Engine Deployment, you can easily convert the project to an App Engine Project
![Page 39: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/39.jpg)
Deploy your HTML project to the Cloud
● After converting your HTML project to an App Engine project you will have to do...
● Add a 'WEB-INF/lib/appengine-web.xml' file○ Note: Click 'Quick Fix' in the Errors console of
Eclipse
● Before deployment make sure your 'WEB-INF/lib' has the necessary runtime App Engine jar files.
![Page 40: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/40.jpg)
Agenda
● PlayN Recap
● Google Cloud Tech Review○ App Engine○ Google Storage○ ...
● Hands on with PlayN - Getting Started
● Deploying your game to the cloud
● Setting up an RPC mechanism
![Page 41: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/41.jpg)
Setting up an RPC mechanism
● Building Your Server○ PlayN comes with a preliminary Server example
code that uses Jetty■ Is not needed if deploying to App Engine■ Instead, you can implement your own server by
adding an HttpServlet to your project■ Have it implement the doPost() method■ Can map it to url: '/rpc' in web.xml
● Building your client code○ If Cloud is your main deployment, you can use
GWT's RequestBuilder�■ You can build your HTTP Post to send data to
your server
![Page 42: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/42.jpg)
Setting up an RPC mechanism● Example: A client method to persist a score
private void submitScore(int score) { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "/rpc"); rb.setHeader("Content-Type", "application/x-www-form-urlencoded"); try { rb.sendRequest("score="+score, new RequestCallback() { public void onError(Request request, Throwable exception) { requestFailed(exception); } public void onResponseReceived(Request request, Response response) { log.info("Score sent and response received."); } }); } catch (RequestException ex) { requestFailed(ex); }}
![Page 43: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/43.jpg)
Setting up an RPC mechanism● Example: Server method to persist score sent from
clientprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain");
User user = UserServiceFactory.getUserService().getCurrentUser(); String id = null; if (user == null){ id = "Anonymous"; } else { id = user.getNickname(); } String score = req.getParameter("score"); if (score != null){ persistScore(score, id); } }private void persistScore(String score, String userid) {...}
![Page 44: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/44.jpg)
New! Using the RPCService Wizard(As of version 2.4 of the Google Plugin for Eclipse)
Select the project containing any Persistent classes, and then...File > New > Other > Google > RPC Service
Generates CRUD stub code for all persistent classes
![Page 45: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/45.jpg)
Demo: Introducing 'Cloud Warrior'
Google Storage
Game Assets(images/sounds)
Game ScoresProfile Data
App EngineDatastore
Game Play (PlayN)
![Page 46: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/46.jpg)
PlayN Summary
● Open source, cross-platform game abstraction layer○ Core game logic is platform agnostic
● ForPlay abstracts away the core components of a game○ The game loop, I/O system, and asset management
● Write in familiar Java, get performance on multiple platforms
○ Superior Java development/debug○ GWT allows compilation to fast JavaScript/HTML5
● Your assignment:○ Download PlayN and build a game! ○ http://code.google.com/p/playn/
![Page 47: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/47.jpg)
Announcing the New PlayN Developer Site!Announcements!
http://developers.google.com/playn/
![Page 48: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/48.jpg)
Join us at New Game! Use coupon HTML5ROCKS for 15% off registration
Announcements!
![Page 49: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/49.jpg)
Q&A@cschalk
![Page 50: Building Kick Ass Video Games for the Cloud](https://reader034.fdocuments.us/reader034/viewer/2022051514/54bf0b564a7959b8618b4570/html5/thumbnails/50.jpg)
Thank You!@cschalk