Scheduled
100DaysOfGameDev: Day 46
I am now on a path of darkness, and no tutorial shall help me. That is, I have finished the tutorial and I am experimenting on my own, therefore there is no one to hold my hand and tell me if I am doing something right, or wrong. Speaking of someone to hold my hand, this post has been sponsored by HedgeTheHog#andranik3949, who was kind enough to help me when I was completely lost debugging my code. Wish I could say the same for the compiler...
The issue was that I was trying to use std::bind
, to pass to the render function a reference to my world. HedgeTheHog found
The arguments to bind are copied or moved, and are never passed by reference unless wrapped in std::ref or std::cref.
Therefore, a solution would be to force pass the reference with the use of std::ref
, where auto f = std::bind(func, std::ref(world));
, then use f();
. Another workaround is to use std::placeholders::_1
, where auto f = std::bind(func, std::placeholders::_1);
the pass the world in function call such as f(world);
. There are some other errors I have yet to battle, but I will talk about them after I find a fix.
The second challenge I have to face is to somehow use local instances of random generators. “Why?” you may ask. Because, if I have several threads using the same random number generator it's gonna be a bottleneck since random generators usually maintain some type of inner state. Therefore, all of the cpu cache across all of the cores will be invalidated. Someone smart reading this may think “Aha! Just use static thread_local
, instead of static
”. Unfortunately, that is useless, because I would have the same seed over all instances. I need to figure out a way to have that with different seeds on each thread and without making my code super ugly.
That's it for today, see you!