Skip to content

Commit 7865ae9

Browse files
committed
lab support
1 parent 52b9482 commit 7865ae9

File tree

9 files changed

+206
-2
lines changed

9 files changed

+206
-2
lines changed

code/lab/dialogs/lab_ui.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ship/shiphit.h"
1212
#include "weapon/weapon.h"
1313
#include "mission/missionload.h"
14+
#include "prop/prop.h"
1415

1516
using namespace ImGui;
1617

@@ -171,6 +172,27 @@ void LabUi::build_object_list()
171172
}
172173
}
173174

175+
void LabUi::build_prop_list()
176+
{
177+
with_TreeNode("Prop Classes")
178+
{
179+
int prop_info_idx = 0;
180+
181+
for (auto const& class_def : Prop_info) {
182+
SCP_string node_label;
183+
sprintf(node_label, "##PropClassIndex%i", prop_info_idx);
184+
TreeNodeEx(node_label.c_str(),
185+
ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen,
186+
"%s",
187+
class_def.name);
188+
if (IsItemClicked() && !IsItemToggledOpen()) {
189+
getLabManager()->changeDisplayedObject(LabMode::Prop, prop_info_idx);
190+
}
191+
prop_info_idx++;
192+
}
193+
}
194+
}
195+
174196
void LabUi::build_background_list() const
175197
{
176198
SCP_vector<SCP_string> t_missions;
@@ -273,6 +295,8 @@ void LabUi::show_object_selector() const
273295
build_weapon_list();
274296

275297
build_object_list();
298+
299+
build_prop_list();
276300
}
277301
}
278302
}
@@ -418,7 +442,8 @@ void LabUi::show_render_options()
418442
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
419443
}
420444
Checkbox("Show full detail", &show_full_detail);
421-
if (getLabManager()->CurrentMode != LabMode::Asteroid) {
445+
if (getLabManager()->CurrentMode == LabMode::Ship ||
446+
getLabManager()->CurrentMode == LabMode::Weapon) {
422447
Checkbox("Show thrusters", &show_thrusters);
423448
if (getLabManager()->CurrentMode == LabMode::Ship) {
424449
Checkbox("Show afterburners", &show_afterburners);
@@ -1482,6 +1507,32 @@ void LabUi::show_object_options() const
14821507
}
14831508
}
14841509
}
1510+
} else if (getLabManager()->CurrentMode == LabMode::Prop && getLabManager()->CurrentClass >= 0) {
1511+
const auto& info = Prop_info[getLabManager()->CurrentClass];
1512+
1513+
with_CollapsingHeader("Object Info")
1514+
{
1515+
static SCP_string table_text;
1516+
static int old_class = -1;
1517+
1518+
if (table_text.empty() || old_class != getLabManager()->CurrentClass) {
1519+
table_text = get_prop_table_text(&info);
1520+
old_class = getLabManager()->CurrentClass;
1521+
}
1522+
1523+
InputTextMultiline("##prop_table_text",
1524+
const_cast<char*>(table_text.c_str()),
1525+
table_text.length(),
1526+
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
1527+
ImGuiInputTextFlags_ReadOnly);
1528+
}
1529+
1530+
with_CollapsingHeader("Object actions")
1531+
{
1532+
if (getLabManager()->isSafeForAsteroids()) {
1533+
// No actions yet
1534+
}
1535+
}
14851536
}
14861537
}
14871538
}

code/lab/dialogs/lab_ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class LabUi {
3232
static void build_object_list();
3333
static void build_asteroid_list();
3434
static void build_debris_list();
35+
static void build_prop_list();
3536
void build_background_list() const;
3637
void show_render_options();
3738
void show_object_options() const;

code/lab/dialogs/lab_ui_helpers.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,128 @@ SCP_string get_asteroid_table_text(const asteroid_info* aip)
411411
return result;
412412
}
413413

414+
SCP_string get_prop_table_text(const prop_info* pip)
415+
{
416+
char line[256], line2[256], file_text[82];
417+
int i, j, n, found = 0, comment = 0, num_files = 0;
418+
SCP_vector<SCP_string> tbl_file_names;
419+
SCP_string result;
420+
421+
auto fp = cfopen("props.tbl", "r");
422+
if (!fp)
423+
return "No props.tbl found.\r\n";
424+
425+
while (cfgets(line, 255, fp)) {
426+
while (line[strlen(line) - 1] == '\n')
427+
line[strlen(line) - 1] = 0;
428+
429+
for (i = j = 0; line[i]; i++) {
430+
if (line[i] == '/' && line[i + 1] == '/')
431+
break;
432+
if (line[i] == '/' && line[i + 1] == '*') {
433+
comment = 1;
434+
i++;
435+
continue;
436+
}
437+
if (line[i] == '*' && line[i + 1] == '/') {
438+
comment = 0;
439+
i++;
440+
continue;
441+
}
442+
if (!comment)
443+
line2[j++] = line[i];
444+
}
445+
446+
line2[j] = 0;
447+
if (!strnicmp(line2, "$Name:", 6)) {
448+
drop_trailing_white_space(line2);
449+
found = 0;
450+
i = 6;
451+
452+
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
453+
i++;
454+
455+
if (!stricmp(line2 + i, pip->name)) {
456+
result += "-- props.tbl -------------------------------\r\n";
457+
found = 1;
458+
}
459+
}
460+
461+
if (found) {
462+
result += line;
463+
result += "\r\n";
464+
}
465+
}
466+
467+
cfclose(fp);
468+
469+
num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-prp.tbm"), CF_SORT_REVERSE);
470+
471+
for (n = 0; n < num_files; n++) {
472+
tbl_file_names[n] += ".tbm";
473+
474+
fp = cfopen(tbl_file_names[n].c_str(), "r");
475+
if (!fp)
476+
continue;
477+
478+
memset(line, 0, sizeof(line));
479+
memset(line2, 0, sizeof(line2));
480+
found = 0;
481+
comment = 0;
482+
483+
while (cfgets(line, 255, fp)) {
484+
while (line[strlen(line) - 1] == '\n')
485+
line[strlen(line) - 1] = 0;
486+
487+
for (i = j = 0; line[i]; i++) {
488+
if (line[i] == '/' && line[i + 1] == '/')
489+
break;
490+
if (line[i] == '/' && line[i + 1] == '*') {
491+
comment = 1;
492+
i++;
493+
continue;
494+
}
495+
if (line[i] == '*' && line[i + 1] == '/') {
496+
comment = 0;
497+
i++;
498+
continue;
499+
}
500+
if (!comment)
501+
line2[j++] = line[i];
502+
}
503+
504+
line2[j] = 0;
505+
if (!strnicmp(line2, "$Name:", 6)) {
506+
drop_trailing_white_space(line2);
507+
found = 0;
508+
i = 6;
509+
510+
while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
511+
i++;
512+
513+
if (!stricmp(line2 + i, pip->name)) {
514+
memset(file_text, 0, sizeof(file_text));
515+
snprintf(file_text,
516+
sizeof(file_text) - 1,
517+
"-- %s -------------------------------\r\n",
518+
tbl_file_names[n].c_str());
519+
result += file_text;
520+
found = 1;
521+
}
522+
}
523+
524+
if (found) {
525+
result += line;
526+
result += "\r\n";
527+
}
528+
}
529+
530+
cfclose(fp);
531+
}
532+
533+
return result;
534+
}
535+
414536
SCP_string get_directory_or_vp(const char* path)
415537
{
416538
SCP_string result(path);

code/lab/dialogs/lab_ui_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "asteroid/asteroid.h"
44
#include "ship/ship.h"
5+
#include "prop/prop.h"
56

67
SCP_map<int, SCP_string> get_docking_point_map(int model_index);
78

@@ -13,6 +14,8 @@ SCP_string get_weapon_table_text(weapon_info* wip);
1314

1415
SCP_string get_asteroid_table_text(const asteroid_info* aip);
1516

17+
SCP_string get_prop_table_text(const prop_info* pip);
18+
1619
SCP_string get_directory_or_vp(const char* path);
1720

1821
bool graphics_options_changed();

code/lab/labv2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ enum class LabMode {
44
Asteroid,
55
Ship,
66
Weapon,
7+
Prop,
78
None
89
};
910

code/lab/manager/lab_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "weapon/muzzleflash.h"
1515
#include "weapon/beam.h"
1616
#include "ai/aigoals.h"
17+
#include "prop/prop.h"
1718

1819
#include "freespace.h"
1920

@@ -748,6 +749,12 @@ void LabManager::changeDisplayedObject(LabMode mode, int info_index, int subtype
748749
ai_add_ship_goal_scripting(AI_GOAL_PLAY_DEAD_PERSISTENT, -1, 100, nullptr, &Ai_info[Player_ship->ai_index], 0, 0);
749750
}
750751
break;
752+
case LabMode::Prop:
753+
CurrentObject = prop_create(&CurrentOrientation, &CurrentPosition, CurrentClass);
754+
if (isSafeForShips()) {
755+
ModelFilename = Prop_info[CurrentClass].pof_file;
756+
}
757+
break;
751758
case LabMode::Weapon:
752759
if (ShowingTechModel && VALID_FNAME(Weapon_info[CurrentClass].tech_model)) {
753760
ModelFilename = Weapon_info[CurrentClass].tech_model;

code/lab/manager/lab_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class LabManager {
107107
return CurrentMode == LabMode::Ship && CurrentObject != -1 && Objects[CurrentObject].type == OBJ_SHIP;
108108
}
109109

110+
bool isSafeForProps() {
111+
return CurrentMode == LabMode::Prop && CurrentObject != -1 && Objects[CurrentObject].type == OBJ_PROP;
112+
}
113+
110114
bool isSafeForWeapons() {
111115
bool valid = CurrentObject != -1 && (Objects[CurrentObject].type == OBJ_WEAPON || Objects[CurrentObject].type == OBJ_BEAM);
112116
return CurrentMode == LabMode::Weapon && valid;

code/lab/renderer/lab_renderer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "particle/particle.h"
1414
#include "starfield/starfield.h"
1515
#include "starfield/nebula.h"
16+
#include "prop/prop.h"
1617

1718
#include "missionui/missionscreencommon.h"
1819
#include "tracing/tracing.h"
@@ -114,6 +115,20 @@ void LabRenderer::renderModel(float frametime) {
114115
}
115116
}
116117

118+
if (obj->type == OBJ_PROP) {
119+
Props[obj->instance].flags.set(Prop::Prop_Flags::Draw_as_wireframe, renderFlags[LabRenderFlag::ShowWireframe]);
120+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_full_detail, renderFlags[LabRenderFlag::ShowFullDetail]);
121+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_light,
122+
renderFlags[LabRenderFlag::NoLighting] || currentMissionBackground == LAB_MISSION_NONE_STRING);
123+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_diffuse, renderFlags[LabRenderFlag::NoDiffuseMap]);
124+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_glowmap, renderFlags[LabRenderFlag::NoGlowMap]);
125+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_normalmap, renderFlags[LabRenderFlag::NoNormalMap]);
126+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_specmap, renderFlags[LabRenderFlag::NoSpecularMap]);
127+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_reflectmap, renderFlags[LabRenderFlag::NoReflectMap]);
128+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_heightmap, renderFlags[LabRenderFlag::NoHeightMap]);
129+
Props[obj->instance].flags.set(Prop::Prop_Flags::Render_without_ambientmap, renderFlags[LabRenderFlag::NoAOMap]);
130+
}
131+
117132
if (obj->type == OBJ_WEAPON) {
118133
Weapons[obj->instance].weapon_flags.set(Weapon::Weapon_Flags::Draw_as_wireframe, renderFlags[LabRenderFlag::ShowWireframe]);
119134
Weapons[obj->instance].weapon_flags.set(Weapon::Weapon_Flags::Render_full_detail, renderFlags[LabRenderFlag::ShowFullDetail]);

code/parse/sexp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class ship_subsys;
2121
class ship;
22-
class prop;
22+
struct prop;
2323
class waypoint_list;
2424
class object;
2525
class waypoint;

0 commit comments

Comments
 (0)