Guild icon
Teeworlds
discord.gg/teeworlds / development
For discussions around the development of the official Teeworlds
Between 2019-01-04 00:00:00Z and 2019-01-05 00:00:00Z
Avatar
Shame. Makes my awful code at least a bit readable :/
Avatar
Programming is communicating with other humans, not just the machine 😀
Avatar
Hmm, that makes me thinking what you really mean.
09:37
If I think my piece of code is a horrible mess, maybe I should better ask for help?
09:37
Or that readability for humans should always have top priority, even over readability for the machine.
09:37
😅
Avatar
The latter
09:38
"Readability for the machine" is not a thing
09:38
It compiles or it doesn't
Avatar
Or it compiles bot does something really different, because str_format executes from right to left.
09:39
It is never black or white 😛
Avatar
Then it's wrong. No readability gradient. It is black and white
09:40
Writing code that is very difficult to understand is not a masterpiece, even though it may feel like one at times 😀
Avatar
Keeping code SOLID, easy to maintain and readable is hard af.
Avatar
It is, yeah
Avatar
Especially, when people dont use and understand SOLID (edited)
Avatar
Even communicating with yourself is a challenge:D
Avatar
Using oop (edited)
Avatar
You can make solid in oop and non-oop
Avatar
Solid is oop thing
09:45
Was written with oop in mind at least (edited)
09:47
I think only "S", can be used like everywhere. Even in life haha
09:48
"Single responsibility". For a funcition, class
Avatar
Then I misunderstood:)
Avatar
Rest are oop stufd
09:48
Like interfaces, dependecy inversion (edited)
09:51
In object-oriented computer programming, SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable. It is not related to the GRASP software design principles. The principles are a subset of many pri...
09:51
You can check concepts. One is especially hard (edited)
Avatar
If anyone finds some time, I could need some C++ help with my awful code.
09:54
But it is a mod. (if that matters) (edited)
Avatar
snprintf? Prefer functions from src/base/system.h in teeworlds
10:45
You linked the same thing twice btw (?)
10:46
The former is the commit, the latter some lines of it.
10:48
I couldn't find any equivalent function for snprintf in src/base/system.h
10:49
The closest would be str_format
10:50
str_format does not suit you?
Avatar
With some refactoring it should.
10:52
Wouldn't make things easier, though.
10:56
Actually, my biggest problem is the concatenation of 'broadcast color code' plus character.
10:56
Like: ^900 + "C"
10:56
I don't know a proper way without sacrificing too much performance. Therefore, I went with preprocessor macros.
10:58
But iirc from my study they should be avoided whenever possible...
Avatar
preprocessor macros 🤢
Avatar
There must be a better way to do this: return BCOLOR_RED "{";
Avatar
the question is: is the performance loss singificant?
Avatar
Well, if it would be str_format about 25x per tick, then I guess so.
Avatar
I don't think that's important at all
Avatar
At least it would look very stupid to me.
Avatar
You can define colors as const char*?
11:00
high level programming languages do a lot of more impactful stupid things
11:00
if you'd be coding in java or python this would probably be done on a hidden level anyway
Avatar
Hmmm
Avatar
I mean, sure you can use an enum for colors and concatenate them with spaces if you want - as long as it's readable, it's your choice 😀
Avatar
So, I should better use 25 str_format instead of fixed strings? If the performance impact is negligible, then it could make the code indeed more readable...
Avatar
I make static analysers for a living, and as soon as I include a printf, the complexity of the program absurdly explodes 😄 When you do printing stuff, you can generally forget about tiny optimizations
11:08
Now 25 str_format in a function looks a bit ugly, it's strange that you have to resort to that
Avatar
5 spots with 6 variable strings each. My bad, it is 30. (edited)
11:10
Couldn't think of a better way 😕
Avatar
I still don't see why you would need so many calls :/
Avatar
Well, maybe I just missed any great alternative.
11:11
But basically, this is one spot: %s%s%s%s%c%s%s%s
11:11
With each %s being one marker, except the %s%c being the ^900 C
Avatar
I think enum is not handled by the preprocessor btw
Avatar
And each %s itself gets replaced by %s%s (color + char)
Avatar
str_format(str, sizeof(str), "%s%s%s%s%c%s%s%s", ...) ?
Avatar
This is pretty much the line i posted at the beginning.
Avatar
so you don't need 20 calls or god knows how many
Avatar
Why not?
11:13
TextLen += snprintf(aBuf + TextLen, sizeof(aBuf), "%s%s%s%s%c%s%s%s " , GetBroadcastOpen(i, MarkerPos) // Opening Parenthesis , GetBroadcastLine(i, MarkerPos) , GetBroadcastLine(i, MarkerPos) , GetTeamBroadcastColor(m_apDominationSpots[i]->GetTeam()), GetSpotName(i)[0] , GetBroadcastLine(i, MarkerPos) , GetBroadcastLine(i, MarkerPos) , GetBroadcastClose(i, MarkerPos)); // Closing Parenthesis
11:13
With GetBroadcastOpen(i, MarkerPos) and GetBroadcastLine(i, MarkerPos) returning a concatenated string itself.
Avatar
str_format(str, sizeof(str), "%s%s%s%s%c%s%s%s", Colorize(...), Colorize(...), Colorize(...) );
11:14
like that?
Avatar
Pretty much
Avatar
that's not 20 calls to str_format
Avatar
but how would colorize work then?
11:14
If it wouldn't use str_format
Avatar
I don't know how your coloring mechanics work?
11:15
maybe you'd need to, yes
Avatar
Color: "^900" | "^009" | "^999" Char: < | > | - | { | ( | [ | } | ) | ]
11:16
Always picking one of both sets
11:16
And concatenating them.
Avatar
const char* colors[]; str_concat(colors[i], char)
11:16
but that looks readable, it's not 20 calls straight up in a function, so as far as I'm concerned I don't really care if Colorize takes 20 cycles or 500 :D
11:17
I really think it doesn't matter at all
Avatar
it's not 3D rendering, right
11:17
xD
Avatar
src/base/system.c doesn't implement str_concat?
11:17
str_cat maybe?
Avatar
negative.
11:18
str_append maybe
Avatar
meh just use format :D
11:19
you'd need a buffer anyway, that example code is silly
11:20
iirc teeworlds rendering renders everything twice to eval the size of the text
Avatar
Well, at least I could reuse the buffer. All colorized chars are 4 chars long.
Avatar
you don't need to worry so much about str_format calls
11:20
dev time is precious :p machine time isn't
Avatar
IMO, just make good abstraction for colorizing your text
11:21
and you'll be fine
11:21
^.^
Avatar
dune's str_format(str, sizeof(str), "%s%s%s%s%c%s%s%s", Colorize(...), Colorize(...), Colorize(...) ); Colorize() is called abstraction
11:22
actually, generaly functions. It's abstract, anywya
11:22
good, readable functions. You shouldn't care much about performance at first
Avatar
They don't lack too much readability. Except the preprocessor macro usage could be troublesome.
11:24
They are just hilarious explicit 😄
Avatar
i don't know, GetBroadcastLine that thing look scary to me (edited)
11:24
and don't know what it does at first
Avatar
okok, GetColorizedLine would suit better
11:25
But that is just wording.
Avatar
wording is important
11:25
but if it's your own mod, without contributors. then it's fine
11:25
if you understand 😃
Avatar
Ye, but it is 1 word that includes 50 more lines for now 😛
11:26
Don't worry, I will PR it once done 😇
Avatar
iirc, better not use preprocessor macros in C++, you will almost never need them. enum works
Avatar
Thank you Dune. Really appreciate it!
15:41
I wonder if there should be some restrictions on eyes colors
15:41
like half custom half black?
Avatar
Uh, Dune, it is not default eyes
17:31
I used zombies' eyes (edited)
17:32
They were yellow by default
Avatar
are they?
Avatar
Dominant's, iirc
Avatar
not sure how skins work
17:33
aren't the eyes black in the data/skins?
Avatar
Yes, but those are modified
17:33
Vheck yourself, you have these too
Avatar
so that means you cannot chang e the color of the default eyes, but can change yellow eyes to anything?
Avatar
I think so yeah
17:35
I didnt try tho, i only used custom eyes i downloaded for ZOMB gamemode
17:35
But i am pretty sure u cannot change color of default eyes
Avatar
yeah if you slide the cursor only the custom eyes change
Exported 139 message(s)