Over the weekend Glyph and I had another brief hack session on Imaginary. We continued our efforts towards fixing the visibility problem I’ve described over the last couple of posts. This really was a brief session but we took two excellent steps forward.
First, we made a big chunk of progress towards fixing a weird hack in the garment system. If you recall, I previously mentioned that the way
obtain works in Imaginary now, the system will find two links to a hat someone is wearing. In a previous session, Glyph and I removed the code responsible for creating the second link. This was a good thing because it was straight-up deletion of code. The first link still exists and that’s enough to have a path between an observer and a hat being worn by someone nearby.
The downside of this change is that the weird garment system hack was getting in the way of that remaining link being useful. The purpose of the hack was to prevent hats from showing up twice in the old system - once for each link to them. Now, with only one link, the hack would sometimes prevent the hat from even showing up once. The fix was fairly straightforward. To explain it, I have to explain annotations first.
As I’ve mentioned before, Imaginary represents a simulation as a graph. One powerful tool that simulation developers have when using Imaginary is that edges in the graph can be given arbitrary annotations. The behavior of simulation code will be informed by the annotations on each link along the path through the graph the simulation code is concerned with. Clear as mud, right?
Consider this example. Alice and Bob are standing in a room together. Alice is wearing a pair of white tennis shoes. Alice and Bob are standing in two parts of the room which are divided from each other by a piece of red tinted glass. A realistic vision simulation would have Bob observing Alice’s shoes as red. Alice, being able to look directly at those same shoes without an intervening piece of tinted glass, perceives them as white. In Imaginary, for Bob to see the tennis shoes, the vision system uses
obtain to find the path from Bob to those shoes. The resulting path necessarily traverses the
Idea representing the glass - the path looks very roughly like Bob to glass to Alice to shoes. The glass, being concerned with the implementation of tinting for the vision system, annotates the link from itself to Alice with an object that participates in the vision simulation. That object takes care of representing the spectrum which is filtered out of any light which has to traverse that link. When the vision system shows the shoes to Bob, the light spectrum he uses to see them has been altered so that he now perceives them as red.
Clearly I’ve hand-waved over a lot of details of how this works but I hope this at least conveys the very general idea of what’s going on inside Imaginary when a simulation system is basing its behavior on the simulation graph. Incidentally, better documentation for how this stuff works is one of the things that’s been added in the branch Glyph and I are working on.
Now, back to hats. The hack in the garment system annotates links between clothing and the person wearing that clothing. The annotation made the clothing invisible. This produced a good effect - when you look around you, you’re probably not very interested in seeing descriptions of your own clothing. Unfortunately, this annotation is on what is now the only link to your clothing. Therefore, this annotation makes it impossible for you to ever see your own clothing. You could put it on because when you’re merely holding it, it doesn’t receive this annotation. However, as soon as you put it on it vanishes. This poses some clear problems: for example, you can never take anything off.
The fix for this was simple and satisfying. We changed the garment system so that instead of annotating clothing in a way that says “you can’t see this” it annotates clothing in a way that merely says “you’re wearing this”. This is very satisfying because, as you’ll note, the new annotation is a much more obviously correct piece of information. Part of implementing a good simulation system in Imaginary is having a good model for what’s being simulated. “Worn clothing is worn clothing” sounds like a much better piece of information to have in the model than “Worn clothing can’t be seen”. There’s still some polish to do in this area but we’re clearly headed in the right direction.
By comparison, the second thing we did is ridiculously simple. Before Imaginary had
obtain it had
search. Sounds similar (well, maybe…) and they were similar (well, sort of…).
search was a much simpler, less featureful graph traversal API from before Imaginary was as explicitly graph-oriented as it is now. Suffice it to say most of what’s cool about Imaginary now wasn’t possible in the days of
obtain was introduced,
search was re-implemented as a simple wrapper on top of
obtain. This was neat - both because it maintained API compatibility and because it demonstrated that
obtain was strictly more expressive than
search. However, that was a while ago and
search is mostly just technical baggage at this point. We noticed there were only three users of
search left (outside of unit tests) and took the opportunity to delete it and update the users to use
obtain directly instead. Hooray, more code deleted.
Oh, and I think we’re now far enough beneath the fold that I can mention that the project has now completed most of a migration from Launchpad to github (the remaining work is mostly taking things off of Launchpad). Thanks very much to ashfall for doing very nearly all the work on this.