Skip to content

feat: background page compilation + async scene import - #15

Merged
ABKQPO merged 9 commits into
GTNewHorizons:masterfrom
Windorain:compiler-optimization
Jun 17, 2026
Merged

feat: background page compilation + async scene import#15
ABKQPO merged 9 commits into
GTNewHorizons:masterfrom
Windorain:compiler-optimization

Conversation

@Windorain

@Windorain Windorain commented Jun 12, 2026

Copy link
Copy Markdown

Background compilation + async scene import

  • CompileWorker: background daemon thread for page compilation post-world-load
  • AsyncWorker: 4-thread pool for heavy scene import work (StructureLib, SNBT)
  • SceneScript: 3-phase state machine, submits import work to background threads
  • MaterializeTask: yield mechanism fix to support multi-frame scripts
  • Scene async loading progress bar with placeholder frame

Navigation state fixes

  • per-guide nav bar state: refactored to activateGuide() boundary with carry-over, properly scoping expanded page IDs and scroll position per guide
  • expand/collapse write-through persistence: GuideExpansionListener callback ensures expand/collapse state is persisted immediately, preventing stale state restoration when re-entering a guide
  • cross-guide scroll continuity: scroll position no longer jumps when navigating between guides — only restored on initial screen setup

Other fixes

  • Ponder scene localization fix (pass language through ScenePlaceholder)
  • Change nei-custom-diagram to compileOnlyApi to prevent NHItemList crash

@ABKQPO ABKQPO added the bug label Jun 12, 2026
@label-sync-bot-gtnh label-sync-bot-gtnh Bot removed the bug label Jun 15, 2026
@ABKQPO ABKQPO added the Bug Fix Fixes a bug. Please link it in the PR if an issue exists for it. label Jun 15, 2026
Replace synchronous page compilation (blocking main thread during Micromark parse + MDX compile) with a background daemon worker that greedily compiles all pages after world load.

Changes:
- Add CompileWorker: single daemon thread with priority queue, ConcurrentHashMap cache, GuideRegistry-based guide lookup
- LytHost: remove preheat machinery (queue, scheduler, compiler lambda), split nodeResults from PageCacheEntry into 32-entry access-order LRU
- GuideScreen: remove setPreheatCompiler, add async loading path with loading document, delegate to CompileWorker
- MutableGuide: wrap compiledPagesStrong with Collections.synchronizedMap for thread safety, add getCachedCompiledPage()
- ClientProxy: add CompileWorker singleton + getWorker(), remove LytHostPreheatItem registration
- GuideLightweightReloadService: trigger worker.reset() on F3+T reload
- Delete LytHostPreheatItem (replaced by CompileWorker)
…import

- MaterializeTask: remove firstCall, support unlimited yields, log exceptions
- ScriptContext: timeToYield pure check, explicit yield() method, replaceError()
- AsyncWorker: 4-thread daemon pool for background computation
- CompileWorker: persistent poll loop, remove submitIfIdle
- SceneScript: 3-phase state machine (SCAN->POLL->COMPILE) using AsyncWorker
- ImportStructure: check SnbtPreParseCache for worker pre-parsed SNBT
- SnbtPreParseCache: ConcurrentHashMap cache for pre-parsed SNBT data
Show loading progress bar overlay during async structure imports.
Reuse scene object across SCAN→POLL→COMPILE so the user
sees a consistent frame from the start.

- SceneScript: create scene skeleton in doScan, reuse in
  doCompile, ctx.replace once for async path
- LytGuidebookScene: drawLoadProgressOverlay with amber
  progress bar and import count status text
- Minor log level adjustments (warnAlways/infoAlways→info)
…ugh ScenePlaceholder

SceneScript created a runtime PageCompiler via the 5-arg constructor
which hardcodes LangUtil.ENGLISH_LANGUAGE, causing Ponder scene labels
and annotations to always display in English regardless of game language.

Fix: Store the compile-time language in ScenePlaceholder and pass it to
the 6-arg PageCompiler constructor in SceneScript.
- Add GuideNavBar.activateGuide() as single state-switch entry point
  (save old guide state, load new guide state, expand ancestors, rebuild once)
- Add activeGuideId field to track which guide currently owns expandedPageIds
- NavigationState: HOME_KEY sentinel for null guideId, HOME page state now persisted
- GuideScreen.rememberNavigationState: remove guide==null skip, HOME always saves
- GuideScreen constructor: use activateGuide instead of restoreState
- Cross-guide navigation (navigateTo/back/forward/Home): call activateGuide
  when guide changes; same-guide navigation preserves live expansion state
- initGui: call expandNavigationParentsToCurrentPage for external screen openers
  (guide item, hotkey) where tree wasn't available during construction
- add GuideExpansionListener callback to GuideNavBar for write-through
  persistence of expand/collapse state, preventing stale state
  restoration on guide re-entry
- add carryOverIds parameter to activateGuide(), preserve expanded
  state across cross-guide navigation and back/forward history
- make scrollY continuous across cross-guide navigation by only
  restoring saved scroll during initial screen setup (tree==null)
- add updateSavedExpansionState() for surgical state updates without
  overwriting other expanded nodes
@Windorain
Windorain force-pushed the compiler-optimization branch from 5c5fb84 to 3b26d18 Compare June 17, 2026 14:57
@ABKQPO
ABKQPO merged commit fda8bfd into GTNewHorizons:master Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Fixes a bug. Please link it in the PR if an issue exists for it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants