Skip to content

Commit 5078826

Browse files
authored
Lab Weapon Viewer (#6704)
* Activate Lab Weapon viewer * Allow displaying weapon tech models * check for a valid tech model when switching * enable render options for weapons and tech models * Some cleanup * Clang * address feedback
1 parent ce4522d commit 5078826

20 files changed

Lines changed: 676 additions & 99 deletions

code/graphics/shadows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ void shadows_render_all(fov_t fov, matrix *eye_orient, vec3d *eye_pos)
508508

509509
switch(objp->type)
510510
{
511+
case OBJ_RAW_POF:
511512
case OBJ_SHIP:
512513
{
513514
obj_queue_render(objp, &scene);

code/lab/dialogs/lab_ui.cpp

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ void LabUi::build_weapon_list() const
9595
{
9696
//weapon display needs to be rethought
9797

98-
//with_TreeNode("Weapon Classes")
99-
//{
100-
// build_weapon_subtype_list();
101-
//}
98+
with_TreeNode("Weapon Classes")
99+
{
100+
build_weapon_subtype_list();
101+
}
102102
}
103103

104104
void LabUi::build_background_list() const
@@ -342,13 +342,17 @@ void LabUi::show_render_options()
342342

343343
with_CollapsingHeader("Model features")
344344
{
345-
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
345+
if (getLabManager()->CurrentMode == LabMode::Ship) {
346+
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
347+
}
346348
Checkbox("Show full detail", &show_full_detail);
347349
Checkbox("Show thrusters", &show_thrusters);
348-
Checkbox("Show afterburners", &show_afterburners);
349-
Checkbox("Show weapons", &show_weapons);
350-
Checkbox("Show Insignia", &show_insignia);
351-
Checkbox("Show damage lightning", &show_damage_lightning);
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);
355+
}
352356
Checkbox("No glowpoints", &no_glowpoints);
353357
}
354358

@@ -372,6 +376,7 @@ void LabUi::show_render_options()
372376
with_CollapsingHeader("Scene rendering options")
373377
{
374378
Checkbox("Hide Post Processing", &hide_post_processing);
379+
Checkbox("Hide particles", &no_particles);
375380
Checkbox("Render as wireframe", &use_wireframe_rendering);
376381
Checkbox("Render without light", &no_lighting);
377382
Checkbox("Render with emissive lighting", &show_emissive_lighting);
@@ -487,6 +492,7 @@ void LabUi::show_render_options()
487492
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::ShowWeapons, show_weapons);
488493
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::ShowEmissiveLighting, show_emissive_lighting);
489494
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::MoveSubsystems, animate_subsystems);
495+
getLabManager()->Renderer->setRenderFlag(LabRenderFlag::NoParticles, no_particles);
490496
getLabManager()->Renderer->setEmissiveFactor(emissive_factor);
491497
getLabManager()->Renderer->setAmbientFactor(ambient_factor);
492498
getLabManager()->Renderer->setLightFactor(light_factor);
@@ -523,7 +529,7 @@ void LabUi::do_triggered_anim(animation::ModelAnimationTriggerType type,
523529
TextUnformatted(colB); \
524530

525531

526-
void LabUi::build_table_info_txtbox(ship_info* sip) const
532+
static void build_ship_table_info_txtbox(ship_info* sip)
527533
{
528534
with_TreeNode("Table information")
529535
{
@@ -543,6 +549,26 @@ void LabUi::build_table_info_txtbox(ship_info* sip) const
543549
}
544550
}
545551

552+
static void build_weapon_table_info_txtbox(weapon_info* wip)
553+
{
554+
with_TreeNode("Table information")
555+
{
556+
// Cache result across frames for performance
557+
static SCP_string table_text;
558+
static int old_class = getLabManager()->CurrentClass;
559+
560+
if (table_text.length() == 0 || old_class != getLabManager()->CurrentClass) {
561+
table_text = get_weapon_table_text(wip);
562+
}
563+
564+
InputTextMultiline("##weapon_table_text",
565+
const_cast<char*>(table_text.c_str()),
566+
table_text.length(),
567+
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
568+
ImGuiInputTextFlags_ReadOnly);
569+
}
570+
}
571+
546572
void LabUi::build_model_info_box_actual(ship_info* sip, polymodel* pm) const
547573
{
548574
ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg;
@@ -751,15 +777,9 @@ void LabUi::build_weapon_options(ship* shipp) const {
751777

752778
build_primary_weapon_combobox(text, wip, primary_slot);
753779
SameLine();
754-
static bool should_fire[MAX_SHIP_PRIMARY_BANKS] = {false, false, false};
755780
SCP_string cb_text;
756781
sprintf(cb_text, "Fire bank %i", bank);
757-
Checkbox(cb_text.c_str(), &should_fire[bank]);
758-
if (should_fire[bank]) {
759-
getLabManager()->FirePrimaries |= 1 << bank;
760-
} else {
761-
getLabManager()->FirePrimaries &= ~(1 << bank);
762-
}
782+
Checkbox(cb_text.c_str(), &getLabManager()->FirePrimaries[bank]);
763783

764784
bank++;
765785
}
@@ -777,15 +797,9 @@ void LabUi::build_weapon_options(ship* shipp) const {
777797
sprintf(text, "##Secondary bank %i", bank);
778798
build_secondary_weapon_combobox(text, wip, secondary_slot);
779799
SameLine();
780-
static bool should_fire[MAX_SHIP_SECONDARY_BANKS] = {false, false, false, false};
781800
SCP_string cb_text;
782801
sprintf(cb_text, "Fire bank %i##secondary", bank);
783-
Checkbox(cb_text.c_str(), &should_fire[bank]);
784-
if (should_fire[bank]) {
785-
getLabManager()->FireSecondaries |= 1 << bank;
786-
} else {
787-
getLabManager()->FireSecondaries &= ~(1 << bank);
788-
}
802+
Checkbox(cb_text.c_str(), &getLabManager()->FireSecondaries[bank]);
789803

790804
bank++;
791805
}
@@ -1127,7 +1141,7 @@ void LabUi::show_object_options() const
11271141

11281142
with_CollapsingHeader(sip->name)
11291143
{
1130-
build_table_info_txtbox(sip);
1144+
build_ship_table_info_txtbox(sip);
11311145

11321146
build_model_info_box(sip, pm);
11331147

@@ -1154,6 +1168,24 @@ void LabUi::show_object_options() const
11541168
{
11551169
build_weapon_options(shipp);
11561170
}
1171+
} else if (getLabManager()->CurrentMode == LabMode::Weapon && getLabManager()->isSafeForWeapons()) {
1172+
auto wip = &Weapon_info[getLabManager()->CurrentClass];
1173+
1174+
with_CollapsingHeader("Weapon Info")
1175+
{
1176+
build_weapon_table_info_txtbox(wip);
1177+
}
1178+
1179+
with_CollapsingHeader("Object Actions")
1180+
{
1181+
Checkbox("Progress weapon lifetime", &getLabManager()->AllowWeaponDestruction);
1182+
1183+
if (VALID_FNAME(wip->tech_model)) {
1184+
if (Checkbox("Show Tech Model", &getLabManager()->ShowingTechModel)) {
1185+
getLabManager()->changeDisplayedObject(LabMode::Weapon, getLabManager()->CurrentClass);
1186+
}
1187+
}
1188+
}
11571189
}
11581190
}
11591191
}

code/lab/dialogs/lab_ui.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ enum class LabTurretAimType {
1212

1313
class LabUi {
1414
public:
15+
bool show_thrusters = false; // So that it can be toggled on/off based on the lab mode being changed
16+
1517
void create_ui();
1618
void object_changed();
1719
void closeUi();
@@ -31,7 +33,6 @@ class LabUi {
3133
void build_texture_quality_combobox();
3234
void build_antialiasing_combobox();
3335
void build_tone_mapper_combobox();
34-
void build_table_info_txtbox(ship_info* sip) const;
3536
void build_model_info_box(ship_info* sip, polymodel* pm) const;
3637
void build_subsystem_list(object* objp, ship* shipp) const;
3738
void build_subsystem_list_entry(SCP_string& subsys_name,
@@ -85,6 +86,7 @@ class LabUi {
8586
bool show_damage_lightning = false;
8687
bool animate_subsystems = false;
8788
bool hide_post_processing = false;
89+
bool no_particles = false;
8890
bool diffuse_map = true;
8991
bool glow_map = true;
9092
bool spec_map = true;
@@ -98,10 +100,10 @@ class LabUi {
98100
bool use_wireframe_rendering = false;
99101
bool no_lighting = false;
100102
bool show_full_detail = false;
101-
bool show_thrusters = false;
102103
bool show_afterburners = false;
103104
bool show_weapons = false;
104105
bool show_emissive_lighting = false;
106+
bool show_particles = true;
105107

106108
std::optional<vec3d> volumetrics_pos_backup = std::nullopt;
107109
};

code/lab/dialogs/lab_ui_helpers.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,132 @@ SCP_string get_ship_table_text(ship_info* sip)
131131
return result;
132132
}
133133

134+
SCP_string get_weapon_table_text(weapon_info* wip)
135+
{
136+
char line[256], line2[256], file_text[82];
137+
int i, j, n, found = 0, comment = 0, num_files = 0;
138+
SCP_vector<SCP_string> tbl_file_names;
139+
SCP_string result;
140+
141+
auto fp = cfopen("weapons.tbl", "r");
142+
Assert(fp);
143+
144+
while (cfgets(line, 255, fp)) {
145+
while (line[strlen(line) - 1] == '\n')
146+
line[strlen(line) - 1] = 0;
147+
148+
for (i = j = 0; line[i]; i++) {
149+
if (line[i] == '/' && line[i + 1] == '/')
150+
break;
151+
152+
if (line[i] == '/' && line[i + 1] == '*') {
153+
comment = 1;
154+
i++;
155+
continue;
156+
}
157+
158+
if (line[i] == '*' && line[i + 1] == '/') {
159+
comment = 0;
160+
i++;
161+
continue;
162+
}
163+
164+
if (!comment)
165+
line2[j++] = line[i];
166+
}
167+
168+
line2[j] = 0;
169+
if (!strnicmp(line2, "$Name:", 6)) {
170+
drop_trailing_white_space(line2);
171+
found = 0;
172+
i = 6;
173+
174+
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
175+
i++;
176+
177+
if (!stricmp(line2 + i, wip->name)) {
178+
result += "-- weapons.tbl -------------------------------\r\n";
179+
found = 1;
180+
}
181+
}
182+
183+
if (found) {
184+
result += line;
185+
result += "\r\n";
186+
}
187+
}
188+
189+
cfclose(fp);
190+
191+
num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-wep.tbm"), CF_SORT_REVERSE);
192+
193+
for (n = 0; n < num_files; n++) {
194+
tbl_file_names[n] += ".tbm";
195+
196+
fp = cfopen(tbl_file_names[n].c_str(), "r");
197+
Assert(fp);
198+
199+
memset(line, 0, sizeof(line));
200+
memset(line2, 0, sizeof(line2));
201+
found = 0;
202+
comment = 0;
203+
204+
while (cfgets(line, 255, fp)) {
205+
while (line[strlen(line) - 1] == '\n')
206+
line[strlen(line) - 1] = 0;
207+
208+
for (i = j = 0; line[i]; i++) {
209+
if (line[i] == '/' && line[i + 1] == '/')
210+
break;
211+
212+
if (line[i] == '/' && line[i + 1] == '*') {
213+
comment = 1;
214+
i++;
215+
continue;
216+
}
217+
218+
if (line[i] == '*' && line[i + 1] == '/') {
219+
comment = 0;
220+
i++;
221+
continue;
222+
}
223+
224+
if (!comment)
225+
line2[j++] = line[i];
226+
}
227+
228+
line2[j] = 0;
229+
if (!strnicmp(line2, "$Name:", 6)) {
230+
drop_trailing_white_space(line2);
231+
found = 0;
232+
i = 6;
233+
234+
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
235+
i++;
236+
237+
if (!stricmp(line2 + i, wip->name)) {
238+
memset(file_text, 0, sizeof(file_text));
239+
snprintf(file_text,
240+
sizeof(file_text) - 1,
241+
"-- %s -------------------------------\r\n",
242+
tbl_file_names[n].c_str());
243+
result += file_text;
244+
found = 1;
245+
}
246+
}
247+
248+
if (found) {
249+
result += line;
250+
result += "\r\n";
251+
}
252+
}
253+
254+
cfclose(fp);
255+
}
256+
257+
return result;
258+
}
259+
134260
SCP_string get_directory_or_vp(const char* path)
135261
{
136262
SCP_string result(path);

code/lab/dialogs/lab_ui_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
SCP_string get_ship_table_text(ship_info* sip);
66

7+
SCP_string get_weapon_table_text(weapon_info* wip);
8+
79
SCP_string get_directory_or_vp(const char* path);
810

911
bool graphics_options_changed();

0 commit comments

Comments
 (0)