Skip to content

Commit 3eb6cfc

Browse files
authored
custom levels: add support for symbol, type, and string lumps (#3337)
1 parent 0236e36 commit 3eb6cfc

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

custom_levels/jak1/test-zone/test-zone.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// integer types: int32, uint32, enum-int32, enum-uint32
2525
// float types: float, meters (1 meter = 4096.0 units), degrees (65536.0 = 360°)
2626
// vector types: vector (normal floats), vector4m (meters), vector3m (meters with w set to 1.0), vector-vol (normal floats with w in meters), movie-pos (meters with w in degrees)
27-
// special types: eco-info, cell-info, buzzer-info, water-height
27+
// special types: symbol, type, string, eco-info, cell-info, buzzer-info, water-height
2828
//
2929
// examples:
3030
//
@@ -51,6 +51,9 @@
5151
//
5252
// adds a buzzer-info tag:
5353
// "eco-info": ["buzzer-info", "(game-task training-buzzer)", 5]
54+
//
55+
// adds a 'symbol' tag (using the 'type' and 'string' lump types works the same way):
56+
// "symbol-list": ["symbol", "sym-1", "sym-2"]
5457

5558
// The base actor id for your custom level. If you have multiple levels this should be unique!
5659
"base_id": 100,

custom_levels/jak2/test-zone/test-zone.jsonc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"double_sided_collide": false,
2222

2323
// available res-lump tag types:
24-
// value types: int32, uint32, enum-int32, enum-uint32, float, meters (1 meter = 4096.0 units), degrees (65536.0 = 360°)
24+
// integer types: int32, uint32, enum-int32, enum-uint32
25+
// float types: float, meters (1 meter = 4096.0 units), degrees (65536.0 = 360°)
2526
// vector types: vector (normal floats), vector4m (meters), vector3m (meters with w set to 1.0), vector-vol (normal floats with w in meters), movie-pos (meters with w in degrees)
26-
// special types: eco-info, water-height
27+
// special types: symbol, type, string, eco-info, cell-info, buzzer-info, water-height
2728
//
2829
// examples:
2930
//
@@ -44,6 +45,9 @@
4445
//
4546
// adds an eco-info tag:
4647
// "eco-info": ["eco-info", "(pickup-type health)", 2]
48+
//
49+
// adds a 'type' tag (using the "symbol" and "string" lump types works the same way):
50+
// "spawn-types": ["type", "spyder", "juicer"]
4751

4852
// The base actor id for your custom level. If you have multiple levels, this should be unique!
4953
"base_id": 100,

goalc/build_level/common/Entity.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ static std::unordered_map<std::string,
202202
}
203203
return std::make_unique<ResFloat>(name, data, -1000000000.0000);
204204
}},
205+
{"symbol",
206+
[](const std::string& name,
207+
const nlohmann::json& json,
208+
decompiler::DecompilerTypeSystem& dts) {
209+
(void)dts;
210+
std::vector<std::string> data;
211+
for (size_t i = 1; i < json.size(); i++) {
212+
data.push_back(json[i].get<std::string>());
213+
}
214+
return std::make_unique<ResSymbol>(name, data, -1000000000.0000);
215+
}},
216+
{"type",
217+
[](const std::string& name,
218+
const nlohmann::json& json,
219+
decompiler::DecompilerTypeSystem& dts) {
220+
(void)dts;
221+
std::vector<std::string> data;
222+
for (size_t i = 1; i < json.size(); i++) {
223+
data.push_back(json[i].get<std::string>());
224+
}
225+
return std::make_unique<ResType>(name, data, -1000000000.0000);
226+
}},
227+
{"string",
228+
[](const std::string& name,
229+
const nlohmann::json& json,
230+
decompiler::DecompilerTypeSystem& dts) {
231+
(void)dts;
232+
std::vector<std::string> data;
233+
for (size_t i = 1; i < json.size(); i++) {
234+
data.push_back(json[i].get<std::string>());
235+
}
236+
return std::make_unique<ResString>(name, data, -1000000000.0000);
237+
}},
205238
// vectors
206239
{"vector",
207240
[](const std::string& name,

goalc/build_level/common/ResLump.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,31 @@ int ResSymbol::get_alignment() const {
215215
return 4;
216216
}
217217

218+
ResType::ResType(const std::string& name, const std::vector<std::string>& str, float key_frame)
219+
: Res(name, key_frame), m_str(str) {}
220+
221+
ResType::ResType(const std::string& name, const std::string& str, float key_frame)
222+
: Res(name, key_frame), m_str({str}) {}
223+
224+
TagInfo ResType::get_tag_info() const {
225+
TagInfo result;
226+
result.elt_type = "type";
227+
result.elt_count = m_str.size();
228+
result.inlined = false;
229+
result.data_size = 4 * m_str.size();
230+
return result;
231+
}
232+
233+
void ResType::write_data(DataObjectGenerator& gen) const {
234+
for (auto& str : m_str) {
235+
gen.add_type_tag(str);
236+
}
237+
}
238+
239+
int ResType::get_alignment() const {
240+
return 4;
241+
}
242+
218243
void ResLump::add_res(std::unique_ptr<Res> res) {
219244
m_sorted = false;
220245
m_res.emplace_back(std::move(res));

goalc/build_level/common/ResLump.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ class ResSymbol : public Res {
125125
std::vector<std::string> m_str;
126126
};
127127

128+
class ResType : public Res {
129+
public:
130+
ResType(const std::string& name, const std::vector<std::string>& str, float key_frame);
131+
ResType(const std::string& name, const std::string& str, float key_frame);
132+
133+
TagInfo get_tag_info() const override;
134+
void write_data(DataObjectGenerator& gen) const override;
135+
int get_alignment() const override;
136+
137+
private:
138+
std::vector<std::string> m_str;
139+
};
140+
128141
/*
129142
(deftype res-lump (basic)
130143
((length int32 :offset-assert 4)

0 commit comments

Comments
 (0)