intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Oct 19, 2018 9:40 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: showme vs showobj
PostPosted: Sat Sep 22, 2018 10:59 pm 
Offline
User avatar

Joined: Sat Apr 10, 2010 8:40 pm
Posts: 133
Location: Washington, DC, USA
Can anybody point me to the code underlying the I7 debugging command "showme"? I'd like to be able to generate a list of all object in a game, along with their properties and attributes. I'm thinking about this in the context of wanting to be able to save state for a web-based game, where this (and perhaps knowing the current scene) would be enough to allow save/restore, rather than taking a snapshot of the entire VMs memory. I suppose I'd want to package all this up as JSON and squirrel it away somewhere.

I have a very concrete understanding of how this worked with I6 --it is laid out in the showobj routine in parserm.h. I wish I could just plunder that code, but according to the I7 documentation, objects, their properties, flags, etc., aren't stored in the same way in I7.

In I7 I can repeat with item running through objects in the game and figure out containment (holder of the item), but I have no idea of the arcana needed to comprehensively list their associated attribute and properties.

[But what about globals? Well, I'd just tuck them into some convenient dummy object "The gameState is nowhere. The gameState has a number called ennui. The ennui of the gameState is 5., etc." I suppose score, turn count, etc., could be tucked into that object as well at the end of every turn.]

Thoughts? Thanks - Jack


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 12:12 am 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2660
Location: The Midwest
Most* Inform 7 globals are stored in a single huge I6 array, so that's not a problem.

*well, any that have to be accessed by hand-written I6 code are given I6 registers instead, but they're the minority: things like "noun" and "second".

A bigger problem might be tables, which are just big blocks of memory, but you can avoid storing data in those if you try hard.

Unfortunately the SHOWME command's code is created by the ni compiler, which is closed-source so we can't access the internals. The I6 code in Tests.i6t (which defines all the debugging verbs) looks like this:

Code:
[ ShowMeSub t_0 na;
   t_0 = noun;
    if (noun == nothing) noun = real_location;
    if (ShowMeRecursively(noun, 0, (noun == real_location))) {
       if (noun == real_location)
         print "* denotes things which are not in scope^";
   }
    if (t_0 ofclass K2_thing) {
       print "location:"; ShowRLocation(noun, true); print "^";
    }
    {-call:PL::Showme::compile_SHOWME_details}
];


In other words, a nice readable Inform 6 subroutine…with {-call:PL::Showme::compile_SHOWME_details} replacing all the interesting bits. This instructs NI to call an internal routine called "compile_SHOWME_details" that makes all the magic happen depending on the exact details of the game.

On the other hand, you might not need the showme code at all! After all, the fanciest thing it does is figure out the name and type of each property—but a save/restore system doesn't need that. Just iterate over all objects, iterate over all property numbers, if the object provides that property, save its value as an integer. Whether those bytes represent an int, a float, a pointer, etc is all irrelevant to saving and restoring it: you've just got to put those same bytes back in the same spot.

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 8:17 am 
Offline
User avatar

Joined: Sat Apr 10, 2010 8:40 pm
Posts: 133
Location: Washington, DC, USA
Thanks, that's very helpful. I had grepped for "showme", but missed this due to case. ShowMeRecursively gives a nice tree, but provides only superficial details, so it looks like I have to pin my hopes on ShowMeSub, specifically that last somewhat opaque line, "{-call:PL::Showme::compile_SHOWME_details}". I'd have to capture the text that spews out and parse it as needed, which I think is doable. One item I don't understand: how is a parameter (the thing in question) passed to that last low-level routine, does it just work with the noun?

As for tables (and lists), they would have to be static, no reordering or destructive management. I'd need to rely on how they are defined at run time. Pointers to the table, like current_row, could be saved. Too bad everything isn't an object.

Thanks again! - Jack


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 10:15 am 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5770
You want to look at the generated auto.inf code to see what {-call:PL::Showme::compile_SHOWME_details} turns into. It looks like:

Code:
if (t_0) {if (na > 0) { na = 0; print "; "; }
    if ((AllowInShowme(pluralname)) && (t_0  has pluralname)) { if (na++ > 0) print ", "; print "plural-named"; }
    if ((AllowInShowme(pluralname)) && (t_0  hasnt pluralname)) { if (na++ > 0) print ", "; print "singular-named"; }
    if ((AllowInShowme(proper)) && (t_0  has proper)) { if (na++ > 0) print ", "; print "proper-named"; }
    if ((AllowInShowme(proper)) && (t_0  hasnt proper)) { if (na++ > 0) print ", "; print "improper-named"; }
    if ((AllowInShowme(ambigpluralname)) && (t_0  has ambigpluralname)) { if (na++ > 0) print ", "; print "ambiguously plural"; }
}


...and then similar sections for properties defined on rooms, on thing, etc, etc.

So it's not doing anything complicated, just checking each property and printing text.

It looks like that compiler line is hard-wired to display "t_0", which is defined as a local variable in ShowMeSub.


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 11:40 am 
Offline
User avatar

Joined: Fri Jul 11, 2014 12:50 pm
Posts: 109
Just out of curiosity, why would you want to implement a custom way of saving? Is it so it works across mutiple versions of the game?

Because even on the web you could just use regular saves.


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 12:00 pm 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2660
Location: The Midwest
Natrium729 wrote:
Just out of curiosity, why would you want to implement a custom way of saving? Is it so it works across mutiple versions of the game?

Because even on the web you could just use regular saves.

Plus, if you want to save across versions, you have to deal with pointers going rotten. Which is a serious issue.

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 5:30 pm 
Offline
User avatar

Joined: Sat Apr 10, 2010 8:40 pm
Posts: 133
Location: Washington, DC, USA
Thanks everyone for comments. I've never looked under the covers at auto.inf -- that's cool!

Natrium -- I'm thinking about two things. First, how to save a game written with zoom/vorple. Isn't that a still unaddressed limitation (at least in version 3 preview)?

But I was also curious in a more general sense. If one wanted to save an object, or maybe an object and its descendants (in terms of containment) or even a collection of objects, I wondered if there was a programmatic way to comprehensibly capture all of the properties of each object in a way that could be exported. Again, I'm thinking in terms of vorple, values can move back and forth between javascript and inform.

I'm toying with the idea of games where objects could be imported/exported to a server and perhaps shared between games and/or players. I don't have a specific application in mind, but I think there is a lot of potential here.

- Jack


Last edited by dhakajack on Sun Sep 23, 2018 8:52 pm, edited 1 time in total.

Top
 Profile Send private message  
Reply with quote  
 Post subject: Re: showme vs showobj
PostPosted: Sun Sep 23, 2018 6:44 pm 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2660
Location: The Midwest
If you want to capture all the properties, it's straightforward if hacky: iterate through the property numbers, see if the object provides that property, if so save the value.

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group