16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 12:29:18 +02:00
This commit is contained in:
2026-06-30 23:35:46 +02:00
110 changed files with 4141 additions and 4742 deletions

View File

@@ -34,7 +34,7 @@ class float3
inline bool operator==(const float3 &v1, const float3 &v2)
{
return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z);
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
};
inline float3 &operator+=(float3 &v1, const float3 &v2)
{
@@ -60,7 +60,7 @@ inline float float3::Length() const
return std::sqrt(LengthSquared());
};
inline float float3::LengthSquared() const {
return ( x * x + y * y + z * z );
return x * x + y * y + z * z;
}
inline float3 operator*( float3 const &v, float const k ) {
return float3( v.x * k, v.y * k, v.z * k );
@@ -90,7 +90,7 @@ inline float DotProduct( float3 const &v1, float3 const &v2 ) {
inline float3 Interpolate( float3 const &First, float3 const &Second, float const Factor ) {
return ( First * ( 1.0f - Factor ) ) + ( Second * Factor );
return First * (1.0f - Factor) + Second * Factor;
}
class float4
@@ -131,7 +131,7 @@ inline float4 operator-(const float4 &q)
};
inline float4 operator-(const float4 &q1, const float4 &q2)
{ // z odejmowaniem nie ma lekko
return (-q1) * q2; // inwersja tylko dla znormalizowanych!
return -q1 * q2; // inwersja tylko dla znormalizowanych!
};
inline float4 operator+(const float4 &v1, const float4 &v2)
{
@@ -250,7 +250,7 @@ public:
inline bool IdentityIs()
{ // sprawdzenie jednostkowości
for (int i = 0; i < 16; ++i)
if (e[i] != ((i % 5) ? 0.0 : 1.0)) // jedynki tylko na 0, 5, 10 i 15
if (e[i] != (i % 5 ? 0.0 : 1.0)) // jedynki tylko na 0, 5, 10 i 15
return false;
return true;
}
@@ -280,7 +280,7 @@ inline float4x4 &float4x4::Rotation(float const Angle, float3 const &Axis)
auto const c = std::cos(Angle);
auto const s = std::sin(Angle);
// One minus c (short name for legibility of formulai)
auto const omc = (1.f - c);
auto const omc = 1.f - c;
auto const axis = SafeNormalize(Axis);
auto const xs = axis.x * s;
auto const ys = axis.y * s;

View File

@@ -251,7 +251,7 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
{
std::string value;
ParseOne(Parser, value);
asSky = (value == "yes" ? "1" : "0");
asSky = value == "yes" ? "1" : "0";
return true;
}
@@ -263,7 +263,7 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
if (value == "tga")
szDefaultExt = szTexturesTGA;
else
szDefaultExt = (value[0] == '.' ? value : "." + value);
szDefaultExt = value[0] == '.' ? value : "." + value;
return true;
}
@@ -318,8 +318,8 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
GfxRenderer = "experimental";
}
BasicRenderer = (GfxRenderer == "simple");
LegacyRenderer = !NvRenderer && (GfxRenderer != "default");
BasicRenderer = GfxRenderer == "simple";
LegacyRenderer = !NvRenderer && GfxRenderer != "default";
return true;
}
@@ -338,7 +338,7 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
shadowtune.map_size = clamp_power_of_two<unsigned int>(shadowtune.map_size, 512, 8192);
shadowtune.range =
std::max((shadowtune.map_size <= 2048 ? 75.f : 75.f * shadowtune.map_size / 2048),
std::max(shadowtune.map_size <= 2048 ? 75.f : 75.f * shadowtune.map_size / 2048,
shadowtune.range);
return true;
}
@@ -696,7 +696,7 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
{
std::string value;
ParseOne(Parser, value);
iPause |= (value == "yes" ? 1 : 0);
iPause |= value == "yes" ? 1 : 0;
return true;
}
@@ -704,7 +704,7 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
{
std::string value;
ParseOne(Parser, value, 1);
priorityLoadText3D = (value == "yes");
priorityLoadText3D = value == "yes";
return true;
}
@@ -993,7 +993,7 @@ bool global_settings::ConfigParseHardware(cParser& Parser, const std::string& to
{
for (auto const& x : uartfeatures_map)
{
*(x.second) = false;
*x.second = false;
}
std::string key;
@@ -1005,7 +1005,7 @@ bool global_settings::ConfigParseHardware(cParser& Parser, const std::string& to
if (uartfeatures_map.count(key))
{
*(uartfeatures_map[key]) = true;
*uartfeatures_map[key] = true;
}
}
}
@@ -1146,7 +1146,7 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token
int in = 0;
Parser >> in;
if ((in < 0) || (in > 5))
if (in < 0 || in > 5)
in = 5;
Parser.getTokens(4, false);
@@ -1167,7 +1167,7 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token
int in = 0;
Parser >> in;
if ((in < 0) || (in > 5))
if (in < 0 || in > 5)
in = 5;
Parser.getTokens(6, false);
@@ -1187,7 +1187,7 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token
int out = 0;
Parser >> out;
if ((out < 0) || (out > 6))
if (out < 0 || out > 6)
out = 6;
Parser.getTokens(4, false);
@@ -1208,7 +1208,7 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token
int out = 0;
Parser >> out;
if ((out < 0) || (out > 6))
if (out < 0 || out > 6)
out = 6;
Parser.getTokens(6, false);
@@ -1678,7 +1678,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
std::vector<std::string> enabled_uartfeatures;
for(auto const &x : uartfeatures_map) {
if(*(x.second)) {
if(*x.second) {
enabled_uartfeatures.push_back(x.first);
}
}

View File

@@ -108,7 +108,7 @@ void LogService()
{
if (!output.is_open())
{
std::string filename = (Global.MultipleLogs ? "logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" : "log.txt");
std::string filename = Global.MultipleLogs ? "logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" : "log.txt";
output.open(filename, std::ios::trunc);
}
output << msg << "\n";
@@ -143,7 +143,7 @@ void LogService()
if (!errors.is_open())
{
std::string filename = (Global.MultipleLogs ? "logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" : "errors.txt");
std::string filename = Global.MultipleLogs ? "logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" : "errors.txt";
errors.open(filename, std::ios::trunc);
errors << "EU07.EXE " + Global.asVersion << "\n";
}

View File

@@ -11,17 +11,17 @@ http://mozilla.org/MPL/2.0/.
enum class logtype : unsigned int {
generic = ( 1 << 0 ),
file = ( 1 << 1 ),
model = ( 1 << 2 ),
texture = ( 1 << 3 ),
lua = ( 1 << 4 ),
material = ( 1 << 5 ),
shader = ( 1 << 6 ),
net = ( 1 << 7 ),
sound = ( 1 << 8 ),
traction = ( 1 << 9 ),
powergrid = ( 1 << 10 ),
generic = 1 << 0,
file = 1 << 1,
model = 1 << 2,
texture = 1 << 3,
lua = 1 << 4,
material = 1 << 5,
shader = 1 << 6,
net = 1 << 7,
sound = 1 << 8,
traction = 1 << 9,
powergrid = 1 << 10,
};
void LogService();
void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false );

View File

@@ -26,7 +26,7 @@ public:
bool
insert( Type_ *Item, std::string itemname ) {
m_items.emplace_back( Item );
if( ( true == itemname.empty() ) || ( itemname == "none" ) ) {
if( true == itemname.empty() || itemname == "none" ) {
return true;
}
auto const itemhandle { m_items.size() - 1 };
@@ -64,10 +64,7 @@ public:
}
uint32_t find_id( std::string const &Name) const {
auto lookup = m_itemmap.find( Name );
return (
lookup != m_itemmap.end() ?
lookup->second :
-1 );
return lookup != m_itemmap.end() ? lookup->second : -1;
}
void purge (Type_ *Item)
{
@@ -83,10 +80,7 @@ public:
Type_ *
find( std::string const &Name ) const {
auto lookup = m_itemmap.find( Name );
return (
lookup != m_itemmap.end() ?
m_items[ lookup->second ] :
nullptr ); }
return lookup != m_itemmap.end() ? m_items[lookup->second] : nullptr; }
protected:
// types

View File

@@ -34,7 +34,7 @@ public:
m_start = std::chrono::steady_clock::now(); }
std::chrono::duration<float, std::milli>
stop() {
m_last = std::chrono::duration_cast<std::chrono::microseconds>( ( std::chrono::steady_clock::now() - m_start ) );
m_last = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now() - m_start );
m_accumulator = 0.95f * m_accumulator + m_last.count() / 1000.f;
return m_last; }
float

View File

@@ -42,7 +42,7 @@ RGBtoHSV( glm::vec3 const &RGB ) {
return hsv;
}
if( max > 0.0 ) { // NOTE: if Max is == 0, this divide would cause a crash
hsv.y = ( delta / max ); // s
hsv.y = delta / max; // s
}
else {
// if max is 0, then r = g = b = 0
@@ -85,8 +85,8 @@ HSVtoRGB( glm::vec3 const &HSV ) {
int const i = (int)hh;
float const ff = hh - i;
float const p = HSV.z * ( 1.f - HSV.y );
float const q = HSV.z * ( 1.f - ( HSV.y * ff ) );
float const t = HSV.z * ( 1.f - ( HSV.y * ( 1.f - ff ) ) );
float const q = HSV.z * ( 1.f - HSV.y * ff );
float const t = HSV.z * ( 1.f - HSV.y * (1.f - ff) );
switch( i ) {
case 0:

View File

@@ -32,7 +32,7 @@ motiontelemetry::motiontelemetry()
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = (conf.proto == "tcp" ? SOCK_STREAM : SOCK_DGRAM);
hints.ai_socktype = conf.proto == "tcp" ? SOCK_STREAM : SOCK_DGRAM;
if (getaddrinfo(conf.address.c_str(), conf.port.c_str(), &hints, &res))
throw std::runtime_error("motiontelemetry: getaddrinfo failed");

View File

@@ -71,7 +71,7 @@ cParser::cParser(std::string const &Stream, buffertype const Type, std::string P
Path.append(Stream);
mStream = std::make_shared<std::ifstream>(Path, std::ios_base::binary);
// content of *.inc files is potentially grouped together
if ((Stream.size() >= 4) && (ToLower(Stream.substr(Stream.size() - 4)) == ".inc"))
if (Stream.size() >= 4 && ToLower(Stream.substr(Stream.size() - 4)) == ".inc")
{
mIncFile = true;
scene::Groups.create();
@@ -151,7 +151,7 @@ template <> cParser &cParser::operator>>(bool &Right)
return *this;
}
Right = ((this->tokens.front() == "true") || (this->tokens.front() == "yes") || (this->tokens.front() == "1"));
Right = this->tokens.front() == "true" || this->tokens.front() == "yes" || this->tokens.front() == "1";
this->tokens.pop_front();
return *this;
@@ -161,7 +161,7 @@ template <> bool cParser::getToken<bool>(bool const ToLower, const char *Break)
{
auto const token = getToken<std::string>(true, Break);
return ((token == "true") || (token == "yes") || (token == "1"));
return token == "true" || token == "yes" || token == "1";
}
// methods
@@ -290,10 +290,10 @@ void cParser::substituteParameters(std::string& token, bool ToLower) {
if (close == std::string::npos) break; // malformed -> stop like old behavior (it would substr weirdly)
const std::string idxStr = token.substr(pos + 2, close - (pos + 2));
token.erase(pos, (close - pos) + 1);
token.erase(pos, close - pos + 1);
const size_t nr = static_cast<size_t>(std::atoi(idxStr.c_str()));
const std::string repl = (nr >= 1 && (nr - 1) < parameters.size())
const std::string repl = nr >= 1 && nr - 1 < parameters.size()
? parameters[nr - 1]
: std::string("none");
@@ -323,8 +323,8 @@ void cParser::startIncludeFromParser(cParser& srcParser, bool ToLower, std::stri
replace_slashes(includefile);
const bool allowTraction =
(true == LoadTraction) ||
((false == contains(includefile, "tr/")) && (false == contains(includefile, "tra/")));
true == LoadTraction ||
(false == contains(includefile, "tr/") && false == contains(includefile, "tra/"));
if (!allowTraction) {
// skip include block until "end" (original behavior in token-mode include)
@@ -374,7 +374,7 @@ bool cParser::handleIncludeIfPresent(std::string& token, bool ToLower, const cha
}
// line-mode HACK: Break == "\n\r" and line begins with "include"
if ((std::strcmp(Break, "\n\r") == 0) && token.compare(0, 7, "include") == 0) {
if (std::strcmp(Break, "\n\r") == 0 && token.compare(0, 7, "include") == 0) {
cParser includeparser(token.substr(7));
std::string includefile;
if (allowRandomIncludes)
@@ -420,7 +420,7 @@ std::vector<std::string> cParser::readParameters(cParser &Input)
std::vector<std::string> includeparameters;
std::string parameter;
Input.readToken(parameter, false); // w parametrach nie zmniejszamy
while ((parameter.empty() == false) && (parameter != "end"))
while (parameter.empty() == false && parameter != "end")
{
includeparameters.emplace_back(parameter);
Input.readToken(parameter, false);
@@ -537,7 +537,7 @@ int cParser::getFullProgress() const
int progress = getProgress();
if (mIncludeParser)
return progress + ((100 - progress) * (mIncludeParser->getProgress()) / 100);
return progress + (100 - progress) * mIncludeParser->getProgress() / 100;
else
return progress;
}

View File

@@ -60,7 +60,7 @@ class cParser //: public std::stringstream
inline
bool
ok() {
return ( !mStream->fail() ); };
return !mStream->fail(); };
cParser &
autoclear( bool const Autoclear );
inline
@@ -77,10 +77,7 @@ class cParser //: public std::stringstream
inline
std::string
peek() const {
return (
false == tokens.empty() ?
tokens.front() :
"" ); }
return false == tokens.empty() ? tokens.front() : ""; }
// inject string as internal include
void injectString(const std::string &str);

View File

@@ -38,13 +38,13 @@ const std::string& locale::lookup_s(const std::string &msg, bool constant)
if (constant) {
auto it = pointer_cache.find(&msg);
if (it != pointer_cache.end())
return *((const std::string*)(it->second));
return *(const std::string *)it->second;
}
auto it = lang_mapping.find(msg);
if (it != lang_mapping.end()) {
if (constant)
pointer_cache.emplace(&msg, &(it->second));
pointer_cache.emplace(&msg, &it->second);
return it->second;
}
@@ -58,7 +58,7 @@ const char* locale::lookup_c(const char *msg, bool constant)
if (constant) {
auto it = pointer_cache.find(msg);
if (it != pointer_cache.end())
return (const char*)(it->second);
return (const char*)it->second;
}
auto it = lang_mapping.find(std::string(msg));
@@ -156,7 +156,7 @@ std::string locale::parse_c_literal(const std::string &str)
n2 -= 7;
if (n2 > 16)
n2 -= 32;
out += ((n1 << 4) | n2);
out += n1 << 4 | n2;
}
escape = false;
}
@@ -347,10 +347,7 @@ std::string locale::label_cab_control(std::string const &Label)
};
auto const it = cabcontrols_labels.find( Label );
return (
it != cabcontrols_labels.end() ?
lookup_s(it->second) :
"" );
return it != cabcontrols_labels.end() ? lookup_s(it->second) : "";
}
const std::string& locale::coupling_name(int c)

View File

@@ -6,6 +6,7 @@
#include "vehicle/Train.h"
#include "utilities/parser.h"
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "simulation/simulationtime.h"
#include "application/application.h"
@@ -27,9 +28,7 @@ const char* uart_baudrates_list[] = {
"2000000"
};
const size_t uart_baudrates_list_num = (
sizeof(uart_baudrates_list)/sizeof(uart_baudrates_list[0])
);
const size_t uart_baudrates_list_num = sizeof(uart_baudrates_list) / sizeof(uart_baudrates_list[0]);
void uart_status::reset_stats() {
packets_sent = 0;
@@ -194,21 +193,9 @@ uart_input::recall_bindings() {
m_inputbindings.clear();
std::string filePath = "eu07_input-uart.ini";
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
fs::path appPath = fs::path(appdata) / "MaSzyna" / "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
fs::path appPath = user_config_path("eu07_input-uart.ini");
if (!appPath.empty() && fs::exists(appPath))
filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
if (false == bindingparser.ok())
{
@@ -423,8 +410,8 @@ void uart_input::poll()
auto const byte { std::get<std::size_t>( entry ) / 8 };
auto const bit { std::get<std::size_t>( entry ) % 8 };
bool const state { ( ( buffer[ byte ] & ( 1 << bit ) ) != 0 ) };
bool const changed { ( ( ( old_packet[ byte ] & ( 1 << bit ) ) != 0 ) != state ) };
bool const state { ( ( buffer[ byte ] & 1 << bit ) != 0 ) };
bool const changed { ( (old_packet[byte] & 1 << bit) != 0 != state ) };
if( false == changed ) { continue; }
@@ -432,16 +419,12 @@ void uart_input::poll()
auto const action { (
type != input_type_t::impulse ?
GLFW_PRESS :
( state ?
GLFW_PRESS :
GLFW_RELEASE ) ) };
state ? GLFW_PRESS : GLFW_RELEASE) };
auto const command { (
type != input_type_t::toggle ?
std::get<2>( entry ) :
( state ?
std::get<2>( entry ) :
std::get<3>( entry ) ) ) };
state ? std::get<2>(entry) : std::get<3>(entry) ) };
// TODO: pass correct entity id once the missing systems are in place
relay.post( command, 0, 0, action, 0 );
@@ -461,7 +444,7 @@ void uart_input::poll()
}
else {
auto desiredpercent{ buffer[6] * 0.01 };
auto desiredposition{ desiredpercent > 0.01 ? 1 + ((simulation::Train->Occupied()->MainCtrlPosNo - 1) * desiredpercent) : buffer[6] };
auto desiredposition{ desiredpercent > 0.01 ? 1 + (simulation::Train->Occupied()->MainCtrlPosNo - 1) * desiredpercent : buffer[6] };
relay.post(
user_command::mastercontrollerset,
desiredposition,
@@ -484,7 +467,7 @@ void uart_input::poll()
}
if( true == conf.trainenable ) {
// train brake
double const position { (float)( ( (uint16_t)buffer[ 8 ] | ( (uint16_t)buffer[ 9 ] << 8 ) ) - conf.mainbrakemin ) / ( conf.mainbrakemax - conf.mainbrakemin ) };
double const position { (float)( ( (uint16_t)buffer[ 8 ] | (uint16_t)buffer[9] << 8 ) - conf.mainbrakemin ) / ( conf.mainbrakemax - conf.mainbrakemin ) };
relay.post(
user_command::trainbrakeset,
position,
@@ -495,7 +478,7 @@ void uart_input::poll()
}
if( true == conf.localenable ) {
// independent brake
double const position { (float)( ( (uint16_t)buffer[ 10 ] | ( (uint16_t)buffer[ 11 ] << 8 ) ) - conf.localbrakemin ) / ( conf.localbrakemax - conf.localbrakemin ) };
double const position { (float)( ( (uint16_t)buffer[ 10 ] | (uint16_t)buffer[11] << 8 ) - conf.localbrakemin ) / ( conf.localbrakemax - conf.localbrakemin ) };
relay.post(
user_command::independentbrakeset,
position,
@@ -538,7 +521,7 @@ void uart_input::poll()
auto const trainstate = t->get_state();
SYSTEMTIME time = simulation::Time.data();
uint16_t tacho = Global.iPause ? 0 : (trainstate.velocity * conf.tachoscale);
uint16_t tacho = Global.iPause ? 0 : trainstate.velocity * conf.tachoscale;
uint16_t tank_press = (uint16_t)std::min(conf.tankuart, trainstate.reservoir_pressure * 0.1f / conf.tankmax * conf.tankuart);
uint16_t pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart);
uint16_t brake_press = (uint16_t)std::min(conf.brakeuart, trainstate.brake_pressure * 0.1f / conf.brakemax * conf.brakeuart);
@@ -655,5 +638,5 @@ void uart_input::poll()
}
bool uart_input::is_connected() {
return (port != nullptr);
return port != nullptr;
}

View File

@@ -55,20 +55,36 @@ std::string Now()
#endif
}
std::filesystem::path user_config_path(const std::string &filename)
{
namespace fs = std::filesystem;
#if defined(_WIN32)
if (const char *appdata = std::getenv("APPDATA"))
return fs::path(appdata) / "MaSzyna" / filename;
#elif defined(__APPLE__)
if (const char *home = std::getenv("HOME"))
return fs::path(home) / "Library" / "Application Support" / "MaSzyna" / filename;
#else
if (const char *home = std::getenv("HOME"))
return fs::path(home) / ".config" / "MaSzyna" / filename;
#endif
return {}; // env var missing → caller falls back to CWD-relative filename
}
// zwraca różnicę czasu
// jeśli pierwsza jest aktualna, a druga rozkładowa, to ujemna oznacza opóżnienie
// na dłuższą metę trzeba uwzględnić datę, jakby opóżnienia miały przekraczać 12h (towarowych)
double CompareTime(double t1h, double t1m, double t2h, double t2m)
{
if ((t2h < 0))
if (t2h < 0)
return 0;
else
{
auto t = (t2h - t1h) * 60 + t2m - t1m; // jeśli t2=00:05, a t1=23:50, to różnica wyjdzie ujemna
if ((t < -720)) // jeśli różnica przekracza 12h na minus
if (t < -720) // jeśli różnica przekracza 12h na minus
t = t + 1440; // to dodanie doby minut;else
if ((t > 720)) // jeśli przekracza 12h na plus
if (t > 720) // jeśli przekracza 12h na plus
t = t - 1440; // to odjęcie doby minut
return t;
}
@@ -130,8 +146,8 @@ std::string generate_uuid_v4()
b = static_cast<uint8_t>(dist(gen));
// UUID v4 (RFC 4122)
bytes[6] = (bytes[6] & 0x0F) | 0x40;
bytes[8] = (bytes[8] & 0x3F) | 0x80;
bytes[6] = bytes[6] & 0x0F | 0x40;
bytes[8] = bytes[8] & 0x3F | 0x80;
char buf[37]; // 36 znaków + \0
std::snprintf(buf, sizeof(buf),
@@ -153,16 +169,16 @@ double LocalRandom(double a, double b)
bool FuzzyLogic(double Test, double Threshold, double Probability)
{
if ((Test > Threshold) && (!DebugModeFlag))
return (Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
if (Test > Threshold && !DebugModeFlag)
return Random() < Probability * Threshold * 1.0 / Test /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
bool FuzzyLogicAI(double Test, double Threshold, double Probability)
{
if ((Test > Threshold))
return (Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
if (Test > Threshold)
return Random() < Probability * Threshold * 1.0 / Test /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
@@ -223,8 +239,8 @@ std::string to_minutes_str(float const Minutes, bool const Leadingzero, int cons
float minutesintegral;
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
auto const width{Width - 1};
auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
return (minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))]);
auto minutes = std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0));
return minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))];
}
int stol_def(const std::string &str, const int &DefaultValue)
@@ -307,7 +323,7 @@ std::string Bezogonkow(std::string Input, bool const Underscorestospaces)
{
input = space;
}
else if (Underscorestospaces && (input == underscore))
else if (Underscorestospaces && input == underscore)
{
input = space;
}
@@ -323,7 +339,7 @@ template <> bool extract_value(bool &Variable, std::string const &Key, std::stri
if (false == value.empty())
{
// set the specified variable to retrieved value
Variable = (ToLower(value) == "yes");
Variable = ToLower(value) == "yes";
return true; // located the variable
}
else
@@ -331,7 +347,7 @@ template <> bool extract_value(bool &Variable, std::string const &Key, std::stri
// set the variable to provided default value
if (false == Default.empty())
{
Variable = (ToLower(Default) == "yes");
Variable = ToLower(Default) == "yes";
}
return false; // couldn't locate the variable in provided input
}
@@ -422,13 +438,13 @@ std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b)
bool contains(std::string_view const String, std::string_view Substring)
{
// To be replaced with string::contains in C++ 23
return (String.find(Substring) != std::string::npos);
return String.find(Substring) != std::string::npos;
}
bool contains(std::string_view const String, char Character)
{
// To be replaced with string::contains in C++ 23
return (String.find(Character) != std::string::npos);
return String.find(Character) != std::string::npos;
}
// helper, restores content of a 3d vector from provided input stream
@@ -457,7 +473,7 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
// if instead of a single token we've encountered '[' this marks a beginning of a random set
// we retrieve all entries, then return a random one
std::vector<std::string> tokens;
while (((token = deserialize_random_set(Input, Break)) != "") && (token != "]"))
while ((token = deserialize_random_set(Input, Break)) != "" && token != "]")
{
tokens.emplace_back(token);
}

View File

@@ -17,7 +17,7 @@ http://mozilla.org/MPL/2.0/.
template <typename T> T sign(T x)
{
return x < static_cast<T>(0) ? static_cast<T>(-1) : (x > static_cast<T>(0) ? static_cast<T>(1) : static_cast<T>(0));
return x < static_cast<T>(0) ? static_cast<T>(-1) : x > static_cast<T>(0) ? static_cast<T>(1) : static_cast<T>(0);
}
template <typename T> constexpr T sq(T v)
@@ -25,6 +25,10 @@ template <typename T> constexpr T sq(T v)
return v * v;
}
// returns the per-user config path for `filename` (platform-specific dir),
// or an empty path if the home/appdata env var is unavailable
std::filesystem::path user_config_path(const std::string &filename);
// TODO: Shouldn't this be in globals?
namespace paths
{
@@ -99,11 +103,11 @@ double CompareTime(double t1h, double t1m, double t2h, double t2m);
/*funkcje logiczne*/
inline bool TestFlag(int const Flag, int const Value)
{
return ((Flag & Value) == Value);
return (Flag & Value) == Value;
}
inline bool TestFlagAny(int const Flag, int const Value)
{
return ((Flag & Value) != 0);
return (Flag & Value) != 0;
}
bool SetFlag(int &Flag, int const Value);
bool ClearFlag(int &Flag, int const Value);
@@ -126,7 +130,7 @@ std::string to_minutes_str(float const Minutes, bool const Leadingzero, int cons
template <std::same_as<bool> T> // Without this line this function can be used with other types implicit casted to boolean which may create hard to debug bugs.
inline std::string to_string(T Value)
{
return (Value == true ? "true" : "false");
return Value == true ? "true" : "false";
}
template <typename Type_, glm::precision Precision_ = glm::defaultp> std::string to_string(glm::tvec3<Type_, Precision_> const &Value)
@@ -241,7 +245,7 @@ template <typename T> bool is_equal(T const &Left, T const &Right, T const Epsil
if (Epsilon != T(0))
return glm::epsilonEqual(Left, Right, Epsilon);
return (Left == Right);
return Left == Right;
}
// keeps the provided value in specified range 0-Range, as if the range was circular buffer
@@ -278,7 +282,7 @@ template <typename T> T clamp_power_of_two(T Value, T const Min = T(1), T const
template <typename Type_> Type_ quantize(Type_ const Value, Type_ const Step)
{
return (Step * std::round(Value / Step));
return Step * std::round(Value / Step);
}
template <typename T> T min_speed(T const Left, T const Right)
@@ -305,7 +309,7 @@ template <typename VecType_> bool degenerate(VecType_ const &Vertex1, VecType_ c
{
// degenerate( A, B, C, minarea ) = ( ( B - A ).cross( C - A ) ).lengthSquared() < ( 4.0f * minarea * minarea );
return (glm::length2(glm::cross(Vertex2 - Vertex1, Vertex3 - Vertex1)) == 0.0);
return glm::length2(glm::cross(Vertex2 - Vertex1, Vertex3 - Vertex1)) == 0.0;
}
// calculates bounding box for provided set of points

View File

@@ -17,11 +17,11 @@ public:
UID u;
uint64_t a = gen();
uint64_t b = gen();
for (int i = 0; i < 8; ++i) u.bytes[i] = uint8_t((a >> (i*8)) & 0xFF);
for (int i = 0; i < 8; ++i) u.bytes[8 + i] = uint8_t((b >> (i*8)) & 0xFF);
for (int i = 0; i < 8; ++i) u.bytes[i] = uint8_t(a >> (i * 8) & 0xFF);
for (int i = 0; i < 8; ++i) u.bytes[8 + i] = uint8_t(b >> (i * 8) & 0xFF);
u.bytes[6] = (u.bytes[6] & 0x0F) | 0x40;
u.bytes[8] = (u.bytes[8] & 0x3F) | 0x80;
u.bytes[6] = u.bytes[6] & 0x0F | 0x40;
u.bytes[8] = u.bytes[8] & 0x3F | 0x80;
return u;
}