The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Internet Blogs - Blog Top Sites

Site Hits

Total: 2,502,482
since: 19 Jan 2005

Using Ruby as the driving script for my game server?

posted Mon 02 Oct 06

So the other day I was thinking about how I was going to design the schema for the Ulysses Agenda game's server-side database, and then I had a revalation! I wanted pizza! But after I had that revalation, something else dawned on me! I was trying to think of how to store all the data, such as the ship types, the star dock types, the resource/mineral types, etc.. Then I began to think that schemas are just so restrictive, what if people want to expand the functionality of the game? Then I thought... code is data...data is code... Ruby? hell yes.

Before I launch into a tyrade about how ridiculously cool Ruby is and how appropriate it is for what I want to do, I want to provide some background. Back in the good old days, when I was skipping class at University in order to write code for a MUD, I was writing in LPC. Basically what this meant was that the LPMud GameDriver was written in C and ran on a Unix box, and the core networking and File I/O structure was available in a functional API to code written in LPC, a C-like psuedo-object-oriented language that I have always loved. In LPC, you had .c files that represented your "object" hierarchy... so you started off with /std/object.c and derived into things like /std/mobile/player.c and /std/container.c which had child classes such as room.c and player.c since both room and player could have inventories. LPC supports multiple inheritance, and you might code a room that looks something like this:

#include "domain.h"
#include <stdproperties.h>
#include <room.h>

inherit BASE_ROOM;

object knight;

void create_room()
{
    set_short("Room");
    set_long("This is a room. It looks like there's a room to the north.\n");

    add_exit("north", "north_room.c");
}

void reset_room()
{
    if (!knight)
    {
       knight = clone_object(MYDOMAIN + "/npcs/knight.c");
       knight->move(this_object());
       knight->say("Bow before me, you pitiful creatures!");
    }
}

void onenter(object player)
{
    tell(player, "Welcome to my room, " + player->query_race());
}

I am taking some liberties here since it has been a LONG time since I've actually coded any LPC. This was all great and wonderful...but it was a long time ago, and things have come a long way. For example, we now have an object-oriented programming language that sports all the power and flexibility of a pure-functional language like Python or F# as well as full support for object-oriented patterns such as inheritance, polymorphism, encapsulation, etc.

What if, instead of creating this stuffy mySQL or SQL 2005 schema and forcing all of the data into rows and columns, the world itself was defined as an object model scripted in Ruby. This would not only allow for the power of inheritance and instantiation, but data could be stored and state maintained via serialization, and people who got the game could extend and modify the game using the low-barrier-to-entry language of Ruby instead of worrying about compiling with VS 2005 and learning C# and the ins and outs of WCF. What if, just what if, you could create a Star dock called Joe's StarBar and Grill using Ruby and still have the entire Peer-to-Peer networking engine managed using the CLR and Windows Communication Foundation, bridging the top-tier "world script" in Ruby to .NET using RubyCLR? 

# Ruby... its solid beef, baby!

require 'ulyssescore'
require 'stardock'
require 'commerce'

class StarDockAlpha < UlyssesCore.StarDock
  include Store
  include LocalWiki
  include RoomChat

  def initialize
    self.dockname = "Joe's StarDock and Grill"
   
    # set profit margin by Store mix-in
    self.profitmargin = .3

    # set wiki post limit by LocalWiki mix-in
    self.wikilimit = 12

    # set room name for RoomChat mix-in
    self.chatroomname = "joes_stardock_and_grill"
  end
end

And then, out in space, say in Sector 12, you might have code to create an instance of this star dock and place it in the list of objects floating around in the sector:

dock = StarDockAlpha.new
@localobjects.Add(dock,  SpaceCoordinate.new(3,0,4)) # at point (3,0,4) within this sector

If you are sitting there saying OMFG, the potential uses for running Ruby on top of the CLR to enable scripted access to lower-level concepts such as WCF peer-to-peer networking, then I hear ya brother. If not, then you've got no business reading this blog and go back to the stone age where you belong :)

Mix-ins take care of needing Multiple inheritance (which Ruby doesn't actually support) that I had available to me via the psuedo-OOP LPC language. Ruby itself takes care of the simplicity of coding up new content, I just create files in a directory and the main game engine takes care of spawning off all the right objects. The Ruby core would listen to WCF events and take appropriate action, and would also translate the appropriate Ruby methods like Player#tell or Game#broadcast and everything would be, in my opinion, on a level of kick-ass on which my code has never before existed.

Thoughts? 

tags:                  

links: digg this    del.icio.us    technorati    reddit




1. Craig left...
Mon 02 Oct 06 10:00 am

ok a few things, ruby hmm I prefer python I just wish they'd get with the times, TG is nice but ROR is better.

Isn't the entity framework + linq better? If you store data in object form and let something else handle your db storage - what happens if you refactor your objects, how does it handle the data? I missed the jump in your article from object/data storage to the CLR/Networking etc. Maybe my ship doesn't get that channel :)

-c

ps: I wish your blog was correctly visible in IE7 - is that your providers fault or MS's? ;)


2. Craig left...
Mon 02 Oct 06 10:06 am

are you done with the book yet?


3. Kevin Hoffman left...
Mon 02 Oct 06 12:40 pm

Not done with the book...which is why its taking so bloody long to do all my fun stuff. I like Ruby just from an aesthetic point of view - people could argue that Python is as good or better for this purpose. Entity Framework and LINQ only allow me to store _data_, they don't let the people who use my game write their own custom code. For example, you can't use LINQ to make it so that when Joe Admin gets my game, he wants to write a quest that will reward the player with XP for picking up a famous dignitary from planet Y and delivering them to planet Z. Thats what you can't do with pure data, but you can do with Ruby.


4. Kevin Hoffman left...
Mon 02 Oct 06 12:41 pm

My blog look and feel template is a stock one provided by my host - I don't have control over its IE 7 visibility. Btw, IE7 in its current form screws up all kinds of CSS that it shouldn't screw up by the time it RTMs.


5. Craig left...
Mon 02 Oct 06 12:44 pm

ahh ok I see now, I didn't realise it was a script for the game I guess thats what the title says too ;)


Tag Related Posts

MobileMe vs. Live Mesh Throwdown - Round 1

Wed 16 Jul 08 10:33 A GMT-05

One Framework to Rule them All

Mon 25 Feb 08 6:49 P GMT-05

CLINQ v1 Demo - Network Message Filtering

Wed 09 Jan 08 7:47 P GMT-05
tags:        

Building a Ledger Style for WPF Grids

Tue 21 Aug 07 3:30 P GMT-05
tags:    

My first "Acropolis" Application

Mon 04 Jun 07 1:40 P GMT-05
tags:      

Exploring the Delegate Design Pattern

Mon 14 May 07 6:30 P GMT-05

Orcas' Hidden Gem - The managed PNRP stack

Fri 11 May 07 6:45 P GMT-05
tags:        

Will Silverlight be DOA?

Mon 16 Apr 07 8:02 P GMT-05

Exploring the MVC Pattern in WPF

Tue 10 Apr 07 12:51 P GMT-05
tags:                      

My Little Pony .NET Unleashed 2007

Fri 30 Mar 07 1:59 P GMT-05

Authorness

Thu 15 Mar 07 1:44 P GMT-05

WPF Bindings == WTF Bindings?

Mon 12 Mar 07 6:31 P GMT-05

On MUDs

Thu 08 Mar 07 5:00 A GMT-05
tags:                    

Cocoa Programming vs. WPF : NIB vs XAML

Tue 20 Feb 07 2:09 P GMT-05

Cocoa Bindings vs. WPF Binding

Thu 15 Feb 07 5:41 P GMT-05
tags:                

What I think is a bug in WCF POX messaging

Thu 04 Jan 07 4:58 P GMT-05
tags:      

WPF Bumper Stickers

Tue 12 Dec 06 7:32 P GMT-05

Ulysses Agenda Makes Redmond Developer News

Wed 29 Nov 06 7:10 P GMT-05
tags:                

Ulysses Agenda - Network Engine Test 1

Mon 09 Oct 06 2:26 A GMT-05
tags:              

ASP.NET vs Ruby on Rails : Round 2 (Agility)

Thu 05 Oct 06 11:02 A GMT-05
tags:                      

ASP.NET vs Ruby on Rails : Round 1

Wed 04 Oct 06 1:37 P GMT-05
tags:                

Ulysses Agenda : First Cut Networking Design

Thu 14 Sep 06 12:46 A GMT-05
tags:                  

First Impressions of Windows Vista RC1

Thu 07 Sep 06 1:30 P GMT-05
tags: