크리에이티브 커먼즈 라이선스
Creative Commons License
 
module EventDispatcher
	def setup_listeners
		@listeners = {}
		@change = false
	end

	def register_listener(listener, event)
		(@listeners[event] ||= []) << listener
	end

	def remove_listener(listener, event)
		(@listeners[event] ||= []).delete listener
	end

	def remove_listeners(event)
		@listeners[event] = []
	end

	def count_listeners(event)
		(@listeners[event] ||= []).size
	end

	def changed?
		@change
	end

	protected
	def notify(event, arg)
		return if not @change
		if @listeners[event]
			callback = ("update_at_" + event.to_s).to_sym
			@listeners[event].each do |listener|
				if listener.respond_to? callback
					listener.send callback, arg
				elsif listener.respond_to? :update
					listener.update event, arg
				end
			end
		end
		@change = false
		return nil	
	end

	def changed
		@change = true
	end
end	

class TestFactory
	include EventDispatcher
	
	def initialize
		setup_listeners
	end	

	def create_button(color)
		changed
		notify(:new_button, {:color => color})
	end

	def create_label(text)
		changed
		notify(:new_label, {:text => text})
	end
end

class TestWidgetCounter
	def initialize(widget_factory)
		@counts = Hash.new(0)
		widget_factory.register_listener(self, :new_button)
		widget_factory.register_listener(self, :new_label)
	end

	def update(event, arg)
		case event
		when :new_label
			puts "#{arg[:text]} label created."
		end	
	end

	def update_at_new_button(arg)
		color = arg[:color]
		@counts[color] += 1
		puts "#{@counts[color]} #{color} button(s) created."
	end
end



f = TestFactory.new
t = TestWidgetCounter.new(f)

f.create_button("red")
f.create_button("blue")
f.create_button("green")
f.create_label("name")
f.create_button("red")

f.remove_listener(t, :new_label)
f.create_label("cellphone")

f.create_button("blue")


Output:
1
2
3
4
5
6
1 red button(s) created.
1 blue button(s) created.
1 green button(s) created.
name label created.
2 red button(s) created.
2 blue button(s) created.


APE 0.50a 포팅할 때 사용하려고 만들었던 EventDispatcher
저작자 표시 비영리 동일 조건 변경 허락

'객체지향 프로그래밍 > 디자인 페턴' 카테고리의 다른 글

ruby EventDispatcher  (0) 2011/11/06
Thread Pool  (6) 2009/04/10
Object Pool  (11) 2009/03/08
MVC(Model-View-Controller) 디자인 패턴에 대한 좋은 아티클들  (5) 2008/08/08

댓글을 달아 주세요

ape_ruby 0.50a release!!

루비/ape_ruby | 2011/02/12 01:17 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License



readme.txt
ape_ruby 0.50a is ruby port of APE 0.50a. APE(Actionscript Physics Engine) 
is a free AS3 open source 2D physics engine, released under the MIT License. 

ape_ruby supports all features of original Actionsciprt version, and 
slightly modified for support serveral rendering methods. It is released 
under MIT License. 

Because of my lack of English writing skill, there is no documents for 
ape_ruby. But, you can use the documents for original version.

Have a fun.

-- DMW(filepang@lycos.co.kr, http://www.filepang.co.kr) --


license.txt
Copyright (c) 2010, 2011 DMW 

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

download link - source code & windows demo
official homepage

APE google groups

PS.
getting-started-basic-ape-examples and rigid particle will be ported in few days.

저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. PraisedGuy 2011/02/12 01:21  댓글주소  수정/삭제  댓글쓰기

    Aweeeeeeesome ! 

  2. 윤호 2011/03/09 19:03  댓글주소  수정/삭제  댓글쓰기

    루비빠의 귀환이로군...

Ruby + Chipmunk + Gosu

루비 | 2010/09/27 23:08 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
저번 주말부터 그동안 내 시간을 좀먹고 있던 활동 하나를 잠시 끊었다. 그러구나니 시간이 정말 미칠듯이 많이 생겼다능.

원래 잠을 많이 자기도 하지만 남는 시간동안 열심히 잤는데...그래도 시간이 남았다. -_-;;;

그래서 Chipmunk라는 2D물리엔진과 Gosu라는 2D게임 개발 라이브러리를 깔아서 이것저것 예제들을 주워다가 루비를 가지고 돌려봤다. 물론...그냥 돌리기만 하면 재미업으니까 좀 고쳐보구 그러면서 놀았다.

아래 올려놓은게...주말동안 가꾸 놀다가 남은거라능.




돌려보면 알겠지만 루비라서 그런가....좀 많이 느리다능.

저작자 표시 비영리 동일 조건 변경 허락

'루비' 카테고리의 다른 글

Ruby + Chipmunk + Gosu  (2) 2010/09/27
ruby-opengl 0.32g for ruby1.9  (0) 2010/09/18
SWIG Ruby  (0) 2010/03/29
중위표현식을 후위포현식으로 바꾸기  (0) 2009/11/28
Queue  (6) 2009/09/22
tmpdir  (0) 2009/06/20

댓글을 달아 주세요

  1. 양반 2010/09/27 23:48  댓글주소  수정/삭제  댓글쓰기

    끊기지 않고 부드럽게 돌아갔으면 몇배는 더 멋있었을 듯...

    • Favicon of http://wwww.filepang.co.kr BlogIcon DMW 2010/09/28 00:32  댓글주소  수정/삭제

      슈도 플로이드를 대충 흉내배놨는데 루비로 짠거라 어쩔 수 없네염. 렌더링을 ruby-opengl로 하면 좀 빨라지지 않을까 싶어서 해보구 있는데.....그리 빨리질꺼 같지는 않타능

ruby-opengl 0.32g for ruby1.9

루비 | 2010/09/18 23:53 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License

ruby-opengl

ruby-opengl consists of Ruby extension modules that are bindings for the OpenGL, GLU, and GLUT libraries. It is intended to be a replacement for -- and uses the code from -- Yoshi's ruby-opengl.


Ubuntu 10.4(32), ruby 1.9에서 저것의 설치를 시도 했다.

gem으로 ruby-opengl을 설치하면 설치중에 네이티브 익스탠션을 빌드하는 과정에서 에러가 발생한다. 여러가지 방법을 써봐도 안되길레 Yoshi라는 사람이 만들었따는 옛날 버젼을 설치했다능.

링크를 따라가서 가장 최근버젼 0.32g를 받아서 빌드를 하려구 하면 0.32g버젼이 ruby 1.8때 만들어 진거라 빌드가 잘안된다. rbogl-0.32g에 내가 만든 패치를 끼엇고 빌드를 한다.


위에 ruby-opengl 0.60.1 gem을 설치하다 실패한 데이터가 남아 있으면 0.32g를 설치해도 잘 안되니까 gem 디렉토리를 찾아서 다 지워줘야 한다.
저작자 표시 비영리 동일 조건 변경 허락

'루비' 카테고리의 다른 글

Ruby + Chipmunk + Gosu  (2) 2010/09/27
ruby-opengl 0.32g for ruby1.9  (0) 2010/09/18
SWIG Ruby  (0) 2010/03/29
중위표현식을 후위포현식으로 바꾸기  (0) 2009/11/28
Queue  (6) 2009/09/22
tmpdir  (0) 2009/06/20

댓글을 달아 주세요

크리에이티브 커먼즈 라이선스
Creative Commons License

그동안 올렸던 포스트가 제목 때문에 구글 검색이 잘 안되길래...다시 올림. -_-;;

readme.txt
ape_ruby is ruby port of APE. APE(Actionscript Physics Engine) is a free 
AS3 open source 2D physics engine, released under the MIT License. 

ape_ruby supports all features of original Actionsciprt version, and 
slightly modified for support serveral rendering methods. It is released 
under MIT License. 

Because of my lack of English writing skill, there is no documents for 
ape_ruby. But, you can use the documents for original version.

Have a fun.

-- DMW(filepang@lycos.co.kr, http://www.filepang.co.kr) --

Copyright notice
Copyright (c) 2010 DMW 

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

download link


저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

Ubuntu 8.10에 Ruby/SDL 설치하기

리눅스 | 2010/08/21 18:19 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
일단 ruby랑 gem까지 다 설치를 하자. 원래는 그러구나서

sudo gem install rubysdl

명령으로 한방에 설치가 되야 되는데...뭐라고 에러를 막 토해내면서 안된다.
아래처럼 설치하자

sudo apt-get install libruby1.9
sudo apt-get install libsdl-ruby

이러면 된다 -_-;;

원래 ruby/sdl gem이 문제가 좀 많은거 같다. 윈도우에서도 설치가 잘 안된고..암튼 웃기다


고침

gem으로 설치가 왜 안되는지 알았다능. sdl 라이브러리가 설치가 되 있어야 된다능.

sudo apt-get install libsdl1.2-dev libsdl1.2debian

일캐하구

sudo gem install rubysdl

일캐하면 될꺼심. gem으로 깔면 최신버젼이 깔린다능. 위에 써놓은 대로 하면 1.3.1이 깔림.
구식임. 꼬랐다능.

또고침
sudo aptitude install gnome-devel

sudo apt-get install libsdl1.2-dev libsdl1.2debian
sudo apt-get install libsdl-image1.2-dev
sudo apt-get install libsdl-mixer1.2-dev
sudo apt-get install libsdl-ttf2.0-dev
sudo apt-get install libsmpeg-dev

wget http://shinh.skr.jp/sdlkanji/SDL_kanji-0.0.3.tar.gz
    configure
    make
    sudo make install
 
위에 처럼 모든 의존성이 있는 라이브러리를 다 설치하고 gem으로 설치하면 된다. 이게 가장 쉽고 확실한 방법임.
저작자 표시 비영리 동일 조건 변경 허락

'리눅스' 카테고리의 다른 글

Ubuntu 8.10에 Ruby/SDL 설치하기  (4) 2010/08/21
플러그인 만들어보기  (4) 2010/07/24
How to install Boost Library in Ubuntu 9.04  (2) 2009/10/22
The Linux Kernel - 2.0.33  (0) 2009/08/13
내 vimrc  (0) 2009/05/19
ubuntu 설치  (7) 2008/08/17
TAG ruby, SDL, ubuntu

댓글을 달아 주세요

  1. Favicon of http://marocchino.tistory.com BlogIcon progr_ 2009/02/27 01:11  댓글주소  수정/삭제  댓글쓰기

    우왕- sdl이면 저번에 나무그릴떄쓰던 그거죠? 'ㅅ'

  2. Favicon of http://blog.bab2min.pe.kr BlogIcon ∫2tdt=t²+c 2009/02/27 23:49  댓글주소  수정/삭제  댓글쓰기

    루비 실망이쿤효 그럴줄 몰랐는데ㅋㅋㅋ

크리에이티브 커먼즈 라이선스
Creative Commons License
오늘 도 짬내서 코딩을 좀 했다능. 공개해도 될꺼 같아서 일단 올려본다능.


readme.txt
ape_ruby is ruby port of APE. APE(Actionscript Physics Engine) is a free 
AS3 open source 2D physics engine, released under the MIT License. 

ape_ruby supports all features of original Actionsciprt version, and 
slightly modified for support serveral rendering methods. It is released 
under MIT License. 

Because of my lack of English writing skill, there is no documents for 
ape_ruby. But, you can use the documents for original version.

Have a fun.

-- DMW(filepang@lycos.co.kr, http://www.filepang.co.kr) --

Copyright notice
Copyright (c) 2010 DMW 

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

download link

저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. Favicon of http://tcltk.co.kr BlogIcon 2010/07/07 16:08  댓글주소  수정/삭제  댓글쓰기

    우왕~ 굿이라능 >.<
    Tcl 바인딩도 해주세용.

크리에이티브 커먼즈 라이선스
Creative Commons License
간만에 시간내서 버그 좀 잡았다능

오늘 야구장 갔는데 한화가 이겼음 >_<



코드를 좀 더 다듬은 후에 배포하면 될꺼 같은 느낌
저작자 표시 비영리 동일 조건 변경 허락

댓글을 달아 주세요

  1. Favicon of http://lazygyu.tistory.com BlogIcon LazyGyu 2010/05/20 18:54  댓글주소  수정/삭제  댓글쓰기

    바퀴에 점이라도 하나 찍어주세요 ㅠㅠ 회전하는거 보고 싶단 말이에요 ㅠㅠ