This document provides a technical overview of the overworld entity system, including critical bug fixes that enable its functionality and the ongoing plan to refactor it for modularity and ZScream feature parity.
The overworld entity system manages all interactive objects on the overworld map, such as entrances, exits, items, and sprites. The system is undergoing a refactor to move from a monolithic architecture within the Overworld class to a modular design where each entity's save/load logic is handled in dedicated files.
Key Goals of the Refactor:
Overworld class by delegating I/O responsibilities.Several critical bugs were fixed to make the entity system functional. Understanding these fixes is key to understanding the system's design.
File: src/app/editor/overworld/overworld_entity_renderer.cc
hovered_entity_) is now reset only once at the beginning of the entity rendering cycle, specifically in DrawExits(), which is the first rendering function called. Subsequent functions (DrawEntrances(), DrawItems(), etc.) can set the hover state without it being cleared, preserving the correct hover priority (last-drawn entity wins).File: src/app/editor/overworld/entity.cc
set_done flag, which controls the popup's return value, is now correctly managed. The "Done" and "Delete" buttons set set_done = true to signal a save action, while the "Cancel" button does not, correctly discarding changes.File: src/zelda3/overworld/overworld_exit.h
OverworldExit class used uint8_t for player coordinates, truncating 16-bit values.OverworldExit were changed to uint16_t to match the full 0-4088 coordinate range, achieving parity with ZScream's data structures.File: src/zelda3/overworld/overworld_exit.h
x_, y_) would update, but the underlying data used for saving (x_player_, y_player_) would not, leading to a data desync and incorrect saves.UpdateMapProperties method now explicitly syncs the base entity coordinates to the player coordinates before recalculating scroll and camera values. This ensures that drag operations correctly persist.The next phase of development is to extract all entity save and load logic from the monolithic overworld.cc into dedicated files.
New files will be created to handle I/O for each entity type:
src/zelda3/overworld/overworld_entrance.ccsrc/zelda3/overworld/overworld_exit.ccsrc/zelda3/overworld/overworld_item.ccsrc/zelda3/overworld/overworld_transport.cc (for new transport/whirlpool support)Each new file will implement a standard set of flat functions:
LoadAll...(): Reads all entities of a given type from the ROM.SaveAll...(): Writes all entities of a given type to the ROM.The refactor aims to implement key ZScream features:
UpdateMapStuff logic in ZScream.Overworld Class RoleAfter the refactor, the Overworld class will act as a coordinator, delegating all entity I/O to the new, modular functions. Its responsibility will be to hold the entity vectors and orchestrate the calls to the LoadAll... and SaveAll... functions.