Skip to content

Commit 8410ed0

Browse files
authored
Lab asteroid viewer (#6710)
* Allow viewing asteroid and debris objects in the Lab * Address feedback * Minor UI string tweak
1 parent 4d39287 commit 8410ed0

10 files changed

Lines changed: 378 additions & 21 deletions

File tree

code/asteroid/asteroid.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ void asteroid_sub_create(object *parent_objp, int asteroid_type, vec3d *relvec)
534534
/**
535535
* Load in an asteroid model
536536
*/
537-
static void asteroid_load(int asteroid_info_index, int asteroid_subtype)
537+
void asteroid_load(int asteroid_info_index, int asteroid_subtype)
538538
{
539539
int i;
540540
asteroid_info *asip;
@@ -1492,8 +1492,54 @@ void asteroid_render(object * obj, model_draw_list *scene)
14921492

14931493
model_render_params render_info;
14941494

1495+
uint64_t render_flags = MR_IS_ASTEROID;
1496+
1497+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_light])
1498+
render_flags |= MR_NO_LIGHTING;
1499+
1500+
if (asp->render_flags[Object::Raw_Pof_Flags::Glowmaps_disabled]) {
1501+
render_flags |= MR_NO_GLOWMAPS;
1502+
}
1503+
1504+
if (asp->render_flags[Object::Raw_Pof_Flags::Draw_as_wireframe]) {
1505+
render_flags |= MR_SHOW_OUTLINE_HTL | MR_NO_POLYS | MR_NO_TEXTURING;
1506+
render_info.set_color(Wireframe_color);
1507+
}
1508+
1509+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_full_detail]) {
1510+
render_flags |= MR_FULL_DETAIL;
1511+
}
1512+
1513+
uint debug_flags = render_info.get_debug_flags();
1514+
1515+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_diffuse]) {
1516+
debug_flags |= MR_DEBUG_NO_DIFFUSE;
1517+
}
1518+
1519+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_glowmap]) {
1520+
debug_flags |= MR_DEBUG_NO_GLOW;
1521+
}
1522+
1523+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_normalmap]) {
1524+
debug_flags |= MR_DEBUG_NO_NORMAL;
1525+
}
1526+
1527+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_ambientmap]) {
1528+
debug_flags |= MR_DEBUG_NO_AMBIENT;
1529+
}
1530+
1531+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_specmap]) {
1532+
debug_flags |= MR_DEBUG_NO_SPEC;
1533+
}
1534+
1535+
if (asp->render_flags[Object::Raw_Pof_Flags::Render_without_reflectmap]) {
1536+
debug_flags |= MR_DEBUG_NO_REFLECT;
1537+
}
1538+
14951539
render_info.set_object_number( OBJ_INDEX(obj) );
1496-
render_info.set_flags(MR_IS_ASTEROID);
1540+
1541+
render_info.set_flags(render_flags);
1542+
render_info.set_debug_flags(debug_flags);
14971543
if (asp->model_instance_num >= 0)
14981544
render_info.set_replacement_textures(model_get_instance(asp->model_instance_num)->texture_replace);
14991545

@@ -2192,6 +2238,16 @@ static void asteroid_parse_section()
21922238
asteroid_p->type = ASTEROID_TYPE_DEBRIS;
21932239
}
21942240

2241+
auto insert_or_replace_subtype_pof = [](SCP_vector<asteroid_subtype_info>& subtypes, const asteroid_subtype_info& new_subtype) {
2242+
for (auto& subtype : subtypes) {
2243+
if (lcase_equal(subtype.type_name, new_subtype.type_name)) {
2244+
strcpy_s(subtype.pof_filename, new_subtype.pof_filename);
2245+
return;
2246+
}
2247+
}
2248+
subtypes.push_back(new_subtype);
2249+
};
2250+
21952251
if (optional_string("$POF file1:")) {
21962252
asteroid_subtype_info thisType;
21972253

@@ -2201,7 +2257,7 @@ static void asteroid_parse_section()
22012257

22022258
thisType.model_number = -1;
22032259

2204-
asteroid_p->subtypes.push_back(thisType);
2260+
insert_or_replace_subtype_pof(asteroid_p->subtypes, thisType);
22052261
}
22062262

22072263
if (optional_string("$POF file2:")) {
@@ -2212,7 +2268,7 @@ static void asteroid_parse_section()
22122268

22132269
thisType.model_number = -1;
22142270

2215-
asteroid_p->subtypes.push_back(thisType);
2271+
insert_or_replace_subtype_pof(asteroid_p->subtypes, thisType);
22162272
}
22172273

22182274
if (optional_string("$POF file3:")) {
@@ -2223,7 +2279,7 @@ static void asteroid_parse_section()
22232279

22242280
thisType.model_number = -1;
22252281

2226-
asteroid_p->subtypes.push_back(thisType);
2282+
insert_or_replace_subtype_pof(asteroid_p->subtypes, thisType);
22272283
}
22282284

22292285
// For asteroid types we can have unlimited subtypes

code/asteroid/asteroid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "globalincs/globals.h" // for NAME_LENGTH
1616
#include "globalincs/pstypes.h"
17+
#include "object/object_flags.h"
1718
#include "io/timer.h"
1819

1920
class object;
@@ -102,6 +103,7 @@ class asteroid_info
102103

103104
typedef struct asteroid {
104105
int flags;
106+
flagset<Object::Raw_Pof_Flags> render_flags; // Render flags
105107
int objnum;
106108
int model_instance_num;
107109
int asteroid_type; // 0..MAX_DEBRIS_TYPES
@@ -179,6 +181,9 @@ void asteroid_add_target(object* objp);
179181
int get_asteroid_index(const char* asteroid_name);
180182
SCP_vector<SCP_string> get_list_valid_asteroid_subtypes();
181183

184+
// extern for the lab
185+
void asteroid_load(int asteroid_info_index, int asteroid_subtype);
186+
182187
// need to extern for keycontrol debug commands
183188
object *asteroid_create(asteroid_field *asfieldp, int asteroid_type, int asteroid_subtype, bool check_visibility = false);
184189

code/lab/dialogs/lab_ui.cpp

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "lab_ui_helpers.h"
55

6+
#include "asteroid/asteroid.h"
67
#include "graphics/debug_sphere.h"
78
#include "graphics/matrix.h"
89
#include "lab/labv2_internal.h"
@@ -91,16 +92,91 @@ void LabUi::build_weapon_subtype_list() const
9192
}
9293
}
9394

94-
void LabUi::build_weapon_list() const
95+
void LabUi::build_asteroid_list()
96+
{
97+
with_TreeNode("Asteroids")
98+
{
99+
int asteroid_idx = 0;
100+
101+
for (const auto& info : Asteroid_info) {
102+
if (info.type == ASTEROID_TYPE_DEBRIS) {
103+
asteroid_idx++;
104+
continue;
105+
}
106+
107+
int subtype_idx = 0;
108+
for (const auto& subtype : info.subtypes) {
109+
SCP_string node_label;
110+
sprintf(node_label, "##AsteroidClassIndex%i_%i", asteroid_idx, subtype_idx);
111+
TreeNodeEx(node_label.c_str(),
112+
ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen,
113+
"%s (%s)",
114+
info.name,
115+
subtype.type_name.c_str());
116+
117+
if (IsItemClicked() && !IsItemToggledOpen()) {
118+
getLabManager()->changeDisplayedObject(LabMode::Asteroid, asteroid_idx, subtype_idx);
119+
}
120+
121+
subtype_idx++;
122+
}
123+
124+
asteroid_idx++;
125+
}
126+
}
127+
}
128+
129+
void LabUi::build_debris_list()
95130
{
96-
//weapon display needs to be rethought
131+
with_TreeNode("Debris")
132+
{
133+
int debris_idx = 0;
134+
135+
for (const auto& info : Asteroid_info) {
136+
if (info.type != ASTEROID_TYPE_DEBRIS) {
137+
debris_idx++;
138+
continue;
139+
}
97140

141+
int subtype_idx = 0;
142+
for (const auto& subtype : info.subtypes) {
143+
SCP_string node_label;
144+
sprintf(node_label, "##DebrisClassIndex%i_%i", debris_idx, subtype_idx);
145+
TreeNodeEx(node_label.c_str(),
146+
ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen,
147+
"%s (%s)",
148+
info.name,
149+
subtype.type_name.c_str());
150+
151+
if (IsItemClicked() && !IsItemToggledOpen()) {
152+
getLabManager()->changeDisplayedObject(LabMode::Asteroid, debris_idx, subtype_idx);
153+
}
154+
155+
subtype_idx++;
156+
}
157+
158+
debris_idx++;
159+
}
160+
}
161+
}
162+
163+
void LabUi::build_weapon_list() const
164+
{
98165
with_TreeNode("Weapon Classes")
99166
{
100167
build_weapon_subtype_list();
101168
}
102169
}
103170

171+
void LabUi::build_object_list()
172+
{
173+
with_TreeNode("Asteroid/Debris Types")
174+
{
175+
build_asteroid_list();
176+
build_debris_list();
177+
}
178+
}
179+
104180
void LabUi::build_background_list() const
105181
{
106182
SCP_vector<SCP_string> t_missions;
@@ -201,6 +277,8 @@ void LabUi::show_object_selector() const
201277
build_ship_list();
202278

203279
build_weapon_list();
280+
281+
build_object_list();
204282
}
205283
}
206284
}
@@ -346,12 +424,14 @@ void LabUi::show_render_options()
346424
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
347425
}
348426
Checkbox("Show full detail", &show_full_detail);
349-
Checkbox("Show thrusters", &show_thrusters);
350-
if (getLabManager()->CurrentMode == LabMode::Ship) {
351-
Checkbox("Show afterburners", &show_afterburners);
352-
Checkbox("Show weapons", &show_weapons);
353-
Checkbox("Show Insignia", &show_insignia);
354-
Checkbox("Show damage lightning", &show_damage_lightning);
427+
if (getLabManager()->CurrentMode != LabMode::Asteroid) {
428+
Checkbox("Show thrusters", &show_thrusters);
429+
if (getLabManager()->CurrentMode == LabMode::Ship) {
430+
Checkbox("Show afterburners", &show_afterburners);
431+
Checkbox("Show weapons", &show_weapons);
432+
Checkbox("Show Insignia", &show_insignia);
433+
Checkbox("Show damage lightning", &show_damage_lightning);
434+
}
355435
}
356436
Checkbox("No glowpoints", &no_glowpoints);
357437
}
@@ -1186,6 +1266,44 @@ void LabUi::show_object_options() const
11861266
}
11871267
}
11881268
}
1269+
} else if (getLabManager()->CurrentMode == LabMode::Asteroid && getLabManager()->CurrentClass >= 0) {
1270+
const auto& info = Asteroid_info[getLabManager()->CurrentClass];
1271+
1272+
with_CollapsingHeader("Object Info")
1273+
{
1274+
static SCP_string table_text;
1275+
static int old_class = -1;
1276+
1277+
if (table_text.empty() || old_class != getLabManager()->CurrentClass) {
1278+
table_text = get_asteroid_table_text(&info);
1279+
old_class = getLabManager()->CurrentClass;
1280+
}
1281+
1282+
InputTextMultiline("##asteroid_table_text",
1283+
const_cast<char*>(table_text.c_str()),
1284+
table_text.length(),
1285+
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
1286+
ImGuiInputTextFlags_ReadOnly);
1287+
}
1288+
1289+
with_CollapsingHeader("Object actions")
1290+
{
1291+
if (getLabManager()->isSafeForAsteroids()) {
1292+
if (Button("Destroy object")) {
1293+
if (Objects[getLabManager()->CurrentObject].type == OBJ_ASTEROID) {
1294+
auto obj = &Objects[getLabManager()->CurrentObject];
1295+
1296+
if (obj->type == OBJ_ASTEROID) {
1297+
vec3d dummy_pos = obj->pos;
1298+
vec3d dummy_force = ZERO_VECTOR;
1299+
1300+
// Apply full asteroid health to guarantee destruction
1301+
asteroid_hit(obj, nullptr, &dummy_pos, obj->hull_strength + 1.0f, &dummy_force);
1302+
}
1303+
}
1304+
}
1305+
}
1306+
}
11891307
}
11901308
}
11911309
}

code/lab/dialogs/lab_ui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class LabUi {
2424
void build_species_entry(const species_info &species_def, int species_idx) const;
2525
void build_weapon_list() const;
2626
void build_weapon_subtype_list() const;
27+
static void build_object_list();
28+
static void build_asteroid_list();
29+
static void build_debris_list();
2730
void build_background_list() const;
2831
void show_render_options();
2932
void show_object_options() const;

0 commit comments

Comments
 (0)