Some refactoring, moved C++ allocation into the *_Alloc function instead of directly in new, removed new in most of classes too. Cloning should work on all copyable classes now.
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1802 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0a2abc6933
commit
7d7c4c999f
26 changed files with 235 additions and 301 deletions
|
@ -86,12 +86,10 @@ static VALUE Music_GetDuration( VALUE self )
|
|||
return rb_float_new( object->GetDuration() );
|
||||
}
|
||||
|
||||
static VALUE Music_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE Music_Alloc( VALUE aKlass )
|
||||
{
|
||||
sf::Music *object = new sf::Music();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Music_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
return Data_Wrap_Struct( aKlass, 0, Music_Free, object );
|
||||
}
|
||||
|
||||
void Init_Music( void )
|
||||
|
@ -134,7 +132,8 @@ void Init_Music( void )
|
|||
globalMusicClass = rb_define_class_under( sfml, "Music", globalSoundStreamClass );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 );
|
||||
//rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 );
|
||||
rb_define_alloc_func( globalMusicClass, Music_Alloc );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalMusicClass, "initialize", Music_Initialize, -1 );
|
||||
|
|
|
@ -91,6 +91,16 @@ static VALUE Sound_Initialize( int argc, VALUE *args, VALUE self )
|
|||
return self;
|
||||
}
|
||||
|
||||
static VALUE Sound_InitializeCopy( VALUE self, VALUE aSource )
|
||||
{
|
||||
sf::Sound *selfObject = NULL;
|
||||
Data_Get_Struct( self, sf::Sound, selfObject );
|
||||
sf::Sound *sourceObject = NULL;
|
||||
Data_Get_Struct( aSource, sf::Sound, sourceObject );
|
||||
*selfObject = *sourceObject;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* sound.play()
|
||||
*
|
||||
|
@ -269,12 +279,10 @@ static VALUE Sound_ResetBuffer( VALUE self )
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE Sound_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE Sound_Alloc( VALUE aKlass )
|
||||
{
|
||||
sf::Sound *object = new sf::Sound();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Sound_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
return Data_Wrap_Struct( aKlass, 0, Sound_Free, object );
|
||||
}
|
||||
|
||||
void Init_Sound( void )
|
||||
|
@ -312,10 +320,12 @@ void Init_Sound( void )
|
|||
globalSoundClass = rb_define_class_under( sfml, "Sound", globalSoundSourceClass );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalSoundClass, "new", Sound_New, -1 );
|
||||
//rb_define_singleton_method( globalSoundClass, "new", Sound_New, -1 );
|
||||
rb_define_alloc_func( globalSoundClass, Sound_Alloc );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalSoundClass, "initialize", Sound_Initialize, 0 );
|
||||
rb_define_method( globalSoundClass, "initialize_copy", Sound_InitializeCopy, 1 );
|
||||
rb_define_method( globalSoundClass, "play", Sound_Play, 0 );
|
||||
rb_define_method( globalSoundClass, "pause", Sound_Pause, 0 );
|
||||
rb_define_method( globalSoundClass, "stop", Sound_Stop, 0 );
|
||||
|
|
|
@ -231,12 +231,10 @@ static VALUE SoundBuffer_InitializeCopy( VALUE self, VALUE aSource )
|
|||
*
|
||||
* Creates an sound buffer instance for us.
|
||||
*/
|
||||
static VALUE SoundBuffer_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE SoundBuffer_Alloc( VALUE aKlass )
|
||||
{
|
||||
sf::SoundBuffer *object = new sf::SoundBuffer();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundBuffer_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
return Data_Wrap_Struct( aKlass, 0, SoundBuffer_Free, object );
|
||||
}
|
||||
|
||||
void Init_SoundBuffer( void )
|
||||
|
@ -294,7 +292,8 @@ void Init_SoundBuffer( void )
|
|||
globalSoundBufferClass = rb_define_class_under( sfml, "SoundBuffer", rb_cObject );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 );
|
||||
//rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 );
|
||||
rb_define_alloc_func( globalSoundBufferClass, SoundBuffer_Alloc );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalSoundBufferClass, "initialize", SoundBuffer_Initialize, -1 );
|
||||
|
|
|
@ -126,12 +126,10 @@ static VALUE SoundBufferRecorder_GetBuffer( VALUE self )
|
|||
*
|
||||
* Creates a sound buffer recorder instance for us.
|
||||
*/
|
||||
static VALUE SoundBufferRecorder_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE SoundBufferRecorder_Alloc( VALUE aKlass )
|
||||
{
|
||||
rbSoundBufferRecorder *object = new rbSoundBufferRecorder();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundBufferRecorder_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
return Data_Wrap_Struct( aKlass, 0, SoundBufferRecorder_Free, object );
|
||||
}
|
||||
|
||||
void Init_SoundBufferRecorder( void )
|
||||
|
@ -201,7 +199,8 @@ void Init_SoundBufferRecorder( void )
|
|||
globalSoundBufferRecorderClass = rb_define_class_under( sfml, "SoundBufferRecorder", globalSoundRecorderClass );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalSoundBufferRecorderClass, "new", SoundBufferRecorder_New, -1 );
|
||||
//rb_define_singleton_method( globalSoundBufferRecorderClass, "new", SoundBufferRecorder_New, -1 );
|
||||
rb_define_alloc_func( globalSoundBufferRecorderClass, SoundBufferRecorder_Alloc );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalSoundRecorderClass, "getBuffer", SoundBufferRecorder_GetBuffer, 0 );
|
||||
|
|
|
@ -161,12 +161,10 @@ static VALUE SoundRecorder_GetSampleRate( VALUE self )
|
|||
*
|
||||
* Creates a sound recorder instance for us.
|
||||
*/
|
||||
static VALUE SoundRecorder_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE SoundRecorder_Alloc( VALUE aKlass )
|
||||
{
|
||||
rbSoundRecorder *object = new rbSoundRecorder();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundRecorder_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
return Data_Wrap_Struct( aKlass, 0, SoundRecorder_Free, object );
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
|
@ -250,7 +248,8 @@ void Init_SoundRecorder( void )
|
|||
rb_include_module( globalSoundRecorderClass, globalNonCopyableModule );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalSoundRecorderClass, "new", SoundRecorder_New, -1 );
|
||||
//rb_define_singleton_method( globalSoundRecorderClass, "new", SoundRecorder_New, -1 );
|
||||
rb_define_alloc_func( globalSoundRecorderClass, SoundRecorder_Alloc );
|
||||
rb_define_singleton_method( globalSoundRecorderClass, "isAvailable", SoundRecorder_IsAvailable, 0 );
|
||||
|
||||
// Instance methods
|
||||
|
|
|
@ -237,13 +237,9 @@ static VALUE SoundSource_SetVolume( VALUE self, VALUE aValue )
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE SoundSource_InitializeCopy( VALUE self, VALUE aSource )
|
||||
static VALUE SoundSource_Initialize( VALUE self )
|
||||
{
|
||||
sf::SoundSource *object = NULL;
|
||||
Data_Get_Struct( self, sf::SoundSource, object );
|
||||
sf::SoundSource *source = NULL;
|
||||
Data_Get_Struct( aSource, sf::SoundSource, source );
|
||||
*object = *source;
|
||||
rb_raise( rb_eNotImpError, "Trying to construct instance of abstract class" );
|
||||
}
|
||||
|
||||
static void DefineStatusEnum( void )
|
||||
|
@ -269,7 +265,6 @@ void Init_SoundSource( void )
|
|||
DefineStatusEnum();
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalSoundSourceClass, "initialize_copy", SoundSource_InitializeCopy, 1 );
|
||||
rb_define_method( globalSoundSourceClass, "getAttenuation", SoundSource_GetAttenuation, 0 );
|
||||
rb_define_method( globalSoundSourceClass, "getMinDistance", SoundSource_GetMinDistance, 0 );
|
||||
rb_define_method( globalSoundSourceClass, "getPitch", SoundSource_GetPitch, 0 );
|
||||
|
|
|
@ -287,12 +287,11 @@ static VALUE SoundStream_Initialize( VALUE self, VALUE channelsCount, VALUE samp
|
|||
return self;
|
||||
}
|
||||
|
||||
static VALUE SoundStream_New( int argc, VALUE *args, VALUE aKlass )
|
||||
static VALUE SoundStream_Alloc( VALUE aKlass )
|
||||
{
|
||||
rbSoundStream *object = new rbSoundStream();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundStream_Free, object );
|
||||
object->Init( rbData );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
|
@ -361,7 +360,8 @@ void Init_SoundStream( void )
|
|||
rb_include_module( globalSoundStreamClass, globalNonCopyableModule );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalSoundStreamClass, "new", SoundStream_New, -1 );
|
||||
//rb_define_singleton_method( globalSoundStreamClass, "new", SoundStream_New, -1 );
|
||||
rb_define_alloc_func( globalSoundStreamClass, SoundStream_Alloc );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalSoundStreamClass, "initialize", SoundStream_Initialize, 2 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue