Refactor SnesColor class to use constexpr for constructors and methods, improving compile-time evaluation and performance; include <array> for better type handling.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <snes.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -37,24 +38,28 @@ constexpr float kColorByteMaxF = 255.f;
|
||||
*/
|
||||
class SnesColor {
|
||||
public:
|
||||
SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0), rom_color_({0, 0, 0}) {}
|
||||
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
||||
constexpr SnesColor()
|
||||
: rgb_({0.f, 0.f, 0.f, 0.f}), snes_(0), rom_color_({0, 0, 0}) {}
|
||||
|
||||
constexpr explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
||||
snes_color color;
|
||||
color.red = val.x / kColorByteMax;
|
||||
color.green = val.y / kColorByteMax;
|
||||
color.blue = val.z / kColorByteMax;
|
||||
snes_ = ConvertRgbToSnes(color);
|
||||
}
|
||||
explicit SnesColor(const uint16_t val) : snes_(val) {
|
||||
|
||||
constexpr explicit SnesColor(const uint16_t val) : snes_(val) {
|
||||
snes_color color = ConvertSnesToRgb(val);
|
||||
rgb_ = ImVec4(color.red, color.green, color.blue, 0.f);
|
||||
}
|
||||
|
||||
explicit SnesColor(const snes_color val)
|
||||
: rgb_(val.red, val.green, val.blue, kColorByteMaxF),
|
||||
snes_(ConvertRgbToSnes(val)),
|
||||
rom_color_(val) {}
|
||||
|
||||
SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
constexpr SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
rgb_ = ImVec4(r, g, b, kColorByteMaxF);
|
||||
snes_color color;
|
||||
color.red = r;
|
||||
@@ -64,8 +69,6 @@ class SnesColor {
|
||||
rom_color_ = color;
|
||||
}
|
||||
|
||||
ImVec4 rgb() const { return rgb_; }
|
||||
|
||||
void set_rgb(const ImVec4 val) {
|
||||
rgb_.x = val.x / kColorByteMax;
|
||||
rgb_.y = val.y / kColorByteMax;
|
||||
@@ -78,20 +81,20 @@ class SnesColor {
|
||||
snes_ = ConvertRgbToSnes(color);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
void set_snes(uint16_t val) {
|
||||
constexpr void set_snes(uint16_t val) {
|
||||
snes_ = val;
|
||||
snes_color col = ConvertSnesToRgb(val);
|
||||
rgb_ = ImVec4(col.red, col.green, col.blue, 0.f);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
snes_color rom_color() const { return rom_color_; }
|
||||
uint16_t snes() const { return snes_; }
|
||||
bool is_modified() const { return modified; }
|
||||
bool is_transparent() const { return transparent; }
|
||||
void set_transparent(bool t) { transparent = t; }
|
||||
void set_modified(bool m) { modified = m; }
|
||||
constexpr ImVec4 rgb() const { return rgb_; }
|
||||
constexpr snes_color rom_color() const { return rom_color_; }
|
||||
constexpr uint16_t snes() const { return snes_; }
|
||||
constexpr bool is_modified() const { return modified; }
|
||||
constexpr bool is_transparent() const { return transparent; }
|
||||
constexpr void set_transparent(bool t) { transparent = t; }
|
||||
constexpr void set_modified(bool m) { modified = m; }
|
||||
|
||||
private:
|
||||
ImVec4 rgb_;
|
||||
|
||||
Reference in New Issue
Block a user