About
C4DThread is the base class for custom classic threads in Cinema 4D. It can be used to perform operations on multiple cores or in the background.
- Warning
- Threads must not use any OS functions. This is strictly forbidden. The only system calls allowed are memory (de-)allocations.
-
For custom MAXON API ALIASES threads see Threads Manual and Jobs Manual.
{
private:
public:
RenderThread() { _doc = nullptr; }
~RenderThread() { this->DeleteDoc(); }
{
this->DeleteDoc();
_doc = doc;
_bitmap = bitmap;
}
{
if (_doc == nullptr)
return;
if (_bitmap)
{
RenderDocument(_doc, renderSettings,
nullptr,
nullptr, _bitmap, flags, thread);
}
this->DeleteDoc();
}
};
{
{
if (id == CUSTOM_ID_RENDER_FINISH)
{
if (g_displayBitmap)
{
}
}
return true;
}
};
if (g_renderThread == nullptr)
{
{
if (g_renderThread == nullptr)
return false;
}
}
if (g_renderThread->IsRunning())
{
g_renderThread->End(true);
}
g_renderThread->SetData(documentClone, g_displayBitmap);
const Bool started = g_renderThread->Start();
Creation
A custom thread class is created by implementing a class based on C4DThread:
{
public:
ExampleThread() { }
{
return "ExampleThread";
}
};
Now an instance of this custom thread class can be created and used:
ExampleThread* g_exampleThread = nullptr;
{
if (g_exampleThread == nullptr)
{
}
}
{
});
Custom Threads
A custom thread class has to implement these virtual functions:
void Main()
{
for (
Int32 i = 0; i < 60; ++i)
{
if (this->TestBreak())
return;
}
}
const Char* GetThreadName()
{
return "ExampleCustomThread";
}
{
if (_startTime == -1)
return true;
if ((time - _startTime) > 20000)
return true;
return false;
}
- Note
- To send a message from a thread to the main thread use SpecialEventAdd(). See Core Messages Manual.
Use
The custom thread can be started and stopped with these functions:
const Bool started = g_exampleThread->Start();
if (started == false)
- Note
- The THREADPRIORITY should typically not be changed.
Read
Further thread properties are accessed with:
if (g_exampleThread->IsRunning())
{
g_exampleThread->End(true);
}
Further Reading