On Mon, May 14, 2012 at 5:27 PM, Ralph Versteegen <[email protected]> wrote:
> On 14 May 2012 18:36, David Gowers (kampu) <[email protected]> wrote:
>> I think that must be a Windows-only constraint. I can memmap with any
>> offset and any length.
>
> I forgot to try manually specifying the length. Wow, numpy lets you
> grow files by writing off the end of a memmap? I didn't know; that's
> quite nice. But RPGDir needs a special case for that.
>
> It seems LibreOffice can't handle spreadsheets with 1300 columns
> though!
..
..
..
who would have ever imagined THAT? </facetious>
> Would need to change the format to have 'shop id' and 'item
> number' key columns.
>
>>>
>>> What I learnt is that this is totally the wrong approach, and it needs
>>> to be rewritten. You really need to write lump-specific code which
>>> knows how to handle things like enumerations, off-by-ones, arrays that
>>> are split into two pieces, and the like.
>>
>> Yeah, that's what I decided. A more conventional record interface
>> implemented in Python, which uses ndarray subclassing to provide
>> enumeration, badstring, off-by-one, and split record handling. It
>> needs to address two distinct needs : arr.fieldname needs to
>> behave like `recarray`, but it should determine the subclass of the
>> returned array from the dtype metadata associated with the field.
>
> I was trying to do that by subclassing np.void and returning instances
> of that from OhrData.__getitem__, because IIRC even recarray records
> return np.void instances instead of np.records if you index a compound
> subfield of a record (eg. stat 'bonuses' in ITM). But I didn't get it
> working.
No, np.void is a special snowflake.. an arrogant, uncooperative one.
Work to improve this situation in NumPy is ongoing (and will probably
emerge by Numpy 2.0 IIRC).
AFAICS, once you have received an np.void, an np.void it shall forever remain.
One thing I'd like to mention at this point is that some parts of
ndarray subclassing are non-obvious; for instance recarray-style
access is not as good as it sounds because arrays come with a great
many (100+?) methods, which will make things quite confusing when
debugging (Tab-complete -> truckload of options even if there are only
two subfields). I concluded that most of these methods need to be
hidden so when you tab-complete or dir(), you get a useful result.
That's complex to implement correctly. So for now I opted to go for
x['y'] notation, with an extension allowing pseudo-dot-access --
x['y.z.foo.bar']
>
>> To that end I started working on improving the datatype definitions
>> (we can store such additional info in the 'metadata' field of the
>> dtype object.). The format is compilable (ie. you can produce actual
>> dtypes with metadata attached from it, and vice versa), but incomplete
>> (off-by-one isn't handled. not sure if badstring is handled).
>>
>> I thought I'd pushed this work, but no.. Well, that's remedied now.
>
> This looks a lot like what nohrio needs, though the encoding is a bit
> too compact imo :)
There's a few formats. The one that I currently prefer is a good
balance between compact and explicit:
gen = DType ("""
<h:maxmap^me:h:title:h:titlemusic:h:victorymusic:h:battlemusic:
h:passcodeversion^e:h:pw3rotator^o:17B:pw3passcode^o:10h:pw1password^o:
h:maxherogfx^mex:h:maxenemy1gfx^mex:h:maxenemy2gfx^mx:h:maxenemy3gfx^mx:h:maxnpcgfx^mex:
h:maxweapongfx^mex:h:maxattackgfx^mex:h:maxtilesetgfx^mex:
h:maxattack^me:h:maxhero^me:h:maxenemy^me:h:maxformation^me:h:maxpalette^mex:h:maxtextbox^m:
h:nplotscripts^ms:h:newgamescript^s:h:gameoverscript^s:h:maxregularscript^mes:
H:suspendbits^g:h:cameramode^g:4h:cameraarg^g:h:curbackdrop^gx:
[content omitted for the sake of brevity]
""",
suspendbits = bitsets ('npcs player obstruction herowalls npcwalls
caterpillar'
' randomenemies boxadvance overlay ambientmusic'),
maxlevel = limited (99), # start, stop, [individualitems]
playtime = DType ('h:days:h:hours:h:minutes:h:seconds',
hours = limited (23),
minutes = limited (59),
seconds = limited (59)),
e = 'editoronly',
f = 'sound',
g = 'gameonly',
m = 'max',
M = 'softmax',
o = 'obsolete',
x = 'gfx')
(the ^character codes are optional tags. Everything else should be
pretty obvious if you've read PEP 3188. )
Looks like that got left out of the previous commit, so updating will
get you that set of files (nohrio/dtypes/* (but mainly 'general.py'
right now; the others are somewhat experimental and really only
demonstrate a possible subclassing/field access model))
Oh, also, there's machinery for mutable dtypes in nohrio. Useful for
split-records like the attack data, BINSIZE controlled records, or
where valid enumeration values vary across versions. You just freeze()
it after you're done editing.
>
> Originally I wanted to create a metadata file format similar to
> editedit definitions, except describing binary record (and RELOAD)
> based file formats, and try to split that off from editedt menu
> definitions (which would then specify much less: mostly just the order
> in which fields are presented and conditions on each appearing/being
> enabled). But clearly this would just create a whole lot of work, so
> I'm not so keen on it anymore.
(dtype objects are pickleable, and pickling preserves metadata, BTW)
I eventually decided that this kind of idea was overengineering,
because the only application that could do anything useful with that
kind of information would be a generic data editor/filterer (there are
commercial hex editors that provide this functionality).
Despite that, I had a go at writing one; Hopefully it got into the
recent commit. Though it's notably got problems creating the right
widgets for nested fields, it's a decent prototype.
Every other kind of application pretty much needs to have some
hardcoded understanding of the data fields and their type, if not
their structure; So I concluded this functionality doesn't belong in
OHRRPGCE itself.
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org