TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 222 forks source link

Small Transformation Stack optimization #13

Closed enbyted closed 9 years ago

enbyted commented 9 years ago

Instead of using vector's back() in push methoh in renderer2d, you could do:

    void push(const maths::mat4& matrix, bool override = false)
    {
        if (override) {
            m_TransformationStack.push_back(matrix);
        } else {
            maths::mat4* result = m_TransformationBack * matrix;
            m_TransformationStack.push_back(result);
            m_TransformationBack = result;
        }
    }

I haven't tested it, but it should be a bit faster

holgk commented 9 years ago

Don't forget to change m_TransformationBack for the override part:

if (override) {
            m_TransformationStack.push_back(matrix);
            m_TransformationBack = matrix;
        } else {
            maths::mat4* result = m_TransformationBack * matrix;
            m_TransformationStack.push_back(result);
            m_TransformationBack = result;
        }
TheCherno commented 9 years ago

Keep in mind that the transformation stack vector does not hold pointers, so this isn't exactly going to work. Please open another issue if you think I am misunderstanding you. :)