Skip to content

Commit e1d67ce

Browse files
authored
Allow defining a default profile to use in non-mission rendering (#7238)
* allow defining a default profile to use in non-mission rendering * Correct comment typo in lighting_profiles.h
1 parent 252655c commit e1d67ce

File tree

7 files changed

+60
-1
lines changed

7 files changed

+60
-1
lines changed

code/lighting/lighting_profiles.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ typedef int profile_index;
2525
profile _current;
2626
SCP_unordered_map<SCP_string, profile> Profiles;
2727
SCP_string default_profile_name;
28+
SCP_string non_mission_profile_name;
2829

2930
const SCP_string &default_name()
3031
{
3132
return default_profile_name;
3233
}
3334

35+
const SCP_string& non_mission_name()
36+
{
37+
return non_mission_profile_name;
38+
}
39+
3440
const profile* current()
3541
{
3642
return &_current;
@@ -54,6 +60,11 @@ void switch_to(const SCP_string& name)
5460
_current = Profiles[name];
5561
}
5662

63+
void switch_to_non_mission()
64+
{
65+
switch_to(non_mission_profile_name);
66+
}
67+
5768
void update_current_profile()
5869
{
5970
// processes any change-overs and transitions
@@ -250,7 +261,14 @@ void parse_all();
250261
void load_profiles()
251262
{
252263
default_profile_name = "Default Profile";
264+
non_mission_profile_name = default_profile_name;
253265
parse_all();
266+
if (Profiles.find(non_mission_profile_name) == Profiles.end()) {
267+
mprintf(("Unknown non-mission lighting profile '%s'; using '%s' instead.\n",
268+
non_mission_profile_name.c_str(),
269+
default_profile_name.c_str()));
270+
non_mission_profile_name = default_profile_name;
271+
}
254272
switch_to(default_profile_name);
255273
}
256274
// The logic for grabbing all the parseable files
@@ -341,6 +359,10 @@ void profile::parse(const char* filename, const SCP_string& profile_name, const
341359
tonemapper = tn;
342360
parsed = true;
343361
}
362+
if (optional_string("$Non-mission lighting profile:")) {
363+
stuff_string(non_mission_profile_name, F_NAME);
364+
parsed = true;
365+
}
344366
parsed |= parse_optional_float_into("$PPC Toe Strength:", &ppc_values.toe_strength);
345367
parsed |= parse_optional_float_into("$PPC Toe Length:", &ppc_values.toe_length);
346368
parsed |= parse_optional_float_into("$PPC Shoulder Length:", &ppc_values.shoulder_length);

code/lighting/lighting_profiles.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class profile {
8282
};
8383

8484
const SCP_string &default_name();
85+
const SCP_string& non_mission_name();
8586
const profile* current();
8687
enum TonemapperAlgorithm name_to_tonemapper(SCP_string name);
8788
SCP_string tonemapper_to_name(TonemapperAlgorithm tnm);
@@ -103,4 +104,23 @@ float lab_get_emissive();
103104
void lab_set_emissive(float in);
104105
SCP_vector<SCP_string> list_profiles();
105106
void switch_to(const SCP_string& name);
106-
} // namespace lighting_profiles
107+
void switch_to_non_mission();
108+
109+
// Use the tech room profile and then automatically
110+
// remove it on destruction.
111+
class set_non_mission_profile {
112+
public:
113+
set_non_mission_profile() : _old_profile_name(current()->name)
114+
{
115+
switch_to_non_mission();
116+
}
117+
118+
~set_non_mission_profile()
119+
{
120+
switch_to(_old_profile_name);
121+
}
122+
123+
private:
124+
SCP_string _old_profile_name;
125+
};
126+
} // namespace lighting_profiles

code/menuui/techmenu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "io/key.h"
2424
#include "io/mouse.h"
2525
#include "lighting/lighting.h"
26+
#include "lighting/lighting_profiles.h"
2627
#include "localization/localize.h"
2728
#include "menuui/techmenu.h"
2829
#include "missionui/missionscreencommon.h"
@@ -516,6 +517,8 @@ void tech_common_render()
516517

517518
void techroom_ships_render(float frametime)
518519
{
520+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
521+
519522
// render all the common stuff
520523
tech_common_render();
521524

code/missionui/missionbrief.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "io/timer.h"
2929
#include "jumpnode/jumpnode.h"
3030
#include "lighting/lighting.h"
31+
#include "lighting/lighting_profiles.h"
3132
#include "menuui/snazzyui.h"
3233
#include "mission/missionbriefcommon.h"
3334
#include "mission/missioncampaign.h"
@@ -1080,6 +1081,8 @@ void brief_render_closeup_text()
10801081
//
10811082
void brief_render_closeup(int ship_class, float frametime)
10821083
{
1084+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
1085+
10831086
matrix view_orient = IDENTITY_MATRIX;
10841087
matrix temp_matrix;
10851088
float ang;

code/missionui/missionscreencommon.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "io/mouse.h"
3333
#include "io/timer.h"
3434
#include "lighting/lighting.h"
35+
#include "lighting/lighting_profiles.h"
3536
#include "missionui/chatbox.h"
3637
#include "missionui/missionbrief.h"
3738
#include "missionui/missionscreencommon.h"
@@ -1553,6 +1554,8 @@ int restore_wss_data(ubyte *data)
15531554

15541555
void draw_model_icon(int model_id, uint64_t flags, float closeup_zoom, int x, int y, int w, int h, ship_info *sip, int resize_mode, const vec3d *closeup_pos)
15551556
{
1557+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
1558+
15561559
matrix object_orient = IDENTITY_MATRIX;
15571560
angles rot_angles = vmd_zero_angles;
15581561
float zoom = closeup_zoom * 2.5f;
@@ -1674,6 +1677,8 @@ void draw_model_rotating(model_render_params *render_info, int ship_class, int m
16741677
model_set_up_techroom_instance(&Ship_info[ship_class], model_instance);
16751678
}
16761679

1680+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
1681+
16771682
float time = (timer_get_milliseconds()-anim_timer_start)/1000.0f;
16781683
angles rot_angles, view_angles;
16791684
matrix model_orient;

code/missionui/missionweaponchoice.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "io/mouse.h"
2323
#include "io/timer.h"
2424
#include "lighting/lighting.h"
25+
#include "lighting/lighting_profiles.h"
2526
#include "localization/localize.h"
2627
#include "menuui/snazzyui.h"
2728
#include "missionui/chatbox.h"
@@ -768,6 +769,8 @@ void draw_3d_overhead_view(int model_num,
768769
overhead_style style,
769770
const SCP_string& tcolor)
770771
{
772+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
773+
771774
ship_info* sip = &Ship_info[ship_class];
772775

773776
if (model_num < 0) {

code/model/modelrender.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "io/timer.h"
2121
#include "jumpnode/jumpnode.h"
2222
#include "lighting/lighting.h"
23+
#include "lighting/lighting_profiles.h"
2324
#include "math/staticrand.h"
2425
#include "missionui/missionscreencommon.h"
2526
#include "mod_table/mod_table.h"
@@ -3111,6 +3112,8 @@ void modelinstance_replace_active_texture(polymodel_instance* pmi, const char* o
31113112
bool render_tech_model(tech_render_type model_type, int x1, int y1, int x2, int y2, float zoom, bool lighting, int class_idx, const matrix* orient, const SCP_string &pof_filename, float close_zoom, const vec3d *close_pos, const SCP_string& tcolor)
31123113
{
31133114

3115+
lighting_profiles::set_non_mission_profile non_mission_lighting_profile;
3116+
31143117
model_render_params render_info;
31153118
const vec3d *closeup_pos;
31163119
float closeup_zoom;

0 commit comments

Comments
 (0)