Tuesday, 7 September 2010

Roguelike MUD progress #4

Previous post: Roguelike MUD progress #3

Almost no progress on the game today. Instead, I was distracted by two different problems with my code reloading framework. Link to SVN revision.

  1. Use of slots:
    class Tile(object):
    __slots__ = [ "character", "fgColour", "bgColour", "flags" ]
    This also seems to be an unsolved problem in the xreload module, which was written for normal Python namespaces.

    TypeError: descriptor 'flags' for 'Tile' objects doesn't apply to 'Tile' object

    I've not got any better ideas, and I am only using __slots__ for the sake of it. So the solution is to stop using them.

  2. File-local instances of the classes it defines:
    START_TILE = Tile("x", isMarker=True)
    SPAWN_TILE = Tile("s", isMarker=True)
    WALL_TILE = Tile("X", isPassable=False, isOpaque=True)
    WALL1_TILE = Tile("1", isPassable=False, isOpaque=True)
    WALL2_TILE = Tile("2", isPassable=False, isOpaque=True)
    DOOR_TILE = Tile("D")
    FLOOR_TILE = Tile(" ")

    mapTilesByCharacter = {}
    def IndexTiles():
    for k, v in globals().iteritems():
    if k.endswith("_TILE"):
    mapTilesByCharacter[v.character] = v

    CHAR_TILE_TEMPLATE = Tile("@", isPassable=False)
    DRAGON_TILE = Tile("&", isPassable=False)
    I've had to use a custom framework that has xreload-based code reloading, and encountered this same scenario there. In that case, it was because the class was registered with a external factory and subsequently used to churn out bad instances. These then hit the following error.

    unbound method BLAH must be called with BLAH instance as first argument (got BLAH instead)

    Solving that leaked class problem was simple, through locating the references to the throwaway new class, and substituting the old reference for them. Replacing instances though, is a little more complicated.

    This error has gone away in 3.x I am told, which is a pity. As it serves as a good indication that there instances or class references have leaked outside of the code reloading system.
Chances are that I am going to have to try and solve these cases for xreload, as well as in my custom framework.

Next post: Roguelike MUD progress #5

No comments:

Post a Comment