1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 #pragma once
20 
21 /** \file
22  * \ingroup bke
23  * \section aboutglobal Global settings
24  *   Global settings, handles, pointers. This is the root for finding
25  *   any data in Blender. This block is not serialized, but built anew
26  *   for every fresh Blender run.
27  */
28 
29 #include "BLI_utildefines.h"
30 #include "DNA_listBase.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 struct Main;
37 
38 typedef struct Global {
39 
40   /** Active pointers. */
41   struct Main *main;
42 
43   /** Strings: last saved */
44   char ima[1024], lib[1024]; /* 1024 = FILE_MAX */
45 
46   /** When set: `G_MAIN->name` contains valid relative base path. */
47   bool relbase_valid;
48   bool file_loaded;
49   bool save_over;
50 
51   /** Strings of recent opened files. */
52   struct ListBase recent_files;
53 
54   /** Has escape been pressed or Ctrl+C pressed in background mode, used for render quit. */
55   bool is_break;
56 
57   bool background;
58   bool factory_startup;
59 
60   short moving;
61 
62   /** To indicate render is busy, prevent renderwindow events etc. */
63   bool is_rendering;
64 
65   /**
66    * Debug value, can be set from the UI and python, used for testing nonstandard features.
67    * DO NOT abuse it with generic checks like `if (G.debug_value > 0)`. Do not use it as bitflags.
68    * Only precise specific values should be checked for, to avoid unpredictable side-effects.
69    * Please document here the value(s) you are using (or a range of values reserved to some area).
70    *   * -16384 and below: Reserved for python (add-ons) usage.
71    *   *     -1: Disable faster motion paths computation (since 08/2018).
72    *   * 1 - 30: EEVEE debug/stats values (01/2018).
73    *   *    101: Enable UI debug drawing of fullscreen area's corner widget (10/2014).
74    *   *    666: Use quicker batch delete for outliners' delete hierarchy (01/2019).
75    *   *    777: Enable UI node panel's sockets polling (11/2011).
76    *   *    799: Enable some mysterious new depsgraph behavior (05/2015).
77    *   *   1112: Disable new Cloth internal springs handling (09/2014).
78    *   *   1234: Disable new dyntopo code fixing skinny faces generation (04/2015).
79    *   *   3001: Enable additional Fluid modifier (Mantaflow) options (02/2020).
80    *   * 16384 and above: Reserved for python (add-ons) usage.
81    */
82   short debug_value;
83 
84   /** Saved to the blend file as #FileGlobal.globalf,
85    * however this is now only used for runtime options. */
86   int f;
87 
88   struct {
89     /** Logging vars (different loggers may use). */
90     int level;
91     /** FILE handle or use stderr (we own this so close when done). */
92     void *file;
93   } log;
94 
95   /** debug flag, #G_DEBUG, #G_DEBUG_PYTHON & friends, set python or command line args */
96   int debug;
97 
98   /** This variable is written to / read from #FileGlobal.fileflags */
99   int fileflags;
100 
101   /** Message to use when auto execution fails. */
102   char autoexec_fail[200];
103 } Global;
104 
105 /* **************** GLOBAL ********************* */
106 
107 /** #Global.f */
108 enum {
109   G_FLAG_RENDER_VIEWPORT = (1 << 0),
110   G_FLAG_PICKSEL = (1 << 2),
111   /** Support simulating events (for testing). */
112   G_FLAG_EVENT_SIMULATE = (1 << 3),
113   G_FLAG_USERPREF_NO_SAVE_ON_EXIT = (1 << 4),
114 
115   G_FLAG_SCRIPT_AUTOEXEC = (1 << 13),
116   /** When this flag is set ignore the prefs #USER_SCRIPT_AUTOEXEC_DISABLE. */
117   G_FLAG_SCRIPT_OVERRIDE_PREF = (1 << 14),
118   G_FLAG_SCRIPT_AUTOEXEC_FAIL = (1 << 15),
119   G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET = (1 << 16),
120 };
121 
122 /** Don't overwrite these flags when reading a file. */
123 #define G_FLAG_ALL_RUNTIME \
124   (G_FLAG_SCRIPT_AUTOEXEC | G_FLAG_SCRIPT_OVERRIDE_PREF | G_FLAG_EVENT_SIMULATE | \
125    G_FLAG_USERPREF_NO_SAVE_ON_EXIT)
126 
127 /** Flags to read from blend file. */
128 #define G_FLAG_ALL_READFILE 0
129 
130 /** #Global.debug */
131 enum {
132   G_DEBUG = (1 << 0), /* general debug flag, print more info in unexpected cases */
133   G_DEBUG_FFMPEG = (1 << 1),
134   G_DEBUG_PYTHON = (1 << 2),                /* extra python info */
135   G_DEBUG_EVENTS = (1 << 3),                /* input/window/screen events */
136   G_DEBUG_HANDLERS = (1 << 4),              /* events handling */
137   G_DEBUG_WM = (1 << 5),                    /* operator, undo */
138   G_DEBUG_JOBS = (1 << 6),                  /* jobs time profiling */
139   G_DEBUG_FREESTYLE = (1 << 7),             /* freestyle messages */
140   G_DEBUG_DEPSGRAPH_BUILD = (1 << 8),       /* depsgraph construction messages */
141   G_DEBUG_DEPSGRAPH_EVAL = (1 << 9),        /* depsgraph evaluation messages */
142   G_DEBUG_DEPSGRAPH_TAG = (1 << 10),        /* depsgraph tagging messages */
143   G_DEBUG_DEPSGRAPH_TIME = (1 << 11),       /* depsgraph timing statistics and messages */
144   G_DEBUG_DEPSGRAPH_NO_THREADS = (1 << 12), /* single threaded depsgraph */
145   G_DEBUG_DEPSGRAPH_PRETTY = (1 << 13),     /* use pretty colors in depsgraph messages */
146   G_DEBUG_DEPSGRAPH_UUID = (1 << 14),       /* use pretty colors in depsgraph messages */
147   G_DEBUG_DEPSGRAPH = (G_DEBUG_DEPSGRAPH_BUILD | G_DEBUG_DEPSGRAPH_EVAL | G_DEBUG_DEPSGRAPH_TAG |
148                        G_DEBUG_DEPSGRAPH_TIME | G_DEBUG_DEPSGRAPH_UUID),
149   G_DEBUG_SIMDATA = (1 << 15),               /* sim debug data display */
150   G_DEBUG_GPU_MEM = (1 << 16),               /* gpu memory in status bar */
151   G_DEBUG_GPU = (1 << 17),                   /* gpu debug */
152   G_DEBUG_IO = (1 << 18),                    /* IO Debugging (for Collada, ...)*/
153   G_DEBUG_GPU_SHADERS = (1 << 19),           /* GLSL shaders */
154   G_DEBUG_GPU_FORCE_WORKAROUNDS = (1 << 20), /* force gpu workarounds bypassing detections. */
155   G_DEBUG_XR = (1 << 21),                    /* XR/OpenXR messages */
156   G_DEBUG_XR_TIME = (1 << 22),               /* XR/OpenXR timing messages */
157 
158   G_DEBUG_GHOST = (1 << 23), /* Debug GHOST module. */
159 };
160 
161 #define G_DEBUG_ALL \
162   (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS | \
163    G_DEBUG_FREESTYLE | G_DEBUG_DEPSGRAPH | G_DEBUG_GPU_MEM | G_DEBUG_IO | G_DEBUG_GPU_SHADERS | \
164    G_DEBUG_GHOST)
165 
166 /** #Global.fileflags */
167 enum {
168   G_FILE_AUTOPACK = (1 << 0),
169   G_FILE_COMPRESS = (1 << 1),
170 
171   // G_FILE_DEPRECATED_9 = (1 << 9),
172   G_FILE_NO_UI = (1 << 10),
173 
174   /* Bits 11 to 22 (inclusive) are deprecated & need to be cleared */
175 
176   /** On read, use #FileGlobal.filename instead of the real location on-disk,
177    * needed for recovering temp files so relative paths resolve */
178   G_FILE_RECOVER = (1 << 23),
179   /** BMesh option to save as older mesh format */
180   /* #define G_FILE_MESH_COMPAT       (1 << 26) */
181   /* #define G_FILE_GLSL_NO_ENV_LIGHTING (1 << 28) */ /* deprecated */
182 };
183 
184 /**
185  * Run-time only #G.fileflags which are never read or written to/from Blend files.
186  * This means we can change the values without worrying about do-versions.
187  */
188 #define G_FILE_FLAG_ALL_RUNTIME (G_FILE_NO_UI)
189 
190 /** ENDIAN_ORDER: indicates what endianness the platform where the file was written had. */
191 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
192 #  error Either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ must be defined.
193 #endif
194 
195 #define L_ENDIAN 1
196 #define B_ENDIAN 0
197 
198 #ifdef __BIG_ENDIAN__
199 #  define ENDIAN_ORDER B_ENDIAN
200 #else
201 #  define ENDIAN_ORDER L_ENDIAN
202 #endif
203 
204 /** #Global.moving, signals drawing in (3d) window to denote transform */
205 enum {
206   G_TRANSFORM_OBJ = (1 << 0),
207   G_TRANSFORM_EDIT = (1 << 1),
208   G_TRANSFORM_SEQ = (1 << 2),
209   G_TRANSFORM_FCURVES = (1 << 3),
210   G_TRANSFORM_WM = (1 << 4),
211 };
212 
213 /** Defined in blender.c */
214 extern Global G;
215 
216 /**
217  * Stupid macro to hide the few *valid* usages of `G.main` (from startup/exit code e.g.),
218  * helps with cleanup task.
219  */
220 #define G_MAIN (G).main
221 
222 #ifdef __cplusplus
223 }
224 #endif
225