Closed ohlidalp closed 1 year ago
When I'm looking at the serialization loop I wrote, I realize that the way you tell good code isn't about diving into the details, but rather looking from bird's perspective where you can barely read the characters, then observing the overall shape and using just common sense to figure out what it probably does. If the above journey is a pleasure to do and the conclusion you arrive at turns out to be pretty correct, you've met good code.
Yes, I've had a 🤓 moment, judge me all you want.
Purpose: to be able to read, edit and export any fileformat (TRUCK DEF, ODEF, TOBJ, CHARACTER) directly in game using AngelScript.
Estimate: Blocked by #2930. As soon as #2930 is done, this will take at most 1 man day to finish.
Work to be done:
Document@ game.loadDocument(filename, rg_name)
and void game.saveDocument(Document@)
that will check if the file is unzipped and if yes, load/save the document.Viewing truck file of any 'complex' vehicle -> ~30 fps drop:
No frame drops with the DAF Semi.
Also much of the truck file doesn't match the actual file:
@CuriousMike56 Thanks for testing.
Viewing truck file of any 'complex' vehicle -> ~30 fps drop:
Makes sense, it's because the script traverses the entire document every frame, so it's combined overhead of DearIMGUI and string allocation by angelscript. I'd have to optimize it like in Console UI - artificially scale the scrollbar and only populate the visible part of the document. But I'd like to do it in another PR since it's just a demo.
Also much of the truck file doesn't match the actual file:
Interesting, I see 3 problems:
set_*_defaults
are omitted entirely - absolutely no idea why. UPDATE: it was a tokenizer bug, keywords containing underscore got discarded.SameLine()
which works for single linebreaks but squashes multiple linebreaks.Truck definition format parsing is complete.
Note the option 'ALLOW_NAKED_STRINGS' must be on at all times, because otherwise the parser requires all strings to be in quotes. Also see these special cases:
forset
, single node numbers are parsed as NUMBER. Node ranges are not valid numbers so they decay to STRINGs.
axle
and interaxle
keyword have a quirky abc(1 2)
syntax. I added an option 'PARENTHESES_CAPTURE_SPACES' which make the whole expression parse as one string.
Originally I only planned to cover fileformats which are similar to each other (truck, odef, tobj) but now I wanted the demo script to display TOBJ files too, but I didn't want to clog the Terrain API with getFileWhatever()
funcs. I wanted to use the GenericDocument
to parse the TERRN2 file, get TOBJ filenames from there and parse those as well. It turned out to be pretty straightforward, the tokenizer is already robust so it could take a few extra options.
Parsing TERRN2 format needs these special options: "ALLOW_HASH_COMMENTS", "ALLOW_SEPARATOR_EQUALS", "ALLOW_BRACED_KEYWORDS" and of course "ALLOW_NAKED_STRINGS".
Parsing TOBJ format needs just "ALLOW_NAKED_STRINGS" and "ALLOW_SLASH_COMMENTS".
We have multiple formats with very similar syntax: rig def (truck), odef, tobj, character (see #2942). This new parser supports all these formats and adds new features:
Update: I added AngelScript bindings and extended the bundled 'demo_script.as' to showcase them. There's a new button "View document" (changes to "Close document" after pressing) which opens separate window with a syntax highlighted truck file. Update2: all glitches were fixed. It's ready for review.
New script API:
To test, open game console and say![obrazek](https://user-images.githubusercontent.com/491088/206774416-1ab7ce40-7d1e-46d1-9d6e-41f57ecdf068.png)
loadscript demo_script.as
.