Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task more config #919

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5e0c681
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 1, 2023
d5f7361
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 3, 2023
d08bfcf
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Apr 25, 2024
5126833
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk May 3, 2024
7fb35f5
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Jul 22, 2024
ad5c297
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Aug 15, 2024
08daa5b
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Sep 2, 2024
4354d63
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 3, 2024
606f5d4
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
d7dc075
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
b7ce610
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 2, 2024
bd42430
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 15, 2024
4f72ce2
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 21, 2024
a86672e
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 25, 2024
21c6366
Move more items to modern config
royfalk Nov 26, 2024
1d743f7
Possible fix to game crash when running vs
royfalk Nov 26, 2024
4ac74e8
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 5, 2024
89b7966
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 8, 2024
b46c233
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 8, 2024
0a95c09
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 8, 2024
89b1960
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 8, 2024
1721c13
Merge branch 'master' into task_more_config
royfalk Dec 9, 2024
d076534
Fix save of several components
royfalk Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/src/cmd/unit_physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void Unit::UpdatePhysics2(const Transformation &trans,

/****************************** ONLY SOUND/GFX STUFF LEFT IN THOSE FUNCTIONS *********************************/


// TODO: check if this code moved elsewhere.
void GameUnit::Thrust(const Vector &amt1, bool afterburn) {
if (this->afterburntype == 0) {
afterburn = afterburn && this->energy > this->afterburnenergy * simulation_atom_var;
Expand Down
86 changes: 83 additions & 3 deletions engine/src/configuration/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,71 @@

#include "configuration.h"
#include "game_config.h"
#include "json.h"
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>

#include <stdio.h>


std::string GetString(std::string json_string, const std::string key, bool trim = true) {
json::jobject json = json::jobject::parse(json_string);
std::vector<std::string> key_sections;
boost::split(key_sections, key, boost::is_any_of("|"));
int key_sections_size = key_sections.size();

for(std::string& key_section : key_sections) {
key_sections_size--;

if(!json.has_key(key_section)) {
return "";
}

if(key_sections_size > 0) {
json_string = json.get(key_section);
json = json::jobject::parse(json_string);
} else {
json_string = json.get(key_section);

if(!trim) {
return json_string;
}

int len = json_string.length();
json_string = json_string.substr(1,len-2);
return json_string;
}
}

return "";
}

bool GetBool(std::string json_string, const std::string key, bool default_value) {
std::string result = GetString(json_string, key, false);
if(result == "") {
return default_value;
} else {
return result == "true";
}
}

double GetDouble(std::string json_string, const std::string key, double default_value) {
std::string result = GetString(json_string, key, false);
if(result == "") {
return default_value;
} else {
try {
return std::stod(result);
} catch(...) {
std::cout << "Not a double: " << result << std::endl;
abort();
}

}
}

using vega_config::GetGameConfig;

Configuration::Configuration() {
Expand All @@ -43,6 +101,8 @@ Configuration::Configuration() {
buffer << ifs.rdbuf();
const std::string json_text = buffer.str();
graphics2_config = Graphics2Config(json_text);
game_start = vega_config::GameStart(json_text);
fuel = vega_config::Fuel(json_text);
}
}

Expand Down Expand Up @@ -125,9 +185,7 @@ void Configuration::OverrideDefaultsWithUserConfiguration() {
// fuel substruct
fuel.afterburner_fuel_usage =
GetGameConfig().GetFloat("physics.AfterburnerFuelUsage", fuel.afterburner_fuel_usage);
fuel.fmec_exit_velocity_inverse = GetGameConfig().GetFloat("physics.FMEC_exit_vel_inverse", fuel.fmec_exit_velocity_inverse);
// fuel.fmec_exit_velocity_inverse =
// 1.0F / GetGameConfig().GetFloat("physics.FMEC_exit_vel", 1.0F / 0.0000002F);

fuel.fuel_efficiency =
GetGameConfig().GetDouble("physics.LithiumRelativeEfficiency_Lithium", fuel.fuel_efficiency);
fuel.fuel_equals_warp = GetGameConfig().GetBool("physics.fuel_equals_warp", fuel.fuel_equals_warp);
Expand Down Expand Up @@ -432,6 +490,18 @@ vega_config::Fuel::Fuel() :
reactor_uses_fuel(false) {
}

vega_config::Fuel::Fuel(const std::string config) {
fuel_equals_warp = GetBool(config, "components|fuel|fuel_equals_warp", false);
fuel_factor = GetDouble(config, "components|fuel|factor", 1.0);
energy_factor = GetDouble(config, "components|energy|factor", 1.0);
ftl_energy_factor = GetDouble(config, "components|ftl_energy|factor", 1.0);

reactor_factor = GetDouble(config, "components|reactor|factor", 1.0);

ftl_drive_factor = GetDouble(config, "components|ftl_drive|factor", 1.0);
jump_drive_factor = GetDouble(config, "components|jump_drive|factor", 1.0);
}

vega_config::PhysicsConfig::PhysicsConfig() :
collision_scale_factor(1.0f),
inelastic_scale(0.8f),
Expand All @@ -448,6 +518,16 @@ vega_config::WeaponsConfig::WeaponsConfig() :
can_fire_in_spec(false) {
}

vega_config::GameStart::GameStart() :
default_mission(""),
introduction("") {
}

vega_config::GameStart::GameStart(const std::string config) {
default_mission = GetString(config, "game_start|default_mission");
introduction = GetString(config, "game_start|introduction");
}

std::shared_ptr<Configuration> configuration() {
static const std::shared_ptr<Configuration> kConfiguration = std::make_shared<Configuration>();
return kConfiguration;
Expand Down
21 changes: 11 additions & 10 deletions engine/src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,7 @@ struct EjectConfig {

struct Fuel {
float afterburner_fuel_usage;
/* There are a pair of "FMEC" variables - they both involve "Fuel Mass to Energy Conversion" -
* this one happens to specify the inverse (it's only ever used as 1/Value, so just encode 1/Value, not Value)
* of the assumed exit velocity of the mass ejected as thrust, calculated based on energy-possible
* (if not necessarily plausible) outcomes from a Li-6 + Deuterium fusion reaction.
* The other variable (not present here) FMEC_factor, is used in reactor --> energy production.
* As the comment in the code next to the variable init says, it specifies how many metric tons (1 VS mass unit)
* of fuel are used to produce 100MJ (one units.csv energy recharge unit) of recharge.
* At some point, it wouldn't kill us to renormalize the engine and dataset to both just use SI units, but that's not a priority.
*/
float fmec_exit_velocity_inverse{0.0000002F};


/* This used to be Lithium6constant.
* There's some relevant context that's been removed from the original name of this variable "Lithium6constant" --
Expand Down Expand Up @@ -207,6 +198,7 @@ struct Fuel {
double minimum_drive{0.15};

Fuel();
Fuel(const std::string config);
};

struct HudConfig {
Expand Down Expand Up @@ -461,6 +453,14 @@ struct WeaponsConfig {
WeaponsConfig();
};

struct GameStart {
std::string default_mission;
std::string introduction;

GameStart();
GameStart(const std::string config);
};

}

// not using namespace vega_config, because ComputerConfig would be ambiguous
Expand All @@ -485,6 +485,7 @@ class Configuration {
vega_config::UnitConfig unit_config;
vega_config::WarpConfig warp_config;
vega_config::WeaponsConfig weapons;
vega_config::GameStart game_start;
};

extern std::shared_ptr<Configuration> configuration();
Expand Down
53 changes: 25 additions & 28 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ VegaConfig *createVegaConfig(const char *file) {
return new GameVegaConfig(file);
}

std::string ParseCommandLine(int argc, char **CmdLine);
std::pair<std::string, std::string> ParseCommandLine(int argc, char **CmdLine);
/**
* Returns an exit code >= 0 if the game is supposed to exit rightaway
* Returns an exit code < 0 if the game can continue loading.
Expand Down Expand Up @@ -180,8 +180,6 @@ void cleanup(void) {

LeakVector<Mission *> active_missions;

char mission_name[1024];

void bootstrap_main_loop();
void bootstrap_first_loop();
#if defined (WITH_MACOSX_BUNDLE)
Expand Down Expand Up @@ -270,7 +268,6 @@ int main(int argc, char *argv[]) {
// VegaStrikeLogging::VegaStrikeLogger::InitLoggingPart1();

CONFIGFILE = nullptr;
mission_name[0] = '\0';
{
char pwd[8192] = "";
if (nullptr != getcwd(pwd, 8191)) {
Expand Down Expand Up @@ -299,11 +296,19 @@ int main(int argc, char *argv[]) {
//in benchmark mode, always use the same seed
srand(171070);
}

// Initial mission name. Can be loaded from command line arguments.
// Usually loaded from config.json
std::string mission_name;

//this sets up the vegastrike config variable
setup_game_data();
//loads the configuration file .vegastrike/vegastrike.config from home dir if such exists
{
std::string subdir = ParseCommandLine(argc, argv);
std::pair<std::string, std::string> pair = ParseCommandLine(argc, argv);
std::string subdir = pair.first;
mission_name = pair.second;

VS_LOG(info, (boost::format("GOT SUBDIR ARG = %1%") % subdir));
if (CONFIGFILE == 0) {
CONFIGFILE = new char[42];
Expand Down Expand Up @@ -338,9 +343,10 @@ int main(int argc, char *argv[]) {
if (game_options()->force_client_connect) {
ignore_network = false;
}
if (mission_name[0] == '\0') {
strncpy(mission_name, game_options()->default_mission.c_str(), 1023);
mission_name[1023] = '\0';

// Override config with command line argument
if (!mission_name.empty()) {
configuration()->game_start.default_mission = mission_name;
VS_LOG(info, (boost::format("MISSION_NAME is empty using : %1%") % mission_name));
}

Expand Down Expand Up @@ -566,7 +572,7 @@ void bootstrap_main_loop() {
InitTime();
if (LoadMission) {
LoadMission = false;
active_missions.push_back(mission = new Mission(mission_name));
active_missions.push_back(mission = new Mission(configuration()->game_start.default_mission.c_str()));

mission->initMission();

Expand Down Expand Up @@ -674,21 +680,11 @@ void bootstrap_main_loop() {
UpdateTime();
FactionUtil::LoadContrabandLists();
{
// TODO: Figure out how to refactor this section to use a loop or similar, eliminating code duplication
if (!game_options()->intro1.empty()) {
UniverseUtil::IOmessage(0, "game", "all", game_options()->intro1);
if (!game_options()->intro2.empty()) {
UniverseUtil::IOmessage(4, "game", "all", game_options()->intro2);
if (!game_options()->intro3.empty()) {
UniverseUtil::IOmessage(8, "game", "all", game_options()->intro3);
if (!game_options()->intro4.empty()) {
UniverseUtil::IOmessage(12, "game", "all", game_options()->intro4);
if (!game_options()->intro5.empty()) {
UniverseUtil::IOmessage(16, "game", "all", game_options()->intro5);
}
}
}
}
std::vector<std::string> intro_lines;
boost::split(intro_lines, configuration()->game_start.introduction, boost::is_any_of("\n"));

for(const std::string& line : intro_lines) {
UniverseUtil::IOmessage(0, "game", "all", line);
}
}

Expand Down Expand Up @@ -743,9 +739,11 @@ const char versionmessage[] =
"Vega Strike Engine Version " VEGASTRIKE_VERSION_STR "\n"
"\n";

std::string ParseCommandLine(int argc, char **lpCmdLine) {
std::pair<std::string, std::string> ParseCommandLine(int argc, char **lpCmdLine) {
// TODO: replace with boot::program_options
std::string st;
std::string retstr;
std::string mission_name;
std::string datatmp;
g_game.vsdebug = '0';
QVector PlayerLocation;
Expand Down Expand Up @@ -867,8 +865,7 @@ std::string ParseCommandLine(int argc, char **lpCmdLine) {
}
} else {
//no "-" before it - it's the mission name
strncpy(mission_name, lpCmdLine[i], 1023);
mission_name[1023] = '\0';
mission_name = std::string(lpCmdLine[i]);
}
}
if (false == legacy_data_dir_mode) {
Expand All @@ -878,7 +875,7 @@ std::string ParseCommandLine(int argc, char **lpCmdLine) {
}
}

return retstr;
return std::pair<std::string, std::string>(retstr, mission_name);
}

#undef main
Expand Down
16 changes: 0 additions & 16 deletions engine/src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,9 @@ extern VegaConfig *vs_config;

void vs_options::init() {
/* General Options */
default_mission = vs_config->getVariable("general", "default_mission", "test/test1.mission");
galaxy = vs_config->getVariable("general", "galaxy", "milky_way.xml");
command_interpretor = XMLSupport::parse_bool(vs_config->getVariable("general", "command_interpretor", "false"));
load_last_savegame = XMLSupport::parse_bool(vs_config->getVariable("general", "load_last_savegame", "false"));
intro1 = vs_config->getVariable("general",
"intro1",
"Welcome to Vega Strike! Use #8080FFTab#000000 to afterburn (#8080FF+,-#000000 cruise control), #8080FFarrows#000000 to steer.");
intro2 = vs_config->getVariable("general",
"intro2",
"The #8080FFt#000000 key targets objects; #8080FFspace#000000 fires at them & #8080FFa#000000 activates the SPEC drive. To");
intro3 = vs_config->getVariable("general",
"intro3",
"go to another star system, buy a jump drive for about 10000 credits, fly to a");
intro4 = vs_config->getVariable("general",
"intro4",
"wireframe jump-point and press #8080FFj#000000 to warp to a near star. Target a base or planet;");
intro5 = vs_config->getVariable("general",
"intro5",
"When you get close a green box will appear. Inside the box, #8080FFd#000000 will land.");
debug_fs = XMLSupport::parse_int(vs_config->getVariable("general", "debug_fs", "0"));
simulation_atom = XMLSupport::parse_floatf(vs_config->getVariable("general", "simulation_atom", "0.1"));
audio_atom = XMLSupport::parse_floatf(vs_config->getVariable("general", "audio_atom", "0.05555555556"));
Expand Down
6 changes: 0 additions & 6 deletions engine/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ class vs_options {
void init();

/* General Options */
std::string default_mission;
std::string galaxy;
bool command_interpretor{};
bool load_last_savegame{};
std::string intro1;
std::string intro2;
std::string intro3;
std::string intro4;
std::string intro5;
bool debug_fs{};
float simulation_atom{};
float audio_atom{};
Expand Down
Loading