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

Merge remote-tracking branch 'remotes/origin/master' into ecs

This commit is contained in:
2026-04-16 19:08:50 +02:00
34 changed files with 1942 additions and 1589 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -67,7 +67,7 @@ struct global_settings {
int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie
float AirTemperature{ 15.f };
std::string asCurrentSceneryPath{ "scenery/" };
std::string asCurrentTexturePath{ szTexturePath };
std::string asCurrentTexturePath{ paths::textures };
std::string asCurrentDynamicPath;
int CurrentMaxTextureSize{ 4096 };
bool UpdateMaterials{ true };
@@ -345,10 +345,21 @@ struct global_settings {
float m_skysaturationcorrection{ 1.65f };
float m_skyhuecorrection{ 0.5f };
// methods
void LoadIniFile( std::string asFileName );
void ConfigParse( cParser &parser );
bool ConfigParse_gfx( cParser &parser, std::string_view const Token );
// methods
void LoadIniFile( std::string asFileName );
void FinalizeConfig();
void ConfigParse(cParser &parser);
bool ConfigParseGeneral(cParser& Parser, const std::string& token);
bool ConfigParseAudio(cParser& Parser, const std::string& token);
bool ConfigParseGraphics(cParser& Parser, const std::string& token);
bool ConfigParseInput(cParser& Parser, const std::string& token);
bool ConfigParseSimulation(cParser& Parser, const std::string& token);
bool ConfigParseUI(cParser& Parser, const std::string& token);
bool ConfigParsePython(cParser& Parser, const std::string& token);
bool ConfigParseNetwork(cParser& Parser, const std::string& token);
bool ConfigParseHardware(cParser& Parser, const std::string& token);
bool ConfigParseDebug(cParser& Parser, const std::string& token);
bool ConfigParse_gfx( cParser &parser, std::string_view const Token );
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;

View File

@@ -158,55 +158,57 @@ void LogService()
}
void WriteLog(const char *str, logtype const Type, bool isError)
bool ShouldSkipLog(std::string_view str, logtype type)
{
if (!str || *str == '\0')
return;
if (TestFlag(Global.DisabledLogTypes, static_cast<unsigned int>(Type)))
return;
// time calculation
auto now = std::chrono::steady_clock::now();
auto elapsed = now - Global.startTimestamp;
double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(elapsed).count();
// time format
std::ostringstream oss;
oss << "[ " << std::fixed << std::setprecision(3) << seconds << " ] ";
// wyrownanie do np. 10 znaków długości + dwie tabulacje
std::ostringstream final;
final << std::setw(10) << oss.str() << "\t\t" << str;
logMutex.lock();
InfoStack.emplace_back(final.str(), isError);
logMutex.unlock();
return str.empty() ||
TestFlag(Global.DisabledLogTypes, static_cast<unsigned int>(type));
}
void ErrorLog(const char *str, logtype const Type)
std::string FormatLogMessage(std::string_view str)
{
if (!str || *str == '\0')
return;
if (TestFlag(Global.DisabledLogTypes, static_cast<unsigned int>(Type)))
const auto now = std::chrono::steady_clock::now();
const auto elapsed = now - Global.startTimestamp;
const double seconds = std::chrono::duration<double>(elapsed).count();
return std::format("[ {:8.3f} ]\t\t{}", seconds, str);
}
void WriteLog(std::string_view str, logtype type, bool isError)
{
if (ShouldSkipLog(str, type))
return;
// time calculation
auto now = std::chrono::steady_clock::now();
auto elapsed = now - Global.startTimestamp;
double seconds = std::chrono::duration_cast<std::chrono::duration<double>>(elapsed).count();
const auto message = FormatLogMessage(str);
// time format
std::ostringstream oss;
oss << "[ " << std::fixed << std::setprecision(3) << seconds << " ] ";
std::lock_guard<std::mutex> lock(logMutex);
InfoStack.push_back({message, isError});
}
// wyrownanie do np. 10 znaków długości + dwie tabulacje
std::ostringstream final;
final << std::setw(10) << oss.str() << "\t\t" << str;
void ErrorLog(std::string_view str, logtype type)
{
if (ShouldSkipLog(str, type))
return;
logMutex.lock();
ErrorStack.emplace_back(final.str());
logMutex.unlock();
const auto message = FormatLogMessage(str);
std::lock_guard<std::mutex> lock(logMutex);
ErrorStack.push_back(message);
}
void WriteLog(const char* str, logtype type, bool isError)
{
if (str == nullptr || *str == '\0')
return;
WriteLog(std::string_view{str}, type, isError);
}
void ErrorLog(const char* str, logtype type)
{
if (str == nullptr || *str == '\0')
return;
ErrorLog(std::string_view{str}, type);
}

View File

@@ -29,12 +29,15 @@ template <typename T> T sign(T x)
#define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem
#define RadToDeg(r) ((180.0 / M_PI) * (r))
#define szSceneryPath "scenery/"
#define szTexturePath "textures/"
#define szModelPath "models/"
#define szDynamicPath "dynamic/"
#define szSoundPath "sounds/"
#define szDataPath "data/"
namespace paths
{
inline constexpr const char *scenery = "scenery/";
inline constexpr const char *textures = "textures/";
inline constexpr const char *models = "models/";
inline constexpr const char *dynamic = "dynamic/";
inline constexpr const char *sounds = "sounds/";
inline constexpr const char *data = "data/";
}
#define MAKE_ID4(a, b, c, d) (((std::uint32_t)(d) << 24) | ((std::uint32_t)(c) << 16) | ((std::uint32_t)(b) << 8) | (std::uint32_t)(a))

69
utilities/uuid.hpp Normal file
View File

@@ -0,0 +1,69 @@
#pragma once
#include <array>
#include <random>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdint>
class UID {
public:
std::array<uint8_t,16> bytes;
static UID random() {
static thread_local std::mt19937_64 gen(std::random_device{}());
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);
u.bytes[6] = (u.bytes[6] & 0x0F) | 0x40;
u.bytes[8] = (u.bytes[8] & 0x3F) | 0x80;
return u;
}
std::string to_string() const {
std::ostringstream os;
os << std::hex << std::setfill('0');
auto put = [&](int i){
os << std::setw(2) << static_cast<int>(bytes[i]);
};
// format 8-4-4-4-12
for (int i = 0; i < 4; ++i) put(i);
for (int i = 4; i < 6; ++i) put(i);
os << '-';
for (int i = 6; i < 8; ++i) put(i);
os << '-';
for (int i = 8; i < 10; ++i) put(i);
os << '-';
for (int i = 10; i < 12; ++i) put(i);
os << '-';
for (int i = 12; i < 16; ++i) put(i);
return os.str();
}
static UID from_string(const std::string& str) {
std::istringstream is(str);
is >> std::hex;
UID u;
for (int i = 0; i < 16; ++i) {
int byte;
is >> byte;
u.bytes[i] = static_cast<uint8_t>(byte);
if (is.peek() == '-') is.get();
}
return u;
}
bool operator==(const UID &other) const noexcept {
return bytes == other.bytes;
}
bool operator!=(const UID &other) const noexcept {
return !(*this == other);
}
};