Skip to content

nanki/WebSDL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

WebSDL - Ruby/SDL with HTML5 technology

WebSDL is a library which provides Ruby/SDL interface on top of WebSocket and Canvas.

Overview

On the server-side, WebSDL translates the Ruby/SDL API call into a serialized command sequence -- temporarily called 'PostCanvas' -- and translates it to the Canvas API call on the browser-side.

Likewise, the JavaScript events on the browser-side are translated into the Ruby/SDL events on the server-side.

Requirements

Demo

To run native SDL version.

$ ruby -Ilib samples/sample1.rb

You should use rsdl command on Mac OSX.

$ rsdl -Ilib samples/sample1.rb

To run WebSDL version.

$ ruby -Ilib samples/sample1.rb web
$ open samples/test.html

Instruction

Here is a sample code, which draws a black background.

require 'websdl'

class TestFrame < Frame
  def open_screen
    SDL::Screen.open(640, 480, 32, SDL::DOUBLEBUF)
  end

  def mainloop(screen)
    while event = SDL::Event.poll
      # ...
    end
    screen.fill_rect(0, 0, screen.w, screen.h, 0)
    screen.flip
  end
end

# switch to WebSDL
SDL = WebSDL

SDL.init(SDL::INIT_VIDEO)
SDL.run(TestFrame)

To enable multi-user functionality, WebSDL provides Frame class, something like Java Servlet.

Frame#open_screen : is a callback which should return an instance of SDL::Screen.

Frame#mainloop : is application's main loop.

Frame#frames : stores all 'active' instances of Frame.

Known issues

  • All implementations and functions are Proof-of-Concept quality.
  • There are few functions. Actually, only SDL::Surface#draw_rect and SDL::Event::MouseMotion are implemented.

Contact

@nanki / nanki at dotswitch.net / http://blog.netswitch.jp/

About

Leverage your Ruby/SDL projects with HTML5 technology(WebSocket / Canvas).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages