Skip to content

Commit 41f1d18

Browse files
committed
lab support
1 parent a76efe9 commit 41f1d18

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

@@ -177,6 +178,27 @@ void LabUi::build_object_list()
177178
}
178179
}
179180

181+
void LabUi::build_prop_list()
182+
{
183+
with_TreeNode("Prop Classes")
184+
{
185+
int prop_info_idx = 0;
186+
187+
for (auto const& class_def : Prop_info) {
188+
SCP_string node_label;
189+
sprintf(node_label, "##PropClassIndex%i", prop_info_idx);
190+
TreeNodeEx(node_label.c_str(),
191+
ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen,
192+
"%s",
193+
class_def.name);
194+
if (IsItemClicked() && !IsItemToggledOpen()) {
195+
getLabManager()->changeDisplayedObject(LabMode::Prop, prop_info_idx);
196+
}
197+
prop_info_idx++;
198+
}
199+
}
200+
}
201+
180202
void LabUi::build_background_list() const
181203
{
182204
SCP_vector<SCP_string> t_missions;
@@ -279,6 +301,8 @@ void LabUi::show_object_selector() const
279301
build_weapon_list();
280302

281303
build_object_list();
304+
305+
build_prop_list();
282306
}
283307
}
284308
}
@@ -424,7 +448,8 @@ void LabUi::show_render_options()
424448
Checkbox("Rotate/Translate Subsystems", &animate_subsystems);
425449
}
426450
Checkbox("Show full detail", &show_full_detail);
427-
if (getLabManager()->CurrentMode != LabMode::Asteroid) {
451+
if (getLabManager()->CurrentMode == LabMode::Ship ||
452+
getLabManager()->CurrentMode == LabMode::Weapon) {
428453
Checkbox("Show thrusters", &show_thrusters);
429454
if (getLabManager()->CurrentMode == LabMode::Ship) {
430455
Checkbox("Show afterburners", &show_afterburners);
@@ -1397,6 +1422,32 @@ void LabUi::show_object_options() const
13971422
}
13981423
}
13991424
}
1425+
} else if (getLabManager()->CurrentMode == LabMode::Prop && getLabManager()->CurrentClass >= 0) {
1426+
const auto& info = Prop_info[getLabManager()->CurrentClass];
1427+
1428+
with_CollapsingHeader("Object Info")
1429+
{
1430+
static SCP_string table_text;
1431+
static int old_class = -1;
1432+
1433+
if (table_text.empty() || old_class != getLabManager()->CurrentClass) {
1434+
table_text = get_prop_table_text(&info);
1435+
old_class = getLabManager()->CurrentClass;
1436+
}
1437+
1438+
InputTextMultiline("##prop_table_text",
1439+
const_cast<char*>(table_text.c_str()),
1440+
table_text.length(),
1441+
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
1442+
ImGuiInputTextFlags_ReadOnly);
1443+
}
1444+
1445+
with_CollapsingHeader("Object actions")
1446+
{
1447+
if (getLabManager()->isSafeForAsteroids()) {
1448+
// No actions yet
1449+
}
1450+
}
14001451
}
14011452
}
14021453
}

code/lab/dialogs/lab_ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class LabUi {
2727
static void build_object_list();
2828
static void build_asteroid_list();
2929
static void build_debris_list();
30+
static void build_prop_list();
3031
void build_background_list() const;
3132
void show_render_options();
3233
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
@@ -395,6 +395,128 @@ SCP_string get_asteroid_table_text(const asteroid_info* aip)
395395
return result;
396396
}
397397

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

@@ -11,6 +12,8 @@ SCP_string get_weapon_table_text(weapon_info* wip);
1112

1213
SCP_string get_asteroid_table_text(const asteroid_info* aip);
1314

15+
SCP_string get_prop_table_text(const prop_info* pip);
16+
1417
SCP_string get_directory_or_vp(const char* path);
1518

1619
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
@@ -13,6 +13,7 @@
1313
#include "weapon/muzzleflash.h"
1414
#include "weapon/beam.h"
1515
#include "ai/aigoals.h"
16+
#include "prop/prop.h"
1617

1718
#include "freespace.h"
1819

@@ -617,6 +618,12 @@ void LabManager::changeDisplayedObject(LabMode mode, int info_index, int subtype
617618
ai_add_ship_goal_scripting(AI_GOAL_PLAY_DEAD_PERSISTENT, -1, 100, nullptr, &Ai_info[Player_ship->ai_index], 0, 0);
618619
}
619620
break;
621+
case LabMode::Prop:
622+
CurrentObject = prop_create(&CurrentOrientation, &CurrentPosition, CurrentClass);
623+
if (isSafeForShips()) {
624+
ModelFilename = Prop_info[CurrentClass].pof_file;
625+
}
626+
break;
620627
case LabMode::Weapon:
621628
if (ShowingTechModel && VALID_FNAME(Weapon_info[CurrentClass].tech_model)) {
622629
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
@@ -89,6 +89,10 @@ class LabManager {
8989
return CurrentMode == LabMode::Ship && CurrentObject != -1 && Objects[CurrentObject].type == OBJ_SHIP;
9090
}
9191

92+
bool isSafeForProps() {
93+
return CurrentMode == LabMode::Prop && CurrentObject != -1 && Objects[CurrentObject].type == OBJ_PROP;
94+
}
95+
9296
bool isSafeForWeapons() {
9397
bool valid = CurrentObject != -1 && (Objects[CurrentObject].type == OBJ_WEAPON || Objects[CurrentObject].type == OBJ_BEAM);
9498
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
@@ -12,6 +12,7 @@
1212
#include "particle/particle.h"
1313
#include "starfield/starfield.h"
1414
#include "starfield/nebula.h"
15+
#include "prop/prop.h"
1516

1617
#include "missionui/missionscreencommon.h"
1718
#include "tracing/tracing.h"
@@ -112,6 +113,20 @@ void LabRenderer::renderModel(float frametime) {
112113
}
113114
}
114115

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