Forum: IronRuby Xna+IronRuby+RubyNewb=headache

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gabriel R. (Guest)
on 2008-11-14 19:00
Hi
I'm tiring to run a whole XNA game from IronRuby but I'm having some
trouble translating the code from c# to ruby. That might be because I'm
really new at Ruby.
here is what I wrote so far
Game = Microsoft::Xna::Framework::Game
GraphicsDeviceManager = Microsoft::Xna::Framework::GraphicsDeviceManager
Graphics=Microsoft::Xna::Framework::Graphics
class Game1 < Game

def Game1
graphics = GraphicsDeviceManager.new this
end

def Initialize

super
#is this ok?
#in C# i have base.Initialize()
end
#is this ok?
#in C# i have protected override void Draw(GameTime gameTime)
def Draw
Game::GraphicsDevice.Clear Graphics::Color.CornflowerBlue #i don't think
this is is how to access the colour struct
super gameTime
#is this ok?
#in C# i have base.Draw(gameTime)
end
end

game = Game1.new
game.run

ps:allso posted on the Rubyforge page:
http://rubyforge.org/forum/forum.php?thread_id=296...
Orion E. (Guest)
on 2008-11-15 01:39
(Received via mailing list)
On 15/11/2008, at 6:00 AM, Gabriel R. wrote:

> Hi
> I'm tiring to run a whole XNA game from IronRuby but I'm having some
> trouble translating the code from c# to ruby. That might be because
> I'm
> really new at Ruby.
> here is what I wrote so far
> Game = Microsoft::Xna::Framework::Game
> GraphicsDeviceManager =
> Microsoft::Xna::Framework::GraphicsDeviceManager
> Graphics=Microsoft::Xna::Framework::Graphics

You can avoid all this by writing

include Microsoft::Xna::Framework

it's more-or-less the equivalent of using namespace

>
> class Game1 < Game
>
> def Game1
> graphics = GraphicsDeviceManager.new this
> end

Ruby uses 'self' instead of 'this', and constructors are always def
initialize, not def ClassName

>
>
> def Initialize
>
> super
> #is this ok?
> #in C# i have base.Initialize()
> end

Yep super should be fine

>
> #is this ok?
> #in C# i have protected override void Draw(GameTime gameTime)
> def Draw

In ruby you should have def draw(game_time)

>
> Game::GraphicsDevice.Clear Graphics::Color.CornflowerBlue #i don't
> think
> this is is how to access the colour struct

Not sure off the top of my head but I think it should be
Color::CornflowerBlue

>
> super gameTime

That should be fine. Normally in ruby you don't need to pass arguments
to calls to super, but I'm not sure how IronRuby handles this when
interopping with the CLR...

>
> #is this ok?
> #in C# i have base.Draw(gameTime)
> end
> end
>
> game = Game1.new
> game.run
>

Last 2 lines look fine :-)

I'd really suggest you stop and step back a bit, and learn some of the
basics of the ruby programming language.
Also note that C# uses UpperCamelCase for everything, whereas ruby
uses lower_snake_case for everything (except class names)

IronRuby will translate these for you, so if you have a C# method
called MoveAllZig(), then ruby code to call that will be move_all_zig

Good luck!
Gabriel R. (Guest)
on 2008-11-15 02:04
Thanks mate I'll put you suggestions to the test in the morning.
Oh and I'm sort of using this as a pretext to learn some Ruby,
also been playing with Hackety Hack but I don't think I can larn the
ruby way
of OOP form it so I'm going for trial and error and forum.
Thanks again.
Gabriel R. (Guest)
on 2008-11-19 23:52
Everything works great
Made a little c# loader app to hide all of the require and include
statements.
Orion E. wrote:
> ... and constructors are always def initialize, not def ClassName
There is a problem in the fact that Xna has a function that is called
every time the graphics device is lost(ex:alt+tab) and then returned
witch is called Initialize() this function is basically responsible for
initializing the main GraphisDevice object.
Is there a way to call this function?
Curt H. (Guest)
on 2008-11-20 02:41
(Received via mailing list)
I'm not entirely sure I understand the problem, but "Initialize" is the
one CLR method name that we don't mangle.  Is this a Ruby class that
you've derived from an XNA type or just the XNA type directly?
Orion E. (Guest)
on 2008-11-20 03:54
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Curt H. (Guest)
on 2008-11-20 04:17
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Gabriel R. (Guest)
on 2008-11-20 16:00
Curt H. wrote:
Hi
> Is this a Ruby class that you've derived from an XNA type or just the XNA type > 
directly?
Well making a game using Xna basically meas inheriting the Game class
present in Xna and implementing it's methods so yes it's a ruby class
that gets derived from the Microsoft.Xna.Framework.Game class.
The structure required by your main game class is as follows:

-the constructor witch in c# is identified by the class name and in ruby
as initialize
-the graphic initialization/reinitialization method identified by the
name "Initialize", this is the one that is making problems.
-methods for both loading and unloading content
-an update method and a draw method witch make up the actual game loop.

So again my question is how can I call the graphics initialization
function "Initialize", from Ruby, when it has the same name as a ruby
constructor.
Curt H. (Guest)
on 2008-11-20 16:56
(Received via mailing list)
There shouldn't be a conflict in recent versions of IronRuby.
"Initialize" != "initialize" now.
Tomas M. (Guest)
on 2008-11-20 20:00
(Received via mailing list)
Note that "initialize" (lower-case) doesn't manifest itself as a CLR
constructor for the derived class. The derived Ruby class is currently
represented by a CLR type that has a single ctor taking RubyClass. We
are working on improving .NET interop here.

Tomas
Gabriel R. (Guest)
on 2008-11-20 22:07
Curt H. wrote:
> There shouldn't be a conflict in recent versions of IronRuby.
> "Initialize" != "initialize" now.
Ok so I used the Upper cased Initialize and I get this exception:
" wrong number or type of arguments for `Initialize' "
but Initialize doesn't accept any parameters.

Note there might be something wrong with the code I wrote if someone
thinks that I will make the source available
Gabriel R. (Guest)
on 2008-12-15 04:27
Attachment: Opal.zip (0 Bytes)
Here is the source
Can anyone figure why it won't work?
Curt H. (Guest)
on 2008-12-15 20:15
(Received via mailing list)
It would probably be useful if you could describe more specifically what
isn't working.
Gabriel R. (Guest)
on 2008-12-15 21:41
As you say "Initialize" is different from "initialize"
so I have the the constructor:

 def initialize
 graphics = GraphicsDeviceManager.new self
 super
 end

witch works
and then i have the Initialize procedure

 def Initialize
 super
 end

witch manages the actual 3d viewport, it is called every time the 3d
viewport needs reinitialization(like an ALT+TAB) when I try to run the
script I get:
" wrong number or type of arguments for `Initialize' "
the thing is Initialize doesn't have any parameters, is it still being
treated as a constructor?
Dudu Baião (Guest)
on 2008-12-15 22:42
(Received via mailing list)
I've already posted about this issue weeks ago. I was playing iwth XNA
too.

The IronRuby it's not passing correctly the parameters for the super
class methods.


2008/12/15 Gabriel R. <removed_email_address@domain.invalid>:
Gabriel R. (Guest)
on 2008-12-15 22:48
Dudu Baião wrote:
> The IronRuby it's not passing correctly the parameters for the super
> class methods.

That is a bummer :(
Hopeful IronRuby will improve over time.

Guess I'll try with IronPython
Curt H. (Guest)
on 2008-12-16 07:21
(Received via mailing list)
IronRuby is still in "alpha".  CLR interop is a place we know is still
particularly weak.  IronPython just released version 2.0, and is
considerably more mature.  If your goal is to have a fairly polished
dynamic language that runs on .NET, then IronPython is probably a better
choice.  If you like Ruby and don't mind a few hiccups, then your
willingness to file problem reports for issues that you find will be of
great help to us.

Things are likely to be a bit slow over Christmas, but I'll see if I can
get this fixed before the end of the year.
Dudu Baião (Guest)
on 2008-12-16 12:24
(Received via mailing list)
Thanks Curt! I'll be waiting for. :)

2008/12/16 Curt H. <removed_email_address@domain.invalid>:
Gabriel R. (Guest)
on 2008-12-16 15:50
Curt H. wrote:
> ...
>If you like Ruby and don't mind a few hiccups, then your
>willingness to file problem reports for issues that you find will be of
>great help to us.
Ruby is great, all though I'm new to the language I have grown attached
to it.
I'll try to give my feedback to the best of my ability because it
deserves it.
>...
> Things are likely to be a bit slow over Christmas, but I'll see if I can
> get this fixed before the end of the year.

I can't wait for the fix. And a wish of "Happy Hollydays" to the whole
Iron Ruby team and to the users of this discussion board.
This topic is locked and can not be replied to.