Fix T79816: Restore scene.statistics() BPY function
This RNA/BPY function was removed in c08d847488. For understandable
reasons really-- getting scene statistics from a string displayed in the
status bar is not exactly the best design. But we have committed to not
changing the RNA API too much for the 2.90 release, so we would like to
keep this functionality.
Differential Revision: https://developer.blender.org/D8604
Reviewd by: Julian Eisel
This commit is contained in:
committed by
Julian Eisel
parent
97dc370c50
commit
83c78529b9
@@ -31,8 +31,13 @@ struct Main;
|
||||
/* info_stats.c */
|
||||
void ED_info_stats_clear(struct ViewLayer *view_layer);
|
||||
const char *ED_info_statusbar_string(struct Main *bmain,
|
||||
struct bScreen *screen,
|
||||
struct bContext *C);
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer);
|
||||
|
||||
const char *ED_info_statistics_string(struct Main *bmain,
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer);
|
||||
|
||||
void ED_info_draw_stats(
|
||||
struct Main *bmain, Scene *scene, ViewLayer *view_layer, int x, int *y, int height);
|
||||
|
||||
|
||||
@@ -547,19 +547,20 @@ static void get_stats_string(
|
||||
info + *ofs, len - *ofs, TIP_(" | Objects:%s/%s"), stats_fmt->totobjsel, stats_fmt->totobj);
|
||||
}
|
||||
|
||||
const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C)
|
||||
static const char *info_statusbar_string(Main *bmain,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
char statusbar_flag)
|
||||
{
|
||||
char formatted_mem[15];
|
||||
size_t ofs = 0;
|
||||
char *info = screen->statusbar_info;
|
||||
int len = sizeof(screen->statusbar_info);
|
||||
static char info[256];
|
||||
int len = sizeof(info);
|
||||
|
||||
info[0] = '\0';
|
||||
|
||||
/* Scene statistics. */
|
||||
if (U.statusbar_flag & STATUSBAR_SHOW_STATS) {
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
if (statusbar_flag & STATUSBAR_SHOW_STATS) {
|
||||
SceneStatsFmt stats_fmt;
|
||||
if (format_stats(bmain, scene, view_layer, &stats_fmt)) {
|
||||
get_stats_string(info + ofs, len, &ofs, view_layer, &stats_fmt);
|
||||
@@ -567,7 +568,7 @@ const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C)
|
||||
}
|
||||
|
||||
/* Memory status. */
|
||||
if (U.statusbar_flag & STATUSBAR_SHOW_MEMORY) {
|
||||
if (statusbar_flag & STATUSBAR_SHOW_MEMORY) {
|
||||
if (info[0]) {
|
||||
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
|
||||
}
|
||||
@@ -577,7 +578,7 @@ const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C)
|
||||
}
|
||||
|
||||
/* GPU VRAM status. */
|
||||
if ((U.statusbar_flag & STATUSBAR_SHOW_VRAM) && (GPU_mem_stats_supported())) {
|
||||
if ((statusbar_flag & STATUSBAR_SHOW_VRAM) && (GPU_mem_stats_supported())) {
|
||||
int gpu_free_mem_kb, gpu_tot_mem_kb;
|
||||
GPU_mem_stats_get(&gpu_tot_mem_kb, &gpu_free_mem_kb);
|
||||
float gpu_total_gb = gpu_tot_mem_kb / 1048576.0f;
|
||||
@@ -599,7 +600,7 @@ const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C)
|
||||
}
|
||||
|
||||
/* Blender version. */
|
||||
if (U.statusbar_flag & STATUSBAR_SHOW_VERSION) {
|
||||
if (statusbar_flag & STATUSBAR_SHOW_VERSION) {
|
||||
if (info[0]) {
|
||||
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
|
||||
}
|
||||
@@ -609,6 +610,20 @@ const char *ED_info_statusbar_string(Main *bmain, bScreen *screen, bContext *C)
|
||||
return info;
|
||||
}
|
||||
|
||||
const char *ED_info_statusbar_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
{
|
||||
return info_statusbar_string(bmain, scene, view_layer, U.statusbar_flag);
|
||||
}
|
||||
|
||||
const char *ED_info_statistics_string(Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
{
|
||||
const eUserpref_StatusBar_Flag statistics_status_bar_flag = STATUSBAR_SHOW_STATS |
|
||||
STATUSBAR_SHOW_MEMORY |
|
||||
STATUSBAR_SHOW_VERSION;
|
||||
|
||||
return info_statusbar_string(bmain, scene, view_layer, statistics_status_bar_flag);
|
||||
}
|
||||
|
||||
static void stats_row(int col1,
|
||||
const char *key,
|
||||
int col2,
|
||||
|
||||
@@ -68,8 +68,6 @@ typedef struct bScreen {
|
||||
/** User-setting for which editors get redrawn during anim playback. */
|
||||
short redraws_flag;
|
||||
|
||||
char statusbar_info[256];
|
||||
|
||||
/** Temp screen in a temp window, don't save (like user prefs). */
|
||||
char temp;
|
||||
/** Temp screen for image render display or fileselect. */
|
||||
|
||||
@@ -924,6 +924,13 @@ static void rna_Scene_volume_update(Main *UNUSED(bmain), Scene *UNUSED(scene), P
|
||||
DEG_id_tag_update(&scene->id, ID_RECALC_AUDIO_VOLUME | ID_RECALC_SEQUENCER_STRIPS);
|
||||
}
|
||||
|
||||
static const char *rna_Scene_statistics_string_get(Scene *scene,
|
||||
Main *bmain,
|
||||
ViewLayer *view_layer)
|
||||
{
|
||||
return ED_info_statistics_string(bmain, scene, view_layer);
|
||||
}
|
||||
|
||||
static void rna_Scene_framelen_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
|
||||
{
|
||||
scene->r.framelen = (float)scene->r.framapto / (float)scene->r.images;
|
||||
@@ -7277,6 +7284,9 @@ void RNA_def_scene(BlenderRNA *brna)
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
FunctionRNA *func;
|
||||
PropertyRNA *parm;
|
||||
|
||||
static const EnumPropertyItem audio_distance_model_items[] = {
|
||||
{0, "NONE", 0, "None", "No distance attenuation"},
|
||||
{1, "INVERSE", 0, "Inverse", "Inverse distance model"},
|
||||
@@ -7668,6 +7678,14 @@ void RNA_def_scene(BlenderRNA *brna)
|
||||
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||
RNA_def_property_update(prop, NC_SCENE, "rna_Scene_volume_update");
|
||||
|
||||
/* Statistics */
|
||||
func = RNA_def_function(srna, "statistics", "rna_Scene_statistics_string_get");
|
||||
RNA_def_function_flag(func, FUNC_USE_MAIN);
|
||||
parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "View Layer", "");
|
||||
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
|
||||
parm = RNA_def_string(func, "statistics", NULL, 0, "Statistics", "");
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* Grease Pencil */
|
||||
prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "gpd");
|
||||
|
||||
@@ -288,9 +288,11 @@ static void rna_View2D_view_to_region(
|
||||
}
|
||||
}
|
||||
|
||||
static const char *rna_Screen_statusbar_info_get(struct bScreen *screen, Main *bmain, bContext *C)
|
||||
static const char *rna_Screen_statusbar_info_get(struct bScreen *UNUSED(screen),
|
||||
Main *bmain,
|
||||
bContext *C)
|
||||
{
|
||||
return ED_info_statusbar_string(bmain, screen, C);
|
||||
return ED_info_statusbar_string(bmain, CTX_data_scene(C), CTX_data_view_layer(C));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user