Up to Main Index Up to Journal for July, 2021 JOURNAL FOR SATURDAY 31ST JULY, 2021 ______________________________________________________________________________ SUBJECT: Where is here? DATE: Sat 31 Jul 16:44:36 BST 2021 End of the month and just time to squeeze in one more journal entry. I’m still working on respawning and resets. Things were going quite well, until I hit a slight snag. Items in the game world have a problem knowing where they are… Let me elaborate a little. We have the World which contains all of the locations by their unique identifier. Anything knows where it is via item.As[Where] which returns the UID of its location. If something is at a location it can get it’s location via World[item.As[Where]]. With me so far? If we have a container with an Item in it then item.As[Where] gives the UID of the container. How do we know where the container is? We only have the UID reference and World only has locations, so we can’t do World[item.As[Where]] to find the container. This presents a problem when an item in a container that is being held by a player needs to know where it is. There are three immediate solutions to this problem. One easy and messy, one I was hoping to avoid and the last quite favourable but a bit more complicated. The easy way would be to have World contain all containers. A container is anything that can contain something else. World would then contain all locations, actual containers, players, mobiles, etc. If you have thousands of players you’ve just dumped them all into the World map. This isn’t a problem as Go can handle maps with millions of elements — but to me it seems to be a very messy solution. I’ve prototyped this and tested with 64,000 bots running around and there was little to no change in performance and memory used. The second solution involves making Where a pointer field in Thing. We would then know where we are using item.Where and we could know where our parent is using item.Where.Where etc. I was hoping to avoid creating actual hierarchies of linked items — I wanted to try and keep everything soft linked, just using UIDs and lookups was working quite well. I’ve also prototyped this solution with similar results to the first solution. The third and final solution expands on the second. We generalise references. We have a new field Ref on Thing that is a map of *Thing — just like Thing.In, Thing.Out and Thing.Who are. Ref can be used for references to other Thing such as Where, Origin (where an item starts and resets to) and exits. We can then find out where we are using item.Ref[Where] and can get our parent using item.Ref[Where].Ref[Where] we can also get exits using, for example, item.Ref[North]. This would also mean that locations are no longer soft linked via UID but as an actual *Thing reference. This would let us have locations in locations again if we wanted… The third solution may also mean we no longer need the World map — although it may still have some uses. I’ve not prototyped the third solution yet, plan is to do that this afternoon. Of the solutions I think the third fits well with the current design and is the most flexible. Whichever solution I pick it’s a lot of boring refactoring of the code which then needs careful testing. I then need to rebase all of my respawning and reset changes on top of it. For now there are no new updates on the experiment branch while I get all this worked out :( -- Diddymus Up to Main Index Up to Journal for July, 2021