Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mon ouïe

Pages: [1]
1
General discussions / SVN closed
« on: March 26, 2011, 05:57:18 pm »
Maybe there could be an SFML github account, which would own the SFML repository as well as that of each binding ? This way, the bindings will still keep an "official" status, without being in the SFML repository itself.

2
General / rbSFML
« on: February 26, 2011, 07:42:16 am »
The new instance *is* allocated. What you are doing wrong is overriding new. The default implementation does something like that:
Code: [Select]

class Class
  def new(*args, &block)
    obj = alloc
    obj.send :initialize, *args, &block
    obj
  end
end


alloc is the method tha allocates the object. If you need to wrap a C++ object in the Ruby object, you shouldn't override new, but rather alloc, since new isn't the only method that could create an object.

To override alloc, use rb_define_alloc_func.

3
SFML projects / [Ruby] Ray
« on: February 08, 2011, 10:38:33 pm »
Hi,

Here's a project I've been working on for some time. I wrote the original version using the SDL, but rewrote it with the SFML to get hardware acceleration and some of the features the SFML has.

The rewrite didn't change the whole API though. This means that, unlike rbsfml, binding the methods of the SFML is neither a goal nor a requirement. The SFML is merely a mean to get whatever I want (though I am indeed influenced by the way the SFML works).

As an example, here's one of rbsfml's samples:
Code: [Select]
require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'

app = SFML::RenderWindow.new
app.create( [800, 600], "My Ruby SFML" )
app.framerate = 100
app.position = [300, 300]
input = app.input

shape = SFML::Shape.rectangle( [-10, -10, 20, 20], SFML::Color::White )

image = SFML::Image.new
image.create( 100, 100, [255, 0, 0] )
sprite = SFML::Sprite.new( image, [500, 500] )

text = SFML::Text.new( "This is a test!" )
text.position = [ 20, 20 ]

while app.open?
  while event = app.get_event
    if event.type == SFML::Event::Closed
      app.close
    end
  end
 
  app.clear
  shape.position = [input.mouseX, input.mouseY]
  app.draw shape
  app.draw sprite
  app.draw text
  app.display
end


This is how I'd write it with ray:
Code: [Select]
require 'ray'

Ray.game "My Ruby SFML", :size => [800, 600] do
  register do
    add_hook :quit, method(:exit!)
  end

  scene :test do
    @shape = Ray::Shape.rectangle([-10, -10, 20, 20], Ray::Color.white)

    img = Ray::Image.new(:w => 100, :h => 100).fill(Ray::Color.red).update
    @sprite = sprite(img, :at => [500, 500])

    always do
      @shape.position = [mouse_x, mouse_y]
    end

    @font = Ray::Font.default

    render do |win|
      @shape.draw_on  win
      @sprite.draw_on win

      @font.draw("This is a test!", :on => win, :at => [20, 20], :size => 12)
    end
  end

  push_scene :test
end


It uses a C extensions to bind the SFML's features, but an important part is still written just in Ruby.

As it requires the SFML 2, I wouldn't release it as a gem before the SFML 2's release.

I've written a file introducing to some of Ray's features, available on the github rebo where you can also find, aside from (of course) Ray's code, a few samples: https://github.com/Mon-Ouie/ray/tree/sfml (the master branch is still the version written with the SDL).

4
Window / [SOLVED] Having a Window variable in a class
« on: February 07, 2011, 11:35:10 pm »
Just a thought:
Code: [Select]
class dumbClass {
  sf::Window App:
};


is fine. However,
Code: [Select]
dumbClass obj;
obj.App = sf::Window(...);


Would not be, as sf::Window can't be copied (using sf::Window::Open could then solve the problem).

5
General / rbSFML
« on: February 06, 2011, 08:47:32 am »
Using such splats is invalid in Ruby 1.8.7, hence the syntax errors.
It could easily be rewritten to work :
Code: [Select]
file "#{SODIR}/#{so_file}.so" => objs + [SODIR] do

(The latest version of 1.9.2 is ruby 1.9.2p136)

6
General / Process forking for rbSFML?
« on: February 06, 2011, 08:40:10 am »
Quote
Well since Ruby's native threading isn't perfect.

Notice some Ruby implementations have real threading (JRuby, but no C extensions there ; MacRuby, but it's not portable ; Maybe Rubinius too, I'm unsure about that one)

Code: [Select]
thread.yield # When yielding, the process will look if it got any pending messages.
So, something like fibers on a native process ?

7
SFML wiki / Ruby resource manager!
« on: February 05, 2011, 05:52:34 pm »
Using came-case for anything else than a constant in Ruby is weird. Everyone does_it_like_that. I also don't like seeing parentheses containing nothing as they are unneeded in Ruby. Same for the use of the return, which I only ever use when I want to return before the end of the method.

Code: [Select]
protected
  def initialize( aClass, aLoadMethod )


initialize is private by default, even after a call to the protected method, though there are ways to change it :
Code: [Select]
def initialize; puts "Whateverer !"; end
public :initialize


Also, protected is very rarily useful. private is more often what you want.

Code: [Select]
require './ResourceManager.rb'
(The most conventional way to call that file would be resource_manager.rb, too) Don't require like that. You're relying on the current working directory, where ResourceManager.rb may not exist or be another file. Instead, put the directory containing your files into the load path (e.g. $: << File.dirname(__FILE__)) or use Kernel#require_relative.

I'd also use Hash.new's block form to cache the objects. Here's a simplified example :
Code: [Select]

class Manager
  def initialize
   @resources = Hash.new { |h, (key, filename)| h[key] = load(filename || key.to_s) }
  end

  def [](key, filename = nil)
    @resources[[key, filename]]
  end

  private
  def load(filename)
    # Do something
  end
end

8
General discussions / SFML 2 for OS X comes true!
« on: December 25, 2010, 10:38:28 pm »
I had a similar issue. Files which were supposed to be symlinks had been replaced by normal files containing the path to the actual file. Making the symlinks myself worked until the installation, at which point I... simply removed my symlinks and copied the files :p

Code: [Select]
ld: warning: in /Users/Laptop/Documents/sfml2/extlibs/libs-osx/Frameworks/sndfile.framework/sndfile, file was built for unsupported file format which is not the architecture being linked (x86_64)
That doesn't mean it was only built for x86_64. That means the architecture being linked is x86_64. ;)

Pages: [1]