mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 02:49:19 +02:00
Merge branch 'master' into feat/modern-editor
This commit is contained in:
@@ -646,11 +646,11 @@ void TAnimModel::on_season_update() {
|
||||
|
||||
void TAnimModel::RaPrepare()
|
||||
{ // ustawia światła i animacje we wzorcu modelu przed renderowaniem egzemplarza
|
||||
bool state; // stan światła
|
||||
if (Global.UpdateMaterials)
|
||||
on_season_update();
|
||||
for (int i = 0; i < iNumLights; ++i)
|
||||
{
|
||||
bool state{ false }; // stan światła
|
||||
auto const lightmode { static_cast<int>( std::abs( lsLights[ i ] ) ) };
|
||||
switch( lightmode ) {
|
||||
case ls_On:
|
||||
|
||||
@@ -17,6 +17,7 @@ Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
||||
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/utilities.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "utilities/Timer.h"
|
||||
#include "simulation/simulation.h"
|
||||
@@ -55,8 +56,6 @@ TSubModel::~TSubModel()
|
||||
SafeDelete(Child);
|
||||
delete fMatrix; // własny transform trzeba usunąć (zawsze jeden)
|
||||
}
|
||||
delete[] smLetter; // używany tylko roboczo dla TP_TEXT, do przyspieszenia
|
||||
// wyświetlania
|
||||
};
|
||||
|
||||
void TSubModel::Name_Material(std::string const &Name)
|
||||
@@ -892,6 +891,67 @@ void TSubModel::InitialRotate(bool doit)
|
||||
Next->InitialRotate(doit);
|
||||
};
|
||||
|
||||
// text display (TP_TEXT): returns sub-models of the characters to draw for provided text, in drawing order.
|
||||
// a character is matched with the first character of a child sub-model name. both the text and the names can be
|
||||
// encoded either in utf-8 or in windows-1250, so the legacy (ansi) scenery and model files work along the utf-8 ones
|
||||
std::vector<TSubModel *> const &TSubModel::text_letters(std::string const &Text)
|
||||
{
|
||||
// the sequence is prepared once for each text the display shows. the texts of the model instances don't change,
|
||||
// so drawing a display afterwards costs a single lookup, however many instances and passes take turns
|
||||
auto const prepared{m_textlayouts.find(Text)};
|
||||
if (prepared != m_textlayouts.end())
|
||||
{
|
||||
return prepared->second;
|
||||
}
|
||||
|
||||
std::u32string characters;
|
||||
if (false == m_lettersready)
|
||||
{
|
||||
for (auto *letter = Child; letter != nullptr; letter = letter->Next)
|
||||
{
|
||||
if (letter->pName.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (false == utf8_to_utf32(letter->pName, characters))
|
||||
{
|
||||
win1250_to_utf32(letter->pName, characters);
|
||||
}
|
||||
if (characters.front() != 0)
|
||||
{
|
||||
m_letters[characters.front()] = letter;
|
||||
}
|
||||
}
|
||||
m_lettersready = true;
|
||||
}
|
||||
|
||||
// the text is taken for utf-8 if it's valid as such, and for windows-1250 otherwise. a short ansi text can pass
|
||||
// for utf-8 by accident (two upper case accented letters in a row are enough for this to happen),
|
||||
// so if both readings are possible the one which finds more of its characters in the model wins
|
||||
auto const known = [this](std::u32string const &Characters) {
|
||||
return std::ranges::count_if(Characters, [this](char32_t const Character) { return m_letters.contains(Character); });
|
||||
};
|
||||
std::u32string ansi;
|
||||
win1250_to_utf32(Text, ansi);
|
||||
if (false == utf8_to_utf32(Text, characters) || known(ansi) > known(characters))
|
||||
{
|
||||
characters = ansi;
|
||||
}
|
||||
|
||||
auto &textletters{m_textlayouts[Text]};
|
||||
// NOTE: the first character of the text isn't displayed. the displays always worked this way, and the existing
|
||||
// content relies on it
|
||||
for (std::size_t idx = 1; idx < characters.size(); ++idx)
|
||||
{
|
||||
auto const lookup{m_letters.find(characters[idx])};
|
||||
if (lookup != m_letters.end())
|
||||
{
|
||||
textletters.emplace_back(lookup->second);
|
||||
}
|
||||
}
|
||||
return textletters;
|
||||
}
|
||||
|
||||
void TSubModel::ChildAdd(TSubModel *SubModel)
|
||||
{ // dodanie submodelu potemnego (uzależnionego)
|
||||
// Ra: zmiana kolejności, żeby kolejne móc renderować po aktualnym (było
|
||||
@@ -1469,7 +1529,9 @@ void TSubModel::ParentMatrix(float4x4 *m) const
|
||||
|
||||
void TSubModel::ReplaceMatrix(const glm::mat4 &mat)
|
||||
{
|
||||
*fMatrix = float4x4(glm::value_ptr(mat));
|
||||
for (int column = 0; column < 4; ++column)
|
||||
for (int row = 0; row < 4; ++row)
|
||||
fMatrix->e[column * 4 + row] = mat[column][row];
|
||||
}
|
||||
|
||||
void TSubModel::ReplaceMaterial(const std::string &name)
|
||||
@@ -1558,13 +1620,8 @@ TSubModel *TModel3d::GetFromName(std::string const &Name) const
|
||||
{ // wyszukanie submodelu po nazwie
|
||||
if (Name.empty())
|
||||
return Root; // potrzebne do terenu z E3D
|
||||
if (iFlags & 0x0200) // wczytany z pliku tekstowego, wyszukiwanie rekurencyjne
|
||||
return Root ? Root->GetFromName(Name) : nullptr;
|
||||
else // wczytano z pliku binarnego, można wyszukać iteracyjnie
|
||||
{
|
||||
// for (int i=0;i<iSubModelsCount;++i)
|
||||
return Root ? Root->GetFromName(Name) : nullptr;
|
||||
}
|
||||
// both text and binary models are searched recursively
|
||||
return Root ? Root->GetFromName(Name) : nullptr;
|
||||
};
|
||||
|
||||
// returns submodels which scenery instances of the model refer to by name, locating them on first use
|
||||
|
||||
@@ -156,7 +156,10 @@ public: // chwilowo
|
||||
std::uintptr_t iAnimOwner{ 0 }; // roboczy numer egzemplarza, który ustawił animację
|
||||
TAnimType b_aAnim{ TAnimType::at_None }; // kody animacji oddzielnie, bo zerowane
|
||||
std::shared_ptr<float4x4> mAnimMatrix; // macierz do animacji kwaternionowych
|
||||
TSubModel **smLetter{ nullptr }; // wskaźnik na tablicę submdeli do generoania tekstu (docelowo zapisać do E3D)
|
||||
// text display (TP_TEXT) data, filled on first use
|
||||
std::unordered_map<char32_t, TSubModel *> m_letters; // sub-models of the available characters, by unicode code point
|
||||
bool m_lettersready { false }; // whether the character lookup was built yet
|
||||
std::unordered_map<std::string, std::vector<TSubModel *>> m_textlayouts; // sub-models of consecutive characters, for each text shown
|
||||
TSubModel *Parent{ nullptr }; // nadrzędny, np. do wymnażania macierzy
|
||||
int iVisible { 1 }; // roboczy stan widoczności
|
||||
float fVisible { 1.f }; // visibility level
|
||||
@@ -202,6 +205,8 @@ public:
|
||||
void SetTranslate(float3 vNewTransVector);
|
||||
void SetRotateIK1(float3 vNewAngles);
|
||||
TSubModel * GetFromName( std::string const &search, bool i = true );
|
||||
// text display (TP_TEXT): returns sub-models of the characters to draw for provided text, in drawing order
|
||||
std::vector<TSubModel *> const & text_letters( std::string const &Text );
|
||||
inline float4x4 * GetMatrix() { return fMatrix; };
|
||||
inline float4x4 const * GetMatrix() const { return fMatrix; };
|
||||
// returns offset vector from root
|
||||
|
||||
@@ -524,12 +524,12 @@ opengl_texture::make_from_memory(size_t width, size_t height, const uint8_t *raw
|
||||
|
||||
void opengl_texture::update_from_memory(size_t width, size_t height, const uint8_t *raw)
|
||||
{
|
||||
if (id != (GLuint)-1 && (width != data_width || height != data_height || GL_SRGB8_ALPHA8 != data_format || GL_RGBA != data_components))
|
||||
if (id != invalid_id && (width != data_width || height != data_height || GL_SRGB8_ALPHA8 != data_format || GL_RGBA != data_components))
|
||||
{
|
||||
glDeleteTextures(1, &id);
|
||||
id = (GLuint)-1;
|
||||
id = invalid_id;
|
||||
}
|
||||
if (id == (GLuint)-1)
|
||||
if (id == invalid_id)
|
||||
{
|
||||
data_width = width;
|
||||
data_height = height;
|
||||
|
||||
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
#include <limits>
|
||||
#include "winheaders.h"
|
||||
#include <string>
|
||||
#include "model/ResourceManager.h"
|
||||
@@ -86,7 +87,8 @@ struct opengl_texture : public ITexture {
|
||||
virtual void update_from_memory(size_t width, size_t height, const uint8_t *data) override;
|
||||
|
||||
// members
|
||||
GLuint id{ (GLuint)-1 }; // associated GL resource
|
||||
static constexpr GLuint invalid_id { std::numeric_limits<GLuint>::max() }; // id value of texture without GL resource
|
||||
GLuint id{ invalid_id }; // associated GL resource
|
||||
bool has_alpha{ false }; // indicates the texture has alpha channel
|
||||
bool is_ready{ false }; // indicates the texture was processed and is ready for use
|
||||
std::string traits; // requested texture attributes: wrapping modes etc
|
||||
|
||||
Reference in New Issue
Block a user