[Finished] [RGSS] Ruby/C++ Interfaces

Started by Blizzard, March 15, 2011, 03:50:54 pm

Previous topic - Next topic

Blizzard

March 15, 2011, 03:50:54 pm Last Edit: September 10, 2011, 03:26:23 am by Blizzard
Ruby/C++ Interfaces




Description

The C++ classes have to be interfaced to Ruby. I have already created an interface for the Color class. Here is some important information.

1. In the header of the file there is a definition for Ruby's Class instance. The naming convention (taken from the documentation) is rb_cCLASSNAME and rb_mMODULENAME. Like in the Color class, add an "extern VALUE NAME;" in the header and a "VALUE NAME;" in the source file. You will notice the rb_cColor variable.

2. Each class and module needs to have a "static void createRubyInterface()" method declared in the header and implemented. I have added this method for every RGSS class, you have to implement it.

3. You can find out all necessary calls here: http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html#S8

4. Don't bother too much with methods that have default arguments or have overloaded definitions (meaning there are several functions with the same number, but different arguments). Just put the normal number of arguments there. I will take care of rewriting the code so it works with any number of arguments. Of course, if you want to learn a bit more, you can do that yourself anyway. I have already implemented Color::initialize and Color::set in that way.

5. Don't forget to use the conversion marcos like INT2NUM or rb_float_new if you define interfaces constants and class variables.

6. Every method HAS TO return a VALUE. If not actual value is returned in C++, then the return value is Qnil. Again. Refer to the Color class. The first Argument is "VALUE self" and that one is never counter when using interface definitions like rb_define_method. Just compare the actual methods and the interface definitions in Color.

7. You don't have to implement the methods. You just have to add the interface calls and edit the method declarations so they can work with Ruby.

8. All methods are static.

9. Be careful with getters and setters. For attr_reader, attr_writer and attr_accessor you can simply use something like "rb_define_attr(rb_cColor, "red", 1, 0);" where the 3rd argument sets read access (0 for no, 1 for yes) and the 4th argument sets write access (0 for no, 1 for yes). Basically using 1, 0 is attr_reader; 0, 1 is attr_writer and 1, 1 is attr_accessor.



Priority

Critical. Before this task is completed, not further development can be done.



Prerequisites

None.



Assigned

ForeverZer0
game_guy
Ryex



Everything else

I have also interfaced Graphics and Input so you can get more examples there.

There are many classes, make sure you do them one by one and post here which are done so the others don't do your work as well.
Always refer to Graphics, Input and Color if you get stuck. If you still can't figure out how to do things, post. Since you all know Ruby, most things should be clear or you should at least be able to figure it out easily.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Don't expect anything from me right away. Still trying to get the hang of this. I'm not gonna stop trying though :3

Blizzard

That's why I made this task for you guys. That way you can learn something and be useful. :)
Take your time. I probably won't have time to work on this anymore till the weekend.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

Well, I'm gonna tackle the "Window" class. My take me little bit...

* crosses fingers *
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

G_G

I'm gonna try viewport. By the way I have no idea on how to test this O_O

ForeverZer0

March 15, 2011, 07:52:29 pm #5 Last Edit: March 16, 2011, 12:19:55 am by ForeverZer0
I consider a being able to Build a success.  :P

Seriously, though, after a few minutes studying Blizz's examples and reading the link he gave, its actually not too difficult. I'm just gonna take my time and try not to screw it up.

EDIT:
Okay, I have finished Window class as far as I know how. I am still unsure as to how to implement the "update", "dispose", and "disposed?" methods on the C++ side, but all all other variables/methods are interfaced. I think I even did it right!

Until Blizz is around to explain them couple methods I was unsure of, I'm going to move on to the "Sprite" class.

EDIT 2:
Sprite class is done. Going for the Audio module next.

EDIT 3:
Audio module is interfaced. Actual implementation is still missing, but I imagine we will be expanding on this module a lot before were done.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

Yeah, you don't have to add the implementation.

F0, you can test it easily. Just open test.rb, add some Ruby regarding that class and see how it works. Obviously you won't be able to test Sprite or something like that, but you can test Tone if you implement it similar to Color.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

I'm gonna take on tone and viewport. No one else do those >:U I'll kill you!

Ryex

Zer0 something you did in your implementation of the window class has made the project impossible to build and then run, it causes an access violation. I would go through it and fix it but I don't really have time...
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

March 16, 2011, 11:03:31 am #9 Last Edit: March 16, 2011, 11:33:21 am by ForeverZer0
Not sure exactly how. It doesn't actually implement anything yet. I'll check it out soon as I get off work and see what I can figure out.

EDIT:
I looked at it real quick, and I did find one obvious error that I made (fixed). I had copy-pasted a line of code from the Color class to use as a template and save two seconds of typing. It turns out that I had forgot to set the initialize method to call the from the Window class. It was still calling from the color class. Oops.

I did this on my work computer, which I have the project on, but not VS, so I really can't re-compile and test it out. If someone tests it out before I get a chance to, let me know if that fixed it.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I have changed the implementation of Color to some degree. The previous implementation was actually creating Ruby objects and thus should be slower. The current implementation is pure C++ and is only interfaced by Ruby. Also, Ruby takes care of the garbage collection.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: game_guy on March 16, 2011, 08:04:39 am
I'm gonna take on tone and viewport. No one else do those >:U I'll kill you!


I just wanna make sure this is left for me so I don't feel utterly useless when I come back....

ForeverZer0

I haven't touched it. Was tempted to, but didn't. I've been busy with some other stuff the past day or so, so take what time you need.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

March 18, 2011, 05:27:45 am #13 Last Edit: March 19, 2011, 12:04:09 pm by Blizzard
F0, I noticed that you already implemented some methods. I suggest that you don't do that before all classes have been interfaced. Also, I was getting a crash during one of the createRubyInterface methods. I'll go check why.

EDIT: Found it, fixed it. BTW, there is no need for argument errors. It seems that rb_scan_args does that automatically. :) And it's even better than RGSS's default because it tells you something like ArgumentError (2 for 3..4).

EDIT: Alright, I have additionally implemented Tone and Rect so you have even more examples for the interfaces.

EDIT: I haven't seen much SVN activity from you guys in the past few days. Are you having troubles with the code? I realize that there has been a lot of new code and stuff that you probably don't understand. I am asking because this task is critical after all.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

sorry. I was drowning in work. I'm on spring break now so expect a lot of activity from me over the next week.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

March 19, 2011, 10:43:07 pm #15 Last Edit: March 19, 2011, 11:42:34 pm by ForeverZer0
I've been playing around on new PC and getting it all set up. Will get busy.  ;)


EDIT: I'm gonna start interfacing the Bitmap class.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

G_G

Leave viewport for me. Slowly getting it done with the time I do have.

ForeverZer0

I committed Bitmap and now I'm in dire need of some sleep. Will start something else in the morning.
Everything compiles okay, and I'm pretty sure its right, but if I am making any mistakes can someone (looks at Blizzard) let me know.
Otherwise I'm just keep doing how I did the Bitmap class.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I'll see if I can take a look at the Bitmap class later today and let you know. Though, in the meantime you could check if you are following the coding convention.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

March 20, 2011, 06:21:18 pm #19 Last Edit: March 20, 2011, 07:41:38 pm by Ryex
with the Table class we are storing the table in an dynamic array on the c++ side. how do we make sure it gets destroyed when the ruby object is destroyed?

Table should be done.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />