Cleanup: Remove unused variable, use switch, and C++ casting.

This commit is contained in:
Bastien Montagne 2023-01-30 15:40:29 +01:00
parent aca9c131fc
commit 1a50f814e6
1 changed files with 218 additions and 191 deletions

View File

@ -2299,11 +2299,11 @@ static bool lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
{
IDNameLib_Map *id_map = static_cast<IDNameLib_Map *>(arg_pt);
lib_link_seq_clipboard_pt_restore((ID *)seq->scene, id_map);
lib_link_seq_clipboard_pt_restore((ID *)seq->scene_camera, id_map);
lib_link_seq_clipboard_pt_restore((ID *)seq->clip, id_map);
lib_link_seq_clipboard_pt_restore((ID *)seq->mask, id_map);
lib_link_seq_clipboard_pt_restore((ID *)seq->sound, id_map);
lib_link_seq_clipboard_pt_restore(reinterpret_cast<ID *>(seq->scene), id_map);
lib_link_seq_clipboard_pt_restore(reinterpret_cast<ID *>(seq->scene_camera), id_map);
lib_link_seq_clipboard_pt_restore(reinterpret_cast<ID *>(seq->clip), id_map);
lib_link_seq_clipboard_pt_restore(reinterpret_cast<ID *>(seq->mask), id_map);
lib_link_seq_clipboard_pt_restore(reinterpret_cast<ID *>(seq->sound), id_map);
return true;
}
@ -2325,7 +2325,7 @@ static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data)
/* We probably need to add more cases here (hint: nodetrees),
* but will wait for changes from D5559 to get in first. */
if (GS((*id_pointer)->name) == ID_GR) {
Collection *collection = (Collection *)*id_pointer;
Collection *collection = reinterpret_cast<Collection *>(*id_pointer);
if (collection->flag & COLLECTION_IS_MASTER) {
/* We should never reach that point anymore, since master collection private ID should be
* properly tagged with IDWALK_CB_EMBEDDED. */
@ -2357,7 +2357,7 @@ static void lib_link_main_data_restore(IDNameLib_Map *id_map, Main *newmain)
static void lib_link_wm_xr_data_restore(IDNameLib_Map *id_map, wmXrData *xr_data)
{
xr_data->session_settings.base_pose_object = static_cast<Object *>(restore_pointer_by_name(
id_map, (ID *)xr_data->session_settings.base_pose_object, USER_REAL));
id_map, reinterpret_cast<ID *>(xr_data->session_settings.base_pose_object), USER_REAL));
}
static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, ViewLayer *view_layer)
@ -2367,7 +2367,7 @@ static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene, View
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
View3D *v3d = reinterpret_cast<View3D *>(sl);
if (v3d->camera == nullptr || v3d->scenelock) {
v3d->camera = scene->camera;
@ -2416,7 +2416,7 @@ static void lib_link_restore_viewer_path(IDNameLib_Map *id_map, ViewerPath *view
if (elem->type == VIEWER_PATH_ELEM_TYPE_ID) {
IDViewerPathElem *typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
typed_elem->id = static_cast<ID *>(
restore_pointer_by_name(id_map, (ID *)typed_elem->id, USER_IGNORE));
restore_pointer_by_name(id_map, typed_elem->id, USER_IGNORE));
}
}
}
@ -2431,225 +2431,253 @@ static void lib_link_workspace_layout_restore(IDNameLib_Map *id_map,
{
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
switch (static_cast<eSpace_Type>(sl->spacetype)) {
case SPACE_VIEW3D: {
View3D *v3d = reinterpret_cast<View3D *>(sl);
v3d->camera = static_cast<Object *>(
restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL));
v3d->ob_center = static_cast<Object *>(
restore_pointer_by_name(id_map, (ID *)v3d->ob_center, USER_REAL));
v3d->camera = static_cast<Object *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(v3d->camera), USER_REAL));
v3d->ob_center = static_cast<Object *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(v3d->ob_center), USER_REAL));
lib_link_restore_viewer_path(id_map, &v3d->viewer_path);
}
else if (sl->spacetype == SPACE_GRAPH) {
SpaceGraph *sipo = (SpaceGraph *)sl;
bDopeSheet *ads = sipo->ads;
lib_link_restore_viewer_path(id_map, &v3d->viewer_path);
break;
}
case SPACE_GRAPH: {
SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(sl);
bDopeSheet *ads = sipo->ads;
if (ads) {
ads->source = static_cast<ID *>(
restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL));
if (ads) {
ads->source = static_cast<ID *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(ads->source), USER_REAL));
if (ads->filter_grp) {
ads->filter_grp = static_cast<Collection *>(
restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE));
if (ads->filter_grp) {
ads->filter_grp = static_cast<Collection *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(ads->filter_grp), USER_IGNORE));
}
}
/* force recalc of list of channels (i.e. includes calculating F-Curve colors)
* thus preventing the "black curves" problem post-undo
*/
sipo->runtime.flag |= SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC_COLOR;
break;
}
case SPACE_PROPERTIES: {
SpaceProperties *sbuts = reinterpret_cast<SpaceProperties *>(sl);
sbuts->pinid = static_cast<ID *>(
restore_pointer_by_name(id_map, sbuts->pinid, USER_IGNORE));
if (sbuts->pinid == nullptr) {
sbuts->flag &= ~SB_PIN_CONTEXT;
}
/* force recalc of list of channels (i.e. includes calculating F-Curve colors)
* thus preventing the "black curves" problem post-undo
*/
sipo->runtime.flag |= SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC_COLOR;
}
else if (sl->spacetype == SPACE_PROPERTIES) {
SpaceProperties *sbuts = (SpaceProperties *)sl;
sbuts->pinid = static_cast<ID *>(
restore_pointer_by_name(id_map, sbuts->pinid, USER_IGNORE));
if (sbuts->pinid == nullptr) {
sbuts->flag &= ~SB_PIN_CONTEXT;
/* TODO: restore path pointers: T40046
* (complicated because this contains data pointers too, not just ID). */
MEM_SAFE_FREE(sbuts->path);
break;
}
/* TODO: restore path pointers: T40046
* (complicated because this contains data pointers too, not just ID). */
MEM_SAFE_FREE(sbuts->path);
}
else if (sl->spacetype == SPACE_FILE) {
SpaceFile *sfile = (SpaceFile *)sl;
sfile->op = nullptr;
sfile->tags = FILE_TAG_REBUILD_MAIN_FILES;
}
else if (sl->spacetype == SPACE_ACTION) {
SpaceAction *saction = (SpaceAction *)sl;
saction->action = static_cast<bAction *>(
restore_pointer_by_name(id_map, (ID *)saction->action, USER_REAL));
saction->ads.source = static_cast<ID *>(
restore_pointer_by_name(id_map, (ID *)saction->ads.source, USER_REAL));
if (saction->ads.filter_grp) {
saction->ads.filter_grp = static_cast<Collection *>(
restore_pointer_by_name(id_map, (ID *)saction->ads.filter_grp, USER_IGNORE));
case SPACE_FILE: {
SpaceFile *sfile = reinterpret_cast<SpaceFile *>(sl);
sfile->op = nullptr;
sfile->tags = FILE_TAG_REBUILD_MAIN_FILES;
break;
}
case SPACE_ACTION: {
SpaceAction *saction = reinterpret_cast<SpaceAction *>(sl);
/* force recalc of list of channels, potentially updating the active action
* while we're at it (as it can only be updated that way) T28962.
*/
saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
}
else if (sl->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)sl;
saction->action = static_cast<bAction *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(saction->action), USER_REAL));
saction->ads.source = static_cast<ID *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(saction->ads.source), USER_REAL));
sima->image = static_cast<Image *>(
restore_pointer_by_name(id_map, (ID *)sima->image, USER_REAL));
if (saction->ads.filter_grp) {
saction->ads.filter_grp = static_cast<Collection *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(saction->ads.filter_grp), USER_IGNORE));
}
/* this will be freed, not worth attempting to find same scene,
* since it gets initialized later */
sima->iuser.scene = nullptr;
/* force recalc of list of channels, potentially updating the active action
* while we're at it (as it can only be updated that way) T28962.
*/
saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
break;
}
case SPACE_IMAGE: {
SpaceImage *sima = reinterpret_cast<SpaceImage *>(sl);
sima->image = static_cast<Image *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(sima->image), USER_REAL));
/* this will be freed, not worth attempting to find same scene,
* since it gets initialized later */
sima->iuser.scene = nullptr;
#if 0
/* Those are allocated and freed by space code, no need to handle them here. */
MEM_SAFE_FREE(sima->scopes.waveform_1);
MEM_SAFE_FREE(sima->scopes.waveform_2);
MEM_SAFE_FREE(sima->scopes.waveform_3);
MEM_SAFE_FREE(sima->scopes.vecscope);
/* Those are allocated and freed by space code, no need to handle them here. */
MEM_SAFE_FREE(sima->scopes.waveform_1);
MEM_SAFE_FREE(sima->scopes.waveform_2);
MEM_SAFE_FREE(sima->scopes.waveform_3);
MEM_SAFE_FREE(sima->scopes.vecscope);
#endif
sima->scopes.ok = 0;
sima->scopes.ok = 0;
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
sima->gpd = static_cast<bGPdata *>(
restore_pointer_by_name(id_map, (ID *)sima->gpd, USER_REAL));
sima->mask_info.mask = static_cast<Mask *>(
restore_pointer_by_name(id_map, (ID *)sima->mask_info.mask, USER_REAL));
}
else if (sl->spacetype == SPACE_SEQ) {
SpaceSeq *sseq = (SpaceSeq *)sl;
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
sima->gpd = static_cast<bGPdata *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(sima->gpd), USER_REAL));
sima->mask_info.mask = static_cast<Mask *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(sima->mask_info.mask), USER_REAL));
break;
}
case SPACE_SEQ: {
SpaceSeq *sseq = reinterpret_cast<SpaceSeq *>(sl);
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
sseq->gpd = static_cast<bGPdata *>(
restore_pointer_by_name(id_map, (ID *)sseq->gpd, USER_REAL));
}
else if (sl->spacetype == SPACE_NLA) {
SpaceNla *snla = (SpaceNla *)sl;
bDopeSheet *ads = snla->ads;
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
sseq->gpd = static_cast<bGPdata *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(sseq->gpd), USER_REAL));
break;
}
case SPACE_NLA: {
SpaceNla *snla = reinterpret_cast<SpaceNla *>(sl);
bDopeSheet *ads = snla->ads;
if (ads) {
ads->source = static_cast<ID *>(
restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL));
if (ads) {
ads->source = static_cast<ID *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(ads->source), USER_REAL));
if (ads->filter_grp) {
ads->filter_grp = static_cast<Collection *>(
restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE));
if (ads->filter_grp) {
ads->filter_grp = static_cast<Collection *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(ads->filter_grp), USER_IGNORE));
}
}
break;
}
}
else if (sl->spacetype == SPACE_TEXT) {
SpaceText *st = (SpaceText *)sl;
case SPACE_TEXT: {
SpaceText *st = reinterpret_cast<SpaceText *>(sl);
st->text = static_cast<Text *>(
restore_pointer_by_name(id_map, (ID *)st->text, USER_IGNORE));
if (st->text == nullptr) {
st->text = static_cast<Text *>(newmain->texts.first);
st->text = static_cast<Text *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(st->text), USER_IGNORE));
if (st->text == nullptr) {
st->text = static_cast<Text *>(newmain->texts.first);
}
} break;
case SPACE_SCRIPT: {
SpaceScript *scpt = reinterpret_cast<SpaceScript *>(sl);
scpt->script = static_cast<Script *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(scpt->script), USER_REAL));
// screen->script = nullptr; /* 2.45 set to null, better re-run the script. */
if (scpt->script) {
SCRIPT_SET_NULL(scpt->script);
}
break;
}
}
else if (sl->spacetype == SPACE_SCRIPT) {
SpaceScript *scpt = (SpaceScript *)sl;
case SPACE_OUTLINER: {
SpaceOutliner *space_outliner = reinterpret_cast<SpaceOutliner *>(sl);
scpt->script = static_cast<Script *>(
restore_pointer_by_name(id_map, (ID *)scpt->script, USER_REAL));
if (space_outliner->treestore) {
TreeStoreElem *tselem;
BLI_mempool_iter iter;
// screen->script = nullptr; /* 2.45 set to null, better re-run the script. */
if (scpt->script) {
SCRIPT_SET_NULL(scpt->script);
BLI_mempool_iternew(space_outliner->treestore, &iter);
while ((tselem = static_cast<TreeStoreElem *>(BLI_mempool_iterstep(&iter)))) {
/* Do not try to restore pointers to drivers/sequence/etc.,
* can crash in undo case! */
if (TSE_IS_REAL_ID(tselem)) {
tselem->id = static_cast<ID *>(
restore_pointer_by_name(id_map, tselem->id, USER_IGNORE));
}
else {
tselem->id = nullptr;
}
}
/* rebuild hash table, because it depends on ids too */
space_outliner->storeflag |= SO_TREESTORE_REBUILD;
}
break;
}
}
else if (sl->spacetype == SPACE_OUTLINER) {
SpaceOutliner *space_outliner = (SpaceOutliner *)sl;
case SPACE_NODE: {
SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
bNodeTreePath *path, *path_next;
bNodeTree *ntree;
if (space_outliner->treestore) {
TreeStoreElem *tselem;
BLI_mempool_iter iter;
/* node tree can be stored locally in id too, link this first */
snode->id = static_cast<ID *>(restore_pointer_by_name(id_map, snode->id, USER_REAL));
snode->from = static_cast<ID *>(
restore_pointer_by_name(id_map, snode->from, USER_IGNORE));
BLI_mempool_iternew(space_outliner->treestore, &iter);
while ((tselem = static_cast<TreeStoreElem *>(BLI_mempool_iterstep(&iter)))) {
/* Do not try to restore pointers to drivers/sequence/etc.,
* can crash in undo case! */
if (TSE_IS_REAL_ID(tselem)) {
tselem->id = static_cast<ID *>(
restore_pointer_by_name(id_map, tselem->id, USER_IGNORE));
ntree = snode->id ? ntreeFromID(snode->id) : nullptr;
snode->nodetree = ntree ?
ntree :
static_cast<bNodeTree *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(snode->nodetree), USER_REAL));
for (path = static_cast<bNodeTreePath *>(snode->treepath.first); path;
path = path->next) {
if (path == snode->treepath.first) {
/* first nodetree in path is same as snode->nodetree */
path->nodetree = snode->nodetree;
}
else {
tselem->id = nullptr;
path->nodetree = static_cast<bNodeTree *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(path->nodetree), USER_REAL));
}
if (!path->nodetree) {
break;
}
}
/* rebuild hash table, because it depends on ids too */
space_outliner->storeflag |= SO_TREESTORE_REBUILD;
}
}
else if (sl->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)sl;
bNodeTreePath *path, *path_next;
bNodeTree *ntree;
/* node tree can be stored locally in id too, link this first */
snode->id = static_cast<ID *>(restore_pointer_by_name(id_map, snode->id, USER_REAL));
snode->from = static_cast<ID *>(
restore_pointer_by_name(id_map, snode->from, USER_IGNORE));
/* remaining path entries are invalid, remove */
for (; path; path = path_next) {
path_next = path->next;
ntree = snode->id ? ntreeFromID(snode->id) : nullptr;
snode->nodetree = ntree ? ntree :
static_cast<bNodeTree *>(restore_pointer_by_name(
id_map, (ID *)snode->nodetree, USER_REAL));
BLI_remlink(&snode->treepath, path);
MEM_freeN(path);
}
for (path = static_cast<bNodeTreePath *>(snode->treepath.first); path;
path = path->next) {
if (path == snode->treepath.first) {
/* first nodetree in path is same as snode->nodetree */
path->nodetree = snode->nodetree;
/* edittree is just the last in the path,
* set this directly since the path may have been shortened above */
if (snode->treepath.last) {
path = static_cast<bNodeTreePath *>(snode->treepath.last);
snode->edittree = path->nodetree;
}
else {
path->nodetree = static_cast<bNodeTree *>(
restore_pointer_by_name(id_map, (ID *)path->nodetree, USER_REAL));
}
if (!path->nodetree) {
break;
snode->edittree = nullptr;
}
break;
}
case SPACE_CLIP: {
SpaceClip *sclip = reinterpret_cast<SpaceClip *>(sl);
/* remaining path entries are invalid, remove */
for (; path; path = path_next) {
path_next = path->next;
sclip->clip = static_cast<MovieClip *>(
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(sclip->clip), USER_REAL));
sclip->mask_info.mask = static_cast<Mask *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(sclip->mask_info.mask), USER_REAL));
BLI_remlink(&snode->treepath, path);
MEM_freeN(path);
sclip->scopes.ok = 0;
break;
}
/* edittree is just the last in the path,
* set this directly since the path may have been shortened above */
if (snode->treepath.last) {
path = static_cast<bNodeTreePath *>(snode->treepath.last);
snode->edittree = path->nodetree;
case SPACE_SPREADSHEET: {
SpaceSpreadsheet *sspreadsheet = reinterpret_cast<SpaceSpreadsheet *>(sl);
lib_link_restore_viewer_path(id_map, &sspreadsheet->viewer_path);
break;
}
else {
snode->edittree = nullptr;
}
}
else if (sl->spacetype == SPACE_CLIP) {
SpaceClip *sclip = (SpaceClip *)sl;
sclip->clip = static_cast<MovieClip *>(
restore_pointer_by_name(id_map, (ID *)sclip->clip, USER_REAL));
sclip->mask_info.mask = static_cast<Mask *>(
restore_pointer_by_name(id_map, (ID *)sclip->mask_info.mask, USER_REAL));
sclip->scopes.ok = 0;
}
else if (sl->spacetype == SPACE_SPREADSHEET) {
SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl;
lib_link_restore_viewer_path(id_map, &sspreadsheet->viewer_path);
case SPACE_INFO:
case SPACE_IMASEL:
case SPACE_SOUND:
case SPACE_TIME:
case SPACE_LOGIC:
case SPACE_CONSOLE:
case SPACE_USERPREF:
case SPACE_TOPBAR:
case SPACE_STATUSBAR:
case SPACE_EMPTY:
/* Nothing to do here. */
break;
}
}
}
@ -2668,25 +2696,24 @@ void blo_lib_link_restore(Main *oldmain,
LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
lib_link_workspace_layout_restore(id_map, newmain, layout);
}
workspace->pin_scene = static_cast<Scene *>(
restore_pointer_by_name(id_map, (ID *)workspace->pin_scene, USER_IGNORE));
workspace->pin_scene = static_cast<Scene *>(restore_pointer_by_name(
id_map, reinterpret_cast<ID *>(workspace->pin_scene), USER_IGNORE));
lib_link_restore_viewer_path(id_map, &workspace->viewer_path);
}
LISTBASE_FOREACH (wmWindow *, win, &curwm->windows) {
WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
ID *workspace_id = (ID *)workspace;
Scene *oldscene = win->scene;
ID *workspace_id = reinterpret_cast<ID *>(workspace);
workspace = static_cast<WorkSpace *>(restore_pointer_by_name(id_map, workspace_id, USER_REAL));
BKE_workspace_active_set(win->workspace_hook, workspace);
win->scene = static_cast<Scene *>(
restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL));
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(win->scene), USER_REAL));
if (win->scene == nullptr) {
win->scene = curscene;
}
win->unpinned_scene = static_cast<Scene *>(
restore_pointer_by_name(id_map, (ID *)win->unpinned_scene, USER_IGNORE));
restore_pointer_by_name(id_map, reinterpret_cast<ID *>(win->unpinned_scene), USER_IGNORE));
if (BKE_view_layer_find(win->scene, win->view_layer_name) == nullptr) {
STRNCPY(win->view_layer_name, cur_view_layer->name);
}