mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
reformat: remove redundant parentheses
This commit is contained in:
@@ -45,7 +45,7 @@ bool TAnimContainer::Init(TSubModel *pNewSubModel)
|
||||
{
|
||||
fRotateSpeed = 0.0f;
|
||||
pSubModel = pNewSubModel;
|
||||
return (pSubModel != nullptr);
|
||||
return pSubModel != nullptr;
|
||||
}
|
||||
|
||||
void TAnimContainer::SetRotateAnim(glm::vec3 vNewRotateAngles, double fNewRotateSpeed)
|
||||
@@ -166,9 +166,9 @@ void TAnimContainer::UpdateModel() {
|
||||
vRotateAngles.z += 360;
|
||||
}
|
||||
|
||||
if( ( vRotateAngles.x == 0.0 )
|
||||
&& ( vRotateAngles.y == 0.0 )
|
||||
&& ( vRotateAngles.z == 0.0 ) ) {
|
||||
if( vRotateAngles.x == 0.0
|
||||
&& vRotateAngles.y == 0.0
|
||||
&& vRotateAngles.z == 0.0 ) {
|
||||
iAnim &= ~1; // kąty są zerowe
|
||||
}
|
||||
if (!anim)
|
||||
@@ -231,7 +231,7 @@ void TAnimContainer::PrepareModel()
|
||||
|
||||
bool TAnimContainer::InMovement()
|
||||
{ // czy trwa animacja - informacja dla obrotnicy
|
||||
return (fRotateSpeed != 0.0) || (fTranslateSpeed != 0.0);
|
||||
return fRotateSpeed != 0.0 || fTranslateSpeed != 0.0;
|
||||
}
|
||||
|
||||
void TAnimContainer::EventAssign(basic_event *ev)
|
||||
@@ -263,18 +263,18 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
|
||||
// fBlinkTimer = Random() * ( fOnTime + fOffTime );
|
||||
|
||||
pModel = TModelsManager::GetModel( asName );
|
||||
return ( pModel != nullptr );
|
||||
return pModel != nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
TAnimModel::is_keyword( std::string const &Token ) const {
|
||||
|
||||
return ( Token == "endmodel" )
|
||||
|| ( Token == "lights" )
|
||||
|| ( Token == "lightcolors" )
|
||||
|| ( Token == "angles" )
|
||||
|| ( Token == "scale" )
|
||||
|| ( Token == "notransition" );
|
||||
return Token == "endmodel"
|
||||
|| Token == "lights"
|
||||
|| Token == "lightcolors"
|
||||
|| Token == "angles"
|
||||
|| Token == "scale"
|
||||
|| Token == "notransition";
|
||||
}
|
||||
|
||||
bool TAnimModel::Load(cParser *parser, bool ter)
|
||||
@@ -334,8 +334,8 @@ bool TAnimModel::Load(cParser *parser, bool ter)
|
||||
|
||||
if( token == "lights" ) {
|
||||
auto i{ 0 };
|
||||
while( ( false == ( token = parser->getToken<std::string>() ).empty() )
|
||||
&& ( false == is_keyword( token ) ) ) {
|
||||
while( false == (token = parser->getToken<std::string>()).empty()
|
||||
&& false == is_keyword(token) ) {
|
||||
|
||||
if( i < iNumLights ) {
|
||||
// stan światła jest liczbą z ułamkiem
|
||||
@@ -347,16 +347,16 @@ bool TAnimModel::Load(cParser *parser, bool ter)
|
||||
|
||||
if( token == "lightcolors" ) {
|
||||
auto i{ 0 };
|
||||
while( ( false == ( token = parser->getToken<std::string>() ).empty() )
|
||||
&& ( false == is_keyword( token ) ) ) {
|
||||
while( false == (token = parser->getToken<std::string>()).empty()
|
||||
&& false == is_keyword(token) ) {
|
||||
|
||||
if( ( i < iNumLights )
|
||||
&& ( token != "-1" ) ) { // -1 leaves the default color intact
|
||||
if( i < iNumLights
|
||||
&& token != "-1" ) { // -1 leaves the default color intact
|
||||
auto const lightcolor { std::stoi( token, 0, 16 ) };
|
||||
m_lightcolors[i] = {
|
||||
( ( lightcolor >> 16 ) & 0xff ) / 255.f,
|
||||
( ( lightcolor >> 8 ) & 0xff ) / 255.f,
|
||||
( ( lightcolor ) & 0xff ) / 255.f };
|
||||
( lightcolor >> 16 & 0xff ) / 255.f,
|
||||
( lightcolor >> 8 & 0xff ) / 255.f,
|
||||
( lightcolor & 0xff ) / 255.f };
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -391,8 +391,8 @@ bool TAnimModel::Load(cParser *parser, bool ter)
|
||||
m_transition = false;
|
||||
}
|
||||
|
||||
} while( ( false == token.empty() )
|
||||
&& ( token != "endmodel" ) );
|
||||
} while( false == token.empty()
|
||||
&& token != "endmodel" );
|
||||
|
||||
update_instanceable_flag();
|
||||
return true;
|
||||
@@ -486,7 +486,7 @@ std::shared_ptr<TAnimContainer> TAnimModel::AddContainer(std::string const &Name
|
||||
std::shared_ptr<TAnimContainer> TAnimModel::GetContainer(std::string const &Name)
|
||||
{ // szukanie/dodanie sterowania submodelem dla egzemplarza
|
||||
if (true == Name.empty())
|
||||
return (!m_animlist.empty()) ? m_animlist.front() : nullptr; // pobranie pierwszego (dla obrotnicy)
|
||||
return !m_animlist.empty() ? m_animlist.front() : nullptr; // pobranie pierwszego (dla obrotnicy)
|
||||
|
||||
for (auto entry : m_animlist) {
|
||||
if (entry->NameGet() == Name)
|
||||
@@ -583,34 +583,28 @@ void TAnimModel::RaPrepare()
|
||||
case ls_Off:
|
||||
case ls_Blink: {
|
||||
if (LightsOn[i]) {
|
||||
LightsOn[i]->iVisible = ( m_lightopacities[i] > 0.f );
|
||||
LightsOn[i]->iVisible = m_lightopacities[i] > 0.f;
|
||||
LightsOn[i]->SetVisibilityLevel( m_lightopacities[i], true, false );
|
||||
}
|
||||
if (LightsOff[i]) {
|
||||
LightsOff[i]->iVisible = ( m_lightopacities[i] < 1.f );
|
||||
LightsOff[i]->iVisible = m_lightopacities[i] < 1.f;
|
||||
LightsOff[i]->SetVisibilityLevel( 1.f, true, false );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ls_Dark: {
|
||||
// zapalone, gdy ciemno
|
||||
state = (
|
||||
Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= (
|
||||
lsLights[ i ] == static_cast<float>( ls_Dark ) ?
|
||||
DefaultDarkThresholdLevel :
|
||||
( lsLights[ i ] - static_cast<float>( ls_Dark ) ) ) );
|
||||
state =
|
||||
Global.fLuminance - std::max(0.f, Global.Overcast - 1.f) <= (lsLights[i] == static_cast<float>(ls_Dark) ? DefaultDarkThresholdLevel : lsLights[i] - static_cast<float>(ls_Dark));
|
||||
break;
|
||||
}
|
||||
case ls_Home: {
|
||||
// like ls_dark but off late at night
|
||||
auto const simulationhour { simulation::Time.data().wHour };
|
||||
state = (
|
||||
Global.fLuminance - std::max( 0.f, Global.Overcast - 1.f ) <= (
|
||||
lsLights[ i ] == static_cast<float>( ls_Home ) ?
|
||||
DefaultDarkThresholdLevel :
|
||||
( lsLights[ i ] - static_cast<float>( ls_Home ) ) ) );
|
||||
state =
|
||||
Global.fLuminance - std::max(0.f, Global.Overcast - 1.f) <= (lsLights[i] == static_cast<float>(ls_Home) ? DefaultDarkThresholdLevel : lsLights[i] - static_cast<float>(ls_Home));
|
||||
// force the lights off between 1-5am
|
||||
state = state && (( simulationhour < 1 ) || ( simulationhour >= 5 ));
|
||||
state = state && (simulationhour < 1 || simulationhour >= 5);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -644,7 +638,7 @@ int TAnimModel::Flags()
|
||||
{ // informacja dla TGround, czy ma być w Render, RenderAlpha, czy RenderMixed
|
||||
int i = pModel ? pModel->Flags() : 0; // pobranie flag całego modelu
|
||||
if( m_materialdata.replacable_skins[ 1 ] > 0 ) // jeśli ma wymienną teksturę 0
|
||||
i |= (i & 0x01010001) * ((m_materialdata.textures_alpha & 1) ? 0x20 : 0x10);
|
||||
i |= (i & 0x01010001) * (m_materialdata.textures_alpha & 1 ? 0x20 : 0x10);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -745,7 +739,7 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
|
||||
// location and rotation. The 4th token after location is a legacy
|
||||
// shorthand for the Y rotation. We use it (and skip the angles block)
|
||||
// whenever the rotation is purely around Y, which is the common case.
|
||||
bool const xz_rotation_zero = ( vAngle.x == 0.0f && vAngle.z == 0.0f );
|
||||
bool const xz_rotation_zero = vAngle.x == 0.0f && vAngle.z == 0.0f;
|
||||
Output << std::fixed << std::setprecision( 3 )
|
||||
<< location().x << ' '
|
||||
<< location().y << ' '
|
||||
|
||||
@@ -80,7 +80,7 @@ class TAnimContainer : std::enable_shared_from_this<TAnimContainer>
|
||||
bool Init(TSubModel *pNewSubModel);
|
||||
inline
|
||||
std::string NameGet() {
|
||||
return (pSubModel ? pSubModel->pName : ""); };
|
||||
return pSubModel ? pSubModel->pName : ""; };
|
||||
void SetRotateAnim( glm::vec3 vNewRotateAngles, double fNewRotateSpeed);
|
||||
void SetTranslateAnim( glm::dvec3 vNewTranslate, double fNewSpeed);
|
||||
void AnimSetVMD(double fNewSpeed);
|
||||
|
||||
@@ -81,8 +81,8 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
|
||||
// - wczytanie modelu animowanego - Init() - sprawdzić
|
||||
std::string const buftp { Global.asCurrentTexturePath }; // zapamiętanie aktualnej ścieżki do tekstur,
|
||||
std::string filename { Name };
|
||||
if( ( false == Dynamic )
|
||||
&& ( contains( Name, '/' ) ) ) {
|
||||
if( false == Dynamic
|
||||
&& contains(Name, '/') ) {
|
||||
// pobieranie tekstur z katalogu, w którym jest model
|
||||
// when loading vehicles the path is set by the calling routine, so we can skip it here
|
||||
Global.asCurrentTexturePath += Name;
|
||||
@@ -144,10 +144,7 @@ TModelsManager::find_on_disk( std::string const &Name ) {
|
||||
std::vector<std::string> extensions { { ".e3d" }, { ".t3d" } };
|
||||
for( auto const &extension : extensions ) {
|
||||
|
||||
auto lookup = (
|
||||
FileExists( Name + extension ) ? Name :
|
||||
FileExists( paths::models + Name + extension ) ? paths::models + Name :
|
||||
"" );
|
||||
auto lookup = FileExists(Name + extension) ? Name : FileExists(paths::models + Name + extension) ? paths::models + Name : "";
|
||||
if( false == lookup.empty() ) {
|
||||
return lookup;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ void TSubModel::SetDiffuseOverride(glm::vec3 const &Color, bool const Includechi
|
||||
sibling->SetDiffuseOverride(Color, Includechildren, false); // no need for all siblings to duplicate the work
|
||||
}
|
||||
}
|
||||
if ((true == Includechildren) && (Child != nullptr))
|
||||
if (true == Includechildren && Child != nullptr)
|
||||
{
|
||||
Child->SetDiffuseOverride(Color, Includechildren, true); // node's children include child's siblings and children
|
||||
}
|
||||
@@ -134,7 +134,7 @@ void TSubModel::SetVisibilityLevel(float const Level, bool const Includechildren
|
||||
sibling->SetVisibilityLevel(Level, Includechildren, false); // no need for all siblings to duplicate the work
|
||||
}
|
||||
}
|
||||
if ((true == Includechildren) && (Child != nullptr))
|
||||
if (true == Includechildren && Child != nullptr)
|
||||
{
|
||||
Child->SetVisibilityLevel(Level, Includechildren, true); // node's children include child's siblings and children
|
||||
}
|
||||
@@ -156,7 +156,7 @@ void TSubModel::SetLightLevel(glm::vec4 const &Level, bool const Includechildren
|
||||
sibling->SetLightLevel(Level, Includechildren, false); // no need for all siblings to duplicate the work
|
||||
}
|
||||
}
|
||||
if ((true == Includechildren) && (Child != nullptr))
|
||||
if (true == Includechildren && Child != nullptr)
|
||||
{
|
||||
Child->SetLightLevel(Level, Includechildren, true); // node's children include child's siblings and children
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void TSubModel::SetSelfIllum(float const Threshold, bool const Includechildren,
|
||||
sibling->SetSelfIllum(Threshold, Includechildren, false); // no need for all siblings to duplicate the work
|
||||
}
|
||||
}
|
||||
if ((true == Includechildren) && (Child != nullptr))
|
||||
if (true == Includechildren && Child != nullptr)
|
||||
{
|
||||
Child->SetSelfIllum(Threshold, Includechildren, true); // node's children include child's siblings and children
|
||||
}
|
||||
@@ -243,7 +243,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
{
|
||||
std::string errormessage{"Bad model: expected submodel type definition not found while loading model \"" + parser.Name() + "\"" + "\ncurrent model data stream content: \""};
|
||||
auto count{10};
|
||||
while ((true == parser.getTokens()) && (false == (token = parser.peek()).empty()) && (token != "parent:"))
|
||||
while (true == parser.getTokens() && false == (token = parser.peek()).empty() && token != "parent:")
|
||||
{
|
||||
// skip data until next submodel, dump first few tokens in the error message
|
||||
if (--count > 0)
|
||||
@@ -275,7 +275,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
if (dynamic)
|
||||
{
|
||||
// dla pojazdu, blokujemy załączone submodele, które mogą być nieobsługiwane
|
||||
if ((token.size() >= 3) && (token.find("_on") + 3 == token.length()))
|
||||
if (token.size() >= 3 && token.find("_on") + 3 == token.length())
|
||||
{
|
||||
// jeśli nazwa kończy się na "_on" to domyślnie wyłączyć, żeby się nie nakładało z obiektem "_off"
|
||||
iVisible = 0;
|
||||
@@ -418,27 +418,27 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
else if (material.find("replacableskin") != material.npos)
|
||||
{ // McZapkie-060702: zmienialne skory modelu
|
||||
m_material = -1;
|
||||
iFlags |= (Opacity < 0.999) ? 1 : 0x10; // zmienna tekstura 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
|
||||
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
|
||||
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
|
||||
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
|
||||
iFlags |= Opacity < 0.999 ? 8 : 0x10; // zmienna tekstura 4
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -509,10 +509,10 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
// check the scaling
|
||||
auto const matrix = glm::make_mat4(fMatrix->readArray());
|
||||
glm::vec3 const scale{glm::length(glm::vec3(glm::column(matrix, 0))), glm::length(glm::vec3(glm::column(matrix, 1))), glm::length(glm::vec3(glm::column(matrix, 2)))};
|
||||
if ((std::abs(scale.x - 1.0f) > 0.01) || (std::abs(scale.y - 1.0f) > 0.01) || (std::abs(scale.z - 1.0f) > 0.01))
|
||||
if (std::abs(scale.x - 1.0f) > 0.01 || std::abs(scale.y - 1.0f) > 0.01 || std::abs(scale.z - 1.0f) > 0.01)
|
||||
{
|
||||
ErrorLog("Bad model: transformation matrix for sub-model \"" + pName + "\" imposes geometry scaling (factors: " + to_string(scale) + ")", logtype::model);
|
||||
m_normalizenormals = (((std::abs(scale.x - scale.y) < 0.01f) && (std::abs(scale.y - scale.z) < 0.01f)) ? rescale : normalize);
|
||||
m_normalizenormals = std::abs(scale.x - scale.y) < 0.01f && std::abs(scale.y - scale.z) < 0.01f ? rescale : normalize;
|
||||
}
|
||||
transformscalestack *= (scale.x + scale.y + scale.z) / 3.0f;
|
||||
}
|
||||
@@ -536,7 +536,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
}
|
||||
token = parser.getToken<std::string>();
|
||||
}
|
||||
if ((token == "numverts:") || (token == "numverts"))
|
||||
if (token == "numverts:" || token == "numverts")
|
||||
{ // normalna lista wierzchołków
|
||||
/*
|
||||
// Ra 15-01: to wczytać jako tekst - jeśli pierwszy znak zawiera "*", to
|
||||
@@ -550,7 +550,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
}
|
||||
*/
|
||||
m_geometry.vertex_count = parser.getToken<int>(false);
|
||||
if ((m_geometry.index_count <= 0) && (m_geometry.vertex_count % 3 != 0))
|
||||
if (m_geometry.index_count <= 0 && m_geometry.vertex_count % 3 != 0)
|
||||
{
|
||||
m_geometry.vertex_count = 0;
|
||||
Error("Bad model: incomplete triangle encountered in submodel \"" + pName + "\"");
|
||||
@@ -588,12 +588,12 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
++vertexidx;
|
||||
// Ra: z konwersją na układ scenerii - będzie wydajniejsze wyświetlanie
|
||||
wsp[idx] = -1; // wektory normalne nie są policzone dla tego wierzchołka
|
||||
if ((idx % 3) == 0)
|
||||
if (idx % 3 == 0)
|
||||
{
|
||||
// jeśli będzie maska -1, to dalej będą wierzchołki z wektorami normalnymi, podanymi jawnie
|
||||
maska = parser.getToken<int>(false); // maska powierzchni trójkąta
|
||||
// dla maski -1 będzie 0, czyli nie ma wspólnych wektorów normalnych
|
||||
sg[idx / 3] = ((maska == -1) ? 0 : maska);
|
||||
sg[idx / 3] = maska == -1 ? 0 : maska;
|
||||
}
|
||||
auto vertex{vertices + idx};
|
||||
parser.getTokens(3, false);
|
||||
@@ -630,8 +630,8 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
{
|
||||
// jeśli pierwszy trójkąt będzie zdegenerowany, to zostanie usunięty i nie ma co sprawdzać
|
||||
// length2 is better than length for comparing because it does not require sqrt function
|
||||
if ((glm::length2((vertex)->position - (vertex - 1)->position) > sq(1000.0)) || (glm::length2((vertex - 1)->position - (vertex - 2)->position) > sq(1000.0)) ||
|
||||
(glm::length2((vertex - 2)->position - (vertex)->position) > sq(1000.0)))
|
||||
if (glm::length2(vertex->position - (vertex - 1)->position) > sq(1000.0) || glm::length2((vertex - 1)->position - (vertex - 2)->position) > sq(1000.0) ||
|
||||
glm::length2((vertex - 2)->position - vertex->position) > sq(1000.0))
|
||||
{
|
||||
// jeżeli są dalej niż 2km od siebie //Ra 15-01:
|
||||
// obiekt wstawiany nie powinien być większy niż 300m (trójkąty terenu w E3D mogą mieć 1.5km)
|
||||
@@ -649,7 +649,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
for (int i = 0; i < facecount; ++i)
|
||||
{
|
||||
// pętla po trójkątach - będzie szybciej, jak wstępnie przeliczymy normalne trójkątów
|
||||
auto const vertex{vertices + (i * 3)};
|
||||
auto const vertex{vertices + i * 3};
|
||||
auto facenormal = glm::cross(vertex->position - (vertex + 1)->position, vertex->position - (vertex + 2)->position);
|
||||
facenormals.emplace_back(glm::length2(facenormal) > 0.0f ? glm::normalize(facenormal) : glm::vec3());
|
||||
}
|
||||
@@ -690,7 +690,7 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
{
|
||||
WriteLog("Bad model: zero length normal vector generated for sub-model \"" + pName + "\"", logtype::model);
|
||||
}
|
||||
vertex->normal = (glm::length2(vertexnormal) > 0.0f ? glm::normalize(vertexnormal) : facenormals[vertexidx / 3]); // przepisanie do wierzchołka trójkąta
|
||||
vertex->normal = glm::length2(vertexnormal) > 0.0f ? glm::normalize(vertexnormal) : facenormals[vertexidx / 3]; // przepisanie do wierzchołka trójkąta
|
||||
}
|
||||
}
|
||||
Vertices.resize(m_geometry.vertex_count); // in case we had some degenerate triangles along the way
|
||||
@@ -740,9 +740,9 @@ std::pair<int, int> TSubModel::Load(cParser &parser, bool dynamic)
|
||||
parser.getTokens(5, false);
|
||||
parser >> vertex->position.x >> vertex->position.y >> vertex->position.z >> color // zakodowany kolor
|
||||
>> discard;
|
||||
vertex->normal = {((color) & 0xff) / 255.0f, // R
|
||||
((color >> 8) & 0xff) / 255.0f, // G
|
||||
((color >> 16) & 0xff) / 255.0f}; // B
|
||||
vertex->normal = {(color & 0xff) / 255.0f, // R
|
||||
(color >> 8 & 0xff) / 255.0f, // G
|
||||
(color >> 16 & 0xff) / 255.0f}; // B
|
||||
}
|
||||
}
|
||||
else if (eType == TP_FREESPOTLIGHT)
|
||||
@@ -841,15 +841,15 @@ void TSubModel::InitialRotate(bool doit)
|
||||
else if (Global.iConvertModels & 2)
|
||||
{
|
||||
// optymalizacja jest opcjonalna
|
||||
if (((iFlags & 0xC000) == 0x8000) // o ile nie ma animacji
|
||||
&& (false == is_emitter())) // don't optimize smoke emitter attachment points
|
||||
if ((iFlags & 0xC000) == 0x8000 // o ile nie ma animacji
|
||||
&& false == is_emitter()) // don't optimize smoke emitter attachment points
|
||||
{ // jak nie ma potomnych, można wymnożyć przez transform i wyjedynkować go
|
||||
float4x4 *mat = GetMatrix(); // transform submodelu
|
||||
if (false == Vertices.empty())
|
||||
{
|
||||
for (auto &vertex : Vertices)
|
||||
{
|
||||
vertex.position = (*mat) * vertex.position;
|
||||
vertex.position = *mat * vertex.position;
|
||||
}
|
||||
// zerujemy przesunięcie przed obracaniem normalnych
|
||||
(*mat)(3)[0] = (*mat)(3)[1] = (*mat)(3)[2] = 0.0;
|
||||
@@ -858,8 +858,8 @@ void TSubModel::InitialRotate(bool doit)
|
||||
// gwiazdki mają kolory zamiast normalnych, to ich wtedy nie ruszamy
|
||||
for (auto &vertex : Vertices)
|
||||
{
|
||||
vertex.normal = (*mat) * vertex.normal;
|
||||
vertex.tangent.xyz = (*mat) * vertex.tangent.xyz;
|
||||
vertex.normal = *mat * vertex.normal;
|
||||
vertex.tangent.xyz = *mat * vertex.tangent.xyz;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -925,7 +925,7 @@ int TSubModel::count_siblings()
|
||||
int TSubModel::count_children()
|
||||
{
|
||||
|
||||
return (Child == nullptr ? 0 : 1 + Child->count_siblings());
|
||||
return Child == nullptr ? 0 : 1 + Child->count_siblings();
|
||||
}
|
||||
|
||||
// locates submodel mapped with replacable -4
|
||||
@@ -934,7 +934,7 @@ std::tuple<TSubModel *, bool> TSubModel::find_replacable4()
|
||||
|
||||
if (m_material == -4)
|
||||
{
|
||||
return std::make_tuple(this, (fLight != -1.0));
|
||||
return std::make_tuple(this, fLight != -1.0);
|
||||
}
|
||||
|
||||
if (Next != nullptr)
|
||||
@@ -964,7 +964,7 @@ void TSubModel::find_smoke_sources(nameoffset_sequence &Sourcelist) const
|
||||
|
||||
auto const name{ToLower(pName)};
|
||||
|
||||
if ((eType == TP_ROTATOR) && (pName.find("smokesource_") == 0))
|
||||
if (eType == TP_ROTATOR && pName.find("smokesource_") == 0)
|
||||
{
|
||||
Sourcelist.emplace_back(pName, offset());
|
||||
}
|
||||
@@ -994,7 +994,7 @@ uint32_t TSubModel::FlagsCheck()
|
||||
if (Child->m_material != m_material) // i jest ona inna niż rodzica
|
||||
Child->iFlags |= 0x80; // to trzeba sprawdzać, jak z teksturami jest
|
||||
i = Child->FlagsCheck();
|
||||
iFlags |= 0x00FF0000 & ((i << 16) | (i) | (i >> 8)); // potomny, rodzeństwo i dzieci
|
||||
iFlags |= 0x00FF0000 & (i << 16 | i | i >> 8); // potomny, rodzeństwo i dzieci
|
||||
if (eType == TP_TEXT)
|
||||
{ // wyłączenie renderowania Next dla znaków
|
||||
// wyświetlacza tekstowego
|
||||
@@ -1010,10 +1010,10 @@ uint32_t TSubModel::FlagsCheck()
|
||||
{ // Next jest renderowany po danym submodelu (kolejność odwrócona
|
||||
// po wczytaniu T3D)
|
||||
if (m_material) // o ile dany ma teksturę
|
||||
if ((m_material != Next->m_material) || (i & 0x00800000)) // a ma inną albo dzieci zmieniają
|
||||
if (m_material != Next->m_material || i & 0x00800000) // a ma inną albo dzieci zmieniają
|
||||
iFlags |= 0x80; // to dany submodel musi sobie ją ustawiać
|
||||
i = Next->FlagsCheck();
|
||||
iFlags |= 0xFF000000 & ((i << 24) | (i << 8) | (i)); // następny, kolejne i ich dzieci
|
||||
iFlags |= 0xFF000000 & (i << 24 | i << 8 | i); // następny, kolejne i ich dzieci
|
||||
// tekstury nie ustawiamy tylko wtedy, gdy jest taka sama jak Next i jego
|
||||
// dzieci nie zmieniają
|
||||
}
|
||||
@@ -1200,7 +1200,7 @@ void TSubModel::RaAnimation(glm::mat4 &m, TAnimType a)
|
||||
if (sm->pName.size())
|
||||
{
|
||||
// musi mieć niepustą nazwę
|
||||
if ((sm->pName[0] >= '0') && (sm->pName[0] <= '5'))
|
||||
if (sm->pName[0] >= '0' && sm->pName[0] <= '5')
|
||||
{
|
||||
// zegarek ma 6 cyfr maksymalnie
|
||||
sm->SetRotate(float3(0, 1, 0), -Global.fClockAngleDeg[sm->pName[0] - '0']);
|
||||
@@ -1278,12 +1278,12 @@ int TSubModel::index_size() const
|
||||
{
|
||||
size = std::max(size, Child->index_size());
|
||||
}
|
||||
if ((size < 4) && (m_geometry.handle != null_handle))
|
||||
if (size < 4 && m_geometry.handle != null_handle)
|
||||
{
|
||||
auto const indexcount{GfxRenderer->Indices(m_geometry.handle).size()};
|
||||
size = std::max(size, (indexcount >= (1 << 16) ? 4 : indexcount >= (1 << 8) ? 2 : 1));
|
||||
size = std::max(size, indexcount >= 1 << 16 ? 4 : indexcount >= 1 << 8 ? 2 : 1);
|
||||
}
|
||||
if ((size < 4) && (Next))
|
||||
if (size < 4 && Next)
|
||||
{
|
||||
size = std::max(size, Next->index_size());
|
||||
}
|
||||
@@ -1355,7 +1355,7 @@ void TSubModel::create_geometry(std::size_t &Indexoffset, std::size_t &Vertexoff
|
||||
m_geometry.vertex_offset = static_cast<int>(Vertexoffset);
|
||||
Vertexoffset += Vertices.size();
|
||||
// conveniently all relevant custom node types use GL_POINTS, or we'd have to determine the type on individual basis
|
||||
auto type = (eType < TP_ROTATOR ? eType : GL_POINTS);
|
||||
auto type = eType < TP_ROTATOR ? eType : GL_POINTS;
|
||||
m_geometry.handle = GfxRenderer->Insert(Indices, Vertices, Userdata, Bank, type);
|
||||
}
|
||||
|
||||
@@ -1417,7 +1417,7 @@ void TSubModel::ColorsSet(glm::vec3 const &Ambient, glm::vec3 const &Diffuse, gl
|
||||
bool TSubModel::is_emitter() const
|
||||
{
|
||||
|
||||
return ((eType == TP_ROTATOR) && (ToLower(pName).find("smokesource_") == 0));
|
||||
return eType == TP_ROTATOR && ToLower(pName).find("smokesource_") == 0;
|
||||
}
|
||||
|
||||
// pobranie transformacji względem wstawienia modelu
|
||||
@@ -1438,13 +1438,13 @@ void TSubModel::ParentMatrix(float4x4 *m) const
|
||||
submodelmatrix = float4x4(*submodel->GetMatrix());
|
||||
}
|
||||
// ...potentially adjust transformations of the root matrix if the model wasn't yet initialized...
|
||||
if ((submodel->Parent == nullptr) && (false == submodel->m_rotation_init_done))
|
||||
if (submodel->Parent == nullptr && false == submodel->m_rotation_init_done)
|
||||
{
|
||||
// dla ostatniego może być potrzebny dodatkowy obrót, jeśli wczytano z T3D, a nie obrócono jeszcze
|
||||
submodelmatrix.InitialRotate();
|
||||
}
|
||||
// ...combine the transformations...
|
||||
*m = submodelmatrix * (*m);
|
||||
*m = submodelmatrix * *m;
|
||||
// ...and move up the transformation chain for the iteration...
|
||||
submodel = submodel->Parent;
|
||||
// ... until we hit the root
|
||||
@@ -1528,7 +1528,7 @@ TSubModel *TModel3d::AddToNamed(const char *Name, TSubModel *SubModel)
|
||||
{
|
||||
|
||||
TSubModel *sm = Name ? GetFromName(Name) : nullptr;
|
||||
if ((sm == nullptr) && (Name != nullptr) && (std::strcmp(Name, "none") != 0))
|
||||
if (sm == nullptr && Name != nullptr && std::strcmp(Name, "none") != 0)
|
||||
{
|
||||
ErrorLog("Bad model: parent for sub-model \"" + SubModel->pName + "\" doesn't exist or is located later in the model data", logtype::model);
|
||||
}
|
||||
@@ -1651,7 +1651,7 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
|
||||
Init();
|
||||
}
|
||||
|
||||
bool const result = Root ? (iSubModelsCount > 0) : false; // brak pliku albo problem z wczytaniem
|
||||
bool const result = Root ? iSubModelsCount > 0 : false; // brak pliku albo problem z wczytaniem
|
||||
if (false == result)
|
||||
{
|
||||
ErrorLog("Bad model: failed to load 3d model \"" + name + "\"");
|
||||
@@ -1701,7 +1701,7 @@ void TSubModel::serialize(std::ostream &s, std::vector<TSubModel *> &models, std
|
||||
sn_utils::ls_int32(s, (int)b_Anim);
|
||||
|
||||
uint32_t flags = iFlags;
|
||||
if (m_material > 0 && (Global.iConvertModels & 16))
|
||||
if (m_material > 0 && Global.iConvertModels & 16)
|
||||
flags &= ~0x30; // don't save phase information, will be guessed on binary load from material
|
||||
sn_utils::ls_uint32(s, flags);
|
||||
sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix));
|
||||
@@ -1972,11 +1972,11 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
||||
}
|
||||
submodeloffsets.emplace_back(submodelgeometry.vertex_offset, submodelindex);
|
||||
}
|
||||
std::sort(std::begin(submodeloffsets), std::end(submodeloffsets), [](std::pair<int, int> const &Left, std::pair<int, int> const &Right) { return (Left.first) < (Right.first); });
|
||||
std::sort(std::begin(submodeloffsets), std::end(submodeloffsets), [](std::pair<int, int> const &Left, std::pair<int, int> const &Right) { return Left.first < Right.first; });
|
||||
// once sorted we can grab geometry as it comes, and assign it to the chunks it belongs to
|
||||
size_t const vertextype{(((type & 0xFF000000) >> 24) - '0')};
|
||||
hastangents = ((vertextype & 3) > 0);
|
||||
hasuserdata = (vertextype & 4);
|
||||
hastangents = (vertextype & 3) > 0;
|
||||
hasuserdata = vertextype & 4;
|
||||
size_t vertex_size = 0;
|
||||
switch (vertextype & 3)
|
||||
{
|
||||
@@ -2022,7 +2022,7 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
||||
if (submodel.eType < TP_ROTATOR)
|
||||
{
|
||||
// normal vectors debug routine
|
||||
if ((false == submodel.m_normalizenormals) && (std::abs(glm::length2(submodel.Vertices[i].normal) - 1.0f) > 0.01f))
|
||||
if (false == submodel.m_normalizenormals && std::abs(glm::length2(submodel.Vertices[i].normal) - 1.0f) > 0.01f)
|
||||
{
|
||||
submodel.m_normalizenormals = TSubModel::normalize; // we don't know if uniform scaling would suffice
|
||||
WriteLog("Bad model: non-unit normal vector(s) encountered during sub-model geometry deserialization", logtype::model);
|
||||
@@ -2079,7 +2079,7 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
||||
}
|
||||
submodeloffsets.emplace_back(submodelgeometry.index_offset, submodelindex);
|
||||
}
|
||||
std::sort(std::begin(submodeloffsets), std::end(submodeloffsets), [](std::pair<int, int> const &Left, std::pair<int, int> const &Right) { return (Left.first) < (Right.first); });
|
||||
std::sort(std::begin(submodeloffsets), std::end(submodeloffsets), [](std::pair<int, int> const &Left, std::pair<int, int> const &Right) { return Left.first < Right.first; });
|
||||
// once sorted we can grab indices in a continuous read, and assign them to the chunks they belong to
|
||||
size_t const indexsize{(((type & 0xFF000000) >> 24) - '0')};
|
||||
for (auto const &submodeloffset : submodeloffsets)
|
||||
@@ -2204,11 +2204,11 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
|
||||
{ // ustawienie wskaźników w submodelu
|
||||
// m7todo: brzydko
|
||||
iVisible = 1; // tymczasowo używane
|
||||
Child = (iChild > 0) ? s + iChild : nullptr; // zerowy nie może być potomnym
|
||||
Next = (iNext > 0) ? s + iNext : nullptr; // zerowy nie może być następnym
|
||||
fMatrix = ((iMatrix >= 0) && m) ? m + iMatrix : nullptr;
|
||||
Child = iChild > 0 ? s + iChild : nullptr; // zerowy nie może być potomnym
|
||||
Next = iNext > 0 ? s + iNext : nullptr; // zerowy nie może być następnym
|
||||
fMatrix = iMatrix >= 0 && m ? m + iMatrix : nullptr;
|
||||
|
||||
if (n->size() && (iName >= 0))
|
||||
if (n->size() && iName >= 0)
|
||||
{
|
||||
pName = n->at(iName);
|
||||
if (!pName.empty())
|
||||
@@ -2303,7 +2303,7 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
|
||||
m_material = GfxRenderer->Fetch_Material("stars");
|
||||
iFlags |= 0x10;
|
||||
}
|
||||
else if ((eType == TP_FREESPOTLIGHT) && (iFlags & 0x10))
|
||||
else if (eType == TP_FREESPOTLIGHT && iFlags & 0x10)
|
||||
{
|
||||
// we've added light glare which needs to be rendered during transparent phase,
|
||||
// but models converted to e3d before addition won't have the render flag set correctly for this
|
||||
@@ -2328,10 +2328,10 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
|
||||
{
|
||||
auto const matrix = glm::make_mat4(fMatrix->readArray());
|
||||
glm::vec3 const scale{glm::length(glm::vec3(glm::column(matrix, 0))), glm::length(glm::vec3(glm::column(matrix, 1))), glm::length(glm::vec3(glm::column(matrix, 2)))};
|
||||
if ((std::abs(scale.x - 1.0f) > 0.01) || (std::abs(scale.y - 1.0f) > 0.01) || (std::abs(scale.z - 1.0f) > 0.01))
|
||||
if (std::abs(scale.x - 1.0f) > 0.01 || std::abs(scale.y - 1.0f) > 0.01 || std::abs(scale.z - 1.0f) > 0.01)
|
||||
{
|
||||
ErrorLog("Bad model: transformation matrix for sub-model \"" + pName + "\" imposes geometry scaling (factors: " + to_string(scale) + ")", logtype::model);
|
||||
m_normalizenormals = (((std::abs(scale.x - scale.y) < 0.01f) && (std::abs(scale.y - scale.z) < 0.01f)) ? rescale : normalize);
|
||||
m_normalizenormals = std::abs(scale.x - scale.y) < 0.01f && std::abs(scale.y - scale.z) < 0.01f ? rescale : normalize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2492,7 +2492,7 @@ void TModel3d::Init()
|
||||
Root->m_boundingradius = std::max(Root->m_boundingradius, root->m_boundingradius);
|
||||
}
|
||||
|
||||
if ((Global.iConvertModels & 1) && (false == asBinary.empty()))
|
||||
if (Global.iConvertModels & 1 && false == asBinary.empty())
|
||||
{
|
||||
SaveToBinFile(asBinary);
|
||||
asBinary = ""; // zablokowanie powtórnego zapisu
|
||||
|
||||
@@ -228,9 +228,9 @@ public:
|
||||
// sets activation threshold of self-illumination to specitied value
|
||||
void SetSelfIllum( float const Threshold, bool const Includechildren = false, bool const Includesiblings = false );
|
||||
inline float3 Translation1Get() {
|
||||
return fMatrix ? *(fMatrix->TranslationGet()) + v_TransVector : v_TransVector; }
|
||||
return fMatrix ? *fMatrix->TranslationGet() + v_TransVector : v_TransVector; }
|
||||
inline float3 Translation2Get() {
|
||||
return *(fMatrix->TranslationGet()) + Child->Translation1Get(); }
|
||||
return *fMatrix->TranslationGet() + Child->Translation1Get(); }
|
||||
material_handle GetMaterial() const {
|
||||
return m_material; }
|
||||
void ParentMatrix(float4x4 *m) const;
|
||||
@@ -278,11 +278,8 @@ public:
|
||||
TModel3d() = default;
|
||||
~TModel3d();
|
||||
float bounding_radius() const {
|
||||
return (
|
||||
Root ?
|
||||
Root->m_boundingradius :
|
||||
0.f ); }
|
||||
inline TSubModel * GetSMRoot() { return (Root); };
|
||||
return Root ? Root->m_boundingradius : 0.f; }
|
||||
inline TSubModel * GetSMRoot() { return Root; };
|
||||
TSubModel * GetFromName(std::string const &Name) const;
|
||||
TSubModel * AddToNamed(const char *Name, TSubModel *SubModel);
|
||||
nameoffset_sequence const & find_smoke_sources();
|
||||
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
auto const blanktimestamp { std::chrono::steady_clock::time_point() };
|
||||
int releasecount{ 0 };
|
||||
for( auto resourceindex = m_resourcesweepindex; resourceindex < sweeplastindex; ++resourceindex ) {
|
||||
if( ( m_container[ resourceindex ].second != blanktimestamp )
|
||||
&& ( m_resourcetimestamp - m_container[ resourceindex ].second > m_unusedresourcetimetolive ) ) {
|
||||
if( m_container[resourceindex].second != blanktimestamp
|
||||
&& m_resourcetimestamp - m_container[resourceindex].second > m_unusedresourcetimetolive ) {
|
||||
|
||||
m_container[ resourceindex ].first->release();
|
||||
m_container[ resourceindex ].second = blanktimestamp;
|
||||
@@ -59,10 +59,8 @@ public:
|
||||
WriteLog( "Resource garbage sweep released " + std::to_string( releasecount ) + " " + ( releasecount == 1 ? m_resourcename : m_resourcename + "s" ) );
|
||||
}
|
||||
*/
|
||||
m_resourcesweepindex = (
|
||||
m_resourcesweepindex + m_unusedresourcesweepsize >= m_container.size() ?
|
||||
0 : // if the next sweep chunk is beyond actual data, so start anew
|
||||
m_resourcesweepindex + m_unusedresourcesweepsize );
|
||||
m_resourcesweepindex = m_resourcesweepindex + m_unusedresourcesweepsize >= m_container.size() ? 0 : // if the next sweep chunk is beyond actual data, so start anew
|
||||
m_resourcesweepindex + m_unusedresourcesweepsize;
|
||||
|
||||
return releasecount; }
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ void opengl_texture::gles_match_internalformat(GLuint internalformat)
|
||||
for (int y = 0; y < data_height; y++)
|
||||
for (int x = 0; x < data_width; x++)
|
||||
{
|
||||
int pixel = (y * data_width + x);
|
||||
int pixel = y * data_width + x;
|
||||
int in_off = pixel * in_c;
|
||||
int out_off = pixel * out_c;
|
||||
for (int i = 0; i < out_c; i++)
|
||||
@@ -264,19 +264,16 @@ opengl_texture::load() {
|
||||
if( data_state == resource_state::good ) {
|
||||
|
||||
// verify texture size
|
||||
if( ( clamp_power_of_two( data_width ) != data_width ) || ( clamp_power_of_two( data_height ) != data_height ) ) {
|
||||
if( clamp_power_of_two(data_width) != data_width || clamp_power_of_two(data_height) != data_height ) {
|
||||
if( name != "logo" ) {
|
||||
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't powers of 2", logtype::texture );
|
||||
}
|
||||
}
|
||||
if( ( quantize( data_width, 4u ) != data_width ) || ( quantize( data_height, 4u ) != data_height ) ) {
|
||||
if( quantize(data_width, 4u) != data_width || quantize(data_height, 4u) != data_height ) {
|
||||
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't multiples of 4", logtype::texture );
|
||||
}
|
||||
|
||||
has_alpha = (
|
||||
data_components == GL_RGBA ?
|
||||
true :
|
||||
false );
|
||||
has_alpha = data_components == GL_RGBA ? true : false;
|
||||
|
||||
size = data.size() / 1024;
|
||||
|
||||
@@ -355,7 +352,7 @@ void opengl_texture::load_STBI()
|
||||
free(image);
|
||||
|
||||
data_format = GL_RGBA;
|
||||
data_components = (n == 4 ? GL_RGBA : GL_RGB);
|
||||
data_components = n == 4 ? GL_RGBA : GL_RGB;
|
||||
data_width = x;
|
||||
data_height = y;
|
||||
data_mapcount = 1;
|
||||
@@ -553,12 +550,12 @@ opengl_texture::load_DDS() {
|
||||
data_height = ddsd.dwHeight;
|
||||
data_mapcount = ddsd.dwMipMapCount;
|
||||
|
||||
int blockSize = ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 8 : 16 );
|
||||
int blockSize = data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 8 : 16;
|
||||
int offset = 0;
|
||||
|
||||
while( ( data_width > Global.CurrentMaxTextureSize ) || ( data_height > Global.CurrentMaxTextureSize ) ) {
|
||||
while( data_width > Global.CurrentMaxTextureSize || data_height > Global.CurrentMaxTextureSize ) {
|
||||
// pomijanie zbyt dużych mipmap, jeśli wymagane jest ograniczenie rozmiaru
|
||||
offset += ( ( data_width + 3 ) / 4 ) * ( ( data_height + 3 ) / 4 ) * blockSize;
|
||||
offset += (data_width + 3) / 4 * ( ( data_height + 3 ) / 4 ) * blockSize;
|
||||
data_width /= 2;
|
||||
data_height /= 2;
|
||||
--data_mapcount;
|
||||
@@ -608,7 +605,7 @@ opengl_texture::load_DDS() {
|
||||
else if (ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT5)
|
||||
flip_s3tc::flip_dxt45_image(mipmap, width, height);
|
||||
|
||||
mipmap += ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 ) * blockSize;
|
||||
mipmap += (width + 3) / 4 * ( ( height + 3 ) / 4 ) * blockSize;
|
||||
width = std::max( width / 2, 4 );
|
||||
height = std::max( height / 2, 4 );
|
||||
--mapcount;
|
||||
@@ -616,9 +613,7 @@ opengl_texture::load_DDS() {
|
||||
}
|
||||
|
||||
data_components =
|
||||
( ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT1 ?
|
||||
GL_RGB :
|
||||
GL_RGBA );
|
||||
ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT1 ? GL_RGB : GL_RGBA;
|
||||
|
||||
data_state = resource_state::good;
|
||||
|
||||
@@ -662,7 +657,7 @@ opengl_texture::load_KTX() {
|
||||
data_width = sub_data.width;
|
||||
data_height = sub_data.height;
|
||||
|
||||
if( ( data_width > Global.CurrentMaxTextureSize ) || ( data_height > Global.CurrentMaxTextureSize ) ) {
|
||||
if( data_width > Global.CurrentMaxTextureSize || data_height > Global.CurrentMaxTextureSize ) {
|
||||
data_mapcount--;
|
||||
continue;
|
||||
}
|
||||
@@ -753,9 +748,9 @@ opengl_texture::load_TGA() {
|
||||
int const bytesperpixel = tgaheader[ 16 ] / 8;
|
||||
|
||||
// check whether width, height an BitsPerPixel are valid
|
||||
if( ( data_width <= 0 )
|
||||
|| ( data_height <= 0 )
|
||||
|| ( ( bytesperpixel != 1 ) && ( bytesperpixel != 3 ) && ( bytesperpixel != 4 ) ) ) {
|
||||
if( data_width <= 0
|
||||
|| data_height <= 0
|
||||
|| ( bytesperpixel != 1 && bytesperpixel != 3 && bytesperpixel != 4 ) ) {
|
||||
|
||||
data_state = resource_state::failed;
|
||||
return;
|
||||
@@ -790,7 +785,7 @@ opengl_texture::load_TGA() {
|
||||
buffer[ 2 ] = buffer[ 0 ];
|
||||
}
|
||||
// copy all four values in one operation
|
||||
( *datapointer ) = ( *bufferpointer );
|
||||
*datapointer = *bufferpointer;
|
||||
++datapointer;
|
||||
}
|
||||
}
|
||||
@@ -822,7 +817,7 @@ opengl_texture::load_TGA() {
|
||||
buffer[ 2 ] = buffer[ 0 ];
|
||||
}
|
||||
// copy all four values in one operation
|
||||
( *datapointer ) = ( *bufferpointer );
|
||||
*datapointer = *bufferpointer;
|
||||
|
||||
++datapointer;
|
||||
++currentpixel;
|
||||
@@ -842,7 +837,7 @@ opengl_texture::load_TGA() {
|
||||
// copy the color into the image data as many times as dictated
|
||||
for( int i = 0; i <= chunkheader; ++i ) {
|
||||
|
||||
( *datapointer ) = ( *bufferpointer );
|
||||
*datapointer = *bufferpointer;
|
||||
++datapointer;
|
||||
++currentpixel;
|
||||
}
|
||||
@@ -863,7 +858,7 @@ opengl_texture::load_TGA() {
|
||||
}
|
||||
|
||||
downsize( GL_BGRA );
|
||||
if( ( data_width > Global.CurrentMaxTextureSize ) || ( data_height > Global.CurrentMaxTextureSize ) ) {
|
||||
if( data_width > Global.CurrentMaxTextureSize || data_height > Global.CurrentMaxTextureSize ) {
|
||||
// for non-square textures there's currently possibility the scaling routine will have to abort
|
||||
// before it gets all work done
|
||||
data_state = resource_state::failed;
|
||||
@@ -876,9 +871,7 @@ opengl_texture::load_TGA() {
|
||||
data_mapcount = 1;
|
||||
data_format = GL_BGRA;
|
||||
data_components =
|
||||
( bytesperpixel == 4 ?
|
||||
GL_RGBA :
|
||||
GL_RGB );
|
||||
bytesperpixel == 4 ? GL_RGBA : GL_RGB;
|
||||
data_state = resource_state::good;
|
||||
|
||||
return;
|
||||
@@ -887,8 +880,8 @@ opengl_texture::load_TGA() {
|
||||
bool
|
||||
opengl_texture::bind(size_t unit) {
|
||||
|
||||
if( ( false == is_ready )
|
||||
&& ( false == create() ) ) {
|
||||
if( false == is_ready
|
||||
&& false == create() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1044,7 +1037,7 @@ opengl_texture::create( bool const Static ) {
|
||||
// compressed dds formats
|
||||
const int datablocksize = blocksize_it->second;
|
||||
|
||||
datasize = ( ( std::max( datawidth, 4 ) + 3 ) / 4 ) * ( ( std::max( dataheight, 4 ) + 3 ) / 4 ) * datablocksize;
|
||||
datasize = (std::max(datawidth, 4) + 3) / 4 * ( ( std::max( dataheight, 4 ) + 3 ) / 4 ) * datablocksize;
|
||||
|
||||
::glCompressedTexImage2D(
|
||||
target, maplevel, internal_format,
|
||||
@@ -1071,8 +1064,8 @@ opengl_texture::create( bool const Static ) {
|
||||
glGenerateMipmap(target);
|
||||
}
|
||||
|
||||
if( ( true == Global.ResourceMove )
|
||||
|| ( false == Global.ResourceSweep ) ) {
|
||||
if( true == Global.ResourceMove
|
||||
|| false == Global.ResourceSweep ) {
|
||||
// if garbage collection is disabled we don't expect having to upload the texture more than once
|
||||
data = std::vector<unsigned char>();
|
||||
data_state = resource_state::none;
|
||||
@@ -1160,16 +1153,10 @@ opengl_texture::alloc_rendertarget( GLint format, GLint components, int width, i
|
||||
}
|
||||
layers = l;
|
||||
if( layers > 1 ) {
|
||||
target = (
|
||||
samples > 1 ?
|
||||
GL_TEXTURE_2D_MULTISAMPLE_ARRAY :
|
||||
GL_TEXTURE_2D_ARRAY );
|
||||
target = samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY;
|
||||
}
|
||||
else {
|
||||
target = (
|
||||
samples > 1 ?
|
||||
GL_TEXTURE_2D_MULTISAMPLE :
|
||||
GL_TEXTURE_2D );
|
||||
target = samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
|
||||
}
|
||||
create();
|
||||
}
|
||||
@@ -1196,7 +1183,7 @@ opengl_texture::set_filtering() const
|
||||
::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||
|
||||
if( ( Global.AnisotropicFiltering >= 0 )
|
||||
if (Global.AnisotropicFiltering >= 0
|
||||
&& ( GLAD_GL_EXT_texture_filter_anisotropic || GLAD_GL_ARB_texture_filter_anisotropic) ) {
|
||||
// anisotropic filtering
|
||||
::glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, Global.AnisotropicFiltering );
|
||||
@@ -1228,19 +1215,19 @@ opengl_texture::set_filtering() const
|
||||
void
|
||||
opengl_texture::downsize( GLuint const Format ) {
|
||||
|
||||
while( ( data_width > Global.CurrentMaxTextureSize ) || ( data_height > Global.CurrentMaxTextureSize ) ) {
|
||||
while( data_width > Global.CurrentMaxTextureSize || data_height > Global.CurrentMaxTextureSize ) {
|
||||
// scale down the base texture, if it's larger than allowed maximum
|
||||
// NOTE: scaling is uniform along both axes, meaning non-square textures can drop below the maximum
|
||||
// TODO: replace with proper scaling function once we have image middleware in place
|
||||
if( ( data_width < 2 ) || ( data_height < 2 ) ) {
|
||||
if( data_width < 2 || data_height < 2 ) {
|
||||
// can't go any smaller
|
||||
break;
|
||||
}
|
||||
|
||||
WriteLog( "Texture pixelcount exceeds specified limits, downsampling data" );
|
||||
// trim potential odd texture sizes
|
||||
data_width -= ( data_width % 2 );
|
||||
data_height -= ( data_height % 2 );
|
||||
data_width -= data_width % 2;
|
||||
data_height -= data_height % 2;
|
||||
switch( Format ) {
|
||||
|
||||
case GL_RGB: { downsample< glm::tvec3<std::uint8_t> >( data_width, data_height, data.data() ); break; }
|
||||
@@ -1400,9 +1387,9 @@ void
|
||||
texture_manager::delete_textures() {
|
||||
for( auto const &texture : m_textures ) {
|
||||
// usunięcie wszyskich tekstur (bez usuwania struktury)
|
||||
if( ( texture.first->id > 0 )
|
||||
&& ( texture.first->id != -1 ) ) {
|
||||
::glDeleteTextures( 1, &(texture.first->id) );
|
||||
if( texture.first->id > 0
|
||||
&& texture.first->id != -1 ) {
|
||||
::glDeleteTextures( 1, &texture.first->id );
|
||||
}
|
||||
delete texture.first;
|
||||
}
|
||||
@@ -1497,10 +1484,7 @@ texture_manager::find_on_disk( std::string const &Texturename ) {
|
||||
|
||||
// if the first attempt fails, try entire extension list
|
||||
// NOTE: slightly wasteful as it means preferred extension is tested twice, but, eh
|
||||
return (
|
||||
FileExists(
|
||||
filenames,
|
||||
{ ".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex" } ) );
|
||||
return FileExists(filenames, {".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex"});
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
mark_as_used( texture_handle const Texture );
|
||||
// provides direct access to specified texture object
|
||||
opengl_texture &
|
||||
texture( texture_handle const Texture ) const { return *(m_textures[ Texture ].first); }
|
||||
texture( texture_handle const Texture ) const { return *m_textures[Texture].first; }
|
||||
// performs a resource sweep
|
||||
void
|
||||
update();
|
||||
|
||||
@@ -34,7 +34,7 @@ opengl_material::deserialize( cParser &Input, bool const Loadnow ) {
|
||||
result = true; // once would suffice but, eh
|
||||
}
|
||||
|
||||
if( ( path == -1 )
|
||||
if( path == -1
|
||||
&& ( update_on_weather_change || update_on_season_change ) ) {
|
||||
// record current texture path in the material, potentially needed when material is reloaded on environment change
|
||||
// NOTE: we're storing this only for textures that can actually change, to keep the size of path database modest
|
||||
@@ -95,7 +95,7 @@ void opengl_material::finalize(bool Loadnow)
|
||||
if( shader && shader->texture_conf.find( key ) != shader->texture_conf.end() ) {
|
||||
textures[ shader->texture_conf[ key ].id ] = GfxRenderer->Fetch_Texture( value, Loadnow );
|
||||
}
|
||||
else if( ( shader == nullptr )
|
||||
else if( shader == nullptr
|
||||
&& ( lookup = texture_bindings.find( key ) ) != texture_bindings.end() ) {
|
||||
textures[ lookup->second ] = GfxRenderer->Fetch_Texture( value, Loadnow );
|
||||
}
|
||||
@@ -228,8 +228,8 @@ void opengl_material::finalize(bool Loadnow)
|
||||
texture_handle handle = textures[entry.id];
|
||||
// NOTE: texture validation at this stage relies on forced texture load behaviour during its create() call
|
||||
// TODO: move texture id validation to later stage if/when deferred texture loading is implemented
|
||||
if( ( handle )
|
||||
&& ( GfxRenderer->Texture( handle ).get_id() > 0 ) ) {
|
||||
if( handle
|
||||
&& GfxRenderer->Texture(handle).get_id() > 0 ) {
|
||||
GfxRenderer->Texture(handle).set_components_hint((GLint)entry.components);
|
||||
}
|
||||
else {
|
||||
@@ -277,7 +277,7 @@ std::unordered_set<std::string> seasons = {
|
||||
|
||||
bool is_season( std::string const &String ) {
|
||||
|
||||
return ( seasons.find( String ) != seasons.end() );
|
||||
return seasons.find(String) != seasons.end();
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> weather = {
|
||||
@@ -285,7 +285,7 @@ std::unordered_set<std::string> weather = {
|
||||
|
||||
bool is_weather( std::string const &String ) {
|
||||
|
||||
return ( weather.find( String ) != weather.end() );
|
||||
return weather.find(String) != weather.end();
|
||||
}
|
||||
|
||||
// imports member data pair from the config file
|
||||
@@ -295,7 +295,7 @@ opengl_material::deserialize_mapping( cParser &Input, int const Priority, bool c
|
||||
// NOTE: comma can be part of legacy file names, so we don't treat it as a separator here
|
||||
auto key { Input.getToken<std::string>( true, "\n\r\t ;[]" ) };
|
||||
// key can be an actual key or block end
|
||||
if( ( true == key.empty() ) || ( key == "}" ) ) { return false; }
|
||||
if( true == key.empty() || key == "}" ) { return false; }
|
||||
|
||||
if( Priority != -1 ) {
|
||||
// regular attribute processing mode
|
||||
@@ -448,10 +448,7 @@ float opengl_material::get_or_guess_opacity() const {
|
||||
bool
|
||||
opengl_material::is_translucent() const {
|
||||
|
||||
return (
|
||||
textures[ 0 ] != null_handle ?
|
||||
GfxRenderer->Texture( textures[ 0 ] ).get_has_alpha() :
|
||||
false );
|
||||
return textures[0] != null_handle ? GfxRenderer->Texture(textures[0]).get_has_alpha() : false;
|
||||
}
|
||||
|
||||
// create material object from data stored in specified file.
|
||||
@@ -501,8 +498,8 @@ material_manager::create( std::string const &Filename, bool const Loadnow ) {
|
||||
std::make_pair( filename, "make:" ) :
|
||||
find_on_disk( filename ) };
|
||||
|
||||
if( ( false == isgenerated )
|
||||
&& ( false == locator.first.empty() ) ) {
|
||||
if( false == isgenerated
|
||||
&& false == locator.first.empty() ) {
|
||||
// try to parse located file resource
|
||||
cParser materialparser(
|
||||
locator.first + locator.second,
|
||||
@@ -615,10 +612,7 @@ std::pair<std::string, std::string>
|
||||
material_manager::find_on_disk( std::string const &Materialname ) {
|
||||
|
||||
auto const materialname { ToLower( Materialname ) };
|
||||
return (
|
||||
FileExists(
|
||||
{ Global.asCurrentTexturePath + materialname, materialname, paths::textures + materialname },
|
||||
{ ".mat" } ) );
|
||||
return FileExists({Global.asCurrentTexturePath + materialname, materialname, paths::textures + materialname}, {".mat"});
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -19,7 +19,7 @@ struct world_vertex {
|
||||
|
||||
static world_vertex lerp(world_vertex const &a, world_vertex const &b, double factor)
|
||||
{
|
||||
return static_cast<world_vertex>((a * (1.0f - factor)) + (b * factor));
|
||||
return static_cast<world_vertex>(a * (1.0f - factor) + b * factor);
|
||||
}
|
||||
|
||||
// overloads
|
||||
|
||||
Reference in New Issue
Block a user