Skip to content

Conversation

ehughsbaird
Copy link
Contributor

Summary

Bugfixes "Fix terrain not being recognized in palettes based on loading order"

Purpose of change

Fixes #82974

Because conversion to an int_id requires that the object of that type is already loaded, values loaded from JSON should be loaded as string ids, then converted to int ids on use or after all JSON has been loaded.

Because jmapgen_terrain did not do this, if terrain definitions were placed such that they were loaded after the palette the jmapgen_terrain is part of, it would not be able to convert them to a valid int id.

Describe the solution

Use string ids instead of int ids.

This was triggered in the innawood mod, and was resolved by moving the terrain defintions. Now that they are fixed, they can be restored to their previous location.

I want to do memory profiling to see the impact of this change. There are also probably other jmapgens that need to use string ids.

Testing

The innawood mod loads without any errors.

Because conversion to an int_id requires that the object of that type is
already loaded, values loaded from JSON should be loaded as string ids,
then converted to int ids on use or after all JSON has been loaded.

Because jmapgen_terrain did not do this, if terrain definitions were
placed such that they were loaded after the palette the jmapgen_terrain
is part of, it would not be able to convert them to a valid int id.

This was triggered in the innawood mod, and was resolved by moving the
terrain defintions. Now that they are fixed, they can be restored to
their previous location.

TODO: memory profiling - what is the impact of this?
@github-actions github-actions bot added [JSON] Changes (can be) made in JSON Map / Mapgen Overmap, Mapgen, Map extras, Map display [C++] Changes (can be) made in C++. Previously named `Code` Mods: Innawood 🌲 Anything to do with Innawood mod <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Sep 23, 2025
@ehughsbaird ehughsbaird marked this pull request as ready for review October 3, 2025 17:00
@ehughsbaird
Copy link
Contributor Author

This didn't show up in massif, and for ter_t, string ids should be integers, just like int ids. I'm happy with that.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @Light-Wave

@Maleclypse Maleclypse merged commit 9add884 into CleverRaven:master Oct 4, 2025
45 of 49 checks passed
@ehughsbaird ehughsbaird deleted the jmapgen-str-id branch October 5, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Mods: Innawood 🌲 Anything to do with Innawood mod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mapgen resolves terrain ids to int_id before all terrains are loaded
2 participants