Up to Main Index Up to Journal for March, 2017 JOURNAL FOR SUNDAY 12TH MARCH, 2017 ______________________________________________________________________________ SUBJECT: Zoning out & detecting cyclic inventories DATE: Sun 12 Mar 15:27:55 GMT 2017 After the initial frustrations of trying to sort out some issues with the zones package I went away to give the problem a good hard thinking. I then spent Wednesday and Thursday of this week practically rewriting the zones package. As a consequence I also needed to make some other improvements. All Things that are put into an Inventory now have a Locate attribute added automatically. A Locate attribute is simply a back reference to the Inventory a Thing is in. Before this only Things that wanted to know where they were had a Locate attribute. One implication of this is that it's now possible to detect cyclic references. For example, we can now detect and prevent putting A into B into C into A. We can also detect putting B into A, A into C and then trying to add C into B. Yes, just thinking about this can make your head hurt. This works for both Inventory and Location fields on non-locations in zone files. The zone loader itself now works in a totally different way than before. First of all it unmarshals all of the locations into the world and all non-locations into a temporary storage area. Each Thing unmarshaled is tagged with its record from the zone file as a kind of metadata. The loader then links up all of the things in the temporary storage area using pointers according to the Inventory and Location references. For example, say we have two boxes A and B. Say we also have a runestone. We can put the runstone into both box A and box B at the same time - it's just pointers. The loader then makes sure all locations have an inventory and links up all of the location exits in the world. Next the loader goes through all of the locations looking for Inventory references and COPIES items from the temporary storage area. The important bit here is that copies are put into the world. Back to our box example. We copy box A into the world and copy it's inventory - which produces a copy of the runestone. We then copy box B into the world and copy it's inventory - which produces another copy of the runestone. The world now has two runstones - one in each box. This resolves the 'havoc' from my previous post. The loader then does the same again but this time going through the temporary storage area looking for Location references and COPYING items into the world. Finally the temporary storage area is cleared down and the metadata is dropped from all of the locations as it is no longer required. This all happens very quickly when the server starts. The code is also a lot cleaner. Mostly due to the use of the temporary storage area and the metadata. But what about memory? We have a slight increase in memory due to the fact that everything, except locations, now have a Locate attribute - which consists of two Interface references. There is also a slight increase in memory now that we have proper copies of duplicated objects. I don't think this is an issue considering the benefits it will bring later on. We also keep the flexibility of what can be created for our worlds. In the immediate future I can now work on item disposal and resets. All of this is immediately available to play with in the public dev branch. -- Diddymus Up to Main Index Up to Journal for March, 2017