Re: Object Persistence for a MUD



On Sat, Oct 4, 2008 at 8:46 PM, Brent Dillingham
<brentdillingham@xxxxxxxxx> wrote:
Hi all,

For fun, I'm writing a MUD with Ruby. I thought I'd query the hive
mind here and ask some opinions on what library I might use for object
persistence -- that is, storing objects like players and rooms
somewhere.

I could do something really simple like store everything in YAML, I
could try DRb, or I could go all out and use an ORM like DataMapper...
DataMapper is the first route I took, but I soon realized that I'll
have to be really careful when using a lot of the ORM niceties while
still ensuring that a database row only every represents one object in
memory. i.e.:

# assuming Player has_one :room ...

player = Player.get(1) # get Player with ID=1
player.room # the player's current Room association

... player logs out, logs back in later ...

player.room

Oh noes! The ORM fetches the same room from the DB, but creates a
totally new object to represent it. Two players could be in the same
room ID, but actually reference different objects, and thus couldn't
see or interact with one another. Bad.

This problem is hackable by carefully keeping a cache of loaded
objects -- but might end up negating the value of using an ORM like
DataMapper. So, any suggestions out there of what I might do instead?

There are probably a hundred different ways to approach this. I've
never programmed a MUD, but after playing around with the Sequel gem
and Postgresql, I had a simple map with locations, players, and
objects. I updated the DB on the fly, but I'm sure there are other
paradigms.

Very, very simple example...

sql...

create database mud;

create table map (
x int not null,
y int not null,
synopsis varchar not null,
description varchar
primary key (x, y)
);

create table people (
name varchar not null primary key,
xcurrent int not null,
ycurrent int not null,
foreign key (x, y) references map (x, y)
);

insert into map values (0, 0, 'start');
insert into map values (1, 0, 'hallway');
insert into people values ('Loki', 1, 0);
insert into people values ('Thor', 0, 0);
insert into people values ('Freya', 1, 0);

...ruby...

require 'rubygems'
require 'sequel'
Area = Struct.new(:description, :synopsis, :x, :y)
DB = Sequel.connect("postgres://user_name:password@localhost:5432/mud")

#print everyone in the hallway...

DB[:map].join(:people, :xcurrent => :x, :ycurrent => :y).where (:x =>
1, :y => 0).all.each {|row| p row[:name]}

#=> Loki
#=> Freya


Todd

.



Relevant Pages

  • [Review] Age of Steam Expansion: 1830s Pennsylvania / Northern California
    ... Allentown on the map. ... but also extremely non-recommended for new players. ... likely lose the game. ... importance of the black cubes and get soundly defeated as the game ...
    (rec.games.board)
  • Re: I hate chronic camping!
    ... But when you're a one-on-one scenario, sniping the enemy from the other side of the map doesn't strike me as particularly interesting or worth the time of both the sniper and the... ... Other times, I'll want to get that Redeemer nuke from the top of the tower-- which means going for the flying vehicles, the Raptors. ... other players may like flying Raptors because they like the dogfights with the other team's Raptors. ...
    (comp.sys.ibm.pc.games.action)
  • Team Sport/Arena Roguelikes
    ... inclusion of other players. ... Even the MUD ... If the design were smooth enough then people ... could just hop onto an ongoing game as subordinates -- a good excuse ...
    (rec.games.roguelike.development)
  • HOMM 4 : "Disenchanted Forest" User-Map Review
    ... Matthew Charlap, the Qurqirish Dragon, proudly presents journal entry ... Gathering Strom map. ... players were quite strong when I finally entered their area. ... clutter which detracted from my enjoyment of the map. ...
    (comp.sys.ibm.pc.games.strategic)
  • RECRUITING: [custom] TraceMUD Development Seeks Developers/Programmers
    ... First off, what is TraceMUD? ... A wide range of skills are currently ... The MUD itself will be built from the ground up, ... the program will flow, how it will handle basic input from players, and ...
    (rec.games.mud.announce)

Loading