-
Notifications
You must be signed in to change notification settings - Fork 0
General patterns
Here are some general patterns I've picked up. Hopefully if you see them, this may give you a better idea at what's going on and assist debugging.
##idname
A lot of components will have a string, referred to as an idname
. There will then be functions for looking up items based on their idname
. I gather this is mainly a way to allow C and Python to interoperate without Python having direct access to parts of the C code. With raw raw C, if you wanted to share objects, I imagine you'd just you'd store a pointer to the object somewhere other parts of the code can access. Examples are PanelType
, wmOperatorType
, menus, and a few more. Therefore, this name is important, and so is spelling it right!
One other thing to note about the idname, is that there are two styles, one used by C, one used by Python. Example, "MESH_OT_merge"
in C, would be "mesh.merge"
in Python, so be aware of that. This is translated by WM_operator_bl_idname
. Sometimes both styles are interchangeable!
##Linked lists
Lots of Blender's structures are stored in doubly-linked lists. A lot of structs have a ListBase
member which simply contains two void*
(i.e. untyped) pointers pointing the next and previous elements, and blender provides functions for manipulating lists of this type, such as BLI_addtail
, BLI_addhead
, BLI_pophead
, etc. So don't be surprised if you see prev
and next
pointers everywhere! There is some official documentation for this here.
##Prefixes A lot of the functions in the codebase have prefixes to indicate what area they relate to, and the same applies to idnames. Some of this stuff, you will probably never need to touch. There doesn't seem to be a definitive list, this is the best I've found at explaining them. Here are a few more I've found:
- BPY/PY - Code that talks to or manipulates Python structures (RNA?)
- GHOST - Ghost is the name of Blender's OS-agnostic Windowing system. This is conditionally compiled so the functions call into the functions for the correct OS when built.
- GL - OpenGL. Calls down to raw OS calls (conditionally compiled)
- MT - MenuType
- OT - OperatorType
- PT - PanelType
- WM - WindowManager
You can find more for other areas if you search on the Internet. If you know what you want to modify but not where to find it, this may help.
Blender has a lot of these. Here are a few:
-
DEF_ICON - Creates numeric references for icons when compiled that can be referred to by code that expects an
int
for an icon - UNUSED - Supresses compiler warnings about unused function parameters
- STREQ - Like strcmp