From 01f173f2374a335e7ee3ec23167b89859d64e164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Leclaire-Fournier?= Date: Mon, 22 Jan 2024 21:56:44 -0500 Subject: [PATCH] Optimise l'encodage de coleur --- GPA675Lab1GOL/GOLTeamH.cpp | 27 +++++++++------------------ GPA675Lab1GOL/GOLTeamH.h | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/GPA675Lab1GOL/GOLTeamH.cpp b/GPA675Lab1GOL/GOLTeamH.cpp index da4bd47..3c8caea 100644 --- a/GPA675Lab1GOL/GOLTeamH.cpp +++ b/GPA675Lab1GOL/GOLTeamH.cpp @@ -1,7 +1,7 @@ #include "GOLTeamH.h" GOLTeamH::GOLTeamH() - : mParsedRule{}, mDeadColorEncoded{}, mAliveColorEncoded{} + : mParsedRule{}, mColorEncoded{} { } //! \brief Accesseurs retournant des informations générales sur la @@ -351,18 +351,14 @@ bool GOLTeamH::setFromPattern(std::string const& pattern) //! \param color La nouvelle couleur de l'état. void GOLTeamH::setSolidColor(State state, Color const& color) { - if (state == State::alive) { + if (state == State::alive) mAliveColor = color; - mAliveColorEncoded |= mAliveColor.red << 16; - mAliveColorEncoded |= mAliveColor.green << 8; - mAliveColorEncoded |= mAliveColor.blue; - } - else { + else mDeadColor = color; - mDeadColorEncoded |= mDeadColor.red << 16; - mDeadColorEncoded |= mDeadColor.green << 8; - mDeadColorEncoded |= mDeadColor.blue; - } + + mColorEncoded |= ((static_cast(mAliveColor.red) << 16) << 32 * static_cast(state)); + mColorEncoded |= ((static_cast(mAliveColor.green) << 8) << 32 * static_cast(state)); + mColorEncoded |= (static_cast(mAliveColor.blue) << 32 * static_cast(state)); } @@ -510,17 +506,12 @@ void GOLTeamH::updateImage(uint32_t* buffer, size_t buffer_size) const *s_ptr &= 0; // Clear *s_ptr |= MAX_ALPHA << 24; // Alpha = 255 - - if (var) { - *s_ptr |= mAliveColorEncoded; - } - else { - *s_ptr |= mDeadColorEncoded; - } + *s_ptr |= mColorEncoded >> (32 * var); s_ptr++; ptrGrid++; } + s_ptr = nullptr; ptrGrid = nullptr; } diff --git a/GPA675Lab1GOL/GOLTeamH.h b/GPA675Lab1GOL/GOLTeamH.h index 7c406c1..62857fe 100644 --- a/GPA675Lab1GOL/GOLTeamH.h +++ b/GPA675Lab1GOL/GOLTeamH.h @@ -58,7 +58,7 @@ private: GridTeamH mData; Color mDeadColor, mAliveColor; - uint32_t mDeadColorEncoded, mAliveColorEncoded; + uint64_t mColorEncoded; // Fonctions utilisées à l'interne. std::optional convertCharToNumber(const char c);