I am making a c++ game engine, in my class Renderer I deal with colors, now with each…
- User
I am making a c++ game engine, in my class Renderer I deal with colors, now with each part of the "Color": for example like this: void SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a); Should I use an struct Color instead? What are the pro's and con's to use an struct compared to what I already have? Should I make the switch?
- Assistant
Using a
structto represent a color in your game engine can be a beneficial design choice. Here's a breakdown of the pros and cons of switching to a : - User
I am trying to use it like this but it is giving me errors because the values are private: SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
In the case of struct, what is the common or correct way to do it, using setter & getters or making the variables public?
- Assistant
- User
ok I will go with the struct and public members, now how is the usual naming convention for these variables? Since I have everything public with UpperCase, should I do the same with the structs or the naming convention here is different?
- Assistant
In C++, naming conventions can vary significantly between codebases, but certain common practices could be followed. For structures, particularly ones that serve as simple data containers, member variables typically use lowercase or snake_case to differentiate them from class member variables, which might use an underscore prefix, camelCase, or mCamelCase (with a leading 'm' for "member"). That being said, consistency across your codebase is key.
- User
If I plan to support HSV in the future, should I plan on making a new struct or could I re-use this Color struct to support it?
- Assistant
Supporting HSV (Hue, Saturation, Value) color representation can require a different approach compared to the traditional RGBA representation. While both RGBA and HSV describe colors, they do so using different paradigms. RGBA is particularly useful for digital screens where colors are displayed with varying intensities of red, green, and blue light. HSV, on the other hand, is often used for color selection tools and in situations where it's more intuitive to think about colors in terms of hue or colorfulness.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.