How to share data between kernel tasks? (Game engine with kernel/kernel tasks)
I have IKernelTask and derived classes of it (Making individual kernel tasks for input, sound ...) In addition I have CKernel which runs the different kernel tasks. CKernel has a function Execute() which runs through a list of the kernel tasks and runs their Update() function.
I am having difficulties when it comes to sending data between kernel tasks, so I decided to try sending data through the kernel by sending in a reference of the kernel object to Execute() and then to the kernel tasks the same way in Update().
CKernel's Execute() is like so:
Execute(CKernel &oKernel)
For each kernel task:
{
Update(oKernel);
}
IKernelTask's Update() 开发者_开发百科is like so:
Update(CKernel &oKernel)
{
// Each kernel task has an overridden Update() function
}
In Main:
while (running)
{
oKernel.Execute(oKernel);
}
This would allow the kernel tasks to forward data between kernel tasks, by giving them access to the kernel through their Update() function.
However:
1. Is this a good solution? If not, what would be a more conventional way to share data? 2. If this is an ok solution; The problem is that CKernel needs to include IKernelTask and IKernelTask needs to include CKernel. I have tried forward declaration, but am getting errors such as: C2027: use of undefined type 'CKernel'You need to #include
the header file with the definition of CKernel
.
精彩评论