yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
cutscene_shot.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_CUTSCENE_CUTSCENE_SHOT_H_
2#define YAZE_ZELDA3_CUTSCENE_CUTSCENE_SHOT_H_
3
4#include <string>
5#include <string_view>
6#include <vector>
7
8#include "absl/status/statusor.h"
10
11namespace yaze::zelda3 {
12
13// A framed overworld cutscene shot: where the camera sits and where Link and
14// the actors stand. Positions are overworld world pixels, the same values the
15// game keeps in $E2/$E8 (camera left/top) and $22/$20 (Link X/Y).
17 int sprite = 0; // sprite ID, 0x00-0xFF
18 int x = 0;
19 int y = 0;
20 int facing = 0; // 0-3
21 std::string note;
22 bool operator==(const CutsceneActor&) const = default;
23};
24
26 int x = 0;
27 int y = 0;
28 int facing = 0; // 0-3
29 bool operator==(const CutsceneLink&) const = default;
30};
31
33 std::string name; // [A-Za-z0-9_], used for generated assembler symbols
34 int area = 0; // overworld area ID, 0x00-0x7F
35 int camera_x = 0;
36 int camera_y = 0;
38 std::vector<CutsceneActor> actors;
39 bool operator==(const CutsceneShot&) const = default;
40};
41
43 std::vector<CutsceneShot> shots;
44 bool operator==(const CutsceneShotSet&) const = default;
45};
46
47// Strict version-1 parse. Rejects unknown versions, missing fields, invalid
48// names, duplicate names and out-of-range values; the error names the field.
49absl::StatusOr<CutsceneShotSet> ParseCutsceneShots(std::string_view json);
50
51// Stable version-1 text: two-space indentation, fixed key order, hex strings
52// for area and sprite IDs, trailing newline.
53absl::StatusOr<std::string> SerializeCutsceneShots(const CutsceneShotSet& set);
54
55// --- Camera geometry -------------------------------------------------------
56
57inline constexpr int kCutsceneViewportWidth = 256;
58inline constexpr int kCutsceneViewportHeight = 224;
59
60// An overworld area in world pixels. Large areas span 1024 pixels on a side;
61// ZSCustomOverworld can also make an area wide (1024x512) or tall (512x1024).
62struct AreaExtent {
63 int origin_x = 0;
64 int origin_y = 0;
65 int width = 512;
66 int height = 512;
67};
68
70 int min_x = 0;
71 int max_x = 0;
72 int min_y = 0;
73 int max_y = 0;
74};
75
76// The limits the game gives the camera for an area
77// (Overworld_SetCameraBoundaries, $02C0C3): left/top at the area origin,
78// right at width - 256 ($0100 small, $0300 large) and bottom at
79// height - 226 ($011E small, $031E large; two pixels short of a full screen).
81
83 int requested_x = 0;
84 int requested_y = 0;
85 int x = 0;
86 int y = 0;
87 bool clamped() const { return x != requested_x || y != requested_y; }
88};
89
90ClampedCamera ClampCamera(const AreaExtent& area, int x, int y);
91
92// Vanilla area layout from OverworldTransitionPositionX/Y ($02A8C4/$02A944):
93// the origin of the area's parent and whether it is large. Dark World areas
94// (0x40-0x7F) share the Light World layout. Special areas (0x80+) are
95// rejected. ROM hacks with custom area sizes supply their own AreaExtent.
96absl::StatusOr<AreaExtent> VanillaAreaExtent(int area);
97
98// The camera area of an overworld area from the ROM's own layout: `parent`
99// is the area's top-left screen and `size` its ZSCustomOverworld size
100// (small 512x512, large 1024x1024, wide 1024x512, tall 512x1024). Light and
101// Dark World areas share one grid of 512-pixel screens.
102AreaExtent AreaExtentFromParent(int parent, AreaSizeEnum size);
103
104// --- Map placement ---------------------------------------------------------
105
106struct MapRect {
107 float x = 0;
108 float y = 0;
109 float width = 0;
110 float height = 0;
111};
112
113// Where the 256x224 viewport lands on an area map drawn at `scale` map pixels
114// per world pixel, with the area's top-left corner at map (0, 0).
115MapRect ViewportOnMap(const AreaExtent& area, int camera_x, int camera_y,
116 float scale);
117
118// Where a world-pixel point lands on the same map.
119MapRect PointOnMap(const AreaExtent& area, int world_x, int world_y,
120 float scale);
121
122// Whether a world-pixel point is inside the viewport at (camera_x, camera_y).
123bool PointInViewport(int camera_x, int camera_y, int world_x, int world_y);
124
125} // namespace yaze::zelda3
126
127#endif // YAZE_ZELDA3_CUTSCENE_CUTSCENE_SHOT_H_
Zelda 3 specific classes and functions.
absl::StatusOr< std::string > SerializeCutsceneShots(const CutsceneShotSet &set)
CameraBounds CameraBoundsForArea(const AreaExtent &area)
nlohmann::json json
AreaSizeEnum
Area size enumeration for v3+ ROMs.
absl::StatusOr< AreaExtent > VanillaAreaExtent(int area)
constexpr int kCutsceneViewportWidth
MapRect PointOnMap(const AreaExtent &area, int world_x, int world_y, float scale)
MapRect ViewportOnMap(const AreaExtent &area, int camera_x, int camera_y, float scale)
absl::StatusOr< CutsceneShotSet > ParseCutsceneShots(std::string_view json)
bool PointInViewport(int camera_x, int camera_y, int world_x, int world_y)
constexpr int kCutsceneViewportHeight
AreaExtent AreaExtentFromParent(int parent, AreaSizeEnum size)
ClampedCamera ClampCamera(const AreaExtent &area, int x, int y)
bool operator==(const CutsceneActor &) const =default
std::vector< CutsceneShot > shots
bool operator==(const CutsceneShotSet &) const =default
bool operator==(const CutsceneShot &) const =default
std::vector< CutsceneActor > actors