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

Author Topic: rbSFML  (Read 140816 times)

0 Members and 1 Guest are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #210 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: rbSFML
« Reply #211 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.
« Last Edit: April 23, 2012, 11:24:19 pm by Ceylo »
Want to play movies in your SFML application? Check out sfeMovie!

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #212 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.
« Last Edit: April 24, 2012, 06:18:52 am by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: rbSFML
« Reply #213 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.
« Last Edit: April 24, 2012, 08:43:14 am by Groogy »
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #214 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 ^^
« Last Edit: April 24, 2012, 08:45:27 am by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: rbSFML
« Reply #215 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
« Last Edit: April 24, 2012, 10:36:11 am by Ceylo »
Want to play movies in your SFML application? Check out sfeMovie!

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #216 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: rbSFML
« Reply #217 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 :-\
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #218 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() ) );
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: rbSFML
« Reply #219 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.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #220 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.
« Last Edit: April 24, 2012, 12:34:11 pm by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: rbSFML
« Reply #221 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);
}
« Last Edit: April 24, 2012, 12:44:09 pm by Laurent »
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #222 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: rbSFML
« Reply #223 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.
Want to play movies in your SFML application? Check out sfeMovie!

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #224 on: April 24, 2012, 02:00:06 pm »
Did the latest version work for you?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything