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

Add security locks for material manager

thanks to @Milek7 for advice about material manager
This commit is contained in:
2025-02-28 10:54:59 +01:00
parent 1dc7d50851
commit 8b3baa84fe
2 changed files with 53 additions and 45 deletions

View File

@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
#include "motiontelemetry.h" #include "motiontelemetry.h"
#include "ref/discord-rpc/include/discord_rpc.h" #include "ref/discord-rpc/include/discord_rpc.h"
#include <map> #include <map>
#include <thread>
#ifdef WITH_UART #ifdef WITH_UART
#include "uart.h" #include "uart.h"
@@ -35,6 +36,7 @@ struct global_settings {
/// Mapa z watkami w formacie <std::string nazwa, std::thread watek> /// Mapa z watkami w formacie <std::string nazwa, std::thread watek>
/// </summary> /// </summary>
std::map<std::string, std::thread> threads = {}; std::map<std::string, std::thread> threads = {};
std::thread::id mainThreadId = std::this_thread::get_id();
bool shiftState{ false }; //m7todo: brzydko bool shiftState{ false }; //m7todo: brzydko
bool ctrlState{ false }; bool ctrlState{ false };
bool altState{ false }; bool altState{ false };

View File

@@ -29,6 +29,8 @@ Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
using namespace Mtable; using namespace Mtable;
std::mutex materialLoadLock;
float TSubModel::fSquareDist = 0.f; float TSubModel::fSquareDist = 0.f;
std::uintptr_t TSubModel::iInstance; // numer renderowanego egzemplarza obiektu std::uintptr_t TSubModel::iInstance; // numer renderowanego egzemplarza obiektu
texture_handle const *TSubModel::ReplacableSkinId = NULL; texture_handle const *TSubModel::ReplacableSkinId = NULL;
@@ -377,52 +379,56 @@ std::pair<int, int> TSubModel::Load( cParser &parser, bool dynamic )
if (!parser.expectToken("map:")) if (!parser.expectToken("map:"))
Error("Model map parse failure!"); Error("Model map parse failure!");
std::string material = parser.getToken<std::string>(); materialLoadLock.lock();
std::replace(material.begin(), material.end(), '\\', '/');
if (material == "none") std::string material = parser.getToken<std::string>();
{ // rysowanie podanym kolorem std::replace(material.begin(), material.end(), '\\', '/');
Name_Material( "colored" ); if (material == "none")
m_material = GfxRenderer->Fetch_Material( m_materialname ); { // rysowanie podanym kolorem
iFlags |= 0x10; // rysowane w cyklu nieprzezroczystych Name_Material( "colored" );
} m_material = GfxRenderer->Fetch_Material( m_materialname );
else if (material.find("replacableskin") != material.npos) iFlags |= 0x10; // rysowane w cyklu nieprzezroczystych
{ // McZapkie-060702: zmienialne skory modelu
m_material = -1;
iFlags |= (Opacity < 0.999) ? 1 : 0x10; // zmienna tekstura 1
}
else if (material == "-1")
{
m_material = -1;
iFlags |= (Opacity < 0.999) ? 1 : 0x10; // zmienna tekstura 1
}
else if (material == "-2")
{
m_material = -2;
iFlags |= (Opacity < 0.999) ? 2 : 0x10; // zmienna tekstura 2
}
else if (material == "-3")
{
m_material = -3;
iFlags |= (Opacity < 0.999) ? 4 : 0x10; // zmienna tekstura 3
}
else if (material == "-4")
{
m_material = -4;
iFlags |= (Opacity < 0.999) ? 8 : 0x10; // zmienna tekstura 4
}
else {
Name_Material(material);
/*
if( material.find_first_of( "/" ) == material.npos ) {
// jeśli tylko nazwa pliku, to dawać bieżącą ścieżkę do tekstur
material.insert( 0, Global.asCurrentTexturePath );
} }
*/ else if (material.find("replacableskin") != material.npos)
m_material = GfxRenderer->Fetch_Material( material ); { // McZapkie-060702: zmienialne skory modelu
// renderowanie w cyklu przezroczystych tylko jeśli: m_material = -1;
// 1. Opacity=0 (przejściowo <1, czy tam <100) iFlags |= (Opacity < 0.999) ? 1 : 0x10; // zmienna tekstura 1
iFlags |= Opacity < 0.999f ? 0x20 : 0x10 ; // 0x20-przezroczysta, 0x10-nieprzezroczysta }
}; else if (material == "-1")
{
m_material = -1;
iFlags |= (Opacity < 0.999) ? 1 : 0x10; // zmienna tekstura 1
}
else if (material == "-2")
{
m_material = -2;
iFlags |= (Opacity < 0.999) ? 2 : 0x10; // zmienna tekstura 2
}
else if (material == "-3")
{
m_material = -3;
iFlags |= (Opacity < 0.999) ? 4 : 0x10; // zmienna tekstura 3
}
else if (material == "-4")
{
m_material = -4;
iFlags |= (Opacity < 0.999) ? 8 : 0x10; // zmienna tekstura 4
}
else {
Name_Material(material);
/*
if( material.find_first_of( "/" ) == material.npos ) {
// jeśli tylko nazwa pliku, to dawać bieżącą ścieżkę do tekstur
material.insert( 0, Global.asCurrentTexturePath );
}
*/
m_material = GfxRenderer->Fetch_Material( material );
// renderowanie w cyklu przezroczystych tylko jeśli:
// 1. Opacity=0 (przejściowo <1, czy tam <100)
iFlags |= Opacity < 0.999f ? 0x20 : 0x10 ; // 0x20-przezroczysta, 0x10-nieprzezroczysta
};
materialLoadLock.unlock();
} }
else if (eType == TP_STARS) else if (eType == TP_STARS)
{ {