cinera_handmade.network/cmuratori/hero/chat/chat014.hmml

63 lines
5.1 KiB
Plaintext
Raw Permalink Normal View History

[video member=cmuratori stream_platform=twitch stream_username=handmade_hero project=chat title="CRTP and Library Design" vod_platform=youtube id=EhtxDXlrJ6Y annotator=Miblo]
[0:08][Recap yesterday's graphics driver crash and determine to set up an external streaming system]
[4:20][Invite questions and suggestions]
[6:38][@vaualbus][How do you write a program that is graphics driver crash aware?]
[8:36][Install and run Process Explorer, and consider graphics driver crashes[ref
site="Microsoft"
page="Process Explorer v16.21"
url="https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer"]]
[14:37][Making your app graphics card crash proof: 1) Always check for valid contexts]
[15:45][Making your app graphics card crash proof: 2) Use fault handlers]
[16:28][How OBS could handle faults, just protect and flush the stream on crash]
[17:25][Shutting down gracefully and relaunching your application]
[18:40][@crazy_coder456][How many episodes remaining, estimate?]
[19:39][@sgtrumbi][Do you use C++ features like templates? Do you use polymorphism in your own projects?]
[22:47][@bpaf][What do you think about the CRTP to do polymorphism?[ref
site="Wikipedia"
page="Curiously recurring template pattern"
url=https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern]]
[25:18][crtp.cpp: Curiously recurring template pattern]
[27:28][crtp.cpp: The template<struct Something> syntax]
[31:29][Consider ramifications of templates]
[34:40][crtp.cpp: Using a union in a parent struct to contain entity types]
[37:10][crtp.cpp: C++'s "struct entity_ghost \: public entity" inheritance syntax]
[40:59][crtp.cpp: Consider ramifications of the inheritance model]
[45:42][crtp.cpp: Making the derived class more primal]
[50:06][Polymorphic copy construction, virtual functions and the copy constructor[ref
site="Wikipedia"
page="Curiously recurring template pattern"
url=https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern]]
[56:44][crtp.cpp: Spec out our desired Clone() function, using a union in the parent shape struct to contain shape_rectangle and shape_circle, and a switch statement in Clone()]
[1:00:20][crtp2.cpp: Attempt this in a C++ way]
[1:04:03][crtp2.cpp: Run-time type information[ref
site="Wikipedia"
page="Run-time type information"
url="https://en.wikipedia.org/wiki/Run-time_type_information"]]
[1:09:34][crtp2.cpp: Virtual function call for Clone() in the structs]
[1:11:08][crtp2.cpp: Base class containing a pure virtual function for cloning, and a shape_cloner templatised struct]
[1:14:57][@bpaf][I didn't want to use virtual functions, so when I found this I was super happy]
[1:15:46][Polymorphic chaining[ref
site="Wikipedia"
page="Curiously recurring template pattern"
url=https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern]]
[1:20:18][@bpaf][My use case is: I write a library, and I want users of the library to provide their own structs for me to do my library business on, so I need polymorphism one way or another and, since it's a simulation, I want to remove all of the runtime cost I can incur]
[1:21:56][@bpaf][You got it, I have to call them back]
[1:22:17][@bpaf][They define a game, and I define in the library a genetic programming framework to find players that play well at them]
[1:23:27][@bpaf][In particular I create trees (S-expressions) that contain terminals that are defined by the game, which operate on the game state, and then evaluate those games that contains IF, >, == etc, as well as the game terminals, and then make players out of random trees, and do tournaments between each other]
[1:24:30][crtp2.cpp: Spec out an idea for bpaf's library, using an operate_type enum with the library ops occupying the high values]
[1:28:27][@bpaf][How would you pass the information needed to create random operations to the library, from the user, in this framework?]
[1:28:43][crtp2.cpp: Spec out CreateRandomOpCallback()]
[1:31:14][Consider library design]
[1:36:12][@bpaf][The thing I liked about the CRSP approach is that it makes somewhat clear what the "interface" is, you have to implement these methods, and have this data, and I can do the genetic tournament job]
[1:38:17][@bpaf][Your idea is interesting: you extend the enum. It's not that hard to understand]
[1:39:46][@bpaf][Here's a thing, if I want to generate trees for different choices, that need different languages, I use multiple template parameters]
[1:40:31][@bpaf][By different choices I mean, you could have two choices for a game turn, and you might want to have trees that use terminals that look at different aspects of the game]
[1:41:05][@bpaf][For example, imagine a game when you have the choice to play or pass, and if you decide to play you then have to make a move]
[1:41:17][crtp2.cpp: Spec out a GameStateAllowsMeToDoThese condition]
[1:42:47][@bpaf][No, the player doesn't generate random operations, the library generates random trees, and evaluates them]
[1:43:30][@bpaf][Hehe, yeah, it's complicated]
[1:43:57][On picking the things that your library does and does not do]
[1:47:49][Blackboard: Node Graph Disaster Zone]
[1:53:28][Wind it down]
[/video]