Conversation
Notices
-
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Sunday, 27-Oct-2024 21:22:00 JST hazlin no plap pirate I am wonder how best to translate this into c++.
A separate map for each column?- :ihavenomouth: likes this.
-
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Sunday, 27-Oct-2024 21:22:03 JST karna :flipflop: :buffsuki: @hazlin idk about c++ but assuming theres enough overlap with c, you could make an enum of possible colors, which acts as index into an array of structs containing your resistor info
:ihavenomouth: likes this. -
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:47 JST karna :flipflop: :buffsuki: @hazlin ive never used sfml (also I read that acronym as shit fuck my life every time I see it...), is the setup that complicated?
:ihavenomouth: likes this. -
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:48 JST hazlin no plap pirate @karna SFML can do all the font stuff for me xD I am just having fun, trying to do everything from a sprite sheet. Trying to keep things very low level for this first attempt. -
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:48 JST hazlin no plap pirate @karna I would also be doing this in plain C, as I have that working... but it was such a pain to get SFML working with C, I worry about other people being able to use it xD -
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:49 JST hazlin no plap pirate @karna Also, c++ did not like the utf-8 characters xD I read about it some, and tried to work around it, but it was not having it xD
A step I skipped was doing the tokenization inside of c++, but I'm not quite sure how to do that. Examples I found of such things, focus on using a single character to split things. But, that isn't quite what I need.
I need to digest a string, and consume either the next character, or the next group of characters if they match an entry in a list.... a problem for another time?
Thank you again for the help :D -
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:49 JST karna :flipflop: :buffsuki: @hazlin > utf8
getting out of my depth already..
> string tokenization
I'm sure you could write a string parsing and tokenizing function but I'm not sure what standard library tools are available in c++ that might make that easier if you dont want to roll your own -
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:50 JST karna :flipflop: :buffsuki: @hazlin Oh nice. Glad its working
-
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:50 JST hazlin no plap pirate @karna
The explanation for the, verbose symbol names, is that my, "No Game Engine" workflow, has things passing into and out of inkscape/svg_format.
And, it was fighting me quite a bit. So, for now, everything is just alphabet ascii strings. -
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:51 JST hazlin no plap pirate @karna
> at least not without compiler extensions
Maybe the IDE is automagically handling the for me? -
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:52 JST karna :flipflop: :buffsuki: @hazlin no problemo. fwiw, yhe term for this sort of initialization of structs is "designated initializer". I did a little digging and saw that c++ is a little more restrictive than c when it comes to how you can use these (see https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers ). Also you probably dont need to typedef structs in c++ either
Note: out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays are all supported in the C programming language, but are not allowed in C++.
-
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:52 JST karna :flipflop: :buffsuki: @hazlin And the temporary structs being used in the array directly uses "compound literals" which may not be supported in CPP at all (see https://en.cppreference.com/w/c/language/compound_literal ), at least not without compiler extensions
In conversation permalink Attachments
-
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:52 JST hazlin no plap pirate @karna Worry not, it appears to work just fine :D In conversation permalink Attachments
-
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:53 JST karna :flipflop: :buffsuki: @hazlin For the sake of completeness, this is what I meant. Since I don't think your strings need to be dynamically handled, you could do something like this in C. in C++, your mileage may vary, idk what initializers are supported..
#include <stdio.h> enum { RES_BLACK, RES_BROWN, RES_RED, RES_ORANGE, RES_YELLOW, RES_GREEN, RES_BLUE, RES_PURPLE, RES_GREY, RES_WHITE, RES_GOLD, RES_SILVER, RES_NO_COLOR, RES_NUM_COLORS }; typedef struct ResInfo { char number; unsigned int rgb[3]; char *tol; char *mag; } ResInfo; ResInfo res_info[] = { [RES_BLACK] = (ResInfo) {.number = '0', .rgb = {0, 0, 0}, .tol = "_.__%", .mag = "Ω"}, [RES_BROWN] = (ResInfo) {.number = '1', .rgb = {200, 113, 55}, .tol = "1.00%", .mag = "0Ω"}, [RES_RED] = (ResInfo) {.number = '2', .rgb = {200, 55, 55}, .tol = "2.00%", .mag = "00Ω"}, [RES_ORANGE] = (ResInfo) {.number = '3', .rgb = {255, 102, 102}, .tol = "_.__%", .mag = "kΩ"}, [RES_YELLOW] = (ResInfo) {.number = '4', .rgb = {255, 255, 0}, .tol = "_.__%", .mag = "0kΩ"}, [RES_GREEN] = (ResInfo) {.number = '5', .rgb = { 0, 128, 0}, .tol = "0.50%", .mag = "00kΩ"}, [RES_BLUE] = (ResInfo) {.number = '6', .rgb = { 50, 50, 255}, .tol = "0.25%", .mag = "MΩ"}, [RES_PURPLE] = (ResInfo) {.number = '7', .rgb = {128, 0, 128}, .tol = "0.10%", .mag = "0MΩ"}, [RES_GREY] = (ResInfo) {.number = '8', .rgb = {128, 128, 128}, .tol = "0.05%", .mag = "_"}, [RES_WHITE] = (ResInfo) {.number = '9', .rgb = {255, 255, 255}, .tol = "_.__%", .mag = "_"}, [RES_GOLD] = (ResInfo) {.number = '_', .rgb = {186, 176, 0}, .tol = "5.00%", .mag = "0mΩ"}, [RES_SILVER] = (ResInfo) {.number = '_', .rgb = {204, 204, 204}, .tol = "10.0%", .mag = "mΩ"}, [RES_NO_COLOR] = (ResInfo) {.number = '_', .rgb = { 0, 0, 0}, .tol = "20.0%", .mag = "_"}, }; int main(void) { for (int i = 0; i < RES_NUM_COLORS; i++) { printf ("number: '%c', rgb: (%3u, %3u, %3u), tol: '%s', mag: '%s'\n", res_info[i].number, res_info[i].rgb[0], res_info[i].rgb[1], res_info[i].rgb[2], res_info[i].tol, res_info[i].mag); } return 0; }In conversation permalink Attachments
-
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:53 JST hazlin no plap pirate @karna
Thank you friend :D
This syntax feels new to me :O
I'd been already looking at examples of structs, but hadn't seen anything like this.In conversation permalink -
Embed this notice
karna :flipflop: :buffsuki: (karna@poa.st)'s status on Monday, 28-Oct-2024 02:58:54 JST karna :flipflop: :buffsuki: @hazlin I think the STL has maps and unordered_maps if you really want to use dictionaries but I dont use c++ so :akarinShrug:
In conversation permalink -
Embed this notice
hazlin no plap pirate (hazlin@shortstacksran.ch)'s status on Monday, 28-Oct-2024 02:58:54 JST hazlin no plap pirate @karna I appreciate your feedback :D
I'm just trying to figure out the best way to glew all this data together in c++ xD
I am going to pre-tokenize the strings into arrays of strings. And, I wasn't sure if that would work well with a struct.
I was under the impression that they liked... when everything had a known size going into things.
I guess I could just pick a maximum string array length.In conversation permalink