You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not a sol question, but the design of your API gave me this idea and I thought you might be able to point me in the right direction.
I am working on a new multithreaded renderer. An object that lives on the game logic side has a simplified object that lives in the rendering thread, and represents the object's relevant rendering info. For example, a visible entity would have a RenderObject associated with it in the rendering thread. When the entity moves, the RenderObject's 4x4 matrix gets updated when the threads sync.
I am thinking about implementing a list of commands for the rendering thread. This would work by accepting a pointer to a class member and a value, or a pointer to a class method:
class Entity
{
shared_ptr<RenderObject> renderobject;
Vec4 color;
void SetColor(const float r, const float g, const float b, const float a)
{
//Set the color
this->color = Vec4(r,g,b,a);
//Now add an instruction that will update the corresponding object when the threads sync:
commandqueue.AddInstruction( this->renderobject, &RenderObject::color, this->color ); //Object, pointer to member, new value
}
};
Some instructions might call a method instead, along with the function arguments:
commandqueue.AddInstruction( this->renderobject, &RenderObject::SetColor, r, g, b, a ); //Object, pointer to method, arguments
The point of this is to avoid writing a thousand switch/case statements for all the different values and functions. This is what I want:
for each instruction {
instruction.o->(*instruction.member) = instruction.value;
}
This is what I want to avoid doing:
for each instruction {
switch (instruction.id)
{
case INSTRUCTION_MODIFY_ENTITY_COLOR:
dynamic_pointer_cast<RenderObject>(instruction.object)->color = (Vec4)instruction.value;
break;
}
}
Can you suggest how I might go about this? I have only done very basic work with templates. Any advice you have would be appreciated.
The text was updated successfully, but these errors were encountered:
Either way, your goal here sort of goes beyond the scope of sol2. This is a C++ thing, and figuring out how to shadow and/or propogate changes -- with thread safety -- is not necessarily my wheelhouse. I would expect that you'd need to something like store a std::function-alike that just runs some arbitrary code so you don't have to think about what it's actually doing, then invoke it with for each instruction { instruction(); }
This is not a sol question, but the design of your API gave me this idea and I thought you might be able to point me in the right direction.
I am working on a new multithreaded renderer. An object that lives on the game logic side has a simplified object that lives in the rendering thread, and represents the object's relevant rendering info. For example, a visible entity would have a RenderObject associated with it in the rendering thread. When the entity moves, the RenderObject's 4x4 matrix gets updated when the threads sync.
I am thinking about implementing a list of commands for the rendering thread. This would work by accepting a pointer to a class member and a value, or a pointer to a class method:
Some instructions might call a method instead, along with the function arguments:
The point of this is to avoid writing a thousand switch/case statements for all the different values and functions. This is what I want:
This is what I want to avoid doing:
Can you suggest how I might go about this? I have only done very basic work with templates. Any advice you have would be appreciated.
The text was updated successfully, but these errors were encountered: