yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
custom_collision.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_DUNGEON_CUSTOM_COLLISION_H
2#define YAZE_APP_ZELDA3_DUNGEON_CUSTOM_COLLISION_H
3
4#include <array>
5#include <bitset>
6#include <cstddef>
7#include <cstdint>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "rom/rom.h"
14
15namespace yaze {
16namespace zelda3 {
17
19 std::array<uint8_t, 64 * 64> tiles{};
20 // Presence is independent of value: 0x00 is an explicit floor override.
21 std::bitset<64 * 64> overrides;
22 bool has_data = false;
23
24 bool HasOverride(size_t offset) const {
25 // Keep nonzero maps constructed by legacy track producers compatible.
26 return offset < tiles.size() &&
27 (overrides.test(offset) || tiles[offset] != 0);
28 }
29
30 void SetOverride(size_t offset, uint8_t tile) {
31 if (offset >= tiles.size()) {
32 return;
33 }
34 tiles[offset] = tile;
35 overrides.set(offset);
36 has_data = true;
37 }
38
39 void ClearOverride(size_t offset) {
40 if (offset >= tiles.size()) {
41 return;
42 }
43 tiles[offset] = 0;
44 overrides.reset(offset);
45 }
46
47 bool HasOverrides() const {
48 for (size_t offset = 0; offset < tiles.size(); ++offset) {
49 if (HasOverride(offset)) {
50 return true;
51 }
52 }
53 return false;
54 }
55
56 bool operator==(const CustomCollisionMap& other) const {
57 if (has_data != other.has_data || tiles != other.tiles) {
58 return false;
59 }
60 for (size_t offset = 0; offset < tiles.size(); ++offset) {
61 if (HasOverride(offset) != other.HasOverride(offset)) {
62 return false;
63 }
64 }
65 return true;
66 }
67};
68
69// Load the ZScream custom collision map for a dungeon room.
70absl::StatusOr<CustomCollisionMap> LoadCustomCollisionMap(Rom* rom,
71 int room_id);
72
74 uint16_t offset = 0; // Y*64 + X (0..4095)
75 uint8_t value = 0; // Collision type (0..255), including explicit floor 0.
76};
77
79 int room_id = -1;
80 std::vector<CustomCollisionTileEntry> tiles;
81};
82
83// JSON import/export helpers for authoring workflows.
84//
85// Format (v1):
86// {
87// "version": 1,
88// "rooms": [
89// { "room_id": "0x25", "tiles": [ [ 1234, 8 ], [ 42, "0x1B" ] ] }
90// ]
91// }
92//
93// `room_id`, offsets, and values may be provided as ints or strings (hex
94// allowed). A value of 0 is an explicit floor override. Omitted coordinates
95// have no override; importing an empty tile list clears the room's overrides.
96absl::StatusOr<std::string> DumpCustomCollisionRoomsToJsonString(
97 const std::vector<CustomCollisionRoomEntry>& rooms);
98
99absl::StatusOr<std::vector<CustomCollisionRoomEntry>>
100LoadCustomCollisionRoomsFromJsonString(const std::string& json_content);
101
102// Every room with custom collision in `rom`, serialized as the canonical
103// custom_collision.json source (rooms ascending, present tiles including zero).
104// This is the exact byte format Oracle of Secrets' collision source validator
105// requires the tracked file to match.
106absl::StatusOr<std::string> DumpCustomCollisionSourceFromRom(Rom* rom);
107
108} // namespace zelda3
109} // namespace yaze
110
111#endif // YAZE_APP_ZELDA3_DUNGEON_CUSTOM_COLLISION_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:49
absl::StatusOr< std::vector< CustomCollisionRoomEntry > > LoadCustomCollisionRoomsFromJsonString(const std::string &json_content)
absl::StatusOr< std::string > DumpCustomCollisionRoomsToJsonString(const std::vector< CustomCollisionRoomEntry > &rooms)
absl::StatusOr< CustomCollisionMap > LoadCustomCollisionMap(Rom *rom, int room_id)
absl::StatusOr< std::string > DumpCustomCollisionSourceFromRom(Rom *rom)
std::array< uint8_t, 64 *64 > tiles
bool operator==(const CustomCollisionMap &other) const
bool HasOverride(size_t offset) const
void SetOverride(size_t offset, uint8_t tile)
std::vector< CustomCollisionTileEntry > tiles