SlideShare una empresa de Scribd logo
1 de 32
IttyBittyBoom.com Cramp + Websockets = Awesome
What ? Attempt to play film here...
Why ?
How ? Drawing - canvas Network Requests - websockets Server - cramp
HTML5 Canvas Very Cool, Can do lots of cool things with it, Browser support is good (safari3.2, chrome3, firefox 3.0)
<table id= &quot;map&quot; > <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> </table>
 
Sprites canvas.getContext( '2d' ).drawImage( image, imgOffsetX, imgOffsetY,  frameWidth,  frameHeight, xPos, yPos,  frameWidth,  frameHeight)
Websockets Full Duplex communication channel over a single socket Javascript interface Cope with firewalls + proxies
//Create one: var  socket  =   new   WebSocket ( 'ws://ittybittyboom.com/game' ); //Use it: socket . onopen   =   function ( evt )    {  alert ( &quot;Connection open ...&quot; ); }; socket . onmessage   =   function ( evt ) {  alert (  &quot;Received Message:  &quot;   +   evt. data ); }; socket . onclose   =   function ( evt ) {  alert ( &quot;Connection closed.&quot; ); }; socket. send (  &quot;Any data you fancy&quot;  );
Where does Itty  use them? Everywhere!
“ Run Away!”
//Register Keypress switch ( event .which){ case   38 : MrJaba.Bomberman.me.setMovementDirection( 'up' );  break ; case   40 : MrJaba.Bomberman.me.setMovementDirection( 'down' );  break ; case   37 : MrJaba.Bomberman.me.setMovementDirection( 'left' );  break ; case   39 : MrJaba.Bomberman.me.setMovementDirection( 'right' );  break ; } //Run Every Clock Tick: update : function (){ if ( this .canMoveTo( newX, newY )){ MrJaba.Bomberman.GameClient.trigger( 'player_move' );  } } //Send data to the server {&quot;type&quot;:&quot;player_move&quot;,&quot;uuid&quot;:&quot;5a5c0a80-844f-012d-5d1f-001b63957646&quot;,&quot;data&quot;:{&quot;x&quot;:&quot;0&quot;,&quot;y&quot;:&quot;105&quot;}} socket. send (movement_data);
“ You can't give  a bomb to a baby!”
//Trigger the bombdrop on the game client MrJaba.Bomberman.GameClient.trigger( 'send_bomb_drop' ); //Send the Bomb drop message  socket. send ( { &quot;type&quot; : &quot;send_bomb_drop&quot; , &quot;uuid&quot; : &quot;5a5c0a80-844f-012d-5d1f-001b63957646&quot; , &quot;data&quot; :{ &quot;x&quot; : &quot;0&quot; , &quot;y&quot; : &quot;90&quot; }} ); //The server will update it's map of players to bombs and issue an update every 5msec {type: &quot;update_bombs&quot; , positions:{  &quot;7fd93b20-8465-012d-5d20-001b63957646&quot; :{ x:  &quot;0&quot;  y:  &quot;0&quot;  } }} //The socket receives all messages through this: socket . onmessage   =   function ( evt ){ var  data  =  JSON. parse (evt. data ) handleEvent ( data[ 'type' ], data ); };
updateBombPositions :  function ( positions ){ $ .each(positions,  function (bombId, bomb){ if ( isNewBomb(bombId) ){  MrJaba.Bomberman.bombs[bombId]  =   new   Bomb (bombId, bomb)  } }) }, //Event Handling Code calls this
“ Kill! Kill! Kill!  Filthy bastards,  Commies!” “ Norman! Tea's Ready!” “ Coming Dear!”
//tick tick...boom MrJaba.Bomberman.detonate( this ,  this .getTileX(),  this .getTileY()); detonate : function ( bomb, tileX, tileY ){ delete  MrJaba.Bomberman.bombs[bomb.getId()]; MrJaba.Bomberman.GameClient.trigger( 'send_bomb_detonate' , bomb.getId()); bomb.toExplosion(); },
Apparently Explosions Are...Unpleasant sendHotBurningDeath : function (){ var  alreadyKilled  =   this .killed; this .tilesAround(  this .getTileX(),  this .getTileY(),  function (tileX, tileY, direction, radius){ MrJaba.Bomberman.killPlayersAt( tileX, tileY, alreadyKilled ); });  },
Cramp! Asynchronous EventMachine based web framework
Asynchronous Event Driven Code Event Loop Request Handler Request Handler
Cramp::Controller::Action
class   RootController  < Cramp::Controller::Action on_start  :send_socket def   send_socket render   File .open( &quot;public/index.html&quot; ,  'r' ){ | f | f.readlines } finish end end
Anatomy of a cramp request Request: Blow the bloody doors off! initialize Initialize Response  Start request Finish Request
Cramp::Controller::Websocket
class   GameController  < Cramp::Controller::Websocket on_data  :receive_message def   receive_message ( data ) message  =   JSON .parse(data) type  =  message[ 'type' ]  uuid  =  message[ 'uuid' ] if   Game .player_in_game?(uuid)  ||  type  ==   &quot;register&quot; update_last_message_time(uuid) self .send( &quot;receive_ #{type} &quot; , message, uuid) end end end
Example! { &quot;type&quot; : &quot;send_bomb_drop&quot; , &quot;uuid&quot; : &quot;4bba07e0-846c-012d-5d29-001b63957646&quot; , &quot;data&quot; :{ &quot;x&quot; : &quot;0&quot; , &quot;y&quot; : &quot;0&quot; }} Client: def   receive_message ( data ) message  =   JSON .parse(data) type  =  message[ 'type' ]  uuid  =  message[ 'uuid' ] if   Game .player_in_game?(uuid)  ||  type  ==   &quot;register&quot; update_last_message_time(uuid) self .send( &quot;receive_ #{type} &quot; , message, uuid) end end Server: def   receive_send_bomb_drop ( message, uuid ) position  =  { :x  => message[ 'data' ][ 'x' ],  :y  => message[ 'data' ][ 'y' ]} Game .bomb_positions[uuid]  =  position  if   ! uuid.nil? end
Again and Again and Again Recurring Actions are super easy in Cramp
periodic_timer  :push_states ,  :every  =>  0.05 def   push_states data  =  { :type  =>  'update_positions' ,  :positions  => game_states_for_connection}.to_json render  data end def   push_bombs if   Game .bomb_positions.size  >   0 data  =  { :type  =>  'update_bombs' ,  :positions  =>  Game .bomb_positions}.to_json render  data end end periodic_timer  :push_bombs ,  :every  =>  0.05
Alternatives?
Thank You's!
Game Over! Tom Crinson @MrJaba http://github.com/MrJaba/Websocket-Bomberman

Más contenido relacionado

Destacado

Higher Order Ruby
Higher Order RubyHigher Order Ruby
Higher Order RubyTom Crinson
 
Java lead developer & architect
Java lead developer & architectJava lead developer & architect
Java lead developer & architectMark Long
 
Arqu hardware 03 - microprocesadores intel (63170)
Arqu hardware   03 - microprocesadores intel (63170)Arqu hardware   03 - microprocesadores intel (63170)
Arqu hardware 03 - microprocesadores intel (63170)paola
 
Arqu hardware 03 - microprocesadores intel (63170)
Arqu hardware   03 - microprocesadores intel (63170)Arqu hardware   03 - microprocesadores intel (63170)
Arqu hardware 03 - microprocesadores intel (63170)paola
 
Mantenimiento 04 - regulador de voltaje (63170)
Mantenimiento   04 - regulador de voltaje (63170)Mantenimiento   04 - regulador de voltaje (63170)
Mantenimiento 04 - regulador de voltaje (63170)paola
 
In Home Inteligentni Domov
In Home Inteligentni DomovIn Home Inteligentni Domov
In Home Inteligentni DomovJan Prucha
 
Arqu hardware 05 - conectores (63170)
Arqu hardware   05 - conectores (63170)Arqu hardware   05 - conectores (63170)
Arqu hardware 05 - conectores (63170)paola
 
A few questions on MongoDB
A few questions on MongoDBA few questions on MongoDB
A few questions on MongoDBTom Crinson
 

Destacado (9)

CITIB - EN
CITIB - ENCITIB - EN
CITIB - EN
 
Higher Order Ruby
Higher Order RubyHigher Order Ruby
Higher Order Ruby
 
Java lead developer & architect
Java lead developer & architectJava lead developer & architect
Java lead developer & architect
 
Arqu hardware 03 - microprocesadores intel (63170)
Arqu hardware   03 - microprocesadores intel (63170)Arqu hardware   03 - microprocesadores intel (63170)
Arqu hardware 03 - microprocesadores intel (63170)
 
Arqu hardware 03 - microprocesadores intel (63170)
Arqu hardware   03 - microprocesadores intel (63170)Arqu hardware   03 - microprocesadores intel (63170)
Arqu hardware 03 - microprocesadores intel (63170)
 
Mantenimiento 04 - regulador de voltaje (63170)
Mantenimiento   04 - regulador de voltaje (63170)Mantenimiento   04 - regulador de voltaje (63170)
Mantenimiento 04 - regulador de voltaje (63170)
 
In Home Inteligentni Domov
In Home Inteligentni DomovIn Home Inteligentni Domov
In Home Inteligentni Domov
 
Arqu hardware 05 - conectores (63170)
Arqu hardware   05 - conectores (63170)Arqu hardware   05 - conectores (63170)
Arqu hardware 05 - conectores (63170)
 
A few questions on MongoDB
A few questions on MongoDBA few questions on MongoDB
A few questions on MongoDB
 

Similar a Itty bittypresentation lrug

Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflowMark Proctor
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec SpockCARA_Lyon
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)Youssef Dirani
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)Youssef Dirani
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?Eric Smith
 
Bash Scripting Gabrovo
Bash Scripting GabrovoBash Scripting Gabrovo
Bash Scripting GabrovoMarian Marinov
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011Scalac
 
Illuminated Hacks -- Where 2.0 101 Tutorial
Illuminated Hacks -- Where 2.0 101 TutorialIlluminated Hacks -- Where 2.0 101 Tutorial
Illuminated Hacks -- Where 2.0 101 Tutorialmikel_maron
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Alex Kavanagh
 
... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)James Titcumb
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3kitthod
 

Similar a Itty bittypresentation lrug (20)

Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflow
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
 
Bash Geekcamp
Bash GeekcampBash Geekcamp
Bash Geekcamp
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?
 
Bash Scripting Gabrovo
Bash Scripting GabrovoBash Scripting Gabrovo
Bash Scripting Gabrovo
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
Illuminated Hacks -- Where 2.0 101 Tutorial
Illuminated Hacks -- Where 2.0 101 TutorialIlluminated Hacks -- Where 2.0 101 Tutorial
Illuminated Hacks -- Where 2.0 101 Tutorial
 
Groovy
GroovyGroovy
Groovy
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3
 
About Go
About GoAbout Go
About Go
 
JavaScript Needn't Hurt!
JavaScript Needn't Hurt!JavaScript Needn't Hurt!
JavaScript Needn't Hurt!
 
Argon walkthru 1-26
Argon walkthru 1-26Argon walkthru 1-26
Argon walkthru 1-26
 
... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)
 
Presentation1
Presentation1Presentation1
Presentation1
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3
 

Más de Tom Crinson

Destructuring demystified
Destructuring demystifiedDestructuring demystified
Destructuring demystifiedTom Crinson
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of RubyTom Crinson
 
Javascript Basics for Advertisers
Javascript Basics for AdvertisersJavascript Basics for Advertisers
Javascript Basics for AdvertisersTom Crinson
 
Object Oriented Design Principles - SOLID
Object Oriented Design Principles - SOLIDObject Oriented Design Principles - SOLID
Object Oriented Design Principles - SOLIDTom Crinson
 
Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Tom Crinson
 

Más de Tom Crinson (6)

Destructuring demystified
Destructuring demystifiedDestructuring demystified
Destructuring demystified
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Crystal Agile
Crystal AgileCrystal Agile
Crystal Agile
 
Javascript Basics for Advertisers
Javascript Basics for AdvertisersJavascript Basics for Advertisers
Javascript Basics for Advertisers
 
Object Oriented Design Principles - SOLID
Object Oriented Design Principles - SOLIDObject Oriented Design Principles - SOLID
Object Oriented Design Principles - SOLID
 
Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it.
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Itty bittypresentation lrug

  • 1. IttyBittyBoom.com Cramp + Websockets = Awesome
  • 2. What ? Attempt to play film here...
  • 4. How ? Drawing - canvas Network Requests - websockets Server - cramp
  • 5. HTML5 Canvas Very Cool, Can do lots of cool things with it, Browser support is good (safari3.2, chrome3, firefox 3.0)
  • 6. <table id= &quot;map&quot; > <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td><td walk= 'false' > WallBlockTall </td><td> StoneBlock </td> </tr> <tr> <td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td><td> StoneBlock </td> </tr> </table>
  • 7.  
  • 8. Sprites canvas.getContext( '2d' ).drawImage( image, imgOffsetX, imgOffsetY, frameWidth, frameHeight, xPos, yPos, frameWidth, frameHeight)
  • 9. Websockets Full Duplex communication channel over a single socket Javascript interface Cope with firewalls + proxies
  • 10. //Create one: var socket = new WebSocket ( 'ws://ittybittyboom.com/game' ); //Use it: socket . onopen = function ( evt ) { alert ( &quot;Connection open ...&quot; ); }; socket . onmessage = function ( evt ) { alert ( &quot;Received Message: &quot; + evt. data ); }; socket . onclose = function ( evt ) { alert ( &quot;Connection closed.&quot; ); }; socket. send ( &quot;Any data you fancy&quot; );
  • 11. Where does Itty use them? Everywhere!
  • 13. //Register Keypress switch ( event .which){ case 38 : MrJaba.Bomberman.me.setMovementDirection( 'up' ); break ; case 40 : MrJaba.Bomberman.me.setMovementDirection( 'down' ); break ; case 37 : MrJaba.Bomberman.me.setMovementDirection( 'left' ); break ; case 39 : MrJaba.Bomberman.me.setMovementDirection( 'right' ); break ; } //Run Every Clock Tick: update : function (){ if ( this .canMoveTo( newX, newY )){ MrJaba.Bomberman.GameClient.trigger( 'player_move' ); } } //Send data to the server {&quot;type&quot;:&quot;player_move&quot;,&quot;uuid&quot;:&quot;5a5c0a80-844f-012d-5d1f-001b63957646&quot;,&quot;data&quot;:{&quot;x&quot;:&quot;0&quot;,&quot;y&quot;:&quot;105&quot;}} socket. send (movement_data);
  • 14. “ You can't give a bomb to a baby!”
  • 15. //Trigger the bombdrop on the game client MrJaba.Bomberman.GameClient.trigger( 'send_bomb_drop' ); //Send the Bomb drop message socket. send ( { &quot;type&quot; : &quot;send_bomb_drop&quot; , &quot;uuid&quot; : &quot;5a5c0a80-844f-012d-5d1f-001b63957646&quot; , &quot;data&quot; :{ &quot;x&quot; : &quot;0&quot; , &quot;y&quot; : &quot;90&quot; }} ); //The server will update it's map of players to bombs and issue an update every 5msec {type: &quot;update_bombs&quot; , positions:{ &quot;7fd93b20-8465-012d-5d20-001b63957646&quot; :{ x: &quot;0&quot; y: &quot;0&quot; } }} //The socket receives all messages through this: socket . onmessage = function ( evt ){ var data = JSON. parse (evt. data ) handleEvent ( data[ 'type' ], data ); };
  • 16. updateBombPositions : function ( positions ){ $ .each(positions, function (bombId, bomb){ if ( isNewBomb(bombId) ){ MrJaba.Bomberman.bombs[bombId] = new Bomb (bombId, bomb) } }) }, //Event Handling Code calls this
  • 17. “ Kill! Kill! Kill! Filthy bastards, Commies!” “ Norman! Tea's Ready!” “ Coming Dear!”
  • 18. //tick tick...boom MrJaba.Bomberman.detonate( this , this .getTileX(), this .getTileY()); detonate : function ( bomb, tileX, tileY ){ delete MrJaba.Bomberman.bombs[bomb.getId()]; MrJaba.Bomberman.GameClient.trigger( 'send_bomb_detonate' , bomb.getId()); bomb.toExplosion(); },
  • 19. Apparently Explosions Are...Unpleasant sendHotBurningDeath : function (){ var alreadyKilled = this .killed; this .tilesAround( this .getTileX(), this .getTileY(), function (tileX, tileY, direction, radius){ MrJaba.Bomberman.killPlayersAt( tileX, tileY, alreadyKilled ); }); },
  • 20. Cramp! Asynchronous EventMachine based web framework
  • 21. Asynchronous Event Driven Code Event Loop Request Handler Request Handler
  • 23. class RootController < Cramp::Controller::Action on_start :send_socket def send_socket render File .open( &quot;public/index.html&quot; , 'r' ){ | f | f.readlines } finish end end
  • 24. Anatomy of a cramp request Request: Blow the bloody doors off! initialize Initialize Response Start request Finish Request
  • 26. class GameController < Cramp::Controller::Websocket on_data :receive_message def receive_message ( data ) message = JSON .parse(data) type = message[ 'type' ] uuid = message[ 'uuid' ] if Game .player_in_game?(uuid) || type == &quot;register&quot; update_last_message_time(uuid) self .send( &quot;receive_ #{type} &quot; , message, uuid) end end end
  • 27. Example! { &quot;type&quot; : &quot;send_bomb_drop&quot; , &quot;uuid&quot; : &quot;4bba07e0-846c-012d-5d29-001b63957646&quot; , &quot;data&quot; :{ &quot;x&quot; : &quot;0&quot; , &quot;y&quot; : &quot;0&quot; }} Client: def receive_message ( data ) message = JSON .parse(data) type = message[ 'type' ] uuid = message[ 'uuid' ] if Game .player_in_game?(uuid) || type == &quot;register&quot; update_last_message_time(uuid) self .send( &quot;receive_ #{type} &quot; , message, uuid) end end Server: def receive_send_bomb_drop ( message, uuid ) position = { :x => message[ 'data' ][ 'x' ], :y => message[ 'data' ][ 'y' ]} Game .bomb_positions[uuid] = position if ! uuid.nil? end
  • 28. Again and Again and Again Recurring Actions are super easy in Cramp
  • 29. periodic_timer :push_states , :every => 0.05 def push_states data = { :type => 'update_positions' , :positions => game_states_for_connection}.to_json render data end def push_bombs if Game .bomb_positions.size > 0 data = { :type => 'update_bombs' , :positions => Game .bomb_positions}.to_json render data end end periodic_timer :push_bombs , :every => 0.05
  • 32. Game Over! Tom Crinson @MrJaba http://github.com/MrJaba/Websocket-Bomberman