-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use std::uint8_t in place of int to save some precious bytes --------- Co-authored-by: pongo1231 <pongo1999712@gmail.com>
- Loading branch information
Showing
2 changed files
with
25 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
struct Color | ||
{ | ||
unsigned int R, G, B, A; | ||
std::uint8_t R, G, B, A; | ||
|
||
std::uint32_t Get() const | ||
{ | ||
return A << 24 | R << 16 | G << 8 | B; | ||
} | ||
}; | ||
|
||
// Returns a random RGBA value without a random alpha: 255 or max. | ||
inline Color GetRandomColorRGB(unsigned int min = 0, unsigned int max = 255) | ||
inline Color GetRandomColorRGB(std::uint8_t min = 0, std::uint8_t max = 255) | ||
{ | ||
return { | ||
(unsigned int)g_Random.GetRandomInt(min, max), // R | ||
(unsigned int)g_Random.GetRandomInt(min, max), // G | ||
(unsigned int)g_Random.GetRandomInt(min, max), // B | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // R | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // G | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // B | ||
255 // A | ||
}; | ||
} | ||
|
||
// Returns a random RGBA value with a random alpha. | ||
inline Color GetRandomColorRGBA(unsigned int min = 0, unsigned int max = 255) | ||
inline Color GetRandomColorRGBA(std::uint8_t min = 0, std::uint8_t max = 255) | ||
{ | ||
return { | ||
(unsigned int)g_Random.GetRandomInt(min, max), // R | ||
(unsigned int)g_Random.GetRandomInt(min, max), // G | ||
(unsigned int)g_Random.GetRandomInt(min, max), // B | ||
(unsigned int)g_Random.GetRandomInt(min, max) // A | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // R | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // G | ||
(std::uint8_t)g_Random.GetRandomInt(min, max), // B | ||
(std::uint8_t)g_Random.GetRandomInt(min, max) // A | ||
}; | ||
} |