IRC logs for #openttd on OFTC at 2024-06-11
        
        
        
            ⏴ go to previous day
00:12:34  <audigex> andriydohniak: After 20 years of development I'd say that DOESN'T look nice
 
00:12:34  <audigex> Like sure, it's a clever bit of code... but as far as I'm concerned code should be something you can pick up and read and understand from reading it (assuming a baseline competence)
 
00:12:34  <audigex> You shouldn't have to either know what it does ahead of time, or "figure it out" excessively. To me that's a sign of bad code and I regularly reject PRs at work from my juniors for trying to be too fancy. If you can't hand it to a graduate developer who's been with us for 3 weeks and expect them to understand what it does (albeit perhaps not *why*), it's too fiddly
 
00:14:42  <audigex> Far too many developers put a weird focus on clever code that does nothing but prove how clever they are. Occasionally you have to do something fiddly looking for performance reasons, but 99% of the time you're better off being more verbose and writing understandable, maintainable code first and foremost
 
00:14:42  <audigex> Lines of code are cheap, maintenance hours are expensive
 
01:23:15  <bigyihsuan> andriydohniak: without looking at the replies
 
01:23:15  <bigyihsuan> going inside to out
 
01:23:15  <bigyihsuan> 0 if top <= bottom, otherwise
 
01:23:15  <bigyihsuan> ints from bottom to top+1 exclusive, then take evens, then sum together
 
01:23:15  <bigyihsuan> so the sum of even numbers within a given range, and 0 if the range is invalid
 
01:24:36  <bigyihsuan> audigex: my workplace uses go for our apis, and i can say to you that all go code looks the same
 
01:31:59  *** Wormnest has quit IRC (Quit: Leaving)
 
02:09:38  *** gnu_jj_ has quit IRC (Ping timeout: 480 seconds)
 
02:19:49  *** debdog has quit IRC (Ping timeout: 480 seconds)
 
03:04:17  *** gnu_jj_ has joined #openttd
 
03:07:28  *** gnu_jj has quit IRC (Ping timeout: 480 seconds)
 
03:31:54  <ahym> bigyihsuan: I thought it was a clever use of a ternary as well
 
03:32:31  <ahym> in terms of optimization i don't think you save any processing time doing it that way versus a conditional but i could be wrong
 
03:34:25  <bigyihsuan> ahym: all the ternary does here is being a "is the range valid" check, in go this'd be a bog standard if-return-else statement
 
03:35:40  <ahym> bigyihsuan: it condenses it slightly, there's other, arguably easier to read ways to write that in c++ that would still be performant as well
 
03:36:09  <ahym> I'd have to run a disassembly to know exactly how many comparisons it saves but I'm assuming zero
 
03:37:37  <ahym> If you wanted to save time this could be packed into a 128 register and probably be done quicker but it would be even less readable
 
03:42:00  <ahym> You could definitely use xxmintrin here to add more numbers within the range at once, it should reduce the instruction count at least by 4
 
05:28:11  *** keikoz has quit IRC (Ping timeout: 480 seconds)
 
06:06:43  <peter1139> Hmm, strange, Firefox keeps stalling watching videos on Youtube.
 
06:43:20  <silent_tempest> Do you have ad block?
 
07:11:59  *** SigHunter has joined #openttd
 
07:36:42  <peter1139> There is constinit in C++20, I guess.
 
07:51:44  <peter1139> Oof, group_gui.cpp:1175 and vehicle_gui.cpp:2241 are nasty.
 
08:08:38  *** SigHunter has quit IRC (Remote host closed the connection)
 
08:09:39  *** SigHunter has joined #openttd
 
09:56:31  *** Flygon has quit IRC (Quit: A toaster's basically a soldering iron designed to toast bread)
 
10:19:49  <peter1139> Well, still hungry :(
 
10:33:34  <peter1139> I ate them all yesterday.
 
10:54:44  * pickpacket had lunch with an old acquaintance 
 
10:54:55  <pickpacket> That spelling looks wrong
 
11:15:44  <peter1139> Lots of discussion eh?
 
11:16:12  <pickpacket> not as much as the forum threads about it, though
 
11:18:00  <peter1139> I'm betting none of this gets resolved down to a defined feature list, let alone someone willing to implement it.
 
11:19:40  <peter1139> Feature/functionality.
 
11:19:49  <pickpacket> definitely not! But one can hope to gain something from it
 
11:57:25  <andriydohniak> How does fmt::println work? How do I print a simple int?
 
12:00:17  <andriydohniak> ok, I figured it out, its {:d}
 
12:08:54  <andriydohniak> Can I somehow create a separate window, that talks to it's "parrent" without using global statics?
 
12:09:43  <andriydohniak> or can I somehow store the window object in another window object and get access to it's memory & methods
 
12:18:27  <andriydohniak> FindWindowById, and then cast the pointer to the correct type?
 
12:18:52  <andriydohniak> I see that as the best option, because that is the only way I can be sure it's not closed
 
12:20:10  <andriydohniak> now I get why everybody uses globals
 
12:20:15  <andriydohniak> just less things to worry about
 
12:20:32  <peter1139> dynamic_cast<>(FindWindowById()) is used in many places already.
 
12:20:52  <peter1139> But also, some other windows use a static class for state.
 
12:21:19  <andriydohniak> that might be a good idea, but it also makes all state of that class shared
 
12:21:32  <andriydohniak> so I can't have different selections on different graphs for example
 
12:22:18  <andriydohniak> I am not sure if it will be ok to have all company selectors share the same state
 
12:23:07  <peter1139> If you can have different state, then you need some way of visually linking your company selector to the window it applies to.
 
12:23:53  <peter1139> If you have two company selectors open, which is which?
 
12:23:57  <andriydohniak> True, I was thinking most of them will be "embeded" like a widget inside the same window, so no issue there
 
12:24:02  <andriydohniak> peter1139: true
 
12:24:20  <peter1139> If it's embedded, then it's not a separate window and there's no state to pass around.
 
12:24:36  <andriydohniak> Mb I just make all of them embeded?
 
12:26:07  <andriydohniak> Can I make a window change size, for example on a button click, to show the selector?
 
12:26:16  <andriydohniak> so it doesn't always take up space?
 
12:26:31  <peter1139> Yes, the shade button is an example of that.
 
12:27:04  <andriydohniak> And can I add widgets dynamically to the window
 
12:27:24  <andriydohniak> or do I just make it always be there, and just set the relavent size to 0
 
12:28:11  <peter1139> Always there but hidden. But you can add them to the layout dynamically anyway so that the widget structure is shared.
 
12:28:32  <andriydohniak> any examples of this in the current UI?
 
12:28:33  <peter1139> Like how the exist company buttons are added.
 
12:28:44  <peter1139> Or the picker_gui widgets.
 
12:29:21  <peter1139> Bah, Doom maps that are just non-surprise trap-after-trap :(
 
12:29:39  <andriydohniak> peter1139: you are a true retro gamer :)
 
12:30:00  <andriydohniak> I also played through doom once, on medium difficulty, it was fun while it lasted
 
12:30:15  <andriydohniak> I also used an engine with mouse support, so a bit cheaty
 
12:30:42  <peter1139> Doom always supported mouse out of the box, so not really.
 
12:30:57  <peter1139> We just were used to playing it that way...
 
12:31:08  <andriydohniak> peter1139: but from what I remember stock mouse support is kinda crap, and you can't look up
 
12:31:24  <peter1139> Looking up and down is wrong, indeed.
 
12:31:45  <andriydohniak> I enjoyed being able to look up
 
12:38:13  <andriydohniak> I know why it was impossible to look up in the original, it used some weird 2d to 3d ish rendering scheme, but I guess modern doom engines just ignore that and render in full rd
 
12:54:37  <peter1139> It's a 3D game with a heavily optimised (it needed to run on a 386) renderer that can't look up & down.
 
13:53:43  <talltyler> Agh, my finger slipped and I clicked “Rebuild all” instead of “Build all” 🤦
 
14:04:01  <_glx_> Or similar combo, not sure as I'm not in front of a keyboard
 
14:12:25  <talltyler> Good trick, thanks. Also F7 for Visual Studio on Windows 🙂
 
14:13:22  <andriydohniak> make openttd :)
 
14:22:54  <kuhnovic> talltyler: Depends on which keyboard shortcut set you have configured, there's a few of them
 
14:23:45  <kuhnovic> And I can't recommend the Ctrl+F7 shortcut enough, which only compiles the current .cpp file. Saves lots of time.
 
14:25:22  <peter1139> I'm currently developing some back-end code in a front-end C# asp view.
 
14:25:43  <peter1139> Entirely so that I don't have to keep recompiling for every change.
 
14:26:07  <peter1139> (Views are compiled on demand when they changed, back end library code not so much...)
 
14:36:18  <LordAro> what a low effort piece of rubbish
 
14:36:37  <LordAro> "i don't have time/don't know how to" would've been fine
 
14:38:59  <peter1139> Say what you really mean :)
 
14:40:06  <_glx_> and I typed my reply while you were
 
14:41:55  <LordAro> peter1139: i already watered down the above :p
 
14:43:31  <LordAro> i'm surprised it even parses
 
14:43:46  <LordAro> i suppose cmake is fairly lax with undefined variables?
 
14:44:40  <peter1139> I relaxed it with "if", because I don't know if it actually works.
 
14:50:19  <peter1139> Urgh, incredibly verbose and repetitive XML :(
 
14:50:51  <LordAro> we solved that by bolting extensions to our xml parser
 
14:51:02  <LordAro> like includes & inheritance
 
14:51:11  <LordAro> it works as well as you might expect
 
14:52:16  <ahym> writing performant xml parsers is an art form
 
14:53:03  <LordAro> the fact that it's all xpath-based and continually recomputes/reparses stuff over and over doesn't much help
 
14:54:35  <peter1139> This is meant to be a standard document format, so it's flexible. And a pain.
 
14:55:53  <ahym> LordAro: This seems like a performance nightmare
 
14:56:24  <ahym> plaintext in general is too verbose
 
14:56:36  <LordAro> ahym: it's ok, we have a caching layer in front of it
 
14:56:37  <_glx_> <longTagName>a</longTagName>
 
15:28:06  <peter1139> #12777 is completely pointless anyway.
 
15:28:47  <peter1139> I also, uh, have some patches for this...
 
15:31:57  *** Wormnest has joined #openttd
 
15:43:26  <andriydohniak> How would I go about creating a widget, and setting it's size at 0, and changing that later. All my attempts were unsuccesfull
 
15:52:48  <_jgr_> NWID_SELECTION/NWidgetStacked may be something to look into for this
 
15:59:10  <andriydohniak> How and when is the size of widgets determined anyway?
 
16:00:43  <andriydohniak> and how do nested widgets work?
 
16:02:27  <andriydohniak> NWID_SELECTION is a pretty good choice, but then I will have to duplicate the widgets
 
16:04:38  <_jgr_> Probably the best places to look to see how sizing is done are in the various overrides of `NWidgetBase::SetupSmallestSize`, and in `Window::ReInit`
 
16:05:19  <_jgr_> And `Window::UpdateWidgetSize`
 
16:09:27  *** D-HUND is now known as debdog
 
16:44:41  *** HerzogDeXtEr has joined #openttd
 
17:49:28  <peter1139> Okay, `union Colour` is a bit scary with std::endian.
 
18:01:59  <peter1139> I've done it the verbose way.
 
18:05:28  <peter1139> May or may not compile :p
 
18:05:36  <peter1139> May slow compilation by 100x.
 
18:11:56  <peter1139> In my defence, the CI does build with clang like wot I iz using.
 
18:49:55  <truebrain> upgrade to C++23 when?
 
18:51:17  <Rubidium> for just std::byteswap we might be able to get away with it
 
18:51:24  <LordAro> i mean there is __builtin_bswap64
 
18:51:53  <exceptik> Isn't it gnu specific?
 
18:51:58  <LordAro> _byteswap_uint64 for MSVC
 
18:56:01  <peter1139> The MSVC built-ins are not compatible with constexpr.
 
18:56:21  <LordAro> well that's their loss
 
18:56:47  <truebrain> I just read you only need to fix 1 target
 
18:56:52  <truebrain> the others are ... "someone elses problem"
 
18:57:17  <LordAro> regardless, byteswap isn't particularly a complex function, it's not like the maintenance overhead is massive
 
18:58:00  <truebrain> I just now invision peter writing a 1000 line function to byte-swap, just to annoy you 😛
 
18:59:15  <peter1139> Convert it to json-packed XML with some base64 thrown in?
 
19:00:04  <peter1139> I remember that XML BACS STD18 file format...
 
19:05:44  <peter1139> (STD18 is a fixed-length text file format. The XML version of it was... a fixed-length text file format wrapped in some XML tag...)
 
19:11:56  <andriydohniak> Can somebody explain this c++ thing?
 
19:11:56  <andriydohniak> static WindowDesc _graph_legend_desc(
 
19:11:56  <andriydohniak> WDP_AUTO, "graph_legend", 0, 0,
 
19:11:56  <andriydohniak> WC_GRAPH_LEGEND, WC_NONE,
 
19:11:58  <andriydohniak> std::begin(_nested_graph_legend_widgets), std::end(_nested_graph_legend_widgets)
 
19:12:04  <andriydohniak> Is this a function? a constructor?
 
19:12:12  <andriydohniak> it's probably a constructor, right?
 
19:12:55  <LordAro> all of the window stuff is "a bit weird" as far as C++ goes
 
19:13:11  <LordAro> autoformatters hate it :D
 
19:13:40  <andriydohniak> And why can't I do a similar thing inside a struct, and I have to use {} instead of ()?
 
19:14:46  <LordAro> you mean in a struct definition?
 
19:14:53  <LordAro> that's not a constructor
 
19:15:07  <LordAro> the above is constructing an instance of WindowDesc
 
19:15:18  <LordAro> struct FOO { ... } is defining a struct
 
19:16:03  <LordAro> so your question doesn't really make sense
 
19:16:06  <andriydohniak> and what does this do then?
 
19:16:06  <andriydohniak> WindowDesc _graph_legend_desc(
 
19:16:06  <andriydohniak> WDP_AUTO, "graph_legend", 0, 0,
 
19:16:08  <andriydohniak> WC_GRAPH_LEGEND, WC_NONE,
 
19:16:10  <andriydohniak> std::begin(_nested_graph_legend_widgets),     std::end(_nested_graph_legend_widgets)
 
19:16:18  <andriydohniak> I need to change something
 
19:16:37  <andriydohniak> WindowDesc _graph_legend_desc{
 
19:16:37  <andriydohniak> WDP_AUTO, "graph_legend", 0, 0,
 
19:16:37  <andriydohniak> WC_GRAPH_LEGEND, WC_NONE,
 
19:16:38  <andriydohniak> std::begin(_nested_graph_legend_widgets),     std::end(_nested_graph_legend_widgets)
 
19:16:44  <andriydohniak> the first desn't work
 
19:17:21  <LordAro> aha, you've run into C++ uniform initialisation rules
 
19:18:54  <LordAro> but, what would work for your first one is `struct foo { WindowDesc my_desc = WindowDesc(WDP_AUTO, ...); };`
 
19:19:10  <LordAro> initialising members "inline" in struct definitions is still kinda new
 
19:20:03  <LordAro> previously you would've had to define it in the struct's constructor
 
19:20:51  <andriydohniak> I will do that :)
 
19:21:10  <andriydohniak> I tried with the new keyword, but the copy constructor is explicitly deleted
 
19:21:17  <andriydohniak> for some structs*
 
19:22:50  <LordAro> ( with "non-static data member with initializer" )
 
19:23:25  <andriydohniak> and what about static initializers?
 
19:23:40  <andriydohniak> Can I initialize const static members inline?
 
19:24:01  <LordAro> that's in the above too :p
 
19:33:32  *** gelignite has joined #openttd
 
19:37:44  <andriydohniak> How can I reuse an array of NWidgetParts in another array of NWidgetParts
 
19:38:59  <LordAro> the same way you'd insert an array into any other array, i imagine
 
19:39:25  <LordAro> (i.e. probably a vector)
 
19:40:38  <andriydohniak> I can't use some sort of spread operator?
 
19:41:12  <LordAro> well, maybe if you try hard enough with some template magic
 
19:41:22  <andriydohniak> No, I don't want that :)
 
19:42:00  <andriydohniak> NO, NO, NO GOD PLEASE! NO!
 
19:42:09  <peter1139> andriydohniak, look at how picker_gui.cpp does it.
 
19:42:20  <andriydohniak> peter1139: what line?
 
19:42:29  <peter1139> Somewhere in the bottom.
 
19:42:56  <peter1139> There are Make* functions that create the widgets, and then other widget trees call those functions.
 
19:44:04  <andriydohniak> peter1139: Thank you!
 
19:44:39  <andriydohniak> there is a MakeNWidget, that takes in a couple of iterators, and returns a NWidgetBase
 
19:44:46  <andriydohniak> that can be used in another array
 
19:46:02  <peter1139> Yes, it inserts the widget tree at run-time.
 
19:46:56  <peter1139> I've also got a patch that simplifies the begin/end stuff a bit.
 
19:47:43  <andriydohniak> How long do you think untill upstream?
 
19:52:23  <LordAro> (a recurring meme is that peter *always* has a patch for "that")
 
19:52:30  <LordAro> could be a lot sooner, mind
 
19:55:17  <peter1139> The MakeWidget and MakeWidgetTree changes are slightly odd. We need to update the beginning of the span, but you can't do that with spans. So I turned the span into a pair of iterators and use those to make a new span...
 
19:55:34  <peter1139> subspan() is a thing but now really suitable here.
 
19:56:10  <peter1139> And keeping those functions as `const NWidgetPart *` and passing span.begin()/end() doesn't work, because the type different.
 
19:56:18  <peter1139> `&*span.begin()` does work, but ugly.
 
19:57:06  <andriydohniak> I don't get what half of theese words are, so I wish you good luck, and if it touches any code I write, I will gladly learn and update my code then
 
19:58:32  <peter1139> I basically replace those two pointers, begin and end, with a span.
 
19:58:44  <peter1139> Which is more C++-like, as pointers are bad.
 
20:06:00  <andriydohniak> Why can't it just accept an array? ahh, because c++ array is a pointer, and we can't know if it was allocated
 
20:06:48  <peter1139> Because an array only tells you the start of it.
 
20:07:04  <peter1139> A span is both the begin and end.
 
20:08:34  <andriydohniak> forgot about that too :)
 
20:08:47  <andriydohniak> but std::array or std::vector would work, right?
 
20:09:09  <andriydohniak> but spans are immutable, so technically more versatile
 
20:09:23  <andriydohniak> or mb they aren't, idk c++ is hard
 
20:10:09  <andriydohniak> Anyway, what order do the functions get called and the UI gets created when a new window is created
 
20:12:06  <andriydohniak> And can I still use functions like GetScrollbar for the widget that is nested via NWidgetFunction
 
20:36:45  *** gelignite has quit IRC (Quit: Stay safe!)
 
21:09:14  *** nielsm has quit IRC (Ping timeout: 480 seconds)
 
21:22:19  *** keikoz has quit IRC (Ping timeout: 480 seconds)
 
21:24:07  <peter1139> OnInitialPosition() is pretty clearly broken :(
 
21:35:41  <peter1138> Optimised gameplay?
 
21:42:32  *** ChanServ sets mode: +v tokai
 
21:49:17  *** tokai|noir has quit IRC (Ping timeout: 480 seconds)
 
22:13:12  *** Wolf01 has quit IRC (Quit: Once again the world is quick to bury me.)
 
22:18:01  *** HerzogDeXtEr has quit IRC (Read error: Connection reset by peer)
 
22:19:51  *** HerzogDeXtEr has joined #openttd
 
22:23:32  <_glx_> andriydohniak: std::array can be annoying because compile time fixed size determination
 
23:29:45  <silent_tempest> I guess it's not possible for me to request review from others on my PR's?
 
23:30:06  <silent_tempest> Like requesting a review from a speciffic individual.
 
23:52:19  <silent_tempest> This^^  is tiny if someone is looking a quick review.
 
continue to next day ⏵