SFML community forums

Bindings - other languages => General => Topic started by: Groogy on November 01, 2010, 11:20:54 pm

Title: rbSFML
Post by: Groogy on November 01, 2010, 11:20:54 pm
Long time since I was at this forum :)

Well I need a project to work on in between my assignments while at my university so I choose this if the previous maintainer don't mind.
Anyway I started today and already got the sfml-system library done. I will try to make the library conform with the conventions of the SFML library as much as possible but I will also let the library conform to the Ruby conventions. I can't estimate any time as of when this will be completed but I can estimate that I'll work around 1-2 hours each day with this between my assignments.

The task list for rbSFML can be found here: http://taks.groogy.se

Any updates to the library will be edited into this post.

Example code:
Code: [Select]

require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'
require 'sfml/audio'

app = SFML::Window.new [800, 600], "My Ruby SFML"

# Load a sprite to display
image = SFML::Image.new
image.load_from_file  "cute_image.jpg"
sprite  = SFML::Sprite.new image
 
# Create a graphical string to display
arial = SFML::Font.new
arial.load_from_file "arial.ttf"
text = SFML::String.new "Hello SFML", arial, 50
 
# Load a music to play
music = SFML::Music.open_from_file "nice_music.ogg"
# Play the music
music.play
 
# Start the game loop
while app.open?
  # Process events
  while event = app.get_event
    # Close window : exit
    if event.type == SFML::Event::Closed
      app.close
    end
  end
 
  # Clear screen
  app.clear
 
  # Draw the sprite
  app.draw sprite
 
  # Draw the string
  app.draw text
 
  # Update the window
  app.display
end


These classes has been excluded from the library:
Code: [Select]

Thread
Lock
Mutex
Randomizer
Sleep
Unicode
RenderTarget ( Not the same as SFML::RenderTarget )

Why these has been excluded is because the core of Ruby already does these for us. But I also want to go into more detail on Thread, Lock and Mutex. It's true that Ruby does provide this functionality for us but it's still incomplete. The threading in ruby works natively but ruby got a global lock which will always only let one thread run at the same time. So this also made my choice, since if we allow SFML threading it might mess up the internal workings of Ruby. So my choice is to wait with implementing this and let Ruby's threading "mature".
Title: rbSFML
Post by: Laurent on November 01, 2010, 11:45:28 pm
Wow, this is truly amazing :)

Quote
if the previous maintainer don't mind

I think we can safely assume that the last maintainer has left a long time ago. Anyway, you can send him an e-mail if you want (sean.p.oneil@gmail.com).

Quote
Anyway I started today and already got the sfml-system library done

Are you working on SFML 2 or SFML 1.6? You should start with SFML 2, working on SFML 1.6 would be a waste of time.

Quote
I will try to make the library conform with the conventions of the SFML library as much as possible but I will also let the library conform to the Ruby conventions

That sounds good. Ruby conventions should have the priority, don't hesitate to transform things if you can make them look more natural.

Thank you very much for your work :)

And if you need a write access to the SVN, let me know.
Title: rbSFML
Post by: Groogy on November 02, 2010, 09:05:24 am
I'm working on SFML 1.6 but thanks for letting me know. I'll switch over to 2.0 if you feel that's better. And making the library both support the convention of SFML(which I feel looks better) and Ruby is easy since Ruby supports something called Aliasing which makes one method/function have several names.


Quote
And if you need a write access to the SVN, let me know.

That would be perfect. We use SVN on my university for the game projects. Send me a mail/message with the specifics and any other information you need me to know.
Title: rbSFML
Post by: Laurent on November 02, 2010, 09:45:15 am
Quote
And making the library both support the convention of SFML(which I feel looks better) and Ruby is easy since Ruby supports something called Aliasing which makes one method/function have several names.

Is it really a good thing? Is this kind of technique widely used in Ruby?

Quote
That would be perfect. We use SVN on my university for the game projects. Send me a mail/message with the specifics and any other information you need me to know.

You must have an account on sourceforge.net, and send me your login by e-mail.
Title: rbSFML
Post by: Groogy on November 02, 2010, 10:14:45 am
Code: [Select]
Is it really a good thing? Is this kind of technique widely used in Ruby?

It's widely used in the standard library for like arrays so you can both call on "size" and "length" on them but it still calls the same method.

Sent you a mail with my login :)
Just gonna compile together my SFML 2 snapshot now.
Title: rbSFML
Post by: Groogy on November 10, 2010, 11:20:28 am
The development is a bit halted at the moment as we're reaching the deadline for our game project at the university. And my group are putting down finishing touches on the story of the game and bug fixes. So I got a lot to do until Friday.

Anyway I hope having the Window module finished by Monday and will begin with Graphics when I get time again. When the Window module is done you are free to test it and play around with it. Though you'll only be able to do graphics trough OpenGL at that point.

I'll still need to figure out how I'll make the inheritance hierarchy work when it comes to the Graphics module which includes multiple inheritance which I'll have to solve for Ruby somehow.

[SOLVED] I won't do it at all :D
Title: rbSFML
Post by: Groogy on November 16, 2010, 05:43:53 pm
I hope it's okay Laurent that I write updates here? Not cause I think many is interested yet but it's a good reminder for me what I've done so far.

Anyway, sfml-system and sfml-window is complete and rdoc documentation has been generated for them and is located in their folders on the SVN servers. They are finished enough to be used now I believe. I have a window-demo.rb file under testing/ which tests them and so far it has worked. What I have not tested is to actually render something directly trough OpenGL but it should work, I don't see any reasons why it wouldn't.

Anyway if you only want to use SFML to open a OpenGL context then the library is pretty much done for you :)
Title: rbSFML
Post by: Laurent on November 16, 2010, 06:41:50 pm
Quote
I hope it's okay Laurent that I write updates here?

Of course it is ok :)

Quote
rdoc documentation has been generated for them and is located in their folders on the SVN servers

You should never add generated stuff to the repository. It doesn't have to be there, since it's generated from files already versioned. It wastes space and makes commits/updates bigger than they should.
The same applies if you have some compiled rbSFML libraries, never add them.
Title: rbSFML
Post by: Groogy on November 16, 2010, 07:33:26 pm
Quote from: "Laurent"

You should never add generated stuff to the repository. It doesn't have to be there, since it's generated from files already versioned. It wastes space and makes commits/updates bigger than they should.
The same applies if you have some compiled rbSFML libraries, never add them.


Aight will be removed. I just looked at the snapshot which has a doc folder so I just guessed you had it there too ^^

Though I'll in any case have to find a place to put it, I got my own web server I can place it if you don't want it on your. Rdoc documentation is like doxygen but for Ruby, it generates a web-page for you more or less.
Title: rbSFML
Post by: Laurent on November 16, 2010, 09:54:09 pm
Quote
I just looked at the snapshot which has a doc folder so I just guessed you had it there too ^^

Nop, it just contains the files needed to build the doc ;)

Quote
Though I'll in any case have to find a place to put it, I got my own web server I can place it if you don't want it on your. Rdoc documentation is like doxygen but for Ruby, it generates a web-page for you more or less.

Usually, the doc for bindings is put into releases archives but not online. Hmm and the SFML website is not ready for this; maybe we can talk about it again after I rewrite the website (before SFML 2 is released).
Title: rbSFML
Post by: Groogy on November 16, 2010, 10:33:30 pm
Quote from: "Laurent"
Usually, the doc for bindings is put into releases archives but not online.

Like I said, I can put it on my web-server and just link to it from the forum, though might be annoying for users.

Quote from: "Laurent"
Hmm and the SFML website is not ready for this; maybe we can talk about it again after I rewrite the website (before SFML 2 is released).

Sure :D I'm just a bit eager to get people to use this. I love SFML and I love Ruby. And hope people will appreciate this combination as much as I do.
Title: rbSFML
Post by: Groogy on November 19, 2010, 03:35:06 pm
Almost finished the Drawable mixin-module today. I said I wouldn't make it but it will make it easier for me to do a correct inheritance hierarchy when it comes to Sprite, Shape and so on. Plus it wasn't hard to implement, most functions were exactly the same so it was just a lot of copy-pasting.

The only thing not implemented yet is the Render function. Also there is a problem when it comes to actually using it for your own classes which might be dangerous.

The module will hijack your class new method in order to allocate a instance of sf::Drawable and then link the ruby object and Drawable object together. If you would under any circumstances write your own new method then the needed sf::Drawable object won't be allocated unless you call the function specifically your self(Doesn't know if that will work either). If you need to do something like that then I recommend that you instead write a wrapper class around the Drawable class where the wrapper class has the custom made new method.

Anyway the class should take your inheritance into consideration by calling super in it's initialization method. But if you write your own initialization method then you'll have to remember to call super yourself in order to set default values. But if you don't need to set any default values then you don't have to of course, the object is already initiated trough the new method.
Title: rbSFML
Post by: Groogy on November 20, 2010, 09:44:11 pm
Currently working on RenderTarget. This will be a tricky one. This is mainly for the sf::Drawable::Render function's first argument. So the classes SFML::RenderWindow and SFML::RenderImage won't be inheriting from the class but SFML::RenderTarget will act as a temporary wrapper around the C++ instance so that the user can access the rendering functions. Also coincidental this will force the user to have the same functionality as in C++ when they are making their custom Drawable class.

Anyway otherwise just look at the SFML::RenderTarget class as an internal class and have "Look but don't touch" in your mind while using it.
Title: rbSFML
Post by: Groogy on November 22, 2010, 11:46:39 pm
FINALLY! Finished the RenderWindow though I got some weird bug with it which I'll have to look into deeper. RenderWindow inherits from Window of course so it already got the RenderWindow#display function defined for it. But when I tried to override that method ruby crashed at exit whining about that the stack wasn't consistent any more. I don't understand, the sf::RenderWindow::Display function is inherited from sf::Window, could it be something there being the problem?

Also another problem I ran into was that I couldn't just simply have a generic function with a sf::RenderTarget pointer to either a window or render image but I had to have 2 separate functions for each separate type. Well the problem originated in that the sf::RenderTarget::Draw function wasn't virtual which I thought.

Everything works now and you can draw shapes onto a RenderWindow or RenderImage which is pretty cool. Though I'll commit all the new changes tomorrow at the university. I'd like to do some more tests before actually committing the new code.

*EDIT*
This is really bugging me so I can't go to sleep. How come then that this works:
Code: [Select]

void MyDrawable::Render( sf::RenderTarget& aTarget, sf::Renderer& aRenderer ) const
{
        aTarget.Draw( /* Something */ );
}


And this don't?
Code: [Select]

static VALUE RenderTarget_Draw( int argc, VALUE *args, VALUE self )
{
sf::RenderTarget *object = NULL;
Data_Get_Struct( self, sf::RenderTarget, object );
switch( argc )
{
case 2:
{
VALIDATE_CLASS( args[0], globalDrawableModule, "object" );
VALIDATE_CLASS( args[1], globalShaderClass, "shader" );
sf::Drawable *drawable = NULL;
Data_Get_Struct( args[0], sf::Drawable, drawable );
sf::Shader *shader = NULL;
Data_Get_Struct( args[1], sf::Shader, shader );
object->Draw( *drawable, *shader );
break;
}
case 1:
{
VALIDATE_CLASS( args[0], globalDrawableModule, "object" );
sf::Drawable *drawable = NULL;
Data_Get_Struct( args[0], sf::Drawable, drawable );
object->Draw( *drawable );
break;
}
default:
rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc );
}
return Qnil;
}


It crashes when calling the sf::RenderTarget::Draw function, this really bothers me. How come it doesn't work here? What's the main difference that I do? Just ignore all the Ruby specific code. I've checked, the returned objects are correct, I get a sf::RenderTarget in the object pointer and a sf::Drawable in the drawable pointer. If I just change the type of object into sf::RenderWindow then it works without a problem.

*ANOTHER EDIT*
Aaah wait! I get it now I think! The Draw function used to be virtual but isn't any more and SFML2 isn't finished yet so this is still in progress. Aaah no sweat then. I thought I did something wrong... The horrible thought! Well it is working, not elegant but works currently so I can wait until SFML2 is actually finished and then remove the type specific functions or however it turns out.
Title: rbSFML
Post by: Laurent on November 23, 2010, 08:09:33 am
Quote
Aaah wait! I get it now I think! The Draw function used to be virtual but isn't any more and SFML2 isn't finished yet so this is still in progress.

Draw never was virtual. SFML 2 is not finished but it works 100%, there's nothing "half-done".
Title: rbSFML
Post by: Groogy on November 23, 2010, 08:46:30 am
But how come then that the:
Code: [Select]
sf::RenderTarget &target = /* Somewhere */
target.Draw( aDrawable );

works but not this:
Code: [Select]
sf::RenderTarget *target = /* Somewhere */
target->Draw( aDrawable );


If I remember correctly, the error is a Segmentation fault, I'll make a check as soon as I boot up my dev-environment here at school. And like I said, I've checked, the correct objects are there and they are initiated and everything is perfect. Also just changing the type of the pointer fixes my problem.

**EDIT**
The error is a Segmentation Fault and the C level backtrace tells me that it crashes in sf::RenderTarget::Draw( Drawable ) when it happens.
Title: rbSFML
Post by: Groogy on November 24, 2010, 07:03:54 am
Aight now the Graphics module is completed and everything seems to be working. Though I suspect a possible bug in when you create your custom drawable class. But I'll look deeper into that later today.

Anyway your free to start playing around with the graphics library now too.
After this I'm going to jump into the Audio module. Also I'm wondering about if I should do the network module since Ruby got a very large network library by itself. Though I don't know if it's easier to use or even better than the SFML network module. So I'll probably make it just to be sure.

The largest difference between SFML network and Ruby network would be Distributed Ruby I think. This let's you share one common object between two clients or client and server, don't remember which it was. Anyway this is a really sweet feature and I might try to add it into the SFML library too so you can have one common interface.
Title: rbSFML
Post by: Laurent on November 24, 2010, 08:25:16 am
Usually, sfml-system and sfml-network are ignored in bindings, since the target languages have a decent (and better) standard library. I don't think you should bind sfml-network if Ruby has the features you describe.
Title: rbSFML
Post by: Groogy on November 25, 2010, 08:36:26 pm
Well since Ruby standard library offer better network capabilities means that the new rbSFML is now up-to date with SFML2!

As soon as SFML2 is officially released I'll release rbSFML officially as an extension gem and also publish it at sites like Rubyforge. I think it is that site that makes the gem available directly trough rubygem.

So all ruby crazy people like me start using rbSFML now! :D
Title: rbSFML
Post by: Laurent on November 25, 2010, 08:40:08 pm
By the way, I added a news about rbSFML on the website home page ;)
Title: rbSFML
Post by: Groogy on November 25, 2010, 08:49:29 pm
Quote from: "Laurent"
By the way, I added a news about rbSFML on the website home page ;)


That's just awesome :D
I'm already spending my bragging rights ^^
Title: rbSFML
Post by: Groogy on November 25, 2010, 08:56:14 pm
Also I know of a first bug(or at least I think it will crash the app) which is defining a custom Drawable. Defining it works fine but as soon as you try to tell the SFML::RenderTarget to draw anything in the render method it should crash with ruby telling you about a segmentation fault. I haven't confirmed it yet but logically it should crash.

A fix for this would be using RTTI with dynamic_cast to cast the RenderTarget into it's proper type before trying to draw any drawable. This will only be used in the SFML::RenderTarget#draw method and not the SFML::RenderImage#draw and SFML::RenderWindow#draw method. So more or less, when we are not sure of what type the render target actually is. I hope that the dynamic_cast won't take up TOO much performance. Taking performance on every draw call is very bad.

The history for this bug is the previous problem in this post: http://sfml-dev.org/forum/viewtopic.php?p=23512#23512
Title: rbSFML release suggestion
Post by: mistergibson on November 26, 2010, 12:39:06 am
When you release rbSFML, I would suggest you post it as a gem at:

http://rubygems.org/

That will put you instantly into a very easy deploy position as pretty much everyone uses it.

Also: do you have an Ubuntu PPA presence for SFML 2.0 - I found one carrying 1.5, but not 2.0.

I see you are building rbSFML for SFML 2.0, but will it also work (call compatible) with SFML 1.5 ?

Just curious.
Title: Re: rbSFML release suggestion
Post by: Groogy on November 26, 2010, 01:05:41 am
Quote from: "mistergibson"
When you release rbSFML, I would suggest you post it as a gem at:

http://rubygems.org/

That will put you instantly into a very easy deploy position as pretty much everyone uses it.

Thx! Had no idea where the gems repo actually were placed, I guessed on Rubyforge.

Quote from: "mistergibson"

I see you are building rbSFML for SFML 2.0, but will it also work (call compatible) with SFML 1.5 ?

Just curious.


No, I was supposed to originally make rbSFML for SFML 1.6 actually but Laurent told me that it wouldn't be worth it. SFML 2.0 is more or less done soon with a better, faster and easier interface than the 1.X branch.

So I advice you to step over to SFML2 if not already now. Documentation is up for SFML2 and if you need you can generate rdoc documentation from rbSFML. Also you won't find any broken features in SFML2. If something crashes or is broken then I'm 99% certain that it's me that has done something wrong and 0.5% that it is Laurent and 0.5% that it's somewhere else.

And as a side note, I've committed a fix for the "unkown type" RenderTarget problem. If there even was a bug there before that I suspected then it's fixed now.
Title: rbSFML
Post by: Groogy on November 28, 2010, 02:08:29 am
Got an annoying bug that doesn't always show up. I don't know what replicates it but seems like I have done something special to screw it up in my own ruby source code. While doing basic tests everything works but directly in my source it appears.

The problem is somehow that calling SFML::Text#getRect touches something it shouldn't and that messes the font resource up or something. Because when I try to draw the text later, it displays some garbage data or something. How this happens I don't know since it has only happened once for me. Tried staring at my code but doesn't help. I reckon it's something with the ruby garbage collector. Though I'm using the default arial sfml font which I've specified is not allowed to be garbage collected.
Title: rbSFML
Post by: TricksterGuy on November 28, 2010, 03:53:06 am
Nice job on this :D.

I was working on ruby bindings of my own (some two years ago I believe there is a topic in this forum with it), but I stopped since SFML 2 was in development and I didn't want to waste time doing 1.5 if 2.0 had many API changes. I was going to work on it again when Laurent officially released SFML 2.0, but I see that you will beat me to it.

(not to hijack or anything, but there were a number of things holding me back from continuing i.e. I didn't have a linux box to test anything at the time nor did my laptop have an advanced enough video card)

If you need any help on anything or need a second developer I can provide assistance. (And there were also people sending me private messages also I can send those people your way as well)
Title: rbSFML
Post by: Groogy on November 28, 2010, 10:52:23 am
Sure why not. It would be nice if you could use and try it out. Currently I think most of my problems are coming from my drivers on my home computer. Because everything works when I am at the university at my workstation but when I come home everything start's to crash on me and I get very weird undefined behavior. Also one of the call-stacks ended in my driver shared library so that's a pretty good lead :P

But it would be nice if someone else than me would have a look at the code to see if there's something I've done wrong. The undefined behavior could be because of something I've done.
Title: rbSFML
Post by: Groogy on November 28, 2010, 06:50:38 pm
About those last bugs. I have confirmed it was my stupid graphics drivers. I've tested on some other machines the exact same code and it works without any thing weird happening. How a bad graphic driver can make ruby stop working is still a mystery to me. But at least now I know not to work when I'm at home.
Title: rbSFML
Post by: TricksterGuy on November 29, 2010, 09:25:37 am
Ok so I got a fresh copy of sfml2 from svn.

audio and system compile fine

however window and graphics do not.

for window
Quote
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-window$ ruby extconf.rb
checking for main() in -lsfml-window... no
checking for main.hpp in ../sfml-system/system... yes
creating Makefile
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-window$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/i686-linux -I. -I../sfml-system/system -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c window/Window.cpp
window/Window.cpp: In function ‘VALUE Window_SetTitle(VALUE, VALUE)’:
window/Window.cpp:482: error: ‘class sf::Window’ has no member named ‘SetTitle’
make: *** [Window.o] Error 1


for graphics
Quote

brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$ ruby extconf.rb
checking for main() in -lsfml-graphics... no
checking for main.hpp in ../sfml-system/system... yes
creating Makefile
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/i686-linux -I. -I../sfml-system/system -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c graphics/Shape.cpp
g++ -I. -I. -I/usr/lib/ruby/1.8/i686-linux -I. -I../sfml-system/system -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c graphics/View.cpp
graphics/View.cpp: In function ‘VALUE View_Initialize(int, VALUE*, VALUE)’:
graphics/View.cpp:74: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:75: error: ‘class sf::FloatRect’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_GetViewport(VALUE)’:
graphics/View.cpp:139: error: ‘const class sf::Rect<float>’ has no member named ‘Width’
graphics/View.cpp:139: error: ‘const class sf::Rect<float>’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_Reset(VALUE, VALUE)’:
graphics/View.cpp:191: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:192: error: ‘class sf::FloatRect’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_SetViewport(VALUE, VALUE)’:
graphics/View.cpp:311: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:312: error: ‘class sf::FloatRect’ has no member named ‘Height’
make: *** [View.o] Error 1
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$ clear

brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$ ruby extconf.rb
checking for main() in -lsfml-graphics... no
checking for main.hpp in ../sfml-system/system... yes
creating Makefile
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/i686-linux -I. -I../sfml-system/system -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC    -c graphics/View.cpp
graphics/View.cpp: In function ‘VALUE View_Initialize(int, VALUE*, VALUE)’:
graphics/View.cpp:74: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:75: error: ‘class sf::FloatRect’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_GetViewport(VALUE)’:
graphics/View.cpp:139: error: ‘const class sf::Rect<float>’ has no member named ‘Width’
graphics/View.cpp:139: error: ‘const class sf::Rect<float>’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_Reset(VALUE, VALUE)’:
graphics/View.cpp:191: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:192: error: ‘class sf::FloatRect’ has no member named ‘Height’
graphics/View.cpp: In function ‘VALUE View_SetViewport(VALUE, VALUE)’:
graphics/View.cpp:311: error: ‘class sf::FloatRect’ has no member named ‘Width’
graphics/View.cpp:312: error: ‘class sf::FloatRect’ has no member named ‘Height’
make: *** [View.o] Error 1
brandon@ubuntu:~/Documents/src/sfml/bindings/ruby/sfml-graphics$


Could have something to do with the extconf output !!!


I am testing on the latest ubuntu (obviously) and ruby 1.8.7 from the repository.


Also I don't like how I have to go to four directories and type the same thing four times.  A simple command that does all of that for you would be optimal.

When I was working on my own bindings created a Rakefile that handled all of the building / documentation / installing / clean up tasks. And I can adapt it for your code, however I don't know how everyone feels about rake though.

I'm too lazy to try and fix these errors right now (and its my bedtime and I have a class in < 5 hours).
Title: rbSFML
Post by: Laurent on November 29, 2010, 09:32:10 am
It seems like you're using SFML 1 headers (SetTitle, Width, Height are all new to SFML 2).
Title: rbSFML
Post by: TricksterGuy on November 29, 2010, 09:35:32 am
That could be it! I'll have a look at where make is looking for header files and/or my system.

Thanks!
Title: rbSFML
Post by: Groogy on November 29, 2010, 09:55:02 am
If you look at the output of extconf.rb then you see that it didn't find sfml-graphics.so or sfml-window.so

Also I've used Ruby1.9.2 when working with this code, I have no idea if it will work for anything older.

And sure, I wouldn't mind a rake file that does it for you. I'm also thinking of adding a sfml-all package that requires all SFML packages for you.
Title: rbSFML
Post by: Groogy on November 29, 2010, 02:48:21 pm
Apparently there are several parts in sf::RenderWindow and sf:RenderImage that needs a specialized function for their functions inherited from sf::RenderTarget. IF you don't get the behaviour you expect from them then please tell me and I'll add that function.

Trickster, do you have SVN access? Just wondering, if you find one of them you can add it yourself.
Title: rbSFML
Post by: TricksterGuy on November 30, 2010, 03:39:06 am
Quote from: "Groogy"
Apparently there are several parts in sf::RenderWindow and sf:RenderImage that needs a specialized function for their functions inherited from sf::RenderTarget. IF you don't get the behaviour you expect from them then please tell me and I'll add that function.

Trickster, do you have SVN access? Just wondering, if you find one of them you can add it yourself.


So I have tested it with one of the samples from my old bindings (there were very few changes I had to make which makes me happy)

The actual code I have to give credit to the people who created Allegro.
(please excuse any weirdness with this code)
What this should do is produce a flame effect on the screen although its kinda slow.
Code: [Select]

require 'sfml/system'

require 'sfml/window'

require 'sfml/graphics'

include SFML



HOTSPOTS = 10

WIDTH = 128

HEIGHT = 64



class Game

def initialize

@screen = RenderWindow.new

@screen.create([WIDTH, HEIGHT], "Flame")

#screen .width and .height return 0
 or some weird value.
@buffer = Image.new

@buffer.create(WIDTH, HEIGHT)

@sprite = Sprite.new

@sprite.image = @buffer

init_palette

end



def run

@temp = Array.new(WIDTH, 0)

@hotspot = Array.new(HOTSPOTS) {rand(WIDTH)}

loop {break if update == false}

quit

end



def update

return false if @screen.input.key_down?(Key::Escape)

draw_fire

update_fire

@screen.draw(@sprite)

@screen.display

end



def quit

end



def init_palette

@palette = Array.new(256)

@palette.fill(0, 64) {|c| Color.new(c * 4, 0, 0)}

@palette.fill(64, 64) {|c| Color.new(255, c * 4, 0)}

@palette.fill(128, 64) {|c| Color.new(255, 255, c * 4)}

@palette.fill(Color.new(255, 255, 255), 192, 255)

end



def draw_fire

@temp.fill(0)

0.upto(HOTSPOTS-1) do |c|

(@hotspot[c]-20).upto(@hotspot[c]+20) do |x|

if x >= 0 and x < @buffer.width

@temp[x] = [@temp[x] + 20 - (@hotspot[c] - x).abs, 192].min

end

end

@hotspot[c] = (@hotspot[c] + rand(8) - 3) % @buffer.width

end

@temp.each_index do |i|

#p "#{i}, #{@screen.height - 1}, #{@palette[@temp[i]]}"

@buffer.setPixel(i, @screen.height - 1, @palette[@temp[i]])

end

end



def update_fire

0.upto(@buffer.height-2) do |y|

0.upto(@buffer.width-1) do |x|

c = @palette.index(@buffer[x, y + 1])

c -= 1 if c > 0

@buffer[x, y] = @palette[c]

end

end

end

end



Game.new.run



RenderWindow#width and RenderWindow#height do not work as expected.

and I do not have access to fix this myself and commit the changes (I can checkout though if thats what you mean)
Title: rbSFML
Post by: Groogy on November 30, 2010, 06:25:12 am
Nah I was wondering if you had access to commit those changes
Anyway I'll add the getWidth and getHeight specialization.

And you said the code ran kind of slow? Your still using Ruby 1.8.x? If you change to 1.9.x does it still run slow? And if it do can you benchmark to where the performance is down? I might be able to improve it.

Also I recommend that you use for in instead of the Integer#upto method. Just write intead:
Code: [Select]
for index startIndex..endIndex
  # Code
end


It encapsulates the block you pass on and it's easier to read ^^
Title: rbSFML
Post by: TricksterGuy on November 30, 2010, 07:36:21 am
oh, its a kinda slow way to do the effect last time I ran it. (ignore me :P)

However, I can't get the window to display on my computer. You other samples work fine. (it does create a window but it is minimized and when I click on it nothing comes up)

May be an error on my part!
Title: rbSFML
Post by: Laurent on November 30, 2010, 08:00:18 am
Quote
RenderWindow#width and RenderWindow#height do not work as expected.

By the way, if you have any problem with RenderTargets, make sure that you properly deal with the multiple inheritance which is involved (ie. no direct/ugly cast RenderTarget <--> RenderWindow, since RenderTarget is not the first base of RenderWindow). Just a thought, maybe not related at all to your problems :D

Quote
And you said the code ran kind of slow? Your still using Ruby 1.8.x? If you change to 1.9.x does it still run slow? And if it do can you benchmark to where the performance is down? I might be able to improve it.

You shouldn't worry about that, the algorithm and functions used is what makes the application slow. It would be equally slow in C++.
Title: rbSFML
Post by: Groogy on November 30, 2010, 09:07:33 am
Quote from: "TricksterGuy"

However, I can't get the window to display on my computer. You other samples work fine. (it does create a window but it is minimized and when I click on it nothing comes up)

May be an error on my part!


That's probably because of the OS I think. SFML doesn't have any thing that let's you minimize the window last I checked.

Quote from: "Laurent"
By the way, if you have any problem with RenderTargets, make sure that you properly deal with the multiple inheritance which is involved (ie. no direct/ugly cast RenderTarget <--> RenderWindow, since RenderTarget is not the first base of RenderWindow). Just a thought, maybe not related at all to your problems


I would but the Ruby API is written in C with no considerations to C++ so it internally uses ugly c-casts everywhere. And when I tell RenderWindow to include the the RenderTarget module it does a simple dump of all the RenderTarget methods onto the RenderWindow class. It's either that or make every method for hand for 3 classes (RenderWindow, RenderImage and RenderModule::Instance which is used internally with custom Drawables). Doing it this way actually takes of some work for me. I now just need to copy-paste the RenderTarget binding to the 3 classes when it occurs that it doesn't work normally and change the types there.
Title: rbSFML
Post by: TricksterGuy on December 01, 2010, 08:41:06 am
Ok so I have updated that test code

http://pastebin.com/1M2gNbYd

Now when I run this after I close the window I get the message
DRM_IOCTL_GEM_CLOSE 6 failed (region): Bad file descriptor
I have tracked this to the line where I create the image passing in a width and height.
I also tested your other demos and I get two of those messages when I close the program. (Various lines cause this one)

And upon search of this weird message (on google) I was linked to a post on this forum by you haha.


Also why is it a two step process to create an Image of a certain color why not overload the constructor to do this?

I'll be playing around with this a little bit more before diving in.
Title: rbSFML
Post by: Groogy on December 01, 2010, 09:10:20 am
Well I have no idea what to do. From what I could find on google is that it's Compiz. I don't get the message on my workstation. I get the message on my laptop where I do have compiz. Though I uninstalled compiz completely and I still have that message. But I noticed that my driver is really faulty. I get very very weird behavior on my home laptop. Though that particular Intel graphic chip is known to have crappy OpenGL implementation.

Can you try out making a C++ SFML application on the same computer and see if you still get the message? If you do then I'll have to look over the code.
Title: rbSFML
Post by: Groogy on December 01, 2010, 10:00:59 am
I think I already know the answer but just curious Laurent, You don't do this call manually?
Code: [Select]
ret = ioctl (fd, DRM_IOCTL_GEM_CLOSE, &close);
From this page: http://lwn.net/Articles/283798/
Title: rbSFML
Post by: Laurent on December 01, 2010, 11:33:52 am
What's that???
(sorry I'm at work, I don't have time to read this huge article :D)
Title: rbSFML
Post by: Groogy on December 01, 2010, 12:37:53 pm
From what I understand, that's where it fails, when we try to close the file descriptor to a resource it apparently fails. Something like that I guess.

Anyway since you don't know what it is I guess it's Xlib that uses it and fails somehow for you.

*EDIT*
I tried myself with creating a SFML2 app on my home computer and I get that message there too. So now at least I know it is not the ruby bindings that is messing things up :)

Probably are something wrong with xlib on my computer at home and apparently Tricksters computer. Would be nice to know if this happens on other people with Linux or is it specific to us? If it is, what is the common between me and Trickster? If it is not and many linux users get the same message then it might just be that you've missed something with Xlib Laurent. This GEM thing seems to something Intel is developing to manage memory on chipsets. So I guess Trickster is also sitting on a laptop?
Title: rbSFML
Post by: TricksterGuy on December 03, 2010, 07:39:20 am
And you'd be right!

I am almost done with the Rakefile I am putting some finishing touches on it.

All you have to do is type rake and it will build the four .so files.
Then you can type sudo rake install to install the binaries.

There is also a documentation and a gem building task.
(rake rdoc and rake gem)
Title: rbSFML
Post by: Groogy on December 03, 2010, 10:19:16 am
Quote from: "TricksterGuy"
I am almost done with the Rakefile I am putting some finishing touches on it.

All you have to do is type rake and it will build the four .so files.
Then you can type sudo rake install to install the binaries.

There is also a documentation and a gem building task.
(rake rdoc and rake gem)


Nice! :D
I don't know how Laurent feels about it but I wouldn't mind if you had SVN access so you could commit it yourself. But if he don't want too many people to have access then I can commit it for you.

Also I'll make the "sfml/all" option today so you don't need to require each one of the libraries if you want to use them all.
Title: rbSFML
Post by: Laurent on December 03, 2010, 10:34:43 am
Quote
I don't know how Laurent feels about it but I wouldn't mind if you had SVN access so you could commit it yourself. But if he don't want too many people to have access then I can commit it for you.

I give write access to the SVN to developers who want to maintain a binding in the long term.

So it's up to TricksterGuy to decide:
- if he wants to collaborate in the long term to rbSFML I'll give him SVN access
- if he only wants to submit a few patches then it's better if you review and push them to the repository yourself
Title: rbSFML
Post by: Groogy on December 03, 2010, 11:04:00 am
Quote from: "Laurent"
Quote
I don't know how Laurent feels about it but I wouldn't mind if you had SVN access so you could commit it yourself. But if he don't want too many people to have access then I can commit it for you.

I give write access to the SVN to developers who want to maintain a binding in the long term.

So it's up to TricksterGuy to decide:
- if he wants to collaborate in the long term to rbSFML I'll give him SVN access
- if he only wants to submit a few patches then it's better if you review and push them to the repository yourself


Aight, well there's a lot left to do which Trickster could help out with if he's up for it. I could create a "ToDo" for rbSFML like you have Laurent to keep track of what needs to be done. There's a lot left to do actually.

I know some "upgrades" we can do to make it more suited for ruby. For instance add a SFML::Input#mouse_position which should return a vector based on the mouse position. Also it would be nice if it was possible to connect vectors so it would be possible to write:
Code: [Select]
sprite = # From somewhere
sprite.position.x = 25 # This would somehow give the sprite position 25


Currently it works like SFML and returns a copy (Well sfml returns a constant reference but you should work with it like a copy). Possible way of doing this would be to create a private "on_change" method to the vector which will look something like this:
Code: [Select]
def on_change  # This is in ruby code but will be implemented in C instead.
  unless @__owner_ref.nil?
    @__owner_ref.send( @__owner_set_method, self )
  end
end


This should get the desired effect and we only need to call it inside SFML::Vector2#x= and SFML::Vector2#y=. Will probably have to add it to SFML::Rect, SFML::Color and to any other class where this would be logically. Also have to add the actual instance variables on every place where we return a copy where we want to be able to change the actual value on the "owner" object. The solution is simple but it's a lot of work. :)
Title: rbSFML
Post by: Groogy on December 03, 2010, 02:52:09 pm
Added the SFML::NonCopyable module now. If you mixin this module to your class then it will act as the normal sf::NonCopyable class and override so you can't copy any instances from the class including the module.

I will make every class that is NonCopyable in the C++ library non copyable in rbSFML too now. Also I will have to create my own copy method for some classes like Vector2 and so on.
Title: rbSFML
Post by: Laurent on December 03, 2010, 02:59:36 pm
Quote
Added the SFML::NonCopyable module now

I thought this was very C++-specific. And I thought that in languages such as Ruby, there was no implicit copy ("a = b" is only a "pointer" assignment, both will refer to the same object). And that seems to be true because then you say:
Quote
Also I will have to create my own copy method for some classes like Vector2 and so on.

So if you don't provide a copy method for class X, then X is already non-copyable isn't it?
Title: rbSFML
Post by: Groogy on December 03, 2010, 03:17:56 pm
Quote from: "Laurent"
Quote
Added the SFML::NonCopyable module now

I thought this was very C++-specific. And I thought that in languages such as Ruby, there was no implicit copy ("a = b" is only a "pointer" assignment, both will refer to the same object). And that seems to be true because then you say:
Quote
Also I will have to create my own copy method for some classes like Vector2 and so on.

So if you don't provide a copy method for class X, then X is already non-copyable isn't it?


Ruby has a "initialize_copy" method which is like the copy constructor in C++. And it's correct, the assignment operator only operates with references but there is a dup and clone method which is provided by default in the Object class in the standard Ruby library. So in order to disable an instance from being copied I have to specifically disable it myself.

When I say I'll have to write those methods myself then it's because of my idea of being able to link the instances of an utility class to an owner instance (like a Vector2 for the position of a Sprite) in order to get a more ruby like environment. But if I would copy that instance then it shouldn't be linked to the owner anymore.

Example:
Code: [Select]

sprite = # From somewhere
sprite.position.x = 25
vector_copy = sprite.position.clone
vector_copy.x = 100
vector_copy == sprite.position # Will evaluate to false since vector_copy is not linked to sprite.


Anyway back to SFML::NonCopyable, I've added it to all concerned classes so now you can't copy for instance a SFML::Window and so on. I don't even want to know what would happen if you tried. Though there are other classes which can be copied which is wrapped around a C++ class, I don't know if I have to write my own initialize_copy method for those in order to get a proper behavior or how Ruby handles it.
Title: rbSFML
Post by: Laurent on December 03, 2010, 03:30:43 pm
Quote
Ruby has a "initialize_copy" method which is like the copy constructor in C++. And it's correct, the assignment operator only operates with references but there is a dup and clone method which is provided by default in the Object class in the standard Ruby library. So in order to disable an instance from being copied I have to specifically disable it myself.

Ok I see :)

Quote
When I say I'll have to write those methods myself then it's because of my idea of being able to link the instances of an utility class to an owner instance (like a Vector2 for the position of a Sprite) in order to get a more ruby like environment. But if I would copy that instance then it shouldn't be linked to the owner anymore.

Ok ok. Is it something that people usually do in Ruby? It looks pretty heavy and complicated.
Title: rbSFML
Post by: Groogy on December 03, 2010, 04:25:52 pm
Quote from: "Laurent"
Quote
When I say I'll have to write those methods myself then it's because of my idea of being able to link the instances of an utility class to an owner instance (like a Vector2 for the position of a Sprite) in order to get a more ruby like environment. But if I would copy that instance then it shouldn't be linked to the owner anymore.

Ok ok. Is it something that people usually do in Ruby? It looks pretty heavy and complicated.


No but I think it would be nice not to have to write:
Code: [Select]
position = sprite.position
position.x = #something
sprite.position = position

When it can be shortened to:
Code: [Select]

sprite.position.x = #something


It's complicated, but not heavy ;)
The only change is one extra method call which would otherwise be called anyway. Why it becomes ruby-like is because you access the vectors as attributes to the instance, and you would expect the change to be applied directly by itself.
Title: rbSFML
Post by: Laurent on December 03, 2010, 04:41:32 pm
If it's not usual, won't it be confusing? How do other developers deal with this kind of situation?
Title: rbSFML
Post by: Groogy on December 03, 2010, 04:58:22 pm
Quote from: "Laurent"
If it's not usual, won't it be confusing? How do other developers deal with this kind of situation?


It depends on how the system is designed. I guess you have designed yours so that when we call "SetPosition" on a window it does the proper system calls to emulate that the window position is changed. You could call the position of being a virtual attribute of your sf::Window class. It doesn't really exist for your class but it's emulated from the actual operating systems window as a layer on top of it. An public attribute in Ruby is more or less only method calls on the instance so it's kind of virtual.

But anyway now I see what you mean that it might be confusing. "When is the attribute linked and when is it copied?" It might just be easier for the user to stick with that it's a copy and that you have to explicitly set the attribute to a new value for it to be changed. Also there already is functions like SFML::Drawable#move and so on to fix this easier behaviour for us.

Though the SFML::NonCopyable is still required of course since there are objects that should not be allowed to be cloned/duplicated in ruby. Also I will still have to write specialised initialize_copy methods for those classes that still allow being copied and who are wrapped around a C++ Instance in the SFML library.
Title: rbSFML
Post by: Groogy on December 03, 2010, 05:21:26 pm
Hmm just wondering, how should I copy a SFML instance? Do you do the same in the assignment operator as you do in the copy constructor? Just wondering if I should do it like this:
Code: [Select]
*object = sf::Clock( *source );
or like this:
Code: [Select]
*object = *source;
when copying your objects. Does it differ between the classes or can I make something generic for every copy-able class?
Title: rbSFML
Post by: Laurent on December 03, 2010, 10:28:03 pm
Quote
Do you do the same in the assignment operator as you do in the copy constructor?

Basically yes. When possible, the assignment operator uses the copy constructor to ensure a consistent behaviour.

Quote
Just wondering if I should do it like this:
Code: [Select]
*object = sf::Clock( *source );
or like this:
Code: [Select]
*object = *source;

It's the same, except that the first one performs a useless copy before assignment :)

Quote
Does it differ between the classes or can I make something generic for every copy-able class?

Something generic should be ok.
Title: rbSFML
Post by: Groogy on December 03, 2010, 10:39:56 pm
Quote from: "Laurent"
Quote
Do you do the same in the assignment operator as you do in the copy constructor?

Basically yes. When possible, the assignment operator uses the copy constructor to ensure a consistent behaviour.

Quote
Just wondering if I should do it like this:
Code: [Select]
*object = sf::Clock( *source );
or like this:
Code: [Select]
*object = *source;

It's the same, except that the first one performs a useless copy before assignment :)

Quote
Does it differ between the classes or can I make something generic for every copy-able class?

Something generic should be ok.


Nice! I guessed it would be something like that so already using the assignment operator and have already committed the code Though I'm at my home computer so I can't test if it works but it should. Next up to fix is what Trickster wanted, so that providing an string to for instance an image when creating it will implicitly call #loadFromFile and so on.
Title: rbSFML
Post by: Laurent on December 03, 2010, 10:49:47 pm
Quote
Next up to fix is what Trickster wanted, so that providing an string to for instance an image when creating it will implicitly call #loadFromFile and so on.

We had the same discussion for Python and .Net. Basically, creating an empty object (image, sound or whatever) and then calling LoadFromBlop doesn't make sense in such languages where every object is a reference. If you want to load a new image, you can just get a new object instead of reusing the same one. So we chose to remove LoadFromXxx functions and turn them to constructors instead.
Title: rbSFML
Post by: TricksterGuy on December 04, 2010, 01:55:52 am
Quote from: "Laurent"
Quote
I don't know how Laurent feels about it but I wouldn't mind if you had SVN access so you could commit it yourself. But if he don't want too many people to have access then I can commit it for you.

I give write access to the SVN to developers who want to maintain a binding in the long term.

So it's up to TricksterGuy to decide:
- if he wants to collaborate in the long term to rbSFML I'll give him SVN access
- if he only wants to submit a few patches then it's better if you review and push them to the repository yourself


I will collaborate in the long term.  I've been here for almost two years now and I am not leaving anytime soon I love sfml :D
Title: rbSFML
Post by: Laurent on December 04, 2010, 09:22:59 am
Quote
I will collaborate in the long term. I've been here for almost two years now and I am not leaving anytime soon I love sfml

Glad to hear that :)
I need to know your sourceforge.net account login.
Title: rbSFML
Post by: TricksterGuy on December 04, 2010, 09:31:10 am
tricksterguy
Title: rbSFML
Post by: Laurent on December 04, 2010, 11:16:27 am
Done.
Title: rbSFML
Post by: Groogy on December 04, 2010, 03:36:07 pm
Aight goodie!

I've created a Bugtracker here (http://tasks.groogy.se/)( the same as SFML uses ) which we can use to organize who does what.

I'll add the rake build as a feature request assigned to no one until you register Trickster.
Title: rbSFML
Post by: Groogy on December 04, 2010, 08:02:26 pm
Laurent, I'm curious how you did for the .NET/Python bindings with the constructors when it comes to Shaders. How do you detect if it's a file or if it's loading from memory? Both takes a string.
Title: rbSFML
Post by: Laurent on December 04, 2010, 08:09:28 pm
Quote
How do you detect if it's a file or if it's loading from memory? Both takes a string.

Ah ah :D
I have a LoadFromString function (which is not very clean). For Python, they chose to use static functions instead of constructors, which is more flexible as you can use different names. For example:
Code: [Select]
shader = Shader.CreateFromFile("...")
shader = Shader.CreateFromString("...")
Title: rbSFML
Post by: Groogy on December 04, 2010, 08:37:42 pm
Quote from: "Laurent"
Quote
How do you detect if it's a file or if it's loading from memory? Both takes a string.

Ah ah :D
I have a LoadFromString function (which is not very clean). For Python, they chose to use static functions instead of constructors, which is more flexible as you can use different names. For example:
Code: [Select]
shader = Shader.CreateFromFile("...")
shader = Shader.CreateFromString("...")


Hmm I can do that for Ruby too, really interesting. Wouldn't be hard to implement. But then I'll just do that a:
Code: [Select]
SFML::Shader.new( string )
will always assume that it's a file name. And then also provide these methods:
Code: [Select]
SFML::Shader.new_from_file( filename )
SFML::Shader.new_from_memory( source )

And so on for each resource class.

It's no major implementation. I'll create it as a new task at http://task.groogy.se and if you want to do it then you are free to assign it to yourself TricksterGuy. I have some documentation to do first.
Title: rbSFML
Post by: TricksterGuy on December 04, 2010, 10:10:12 pm
Ok I have created an account there.

Groogy if you are interested you can look at the rdocs for my version of the bindings I did a while back

http://trickster.wg2140.com/doc/index.html
Title: rbSFML
Post by: Groogy on December 04, 2010, 10:13:42 pm
I'll do that, might be something there I can steal.

Though I noticed that you made the bind with the C bindings? That would have simplified a lot of things. But would you have had correct inheritance?

Anyway I made you a developer so you are now free to assign any tasks you like as I put them up. You can also put up your own tasks when you find bugs or come up with something you would like to add to the project.

Also you might notice I've added a "Extension" category. I has been thinking of adding a "sfml/ext" module which would contain some standard data structures like arrays, stacks, queues, bitsets and so on which are quite common. Ruby itself supports a form of array and hash but I'd like to extend that capability with some more data structures. There might even be room for things like common algorithms as binary search and so on.
Title: rbSFML
Post by: TricksterGuy on December 05, 2010, 05:27:20 am
I was wondering how one would wrap a C++ library for use with ruby.  I did not know how to do that 2 years ago so I just stuck with CSFML.

When I tested the methods I wrapped they worked.

Also can't you just use
Array#push Array#pop if you want to have a stack
Array#shift Array#push if you want to have a queue (though inefficient since shift moves all of the elements down)

I believe this kind of stuff is straying away from the focus of this, and should be left to another library whose focus is dedicated to datastructures and making them efficient as possible for ruby. As they say don't reinvent the wheel :P

Now that is not to say you should not add anything of this sort.  There are some things that could be added to make peoples lives a little easier.  

For example you can add a datastructure that holds drawables and each drawable has a z value.  You overload RenderWindow#draw to also be able to draw this and it will draw them all in order of z value
Title: rbSFML
Post by: Groogy on December 05, 2010, 03:43:38 pm
Quote from: "TricksterGuy"
Also can't you just use
Array#push Array#pop if you want to have a stack
Array#shift Array#push if you want to have a queue (though inefficient since shift moves all of the elements down)

I've already made some container classes in Ruby to do these things for me and that I feel are more efficient. Though it might just be a "I've done it myself so I know it's better"-thingy :P
Quote from: "TricksterGuy"

I believe this kind of stuff is straying away from the focus of this, and should be left to another library whose focus is dedicated to datastructures and making them efficient as possible for ruby. As they say don't reinvent the wheel :P

Well that's pretty much true. Though multimedia means several contents or something like that so it might just fit in, but most probably not :P

Quote from: "TricksterGuy"

Now that is not to say you should not add anything of this sort.  There are some things that could be added to make peoples lives a little easier.  

For example you can add a datastructure that holds drawables and each drawable has a z value.  You overload RenderWindow#draw to also be able to draw this and it will draw them all in order of z value

Well that could be easily be implemented with a custom drawable. Something like this:
Code: [Select]
class ZOrderedDrawables
  include SFML::Drawable
 
  def initialize
    @drawables = []
  end
 
  def add( aDrawable )
    index = # find the index to place it so the drawables stay in order.
    @drawables.insert( index, aDrawable )
  end

  def render( aTarget, aRenderer )
    for drawable in @drawables
      aTarget.draw( drawable )
    end
  end
end


Though the thing is if it does fit into the SFML library. Though we could make it so that sfml/ext is a totally separate library from SFML that you have to write explicitly to compile. So it's not included in a "rake all" and have to write by yourself "rake extension" or something like that. This depends on how Laurent feels if it fits into a Ruby bindings.
Title: rbSFML
Post by: Laurent on December 05, 2010, 08:33:30 pm
If you want my opinion, I think there should be the binding and the extension as two clearly separated things.
Title: rbSFML
Post by: Calmatory on December 08, 2010, 10:33:01 pm
This is just awesome work, Swede. :)

A big big thank you.
Title: rbSFML
Post by: Hugo on December 26, 2010, 01:02:22 am
+1 dev points for you I've been wanting to learn ruby
Title: rbSFML
Post by: Groogy on January 08, 2011, 04:04:09 pm
Trickster, I added a new project to our task tracker so I had to move the rights around a little. So now your not a global developer but only a rbSFML developer. It's not that I think you would mess anything up(and even if you did it wouldn't matter) but I'm quite picky and right should be right :P

And if I would get more developers to rbSFML or Ascension then it would be nice to know what I am doing :)

Anyway tell me if you still got full access to the rbSFML project but none to the new one.
Title: rbSFML
Post by: TricksterGuy on January 18, 2011, 04:09:12 pm
Its fine I would have done the same thing, but it looks like its down.  I can't access it.
Title: rbSFML
Post by: Groogy on January 18, 2011, 05:54:08 pm
How do you mean down? I'm at the website right now.
Title: rbSFML
Post by: TricksterGuy on January 22, 2011, 09:59:06 pm
It was down at the time I made the post I couldn't access the server or something, but it is back up now

You did not mess anything up.

Also starting next week hopefully I will start working again.  I've been busy for the past couple of weeks.

Also to get this to compile/link successfully on windows I'd have to change the structure of the project a bit. I was not able to solve the linking issues and mingw doesn't have lazy link functionality (from what I've searched on the internet).
Title: rbSFML
Post by: Groogy on January 22, 2011, 10:57:23 pm
That's cool, the important thing is that it works ;)
Title: rbSFML
Post by: Groogy on January 26, 2011, 11:11:09 pm
Just tried recompiling the rbSFML bindings on Linux... I keep getting "undefined symbol: glEnable" which is weird, that library should be included in the sfml-window-s library right?  I tried adding it manually but I got another undefined symbol from another library... So what am I doing wrong?

UPDATE: Made a quick fix in the Rakefile by adding all the external libraries to SFML.... This is a bad fix and should be dealt with. Though I do not understand why I have to manually link them, they are included in the static libraries.  :?
Title: rbSFML
Post by: Laurent on January 27, 2011, 07:44:11 am
Nop. On Linux, external libraries are not included in SFML static libs. You shouldn't even use static libraries on Linux.
Title: rbSFML
Post by: Groogy on January 27, 2011, 07:57:36 am
I know but you usually do on ruby extensions, I think... I know I read it somewhere. Think it was something like that you want the package / extension to be self-containing.

Don't know what is the better choice here actually.
Title: rbSFML
Post by: Laurent on January 27, 2011, 09:26:51 am
Hum I think static linking is always the worst choice on Linux, shared libraries are just handled perfectly. To me, static linking is a hack which is necessary on Windows to workaround the lack of proper shared library management by the OS. Nothing more.

On Linux, your binding will be nicely packaged, its dependencies will be searched automatically and installed if necessary.
Title: rbSFML
Post by: Groogy on January 27, 2011, 10:27:01 am
Quote from: "Laurent"
Hum I think static linking is always the worst choice on Linux, shared libraries are just handled perfectly. To me, static linking is a hack which is necessary on Windows to workaround the lack of proper shared library management by the OS. Nothing more.

On Linux, your binding will be nicely packaged, its dependencies will be searched automatically and installed if necessary.


Yeah your right. If I get any complaints it won't be hard modifying the rakefile to support both I think.

Update: Committed the new rakefile
Sorry trickster for messing up your stuff :P
Title: rbSFML
Post by: etam on February 05, 2011, 11:55:53 pm
Something is broken, or I'm doing something wrong?

I just went to bindings/ruby directory, typed "rake" and that's what I got:
Code: [Select]
rake aborted!
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:136: syntax error, unexpected ',', expecting ']'
file "#{SODIR}/#{so_file}.so" => [*objs, SODIR] do
                                       ^
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:141: syntax error, unexpected kRESCUE, expecting kEND
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:148: syntax error, unexpected kDO_BLOCK, expecting kEND
SO_SRCS.each_key do |so_file|
                  ^
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:149: syntax error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
sh "#{INSTALL} #{SODIR}/#{so_file}.so #{LOCATION}"
   ^
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:151: syntax error, unexpected kRESCUE, expecting kEND
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:158: syntax error, unexpected kDO_BLOCK, expecting kEND
SO_SRCS.each_key do |so_file|
                  ^
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:159: syntax error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
sh "rm -f #{LOCATION}/#{so_file}.so"
   ^
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:162: syntax error, unexpected kRESCUE, expecting kEND
/usr/src/packages/BUILD/sfml2-2.0/bindings/ruby/Rakefile:167: syntax error, unexpected $end, expecting kEND


sources from https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2 rev 1789
ruby 1.8.7
rake 0.8.7
Title: rbSFML
Post by: Groogy on February 06, 2011, 12:53:26 am
I've used the latest official version of ruby(1.9.2p0) while developing this binding. I have no idea if it works on any older version. It worked compiling for me though, so that might be the issue.

Also the rake file is maintained by trickster, I have no idea of how rake works so we'll see if he responds to it.

EDIT: Just tried it and it worked like a charm :) I'm guessing on that you using the old 1.8.x ruby is the problem because we both have the same rake version.

The problem also seems to be syntax errors, which would pretty much confirm it, since there are some new syntax tricks to ruby-1.9.x
I could see if Trickster is willing to make the file compatible with 1.8.x but I'm not sure if it would still compile.

And a final note: You are allowed to create new threads on the forum for anything ruby-ish :)
Though I'm really glad to see that people are starting to use rbSFML ^^
Title: rbSFML
Post by: Mon ouïe 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)
Title: rbSFML
Post by: TricksterGuy on February 06, 2011, 10:02:35 am
Yep that would fix that

sorry about that, etam!

Also I have made progress getting this to compile/link under windows I am able to at least open the window-demo program.

There are a few changes that will have to be made to the directory structure for this to all work however.  Consider this payback for messing with the rakefile I guess :P
Title: rbSFML
Post by: Groogy on February 06, 2011, 11:08:48 am
Hahaha it's cool ^^
It's great if it works for Windows, or else it wouldn't really be cross-OS now would it ;)

Will you implement the directory changes or will I do that?
Title: rbSFML
Post by: Groogy on February 08, 2011, 06:06:27 pm
Trickster, just wondering when you think you will be ready with the structure for Windows?
Title: rbSFML
Post by: TricksterGuy on February 11, 2011, 01:53:51 pm
So I have already changed the structure in my working version.

Basically I just created a shared folder with the things from the system folder that was used in the other folders. And edited all of the other files main.cpp as necessary.

As of now I am working to fix a bug in the window-demo that causes ruby to crash when you exit.  If you want to help find it I could commit what I have right now.

I'm shooting for sometime next week but I have exams keeping me busy unfortunately
Title: rbSFML
Post by: Groogy on February 11, 2011, 03:15:02 pm
It's okay, I got school too :P

Anyway commit what you have and I'll have a look at it. IS the error occuring on your laptop with intel or ATI? Because that might just be what is happening, the old ATI/Intel bug :P

Anyway I'll have a go on my new laptop with a REAL nvidia card and on my university computer which also have a nvidia card and on my old intel laptop to see if the error occurs on all of them. Unfortunley I do not have access to any ATI cards :/
Title: rbSFML
Post by: TricksterGuy on February 13, 2011, 06:08:43 am
I'll have it committed in a second. Checking to make sure I didn't break anything. EDIT It is now committed.

I am testing the changes on linux now and I don't get the crash on exit thing.  Interesting...

Also this laptop has an Intel



So as I said I was testing this under windows with the window-demo.rb test.
It works fine however upon closing ruby crashes.
Interesting enough if I comment all of the code to initialize the window library and require it. It will still crash. That is regardless of the code for window.so requiring it makes ruby crash upon closing.
Title: rbSFML
Post by: Groogy on February 13, 2011, 01:02:54 pm
Yep, it's probably the global opengl context. Laurent is working on it, I'll try it out now.
Title: rbSFML
Post by: Groogy on February 13, 2011, 01:41:19 pm
Aight running Window worked :) Though since it's Windows it was bit tricky to get it to find SFML and be able to compile because of that, don't think you can help out the user with that somehow? Also "rake install" didn't work for me? I normally don't use Ruby on Windows so I don't know what I did wrong. Anyway what it failed on was simply copying audio.so to the ruby directory. I'm using Win7.
Also you have messed up something so that Graphics can't be loaded because WindowLoaded haven't been defined or something... I haven't looked at it really yet, just noticed that I couldn't run render-window-demo.rb because Graphics failed to load. *Fixed* You didn't gain access to the SFML namespace module or the shared objects in here. :)
It's a weird name for a function: rb_define_* because you don't define anything if it already exists, it just returns a VALUE reference to it.

I'll fix it now ^^  Got nothing to do with my coffee.

Anyway it works here without crashing like you said and it's on WINDOWS :D
So we officially support windows now too ^^
Title: rbSFML
Post by: TricksterGuy on February 13, 2011, 06:52:17 pm
If you get it from svn (the whole sfml2 stuff) it should compile out of the box.  The default directories it searches assumes the same directory structure as whats in the repository.

You can switch them by defining some environment variables in which case it will override the default.

SFML_INCLUDE to tell it where the SFML header files are
SFML_LIB to tell it where the SFML library files are

and currently rake install does put the things in the wrong directory however on linux it installs in the correct directory at least from what I have seen :|
This should be an easy fix however.

Haha cool, but ruby still crashes on exit on my computer :P
Title: rbSFML
Post by: Groogy on February 13, 2011, 07:12:51 pm
Quote from: "TricksterGuy"
If you get it from svn (the whole sfml2 stuff) it should compile out of the box.  The default directories it searches assumes the same directory structure as whats in the repository.

Ah okay, I took it down from the repo but I didn't care to compile SFML2 since I already had it.

Quote from: "TricksterGuy"

You can switch them by defining some environment variables in which case it will override the default.

SFML_INCLUDE to tell it where the SFML header files are
SFML_LIB to tell it where the SFML library files are

Sweet, can you pass that to rake as arguments? That would be handy. I had a problem with the environment variable since the path has spaces in it and Ruby didn't like that :P

Quote from: "TricksterGuy"

and currently rake install does put the things in the wrong directory however on linux it installs in the correct directory at least from what I have seen :|
This should be an easy fix however.

In my eyes it looked like the correct one: #<RuntimeError: Command failed with status (127): [install sfml/audio.so C:/Ruby
192/lib/ruby/...]>

Quote from: "TricksterGuy"

Haha cool, but ruby still crashes on exit on my computer :P

Well like I said, Laurent is working on it :)
Title: rbSFML
Post by: Groogy on February 26, 2011, 02:27:20 am
Just a general warning for anyone, cloning a SFML object that is not mixed in non-copyable and wraps a C++ instance will result in undefined behaviour, most probably a crash if Ruby is kind on you. I thought I only had to define the SFML::<insert class here>#initialize_copy method in order to have it working. But what I forgot is that a new instance is never allocated, so I am actually working on a wild pointer in that method.

I am going to fix it this weekend, I have already made a fix for SFML::Sprite that worked. I'll upload it all in one bunch.

EDIT: Added task here (http://tasks.groogy.se/index.php?do=details&task_id=13)

EDIT2: Only got Graphics and Audio library left.
Title: rbSFML
Post by: Mon ouïe 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.
Title: rbSFML
Post by: Groogy on February 26, 2011, 04:45:15 pm
I'll have a look at it.

Update: Initial testing seems to work. More re-factoring for me... YAY!
Update: The different event type classes won't be re-factored, they should only be acquired trough an event instance anyway. Might re-factor them when I got the time to do it.
Title: rbSFML
Post by: Groogy on February 27, 2011, 02:39:02 pm
I'm wondering, is these classes copyable?
SoundBufferRecorder
SoundRecorder

They don't inherit from NonCopyable but they don't have an assignment operator or copy constructor defined. Is it still safe to copy them?

Edit: When I tried I got massive failure, but this is not reflected in the documentation. =/

In any case the re-factoring is done.

Update: Well ruby is bad mouthing me about my allocating in drawable. Don't know why I made a special case there. Anyway I've fixed it, I'll commit it when I get home. So if you get a warning message about deprecated allocation method setting or something, just update to a later rbSFML binding.
Title: rbSFML
Post by: Groogy on March 05, 2011, 03:42:31 pm
I'm wondering what you think trickster? Should we support that the end user compile rbSFML with static sfml libraries? Like he writes in the console:
Code: [Select]
rake static and it uses the static libraries instead?

I'm just thinking it might be annoying for some people having to juggle around double shared libraries, especially on windows. It probably should even be the default on windows.

It's just a convenience thing and not something important really. They can live with it. So it depends on if you got the time to modify the rakefile to support it. If not, then we don't do it unless someone complains.

Since the libraries should be encapsulated in a gem normally, it shouldn't be a bother.
Title: rbSFML
Post by: Groogy on March 28, 2011, 10:15:46 am
Aight a Github repo is up for rbSFML: https://github.com/Groogy/rbSFML
Title: rbSFML
Post by: Groogy on April 06, 2011, 10:48:09 pm
rbSFML should be up-to-date right now. At least it compiles. If there's a new function in the API that I've missed please notify me. I am doing my best following Laurent's commits.
Title: rbSFML
Post by: Laurent on April 07, 2011, 07:47:35 am
The latest modifications didn't add anything, they removed RenderImage::IsAvailable.

There are default values that changed in sf::ContextSettings and sf::Image, I don't know if it makes a difference for you.
Title: rbSFML
Post by: TricksterGuy on April 07, 2011, 07:49:36 am
Quote from: "Groogy"
I'm wondering what you think trickster? Should we support that the end user compile rbSFML with static sfml libraries? Like he writes in the console:
Code: [Select]
rake static and it uses the static libraries instead?

I'm just thinking it might be annoying for some people having to juggle around double shared libraries, especially on windows. It probably should even be the default on windows.

It's just a convenience thing and not something important really. They can live with it. So it depends on if you got the time to modify the rakefile to support it. If not, then we don't do it unless someone complains.

Since the libraries should be encapsulated in a gem normally, it shouldn't be a bother.


I'll wait until someome complains.

I also have little time for the next couple of weeks due to graduate school...

However the good news is I have purchased a new laptop with a better graphics card than my old laptop and its a 64 bit system. So I'll play around it with it with this when I am able.
Title: rbSFML
Post by: Groogy on April 07, 2011, 09:10:08 am
Quote from: "Laurent"
The latest modifications didn't add anything, they removed RenderImage::IsAvailable.

There are default values that changed in sf::ContextSettings and sf::Image, I don't know if it makes a difference for you.


If it's default arguments then there's some stuff that I have to change. If it is default values set inside the constructor then I don't need to change anything.

I'll look at the changes in the commit list to be extra sure.

Quote from: "TricksterGuy"

I'll wait until someome complains.

I also have little time for the next couple of weeks due to graduate school...

However the good news is I have purchased a new laptop with a better graphics card than my old laptop and its a 64 bit system. So I'll play around it with it with this when I am able.

No worries, know you don't have much time. Also congrats to the new laptop. Though the ATI/Intel bug has been fixed in SFML2 now ^^

You are aware that the entire SFML project has moved to Github? I have created a Github repo for rbSFML, if you create an account I can set you as a developer for it.
Title: rbSFML
Post by: Laurent on April 07, 2011, 09:12:08 am
Quote
If it's default arguments then there's some stuff that I have to change.

In sf::ContextSettings it's the default arguments of the default constructor. In sf::Image it's only a default value.
Title: rbSFML
Post by: Groogy on April 07, 2011, 09:18:45 am
Quote from: "Laurent"
Quote
If it's default arguments then there's some stuff that I have to change.

In sf::ContextSettings it's the default arguments of the default constructor. In sf::Image it's only a default value.

I just noticed that I might not even have to do that, some really stupid code replication actually saved my ass here.

I already found the new stuff, Github's commit shower is sweet :P
Title: rbSFML
Post by: TricksterGuy on June 04, 2011, 10:45:21 pm
Alright I am back for the most part.

I have set up a github account username is the same as my username here.

and I come with gifts too

http://trickster.wg2140.com/Games/samegamerbsfml.zip (depends on Narray)

^ ported this code I wrote with Rubygame to rbSfml last night  :D

Also my new laptop is awesome.
Title: rbSFML
Post by: Groogy on June 04, 2011, 10:55:17 pm
Nice to see you again!

Also sweet but I can't run it, I don't have narray and is having trouble with installing it(same thing when trying to install ruby-opengl I think).

Anyway I added you as a collaborator to the project.
Title: rbSFML
Post by: TricksterGuy on June 05, 2011, 12:34:26 am
Alright.

Odd that you can't get it working.

Also it seems like rake rdoc generates unreadable documentation or at least the documentation doesn't look great.  I'll be having a look at this

And I just provided an overload for Image#new pass in a width, height, and a color object it will call Create (the one thing that annoyed me when porting my code over)'
Title: rbSFML
Post by: Groogy on June 05, 2011, 01:34:34 am
Ah didn't mean like that, I think you miss understood what I meant. I don't have the gem narray and my gem on Windows are messing with me so I can't install anything!

Also commented on your commit on Github, love that feature by the way, on something stupid on my side that I just realized.
Title: rbSFML
Post by: Groogy on July 06, 2011, 04:32:41 am
Allright rbSFML now also support the three new input classes and SFML::Input was removed.
Title: rbSFML
Post by: kurayama on August 07, 2011, 01:53:18 am
Can't seem to get it working on osx with rvm.
Always get ''require' no such file to load...' on sfml includes
Title: rbSFML
Post by: Groogy on August 16, 2011, 10:50:00 am
Sorry, I have been trying to aquire access to a OS X machine but could not. Maybe you can describe the problem a little more? Did you follow the instructions? Did it compile and install successfully?

Any information will be help full.
Title: rbSFML
Post by: Groogy on August 20, 2011, 02:19:09 pm
An update to what's going on with rbSFML so you guys don't think I've forgotten. Whoever you few guys are that uses it. Anyway keep sending me messages about it is incompatible with the latest version of SFML2 or just say: "Hi, I use rbSFML!"
It's nice to see that there actually is developers that are using my library :)

Anyway I am currently working on getting the library up to date to the Texture changes of SFML2 so it compiles.

After that I will have to implement the InputStream functionality somehow. Either I will just simply use the IO base class in Ruby or I'll provide a whole new class for that. Suggestion from anyone here is appreciated, even though if you have no idea of how Ruby works or looks like you can still come with valid design suggestions and so on.

And last thing I'll do is a complete overhaul of rbSFML going trough each file and function to see if I've missed something and also update the documentation. This will take it's sweet time as well because I am doing most of my work from my android phone so it's going pretty slow though I find it quite cool.
Title: rbSFML
Post by: Groogy on August 21, 2011, 07:26:39 pm
Alright! rbSFML is now up to date!

If anything seems weird or you get crashes, undefined behaviour let me know and I'll fix it. The changes were pretty major so I might have missed something somewhere.

If Laurent doesn't decide to change anything else in the near future I will start and try develop BigTexture and BigSprite classes to rbSFML and post it on the wiki for people who want to draw sprites larger than what their graphics card allow.
Title: rbSFML
Post by: Zerralin on September 19, 2011, 08:47:34 am
Hello, I'm trying to use SFML2 with this binding but i get a error during compiling..
Code: [Select]


C:\Users\creep\Downloads\Groogy-rbSFML-fd916bf\Groogy-rbSFML-fd916bf>rake
(in C:/Users/creep/Downloads/Groogy-rbSFML-fd916bf/Groogy-rbSFML-fd916bf)
mkdir -p obj
mkdir -p obj/shared
Compiling shared/global.cpp
Compiling shared/NonCopyable.cpp
Compiling shared/Vector2.cpp
Compiling shared/Vector3.cpp
mkdir -p obj/audio
Compiling audio/Listener.cpp
Compiling audio/main.cpp
Compiling audio/Music.cpp
Compiling audio/Sound.cpp
Compiling audio/SoundBuffer.cpp
Compiling audio/SoundBufferRecorder.cpp
Compiling audio/SoundRecorder.cpp
Compiling audio/SoundSource.cpp
Compiling audio/SoundStream.cpp
mkdir -p obj/graphics
Compiling graphics/Color.cpp
Compiling graphics/Drawable.cpp
Compiling graphics/Font.cpp
Compiling graphics/Glyph.cpp
Compiling graphics/Image.cpp
Compiling graphics/main.cpp
Compiling graphics/Rect.cpp
Compiling graphics/Renderer.cpp
Compiling graphics/RenderTarget.cpp
Compiling graphics/RenderTexture.cpp
Compiling graphics/RenderWindow.cpp
Compiling graphics/Shader.cpp
Compiling graphics/Shape.cpp
Compiling graphics/Sprite.cpp
Compiling graphics/Text.cpp
Compiling graphics/Texture.cpp
Compiling graphics/View.cpp
mkdir -p obj/window
Compiling window/Context.cpp
Compiling window/ContextSettings.cpp
Compiling window/Event.cpp
Compiling window/Joystick.cpp
Compiling window/Keyboard.cpp
Compiling window/main.cpp
Compiling window/Mouse.cpp
Compiling window/VideoMode.cpp
Compiling window/Window.cpp
mkdir -p obj/system
Compiling system/Clock.cpp
Compiling system/InputStream.cpp
Compiling system/main.cpp
Creating system.so
obj/system/InputStream.o: In function `~InputStream':
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/Inp
utStream.hpp:48: undefined reference to `_imp___ZTVN2sf11InputStreamE'
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/Inp
utStream.hpp:48: undefined reference to `_imp___ZTVN2sf11InputStreamE'
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/Inp
utStream.hpp:48: undefined reference to `_imp___ZTVN2sf11InputStreamE'
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/Inp
utStream.hpp:48: undefined reference to `_imp___ZTVN2sf11InputStreamE'
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/Inp
utStream.hpp:48: undefined reference to `_imp___ZTVN2sf11InputStreamE'
collect2: ld returned 1 exit status
mkdir -p obj/all
Compiling all/main.cpp

C:\Users\creep\Downloads\Groogy-rbSFML-fd916bf\Groogy-rbSFML-fd916bf>

OS: Windows 7
Ruby(rubyinstaller): ruby 1.9.2p290(2011-07-09) [1386-mingw32]

Can you help me ? thanks.
Title: rbSFML
Post by: Groogy on September 19, 2011, 06:23:34 pm
I'm at my university computer right now but can you check so that the library files you are linking against are the latest? Remove any SFML2 installation you have and recompile it from scratch.
Title: rbSFML
Post by: Groogy on September 20, 2011, 07:45:29 pm
Verified that this is a sfml error and not a problem in rbSFML in itself. Laurent said he would fix it today so when thats done it should work.
Title: rbSFML
Post by: Zerralin on September 20, 2011, 08:57:31 pm
Ok, i have reinstalled sfml2, ruby/rbsfml and mingw like 3 times, but always the same error. It's happen only to me or i'm the only one windows user ? :lol:
Title: rbSFML
Post by: Groogy on September 20, 2011, 09:29:32 pm
You've done nothing wrong, everyone get it but Laurent have fixed it now so just download latest SFML and try again(you don't have to reinstall ruby or mingw).

Here's the issue on SFML: https://github.com/SFML/SFML/issues/100

The error would occur for any SFML users that compiled with MinGW, not only ruby developers ;)

Let me know what you think about the bindings and if you need more help I'm here. The documentation is quite out of date(will be fixed when SFML2 is officially released) but I've tried to mimic SFML as much as possible without breaking Ruby all too much.
Title: rbSFML
Post by: Rukiri on October 01, 2011, 07:44:39 pm
The issue is still there, wonder if she'll post the update soon.. really want to use rbsfml.
Title: rbSFML
Post by: Groogy on October 01, 2011, 07:56:15 pm
Are you a 100% sure you got the latest SFML2 and rbSFML? Everything compiles fine for me.
Title: rbSFML
Post by: Rukiri on October 01, 2011, 07:58:32 pm
Downloaded SMFL-2 directly from github this morning, and RBSFML from Github an hr ago.

Redownloaded RBSFML to make sure and I get the same error..

(http://i54.tinypic.com/19a1qr.jpg)
Title: rbSFML
Post by: Laurent on October 01, 2011, 08:12:16 pm
Make sure that you really have the most recent version of SFML, and try a complete rebuild ("make clean").
Title: rbSFML
Post by: Groogy on October 01, 2011, 08:23:50 pm
Ah crap forgot that. Do first a "rake clobber" to be sure that EVERYTHING is gone before compiling. And a mingw32-make clean on SFML. And of course follow the normal procedure as laid out in the readme file. (You know the pathing thing because Windows is a bitch :P)

The obj files might not be updated and so when they are being linked this error would appear again.
Title: rbSFML
Post by: Rukiri on October 01, 2011, 08:39:38 pm
Looks like it is the obj file, got any ideas?
Title: rbSFML
Post by: Groogy on October 01, 2011, 09:04:18 pm
You got the latest SFML2 version? You have a fresh version, compiled it and installed it? You have copied the new SFML include and lib files into the rbSFML folder as it says you should in the readme? You have done all of these steps?
Title: rbSFML
Post by: Rukiri on October 02, 2011, 01:11:51 am
Lol, that was it :oops:

But now it's giving me a load error when I try to require 'sfml/system' and I placed everything in the correct folders.

Edit: I got it running a hello world program, only problem is I have to have the dlls where the projects main.rb file is.
Title: rbSFML
Post by: Groogy on October 02, 2011, 01:44:44 am
Place them in system32 or anywhere in the PATH environment variable. I manually added C:\Program Files\SFML\bin to my PATH variable so that I don't have to do that.

Windows is a bitch when it comes to these things  :lol:
Title: rbSFML
Post by: Groogy on January 22, 2012, 12:29:26 am
Alright for those few that might be interested in the progress of rbSFML I would just like to let you guys know that since Laurent is nearing the end of SFML2 development the development of rbSFML will pick up. LB has been working on a complete remake to make maintenance easier and really use C++ to what it was meant for. I am right now sitting on his code and coding away ^^

Anyway lately I have been looking just quick glances at other implementations of Ruby. Our main goal will of course at all times be the MRI Ruby 1.9 branch. But since Rubinus is also starting/finishing with Ruby 1.9 and they say they will work with almost all MRI Ruby extensions I hope they work for us too. And when SFML2 comes to a close I would like to look at the possibilities to also support other implementations like JRuby and Rubinus. Especially Rubinus as it delivers more power for the buck.

Opinions wanted and possible testers who are used to these alternative implementations.
Title: rbSFML
Post by: Groogy on February 26, 2012, 10:09:57 pm
Alright getting some work done on rbSFML. I and LBg have hacked up an "unmaintainable" version of the modules (except for graphics) so far. After SFML2.0 is released we will slowly start to move to LBg's C++ to Ruby wrapper to make it easier and faster to change the API according to the C++ version. So if Laurent decided to re-write the whole API it should only take us about a day to comply instead of an entire month.

Currently working on the graphics module. But since these are "just-in-time" code so that you can do basic SFML stuff with it some things will not be supported. Like inheriting from Drawable and define your own and stuff like that. These will come instead with the new wrapper LBg is writing.
Title: Re: rbSFML
Post by: Groogy on March 28, 2012, 12:30:58 am
Alright I just uploaded the Sprite implementation. Did a quick test, fixed some bugs that appeared and then I could render graphics to the window :D

Anyway I got shapes and text left. Other than that the library is expected to work like it should. If not please let me know and I'll fix it. I've used SFML as a layout blueprint for the whole library so it's not that ruby-like. Some parts have been "rubyfied" but there's probably a lot left. If you find something that you feel should use some ruby language specific feature then let me know. Or if there is anything else you think I should change to make it easier to work with don't be afraid to tell me.
Title: Re: rbSFML
Post by: Groogy on April 01, 2012, 01:04:15 am
IT IS FINALLY DONE!

Took some time and a lot of effort but rbSFML is finally up to date with Laurent/SFML @ Github.
With time documentation and Rspec's will be put up to complete the binding.

Getting started steps are available in the readme (https://github.com/Groogy/rbSFML/blob/master/README.markdown) and if you have programmed before with SFML but in any other language it should be really easy to get started as every method has an alias method which mimics the C++ Documentation so you can more or less both write Ruby-style code and C++-style code with the binding to make it as easy as possible to get started with rbSFML.

Example:
text = SFML::Text.new( "Hello World!" )
text.color = [ 255, 0, 255 ]
text.position = [ 10, 10 ]
image = SFML::Image.new( 100, 100, SFML::Color::White )
texture = SFML::Texture.new( 100, 100 )
sprite = SFML::Sprite.new( texture )
sprite.origin = [ 50, 50 ]
texture.update( image )
Is the same as
text = SFML::Text.new( "Hello World!" )
text.setColor( SFML::Color.new( 255, 0, 255 ) )
text.setPosition( SFML::Vector2.new( 10, 10 ) )
image = SFML::Image.new( 100, 100, SFML::Color::White )
texture = SFML::Texture.new( 100, 100 )
sprite = SFML::Sprite.new( texture )
sprite.setOrigin( SFML::Vector2.new( 50, 50 ) )
texture.update( image )

As you can also see we have provided an implicit way to define the common SFML structures to make it easier and faster to use. So instead of having to write the code to create a vector object you can just provide an equivalent array and rbSFML will construct a vector object from it.

I hope my previous users like the bindings and if they have opinions on how to improve it and make it more Ruby-like I would love to hear them. And I hope I will get more users and I hope they as well will have opinions and give them to me :)

Until I get going with Rspec and documentation here is a working example you can play around with:
require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'

window = SFML::RenderWindow.new( [ 800, 600 ], "Test" )

text = SFML::Text.new( "Hello World!" )
text.color = [ 255, 0, 255 ]
text.position = [ 10, 10 ]
image = SFML::Image.new( 100, 100, SFML::Color::White )
texture = SFML::Texture.new( 100, 100 )
sprite = SFML::Sprite.new( texture )
sprite.origin = [ 50, 50 ]
texture.update( image )

while window.open?
  window.clear
  window.draw text
  window.draw sprite
  window.display
 
  sprite.position = SFML::Mouse.position( window )
 
  window.each_event do |event|
    if event.type == SFML::Event::Closed
      window.close
    end
  end
end

Have fun!
Title: Re: rbSFML
Post by: Laurent on April 01, 2012, 09:53:37 am
Nice :)
Title: Re: rbSFML
Post by: vivo on April 18, 2012, 01:07:44 pm
Hello all, first I'd like to thank all you for your effort within this project.

I'm completely newbie with SFML but I'm going to try to develop some king of engine for adventure games, 2D and as simple as possible. If the project makes sense i'll post any progress.

Well, I was just introducing my self.
Installing rbSFML was rough, now at now I've finally made it thanks to Groogy's Installation guide (Linux).
Not sure, but i think I still have some errors, dont know if are normal errors or maybe are related with the instalation I made:

Code: [Select]
Loaded 'sfml/system'
Loaded 'sfml/window'
Loaded 'sfml/graphics'
Loaded 'sfml/audio'
Loaded suite /usr/local/bin/rake
Started
EEF.FEE..............EEE....EEE........FEF
Finished in 0.848552 seconds.

  1) Error:
test_compare(TestClock):
NoMethodError: undefined method `>' for SFML::Clock(0.100312s):SFML::Clock
    test/System/Clock.rb:49:in `test_compare'

  2) Error:
test_elapsed_time(TestClock):
TypeError: can't convert Fixnum into SFML::Time
    test/System/Clock.rb:30:in `test_elapsed_time'

  3) Failure:
test_equal(TestClock) [test/System/Clock.rb:15]:
<SFML::Clock(0.200389s)> expected but was
<SFML::Clock(0.200430s)>.

  4) Failure:
test_inspect(TestClock) [test/System/Clock.rb:23]:
Expected /SFML::Clock\(\d+ms\)/ to match "SFML::Clock(0.000000s)".

  5) Error:
test_reset(TestClock):
TypeError: can't convert Fixnum into SFML::Time
    test/System/Clock.rb:35:in `test_reset'

  6) Error:
test_subclass(TestClock):
TypeError: can't convert Fixnum into SFML::Time
    test/System/Clock.rb:66:in `test_subclass'

  7) Error:
test_initialization3(TestVector2):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector2.rb:24:in `initialize'
    test/System/Vector2.rb:24:in `new'
    test/System/Vector2.rb:24:in `test_initialization3'

  8) Error:
test_inspect(TestVector2):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector2.rb:56:in `initialize'
    test/System/Vector2.rb:56:in `new'
    test/System/Vector2.rb:56:in `test_inspect'

  9) Error:
test_operators(TestVector2):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector2.rb:35:in `initialize'
    test/System/Vector2.rb:35:in `new'
    test/System/Vector2.rb:35:in `test_operators'

 10) Error:
test_initialization3(TestVector3):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector3.rb:28:in `initialize'
    test/System/Vector3.rb:28:in `new'
    test/System/Vector3.rb:28:in `test_initialization3'

 11) Error:
test_inspect(TestVector3):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector3.rb:62:in `initialize'
    test/System/Vector3.rb:62:in `new'
    test/System/Vector3.rb:62:in `test_inspect'

 12) Error:
test_operators(TestVector3):
TypeError: Did not receive expected types ( 'Fixnum', 'Float' )
    test/System/Vector3.rb:41:in `initialize'
    test/System/Vector3.rb:41:in `new'
    test/System/Vector3.rb:41:in `test_operators'

 13) Failure:
test_subclass(TestVideoMode) [test/Window/VideoMode.rb:100]:
Expected SFML::VideoMode(1366x768, 24-bits) to be an instance of TestVideoMode::MyVideoMode, not SFML::VideoMode.

 14) Error:
test1(TestWindow):
NoMethodError: undefined method `opened?' for SFML::Window(0x92367d0):SFML::Window
    test/Window/Window.rb:10:in `test1'

 15) Failure:
test_exceptions(TestWindow) [test/Window/Window.rb:38]:
[TypeError] exception expected, not
Class: <RuntimeError>
Message: <"SFML::Window can not be copied!">
---Backtrace---
test/Window/Window.rb:38:in `initialize_copy'
test/Window/Window.rb:38:in `initialize_dup'
test/Window/Window.rb:38:in `dup'
test/Window/Window.rb:38:in `block in test_exceptions'
---------------

42 tests, 374 assertions, 4 failures, 11 errors, 0 skips

Test run options: --seed 49933
/usr/local/bin/rake: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

-- control frame ----------
c:0001 p:0000 s:0002 b:0002 l:002474 d:002474 TOP   
---------------------------

-- C level backtrace information -------------------------------------------
/usr/local/lib/libruby.so.1.9(rb_vm_bugreport+0xa5) [0xe1cfb5]
/usr/local/lib/libruby.so.1.9(+0xa85e9) [0xd005e9]
/usr/local/lib/libruby.so.1.9(rb_bug+0x28) [0xd00698]
/usr/local/lib/libruby.so.1.9(+0x156088) [0xdae088]
[0xa4a40c]
/usr/lib/libX11.so.6(_XSend+0x14c) [0x626dec]
/usr/lib/libX11.so.6(_XReply+0x60) [0x626f90]
/usr/lib/libX11.so.6(XSync+0x67) [0x61a867]
/usr/lib/fglrx/libGL.so.1(+0x4b205) [0x43b205]
[0x5600001]
/usr/lib/fglrx/dri/fglrx_dri.so(+0x15e6f3a) [0x3a53f3a]

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html



Title: Re: rbSFML
Post by: Lupinius on April 19, 2012, 02:38:26 pm
When trying to compile rbSFML on windows I get this message:
Code: [Select]
sh.exe"-3.1$ rake
Creating sfml/system.so
Creating sfml/window.so
Compiling ext/Graphics/Font.cpp
ext/Graphics/Font.cpp: In function 'VALUE rbFont::LoadFromStream(VALUE, VALUE)':
ext/Graphics/Font.cpp:133: error: cannot declare variable 'stream' to be of abstract type 'rbInputStream'
ext/InputStream.hpp:31: note:   because the following virtual functions are pure within 'rbInputStream':
include/SFML/System/InputStream.hpp:59: note:   virtual sf::Int64 sf::InputStream::read(char*, sf::Int64)
rake aborted!
Command failed with status (1): [g++  -O3 -fno-omit-frame-pointer -g -Wextr...]

Tasks: TOP => default => all => graphics
(See full trace by running task with --trace)
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 04:46:10 pm
Alright the first problem looked like you were trying to run the tests? I haven't implemented tests for the release candidate yet so don't depend on it to check that it works. If it's tests you have implemented yourself then please send them to me to have a look at.

And the second problem with rbSFML not compiling were probably that you didn't have the latest version of rbSFML and the latest version of SFML. (I think I have forgotten to update the SFML version on the README I'll check it out now).
Just make sure you have the latests of both and it will work ;)

Thank you guys and keep on coming in with these reports. Whenever you create anything in rbSFML I am interested to see it so create a thread here in the ruby forum and tell me about it. It will inspire me to make rbSFML even better!
Title: Re: rbSFML
Post by: Lupinius on April 19, 2012, 05:36:34 pm
First of all: Thank you for the quick answer!
I completely deleted what i had before, redownloaded rbSFML and SFML2 and now it compiles without problems. The "rake test" and "rake samples" both fail to run though, and even the program you posted crashes:
Code: [Select]
sh.exe"-3.1$ ruby test.rb
Failed to create texture, invalid size (0x0)
Failed to create texture, invalid size (0x0)
Trying to access the pixels of an empty image
Failed to create texture, invalid size (0x0)
Trying to access the pixels of an empty image
test.rb:11:in `initialize': Failed to create texture, invalid size (0x0) (SFML::Error)
        from test.rb:11:in `new'
        from test.rb:11:in `<main>'
When I delete the lines causing the crash the program runs but I only get pink squares instead of text and similar errors.
Is it possible that it doesn't work because I've used the Ruby installer to get ruby?

In case it's relevant the outputs of the rake test thingies ("rake samples" show a "program crashed" dialog right before the last line):
Code: [Select]
sh.exe"-3.1$ rake test
Loaded 'sfml/system'
Loaded 'sfml/window'
Loaded 'sfml/graphics'
Loaded 'sfml/audio'
rake aborted!
uninitialized constant SFML::Graphics

Tasks: TOP => test
(See full trace by running task with --trace)
sh.exe"-3.1$ rake samples
c:/Ruby193/bin/ruby.exe sound.rb
canary.wav:
  SFML::Time(0.005756s) seconds
  11025 samples / sec
sound.rb:22:in `play_sound'c:/Ruby193/bin/ruby.exe window.rb
c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- opengl (LoadError)
        from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from window.rb:11:in `<main>'
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 05:41:37 pm
The test and samples rake targets are not updated yet to the release candidate so they won't work. I'll work on the documentation first.

And the test sample I gave here didn't work? I'll look into it and see if I made a bobo somewhere.
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 06:01:51 pm
This is really weird, I haven't changed anything here. This should work. Just to be sure I checked so the SFML examples worked and they do. I have no idea.

I don't get an error response but I do get error results(text works but sprite isn't shown and no error message is written.)
Title: Re: rbSFML
Post by: Lupinius on April 19, 2012, 06:07:25 pm
The error is on my side. I just ported the sample over to C++ and get the same error. So everything is alright with rbSFML, I made a mistake installing SFML somewhere.
Thanks again.
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 06:17:42 pm
Actually the example did have a mistake in it ^^
It's fixed now. It won't fix your problem but you will be confused if you don't have this correction.

I have forgotten to add the texture to the sprite. The example is updated and fixed now.
It also made me find a mistake I had done in the sprite initialize method which has also been fixed.

If you have problems with installing SFML I can help you with that as well but you should post those questions in another forum ^^
Title: Re: rbSFML
Post by: Lupinius on April 19, 2012, 08:02:15 pm
Reredownloaded and rerecompiled SFML and made sure that I replace every SFML dll I have on my machine and got it to work.
Thank you for the binding and your support!

I'll try to use this for the upcoming ludum dare. How well do small scale games in ruby perform? I've heard that ruby's garbage collection and it being a scripting language slows down real-time applications quite a bit, but for smaller projects this shouldn't really be problem, right? (Also, sorry if these questions are too off-topic. I don't really know where else to ask them.)
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 08:23:07 pm
I'll try to use this for the upcoming ludum dare. How well do small scale games in ruby perform? I've heard that ruby's garbage collection and it being a scripting language slows down real-time applications quite a bit, but for smaller projects this shouldn't really be problem, right? (Also, sorry if these questions are too off-topic. I don't really know where else to ask them.)

Awesome I'm looking forward to seeing it!

You can start a new topic about it and I can answer all questions you have about optimizations in Ruby, benchmarks comparing to other languages, strengths of ruby versus other languages and a lot more. Anything you need to make your project work ;)

It will be awesome to see a Ludum Dare project in Ruby.

I can for instance say that I am working on making a Open Worlded RPG in Ruby. Well mostly in ruby. The OpenGL Renderer will be writtin in C++ running on it's own thread with only a small layer between it and Ruby. So most code will still be ruby code. It's currently named Ymir as in the nordic mythological giant which body was used to create the world ;)
Title: Re: rbSFML
Post by: vivo on April 19, 2012, 09:04:32 pm
I've tried your sample and its ok for me too. But later I changed the code as you will see in order to load the texture from a file:

require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'

window = SFML::RenderWindow.new( [ 800, 600 ], "Test" )

text = SFML::Text.new( "Hello World!" )
text.color = [ 255, 0, 255 ]
text.position = [ 10, 10 ]
image = SFML::Image.new( 100, 100, SFML::Color::White )

#this works
texture = SFML::Texture.new("cute_image.jpg")

#this doesn't
#texture = SFML::Texture.new();
#texture.loadFromFile("cute_image.jpg")

sprite = SFML::Sprite.new( texture )
sprite.origin = [ 50, 50 ]
texture.update( image )

while window.open?
  window.clear
  window.draw text
  window.draw sprite
  window.display
 
  sprite.position = SFML::Mouse.position( window )
 
  window.each_event do |event|
    if event.type == SFML::Event::Closed
      window.close
    end
  end
end
 


As you can see I firstly tried with the "loadFromFile" method (following the SFML 2.0 documentation) but It gave me the following error:

vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ruby groogy_sample.rb
groogy_sample.rb:19:in `<main>': undefined method `loadFromFile' for SFML::Sprite(0x969ff30):SFML::Sprite (NoMethodError)
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "X�1   ��&"
      after 119 requests (118 known processed) with 0 events remaining.
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ vi groogy_sample.rb
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ruby groogy_sample.rb
groogy_sample.rb:17:in `<main>': undefined method `loadFromFile' for SFML::Texture(0x0, 0x98cec98):SFML::Texture (NoMethodError)


Then I tried succesfully loading it using its class constructor and it worked, so I guess you made some changes for ruby.
I know you are working on it, but is there any kind of documentation about this changes? or not yet?
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 09:24:07 pm
I'm currently working on the documentation. And this is just a little mistake on my side. I forgot to add the SFML aliases for the texture class. Keep giving me errors like this. There will probably be a lot of them.

A fix is already up for this problem :)
Title: Re: rbSFML
Post by: vivo on April 19, 2012, 09:43:39 pm
Documentation will be great

Ok, then count on me for at least next two mounths, im going to work on rbSFML and i will report almost everything (found) :)

I've noticed that exception errors are not controlled, i will report them too
Title: Re: rbSFML
Post by: Lupinius on April 19, 2012, 09:44:06 pm
Just downloaded that fix. You seem to have a typo ;)
Code: [Select]
sh.exe"-3.1$ ruby main.rb
c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': undefined method `load_from_tream' for class `SFML::Texture' (NameError)
        from c:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from main.rb:1:in `<main>'
Either that or I suck at downloading again.
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 09:47:08 pm
Ok, then count on me for at least next two mounths, im going to work on rbSFML and i will report almost everything (found) :)

Great!

I've noticed that exception errors are not controlled, i will report them too
What do you mean?

And no it wasn't a typo...... It was my keyboard which was too slow.. See it says so in the commitment message so it must be true!
Title: Re: rbSFML
Post by: vivo on April 19, 2012, 10:08:39 pm
With exception error I wanted to mean handling exceptions, for instance, when you try to load music from a file that doesn't exist (same occurs with texture, and probably but not tested Sprites, Images, etc).

when trying:
texture = Texture.new('non_existent.jpg')
 
the konsole output is:
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ruby juego.rb
juego.rb:19:in `initialize': Failed to load image "non_existent.jpg". Reason : Unable to open file (SFML::Error)
        from juego.rb:19:in `
new'
        from juego.rb:19:in `<main>'

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "xU
X&#65533;&#65533;       "

      after 119 requests (118 known processed) with 0 events remaining.
*** glibc detected *** ruby: free(): invalid pointer: 0x0a29d620 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c0c1)[0x3f20c1]
/lib/libc.so.6(+0x6d930)[0x3f3930]
/lib/libc.so.6(cfree+0x6d)[0x3f6a1d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x595441]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x577acd]
/usr/lib/libstdc++.so.6(_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev+0xe8)[0x5701d8]
/lib/libc.so.6(+0x2f69e)[0x3b569e]
/lib/libc.so.6(+0x2f70f)[0x3b570f]
/usr/lib/libX11.so.6(_XDefaultIOError+0xb0)[0x671bb0]
/usr/lib/libX11.so.6(_XIOError+0x56)[0x671c36]
/usr/lib/libX11.so.6(+0x41a8a)[0x679a8a]
/usr/lib/libX11.so.6(_XReply+0x106)[0x67a036]
/usr/lib/libX11.so.6(XQueryExtension+0xa2)[0x6673c2]
/usr/lib/libX11.so.6(XInitExtension+0x3b)[0x65b9bb]
/usr/lib/libXext.so.6(XextAddDisplay+0x4c)[0x76ec5c]
/usr/lib/fglrx/libGL.so.1(AtiCallFGLComposite+0x213)[0x872df9]
======= Memory map: ========
00110000-00338000 r-xp 00000000 07:00 1151702    /usr/local/lib/libruby.so.1.9.1
00338000-00339000 r--p 00227000 07:00 1151702    /usr/local/lib/libruby.so.1.9.1
00339000-0033a000 rw-p 00228000 07:00 1151702    /usr/local/lib/libruby.so.1.9.1
0033a000-00347000 rw-p 00000000 00:00 0
00347000-0034e000 r-xp 00000000 07:00 724171     /lib/librt-2.12.1.so
0034e000-0034f000 r--p 00006000 07:00 724171     /lib/librt-2.12.1.so
0034f000-00350000 rw-p 00007000 07:00 724171     /lib/librt-2.12.1.so
00350000-00352000 r-xp 00000000 07:00 724086     /lib/libdl-2.12.1.so
00352000-00353000 r--p 00001000 07:00 724086     /lib/libdl-2.12.1.so
00353000-00354000 rw-p 00002000 07:00 724086     /lib/libdl-2.12.1.so
00354000-0035d000 r-xp 00000000 07:00 724071     /lib/libcrypt-2.12.1.so
0035d000-0035e000 r--p 00008000 07:00 724071     /lib/libcrypt-2.12.1.so
0035e000-0035f000 rw-p 00009000 07:00 724071     /lib/libcrypt-2.12.1.so
0035f000-00386000 rw-p 00000000 00:00 0
00386000-004dd000 r-xp 00000000 07:00 724508     /lib/libc-2.12.1.so
004dd000-004df000 r--p 00157000 07:00 724508     /lib/libc-2.12.1.so
004df000-004e0000 rw-p 00159000 07:00 724508     /lib/libc-2.12.1.so
004e0000-004e3000 rw-p 00000000 00:00 0
004e3000-004e5000 r-xp 00000000 07:00 1135415    /usr/local/lib/ruby/1.9.1/i686-linux/enc/encdb.so
004e5000-004e6000 r--p 00001000 07:00 1135415    /usr/local/lib/ruby/1.9.1/i686-linux/enc/encdb.so
004e6000-004e7000 rw-p 00002000 07:00 1135415    /usr/local/lib/ruby/1.9.1/i686-linux/enc/encdb.so
004e7000-004e9000 r-xp 00000000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
004e9000-004ea000 r--p 00001000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
004ea000-004eb000 rw-p 00002000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
004eb000-005ca000 r-xp 00000000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
005ca000-005ce000 r--p 000de000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
005ce000-005cf000 rw-p 000e2000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
005cf000-005d6000 rw-p 00000000 00:00 0
005d6000-005dc000 r-xp 00000000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
005dc000-005dd000 r--p 00005000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
005dd000-005de000 rw-p 00006000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
005de000-005df000 r-xp 00000000 07:00 1151037    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/all.so
005df000-005e0000 r--p 00000000 07:00 1151037    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/all.so
005e0000-005e1000 rw-p 00001000 07:00 1151037    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/all.so
005e1000-005fb000 r-xp 00000000 07:00 654160     /lib/libgcc_s.so.1
005fb000-005fc000 r--p 00019000 07:00 654160     /lib/libgcc_s.so.1
005fc000-005fd000 rw-p 0001a000 07:00 654160     /lib/libgcc_s.so.1
005fd000-00606000 r-xp 00000000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00606000-00607000 r--p 00008000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00607000-00608000 rw-p 00009000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00608000-00620000 r-xp 00000000 07:00 1151035    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/window.so
00620000-00621000 r--p 00017000 07:00 1151035    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/window.so
00621000-00622000 rw-p 00018000 07:00 1151035    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/window.so
00622000-00636000 r-xp 00000000 07:00 1135355    /usr/local/lib/libsfml-window.so.2.0
00636000-00637000 r--p 00013000 07:00 1135355    /usr/local/lib/libsfml-window.so.2.0
00637000-00638000 rw-p 00014000 07:00 1135355    /usr/local/lib/libsfml-window.so.2.0
00638000-00751000 r-xp 00000000 07:00 788746     /usr/lib/libX11.so.6.3.0
00751000-00752000 r--p 00118000 07:00 788746     /usr/lib/libX11.so.6.3.0
00752000-00754000 rw-p 00119000 07:00 788746     /usr/lib/libX11.so.6.3.0
00754000-00755000 rw-p 00000000 00:00 0
00755000-0075c000 r-xp 00000000 07:00 785634     /usr/lib/fglrx/libatiuki.so.1.0
0075c000-0075d000 rw-p 00006000 07:00 785634     /usr/lib/fglrx/libatiuki.so.1.0
0075d000-0075f000 r-xp 00000000 07:00 788750     /usr/lib/libXau.so.6.0.0
0075f000-00760000 r--p 00001000 07:00 788750     /usr/lib/libXau.so.6.0.0
00760000-00761000 rw-p 00002000 07:00 788750     /usr/lib/libXau.so.6.0.0
00762000-00770000 r-xp 00000000 07:00 788763     /usr/lib/libXext.so.6.4.0
00770000-00771000 r--p 0000d000 07:00 788763     /usr/lib/libXext.so.6.4.0
00771000-00772000 rw-p 0000e000 07:00 788763     /usr/lib/libXext.so.6.4.0
00772000-0077a000 r-xp 00000000 07:00 788785     /usr/lib/libXrender.so.1.3.0
0077a000-0077b000 r--p 00007000 07:00 788785     /usr/lib/libXrender.so.1.3.0
0077b000-0077c000 rw-p 00008000 07:00 788785     /usr/lib/libXrender.so.1.3.0
0077c000-007b1000 r-xp 00000000 07:00 848703     /usr/lib/libjpeg.so.8.0.2
007b1000-007b2000 r--p 00034000 07:00 848703     /usr/lib/libjpeg.so.8.0.2
007b2000-007b3000 rw-p 00035000 07:00 848703     /usr/lib/libjpeg.so.8.0.2
007b3000-007b6000 r-xp 00000000 07:00 662016     /lib/libuuid.so.1.3.0
007b6000-007b7000 r--p 00002000 07:00 662016     /lib/libuuid.so.1.3.0
007b7000-007b8000 rw-p 00003000 07:00 662016     /lib/libuuid.so.1.3.0
007bb000-007d7000 r-xp 00000000 07:00 724038     /lib/ld-2.12.1.so
007d7000-007d8000 r--p 0001b000 07:00 724038     /lib/ld-2.12.1.so
007d8000-007d9000 rw-p 0001c000 07:00 724038     /lib/ld-2.12.1.so
007d9000-007e0000 r-xp 00000000 07:00 788742     /usr/lib/libSM.so.6.0.1
007e0000-007e1000 r--p 00006000 07:00 788742     /usr/lib/libSM.so.6.0.1
007e1000-007e2000 rw-p 00007000 07:00 788742     /usr/lib/libSM.so.6.0.1
007e2000-007f7000 r-xp 00000000 07:00 788721     /usr/lib/libICE.so.6.3.0
007f7000-007f8000 r--p 00014000 07:00 788721     /usr/lib/libICE.so.6.3.0
007f8000-007f9000 rw-p 00015000 07:00 788721     /usr/lib/libICE.so.6.3.0Abortado
 

As far as my newbie knowledge lets me, I see an SFM::Error message, so it looks controlled. But Ruby crashes (or it seems to me, maybe it's normal, i'm newbie with Ruby, sorry):
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 10:17:47 pm
Hmm no that's not right, can you give me your source? Cause it looks very odd. You should get a SFML::Error but it shouldn't crash like that.

Also what version of Ruby are you using?
Title: Re: rbSFML
Post by: vivo on April 19, 2012, 10:48:03 pm
I've tried to handle the exception and now works properly
sample:
def create_texture_from_file file
        begin
                texture = Texture.new(file)
                return texture
        rescue
                #texture = Texture.new(100,100)
                puts("Error loading texture from file #{file}")
                return false
        end
end

if(!texture = create_texture_from_file('non_exist.jpg'))
        exit!
 

Now the output is simply:
Error loading texture from file non_exist.jpg
 

Do you mean could be a problem with my installation?
I'm using ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Title: Re: rbSFML
Post by: Groogy on April 19, 2012, 10:55:49 pm
Something is up... It works perfectly for me with just throwing the exception though I am on Windows. (Should work exactly the same on Linux as well)

It could be that the X windowing system doesn't like Ruby exceptions. What if you throw an exception manually? Also what graphics card are you sitting on? If it is a integrated intel card then I already know what's wrong ^^

Update: Actually I am thinking about reporting this to the Ruby issue tracker. So can you run the test with ruby -v and give me all information you get from that run.  I also want the machine configuration(Architecture, Graphics card and what Linux you are running on).

Also make sure you have the latest Ruby, latest drivers, latest everything :P
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 12:22:27 am
Throwing by my self an exception
with:
raise "I throw an exception"
 
console:
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ruby juego.rb
juego.rb:32:in `<main>': I throw an exception (RuntimeError)
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "&#65533;&#65533;XG"

My laptop:
intel core i5
ATI Mobility RADEON
Ubuntu 10.10

ruby -v prog.rb:  (almost the same output)
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ruby -v juego.rb
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
juego.rb:38: warning: mismatched indentations at 'end' with 'if' at 36
juego.rb:59: warning: mismatched indentations at 'end' with 'if' at 57
juego.rb:72: warning: mismatched indentations at 'end' with 'if' at 70
juego.rb:73: warning: mismatched indentations at 'end' with 'while' at 68
juego.rb:85: warning: mismatched indentations at 'end' with 'while' at 64
/usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/graphics.so: warning: method redefined; discarding old (null)
juego.rb:30:in `initialize': Failed to load image "inexistent.jpg". Reason : Unable to open file (SFML::Error)
        from juego.rb:30:in `
new'
        from juego.rb:30:in `<main>'

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "&#65533;&#65533;&#65533;        &#65533;&#65533;
"

      after 119 requests (118 known processed) with 0 events remaining.
*** glibc detected *** ruby: free(): invalid pointer: 0x0a168388 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c0c1)[0x3060c1]
/lib/libc.so.6(+0x6d930)[0x307930]
/lib/libc.so.6(cfree+0x6d)[0x30aa1d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x4a1441]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x483acd]
/usr/lib/libstdc++.so.6(_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev+0xe8)[0x47c1d8]
/lib/libc.so.6(+0x2f69e)[0x2c969e]
/lib/libc.so.6(+0x2f70f)[0x2c970f]
/usr/lib/libX11.so.6(_XDefaultIOError+0xb0)[0xac4bb0]
/usr/lib/libX11.so.6(_XIOError+0x56)[0xac4c36]
/usr/lib/libX11.so.6(+0x41a8a)[0xacca8a]
/usr/lib/libX11.so.6(_XReply+0x106)[0xacd036]
/usr/lib/libX11.so.6(XQueryExtension+0xa2)[0xaba3c2]
/usr/lib/libX11.so.6(XInitExtension+0x3b)[0xaae9bb]
/usr/lib/libXext.so.6(XextAddDisplay+0x4c)[0x15bc5c]
/usr/lib/fglrx/libGL.so.1(AtiCallFGLComposite+0x213)[0x20fdf9]
======= Memory map: ========
00110000-00112000 r-xp 00000000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
00112000-00113000 r--p 00001000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
00113000-00114000 rw-p 00002000 07:00 1135417    /usr/local/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
00114000-0012e000 r-xp 00000000 07:00 654160     /lib/libgcc_s.so.1
0012e000-0012f000 r--p 00019000 07:00 654160     /lib/libgcc_s.so.1
0012f000-00130000 rw-p 0001a000 07:00 654160     /lib/libgcc_s.so.1
00130000-0013c000 r-xp 00000000 07:00 1151036    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/system.so
0013c000-0013d000 r--p 0000b000 07:00 1151036    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/system.so
0013d000-0013e000 rw-p 0000c000 07:00 1151036    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/system.so
0013e000-00147000 r-xp 00000000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00147000-00148000 r--p 00008000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00148000-00149000 rw-p 00009000 07:00 1135353    /usr/local/lib/libsfml-system.so.2.0
00149000-0014b000 r-xp 00000000 07:00 788750     /usr/lib/libXau.so.6.0.0
0014b000-0014c000 r--p 00001000 07:00 788750     /usr/lib/libXau.so.6.0.0
0014c000-0014d000 rw-p 00002000 07:00 788750     /usr/lib/libXau.so.6.0.0
0014f000-0015d000 r-xp 00000000 07:00 788763     /usr/lib/libXext.so.6.4.0
0015d000-0015e000 r--p 0000d000 07:00 788763     /usr/lib/libXext.so.6.4.0
0015e000-0015f000 rw-p 0000e000 07:00 788763     /usr/lib/libXext.so.6.4.0
0015f000-00166000 r-xp 00000000 07:00 785634     /usr/lib/fglrx/libatiuki.so.1.0
00166000-00167000 rw-p 00006000 07:00 785634     /usr/lib/fglrx/libatiuki.so.1.0
00167000-0017f000 r-xp 00000000 07:00 789712     /usr/lib/libxcb.so.1.1.0
0017f000-00180000 r--p 00017000 07:00 789712     /usr/lib/libxcb.so.1.1.0
00180000-00181000 rw-p 00018000 07:00 789712     /usr/lib/libxcb.so.1.1.0
00181000-00185000 r-xp 00000000 07:00 788761     /usr/lib/libXdmcp.so.6.0.0
00185000-00186000 r--p 00003000 07:00 788761     /usr/lib/libXdmcp.so.6.0.0
00186000-00187000 rw-p 00004000 07:00 788761     /usr/lib/libXdmcp.so.6.0.0
00187000-0018e000 r-xp 00000000 07:00 788742     /usr/lib/libSM.so.6.0.1
0018e000-0018f000 r--p 00006000 07:00 788742     /usr/lib/libSM.so.6.0.1
0018f000-00190000 rw-p 00007000 07:00 788742     /usr/lib/libSM.so.6.0.1
00190000-00193000 r-xp 00000000 07:00 662016     /lib/libuuid.so.1.3.0
00193000-00194000 r--p 00002000 07:00 662016     /lib/libuuid.so.1.3.0
00194000-00195000 rw-p 00003000 07:00 662016     /lib/libuuid.so.1.3.0
00195000-00197000 r-xp 00000000 07:00 788773     /usr/lib/libXinerama.so.1.0.0
00197000-00198000 r--p 00001000 07:00 788773     /usr/lib/libXinerama.so.1.0.0
00198000-00199000 rw-p 00002000 07:00 788773     /usr/lib/libXinerama.so.1.0.0
00199000-001a0000 r-xp 00000000 07:00 724171     /lib/librt-2.12.1.so
001a0000-001a1000 r--p 00006000 07:00 724171     /lib/librt-2.12.1.so
001a1000-001a2000 rw-p 00007000 07:00 724171     /lib/librt-2.12.1.so
001a2000-00256000 r-xp 00000000 07:00 785638     /usr/lib/fglrx/libGL.so.1.2
00256000-00261000 rwxp 000b3000 07:00 785638     /usr/lib/fglrx/libGL.so.1.2
00261000-00266000 rwxp 00000000 00:00 0
00266000-0026b000 r-xp 00000000 07:00 789433     /usr/lib/libogg.so.0.7.0
0026b000-0026c000 r--p 00004000 07:00 789433     /usr/lib/libogg.so.0.7.0
0026c000-0026d000 rw-p 00005000 07:00 789433     /usr/lib/libogg.so.0.7.0
0026d000-00271000 r-xp 00000000 07:00 788765     /usr/lib/libXfixes.so.3.1.0
00271000-00272000 r--p 00003000 07:00 788765     /usr/lib/libXfixes.so.3.1.0
00272000-00273000 rw-p 00004000 07:00 788765     /usr/lib/libXfixes.so.3.1.0
00274000-00298000 r-xp 00000000 07:00 724364     /lib/libm-2.12.1.so
00298000-00299000 r--p 00023000 07:00 724364     /lib/libm-2.12.1.so
00299000-0029a000 rw-p 00024000 07:00 724364     /lib/libm-2.12.1.so
0029a000-003f1000 r-xp 00000000 07:00 724508     /lib/libc-2.12.1.so
003f1000-003f3000 r--p 00157000 07:00 724508     /lib/libc-2.12.1.so
003f3000-003f4000 rw-p 00159000 07:00 724508     /lib/libc-2.12.1.so
003f4000-003f7000 rw-p 00000000 00:00 0
003f7000-004d6000 r-xp 00000000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
004d6000-004da000 r--p 000de000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
004da000-004db000 rw-p 000e2000 07:00 789602     /usr/lib/libstdc++.so.6.0.14
004db000-004e2000 rw-p 00000000 00:00 0
004e2000-00523000 r-xp 00000000 07:00 1151034    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/graphics.so
00523000-00524000 r--p 00040000 07:00 1151034    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/graphics.so
00524000-00525000 rw-p 00041000 07:00 1151034    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/graphics.so
00525000-00534000 r-xp 00000000 07:00 1151033    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/audio.so
00534000-00535000 r--p 0000e000 07:00 1151033    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/audio.so
00535000-00536000 rw-p 0000f000 07:00 1151033    /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux/sfml/audio.so
00536000-0053c000 r-xp 00000000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
0053c000-0053d000 r--p 00005000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
0053d000-0053e000 rw-p 00006000 07:00 788783     /usr/lib/libXrandr.so.2.2.0
0053e000-005d2000 r-xp 00000000 07:00 1135359    /usr/local/lib/libsfml-graphics.so.2.0
005d2000-005d3000 r--p 00093000 07:00 1135359    /usr/local/lib/libsfml-graphics.so.2.0
005d3000-005d4000 rw-p 00094000 07:00 1135359    /usr/local/lib/libsfml-graphics.so.2.0
005d4000-005e9000 r-xp 00000000 07:00 788721     /usr/lib/libICE.so.6.3.0
005e9000-005ea000 r--p 00014000 07:00 788721     /usr/lib/libICE.so.6.3.0
005ea000-005eb000 rw-p 00015000 07:00 788721     /usr/lib/libICE.so.6.3.0Abortado
 
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 12:28:55 am
Also make sure you have the latest Ruby, latest drivers, latest everything :P
I have the latest Ruby, never updated my graphics card (lazy but I will  :P), my SFML lib is the same that you recommend in your "how to install", and also my rbSFML (the commit version you sugested). May I update rbSFML to your last commit?
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 12:42:29 am
Don't think it will solve it. Though you should.

Anyway I will wait with providing the bug report until you have updated your drivers. Also try this code:
require 'sfml/graphics'
texture = SFML::Texture.new( "someFileThatExist.png" )
raise "Whatever"

It might be that when the exception is raised something breaks if there is OpenGL resources.
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 12:57:23 am
well, i just tried that code and no problem, raises the exception without crashing
groogy_prueba.rb:3:in `<main>': Whatever (RuntimeError)
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 01:07:05 am
As far as I know when you boot a ruby script you start a process, does rbSFML kill the process itself when catching an exception? I mean, uses rbSFML the Kernel.exit or Kernel.abort after (or while) using SFML::Error?
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 02:07:46 am
Nope it doesn't... It does none of the things. It simply calls ruby's built in C function for raising an exception. And this function in turn does a longjmp call to somewhere in Ruby where it handles the exceptions.

Can you test and see what happens in C++? Write a C++ program that attempts to load a texture that doesn't exist and then exit's the application. If nothing happens then try raising a C++ exception and see what happens there. I just want to see if it is specific to Ruby or to SFML.

You can also try turning of exceptions by writing:
SFML.raise_exceptions = false

And looking at the backtrace more closely it actually looks like the crash comes from the X system trying to output an error(which it did) and something failed in there. So check also if the C++ version outputs something from X server. If not I have no idea what's wrong. Does the output come every-time you run a script that includes rbSFML code? Will it come up for every texture you create or just once no matter what? Etc. etc.
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 02:24:06 am
http://en.sfml-dev.org/forums/index.php?topic=3879.msg33533#msg33533

After some quick searching in Google for a solution to the problem I actually got a good link back to SFML here ^^
Seems it is a driver issue and probably upgrading will help you out. If that doesn't fix it I guess you can still work with this as long as your application don't crash :)
Or well until the window is closed. It seems the error is triggered by that.
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 11:29:33 am
Ok, now I have to go, but I will try in a few hours to update my drivers and the C test you sugested
Title: Re: rbSFML
Post by: Lupinius on April 20, 2012, 05:05:20 pm
I've been playing around with rbSFML a bit more and seem to have problems with number types (never thought I'd see that in ruby). When using this test code:
require "sfml/graphics"

foo = SFML::Rect.new(0, 0, 1, 1)
bar = SFML::Rect.new(0.5, 0.5, 1, 1)
puts foo.intersects?(bar)
I get an error:
Code: [Select]
sh.exe"-3.1$ ruby test.rb
test.rb:4:in `initialize': Did not receive expected types ( 'Fixnum', 'Float' ) (TypeError)
        from test.rb:4:in `new'
        from test.rb:4:in `<main>'

What am I doing wrong?
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 06:04:32 pm
from doc:
sf::Rect is a template and may be used with any numeric type, but for simplicity the instanciations used by SFML are typedefed:

    sf::Rect<int> is sf::IntRect
    sf::Rect<float> is sf::FloatRect

make a try with SFML::FloatRect instead of SFML::Rect
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 06:06:02 pm
The thing is that I am kind of mimicking how C++ works with the rect. So either you give Floats or Fixnums to the rect.

I am at a loss at what to do here. As in Ruby nothing is implicitly converted you have to explicitly do it with the #to_* methods. But on the other hand most of the number classes can be used with each other seamlessly.

What do you feel would be most convenient?

And to quickly solve your problem: Rect's don't accept different types in their arguments as of now.
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 06:13:14 pm
http://en.sfml-dev.org/forums/index.php?topic=3879.msg33533#msg33533

After some quick searching in Google for a solution to the problem I actually got a good link back to SFML here ^^
Seems it is a driver issue and probably upgrading will help you out. If that doesn't fix it I guess you can still work with this as long as your application don't crash :)
Or well until the window is closed. It seems the error is triggered by that.
Yes, I have a ATI Mobility Radeon HD serios 5xxx too. So probably is the same problem, my fglrx (ATI debian drivers) are updated, I will try with a better conexion to do an apt-get update for all

One question besides all this, wich editor are you using for rbSFML?
I'm using vim, but I'd like to try another editor with code intelligence (autocompletion, go to definition, etc..)
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 06:16:59 pm
I like Geany but I am currently trying out Redcar which itself is written in Ruby as well. And it seems to be working out pretty well even though it is not in a finished state yet.
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 06:24:13 pm
thanks, I'll try Geany then.

This is the output when I disable raise_exceptions, looks better
Failed to load image "cute_image2.jpg". Reason : Unable to open file
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "&#65533;&#65533;                @n"
      after 6374 requests (6373 known processed) with 0 events remaining.
AL lib: ALc.c:1420: alcDestroyContext(): deleting 1 Source(s)
AL lib: ALc.c:1818: alcCloseDevice(): deleting 3 Buffer(s)
ruby: /build/buildd/openal-soft-1.12.854/OpenAL32/Include/alMain.h:75: EnterCriticalSection: Assertion `ret == 0' failed.
Abortado

Title: Re: rbSFML
Post by: Lupinius on April 20, 2012, 06:29:53 pm
Should it work when I exclusively give floats as arguments? Both these lines give the same error as before:
bar = SFML::Rect.new(0.5, 0.5, 1.to_f, 1.to_f)
bar = SFML::Rect.new(0.5, 0.5, 1.0, 1.0)
I think the type of number shouldn't matter in this case. Usually floats, bignums and fixnums can be used exchangeable, so they should be here as well. I personally think the code I posted looks valid (to me at least) and should therefore work (or, as it's called in the programmer's guide, it should follow the "Principle of Least Surprise". Not being able to use one type of number was a surprise for me). It doesn't feel consistent right now.
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 06:40:05 pm
Alright, I'll fix rect as soon as I get home. And it looks like there is a problem in the audio module. Can I get your code that causes the abortion so I can check if something is wrong on my end.
Title: Re: rbSFML
Post by: vivo on April 20, 2012, 06:55:10 pm
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
# Include the RubySFML extension
#require 'sfml/system'
#require 'sfml/window'
#require 'sfml/audio'
#require 'sfml/graphics'
    Kernel.require( 'sfml/all' )
    Kernel.require( 'logger' )
include SFML

def create_texture_from_file file
        begin
                texture = Texture.new(file)
                return texture
        rescue
                #texture = Texture.new(100,100)
                puts("Error loading texture from file #{file}")
                return false
        end    
end    
SFML.raise_exceptions = false
 #    // Create the main window
#    sf::RenderWindow
        vm = VideoMode.new(800,600,32)
        window = RenderWindow.new(vm, "SFML window")
 
 #    // Load a sprite to display
#     sf::Texture texture;
        texture = Texture.new('cute_image2.jpg')
#if(!texture = create_texture_from_file('cute_image2.jpg'))
#       raise "I throw an exception"
#       #exit!
#end

     if (!texture)
        return SystemExit#success?
end
      sprite = Sprite.new(texture);
#       sprite.setTexture(texture)
 
 #   // Create a graphical text to display
#     sf::Font font;
        font = Font.new()
#     if(!font.loadFromFile("arial.ttf"))
font = Font::getDefaultFont()    
   #return EXIT_FAILURE;
   
#       end
 text = Text.new("Hello SFML");
text.setFont(font)
text.setCharacterSize(50);
 
 #   // Load a music to play
#     sf::Music music;
        music = Music.new
     if (!music.openFromFile("nice_music.ogg"))
         return EXIT_FAILURE;
        end
 #   // Play the music
     music.play();
 
 #   // Start the game loop
     while (window.isOpen())
 #       // Process events
         #sf::Event event;
        event = Event.new()
         while (window.pollEvent(event))
 #           // Close window : exit
             if (event.type == Event::Closed)
                 window.close();
                end
        end
 #       // Clear screen
         window.clear();
 
 #       // Draw the sprite
        window.draw(sprite);
 
 #       // Draw the string
         window.draw(text);
 
 #       // Update the window
         window.display();
        end
     return EXIT_SUCCESS;
 
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 09:10:34 pm
Alright up and running with Rect and I don't really know what's causing your problem with OpenAL. Seems like Linux like playing around with my stuff... Have you tested a C++ application and see what happens yet? Remember to link against sfml-audio as well.
Title: Re: rbSFML
Post by: Lupinius on April 20, 2012, 10:19:19 pm
I tried out the audio package as well, and found another mystifying thing: When calling a non existent method on a SFML::Music object the program crashes. Not just a simple "undefined method" error, but a full "Ruby interpreter has stopped working" error message. No other classes seem to have this behavior. Playing music seems to work fine for me though (when using the right method).
Title: Re: rbSFML
Post by: Groogy on April 20, 2012, 10:39:03 pm
That is strange indeed and shouldn't be possible. I'll have a look at it.
Title: Re: rbSFML
Post by: Lupinius on April 21, 2012, 11:51:07 am
It appears to be impossible to create a new render state. Or am I doing something wrong?
Code: [Select]
irb(main):009:0> state = SFML::RenderStates.new
RuntimeError: can't modify frozen SFML::Transform

Edit: Also, the PrimitiveTypes for drawing vertices don't appear to make sense. They contain 0, 1, 2, true, false, nil and SFML::Quads isn't initialized.
Code: [Select]
irb(main):014:0> puts SFML::Lines
0
=> nil
irb(main):015:0> puts SFML::Points
false
=> nil
irb(main):016:0> puts SFML::LinesStrip
true
=> nil
irb(main):017:0> puts SFML::Triangles
1
=> nil
irb(main):018:0> puts SFML::TrianglesStrip

=> nil
irb(main):019:0> puts SFML::TrianglesFan
2
=> nil
irb(main):020:0> puts SFML::Quads
NameError: uninitialized constant SFML::Quads
        from (irb):20
        from C:/Ruby193/bin/irb:12:in `<main>'
Title: Re: rbSFML
Post by: vivo on April 21, 2012, 01:46:05 pm
well, heres is the output for a test.cpp and linking with audio and graphics

Any error, besides the expected "could'nt find the file"

gcc graph.o -o test -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
vivo@ubuntu:~/Escritorio/proyectoAG/primer_juego$ ./test
Failed to load image "cute_image". Reason : Unable to open file
 

This takes me to thing that the problem comes for an unhandled exception in ruby (maybe in windows doesn't mather this, but x-konsole shows the error). If you remember, when I handled the exception the program didn't crash.

    Kernel.require( 'sfml/all' )
include SFML

def create_texture_from_file file
        begin
                texture = Texture.new(file)
                return texture
        rescue
                #texture = Texture.new(100,100)
                puts("Error loading texture from file #{file}")
                return false
        end
end

if(!texture = create_texture_from_file('cute_image2.jpg'))
#       raise "I throw an exception"
#        return -1
Kernel.exit!
end
 


if I uncomment raise line-> crashes
if I uncomment return line-> crashes
if I uncomment exit line-> exit is: Error loading texture from file

The return line in mi mind represents whats happening now at now, letting the c++ SFML behabior for handle the exception, probably returning some value
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 05:12:11 pm
Alright fixed the bug with BlendModes, PrimitiveTypes and RenderStates. Most of these bugs have been simple mistakes which comes from that I had to write a lot of code under little time ^^

Anyway the Linux problem I am kind of lost at. Did you try to mimic the ruby code in C++? Keep in mind that everything in Ruby is allocated on the heap so you have to use the new keyword. And check what happens if you ignore deleting and what if you delete. Can you also try and find out when in the application the error messages are put out? Like during the application runs or when it exists? Can you try and invoke the garbage collector while running and see what happens then?

The only thing I can find that is causing this is that I somehow isn't handling the Ruby memory correctly or something. Since I am using SFML code in the code so it has to be something there in-between.

I created a new branch called "linux_fix" which doesn't use Ruby's heap to allocate objects. See if this works better for you.
Title: Re: rbSFML
Post by: vivo on April 21, 2012, 05:45:31 pm
Anyway the Linux problem I am kind of lost at. Did you try to mimic the ruby code in C++? Keep in mind that everything in Ruby is allocated on the heap so you have to use the new keyword.
I don't understand what you want to mean with mimic the ruby code, sorry

I created a new branch called "linux_fix" which doesn't use Ruby's heap to allocate objects. See if this works better for you.
Thanks, I'll check it in advance
For the moment, as far as the problem only occurs with exceptions, I can keep working

Title: Re: rbSFML
Post by: vivo on April 21, 2012, 05:59:22 pm
More reports:

No method Texture.loadFromImage (like loadFromFile)

I guess alias is not implemented yet


[attachment deleted by admin]
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 06:01:42 pm
I ment that you should copy the code in ruby as C++ completely. So they do the same thing. One of the things is that everything in Ruby is allocated dynamically so just putting it on the stack is not enough.

And Texture#loadFromImage does exist. I just checked it. Sure you didn't misspell?
Title: Re: rbSFML
Post by: Lupinius on April 21, 2012, 06:27:45 pm
Thank you once again for your support and the binding. Ludum dare has so far been been a joy to code, regardless of the currently missing documentation. I'll show something once I have the first "complete" version.

I'm still having problems using vertices though. This is my test code:
require "sfml/graphics"

app = SFML::RenderWindow.new [800, 600], "Vertices Test"

vertices = Array.new(2) { SFML::Vertex.new }
vertices[0].position = [0, 0]
vertices[1].position = [1, 1]

state = SFML::RenderStates.new

app.draw vertices, 4, SFML::Lines, state # Variant 1
app.draw vertices, SFML::Lines, state # Variant 2
Variant 1 doesn't work because 1..3 parameters are expected. Looking at the source code, it appears that the vertex count the array provides is used. So I was guessing variant 2 would work, it leads to a segmentation fault tough. How do I use it correctly?

Also, another request: Also make Vector2 and Vector3 different number types.
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 06:53:16 pm
The vector fix is done and I am locking into why the vertexes crashes.

When it comes to raw memory the API either uses an array or a string to handle it and you never have to give explicitly the size of the memory as Ruby knows it ;)
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 06:55:55 pm
Render target crash is now up and fixed as well. The problem was that I thought of it just like in C++ ^^ Like how you did from the beginning so I retrieved the length from argument 0 and the pointer from argument 1 which is VERY wrong.

I am interested in showing up rbSFML so other users see it. Would you mind having a rbSFML logo on your ludum dare project? =)
Title: Re: rbSFML
Post by: vivo on April 21, 2012, 07:01:26 pm
I ment that you should copy the code in ruby as C++ completely. So they do the same thing. One of the things is that everything in Ruby is allocated dynamically so just putting it on the stack is not enough.
Yes, i copied (translated) the code contemplating the same instructions

And Texture#loadFromImage does exist. I just checked it. Sure you didn't misspell?
Sure :S
I haven't updated my rbSFML copy. I have the one you suggested in your installation tutorial. Could it be the reason?
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 07:08:36 pm
Download the latest one from Github, and if this still doesn't work then something is wrong on my side... Ow yeah you aren't trying to use the loadFrom methods as class methods? I can add them as that as well as it makes sense. Though it would be more like newFromImage/new_from_image or something like that.

And how did it go with the linux fix branch? Did it make any difference?
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 07:11:53 pm
And for drawing vertices manually. That's pretty slow just so you know. I have to manually allocate memory equally big and convert the ruby objects to SFML objects for each draw call. Use the vertex array class that comes with SFML if you can. It will be much more efficient as no Ruby -> SFML conversion will have to be done.

Stuff like this will be covered in the documentation.
Title: Re: rbSFML
Post by: vivo on April 21, 2012, 07:18:26 pm
Download the latest one from Github, and if this still doesn't work then something is wrong on my side... Ow yeah you aren't trying to use the loadFrom methods as class methods? I can add them as that as well as it makes sense. Though it would be more like newFromImage/new_from_image or something like that.
Not really as a class method, I was invoking as an instance method. The code I posted was just for letting you know from wich class was I invoking, sorry for the missunderstanding.
I do:
tex = Texture.new
tex.loadFromFile("file.jpg")
 
And how did it go with the linux fix branch? Did it make any difference?
[/quote]
Don't know yet :P, i'll try tomorrow (Barça-Madrid is waiting for me)
Title: Re: rbSFML
Post by: Lupinius on April 21, 2012, 07:53:07 pm
I am interested in showing up rbSFML so other users see it. Would you mind having a rbSFML logo on your ludum dare project? =)
I'd love to! Where can I find one? I remember there being some in the "A new logo for SFML" thread (like this one (http://img9.uploadhouse.com/fileuploads/11379/1137918274bf18acff14d4c726ae5efd9d5648ae.png)).

I am having a problem compiling the latest version though:
Code: [Select]
Compiling ext/Graphics/RenderTarget.cpp
ext/Graphics/RenderTarget.cpp: In function 'VALUE rbRenderTarget::Draw(int, VALUE*, VALUE)':
ext/Graphics/RenderTarget.cpp:288: error: invalid conversion from 'void*' to 'sf::Vertex*'
rake aborted!
Command failed with status (1): [g++  -O3 -fno-omit-frame-pointer -g -Wextr...]

And i can't find a VertexArray class in rbSFML:
Code: [Select]
irb(main):015:0> puts SFML.constants.sort
BINDING_VERSION
BlendAdd
[...]
Vector2
Vector3
Vertex
VideoMode
View
Window

Speed shouldn't matter that much in this case though, I just need vertices so I can stretch my images over distorted rectangles.
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 08:23:43 pm
Alright fixed both. The vertex array thing was because I forgot to call the initiate function for the class xD

And you can use that logo yes :D
I don't know if SFML has switched logo yet but I might change later.
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 08:42:51 pm
I put up a blog post with the logo so there is one central way to always find it and download it. It will be up 24/7.

http://groogy.se/mainsite/2012/04/21/rbsfml-logo/
Title: Re: rbSFML
Post by: Lupinius on April 21, 2012, 10:05:48 pm
There are still problems. This code paints "img.png" to the screen:
#include <SFML/Graphics.hpp>

int main() {
        sf::RenderWindow app(sf::VideoMode(800, 600), "Vertices Test");
       
        sf::Texture tex;
        tex.loadFromFile("img.png");
       
        while (true) {
                sf::Vertex vertices[4];
               
                vertices[0].position = sf::Vector2f(0, 0);
                vertices[0].texCoords = sf::Vector2f(0, 0);
                vertices[1].position = sf::Vector2f(0, 100);
                vertices[1].texCoords = sf::Vector2f(0, 256);
                vertices[2].position = sf::Vector2f(100, 100);
                vertices[2].texCoords = sf::Vector2f(256, 256);
                vertices[3].position = sf::Vector2f(100, 0);
                vertices[3].texCoords = sf::Vector2f(256, 0);
               
                sf::RenderStates state;
                state.texture = &tex;
               
                app.clear();
                app.draw(vertices, 4, sf::Quads, state);
                app.display();
        }
}
The same in ruby draws a white rectangle:
require "sfml/graphics"

app = SFML::RenderWindow.new([800, 600], "Vertices Test")
       
tex = SFML::Texture.new
tex.loadFromFile("img.png")

while true
        vertices = Array.new(4) { SFML::Vertex.new }
       
        vertices[0].position = [0, 0]
        vertices[0].tex_coords = [0, 0]
        vertices[1].position = [0, 100]
        vertices[1].tex_coords = [0, 256]
        vertices[2].position = [100, 100]
        vertices[2].tex_coords = [256, 256]
        vertices[3].position = [100, 0]
        vertices[3].tex_coords = [256, 0]
       
        state = SFML::RenderStates.new
        state.texture = tex
       
        app.clear()
        app.draw(vertices, SFML::Quads, state)
        app.display()
end
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 10:24:07 pm
I am having a hard time finding what would be the source of the problem and I am not at a computer right now where I can test this. But I think... just think that there might be a problem with the vector. Can you try giving it float values instead? I think it might be a problem that the Ruby C API can't convert any kind of Numeric to C float/double and thus give me a weird number or even 0. The macro I use is NUM2DBL which should take any numeric and give me a double but documentation here is pretty limited. Though it doesn't say that it includes a type check so it might not even do that and just do a raw conversion.

If it still doesn't work try doing it manually with SFML::Vector2.new instead of array's just to be certain. I will fix this so that there is a better conversion layer between Ruby and SFML but that means conversions will be slower but I will stay with the principle of least surprise at least. Besides the interpreter will stand for most of the time anyway so think it's okay.

also attemt with doing the state as an array. [ tex ]

And to verify that the texture is still valid create a sprite which draws it on a position elsewhere on the window. This is just to find where the error is located. If it's in texture or if it's render states.
Title: Re: rbSFML
Post by: Lupinius on April 21, 2012, 10:54:58 pm
Changing to floats or using vectors directly did not work. However, adding "sleep 1" or even some lower amount (down to ~0.05) to the end of the loop displays the graphic. Same thing seems to happen when the first few frames take a bit to show up.

I'm not sure what you mean with "doing the state as an array.". Trying to replace
app.draw(vertices, SFML::Quads, state)
with
app.draw(vertices, SFML::Quads, [tex])
does not work due to an conversion error.

Sprite seem to show the same behavior (not having a texture) in this example. They also seem to lose size information and get thin. However in my game sprites worked fine, the texture seemed to be.

Everything works when I declare the RenderState before the loop and only assign the texture once. The texture seems to be damaged when it is attached to a RenderState often.
Title: Re: rbSFML
Post by: Groogy on April 21, 2012, 11:15:47 pm
I think I know what the problem is now. I've done the garbage collection wrong so the texture get's garbage collected while it is still in use. I will put up a quick fix trough the github editor now.

Though problem will now be that it does not mimic C++ now.
state.texture->functionThatModifies(); // <- Doesn't work
state.texture.function_that_modifies() # <- Does work now
Title: Re: rbSFML
Post by: vivo on April 22, 2012, 01:06:01 pm
great!
I've updated rbSFML with git pull and loadFromFile works :)

How do i get the fix branch?
Title: Re: rbSFML
Post by: Groogy on April 22, 2012, 01:19:00 pm
You do this:
Code: [Select]
git checkout -b linux_fix
git pull <remote_name> linux_fix
And just replace <remote_name> with whatever you named it.
Title: Re: rbSFML
Post by: vivo on April 22, 2012, 08:10:38 pm
Now i've already got the fix branch version,
I still got the same errors
 -when closing a window:
SFML::Texture(800x600, 0x9ebc810)
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ""
      after 1812 requests (1811 known processed) with 0 events remaining.
AL lib: ALc.c:1420: alcDestroyContext(): deleting 1 Source(s)
AL lib: ALc.c:1818: alcCloseDevice(): deleting 3 Buffer(s)
ruby: /build/buildd/openal-soft-1.12.854/OpenAL32/Include/alMain.h:107: DeleteCriticalSection: Assertion `ret == 0' failed.
Abortado

 -When loading an non-existing file

Will I be updated in this branch or shall I switch to the main one
Title: Re: rbSFML
Post by: Groogy on April 22, 2012, 09:29:19 pm
Switch to the main one. Don't think I'll be able to fix it. As I have no idea where this comes from.
Title: Re: rbSFML
Post by: Ceylo on April 23, 2012, 02:40:17 pm
Hello,

I'm totally new to Ruby but I wanted to test the game at http://en.sfml-dev.org/forums/index.php?topic=7673.msg50939;topicseen#new on Mac OS X.

So I downloaded rbSFML, tested what was already installed. Both Ruby and Rake were already there. Then I typed "sudo gem install yard" and downloaded rbSFML.

I didn't install the latest version of Ruby as there is already one installed, plus I couldn't build Ruby from the latest sources because of an unknown linking flag (and I couldn't find where it's defined).

So with my current version of Ruby, here is what I get :
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake --version
rake, version 0.8.7
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake
(in /Users/ceylo/Desktop/rbSFML)
rake aborted!
/Users/ceylo/Desktop/rbSFML/Rakefile:260: syntax error, unexpected ':', expecting ')'
    ruby("#{sample}", verbose: true) { }
                              ^

(See full trace by running task with --trace)

Do you know why I get this error message?
I admit I'm a bit lazy to search among the 14 pages of this topic, and a search didn't give anything.
Thanks,

Ceylo
Title: Re: rbSFML
Post by: vivo on April 23, 2012, 03:53:30 pm
Hi, you need the last version of ruby
Title: Re: rbSFML
Post by: Groogy on April 23, 2012, 03:57:18 pm
You have version 1.8.x while I have based the bindings on 1.9.x which have changes to the actual syntax.
So you will need to upgrade to a newer version of Linux ^^
Title: Re: rbSFML
Post by: Ceylo on April 23, 2012, 06:14:01 pm
Hmm ok, so I suppose I'll have to install Fink in order to get up-to-date binaries.

Thanks!


Edit: actually Fink just provides Ruby 1.8.7 too ...
Edit 2: but MacPort provides Ruby 1.9 :D
Title: Re: rbSFML
Post by: Ceylo on April 23, 2012, 07:45:48 pm
I finally got Ruby 1.9 installed thanks to MacPort.
Now I get this:

Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake
Compiling ext/System/Clock.cpp
In file included from ext/System/Clock.cpp:24:
In file included from ext/System/Clock.hpp:26:
ext/rbSFML.hpp:54:16: error: call to function 'ToRuby' that is neither visible in the template definition nor found by argument-dependent lookup
        return ToRuby( object, aKlass );
               ^
ext/System/Clock.cpp:32:43: note: in instantiation of function template specialization 'rbMacros::Allocate<sf::Clock>' requested here
    rb_define_alloc_func( rbClock::Class, rbMacros::Allocate< sf::Clock > );
                                          ^
ext/rbSFML.hpp:78:25: note: 'ToRuby' should be declared prior to the call site or in namespace 'sf'
    static inline VALUE ToRuby( T* anObject, VALUE aKlass )
                        ^
1 error generated.
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -pipe -O2 -Iinclude -Iext...]

Tasks: TOP => default => all => system
(See full trace by running task with --trace)
Title: Re: rbSFML
Post by: Groogy on April 23, 2012, 07:56:16 pm
What compiler are you using? Haven't tried for Mac so we'll have to see if we can solve this. So far it looks like your compiler doesn't like my template definitions. Can you have a look in rbSFML. hpp and just check what would be valid on your compiler?

There will probably come up more problems. Just so you are ready for it.
Title: Re: rbSFML
Post by: Laurent on April 23, 2012, 08:17:34 pm
If I were you, I'd do what the compiler says ;)
Quote
'ToRuby' should be declared prior to the call site
Title: Re: rbSFML
Post by: Groogy on April 23, 2012, 08:28:29 pm
The thing is that the template function has been declared prior to the call site. So I have no idea what his compiler is complaining about. I'll look at it when I get home of course.
Title: Re: rbSFML
Post by: Laurent on April 23, 2012, 08:32:15 pm
Where? I can only see it below, at line 78.
Title: Re: rbSFML
Post by: Ceylo on April 23, 2012, 08:37:19 pm
What compiler are you using?
According to the error message: Clang. I don't know how to tell Rake to use GCC though.

Haven't tried for Mac so we'll have to see if we can solve this. So far it looks like your compiler doesn't like my template definitions. Can you have a look in rbSFML. hpp and just check what would be valid on your compiler?
What am I supposed to find ? There is no #ifdef except for the inclusion guard.
Title: Re: rbSFML
Post by: Groogy on April 23, 2012, 09:05:59 pm
Can you test doing a prototype declaration? Because to me it looks like it is calling the definition of the function as a calling point? I don't get it. My network card is messing with me. So is writing from my tablet.

And if you want GCC then change manually the variable CXX and LINK. Though currently these are retrived from ruby. So if ruby says Clang lets first try that.
Title: Re: rbSFML
Post by: Groogy on April 23, 2012, 09:37:12 pm
Never mind I got network working and did it myself, just update and see what it says.
Title: Re: rbSFML
Post by: Ceylo on April 23, 2012, 11:19:30 pm
Yay it went a bit further this time :D

Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] git pull
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 4 (delta 3), reused 4 (delta 3)
Unpacking objects: 100% (4/4), done.
From github.com:Groogy/rbSFML
   3c07a96..7a14d93  master     -> origin/master
Updating 3c07a96..7a14d93
Fast-forward
 ext/rbSFML.hpp |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake
Compiling ext/System/Clock.cpp
Compiling ext/System/main.cpp
Compiling ext/System/NonCopyable.cpp
Compiling ext/System/SFML.cpp
Compiling ext/System/Time.cpp
Compiling ext/System/Vector2.cpp
Compiling ext/System/Vector3.cpp
ext/System/Vector3.cpp:191:7: warning: data argument not used by format string
      [-Wformat-extra-args]
                                                StringValueCStr( z ) );
                                                ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:468:28: note: expanded from macro
      'StringValueCStr'
#define StringValueCStr(v) rb_string_value_cstr(&(v))
                           ^
1 warning generated.
Compiling ext/InputStream.cpp
Creating sfml/system.so
Compiling ext/Window/Context.cpp
Compiling ext/Window/ContextSettings.cpp
Compiling ext/Window/Event.cpp
Compiling ext/Window/Joystick.cpp
Compiling ext/Window/Keyboard.cpp
Compiling ext/Window/main.cpp
Compiling ext/Window/Mouse.cpp
Compiling ext/Window/Style.cpp
Compiling ext/Window/VideoMode.cpp
Compiling ext/Window/Window.cpp
ext/Window/Window.cpp:392:64: warning: conversion specifies type 'int' but the argument has type
      'size_t' (aka 'unsigned long') [-Wformat]
        rb_raise( rb_eTypeError, "expected array lenght to be %d", size );
                                                              ~^   ~~~~
                                                              %lu
ext/Window/Window.cpp:472:22: error: cast from pointer to smaller type 'unsigned int' loses
      information
  ...UINT2NUM( (unsigned int)rbMacros::ToSFML< sf::Window >( aSelf, rbWindow::Class )->getSystemHandle() )...
     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/ruby-1.9.1/ruby/ruby.h:974:46: note: expanded from macro 'UINT2NUM'
# define UINT2NUM(v) LONG2FIX((unsigned int)(v))
                                             ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:226:29: note: expanded from macro 'LONG2FIX'
#define LONG2FIX(i) INT2FIX(i)
                            ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
1 warning and 1 error generated.
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -pipe -O2 -Iinclude -Iext...]

Tasks: TOP => default => all => window
(See full trace by running task with --trace)

Edit: note that I'm using OS X in 64 bits.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 06:11:35 am
Alright commited more fixes, some warning fixes and the error that you got. Run again and see what else fails.

Also when you have learned Ruby I recommend this guy: https://www.destroyallsoftware.com/screencasts
He's a Mac programmer who is really good at what he does and he teaches various programming paradigms in Ruby. Though he uses Ruby on Rails which is for the web you can still extract the key elements from his screencasts and apply it to rbSFML. At least I am doing it for Ymir.

This one is quite funny, for free and shows what you can expect from him:
https://www.destroyallsoftware.com/talks/wat

That video also shows the power of Ruby ;)
But mostly it shows design flaws in most dynamic languages today.
Title: Re: rbSFML
Post by: Laurent on April 24, 2012, 08:13:28 am
By the way, why are all the functions in rbSFML.hpp static? They'll be duplicated in every .cpp where this header is included. The static keyword should only be used in .cpp files.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 08:43:32 am
By the way, why are all the functions in rbSFML.hpp static? They'll be duplicated in every .cpp where this header is included. The static keyword should only be used in .cpp files.

Well I didn't write the original code I just went with what was already written and added to that. Anyway the code in rbSFML is simple macros more or less. The code inside is so small that I want it to be inlined which means it would be copied anyway. Though functions like Allocate and Free shouldn't be since I use pointers to these functions.

Or well I should take some of the blame. I more or less did an "extract method" refactoring on a lot of code that existed all over the code base. So instead of just then going with the flow I should have done more refactoring here.

Note: Ops I accidentally pressed modify instead of quote ^^
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 10:28:52 am
Still the error at the same line in Window.cpp :/

Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] git pull
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 25 (delta 20), reused 21 (delta 16)
Unpacking objects: 100% (25/25), done.
From github.com:Groogy/rbSFML
   7a14d93..f92b774  master     -> origin/master
Updating 7a14d93..f92b774
Fast-forward
 ext/System/Vector3.cpp |    2 +-
 ext/Window/Window.cpp  |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake
Compiling ext/System/Vector3.cpp
Creating sfml/system.so
Compiling ext/Window/Window.cpp
ext/Window/Window.cpp:392:64: warning: conversion specifies type 'unsigned int'
      but the argument has type 'unsigned long' [-Wformat]
        rb_raise( rb_eTypeError, "expected array lenght to be %ul", size );
                                                              ~^    ~~~~
                                                              %lu
ext/Window/Window.cpp:472:22: error: cast from pointer to smaller type
      'unsigned int' loses information
  ...UINT2NUM( reinterpret_cast< unsigned int >( rbMacros::ToSFML< sf::Window >( aSelf, rbWindow::Class )->getSystemHandle() ) )...
     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/ruby-1.9.1/ruby/ruby.h:974:46: note: expanded from macro
      'UINT2NUM'
# define UINT2NUM(v) LONG2FIX((unsigned int)(v))
                                             ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:226:29: note: expanded from macro
      'LONG2FIX'
#define LONG2FIX(i) INT2FIX(i)
                            ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro
      'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
1 warning and 1 error generated.
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -pipe -O2 -Iinclude -Iext...]

Tasks: TOP => default => all => window
(See full trace by running task with --trace)

Edit: for who did you write this ?
Quote
Also when you have learned Ruby I recommend this guy: https://www.destroyallsoftware.com/screencasts
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 11:29:13 am
Code: [Select]
...
Compiling ext/Window/Window.cpp
ext/Window/Window.cpp:392:64: warning: conversion specifies type 'unsigned int'
      but the argument has type 'unsigned long' [-Wformat]
        rb_raise( rb_eTypeError, "expected array lenght to be %ul", size );
                                                              ~^    ~~~~
                                                              %lu
ext/Window/Window.cpp:472:22: error: cast from pointer to smaller type
      'unsigned int' loses information
  ...UINT2NUM( reinterpret_cast< unsigned int >( rbMacros::ToSFML< sf::Window >( aSelf, rbWindow::Class )->getSystemHandle() ) )...
     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/ruby-1.9.1/ruby/ruby.h:974:46: note: expanded from macro
      'UINT2NUM'
# define UINT2NUM(v) LONG2FIX((unsigned int)(v))
                                             ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:226:29: note: expanded from macro
      'LONG2FIX'
#define LONG2FIX(i) INT2FIX(i)
                            ^
/opt/local/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro
      'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^

Erhm... looks like it is the.. eer... Ruby macro that is causing the problem? I've tried another conversion in hope that it works.

Edit: for who did you write this ?
Quote
Also when you have learned Ruby I recommend this guy: https://www.destroyallsoftware.com/screencasts

For you and everyone else that might read this.
Title: Re: rbSFML
Post by: Laurent on April 24, 2012, 11:39:08 am
Quote
Erhm... looks like it is the.. eer... Ruby macro that is causing the problem? I've tried another conversion in hope that it works.
This code is too dangerous, you have to fix it. Basically, you reinterpret_cast to unsigned int a type that you know nothing about -- and might no be the same size. sf::Window::getSystemHandle() usually returns a long or a pointer, so there's a chance that its size is 8 bytes on 64-bits architectures, whereas unsigned int will most likely be stuck at 4 bytes.
A correct code would:
- static_cast<unsigned int>(reinterpret_cast<uintptr_t>(handle)) for pointers
- static_cast<unsigned int>(handle) for numeric types
You can use overloads and templates to handle both cases without having to worry about the type returned by getSystemHandle().
By the way, uintptr_t is not standard, but it is the only numeric type which can safely replace a pointer type :-\
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 12:07:35 pm
Well I changed it into unsigned long instead. The problem is that Ruby has nothing that support this kind of thing. It's just a function hat LBg added a long time ago. In my original version I didn't have this as I didn't see a use for it. Though if you want to use rbSFML with a GUI toolkit I guess you need it.

More or less I changed to: return ULONG2NUM( reinterpret_cast< unsigned long >( rbMacros::ToSFML< sf::Window >( aSelf, rbWindow::Class )->getSystemHandle() ) );
Title: Re: rbSFML
Post by: Laurent on April 24, 2012, 12:16:49 pm
This is still unsafe. It might work without warning or error, but one day it might blow up in somebody's face.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 12:26:07 pm
Well in order to do it properly I'll have to create an entire class to wrap around it probably. Because Ruby has only Fixnum(4 bytes) and Bignum(n* bytes).

With your cast we will still be casting down to 4 bytes in the end right? So even if I do add template to handle both cases it will still be wrong in the ruby code right?

Also looking quickly at how GUI libraries wants it: http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AWindow#Gdk%3A%3AWindow.foreign_new
http://wxruby.rubyforge.org/doc/window.html#Window_new

It expects an integer which would be a Fixnum. Don't know about a Bignum as it's an object and can't be treated as a fixnum so I wouldn't bet on it.
Title: Re: rbSFML
Post by: Laurent on April 24, 2012, 12:41:39 pm
It doesn't require a class, only a few macros and overloads so that, according to sizeof(void*) and what sf::WindowHandle is, the correct cast is made and the correct Ruby type is produced (Fixnum or Bignum).

Something like that:
VALUE HANDLE2NUM(void* handle)
{
#if sizeof(void*) == sizeof(unsigned long)
    return ULONG2NUM(reinterpret_cast<unsigned long>(handle));
#elif sizeof(void*) == sizeof(unsigned long long)
    return ULL2NUM(reinterpret_cast<unsigned long long>(handle));
#else
    return UINT2NUM(reinterpret_cast<unsigned int>(handle));
}

VALUE HANDLE2NUM(unsigned long handle)
{
    return ULONG2NUM(handle);
}
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 01:05:18 pm
These will all produce Fixnums that are 4 bytes big ^^

As I said Bignum is a separate object that is created by ruby code and not the native interface. You can't for instance inspect a Bignum value easily in the native interface.

But that code looks a lot better than what I currently got, I'll change mine when I got time to that instead.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 01:49:47 pm
Mostly for curiosity but here is what I get for the different sizes of C types :
Code: [Select]
[ ceylo ceylo-pc ~/Desktop ] ./32b
      sizeof short : 2 bytes
        sizeof int : 4 bytes
       sizeof long : 4 bytes
  sizeof long long : 8 bytes
      sizeof float : 4 bytes
     sizeof double : 8 bytes
sizeof long double : 16 bytes
      sizeof void* : 4 bytes
[ ceylo ceylo-pc ~/Desktop ] ./64b
      sizeof short : 2 bytes
        sizeof int : 4 bytes
       sizeof long : 8 bytes
  sizeof long long : 8 bytes
      sizeof float : 4 bytes
     sizeof double : 8 bytes
sizeof long double : 16 bytes
      sizeof void* : 8 bytes

where 32b is a 32 bits binary and 64b a 64 bits one.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 02:00:06 pm
Did the latest version work for you?
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 02:08:46 pm
It went much further :)

Code: [Select]
Compiling ext/Audio/Music.cpp
ext/Audio/Music.cpp:117:23: error: cannot pass object of non-POD type 'sf::Time' through variadic function; call will abort at runtime
      [-Wnon-pod-varargs]
                      rbMacros::ToSFML< sf::Music >( aSelf, rbMusic::Class )->getDuration() );
                      ^
ext/Audio/Music.cpp:114:33: warning: conversion specifies type 'double' but the argument has type 'sf::Time' [-Wformat]
    return rb_sprintf( "%s(%p: %fs)",
                               ~^
1 warning and 1 error generated.
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -pipe -O2 -Iinclude -Iext...]

Tasks: TOP => default => all => audio
(See full trace by running task with --trace)
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 02:17:02 pm
I'm starting to like your compiler.. It's finding errors I've missed ^^

Alright let's try it out now.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 02:22:09 pm
Code: [Select]
Compiling ext/Audio/SoundBuffer.cpp
ext/Audio/SoundBuffer.cpp:182:61: warning: conversion specifies type 'int' but the argument has type 'std::size_t' (aka 'unsigned long')
      [-Wformat]
        rb_raise( rb_eArgError, "expected array size to be %d", sampleCount );
                                                           ~^   ~~~~~~~~~~~
                                                           %lu
ext/Audio/SoundBuffer.cpp:288:23: error: cannot pass object of non-POD type 'sf::Time' through variadic function; call will abort at
      runtime [-Wnon-pod-varargs]
                      rbMacros::ToSFML< sf::SoundBuffer >( aSelf, rbSoundBuffer::Class )->getDuration() );
                      ^
ext/Audio/SoundBuffer.cpp:285:32: warning: conversion specifies type 'int' but the argument has type 'sf::Time' [-Wformat]
    return rb_sprintf("%s(%p: %ims)",
                              ~^
2 warnings and 1 error generated.
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -pipe -O2 -Iinclude -Iext...]

Tasks: TOP => default => all => audio
(See full trace by running task with --trace)

Do you know that Clang isn't specific to Mac OS X ? You can give it a try quite easily on Linux. Dunno what about Windows.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 02:30:50 pm
Do you know that Clang isn't specific to Mac OS X ? You can give it a try quite easily on Linux. Dunno what about Windows.

Alright another try.

And I can't really right now because I am sitting at my workstation doing the changes over the Github web editor.
Title: Re: rbSFML
Post by: Laurent on April 24, 2012, 02:34:17 pm
Quote
Dunno what about Windows
Last time I tried (3.0.0), there were bugs that prevented it to work. And you have to build it yourself, there's no precompiled package.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 02:37:04 pm
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake
Creating sfml/system.so
Creating sfml/window.so
Creating sfml/graphics.so
Compiling ext/Audio/SoundBuffer.cpp
Compiling ext/Audio/SoundBufferRecorder.cpp
Compiling ext/Audio/SoundRecorder.cpp
Compiling ext/Audio/SoundSource.cpp
Compiling ext/Audio/SoundStream.cpp
Creating sfml/audio.so
Compiling ext/all.cpp
Creating sfml/all.so
[ ceylo ceylo-pc ~/Desktop/rbSFML ]
:)

Yeah it's still under heavy development at the moment : http://clang.llvm.org/cxx_status.html
But I really love how clear the error messages are, compared to GCC.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 02:49:51 pm
Finally compiled :D
I am now Clang++ proof  8)

Let me know how writing actual ruby code goes. I hope it works out well :D
And most important, have fun coding. I think that's the most important aspect of Ruby. It makes coding really fun, fast and simple. And let me know if you feel that I disrupt and of the Ruby principles(if you know them).
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 02:53:55 pm
I don't want to disappoint you but... my purpose was just to test someone else's game, not learn Ruby :D . At least, for now :) .


Edit: I tried this, without success :(
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] sudo rake install
Password:
Nothing to uninstall.
Installing library to /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml
Installing sfml/all.so...
Installing sfml/audio.so...
Installing sfml/graphics.so...
Installing sfml/system.so...
Installing sfml/window.so...
[ ceylo ceylo-pc ~/Desktop/rbSFML ] ls /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml
all.so audio.so graphics.so system.so window.so
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake test
Warning: Cannot load 'sfml/system'
Warning: Cannot load 'sfml/window'
Warning: Cannot load 'sfml/graphics'
Warning: Cannot load 'sfml/audio'
[ ceylo ceylo-pc ~/Desktop/rbSFML ] rake samples
/opt/local/bin/ruby1.9 sound.rb
/opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- sfml/system (LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from sound.rb:7:in `rescue in <main>'
from sound.rb:4:in `<main>'
/opt/local/bin/ruby1.9 window.rb
/opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- sfml/system (LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from window.rb:7:in `rescue in <main>'
from window.rb:4:in `<main>'

Can't rake test and rake samples be a bit more verbose about why sfml/system couldn't be loaded ?
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 02:59:24 pm
I don't want to disappoint you but... my purpose was just to test someone else's game, not learn Ruby :D . At least, for now :) .



WAAARGHH!!!! *breaths heavily*
Let me guess, You are going to play Steel? :P

The test is not valid, just take my example script from a few pages back and test. Does that work then the game you are going to test will work.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 03:00:12 pm
WAAARGHH!!!! *breaths heavily*
Let me guess, You are going to play Steel? :P
Yup I want to give it a try :D .

PS: I edited the above message.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 03:01:21 pm
Test and samples are out of date so don't trust them. I should just have them removed really as it confuses people. Take the test script from a couple of pages back on this thread and if that one runs the game runs ;)
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 03:14:45 pm
Well, the point is I'm getting the same error when I try to run Steel :
Code: [Select]
[ ceylo ceylo-pc ~/Downloads/Steel src ] ruby Steel.rb
/opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- sfml/graphics (LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from Steel.rb:1:in `<main>'

That's why I'd like to understand why it's failing.

Thanks,
Ceylo
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 04:03:11 pm
That's tricky.. as far as I can see the library is installed to the correct folder. Try adding this to the top of the main ruby file in Steel:

$: << "/opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11"
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 04:14:52 pm
It didn't change anything.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 04:46:46 pm
Hmm maybe there is a missing flag to the linker to create the shared library so it becomes invalid somehow? Do the compilation again with rake verbose and give it to me. Also say if you see some weird value in the CXX and LINK values since I don't know what's right in Clang.

If this fails just swap to GCC by giving these values to these variables:

CXX = "g++"
CXXFLAGS = "-O3 -g -I#{SFML_INC} -I#{EXT_DIR} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']}"

LINK = "g++ -shared"
LINK_FLAGS = "-Wl,--enable-auto-image-base,--enable-auto-import -L. -L#{SFML_LIB} -L#{RUBY_LIB} #{RUBY_LINK}"

Edit: Actually just tried including a file that doesn't exist. That is the exact message you get. So somehow Steel is not able to read from that path. So installation was correct now I don't know really since this feels like Mac-space. Not 100% sure.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 05:26:23 pm
Code: [Select]
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11]

OBJ_DIR    = "obj"
SO_DIR     = "sfml"
DOC_DIR    = "doc"
EXT_DIR    = "ext"
INST_DIR   = "/opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml" (found)

SFML_INC   = "include" (found)
SFML_LIB   = "lib" (found)

RUBY_INC   = "/opt/local/include/ruby-1.9.1" (found)
RUBY_LIB   = "/opt/local/lib" (found)
RUBY_LINK  = "-lruby.1.9.1"

CXX        = "/usr/bin/clang++"
CXXFLAGS   = "-pipe -O2 -Iinclude -Iext -I/opt/local/include/ruby-1.9.1 -I/opt/local/include/ruby-1.9.1/x86_64-darwin11 -Wall -Wextra "

LINK       = "/usr/bin/clang++ -dynamic -bundle"
LINK_FLAGS = "-Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -L. -L/opt/local/lib  -arch x86_64 -L/usr/local/lib -Llib -L/opt/local/lib -lruby.1.9.1"

There are several options that I never used and some that look weird.
- Especially "-Wl,-undefined,dynamic_lookup" that tells the linker not to complain if there are undefined symbols, and look for them at runtime. This is weak linking, but I don't know why it's needed here.
- As for -multiply_defined, it's obsolete.
- -pipe is unknown to both Clang and ld. Only GCC knows it.
- And I don't know why -bundle is used. I'd rather expect -dynamiclib.


I changed the Rakefile with what you gave except some options (that do not exist with Apple's GCC) :
Code: [Select]
CXX = "g++"
CXXFLAGS = "-O3 -g -I#{SFML_INC} -I#{EXT_DIR} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']}"

LINK = "g++ -dynamiclib"
LINK_FLAGS = "-L. -L#{SFML_LIB} -L#{RUBY_LIB} #{RUBY_LINK}"

Which now gives
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] file /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/graphics.so
/opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/graphics.so: Mach-O 64-bit dynamically linked shared library x86_64

instead of
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] file /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/system.so
/opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/system.so: Mach-O 64-bit bundle x86_64

But I don't know a lot about Ruby or bundles so I don't know whether this change is useful.

Anyway, I still get the same error message when trying to launch Steel.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 05:38:04 pm
Actually I jsut realized. You are running on 64 bit and compiling for 64bit. What kind of version is your ruby installation? 32 or 64?

Oh wait never mind it says that right there. It is 64bit system. I am at a loss. Your SFML libraries are 64 as well? I don't know anything else.

The problem is more or less that Ruby can't read the library files for some reason. It can be all from architecture to the filesystem not letting it.
Title: Re: rbSFML
Post by: Ceylo on April 24, 2012, 05:58:41 pm
Code: [Select]
[ ceylo ceylo-pc ~/Desktop/rbSFML ] which ruby
/usr/bin/ruby
[ ceylo ceylo-pc ~/Desktop/rbSFML ] file /usr/bin/ruby
/usr/bin/ruby: Mach-O 64-bit executable x86_64
[ ceylo ceylo-pc ~/Desktop/rbSFML ] file /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/graphics.so
/opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/graphics.so: Mach-O 64-bit dynamically linked shared library x86_64
[ ceylo ceylo-pc ~/Desktop/rbSFML ] file /usr/local/lib/libsfml-graphics.dylib
/usr/local/lib/libsfml-graphics.dylib: Mach-O 64-bit dynamically linked shared library x86_64

If I try to run Steel in debug mode (-d):
Code: [Select]
[ ceylo ceylo-pc ~/Downloads/Steel src ] ruby -d Steel.rb
Exception `LoadError' at /opt/local/lib/ruby1.9/1.9.1/rubygems.rb:1264 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /opt/local/lib/ruby1.9/1.9.1/rubygems.rb:1273 - cannot load such file -- rubygems/defaults/ruby
Steel.rb:77: warning: ambiguous first argument; put parentheses or even spaces
Exception `LoadError' at /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36 - cannot load such file -- sfml/graphics
Exception `LoadError' at /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:63 - cannot load such file -- sfml/graphics
/opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- sfml/graphics (LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from Steel.rb:2:in `<main>'

I'mma have a look at Ruby 'getting started' tutorials on OS X to see whether I missed something.
Title: Re: rbSFML
Post by: Groogy on April 24, 2012, 06:57:47 pm
I'm wondering if there is some read-write settings you have to set for Ruby and Steel.rb and so on?

You could try moving around the sfml folder in the ruby folder until you get results XD
Like I said I am out of ideas of what the problem might be so I am just spewing out brute force things now.
Title: Re: rbSFML
Post by: Groogy on April 25, 2012, 07:44:00 am
Just realized, what happens if you create a ruby file in the ruby library directory and tries to load that? Can ruby find it?
Title: Re: rbSFML
Post by: Ceylo on April 25, 2012, 11:36:45 am
Do you mean in /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11 ?
I copied all of the Steel files there and it still can't load.

I also tried to run ruby as root in case the issue would be related to permissions, but it's still failing.
Even if I replace the 'require' with 'require_relative' in Steel.rb.

Code: [Select]
Steel.rb:2:in `require_relative': cannot load such file -- /opt/local/lib/ruby1.9/site_ruby/1.9.1/x86_64-darwin11/sfml/graphics (LoadError)
from Steel.rb:2:in `<main>'

PS: I may have an idea...
Title: Re: rbSFML
Post by: Ceylo on April 25, 2012, 11:49:03 am
Is the extension that the Ruby libraries should take in the $CONFIG variable ?
Title: Re: rbSFML
Post by: Groogy on April 26, 2012, 08:21:41 pm
Is the extension that the Ruby libraries should take in the $CONFIG variable ?

I don't know, I think so. It got like everything about the environment in there. Just launch up irb in a console and type:

require 'rbconfig'
rbConfig::CONFIG

DAMNIT, I keep pressing modify when I want to quote xD
Title: Re: rbSFML
Post by: Ceylo on April 27, 2012, 12:32:18 am
Code: [Select]
irb(main):009:0> RbConfig::CONFIG['DLEXT']
=> "bundle"

According to http://guides.rubygems.org/c-extensions/ , this is what I was looking for.
And using this extension and reinstalling, here is what I get :
Code: [Select]
/opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require': wrong argument type false (expected Module) (TypeError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from Steel.rb:1:in `<main>'

Where line 1 is just
Code: [Select]
require "sfml/graphics"(I redownloaded the sources to make sure I hadn't introduced errors in the game's sources)
Title: Re: rbSFML
Post by: Groogy on April 27, 2012, 02:18:51 am
Alright just to be sure we get this right. I have to end the shared libraries on mac with bundle?

So more or less this should solve it for all platforms:
"#{SO_DIR}/#{file}.#{CONFIG['DLEXT']}"
I will create a "ceylo-branch" on the repo where I will do some printouts as of where it goes wrong and then you'll have to get back to me with the output log.

I will setup the branch now this weekend unless you know a better way to check. The error message doesn't say where it goes wrong it just says that something went wrong. What you could do until then is do a require on each library module and see what happens. This will give me a bit more precise information of what is happening.

rbSFML is just like SFML divided into system, window, graphics, audio. The difference is that rbSFML will check if the others have been loaded and if not load them for you.

boot up IRB in a console and type:
require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'
Title: Re: rbSFML
Post by: Ceylo on April 28, 2012, 11:24:51 am
Code: [Select]
[ ceylo ceylo-pc ~/Downloads/Steel src-1 ] irb1.9
irb(main):001:0> require 'sfml/system'
=> true
irb(main):002:0> require 'sfml/window'
=> true
irb(main):003:0> require 'sfml/graphics'
=> true

Code: [Select]
[ ceylo ceylo-pc ~/Downloads/Steel src-1 ] irb1.9
irb(main):001:0> require 'sfml/graphics'
TypeError: wrong argument type false (expected Module)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from /opt/local/lib/ruby1.9/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from /opt/local/bin/irb1.9:12:in `<main>'

If I add require 'sfml/window' in Steel.rb, before require 'sfml/graphics', it launches, then crashes.

Code: [Select]
Process:         ruby1.9 [91091]
Path:            /opt/local/bin/ruby1.9
Identifier:      ruby1.9
Version:         ??? (???)
Code Type:       X86-64 (Native)
Parent Process:  bash [90739]

Date/Time:       2012-04-28 11:19:48.006 +0200
OS Version:      Mac OS X 10.7.3 (11D50)
Report Version:  9

Interval Since Last Report:          369575 sec
Crashes Since Last Report:           10
Per-App Crashes Since Last Report:   2
Anonymous UUID:                      58ED1128-DF39-4F74-B69D-C036FB889BA8

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
objc[91091]: garbage collection is OFF
*** error for object 0x7f8cc25a4650: pointer being freed was not allocated
 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        0x00007fff8f35cce2 __pthread_kill + 10
1   libsystem_c.dylib              0x00007fff8824e7d2 pthread_kill + 95
2   libsystem_c.dylib              0x00007fff8823fa7a abort + 143
3   libsystem_c.dylib              0x00007fff8829e84c free + 389
4   libruby.1.9.1.dylib            0x0000000106602458 finalize_list + 184
5   libruby.1.9.1.dylib            0x00000001066e86a6 rb_threadptr_execute_interrupts_common + 86
6   libruby.1.9.1.dylib            0x00000001066e67c7 vm_call_method + 2423
7   libruby.1.9.1.dylib            0x00000001066d7cb4 vm_exec_core + 15172
8   libruby.1.9.1.dylib            0x00000001066e06e2 vm_exec + 98
9   libruby.1.9.1.dylib            0x00000001066ddc63 rb_yield + 99
10  libruby.1.9.1.dylib            0x00000001065c67cd rb_ary_each + 45
11  libruby.1.9.1.dylib            0x00000001066e60b9 vm_call_method + 617
12  libruby.1.9.1.dylib            0x00000001066d67af vm_exec_core + 9791
13  libruby.1.9.1.dylib            0x00000001066e06e2 vm_exec + 98
14  libruby.1.9.1.dylib            0x00000001066ddc63 rb_yield + 99
15  libruby.1.9.1.dylib            0x0000000106658218 range_each + 168
16  libruby.1.9.1.dylib            0x00000001066e60b9 vm_call_method + 617
17  libruby.1.9.1.dylib            0x00000001066d67af vm_exec_core + 9791
18  libruby.1.9.1.dylib            0x00000001066e06e2 vm_exec + 98
19  libruby.1.9.1.dylib            0x00000001066e0e48 rb_iseq_eval_main + 184
20  libruby.1.9.1.dylib            0x00000001065efa4f ruby_exec_internal + 111
21  libruby.1.9.1.dylib            0x00000001065ef997 ruby_run_node + 71
22  ruby1.9                        0x00000001065b9edf main + 79
23  ruby1.9                        0x00000001065b9e84 start + 52
Title: Re: rbSFML
Post by: Groogy on April 29, 2012, 10:21:38 pm
Can you try and find on what function it is that it crashes?
Title: Re: rbSFML
Post by: Ceylo on April 29, 2012, 10:31:55 pm
Yes sure!
It's the draw call at line ~262 (more or less, as I've added a few 'require') in Steel.rb.

Everything runs fine until I comment out this call.
Title: Re: rbSFML
Post by: Groogy on April 30, 2012, 11:52:58 pm
Yes sure!
It's the draw call at line ~262 (more or less, as I've added a few 'require') in Steel.rb.

Everything runs fine until I comment out this call.

Well that is a call to a method in the Game class. So you'll have to narrow done what in that function causes it. It begin at the line 67.
Title: Re: rbSFML
Post by: Ceylo on May 01, 2012, 01:18:20 pm
Uh, you're right. I didn't know how to recognize rbSFML methods from the Steel's ones.

So I've looked a bit further and I found out it crashes until I comment out "@app.view = @app.default_view" at line 59 of Steel.rb. I suppose it's related to rbSFML this time?
Title: Re: rbSFML
Post by: Groogy on May 01, 2012, 05:24:44 pm
Yes it is. I don't understand why though... this code should be safe:

VALUE rbRenderTarget::SetView( VALUE aSelf, VALUE aView )
{
        rbRenderTarget::ToSFML( aSelf )->setView( *rbMacros::ToSFML< sf::View >( aView, rbView::Class ) );
        return Qnil;
}

VALUE rbRenderTarget::GetDefaultView( VALUE aSelf )
{
        const sf::View& view = rbRenderTarget::ToSFML( aSelf )->getDefaultView();
        VALUE obj = rbMacros::ToRuby( const_cast< sf::View* >( &view ), rbView::Class );
        rb_iv_set( obj, "@__ref__owner", aSelf );
        rb_obj_freeze( obj );
        return obj;
}

I am having a hard time seeing what is wrong here =/


Update: Nevermind I just saw it I think.
The problem is that I more or less forgot about the garbage collector here and is collecting memory inside the render target which is very very bad. Somehow the Mac version garbage collector is invoked more often or something I guess. Anyway there is probably mistakes like this all over the binding.
Title: Re: rbSFML
Post by: Ceylo on May 01, 2012, 07:55:57 pm
Hmm ok. So I suppose I'll just have to wait for you to fix memory handling?
Maybe you could try to fix it for this instruction only so that we can check whether the issue is really related to the garbage collector.
Title: Re: rbSFML
Post by: Groogy on May 02, 2012, 03:51:27 pm
I already did. Now I am just waiting for the next bug for you to find :D
Title: Re: rbSFML
Post by: Ceylo on May 02, 2012, 03:54:55 pm
The game is working fine now :D .
Title: Re: rbSFML
Post by: Groogy on May 02, 2012, 10:32:25 pm
The game is working fine now :D .

Great! I hope you will try out Ruby and find all the bugs I have made in Mac ^^
Title: Re: rbSFML
Post by: vivo on May 05, 2012, 01:29:02 am
Hello Groogy, I've been asking for the code intelligence, you were right, the only way to get completions would be to create a pure ruby file that defined the classes/functions of the module.

http://support.activestate.com/node/8496#comment-21090
Title: Re: rbSFML
Post by: Groogy on May 05, 2012, 02:05:32 am
Thought so.

The documentation is done with ruby files and contain all the information you need. So if you only can get the code intelligence tool to parse those files then you are good to go!
Title: Re: rbSFML
Post by: vivo on May 11, 2012, 07:00:50 pm
Hi. Not sure if it's an error, but when I try to get a Texture from a RenderTexture using getTexture i get:
undefined method `getTexture' for SFML::RenderTexture(500x300, 0x9a16848):SFML::RenderTexture (NoMethodError)

this is a piece of my code:
...
rendertexture = RenderTexture.new(500,300)
 #drawing the texture
showText("A RAGE Game",rendertexture)
texture.display
texture = rendertexture.getTexture
sprite = Sprite.new(texture)
...

 #draws a text in the window
        #default position is like a subtittle
        def showText(text, render = main_window, size = 50, color = Color::White, pos = nil)
                if(!pos)
                        pos = main_window.getSize/2
                        pos.y += 2*pos.y/3
                end
                txt = Text.new(text)
                #txt.setString(text)
                txt.setFont(main_font)
                txt.setCharacterSize(50)
                txt.setColor(color)
                txt.setPosition(pos)
                render.draw txt

        end

 
Title: Re: rbSFML
Post by: Groogy on May 12, 2012, 11:01:02 am
That's a bug, I have somehow, I don't know how, missed the getTexture function. I'll add it as soon as I'm at a computer where I can.
Title: Re: rbSFML
Post by: Groogy on May 12, 2012, 02:37:54 pm
Alright fixed and updated the repo.
Title: Re: rbSFML
Post by: vivo on May 15, 2012, 08:58:39 pm
Great Groogy
Title: Re: rbSFML
Post by: vivo on May 15, 2012, 09:09:42 pm
Have you tried the Font::loadFromFile method ?
Maybe it's because of my ATI card, but I get a seg fault  :-\
Title: Re: rbSFML
Post by: Groogy on May 15, 2012, 10:24:16 pm
Was just the result of a stupid typo from me. It's fixed now.

I'm interested in seeing anything you are working on :)
Title: Re: rbSFML
Post by: vivo on May 19, 2012, 12:35:50 pm
It's an adventure game engine (and a little sample game). Its taking longer than I expected, as soon as It will be able to display something near to a game I'll show you  ;D
Title: Re: rbSFML
Post by: vivo on May 19, 2012, 08:57:23 pm
Hi again Groogy, I can't use RenderWindow::getFrameTime wich should give me the time between frames 
Title: Re: rbSFML
Post by: Groogy on May 20, 2012, 01:49:48 pm
That's because the method doesn't exist   ;)
You will have to create a clock yourself now in order to get the frame time. If you have trouble with that I can give a code example for you.
Title: Re: rbSFML
Post by: vivo on May 20, 2012, 07:57:52 pm
hehe, that's how i'm doing it now. A clock wich restarts each window.display. The only problem I see is that i'll have to control it when user pauses the game. But it won't be a problem, thanks
Title: Re: rbSFML
Post by: vivo on May 22, 2012, 09:35:26 pm
Could you help me?
When I try to pull your project and exec rake I get:

vivo@ubuntu:~/Escritorio/proyectoAG/rbSFML/Groogy_def/rbSFML$ git pull git@github.com:Groogy/rbSFML.git masterFrom github.com:Groogy/rbSFML
 * branch            master     -> FETCH_HEAD
Already up-to-date.

vivo@ubuntu:~/Escritorio/proyectoAG/rbSFML/Groogy_def/rbSFML$ rake
Creating sfml/system.so
Compiling ext/Window/Window.cpp
ext/Window/Window.cpp: In function ‘VALUE rbWindow::SetIcon(VALUE, VALUE, VALUE, VALUE)’:
ext/Window/Window.cpp:391: warning: comparison between signed and unsigned integer expressions
ext/Window/Window.cpp: In function ‘VALUE rbWindow::GetSystemHandle(VALUE)’:
ext/Window/Window.cpp:472: error: invalid cast from type ‘sf::WindowHandle’ to type ‘long unsigned int’
rake aborted!
Command failed with status (1): [g++  -O3 -ggdb -Wextra -Wno-unused-paramet...]

Tasks: TOP => default => all => window
(See full trace by running task with --trace)
vivo@ubuntu:~/Escritorio/proyectoAG/rbSFML/Groogy_def/rbSFML$
 
I'm completely lost at this point  :-[
Title: Re: rbSFML
Post by: vivo on May 22, 2012, 09:38:08 pm
This is the last update:

vivo@ubuntu:~/Escritorio/proyectoAG/rbSFML/Groogy_def/rbSFML$ git pull git@github.com:Groogy/rbSFML.git masterFrom github.com:Groogy/rbSFML
 * branch            master     -> FETCH_HEAD
Updating 3c07a96..979f32c
Fast-forward
 Rakefile                       |   16 ++++++++--------
 ext/Audio/Music.cpp            |    2 +-
 ext/Audio/SoundBuffer.cpp      |    4 ++--
 ext/Graphics/Font.cpp          |    6 +++---
 ext/Graphics/RenderTarget.cpp  |    4 ++--
 ext/Graphics/RenderTexture.cpp |   16 ++++++++++++++++
 ext/Graphics/RenderTexture.hpp |    5 +++++
 ext/Graphics/Shader.cpp        |    1 +
 ext/System/Vector3.cpp         |    2 +-
 ext/Window/Window.cpp          |    8 ++++----
 ext/rbSFML.hpp                 |   29 ++++++++++++++++++++++++++++-
 11 files changed, 71 insertions(+), 22 deletions(-)

 
Title: Re: rbSFML
Post by: Groogy on May 22, 2012, 10:03:55 pm
That's weird, haven't changed that in a long time. Try now and see if it works.
Title: Re: rbSFML
Post by: vivo on May 23, 2012, 09:31:56 am
thanks Groogy, now it works!
Title: Re: rbSFML
Post by: Groogy on May 26, 2012, 03:46:22 pm
I've just set up my Twitter account (https://twitter.com/#!/SirVogelius) and a facebook page (http://www.facebook.com/rbsfml) where updates on rbSFML will be posted and anything that happens for instance projects you guys work on.

It will probably be quite silent but might be a good thing to follow and show support to the project :)
Title: Re: rbSFML
Post by: vivo on May 28, 2012, 06:58:41 pm
Hi there, seems that there is no method Texture:loadFromImage
/home/vivo/Escritorio/proyectoAG/proyecto/SceneChar.rb:57:in `block (2 levels) in load_animation': undefined method `loadFromImage' for SFML::Texture:Class (NoMethodError)
Title: Re: rbSFML
Post by: Groogy on May 29, 2012, 09:18:01 am
That's weird, the method is there. Are you sure you are running on the latest version?
Title: Re: rbSFML
Post by: Groogy on May 29, 2012, 06:30:07 pm
sure... maybe it's because of the alias? I've done a "grep -R alias * | grep loadFromImage" on the ext folder and nothing appeared

https://github.com/Groogy/rbSFML/blob/master/ext/Graphics/Texture.cpp @ line 69.

As you can clearly see, the alias is there.
Try to take a clean fresh copy of rbSFML and see if it works then.
Title: Re: rbSFML
Post by: vivo on May 29, 2012, 06:57:25 pm
sorry, as you can see I deleted my message as soon as I noticed it.
BTW, I still can't use the method... does it works on your installation?
Title: Re: rbSFML
Post by: vivo on May 29, 2012, 07:14:07 pm
oooooppssss... now I know whats happening here

I'm trying
texture = Texture.loadFromImage(image, area)
 
but the message is that there is no method for Texture:Class
whereas if I try the method in an object
texture = Texture.new
texture.loadFromImage(image,area)
 
then it works

(weird... sprite = Sprite.loadFromImage works :P)
either works...ok, sorry for my missunderstanding
Title: Re: rbSFML
Post by: Groogy on May 29, 2012, 07:18:16 pm
That's weird, should not work for sprites either. Though I am wondering if I should add construction methods to the classes as well. It makes sense to have them.
Title: Re: rbSFML
Post by: Laurent on May 29, 2012, 07:33:23 pm
I don't know how Ruby handles that, but I guess it's similar to .Net, Python and all interpreted/dynamic languages. For these languages, I think it's ok (and better) to transform load functions to constructors, since "empty" objects are basically useless. That's what I do in SFML.Net, and even in CSFML actually.
Title: Re: rbSFML
Post by: vivo on May 29, 2012, 07:41:45 pm
yes... seems more intuitive that way
Title: Re: rbSFML
Post by: vivo on June 10, 2012, 11:56:29 pm
I again Groogy, more reports:
when I try the applyTransform method from a RenderTexture instance I get:
undefined method `applyTransform' for SFML::RenderTexture(0x0, 0x94c92c0):SFML::RenderTexture (NoMethodError)

All I want is to get a mirrored texture from another one, do you know an easier way to do it?
Title: Re: rbSFML
Post by: Laurent on June 11, 2012, 08:06:47 am
applyTransform is not part of the public API.
Title: Re: rbSFML
Post by: vivo on June 11, 2012, 12:04:26 pm
so is it internally called by RenderTexture when you for instance call the scale method?

How would you do the trick?
I've tried with scale (-1,1) without success
Title: Re: rbSFML
Post by: Laurent on June 11, 2012, 12:25:29 pm
Setting the scale of the sprite that draws the render-texture contents to -1 should work.
Title: Re: rbSFML
Post by: vivo on June 14, 2012, 10:45:07 pm
Thanks, done
Title: Re: rbSFML
Post by: Lupinius on July 27, 2012, 06:48:54 pm
I'm back, using Archlinux this time. When trying to compile I get these errors:
Code: [Select]
[eric@Brictop Groogy-rbSFML-afda8ca]$ rake
Compiling ext/System/main.cpp
In file included from ext/System.hpp:33:0,
                 from ext/System/main.cpp:22:
ext/System/Vector2.hpp: In function 'VALUE rbVector2::ToRuby(VALUE)':
ext/System/Vector2.hpp:119:92: error: taking address of temporary array
ext/System/Vector2.hpp: In function 'VALUE rbVector2::ToRuby(const Vector2i&)':
ext/System/Vector2.hpp:133:76: error: taking address of temporary array
ext/System/Vector2.hpp: In function 'VALUE rbVector2::ToRuby(const Vector2u&)':
ext/System/Vector2.hpp:140:76: error: taking address of temporary array
ext/System/Vector2.hpp: In function 'VALUE rbVector2::ToRuby(const Vector2f&)':
ext/System/Vector2.hpp:147:76: error: taking address of temporary array
In file included from ext/System.hpp:34:0,
                 from ext/System/main.cpp:22:
ext/System/Vector3.hpp: In function 'VALUE rbVector3::ToRuby(VALUE)':
ext/System/Vector3.hpp:120:56: error: taking address of temporary array
ext/System/Vector3.hpp: In function 'VALUE rbVector3::ToRuby(const Vector3i&)':
ext/System/Vector3.hpp:135:79: error: taking address of temporary array
ext/System/Vector3.hpp: In function 'VALUE rbVector3::ToRuby(const Vector3f&)':
ext/System/Vector3.hpp:143:79: error: taking address of temporary array
rake aborted!
Command failed with status (1): [g++ -march=x86-64 -mtune=generic -O2 -pipe...]

Tasks: TOP => default => all => system
(See full trace by running task with --trace)

I did not follow all the instructions from the rbSFML page (I'm using the SFML version from my packet manager), but this does not look like it is the problem here.
Title: Re: rbSFML
Post by: Groogy on July 30, 2012, 11:00:31 am
I'll look at it as soon as I get time, I hope tonight.
Title: Re: rbSFML
Post by: Groogy on August 16, 2012, 10:52:01 pm
That problem on Archlinux was weird, should work. Anyway not hard to fix. Will get around to it. Sorry for the delay but it is summer :)

I am having another problem which I need Laurents help with. Setting parameters on shaders in C++ and examples work just fine but somehow for me in Ruby it doesn't. I only get "Parameter "<name>" not found in shader" though it is clearly there and the names are copy pasted and is 100% correct. I don't do anything funky in the binding I just convert the Ruby string to a C++ string before passing it to SFML. So technically it should work unless I am doing something wrong with the conversion. So I tried forcing the parameter name in the Ruby binding code to something specific to see if it works but it still says it can't find it.

I've tried binding before setting parameters and I've tried moving the parameter set to after something is rendered. But still no prevail. I've searched the forum after similar problems or solutions but found nothing. So wondering if you are aware of any potential problem I can have stumbled upon?

I know the shader compiles and works because I am rendering with it and is seeing the effects from it.

I am trying with a uniform vec2 uniformTest variable with the @state.shader.setParameter("uniformTest", SFML::Vector2.new(0, 1)) code in ruby which becomes this : shader->setParameter( "uniformTest", sf::Vector2f( 0, 1 ) ); for C++ but it don't work.

There is clearly a problem on my end but can't find it =/
Title: Re: rbSFML
Post by: Groogy on August 16, 2012, 11:14:17 pm
Never mind! I am sorry... seems to be if I don't use the variable GLSL optimizes it away and you can't use it. So doing a simple "Test if this works" steps made me see an error that didn't exist.
Title: Re: rbSFML
Post by: Groogy on September 09, 2012, 06:55:15 pm
I'm looking at the problem that occurred in Arch Linux and fixed that. But afterwards I had a lot more problems with it not being able to find types I was including and so on. Have no idea why Arch would have such problems with my source, works perfectly in all other distro's I tested.
Title: Re: rbSFML
Post by: Groogy on September 10, 2012, 09:02:25 am
Managed to fix it after a good night of sleep :)
Title: Re: rbSFML
Post by: vivo on March 01, 2013, 01:18:10 pm
Hello! It has been a long time since the last time I post here. I'm surprised that there has been no activity here... I've found ruby a great language for developing games, really friendly  :-\
BTW, I wanted to announce here that that the Ruby Adventure Game Engine it's almost finished, it's my first project in Ruby, SFML and even games :-P but I think the final result it's not bad at all, at least for being a first iteration. I'll post a link to a github project when the doc is ready and fix a few issues of the engine (maybe a mounth?) in case anyone wanted to use it
regards
Title: Re: rbSFML
Post by: Groogy on March 01, 2013, 01:43:13 pm
Well since I got a contract with Packt Publishing to make a book for them I've had little to no time to work at rbSFML at all. But in April I'll be free again and fix a lot of stuff. I will also consider to create a branch for OpenGL in the rbSFML binding so doing require 'sfml/opengl' will be possible since the only binding for OpenGL that exists are out of date. But this is not a promise and only an idea and it might not even be "officially supported".
Title: Re: rbSFML
Post by: vivo on March 01, 2013, 02:03:53 pm
I appreciate your altruistic work here, I haven't tried any 3D aspect but I must say rbSFML actually works great with 2D graphics.
What kind of book are u writing?
Title: Re: rbSFML
Post by: Groogy on March 01, 2013, 02:10:43 pm
"SFML Game Development" with 2 other authors. DevilWithin/Grimshaw and Nexus on this forum. Also Laurent is keeping an eye on it and comes with suggestions from time to time.

It just teaches some techniques in game development and uses SFML as the technology to do it. Though it is in C++.

Also the OpenGL extensions primary goal is not to be used for 3D really. Though it would be nice and cool. It's to allow you to extend SFML yourself in Ruby code like how you can do in C++ with sf::Drawable and so on.
Title: Re: rbSFML
Post by: vivo on March 01, 2013, 02:22:12 pm
Sounds really interesting and most of all, useful!

Also the OpenGL extensions primary goal is not to be used for 3D really. Though it would be nice and cool. It's to allow you to extend SFML yourself in Ruby code like how you can do in C++ with sf::Drawable and so on.
I haven't tried any of that stuff, all I can say is, keep the good work  :)
Title: Re: rbSFML
Post by: wintertime on October 12, 2013, 08:30:09 pm
Hi,

I started making a little game with rbSFML on Windows to practise Ruby programming and would like to tell a bit of my experience with it.
I followed the readme on github, but the clone command in there didnt work somehow, scrolling up and using the slightly different clone command provided by github worked. rake test produced some errors, but rake samples and later my program worked flawlessly - after I found out myself SFML should also be compiled with the Ruby DevKit.
What I noticed is that the .dll files don't get packaged into the gem and you need to copy them into the folder with your own Ruby files or add them to the path variable. I already had another version of SFML in the path from using it with C++ and Ruby would crash when it found that. It would be nice if you could fix this and put them into the gem such that Ruby gems can take over the work of fixing the path, as that would installation much easier when distributing a game. Or is that not possible and I should try rake static?

The documentation seems a bit incomplete, but after finding out the code actually exists I could just look at the docs on the SFML website for C++. It would just be a little less confusing if there was a notice that not all classes are documented.

The only thing I found missing in rbSFML, while using it, were the constants for the Text styles, for making it bold for example, but I could put a number from a SFML header in manually.

Oh and one weird thing was when I tried activating vertical sync for the RenderWindow. I printed the frametimes to the console and the program did go slower from waiting, but the cpu utilization did not drop when looking at the task manager like I had hoped for, so I commented it out. I dont know if this comes from rbSFML, its a normal thing with SFML or maybe just my graphics driver? Maybe I should try it again in C++.

Anyway, thanks for making it available. :)
Title: Re: rbSFML
Post by: Groogy on October 12, 2013, 10:16:48 pm
The binding has a lot of shortcomings and has gone out of date. I want to work on it but have a hard time finding time for hobby projects outside my job. But I have recently moved stuff around so my weekends are free, hopefully I will pick this up again as the project is really important to me.
Title: Re: rbSFML
Post by: wintertime on October 31, 2013, 04:20:45 pm
I just wanted to say thank you again. I noticed the vertex array didn't want to accept changes to its data after appending to it (I guess thats one of those shortcomings you mentioned), but I managed to work around it so its all well. :)