Skip to content

nwn-bake compare: two versions of a module

nwn-bake compare A B says which areas differ between two versions of a module and where. It is the engine of NWN Bake's changes screen (DESIGN-app.md, screen 4): the list of changed areas, and close-ups of each changed spot. The library call is nwn_bake::compare::compare, which takes two module sources, each with the game opened with its haks, and calls back once per area.

nwn-bake compare <A> <B> [--haks-a a,b,c] [--haks-b a,b,c] [--user-a <folder>] [--user-b <folder>] [--target <name>] [--objects on|off] [--tolerance <metres>] [--jobs <n>] [--root <game>] [--user <folder>]
  • A and B are anything area-iso takes: a .mod, a module folder, a nasher project, a module.ifo or one area file. The two may be different forms (a .mod against the nasher project it was packed from).
  • --haks-a and --haks-b replace each side's own hak list, for one module before and after a hak rebuild. The same list on both sides opens the game once.
  • --user-a and --user-b give each side its own user folder (hak/, override/), for one module against two hak folders. Either defaults to the shared one (--user, else NWN_BAKE_USER, else NWN_HOME). The same list and folder on both sides open the game once.
  • --target names a nasher project's target, on whichever side is a nasher project.
  • --objects off leaves the .git's placeables and doors out of the scenes, as in area-iso.
  • --tolerance is the rounding noise to ignore, in metres (default 0.001, 1 mm; below). 0 counts every move.
  • --jobs is how many areas are compared at once (default NWN_BAKE_JOBS, then half the cores).

Exit code 0 whatever changed, 2 on misuse, 1 on an error, 3 when an area could not be compared (its line says why).

What counts as a change

Areas are paired by resref (lower case). An area in A only is removed, in B only added. An area in both is changed when its scene differs, by the digest area-scene prints, and unchanged when it does not: a new script, a renamed tag or another creature in the .git leaves the pictures as they were, so it is no change here.

Before any scene is built, a quick check: when the .are and .git hold the same fields and values (in any order) and both games read the same files, the scenes are the same, and the line says "by": "files". The games read the same files when they have the same layers at the same paths, or, failing that, when each hak's SHA-256, the install's key file and the talk table are the same (each hak is read once for this). Otherwise both scenes are built, and the line says "by": "scene" and gives both digests.

Where an area changed

For a changed area, changes lists what differs:

  • area: the whole area, when its size, tileset, flags (interior, underground) or sun differ, or when the digests differ and no tile or object below does.
  • tile: a tile whose triangles differ: their corners, texture coordinates, textures (name and pixels) and water. This finds a tile swapped, turned or raised in the .are, and a tile model or texture changed in a hak. index_a and index_b are its index in Tile_List, row by row from the south-west.
  • placeable and door: the .git's objects, paired by kind, template resref, tag and appearance (the nearest first). moved has another place or bearing; changed is in the same place but drawn differently (a model or texture changed in a hak); added and removed are on one side only. a and b are its places (at, metres, and bearing, radians), index_a and index_b its index in the .git's list. An object that draws nothing on either side is left out.

Rounding noise. An object whose place and every corner it draws moved by less than the tolerance (1 mm by default) has not moved: saving a module again in the toolset can move a placeable by a hundredth of a millimetre or turn a door by a hundred-thousandth of a radian (the campaign's Chapter1.nwm against Chapter4.nwm has several). Such an object is counted in ignored and is not a change, and an area whose only differences are such moves is unchanged, "by": "scene", with its two digests (which differ) and ignored above 0. The app shows it as unchanged with a note.

Each change has a rect, [x0, y0, x1, y1] in game metres: the ground its triangles cover on both sides, clamped to the area. regions are the close-ups to draw: each rect 4 m larger on every side, those that overlap joined, clamped to the area, ready for area-iso --region. A moved object's a.at and b.at are the points for --mark.

Not covered yet: which triangles of a tile or object differ (a change is a whole tile or object), creatures, sounds, triggers and other objects the scene does not draw.

A line

One JSON object a line, A's areas in A's order, then the areas only B has. docs/compare.schema.json is its JSON Schema.

{"area":"town","status":"changed","by":"scene","digest_a":"eb33…","digest_b":"6f43…","size_m":[110.0,110.0],
 "changes":[{"subject":"placeable","what":"moved","index_a":0,"index_b":0,"resref":"plc_pyre","tag":"Pyre",
   "a":{"at":[24.28,65.05,0.0],"bearing":0.0},"b":{"at":[30.28,65.05,0.0],"bearing":0.0},"rect":[23.38,64.21,31.27,65.97]}],
 "regions":[[19.38,60.21,35.27,69.97]],"error":null,"ignored":0,"seconds":0.48}
  • status: added, removed, unchanged, changed or failed.
  • by: files or scene (above); null for added, removed and failed.
  • digest_a, digest_b: the scene digests, when the scenes were built.
  • size_m: the area's size in metres, B's (A's when it was removed).
  • error: why a failed area failed.
  • ignored: how many objects moved by less than the tolerance (above); 0 for most areas.
  • seconds: how long the area took.

Speed

On the game's own campaign, with every core: Chapter1.nwm (113 areas) against itself takes 0.12 s, every area by its files. Against Chapter4.nwm (30 areas), which shares 9 areas with it, 0.62 s: 104 removed, 21 added, 9 changed, each scene pair built in 0.1 to 0.5 s.