diff --git a/src/graphics/moving_texture.cpp b/src/graphics/moving_texture.cpp index 1ecca8f18..dbd3ca04d 100644 --- a/src/graphics/moving_texture.cpp +++ b/src/graphics/moving_texture.cpp @@ -33,6 +33,7 @@ MovingTexture::MovingTexture(core::matrix4 *matrix, const XMLNode &node) m_x = 0.0f; m_y = 0.0f; m_count = 0.0f; + m_sp_tm = NULL; if (m_matrix) { @@ -49,8 +50,6 @@ MovingTexture::MovingTexture(core::matrix4 *matrix, const XMLNode &node) node.get("dt", &m_dt); node.get("animByStep", &m_isAnimatedByStep); - m_sp_tm[0].reset(new float(0.0f)); - m_sp_tm[1].reset(new float(0.0f)); } // MovingTexture //----------------------------------------------------------------------------- @@ -71,8 +70,8 @@ MovingTexture::MovingTexture(core::matrix4 *matrix, float dx, float dy) core::vector3df v = m_matrix->getTranslation(); m_x = v.X; m_y = v.Y; - m_sp_tm[0].reset(new float(0.0f)); - m_sp_tm[1].reset(new float(0.0f)); + m_count = 0.0f; + m_sp_tm = NULL; } // MovingTexture //----------------------------------------------------------------------------- @@ -85,9 +84,9 @@ MovingTexture::MovingTexture(float dx, float dy) m_dy = dy; m_x = 0; m_y = 0; + m_count = 0.0f; m_matrix = NULL; - m_sp_tm[0].reset(new float(0.0f)); - m_sp_tm[1].reset(new float(0.0f)); + m_sp_tm = NULL; } // MovingTexture //----------------------------------------------------------------------------- @@ -103,12 +102,15 @@ MovingTexture::~MovingTexture() void MovingTexture::reset() { m_x = m_y = 0; - *m_sp_tm[0] = 0; - *m_sp_tm[1] = 0; if (m_matrix) { m_matrix->setTextureTranslate(m_x, m_y); } + else if (m_sp_tm) + { + m_sp_tm[0] = 0.0f; + m_sp_tm[1] = 0.0f; + } } // reset //----------------------------------------------------------------------------- @@ -134,10 +136,10 @@ void MovingTexture::update(float dt) { m_matrix->setTextureTranslate(m_x, m_y); } - else + else if (m_sp_tm) { - *m_sp_tm[0] = m_x; - *m_sp_tm[1] = m_y; + m_sp_tm[0] = m_x; + m_sp_tm[1] = m_y; } } } @@ -151,10 +153,10 @@ void MovingTexture::update(float dt) { m_matrix->setTextureTranslate(m_x, m_y); } - else + else if (m_sp_tm) { - *m_sp_tm[0] = m_x; - *m_sp_tm[1] = m_y; + m_sp_tm[0] = m_x; + m_sp_tm[1] = m_y; } } } // update diff --git a/src/graphics/moving_texture.hpp b/src/graphics/moving_texture.hpp index afe8cdb9e..782d3048a 100644 --- a/src/graphics/moving_texture.hpp +++ b/src/graphics/moving_texture.hpp @@ -20,8 +20,6 @@ #define MOVING_TEXTURE_HPP #include "utils/no_copy.hpp" -#include <array> -#include <memory> #include <string> #include <matrix4.h> using namespace irr; @@ -49,7 +47,7 @@ private: core::matrix4 *m_matrix; // For sp - std::array<std::shared_ptr<float>, 2> m_sp_tm; + float* m_sp_tm; public: MovingTexture(core::matrix4 *matrix, const XMLNode &node); @@ -61,7 +59,7 @@ public: void setSpeed(float dx, float dy) {m_dx = dx; m_dy = dy;} /** Sets the texture matrix. */ void setTextureMatrix(core::matrix4 *matrix) {m_matrix=matrix;} - std::array<std::shared_ptr<float>, 2> getSPTM() const { return m_sp_tm; } + void setSPTM(float* sp_tm) { m_sp_tm = sp_tm; } virtual void update (float dt); virtual void reset (); } diff --git a/src/graphics/referee.cpp b/src/graphics/referee.cpp index fbb75f59c..9a0f7002b 100644 --- a/src/graphics/referee.cpp +++ b/src/graphics/referee.cpp @@ -248,9 +248,7 @@ void Referee::selectReadySetGo(int rsg) SP::SPMeshNode* spmn = dynamic_cast<SP::SPMeshNode*>(m_scene_node); if (spmn) { - spmn->setTextureMatrix(m_st_traffic_buffer, - {{ std::make_shared<float>(0.0f), - std::make_shared<float>(rsg * 0.333f) }}); + spmn->setTextureMatrix(m_st_traffic_buffer, {{ 0.0f, rsg * 0.333f }}); } else { diff --git a/src/graphics/slip_stream.cpp b/src/graphics/slip_stream.cpp index aebc1d223..6acdb4b1f 100644 --- a/src/graphics/slip_stream.cpp +++ b/src/graphics/slip_stream.cpp @@ -59,7 +59,7 @@ SlipStream::SlipStream(AbstractKart* kart) : MovingTexture(0, 0), m_kart(kart) m_node->setVisible(false); SP::SPMeshNode* spmn = dynamic_cast<SP::SPMeshNode*>(m_node); assert(spmn); - spmn->setTextureMatrix(0, getSPTM()); + setSPTM(spmn->getTextureMatrix(0).data()); } #endif diff --git a/src/graphics/sp/sp_base.cpp b/src/graphics/sp/sp_base.cpp index 0daec9cf6..620e900df 100644 --- a/src/graphics/sp/sp_base.cpp +++ b/src/graphics/sp/sp_base.cpp @@ -1260,16 +1260,9 @@ void addObject(SPMeshNode* node) float hue = node->getRenderInfo(m) ? node->getRenderInfo(m)->getHue() : 0.0f; - float tm_x = 0.0f; - float tm_y = 0.0f; - const auto& ret = node->getTextureMatrix(m); - if (ret[0] && ret[1]) - { - tm_x = *ret[0]; - tm_y = *ret[1]; - } SPInstancedData id = SPInstancedData - (node->getAbsoluteTransformation(), tm_x, tm_y, hue, + (node->getAbsoluteTransformation(), node->getTextureMatrix(m)[0], + node->getTextureMatrix(m)[1], hue, (short)node->getSkinningOffset()); for (int dc_type = 0; dc_type < (g_handle_shadow ? 5 : 1); dc_type++) diff --git a/src/graphics/sp/sp_mesh_node.cpp b/src/graphics/sp/sp_mesh_node.cpp index aaa9d8c4d..1392ad5a6 100644 --- a/src/graphics/sp/sp_mesh_node.cpp +++ b/src/graphics/sp/sp_mesh_node.cpp @@ -88,7 +88,8 @@ void SPMeshNode::setMesh(irr::scene::IAnimatedMesh* mesh) cleanRenderInfo(); if (m_mesh) { - m_texture_matrices.resize(m_mesh->getMeshBufferCount()); + m_texture_matrices.resize(m_mesh->getMeshBufferCount(), + {{ 0.0f, 0.0f }}); if (!m_mesh->isStatic()) { #ifndef SERVER_ONLY diff --git a/src/graphics/sp/sp_mesh_node.hpp b/src/graphics/sp/sp_mesh_node.hpp index f68bb922d..f039ed3a1 100644 --- a/src/graphics/sp/sp_mesh_node.hpp +++ b/src/graphics/sp/sp_mesh_node.hpp @@ -56,7 +56,7 @@ private: video::SColorf m_glow_color; - std::vector<std::array<std::shared_ptr<float>, 2> > m_texture_matrices; + std::vector<std::array<float, 2> > m_texture_matrices; // ------------------------------------------------------------------------ void cleanRenderInfo(); @@ -143,14 +143,13 @@ public: m_glow_color.b == 0.0f); } // ------------------------------------------------------------------------ - std::array<std::shared_ptr<float>, 2>& getTextureMatrix(unsigned mb_id) + std::array<float, 2>& getTextureMatrix(unsigned mb_id) { assert(mb_id < m_texture_matrices.size()); return m_texture_matrices[mb_id]; } // ------------------------------------------------------------------------ - void setTextureMatrix(unsigned mb_id, - std::array<std::shared_ptr<float>, 2> tm) + void setTextureMatrix(unsigned mb_id, const std::array<float, 2>& tm) { assert(mb_id < m_texture_matrices.size()); m_texture_matrices[mb_id] = tm; diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index b6ff453d6..05f92794c 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -1135,13 +1135,8 @@ void KartModel::update(float dt, float distance, float steer, float speed, for (unsigned i = 0; i < spmn->getSPM()->getMeshBufferCount(); i++) { auto& ret = spmn->getTextureMatrix(i); - if (!ret[0] || !ret[1]) - { - ret[0].reset(new float); - ret[1].reset(new float); - } - *ret[0] = obj.m_texture_cur_offset.X; - *ret[1] = obj.m_texture_cur_offset.Y; + ret[0] = obj.m_texture_cur_offset.X; + ret[1] = obj.m_texture_cur_offset.Y; } } else diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 6dca271bb..d8b333819 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1480,7 +1480,7 @@ void Track::handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml) spmb->enableTextureMatrix(j); MovingTexture* mt = new MovingTexture(NULL, *texture_node); - spmn->setTextureMatrix(i, mt->getSPTM()); + mt->setSPTM(spmn->getTextureMatrix(i).data()); m_animated_textures.push_back(mt); // For spm only 1 texture matrix per mesh buffer is // possible