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 threads see Threads Manual and Jobs Manual.
{
private:
public:
RenderThread() { _doc = nullptr; }
~RenderThread() { this->DeleteDoc(); }
{
this->DeleteDoc();
_bitmap = bitmap;
}
{
if (_doc == nullptr)
return;
if (_bitmap)
{
}
this->DeleteDoc();
}
};
{
{
if (id == CUSTOM_ID_RENDER_FINISH)
{
if (g_displayBitmap)
{
}
}
return true;
}
};
PyCompilerFlags * flags
Definition: ast.h:14
RENDERRESULT RenderDocument(BaseDocument *doc, const BaseContainer &rdata, ProgressHook *prog, void *private_data, BaseBitmap *bmp, RENDERFLAGS renderflags, BaseThread *th, WriteProgressHook *wprog=nullptr, void *data=nullptr)
void SpecialEventAdd(Int32 messageid, UInt p1=0, UInt p2=0)
Bool ShowBitmap(const Filename &fn)
Definition: c4d_basebitmap.h:428
Definition: c4d_basecontainer.h:47
Definition: c4d_basedocument.h:498
RenderData * GetActiveRenderData()
static void Free(BaseDocument *&bl)
BaseContainer GetData()
Definition: c4d_baselist.h:2329
Definition: c4d_thread.h:28
Definition: c4d_thread.h:62
BaseThread * Get() const
Definition: c4d_thread.h:90
virtual const Char * GetThreadName()=0
Definition: c4d_messagedata.h:65
virtual Bool CoreMessage(Int32 id, const BaseContainer &bc)=0
Definition: c4d_basedocument.h:144
maxon::Char Char
Definition: ge_sys_math.h:56
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int32 Int32
Definition: ge_sys_math.h:60
RENDERFLAGS
Definition: ge_prepass.h:4681
@ NODOCUMENTCLONE
Set to avoid an automatic clone of the scene sent to RenderDocument().
const char * doc
Definition: pyerrors.h:226
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();
#define ifnoerr(...)
The opposite of iferr.
Definition: errorbase.h:393
#define NewObj(T,...)
Definition: newobj.h:108
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)
{
}
}
{
});
return OK
Definition: apibase.h:2690
#define MAXON_INITIALIZATION(...)
Definition: module.h:795
#define DeleteObj(obj)
Definition: newobj.h:159
#define iferr_scope
Definition: resultbase.h:1384
#define iferr_return
Definition: resultbase.h:1519
Custom Threads
A custom thread class has to implement these virtual functions:
void Main()
{
{
if (this->TestBreak())
return;
}
}
const Char* GetThreadName()
{
return "ExampleCustomThread";
}
{
if (_startTime == -1)
return true;
if ((time - _startTime) > 20000)
return true;
return false;
}
Py_ssize_t i
Definition: abstract.h:645
void GeSleep(Int32 milliseconds)
Int32 GeGetTimer()
Definition: c4d_general.h:449
static String IntToString(Int32 v)
Definition: c4d_string.h:495
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
- 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)
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
- 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