16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-20 10:19:19 +02:00

Merge pull request #29 from MaSzyna-EU07/fix-experimental

Move configs to alternative location
This commit is contained in:
2025-11-03 20:02:26 +01:00
committed by GitHub
6 changed files with 143 additions and 21 deletions

View File

@@ -896,12 +896,34 @@ eu07_application::init_files() {
mkdir("logs", 0755);
#endif
}
namespace fs = std::filesystem;
int
eu07_application::init_settings( int Argc, char *Argv[] ) {
Global.asVersion = VERSION_INFO;
Global.LoadIniFile( "eu07.ini" );
fs::path iniPath;
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
iniPath = fs::path(appdata) / "MaSzyna" / "Config" / "eu07.ini";
}
#else
if (const char *home = std::getenv("HOME"))
{
iniPath = fs::path(home) / ".config" / "MaSzyna" / "eu07.ini";
}
#endif
if (!iniPath.empty() && fs::exists(iniPath))
{
Global.LoadIniFile(iniPath.string().c_str());
}
else
{
Global.LoadIniFile("eu07.ini");
}
// process command line arguments
for( int i = 1; i < Argc; ++i ) {

View File

@@ -175,12 +175,32 @@ drivermouse_input::init() {
return true;
}
namespace fs = std::filesystem;
bool
drivermouse_input::recall_bindings() {
cParser bindingparser( "eu07_input-mouse.ini", cParser::buffer_FILE );
if( false == bindingparser.ok() ) {
std::string filePath = "eu07_input-mouse.ini";
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
fs::path appPath = fs::path(appdata) / "MaSzyna" / "Config" / "eu07_input-mouse.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#else
if (const char *home = std::getenv("HOME"))
{
fs::path appPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-mouse.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#endif
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
if (false == bindingparser.ok()) {
return false;
}

View File

@@ -150,10 +150,31 @@ gamepad_input::bind( std::vector< std::reference_wrapper<user_command> > &Target
}
}
namespace fs = std::filesystem;
bool
gamepad_input::recall_bindings() {
std::string filePath = "eu07_input-gamepad.ini";
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
fs::path appPath = fs::path(appdata) / "MaSzyna" / "Config" / "eu07_input-gamepad.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#else
if (const char *home = std::getenv("HOME"))
{
fs::path appPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-gamepad.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#endif
// bindingparser tworzony zawsze, z wybran¹ œcie¿k¹
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
cParser bindingparser( "eu07_input-gamepad.ini", cParser::buffer_FILE );
if( false == bindingparser.ok() ) {
return false;
}

View File

@@ -117,12 +117,38 @@ std::unordered_map<int, std::string> keyboard_input::keytonamemap =
{ GLFW_KEY_PAGE_UP, "page_up" },
{ GLFW_KEY_PAGE_DOWN, "page_down" },
};
namespace fs = std::filesystem;
bool
keyboard_input::recall_bindings() {
cParser bindingparser( "eu07_input-keyboard.ini", cParser::buffer_FILE );
bindingparser.skipComments = false;
fs::path iniPath;
std::string path = "";
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
iniPath = fs::path(appdata) / "MaSzyna" / "Config" / "eu07_input-keyboard.ini";
}
#else
if (const char *home = std::getenv("HOME"))
{
iniPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-keyboard.ini";
}
#endif
if (!iniPath.empty() && fs::exists(iniPath))
{
// Plik istnieje w AppData / ~/.config
path = iniPath.string().c_str();
}
else
{
// Fallback plik w folderze symulatora
path = "eu07_input-keyboard.ini";
}
cParser bindingparser(path.c_str(), cParser::buffer_FILE);
bindingparser.skipComments = false;
if( false == bindingparser.ok() ) {
return false;
}

View File

@@ -23,21 +23,29 @@ float calc_shadow()
for (cascade = 0U; cascade < MAX_CASCADES; cascade++)
if (distance <= cascade_end[cascade])
break;
float dist_casc = distance / cascade_end[cascade];
vec3 coords = f_light_pos[cascade].xyz / f_light_pos[cascade].w;
if (coords.z < 0.0f)
if (coords.z < 0.0)
return 0.0f;
float shadow = 0.0;
//basic
// shadow = texture(shadowmap, coords.xyz + vec3(0.0, 0.0, bias));
//PCF
float bias = 0.00005f * float(cascade + 1U);
vec2 texel = vec2(1.0) / vec2(textureSize(shadowmap, 0));
//float radius = 1.0; f_light_pos[cascade].w; //0.5 + 2.0 * max(abs(2.0 * coords.x - 1.0), abs(2.0 * coords.y - 1.0));
float radius = 1.0;
float minradius = 0.0;
if (cascade == 0U)
minradius = 1.0;
if (cascade < MAX_CASCADES - 1U)
radius = mix(minradius, f_light_pos[cascade+1U].w/f_light_pos[cascade].w, dist_casc);
else
radius = 0.5;
for (float y = -1.5; y <= 1.5; y += 1.0)
for (float x = -1.5; x <= 1.5; x += 1.0)
shadow += texture( shadowmap, vec4(coords.xy + vec2(x, y) * radius * texel, cascade, coords.z + bias) );
shadow += texture(shadowmap, vec4(coords.xy + vec2(x, y) * radius * texel, cascade, coords.z + bias) );
shadow /= 16.0;
return shadow;
@@ -65,7 +73,8 @@ vec2 calc_point_light(light_s light, vec3 fragnormal)
val *= light.intensity;
float distance = length(light.pos - f_pos.xyz);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
float atten = 1.0f / (distance * distance);
//float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
return val * atten;
}
@@ -135,10 +144,15 @@ vec3 apply_lights(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float refl
// fragcolor *= lights[0].intensity;
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
// fragcolor += mix(lights[0].color * diffuseamount, envcolor, reflectivity);
fragcolor += lights[0].color * diffuseamount;
fragcolor = mix(fragcolor, envcolor, reflectivity);
float shadow1 = 0.0;
if (shadowtone < 1.0)
{
shadow1 = (1 - shadowtone) * clamp(calc_shadow(), 0.0, 1.00);
}
fragcolor += lights[0].color * 5.0 * (1.0 - shadow1) * diffuseamount;
fragcolor = mix(fragcolor * 0.35, envcolor, reflectivity);
for (uint i = 1U; i < lights_count; i++)
{
@@ -160,9 +174,9 @@ vec3 apply_lights(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float refl
float specularamount = (sunlight.y * param[1].y * specularity) * lights[0].intensity * clamp(1.0 - shadowtone, 0.0, 1.0);
if (shadowtone < 1.0)
{
float shadow = calc_shadow();
specularamount *= clamp(1.0 - shadow, 0.0, 1.0);
fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp(diffuseamount * shadow + specularamount, 0.0, 1.0));
//float shadow = calc_shadow();
specularamount *= clamp(1.0 - shadow1, 0.0, 1.00);
//fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp((diffuseamount) * shadow1 , 0.0, 1.0));
}
fragcolor += emissioncolor;
vec3 specularcolor = specularamount * lights[0].color;

View File

@@ -186,13 +186,32 @@ uart_input::~uart_input()
sp_free_port(port);
}
namespace fs = std::filesystem;
bool
uart_input::recall_bindings() {
m_inputbindings.clear();
std::string filePath = "eu07_input-uart.ini";
cParser bindingparser( "eu07_input-uart.ini", cParser::buffer_FILE );
if( false == bindingparser.ok() ) {
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
fs::path appPath = fs::path(appdata) / "MaSzyna" / "Config" / "eu07_input-uart.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#else
if (const char *home = std::getenv("HOME"))
{
fs::path appPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-uart.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#endif
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
if (false == bindingparser.ok())
{
return false;
}