Thanks so much for this! A great way to get into the C4D SDK. Such a time saver.
Best posts made by wnoyce
-
RE: Ray Tracing In One Weekend
Latest posts made by wnoyce
-
RE: Instance variables static or not?
Hi @ferdinand,
Thank you for moving this topic to its correct category.
Although I believe we agree on the C++ meaning of static members I really wasn't aware that the use of static plugin parameters and static plugin state could in practice be as problematic as you describe and will certainly heed your advice to no longer use static plugin state.
Also, your point on field members and parallel execution of member functions is well taken.Thanks again!
-
Instance variables static or not?
Hi there,
I am working on an ObjectData derived plugin and can't seem to decide whether to make my private instance variables - simple structs really - static or not.
So, would
struct MyPluginParameters { Float a; Int32 b; Int32 c; Bool d; Bool e; }; struct MyPluginState { Float f; Bool g; Int32 h; Int32 i; }; class MyPlugin : public ObjectData { public: virtual Bool Init(GeListNode* node); virtual BaseObject* GetVirtualObjects(BaseObject* op, HierarchyHelp* hh); virtual Bool Message(GeListNode* node, Int32 type, void* t_data); static NodeData* Alloc() { return NewObjClear(MyPlugin); } private: static MyPluginParameters params; static MyPluginState state; }; MyPluginParameters MyPlugin::params; MyPluginState MyPlugin::state;
be preferred to the simpler:
class MyPlugin : public ObjectData { public: virtual Bool Init(GeListNode* node); virtual BaseObject* GetVirtualObjects(BaseObject* op, HierarchyHelp* hh); virtual Bool Message(GeListNode* node, Int32 type, void* t_data); static NodeData* Alloc() { return NewObjClear(MyPlugin); } private: MyPluginParameters params; MyPluginState state; };
or not? Is there any pragmatic difference between the two options?
Thank you very much.
-
RE: Multiple instances of ObjectData plugin?
@ferdinand Thank you very much for your elaborate answer!
Explaining the difference between the interface layer and the plugin layer was very enlightening. I now understand that calling functions more than once is all part of the package and that
this
does not refer to the actual plugin instance. Thank you again. -
Multiple instances of ObjectData plugin?
Hi all, my first post here. Thank you for the opportunity.
I'm developing a C++ ObjectData plugin. During testing it seems that straight from the start multiple instances of the plugin are created. Why is that and can it be avoided?
I've cobbled together a bare bones plugin (called Minst, plugin ID=1111111) which displays the same behaviour as my actual plugin.
Here's the output to the Console:
I believe the Console shows that multiple instances of Minst are created by calling Init() more than once. (My more complex plugin also calls GetDDescription() more than once, so this multiple calling of the same functions can become quite involved very quickly. That's why I would very much like to know the reasoning behind it.)
The Console also shows that GetVirtualObjects() is only called for the first instance of the plugin, not the other two, which seems a good thing. (However, it also shows that GetVirtualObjects() is called twice in a row, one right after the other, which seems a bit superfluous.)
Here 's the code:
main.h
#ifndef MAIN_H #define MAIN_H Bool RegisterMinst(); #endif
main.cpp
#include "c4d.h" #include "main.h" Bool PluginStart() { return RegisterMinst() != 0; } void PluginEnd() { } Bool PluginMessage(Int32 id, void* data) { switch (id) { case C4DPL_INIT_SYS: { return g_resource.Init() != 0; } case C4DMSG_PRIORITY: { return true; } default: return false; } }
minst.cpp
#include "c4d.h" #include "main.h" #define ID_MINST 1111111 // Temporary plugin id. Replace this with a proper ID. class Minst : public ObjectData { INSTANCEOF(Minst, ObjectData) public: Bool Init(GeListNode* node) final; BaseObject* GetVirtualObjects(BaseObject* op, HierarchyHelp* hh) final; Bool Message(GeListNode* node, Int32 type, void* t_data) final; static NodeData* Alloc() { return NewObjClear(Minst); } }; Bool Minst::Init(GeListNode* node) { maxon::String message = FormatString("Init: Plugin Instance=0x@, Plugin ID=@", (void*)this, node->GetType()); ApplicationOutput(message); return true; } Bool Minst::Message(GeListNode* node, Int32 type, void* t_data) { return true; } BaseObject* Minst::GetVirtualObjects(BaseObject* op, HierarchyHelp* hh) { maxon::String message = FormatString("GetVirtualObjects: Plugin Instance=0x@, Plugin ID=@", (void*)this, op->GetType()); ApplicationOutput(message); return nullptr; } Bool RegisterMinst() { ApplicationOutput("RegisterMinst"); return RegisterObjectPlugin(ID_MINST, "Minst"_s, OBJECT_GENERATOR, Minst::Alloc, ""_s, nullptr, 0); }
Can someone please shed some light on this?
Thank you.
-
RE: Ray Tracing In One Weekend
Thanks so much for this! A great way to get into the C4D SDK. Such a time saver.