mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 09:15:01 +01:00
Merge branch 'master' into feat/renderers-cleanup
This commit is contained in:
@@ -88,6 +88,23 @@ void TAnimContainer::SetTranslateAnim(glm::dvec3 vNewTranslate, double fNewSpeed
|
||||
}
|
||||
}
|
||||
|
||||
void TAnimContainer::Finish()
|
||||
{
|
||||
// the next UpdateModel() finds them there and ends the animation as it would have
|
||||
if (fRotateSpeed != 0.0)
|
||||
vRotateAngles = vDesiredAngles;
|
||||
if (fTranslateSpeed != 0.0)
|
||||
vTranslation = vTranslateTo;
|
||||
// and the submodel takes them now: one brought back to its rest is no longer prepared, it'd keep the angles of the jump
|
||||
// before, where the frames of a run leave it a step short of the rest only
|
||||
if (pSubModel) {
|
||||
if (iAnim & 1)
|
||||
pSubModel->SetRotateXYZ(vRotateAngles);
|
||||
if (iAnim & 2)
|
||||
pSubModel->SetTranslate(vTranslation);
|
||||
}
|
||||
}
|
||||
|
||||
// przeliczanie animacji wykonać tylko raz na model
|
||||
void TAnimContainer::UpdateModel() {
|
||||
|
||||
@@ -823,7 +840,7 @@ void TAnimModel::AnimUpdate(double dt)
|
||||
// For non-uniform scale we use the largest axis factor so the bounding sphere
|
||||
// fully contains the scaled model — undersizing would cause incorrect culling.
|
||||
float
|
||||
TAnimModel::radius_() {
|
||||
TAnimModel::radius_() const {
|
||||
|
||||
if( pModel == nullptr ) { return 0.f; }
|
||||
float const max_scale = std::max( { m_scale.x, m_scale.y, m_scale.z } );
|
||||
|
||||
@@ -83,6 +83,8 @@ class TAnimContainer : public std::enable_shared_from_this<TAnimContainer>
|
||||
return pSubModel ? pSubModel->pName : ""; };
|
||||
void SetRotateAnim( glm::vec3 vNewRotateAngles, double fNewRotateSpeed);
|
||||
void SetTranslateAnim( glm::dvec3 vNewTranslate, double fNewSpeed);
|
||||
// the rotation and the shift set brought to their ends at once, for the editor which shows them with the time stopped
|
||||
void Finish();
|
||||
void AnimSetVMD(double fNewSpeed);
|
||||
void PrepareModel();
|
||||
void UpdateModel();
|
||||
@@ -181,7 +183,7 @@ public:
|
||||
void RaAnimate( unsigned int const Framestamp ); // przeliczenie animacji egzemplarza
|
||||
|
||||
// radius() subclass details, calculates node's bounding radius
|
||||
float radius_();
|
||||
float radius_() const override;
|
||||
// serialize() subclass details, sends content of the subclass to provided stream
|
||||
void serialize_( std::ostream &Output ) const;
|
||||
// deserialize() subclass details, restores content of the subclass from provided stream
|
||||
|
||||
@@ -160,15 +160,19 @@ TModelsManager::find_in_databank( std::string const &Name ) {
|
||||
}
|
||||
|
||||
// checks whether specified file exists. returns name of the located file, or empty string.
|
||||
// the file is found in any case, as the scenery made on Windows names it, but the name is given back as asked for: it's the key of
|
||||
// the bank, and TModel3d::LoadFromFile() opens the file as it's named on the disk
|
||||
std::string
|
||||
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 : "";
|
||||
if( false == lookup.empty() ) {
|
||||
return lookup;
|
||||
if( false == FileCased( Name + extension ).empty() ) {
|
||||
return Name;
|
||||
}
|
||||
if( false == FileCased( paths::models + Name + extension ).empty() ) {
|
||||
return paths::models + Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1860,26 +1860,29 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
|
||||
m_filename = name;
|
||||
|
||||
asBinary = name + ".e3d";
|
||||
// the files as they're named on the disk, the name given is in lowercase
|
||||
auto const textfile{FileCased(name + ".t3d")};
|
||||
auto const binaryfile{FileCased(asBinary)};
|
||||
|
||||
// Hirek: Jesli mamy ustawione priorityLoadText3D na yes to wpierw ladujemy t3d
|
||||
if (Global.priorityLoadText3D && FileExists(name + ".t3d"))
|
||||
if (Global.priorityLoadText3D && (false == textfile.empty()))
|
||||
{
|
||||
WriteLog("Forced loading text model \"" + name + ".t3d\"");
|
||||
LoadFromTextFile(name + ".t3d", dynamic);
|
||||
WriteLog("Forced loading text model \"" + textfile + "\"");
|
||||
LoadFromTextFile(textfile, dynamic);
|
||||
if (!dynamic)
|
||||
Init();
|
||||
assign_lod_ranges(Root, name);
|
||||
}
|
||||
else if (FileExists(asBinary))
|
||||
else if (false == binaryfile.empty())
|
||||
{
|
||||
LoadFromBinFile(asBinary, dynamic);
|
||||
LoadFromBinFile(binaryfile, dynamic);
|
||||
asBinary = "";
|
||||
Init();
|
||||
assign_lod_ranges(Root, name);
|
||||
}
|
||||
else if (FileExists(name + ".t3d"))
|
||||
else if (false == textfile.empty())
|
||||
{
|
||||
LoadFromTextFile(name + ".t3d", dynamic);
|
||||
LoadFromTextFile(textfile, dynamic);
|
||||
if (!dynamic)
|
||||
Init();
|
||||
assign_lod_ranges(Root, name);
|
||||
|
||||
@@ -568,7 +568,7 @@ void texture_source::load_STBI()
|
||||
{
|
||||
int x, y, n;
|
||||
stbi_set_flip_vertically_on_load(1);
|
||||
uint8_t *image = stbi_load((name + type).c_str(), &x, &y, &n, 4);
|
||||
uint8_t *image = stbi_load(FileOnDisk(name + type).c_str(), &x, &y, &n, 4);
|
||||
|
||||
if (!image) {
|
||||
data_state = resource_state::failed;
|
||||
@@ -744,7 +744,7 @@ DDSURFACEDESC2 texture_source::deserialize_ddsd(std::istream &s)
|
||||
void
|
||||
texture_source::load_DDS() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::size_t filesize = static_cast<size_t>(file.tellg()); // ios::ate already positioned us at the end of the file
|
||||
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||
|
||||
@@ -864,7 +864,7 @@ texture_source::load_DDS() {
|
||||
if( true == Global.gfx_texture_streaming ) {
|
||||
// the data is read by a worker thread, everything else about the texture is known already
|
||||
request = std::make_shared<texture_request>();
|
||||
request->file = name + type;
|
||||
request->file = FileOnDisk( name + type );
|
||||
request->offset = static_cast<std::size_t>( file.tellg() ) + offset;
|
||||
request->size = datasize;
|
||||
request->flip = flip;
|
||||
@@ -927,7 +927,7 @@ texture_source::load_DDS() {
|
||||
|
||||
void
|
||||
texture_source::load_KTX() {
|
||||
std::ifstream file( name + type, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::size_t filesize = static_cast<size_t>(file.tellg()); // ios::ate already positioned us at the end of the file
|
||||
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||
|
||||
@@ -988,7 +988,7 @@ texture_source::load_KTX() {
|
||||
void
|
||||
texture_source::load_TEX() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
|
||||
char head[ 5 ];
|
||||
file.read( head, 4 );
|
||||
@@ -1035,7 +1035,7 @@ texture_source::load_TEX() {
|
||||
void
|
||||
texture_source::load_TGA() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
|
||||
// Read the header of the TGA, compare it with the known headers for compressed and uncompressed TGAs
|
||||
unsigned char tgaheader[ 18 ];
|
||||
@@ -1755,6 +1755,17 @@ opengl_texture::destroy() {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
opengl_texture::unload_object() {
|
||||
|
||||
// deleted outright: release() would read the texture back from the card with gfx.resource.move, only for it to be dropped
|
||||
if( ( id != invalid_id ) && ( id != 0 ) ) {
|
||||
::glDeleteTextures( 1, &id );
|
||||
}
|
||||
id = invalid_id;
|
||||
is_ready = false;
|
||||
}
|
||||
|
||||
void
|
||||
opengl_texture::on_failed() {
|
||||
|
||||
@@ -1800,6 +1811,48 @@ texture_bank::mark_as_needed( texture_handle const Texture, bool const Near ) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
texture_bank::unload( texture_handle const Texture ) {
|
||||
|
||||
if( ( Texture <= 0 )
|
||||
|| ( Texture >= static_cast<texture_handle>( m_textures.size() ) ) ) {
|
||||
return;
|
||||
}
|
||||
auto const &record { m_textures[ Texture ] };
|
||||
auto &texture { *record.first };
|
||||
if( ( record.second != resource_timestamp() )
|
||||
|| ( true == texture.busy() ) // another thread of the renderer makes it
|
||||
|| ( ( true == texture.resident() ) && ( texture.get_id() == 0 ) ) // failed to load
|
||||
|| ( true == texture.is_static )
|
||||
|| ( true == texture.is_rendertarget )
|
||||
|| ( texture.type == "make:" )
|
||||
|| ( texture.type == "internalsrc:" ) ) {
|
||||
return;
|
||||
}
|
||||
if( ( texture.data_state == resource_state::loading )
|
||||
&& ( texture.request != nullptr ) ) {
|
||||
// read by a worker thread: taken over first, to be dropped with the rest
|
||||
texture.complete_data();
|
||||
if( texture.data_state == resource_state::failed ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto const created { texture.resident() };
|
||||
if( ( false == created )
|
||||
&& ( texture.data_state != resource_state::good ) ) {
|
||||
// nothing read nor made, e.g. the textures of a material asked for without loading
|
||||
return;
|
||||
}
|
||||
if( true == created ) {
|
||||
texture.unload_object();
|
||||
// the released names can be given to new textures, the unit cache can't trust them
|
||||
released();
|
||||
}
|
||||
texture.data = std::vector<unsigned char>();
|
||||
texture.data_state = resource_state::none;
|
||||
texture.reload_on_use = true;
|
||||
}
|
||||
|
||||
// releases gl textures of vehicles not needed nor drawn for a while
|
||||
void
|
||||
texture_bank::release_unneeded() {
|
||||
|
||||
@@ -92,6 +92,11 @@ struct texture_source : public ITexture {
|
||||
// the object of the renderer goes, with the bank of the textures
|
||||
virtual void
|
||||
destroy() = 0;
|
||||
// the object of the renderer let go of with no copy of its data kept, the texture read from its file again when it's used
|
||||
// (texture_bank::unload())
|
||||
virtual void
|
||||
unload_object() {
|
||||
release(); }
|
||||
// another thread of the renderer works on the texture (makes its object from the data, which it reads too): what it holds isn't for
|
||||
// the other threads to read until it's done
|
||||
virtual bool
|
||||
@@ -188,6 +193,8 @@ struct opengl_texture : public texture_source {
|
||||
return id != invalid_id; }
|
||||
void
|
||||
destroy() override;
|
||||
void
|
||||
unload_object() override;
|
||||
|
||||
// members
|
||||
static constexpr GLuint invalid_id { std::numeric_limits<GLuint>::max() }; // id value of texture without GL resource
|
||||
@@ -245,6 +252,10 @@ public:
|
||||
// releases gl textures of vehicles not needed nor drawn for a while
|
||||
void
|
||||
release_unneeded();
|
||||
// takes a texture the scene has never drawn out of both the gfx card and the memory, e.g. the image of a picker scrolled
|
||||
// past, or one read and not made yet; it's read again when it's used. textures the scene draws are left to the resource sweep
|
||||
void
|
||||
unload( texture_handle const Texture );
|
||||
// debug performance string
|
||||
std::string
|
||||
info() const;
|
||||
|
||||
@@ -66,6 +66,13 @@ struct opengl_material : public IMaterial {
|
||||
{
|
||||
return textures[slot];
|
||||
}
|
||||
virtual std::vector<texture_handle> GetAllTextures() const override
|
||||
{
|
||||
std::vector<texture_handle> all(textures.begin(), textures.end());
|
||||
for (auto const &variant : texture_variants)
|
||||
all.insert(all.end(), variant.begin(), variant.end());
|
||||
return all;
|
||||
}
|
||||
// returns texture set to use for model instance identified by provided variant id
|
||||
texture_set const &GetTextures(std::uint32_t const Variant) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user