Skip to content

Commit

Permalink
Default settings tbl (#6491)
Browse files Browse the repository at this point in the history
* initial version of default_settings.tbl

* Add a way to change player detail level defaults and implement a couple more options to detail_settings.tbl

* support the rest of 2d.cpp options

* Allow enforcing options to a specific value

* modernize detail defaults, levels, and values

* Fix parsing issue and remove lambda capture by reference

* fix print

* clang

* More efficient +Enforce parsing

* cleanup

* typo

* don't negate this

* error_display

* clarify language between presets, levels, and values

* add default case

* small fix

* use a map to minimize string lookups
  • Loading branch information
MjnMixael authored Jan 12, 2025
1 parent de969b5 commit 4dfaa85
Show file tree
Hide file tree
Showing 27 changed files with 635 additions and 214 deletions.
4 changes: 2 additions & 2 deletions code/ai/ai_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void parse_ai_profiles_tbl(const char *filename)
}

if (optional_string("$Detail Distance Multiplier:"))
parse_float_list(profile->detail_distance_mult, MAX_DETAIL_LEVEL + 1);
parse_float_list(profile->detail_distance_mult, MAX_DETAIL_VALUE + 1);

set_flag(profile, "$big ships can attack beam turrets on untargeted ships:", AI::Profile_Flags::Big_ships_can_attack_beam_turrets_on_untargeted_ships);

Expand Down Expand Up @@ -822,7 +822,7 @@ void ai_profile_t::reset()
player_autoaim_fov[i] = 0;
}

for (int i = 0; i <= MAX_DETAIL_LEVEL; ++i) {
for (int i = 0; i <= MAX_DETAIL_VALUE; ++i) {
detail_distance_mult[i] = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion code/ai/ai_profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ai_profile_t {
// Player-specific autoaim FOV override
float player_autoaim_fov[NUM_SKILL_LEVELS];

float detail_distance_mult[MAX_DETAIL_LEVEL + 1]; //MAX_DETAIL_LEVEL really needs to be 4
float detail_distance_mult[MAX_DETAIL_VALUE + 1]; //MAX_DETAIL_VALUE really needs to be 4

// minimum radius for the line-of-sight (los) detection --wookieejedi
float los_min_detection_radius;
Expand Down
2 changes: 1 addition & 1 deletion code/asteroid/asteroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void asteroid_create_all()
return;
}

int max_asteroids = Asteroid_field.num_initial_asteroids; // * (1.0f - 0.1f*(MAX_DETAIL_LEVEL-Detail.asteroid_density)));
int max_asteroids = Asteroid_field.num_initial_asteroids; // * (1.0f - 0.1f*(MAX_DETAIL_VALUE-Detail.asteroid_density)));

int num_debris_types = 0;

Expand Down
233 changes: 141 additions & 92 deletions code/globalincs/systemvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,88 +155,84 @@ void game_busy(const char *filename)
}
}

#if MAX_DETAIL_LEVEL != 4
#error MAX_DETAIL_LEVEL is assumed to be 4 in SystemVars.cpp
#endif
static_assert(MAX_DETAIL_VALUE == 4, "MAX_DETAIL_VALUE is assumed to be 4 in SystemVars.cpp");

#if NUM_DEFAULT_DETAIL_LEVELS != 4
#error NUM_DEFAULT_DETAIL_LEVELS is assumed to be 4 in SystemVars.cpp
#endif
static_assert(static_cast<int>(DefaultDetailPreset::Num_detail_presets) == 4, "Code in ManagePilot assumes Num_detail_presets = 4");

// Detail level stuff
detail_levels Detail_defaults[NUM_DEFAULT_DETAIL_LEVELS] = {
{ // Low
0, // setting
// ===== Analogs (0-MAX_DETAIL_LEVEL) ====
0, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
0, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
0, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
0, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
0, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
0, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
0, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
2, // lighting; // 0=min, MAX_DETAIL_LEVEL=max

// ==== Booleans ====
0, // targetview_model; // 0=off, 1=on
0, // planets_suns; // 0=off, 1=on
0, // weapon_extras
// Detail preset stuff
detail_levels Detail_defaults[static_cast<int>(DefaultDetailPreset::Num_detail_presets)] = {
{
DefaultDetailPreset::Low, // setting
// ================== Analogs ==================
0, // nebula_detail; // 0=lowest detail, MAX_DETAIL_VALUE=highest detail
0, // detail_distance; // 0=lowest MAX_DETAIL_VALUE=highest
0, // hardware_textures; // 0=max culling, MAX_DETAIL_VALUE=no culling
0, // num_small_debris; // 0=min number, MAX_DETAIL_VALUE=max number
0, // num_particles; // 0=min number, MAX_DETAIL_VALUE=max number
0, // num_stars; // 0=min number, MAX_DETAIL_VALUE=max number
0, // shield_effects; // 0=min, MAX_DETAIL_VALUE=max
2, // lighting; // 0=min, MAX_DETAIL_VALUE=max

// ================== Booleans ==================
false, // targetview_model; // false=off, true=on
false, // planets_suns; // false=off, true=on
false, // weapon_extras // false=off, true=on
},
{ // Medium
1, // setting
// ===== Analogs (0-MAX_DETAIL_LEVEL) ====
2, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
2, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
2, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
2, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
2, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
2, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
2, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
3, // lighting; // 0=min, MAX_DETAIL_LEVEL=max

// ==== Booleans ====
1, // targetview_model; // 0=off, 1=on
1, // planets_suns; // 0=off, 1=on
1, // weapon extras
{
DefaultDetailPreset::Medium, // setting
// ================== Analogs ==================
2, // nebula_detail; // 0=lowest detail, MAX_DETAIL_VALUE=highest detail
2, // detail_distance; // 0=lowest MAX_DETAIL_VALUE=highest
2, // hardware_textures; // 0=max culling, MAX_DETAIL_VALUE=no culling
2, // num_small_debris; // 0=min number, MAX_DETAIL_VALUE=max number
2, // num_particles; // 0=min number, MAX_DETAIL_VALUE=max number
2, // num_stars; // 0=min number, MAX_DETAIL_VALUE=max number
2, // shield_effects; // 0=min, MAX_DETAIL_VALUE=max
3, // lighting; // 0=min, MAX_DETAIL_VALUE=max

// ================== Booleans ==================
true, // targetview_model; // false=off, true=on
true, // planets_suns; // false=off, true=on
true, // weapon_extras // false=off, true=on
},
{ // High level
2, // setting
// ===== Analogs (0-MAX_DETAIL_LEVEL) ====
2, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
2, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
3, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
3, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
3, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
4, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
3, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
4, // lighting; // 0=min, MAX_DETAIL_LEVEL=max

// ==== Booleans ====
1, // targetview_model; // 0=off, 1=on
1, // planets_suns; // 0=off, 1=on
1, // weapon_extras
{
DefaultDetailPreset::High, // setting
// ================== Analogs ==================
2, // nebula_detail; // 0=lowest detail, MAX_DETAIL_VALUE=highest detail
2, // detail_distance; // 0=lowest MAX_DETAIL_VALUE=highest
3, // hardware_textures; // 0=max culling, MAX_DETAIL_VALUE=no culling
3, // num_small_debris; // 0=min number, MAX_DETAIL_VALUE=max number
3, // num_particles; // 0=min number, MAX_DETAIL_VALUE=max number
4, // num_stars; // 0=min number, MAX_DETAIL_VALUE=max number
3, // shield_effects; // 0=min, MAX_DETAIL_VALUE=max
4, // lighting; // 0=min, MAX_DETAIL_VALUE=max

// ================== Booleans ==================
true, // targetview_model; // false=off, true=on
true, // planets_suns; // false=off, true=on
true, // weapon_extras // false=off, true=on
},
{ // Highest level
3, // setting
// ===== Analogs (0-MAX_DETAIL_LEVEL) ====
4, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
4, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
4, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
4, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
4, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
4, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
4, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
4, // lighting; // 0=min, MAX_DETAIL_LEVEL=max

// ==== Booleans ====
1, // targetview_model; // 0=off, 1=on
1, // planets_suns; // 0=off, 1=on
1, // weapon_extras
{
DefaultDetailPreset::VeryHigh, // setting
// ================== Analogs ==================
4, // nebula_detail; // 0=lowest detail, MAX_DETAIL_VALUE=highest detail
4, // detail_distance; // 0=lowest MAX_DETAIL_VALUE=highest
4, // hardware_textures; // 0=max culling, MAX_DETAIL_VALUE=no culling
4, // num_small_debris; // 0=min number, MAX_DETAIL_VALUE=max number
4, // num_particles; // 0=min number, MAX_DETAIL_VALUE=max number
4, // num_stars; // 0=min number, MAX_DETAIL_VALUE=max number
4, // shield_effects; // 0=min, MAX_DETAIL_VALUE=max
4, // lighting; // 0=min, MAX_DETAIL_VALUE=max

// ================== Booleans ==================
true, // targetview_model; // false=off, true=on
true, // planets_suns; // false=off, true=on
true, // weapon_extras // false=off, true=on
},
};

// Global used to access detail levels in game and libs
detail_levels Detail = Detail_defaults[NUM_DEFAULT_DETAIL_LEVELS - 1];
// Global used to access detail presets in game and libs
detail_levels Detail = Detail_defaults[static_cast<int>(DefaultDetailPreset::Num_detail_presets) - 1];

const SCP_vector<std::pair<int, std::pair<const char*, int>>> DetailLevelValues = {{ 0, {"Minimum", 1680}},
{ 1, {"Low", 1160}},
Expand All @@ -250,7 +246,7 @@ const auto ModelDetailOption __UNUSED = options::OptionBuilder<int>("Graphics.De
.importance(8)
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.change_listener([](int val, bool) {
Detail.detail_distance = val;
return true;
Expand All @@ -264,7 +260,7 @@ const auto TexturesOption __UNUSED = options::OptionBuilder<int>("Graphics.Textu
.importance(6)
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.change_listener([](int val, bool) {
Detail.hardware_textures = val;
return true;
Expand All @@ -278,7 +274,7 @@ const auto ParticlesOption __UNUSED = options::OptionBuilder<int>("Graphics.Part
.importance(5)
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.change_listener([](int val, bool) {
Detail.num_particles = val;
return true;
Expand All @@ -291,7 +287,7 @@ const auto SmallDebrisOption __UNUSED = options::OptionBuilder<int>("Graphics.Sm
std::pair<const char*, int>{"Level of detail of impact effects", 1743})
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.importance(4)
.change_listener([](int val,bool) {
Detail.num_small_debris = val;
Expand All @@ -306,7 +302,7 @@ const auto ShieldEffectsOption __UNUSED = options::OptionBuilder<int>("Graphics.
.importance(3)
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.change_listener([](int val, bool) {
Detail.shield_effects = val;
return true;
Expand All @@ -320,7 +316,7 @@ const auto StarsOption __UNUSED = options::OptionBuilder<int>("Graphics.Stars",
.importance(2)
.category(std::make_pair("Graphics", 1825))
.values(DetailLevelValues)
.default_val(MAX_DETAIL_LEVEL)
.default_val(MAX_DETAIL_VALUE)
.change_listener([](int val, bool) {
Detail.num_stars = val;
return true;
Expand All @@ -330,32 +326,85 @@ const auto StarsOption __UNUSED = options::OptionBuilder<int>("Graphics.Stars",

// Call this with:
// 0 - lowest
// NUM_DETAIL_LEVELS - highest
// Num_detail_presets - highest
// To set the parameters in Detail to some set of defaults
void detail_level_set(int level)
void detail_level_set(DefaultDetailPreset preset)
{
if ( level < 0 ) {
Detail.setting = -1;
if (preset == DefaultDetailPreset::Custom) {
Detail.setting = DefaultDetailPreset::Custom;
return;
}
Assert( level >= 0 );
Assert( level < NUM_DEFAULT_DETAIL_LEVELS );

Detail = Detail_defaults[level];
Detail = Detail_defaults[static_cast<int>(preset)];
}

// Change detail values 0 - MAX_DETAIL_VALUE
void change_default_detail_level(DefaultDetailPreset preset, DetailSetting selection, int value)
{

// Use a switch statement for more readable access to the struct members
switch (selection) {
case DetailSetting::NebulaDetail:
Detail_defaults[static_cast<int>(preset)].nebula_detail = value;
break;
case DetailSetting::DetailDistance:
Detail_defaults[static_cast<int>(preset)].detail_distance = value;
break;
case DetailSetting::HardwareTextures:
Detail_defaults[static_cast<int>(preset)].hardware_textures = value;
break;
case DetailSetting::NumSmallDebris:
Detail_defaults[static_cast<int>(preset)].num_small_debris = value;
break;
case DetailSetting::NumParticles:
Detail_defaults[static_cast<int>(preset)].num_particles = value;
break;
case DetailSetting::NumStars:
Detail_defaults[static_cast<int>(preset)].num_stars = value;
break;
case DetailSetting::ShieldEffects:
Detail_defaults[static_cast<int>(preset)].shield_effects = value;
break;
case DetailSetting::Lighting:
Detail_defaults[static_cast<int>(preset)].lighting = value;
break;
default:
Assertion(false, "Invalid detail selection. Get a coder!");
}
}

// Change detail values bool overload
void change_default_detail_level(DefaultDetailPreset preset, DetailSetting selection, bool value)
{

// Use a switch statement for more readable access to the struct members
switch (selection) {
case DetailSetting::TargetViewModel:
Detail_defaults[static_cast<int>(preset)].targetview_model = value;
break;
case DetailSetting::PlanetsSuns:
Detail_defaults[static_cast<int>(preset)].planets_suns = value;
break;
case DetailSetting::WeaponExtras:
Detail_defaults[static_cast<int>(preset)].weapon_extras = value;
break;
default:
Assertion(false, "Invalid detail selection. Get a coder!");
}
}

// Returns the current detail level or -1 if custom.
int current_detail_level()
// Returns the current detail preset or -1 if custom.
DefaultDetailPreset current_detail_preset()
{
// return Detail.setting;
int i;

for (i=0; i<NUM_DEFAULT_DETAIL_LEVELS; i++ ) {
for (i = 0; i < static_cast<int>(DefaultDetailPreset::Num_detail_presets); i++) {
if ( memcmp( &Detail, &Detail_defaults[i], sizeof(detail_levels) )==0 ) {
return i;
return static_cast<DefaultDetailPreset>(i);
}
}
return -1;
return DefaultDetailPreset::Custom;
}

#ifndef NDEBUG
Expand Down
Loading

0 comments on commit 4dfaa85

Please sign in to comment.