ruck-glapp 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/README ADDED
@@ -0,0 +1,3 @@
1
+
2
+ a ruck shreduler for glapp.
3
+ not ready.
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ begin
5
+ require "jeweler"
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruck-glapp"
8
+ gem.email = "tom@alltom.com"
9
+ gem.homepage = "http://github.com/alltom/ruck-glapp"
10
+ gem.authors = ["Tom Lieber"]
11
+ gem.summary = %Q{ruck shreduler based on GLApp (a thin ruby-opengl)}
12
+ gem.description = <<-EOF
13
+ A ruck shreduler which runs in an OpenGL callback, with
14
+ frame, keyboard, and mouse events.
15
+ EOF
16
+ gem.has_rdoc = false
17
+ gem.add_dependency "ruck", ">= 0"
18
+ gem.add_dependency "glapp", ">= 0"
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+
5
+ # for testing inside gem dir
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+
8
+ require "glapp"
9
+ require "ruck"
10
+ require "ruck/glapp"
11
+
12
+ SHREDULER = Ruck::GLApp::GLAppShreduler.new
13
+
14
+ include GLApp::Helpers
15
+ include Ruck::GLApp::ShredLocal
16
+ Ruck::GLApp::RuckSketch.new(ARGV).show 800, 600, "ruck"
@@ -0,0 +1,28 @@
1
+
2
+ clear
3
+
4
+ spork("framerate watcher") do
5
+ start_time = Time.now
6
+ frames = 0
7
+
8
+ loop do
9
+ wait_for_frame
10
+ frames += 1
11
+ if frames % 100 == 0
12
+ puts "#{frames.to_f / (Time.now - start_time)}"
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ loop do
19
+ wait 2
20
+
21
+ glColor 1, 0, 0
22
+ glTranslate(0, 0, -5)
23
+ glutSolidCube(2)
24
+
25
+ wait 0.1
26
+
27
+ clear
28
+ end
@@ -0,0 +1,57 @@
1
+
2
+ require "rubygems"
3
+ require "midiator"
4
+
5
+ $midi = MIDIator::Interface.new
6
+ $midi.use :dls_synth
7
+ $midi.instruct_user!
8
+
9
+ def note_on(note, velocity = 127, channel = 0)
10
+ $midi.driver.note_on(note, channel, velocity)
11
+ end
12
+
13
+ def note_off(note, channel = 0)
14
+ $midi.driver.note_on(note, channel, 0)
15
+ end
16
+
17
+ def star_shifter(key)
18
+ wait 3
19
+ @stars.shift
20
+ note_off(key)
21
+ end
22
+
23
+ spork do
24
+ while ev = wait_for_key_down
25
+ note_on(ev.key)
26
+
27
+ @stars << Star.new
28
+ spork { star_shifter ev.key }
29
+ end
30
+ end
31
+
32
+ spork do
33
+ while ev = wait_for_key_up
34
+ end
35
+ end
36
+
37
+ class Star
38
+ def initialize
39
+ @x = rand * 2 - 1
40
+ @y = rand * 2 - 1
41
+ end
42
+
43
+ def draw
44
+ glPushMatrix
45
+ glTranslate @x, @y, -5
46
+ glutSolidCube(0.1)
47
+ glPopMatrix
48
+ end
49
+ end
50
+
51
+ clear
52
+
53
+ @stars = []
54
+ while wait_for_frame
55
+ clear
56
+ @stars.each { |star| star.draw }
57
+ end
@@ -0,0 +1,13 @@
1
+
2
+ spork do
3
+ loop do
4
+ ev = wait_for_key_down
5
+ puts "you pressed #{ev.key}"
6
+ end
7
+ end
8
+
9
+ on_key_down do |ev|
10
+ puts "you pressed #{ev.key}"
11
+ end
12
+
13
+ clear
@@ -0,0 +1,2 @@
1
+
2
+ require File.join(File.dirname(__FILE__), "glapp", "glapp")
@@ -0,0 +1,145 @@
1
+
2
+ module Ruck
3
+ module GLApp
4
+
5
+ class GLAppShreduler < Shreduler
6
+ def initialize
7
+ @shred_queues = {}
8
+ [:frame,
9
+ :key_down, :key_up,
10
+ :mouse_down, :mouse_up, :mouse_move].each do |q|
11
+ @shred_queues[q] = []
12
+ end
13
+ super
14
+ end
15
+
16
+ def starting
17
+ @start_time = Time.now
18
+ end
19
+
20
+ def actual_now
21
+ Time.now - @start_time
22
+ end
23
+
24
+ def sleep_current_til(queue)
25
+ shred = current_shred
26
+ @shreds.delete(shred)
27
+ @shred_queues[queue] << shred
28
+ shred.yield(0)
29
+
30
+ @ev
31
+ end
32
+
33
+ def raise_event(ev, queue)
34
+ # should use actual_now,
35
+ # but we don't want to put it into the future
36
+ new_now = actual_now
37
+ new_now = [new_now, next_shred.now].min if next_shred
38
+ @now = new_now
39
+
40
+ @ev = ev # returned by sleep_current_til
41
+
42
+ shreds = @shred_queues[queue]
43
+ @shred_queues[queue] = []
44
+
45
+ shreds.each do |shred|
46
+ shred.now = new_now
47
+ @shreds << shred
48
+ invoke_shred shred
49
+ end
50
+ end
51
+
52
+ def catch_up
53
+ while shreds.length > 0 && next_shred.now < actual_now
54
+ run_one
55
+ end
56
+ end
57
+ end
58
+
59
+ # stuff accessible in a shred
60
+ module ShredLocal
61
+ def spork(name = "unnamed", &shred)
62
+ SHREDULER.spork(name, &shred)
63
+ end
64
+
65
+ def wait(seconds)
66
+ SHREDULER.current_shred.yield(seconds)
67
+ end
68
+
69
+ [:frame, :key_down, :key_up, :mouse_down, :mouse_up, :mouse_move].each do |event|
70
+ define_method("wait_for_#{event}") do
71
+ SHREDULER.sleep_current_til(event)
72
+ end
73
+
74
+ define_method("on_#{event}") do |&blk|
75
+ spork do
76
+ loop do
77
+ ev = SHREDULER.sleep_current_til(event)
78
+ blk[ev]
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ class RuckSketch
86
+ include ::GLApp
87
+
88
+ def initialize(filenames)
89
+ @filenames = filenames
90
+ end
91
+
92
+ def setup
93
+ @filenames.each do |filename|
94
+ SHREDULER.spork(filename) do
95
+ require filename
96
+ end
97
+ end
98
+ @events = []
99
+
100
+ SHREDULER.starting
101
+ end
102
+
103
+ def draw
104
+ @events.each do |pair|
105
+ ev, queue = pair
106
+ SHREDULER.raise_event ev, queue
107
+ end
108
+ @events = []
109
+
110
+ SHREDULER.catch_up # execute shreds whose time came while drawing previous frame
111
+
112
+ SHREDULER.raise_event Object.new, :frame
113
+ end
114
+
115
+ def keyboard_down(key, modifiers)
116
+ @events << [Struct.new(:key).new(key), :key_down]
117
+ end
118
+
119
+ def keyboard_up(key, modifiers)
120
+ @events << [Struct.new(:key).new(key), :key_up]
121
+ end
122
+
123
+ def special_keyboard_down(key, modifiers)
124
+ @events << [Struct.new(:key).new(key), :key_down]
125
+ end
126
+
127
+ def special_keyboard_up(key, modifiers)
128
+ @events << [Struct.new(:key).new(key), :key_up]
129
+ end
130
+
131
+ def mouse_click(button, state, x, y)
132
+ if state == 0
133
+ @events << [Struct.new(:button, :x, :y).new(button, x, y), :mouse_down]
134
+ else
135
+ @events << [Struct.new(:button, :x, :y).new(button, x, y), :mouse_up]
136
+ end
137
+ end
138
+
139
+ def mouse_motion(x, y)
140
+ @events << [Struct.new(:x, :y).new(x, y), :mouse_move]
141
+ end
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruck-glapp}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tom Lieber"]
12
+ s.date = %q{2010-07-10}
13
+ s.default_executable = %q{ruck_glapp}
14
+ s.description = %q{ A ruck shreduler which runs in an OpenGL callback, with
15
+ frame, keyboard, and mouse events.
16
+ }
17
+ s.email = %q{tom@alltom.com}
18
+ s.executables = ["ruck_glapp"]
19
+ s.extra_rdoc_files = [
20
+ "README"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "README",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/ruck_glapp",
29
+ "examples/ex01.rb",
30
+ "examples/ex02.rb",
31
+ "examples/ex03.rb",
32
+ "lib/ruck/glapp.rb",
33
+ "lib/ruck/glapp/glapp.rb",
34
+ "ruck-glapp.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/alltom/ruck-glapp}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{ruck shreduler based on GLApp (a thin ruby-opengl)}
41
+ s.test_files = [
42
+ "examples/ex01.rb",
43
+ "examples/ex02.rb",
44
+ "examples/ex03.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<ruck>, [">= 0"])
53
+ s.add_runtime_dependency(%q<glapp>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<ruck>, [">= 0"])
56
+ s.add_dependency(%q<glapp>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<ruck>, [">= 0"])
60
+ s.add_dependency(%q<glapp>, [">= 0"])
61
+ end
62
+ end
63
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruck-glapp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Tom Lieber
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-10 00:00:00 -07:00
18
+ default_executable: ruck_glapp
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ruck
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: glapp
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: " A ruck shreduler which runs in an OpenGL callback, with\n frame, keyboard, and mouse events.\n"
45
+ email: tom@alltom.com
46
+ executables:
47
+ - ruck_glapp
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - README
52
+ files:
53
+ - .document
54
+ - .gitignore
55
+ - README
56
+ - Rakefile
57
+ - VERSION
58
+ - bin/ruck_glapp
59
+ - examples/ex01.rb
60
+ - examples/ex02.rb
61
+ - examples/ex03.rb
62
+ - lib/ruck/glapp.rb
63
+ - lib/ruck/glapp/glapp.rb
64
+ - ruck-glapp.gemspec
65
+ has_rdoc: true
66
+ homepage: http://github.com/alltom/ruck-glapp
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: ruck shreduler based on GLApp (a thin ruby-opengl)
95
+ test_files:
96
+ - examples/ex01.rb
97
+ - examples/ex02.rb
98
+ - examples/ex03.rb