From 85a4e5155e3c6a41dc204127121fd87162a6a27b Mon Sep 17 00:00:00 2001 From: groogy Date: Tue, 16 Nov 2010 16:26:00 +0000 Subject: [PATCH] Removed some stuff that wasn't needed any more in the window module Also made the required changed for Rdoc to the system module and generated rdoc documentation for both modules. It's safe to say now that rbSFML is available to be used for at least opening up a window and opengl context and render something in opengl. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1658 4e206d99-4929-0410-ac5d-dfc041789085 --- bindings/ruby/sfml-system/system/Clock.cpp | 17 ++++-- bindings/ruby/sfml-system/system/Vector2.cpp | 59 +++++++++++--------- bindings/ruby/sfml-system/system/Vector3.cpp | 59 +++++++++++--------- bindings/ruby/sfml-system/system/main.cpp | 6 +- bindings/ruby/sfml-system/system/main.hpp | 5 +- bindings/ruby/sfml-window/window/main.cpp | 5 -- bindings/ruby/sfml-window/window/main.hpp | 4 -- 7 files changed, 83 insertions(+), 72 deletions(-) diff --git a/bindings/ruby/sfml-system/system/Clock.cpp b/bindings/ruby/sfml-system/system/Clock.cpp index 2a93a8da..9a5fe074 100644 --- a/bindings/ruby/sfml-system/system/Clock.cpp +++ b/bindings/ruby/sfml-system/system/Clock.cpp @@ -24,7 +24,6 @@ #include "main.hpp" #include -/* Utility class for manipulating time. */ VALUE globalClockClass; /* Free a heap allocated object @@ -76,14 +75,22 @@ static VALUE Clock_New( VALUE aKlass ) void Init_Clock( void ) { - globalClockClass = rb_define_class_under( GetNamespace(), "Clock", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* Utility class for manipulating time. + * + * sf::Clock is a lightweight class for measuring time. + * + * Its resolution depends on the underlying OS, but you can generally expect a 1 ms resolution. + */ + globalClockClass = rb_define_class_under( sfml, "Clock", rb_cObject ); // Class methods - rb_define_singleton_method( globalClockClass, "new", FUNCPTR( Clock_New ), 0 ); + rb_define_singleton_method( globalClockClass, "new", Clock_New, 0 ); // Instance methods - rb_define_method( globalClockClass, "getElapsedTime", FUNCPTR( Clock_GetElapsedTime ), 0 ); - rb_define_method( globalClockClass, "reset", FUNCPTR( Clock_Reset ), 0 ); + rb_define_method( globalClockClass, "getElapsedTime", Clock_GetElapsedTime, 0 ); + rb_define_method( globalClockClass, "reset", Clock_Reset, 0 ); // Aliases rb_define_alias( globalClockClass, "elapsedTime", "getElapsedTime" ); diff --git a/bindings/ruby/sfml-system/system/Vector2.cpp b/bindings/ruby/sfml-system/system/Vector2.cpp index 5043c437..aed44232 100644 --- a/bindings/ruby/sfml-system/system/Vector2.cpp +++ b/bindings/ruby/sfml-system/system/Vector2.cpp @@ -23,22 +23,6 @@ #include "Vector2.hpp" #include "main.hpp" -/* SFML::Vector2 is a simple class that defines a mathematical vector with two coordinates (x and y). - * - * It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc. - * - * This class differs from the C++ version. It will accept any value that is Numeric and both x and y must be of the same class. - * - * v1 = SFML::Vector2.new(16.5, 24.0) - * v1.x = 18.2 - * y = v1.y - * - * v2 = v1 * v1; - * v3 = SFML::Vector2.new - * v3 = v1 + v2 - * - * different = (v2 != v3); - */ VALUE globalVector2Class; /* Internal function @@ -94,6 +78,7 @@ static void Vector2_internal_ValidateTypes( VALUE aFirst, VALUE aSecond ) } } +/* */ static VALUE Vector2_Negate( VALUE self ) { VALUE x = rb_funcall( self, rb_intern( "x" ), 0 ); @@ -103,6 +88,7 @@ static VALUE Vector2_Negate( VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, negatedX, negatedY ); } +/* */ static VALUE Vector2_Add( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector2_ForceType( aRightOperand ); @@ -119,6 +105,7 @@ static VALUE Vector2_Add( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY ); } +/* */ static VALUE Vector2_Subtract( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector2_ForceType( aRightOperand ); @@ -135,6 +122,7 @@ static VALUE Vector2_Subtract( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY ); } +/* */ static VALUE Vector2_Multiply( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector2_ForceType( aRightOperand ); @@ -151,6 +139,7 @@ static VALUE Vector2_Multiply( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY ); } +/* */ static VALUE Vector2_Divide( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector2_ForceType( aRightOperand ); @@ -167,6 +156,7 @@ static VALUE Vector2_Divide( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY ); } +/* */ static VALUE Vector2_Equal( VALUE self, VALUE anArgument ) { VALUE aVector = Vector2_ForceType( anArgument ); @@ -186,6 +176,7 @@ static VALUE Vector2_Equal( VALUE self, VALUE anArgument ) } } +/* */ static VALUE Vector2_StrictEqual( VALUE self, VALUE anArgument ) { VALUE aVector = Vector2_ForceType( anArgument ); @@ -243,19 +234,37 @@ static VALUE Vector2_Initialize( VALUE self, VALUE someArgs ) void Init_Vector2( void ) { - globalVector2Class = rb_define_class_under( GetNamespace(), "Vector2", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* SFML::Vector2 is a simple class that defines a mathematical vector with two coordinates (x and y). + * + * It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc. + * + * This class differs from the C++ version. It will accept any value that is Numeric and both x and y must be of the same class. + * + * v1 = SFML::Vector2.new(16.5, 24.0) + * v1.x = 18.2 + * y = v1.y + * + * v2 = v1 * v1; + * v3 = SFML::Vector2.new + * v3 = v1 + v2 + * + * different = (v2 != v3); + */ + globalVector2Class = rb_define_class_under( sfml, "Vector2", rb_cObject ); // Instance methods - rb_define_method( globalVector2Class, "initialize", FUNCPTR( Vector2_Initialize ), -2 ); - rb_define_method( globalVector2Class, "eql?", FUNCPTR( Vector2_Initialize ), 1 ); + rb_define_method( globalVector2Class, "initialize", Vector2_Initialize, -2 ); + rb_define_method( globalVector2Class, "eql?", Vector2_StrictEqual, 1 ); // Instance operators - rb_define_method( globalVector2Class, "-@", FUNCPTR( Vector2_Negate ), 0 ); - rb_define_method( globalVector2Class, "+", FUNCPTR( Vector2_Add ), 1 ); - rb_define_method( globalVector2Class, "-", FUNCPTR( Vector2_Subtract ), 1 ); - rb_define_method( globalVector2Class, "*", FUNCPTR( Vector2_Multiply ), 1 ); - rb_define_method( globalVector2Class, "/", FUNCPTR( Vector2_Divide ), 1 ); - rb_define_method( globalVector2Class, "==", FUNCPTR( Vector2_Divide ), 1 ); + rb_define_method( globalVector2Class, "-@", Vector2_Negate, 0 ); + rb_define_method( globalVector2Class, "+", Vector2_Add, 1 ); + rb_define_method( globalVector2Class, "-", Vector2_Subtract, 1 ); + rb_define_method( globalVector2Class, "*", Vector2_Multiply, 1 ); + rb_define_method( globalVector2Class, "/", Vector2_Divide, 1 ); + rb_define_method( globalVector2Class, "==", Vector2_Equal, 1 ); // Attribute accessors rb_define_attr( globalVector2Class, "x", 1, 1 ); diff --git a/bindings/ruby/sfml-system/system/Vector3.cpp b/bindings/ruby/sfml-system/system/Vector3.cpp index d75bc02a..e5751ac7 100644 --- a/bindings/ruby/sfml-system/system/Vector3.cpp +++ b/bindings/ruby/sfml-system/system/Vector3.cpp @@ -23,22 +23,6 @@ #include "Vector3.hpp" #include "main.hpp" -/* SFML::Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z). - * - * It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc. - * - * This class differs from the C++ version. It will accept any value that is Numeric and both x, y an z must be of the same class. - * - * v1 = SFML::Vector3.new(16.5, 24.0, -8.2) - * v1.z = 18.2 - * y = v1.y - * - * v2 = v1 * v1; - * v3 = SFML::Vector3.new - * v3 = v1 + v2 - * - * different = (v2 != v3); - */ VALUE globalVector3Class; /* Internal function @@ -97,6 +81,7 @@ static void Vector3_internal_ValidateTypes( VALUE aFirst, VALUE aSecond, VALUE a } } +/* */ static VALUE Vector3_Negate( VALUE self ) { VALUE x = rb_funcall( self, rb_intern( "x" ), 0 ); @@ -108,6 +93,7 @@ static VALUE Vector3_Negate( VALUE self ) return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, negatedX, negatedY, negatedZ ); } +/* */ static VALUE Vector3_Add( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector3_ForceType( aRightOperand ); @@ -127,6 +113,7 @@ static VALUE Vector3_Add( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ ); } +/* */ static VALUE Vector3_Subtract( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector3_ForceType( aRightOperand ); @@ -146,6 +133,7 @@ static VALUE Vector3_Subtract( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ ); } +/* */ static VALUE Vector3_Multiply( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector3_ForceType( aRightOperand ); @@ -165,6 +153,7 @@ static VALUE Vector3_Multiply( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ ); } +/* */ static VALUE Vector3_Divide( VALUE self, VALUE aRightOperand ) { VALUE rightVector = Vector3_ForceType( aRightOperand ); @@ -184,6 +173,7 @@ static VALUE Vector3_Divide( VALUE self, VALUE aRightOperand ) return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ ); } +/* */ static VALUE Vector3_Equal( VALUE self, VALUE anArgument ) { VALUE aVector = Vector3_ForceType( anArgument ); @@ -206,6 +196,7 @@ static VALUE Vector3_Equal( VALUE self, VALUE anArgument ) } } +/* */ static VALUE Vector3_StrictEqual( VALUE self, VALUE anArgument ) { VALUE aVector = Vector3_ForceType( anArgument ); @@ -269,19 +260,37 @@ static VALUE Vector3_Initialize( VALUE self, VALUE someArgs ) void Init_Vector3( void ) { - globalVector3Class = rb_define_class_under( GetNamespace(), "Vector3", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* SFML::Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z). + * + * It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc. + * + * This class differs from the C++ version. It will accept any value that is Numeric and both x, y an z must be of the same class. + * + * v1 = SFML::Vector3.new(16.5, 24.0, -8.2) + * v1.z = 18.2 + * y = v1.y + * + * v2 = v1 * v1; + * v3 = SFML::Vector3.new + * v3 = v1 + v2 + * + * different = (v2 != v3); + */ + globalVector3Class = rb_define_class_under( sfml, "Vector3", rb_cObject ); // Instance methods - rb_define_method( globalVector3Class, "initialize", FUNCPTR( Vector3_Initialize ), -2 ); - rb_define_method( globalVector3Class, "eql?", FUNCPTR( Vector3_Initialize ), 1 ); + rb_define_method( globalVector3Class, "initialize", Vector3_Initialize, -2 ); + rb_define_method( globalVector3Class, "eql?", Vector3_StrictEqual, 1 ); // Instance operators - rb_define_method( globalVector3Class, "-@", FUNCPTR( Vector3_Negate ), 0 ); - rb_define_method( globalVector3Class, "+", FUNCPTR( Vector3_Add ), 1 ); - rb_define_method( globalVector3Class, "-", FUNCPTR( Vector3_Subtract ), 1 ); - rb_define_method( globalVector3Class, "*", FUNCPTR( Vector3_Multiply ), 1 ); - rb_define_method( globalVector3Class, "/", FUNCPTR( Vector3_Divide ), 1 ); - rb_define_method( globalVector3Class, "==", FUNCPTR( Vector3_Divide ), 1 ); + rb_define_method( globalVector3Class, "-@", Vector3_Negate, 0 ); + rb_define_method( globalVector3Class, "+", Vector3_Add, 1 ); + rb_define_method( globalVector3Class, "-", Vector3_Subtract, 1 ); + rb_define_method( globalVector3Class, "*", Vector3_Multiply, 1 ); + rb_define_method( globalVector3Class, "/", Vector3_Divide, 1 ); + rb_define_method( globalVector3Class, "==", Vector3_Equal, 1 ); // Attribute accessors rb_define_attr( globalVector3Class, "x", 1, 1 ); diff --git a/bindings/ruby/sfml-system/system/main.cpp b/bindings/ruby/sfml-system/system/main.cpp index cc68a108..105477c5 100644 --- a/bindings/ruby/sfml-system/system/main.cpp +++ b/bindings/ruby/sfml-system/system/main.cpp @@ -27,13 +27,9 @@ VALUE globalSFMLNamespace; -VALUE GetNamespace( void ) -{ - return globalSFMLNamespace; -} - void Init_system( void ) { + /* SFML namespace which contains the classes of this module. */ globalSFMLNamespace = rb_define_module( "SFML" ); rb_define_const(globalSFMLNamespace, "SystemLoaded", Qtrue); Init_Clock(); diff --git a/bindings/ruby/sfml-system/system/main.hpp b/bindings/ruby/sfml-system/system/main.hpp index fbfd888a..286aced3 100644 --- a/bindings/ruby/sfml-system/system/main.hpp +++ b/bindings/ruby/sfml-system/system/main.hpp @@ -25,13 +25,12 @@ #include "ruby.h" -VALUE GetNamespace( void ); - // Ruby initiation function extern "C" void Init_system( void ); typedef VALUE ( *RubyFunctionPtr )( ... ); -#define FUNCPTR( x ) ( reinterpret_cast< RubyFunctionPtr >( x ) ) +#define rb_define_singleton_method( klass, name, func, argc, ... ) rb_define_singleton_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) +#define rb_define_method( klass, name, func, argc, ... ) rb_define_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) #endif // SFML_RUBYEXT_MAIN_HEADER_ diff --git a/bindings/ruby/sfml-window/window/main.cpp b/bindings/ruby/sfml-window/window/main.cpp index e2de8961..8cae5ff3 100644 --- a/bindings/ruby/sfml-window/window/main.cpp +++ b/bindings/ruby/sfml-window/window/main.cpp @@ -42,11 +42,6 @@ VALUE globalStyleNamespace; /* External classes */ VALUE globalVector2Class; -VALUE GetNamespace( void ) -{ - return globalSFMLNamespace; -} - static const char * keyNamesMisc[] = { "Escape", "LControl", "LShift", "LAlt", "LSystem", "RControl", "RShift", "RAlt", "RSystem", diff --git a/bindings/ruby/sfml-window/window/main.hpp b/bindings/ruby/sfml-window/window/main.hpp index 5094cf8c..f3e77023 100644 --- a/bindings/ruby/sfml-window/window/main.hpp +++ b/bindings/ruby/sfml-window/window/main.hpp @@ -25,10 +25,6 @@ #include "ruby.h" -#define SFML_STATIC - -VALUE GetNamespace( void ); - // Ruby initiation function extern "C" void Init_window( void );