Torch
Loading...
Searching...
No Matches
MapFactory.h
1#pragma once
2
3#include <factories/BaseFactory.h>
4#include <vector>
5
6namespace BK64 {
7
37typedef struct NodeProp {
38 int16_t position[3]; // X, Y, Z world position (s16)
39 uint16_t radius : 9; // selector_or_radius: trigger/volume radius
40 uint16_t bit6 : 6; // category, see above
41 uint16_t bit0 : 1; // path waypoint
42 uint16_t unk8; // actorId — meaning depends on category
43 uint8_t unkA; // markerId: index into the ActorMarker lookup table
44 uint8_t padB; // padding
45 uint32_t yaw : 9; // degrees
46 uint32_t scale : 23; // percent for an actor spawn, 0 for its default size
47 uint32_t unk10_31 : 12; // this record's number in a path chain
48 uint32_t unk10_19 : 12; // the next record's number in the chain
49 uint32_t pad10_7 : 1; // padding
50 uint32_t unk10_6 : 1; // "initialized" flag, set at runtime
51 uint32_t pad10_5 : 4; // padding
52 uint32_t unk10_0 : 2; // param passed to func_803303B8
53} NodeProp;
54
72typedef struct Prop {
73 uint8_t raw[12];
74} Prop;
75
81typedef struct CubeData {
82 int32_t x;
83 int32_t y;
84 int32_t z;
85 bool listedEmpty = false; // holds nothing, but the file still writes its node and prop blocks
86 std::vector<NodeProp> nodeProps;
87 std::vector<Prop> props;
88} CubeData;
89
95typedef struct CameraNodeType1 {
96 float position[3]; // camera position
97 float horizontalSpeed; // horizontal speed
98 float verticalSpeed; // vertical speed
99 float rotation; // rotation speed
100 float accelaration; // acceleration
101 float pitchYawRoll[3]; // the point it looks from while the player is nearly underneath it
102 int32_t unknownFlag; // unknown; tested against 1, 2, 4
104
110typedef struct CameraNodeType2 {
111 float position[3]; // camera position
112 float pitchYawRoll[3]; // orientation (pitch, yaw, roll)
114
120typedef struct CameraNodeType3 {
121 float position[3]; // camera position
122 float horizontalSpeed; // horizontal speed
123 float verticalSpeed; // vertical speed
124 float rotation; // rotation speed
125 float accelaration; // acceleration
126 float closeDistance; // nearest it comes to the player
127 float farDistance; // farthest it drops back
128 float pitchYawRoll[3]; // the point it looks from while the player is nearly underneath it
129 int32_t unknownFlag; // unknown
131
137typedef struct CameraNodeType4 {
138 int32_t unknownFlag; // the preset
140
154typedef struct CameraNode {
155 int16_t index; // node index
156 uint8_t type; // 0=Empty, 1=Pivot, 2=Static, 3=Dolly, 4=ZoomPreset
157 union {
158 CameraNodeType1 type1;
159 CameraNodeType2 type2;
160 CameraNodeType3 type3;
161 CameraNodeType4 type4;
162 } data;
163} CameraNode;
164
170typedef struct LightingVector {
171 float position[3]; // X, Y, Z light position
172 float fadeRadii[2]; // inner/outer fade distances
173 int32_t rgb[3]; // R, G, B
175
176class MapData : public IParsedData {
177 public:
178 // Cube data section (chunk type 0x01)
179 int32_t mCubeMin[3]; // grid min bounds
180 int32_t mCubeMax[3]; // grid max bounds
181 std::vector<CubeData> mCubes;
182
183 // Camera nodes section (chunk type 0x03)
184 std::vector<CameraNode> mCameraNodes;
185
186 // Lighting section (chunk type 0x04)
187 std::vector<LightingVector> mLightingVectors;
188
189 MapData() {
190 mCubeMin[0] = mCubeMin[1] = mCubeMin[2] = 0;
191 mCubeMax[0] = mCubeMax[1] = mCubeMax[2] = 0;
192 }
193};
194
196 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
197 YAML::Node& node, std::string* replacement) override;
198};
199
201 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
202 YAML::Node& node, std::string* replacement) override;
203};
204
206 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
207 YAML::Node& node, std::string* replacement) override;
208};
209
211 ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName,
212 YAML::Node& node, std::string* replacement) override;
213};
214
215// The setup as the ROM stores it once decompressed, which is also the decomp's .lvl_setup.bin.
216std::shared_ptr<MapData> ReadMapRom(const std::vector<uint8_t>& bytes, const std::string& symbol);
217std::vector<uint8_t> WriteMapRom(const MapData& map);
218// A BKMap resource, as MapBinaryExporter writes it.
219std::shared_ptr<MapData> ReadMapResource(const std::vector<uint8_t>& resource);
220std::string MapToYaml(const MapData& map, const std::string& symbol);
221bool MapFromYaml(const std::string& text, MapData& out, std::string& error);
222
223class MapFactory : public BaseFactory {
224 public:
225 std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
226 std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override;
227 inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
228 return { REGISTER(Code, MapCodeExporter) REGISTER(Header, MapHeaderExporter) REGISTER(Binary, MapBinaryExporter)
229 REGISTER(Modding, MapModdingExporter) };
230 }
231
232 bool HasModdedDependencies() override {
233 return true;
234 }
235 bool SupportModdedAssets() override {
236 return true;
237 }
238};
239} // namespace BK64
Definition MapFactory.h:200
Definition MapFactory.h:205
Definition MapFactory.h:176
Definition MapFactory.h:223
Definition MapFactory.h:195
Definition MapFactory.h:210
Definition BaseFactory.h:96
Definition BaseFactory.h:102
Definition BaseFactory.h:88
Definition MapFactory.h:95
Definition MapFactory.h:110
Definition MapFactory.h:120
Definition MapFactory.h:137
Definition MapFactory.h:154
Definition MapFactory.h:81
Definition MapFactory.h:170
Definition MapFactory.h:37
Definition MapFactory.h:72