Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New navcon text format, with converter, fix #1772 #2329

Merged
merged 3 commits into from Jan 16, 2023

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Dec 7, 2022

Introduce a new navcon text format.
Make the engine loads both old and new format and write new format.
Add a navcon converter to convert existing navcon files to the new format.

Fix #1772.

The output format is a text format, all numbers are written as integers as float precision is believed to be overkill.

Output format is like:

navcon 3
x1 z1 y1 x2 z2 y2 rad flags areas dirs
x1 z1 y1 x2 z2 y2 rad flags areas dirs

Example:

$ hexdump -Cv ~/.local/share/unvanquished/game/maps/plat23-level4.navcon
00000000  02 00 00 00 02 00 00 00  56 c5 7e c3 00 00 00 c0  |........V.~.....|
00000010  b9 bc e4 44 e1 59 0a c3  28 6c c9 3d 48 65 dc 44  |...D.Y..(l.=He.D|
00000020  99 f8 1e 43 00 00 00 c0  91 76 0c 45 9f 45 a3 43  |...C.....v.E.E.C|
00000030  4c 6f e1 c2 24 12 0c 45  00 00 48 42 00 00 48 42  |Lo..$..E..HB..HB|
00000040  01 00 01 00 3f 3f 01 00  00 00 00 00 00 00 00 00  |....??..........|
00000050

$ ./convert-navcon ~/.local/share/unvanquished/game/maps/plat23-level4.navcon > plat23-level4.navcon
Converting /home/illwieckz/.local/share/unvanquished/game/maps/plat23-level4.navcon
Converting from format version 2 to 3
Converting 2 connections

$ ./convert-navcon plat23-level4.navcon
Not converting plat23-level4.navcon
Already in format version 3

$ cat plat23-level4.navcon
navcon 3
-254 -2 1829 -138 0 1763 50 1 63 1
158 -2 2247 326 -112 2241 50 1 63 0

$ du -b ~/.local/share/unvanquished/game/maps/plat23-level4.navcon plat23-level4.navcon
80	/home/illwieckz/.local/share/unvanquished/game/maps/plat23-level4.navcon
80	plat23-level4.navcon

@illwieckz illwieckz assigned illwieckz and unassigned illwieckz Dec 7, 2022
@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 2 times, most recently from 2bc1941 to 2615223 Compare December 7, 2022 12:18
@sweet235
Copy link
Contributor

sweet235 commented Dec 7, 2022

lgtm

@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 6 times, most recently from ffd46eb to 0411c5d Compare December 7, 2022 13:16
tools/navcon-converter/navcon-converter Outdated Show resolved Hide resolved
tools/navcon-converter/navcon-converter Outdated Show resolved Hide resolved
tools/navcon-converter/navcon-converter Outdated Show resolved Hide resolved
@slipher
Copy link
Contributor

slipher commented Dec 8, 2022

userid seems to be unused (always 0) so you could omit that from the text format.

@illwieckz
Copy link
Member Author

userid seems to be unused (always 0) so you could omit that from the text format.

I stripped it.

Anyway, that's fun:

$ du -b ~/.local/share/unvanquished/game/maps/plat23-level4.navcon plat23-level4.navcon
80	/home/illwieckz/.local/share/unvanquished/game/maps/plat23-level4.navcon
80	plat23-level4.navcon

@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 3 times, most recently from 1bc1aaf to 7ceb19a Compare December 8, 2022 13:04
@illwieckz
Copy link
Member Author

illwieckz commented Dec 8, 2022

I added a patch to make the game load both the old and new format and write the new format instead of the old one.

  old new
read yes yes
write no yes

This is based on a shameless copy-paste of the layout parser writer (which uses a similar format), despite being so C89 and featuring a lot of cargo cult, it works.

@illwieckz illwieckz changed the title tools: add navcon-converter New navcon text format, with converter, fix #1772 Dec 8, 2022
@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 5 times, most recently from 3d7c87b to 9fc0ada Compare December 9, 2022 13:39
@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 2 times, most recently from 50848a9 to f25dae6 Compare December 10, 2022 15:06
@illwieckz
Copy link
Member Author

I added the ability to pass -i to the converter to rewrite a file in place.

@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 3 times, most recently from 129fc95 to d8dce9f Compare December 10, 2022 20:19
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
@illwieckz illwieckz force-pushed the illwieckz/navcon-converter branch 2 times, most recently from 72c95be to 0bd26c9 Compare December 29, 2022 03:08
@illwieckz
Copy link
Member Author

I added some extra code to make sure the parser doesn't read missing number of a line from the next line, also the sscanf calls detect if there is missing fields or too much fields.

src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
This commit is easy to revert to re-enable debugging.
@illwieckz
Copy link
Member Author

I added a commit to delete the extra debug print, that commit is easy to revert for re-enabling debugging.

src/sgame/botlib/bot_load.cpp Show resolved Hide resolved
src/sgame/botlib/bot_load.cpp Outdated Show resolved Hide resolved
@illwieckz illwieckz merged commit 6e6b5eb into master Jan 16, 2023
7 checks passed
@illwieckz illwieckz deleted the illwieckz/navcon-converter branch January 16, 2023 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

migrate navcon files from binary to text format
4 participants