Skip to content

Commit

Permalink
Blender 2.76 A update. Lag scrubbing with PlayAnim
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinerBforartists committed Nov 12, 2015
1 parent 9030c88 commit 94f401c
Showing 1 changed file with 46 additions and 29 deletions.
75 changes: 46 additions & 29 deletions source/blender/windowmanager/intern/wm_playanim.c
Expand Up @@ -383,7 +383,6 @@ static void build_pict_list_ex(PlayState *ps, const char *first, int totframes,
// short val;
PlayAnimPict *picture = NULL;
struct ImBuf *ibuf = NULL;
char str[32 + FILE_MAX];
struct anim *anim;

if (IMB_isanim(first)) {
Expand All @@ -402,8 +401,7 @@ static void build_pict_list_ex(PlayState *ps, const char *first, int totframes,
picture->anim = anim;
picture->frame = pic;
picture->IB_flags = IB_rect;
BLI_snprintf(str, sizeof(str), "%s : %4.d", first, pic + 1);
picture->name = strdup(str);
picture->name = BLI_sprintfN("%s : %4.d", first, pic + 1);
BLI_addtail(&picsbase, picture);
}
}
Expand All @@ -414,7 +412,14 @@ static void build_pict_list_ex(PlayState *ps, const char *first, int totframes,
else {
int count = 0;

int fp_framenr;
struct {
char head[FILE_MAX], tail[FILE_MAX];
unsigned short digits;
} fp_decoded;

BLI_strncpy(filepath, first, sizeof(filepath));
fp_framenr = BLI_stringdec(filepath, fp_decoded.head, fp_decoded.tail, &fp_decoded.digits);

pupdate_time();
ptottime = 1.0;
Expand Down Expand Up @@ -480,8 +485,8 @@ static void build_pict_list_ex(PlayState *ps, const char *first, int totframes,
}

picture->mem = mem;
picture->name = strdup(filepath);
picture->frame = count; /* not exact but should work for positioning */
picture->name = BLI_strdup(filepath);
picture->frame = count;
close(file);
BLI_addtail(&picsbase, picture);
count++;
Expand All @@ -505,7 +510,9 @@ static void build_pict_list_ex(PlayState *ps, const char *first, int totframes,
ptottime = 0.0;
}

BLI_newname(filepath, +fstep);
/* create a new filepath each time */
fp_framenr += fstep;
BLI_stringenc(filepath, fp_decoded.head, fp_decoded.tail, fp_decoded.digits, fp_framenr);

while ((hasevent = GHOST_ProcessEvents(g_WS.ghost_system, 0))) {
if (hasevent) {
Expand Down Expand Up @@ -544,17 +551,16 @@ static void update_sound_fps(void)
static void change_frame(PlayState *ps, int cx)
{
int sizex, sizey;
int i;
int i, i_last;

playanim_window_get_size(&sizex, &sizey);
ps->picture = picsbase.first;
/* TODO - store in ps direct? */
i = 0;
while (ps->picture) {
i++;
ps->picture = ps->picture->next;
if (BLI_listbase_is_empty(&picsbase)) {
return;
}
i = (i * cx) / sizex;

playanim_window_get_size(&sizex, &sizey);
i_last = ((struct PlayAnimPict *)picsbase.last)->frame;
i = (i_last * cx) / sizex;
CLAMP(i, 0, i_last);

#ifdef WITH_AUDASPACE
if (scrub_handle) {
Expand Down Expand Up @@ -588,11 +594,8 @@ static void change_frame(PlayState *ps, int cx)
}
#endif

ps->picture = picsbase.first;
for (; i > 0; i--) {
if (ps->picture->next == NULL) break;
ps->picture = ps->picture->next;
}
ps->picture = BLI_findlink(&picsbase, i);
BLI_assert(ps->picture != NULL);

ps->sstep = true;
ps->wait2 = false;
Expand Down Expand Up @@ -977,6 +980,19 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
GHOST_TEventCursorData *cd = GHOST_GetEventData(evt);
int cx, cy;

/* Ignore 'in-between' events, since they can make scrubbing lag.
*
* Ideally we would keep into the event queue and see if this is the last motion event.
* however the API currently doesn't support this. */
{
int x_test, y_test;
GHOST_GetCursorPosition(g_WS.ghost_system, &x_test, &y_test);
if (x_test != cd->x || y_test != cd->y) {
/* we're not the last event... skipping */
break;
}
}

GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy);

change_frame(ps, cx);
Expand Down Expand Up @@ -1093,7 +1109,6 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
GHOST_TUns32 maxwinx, maxwiny;
int i;
/* This was done to disambiguate the name for use under c++. */
struct anim *anim = NULL;
int start_x = 0, start_y = 0;
int sfra = -1;
int efra = -1;
Expand Down Expand Up @@ -1200,6 +1215,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)

if (IMB_isanim(filepath)) {
/* OCIO_TODO: support different input color spaces */
struct anim *anim;
anim = IMB_open_anim(filepath, IB_rect, 0, NULL);
if (anim) {
ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
Expand Down Expand Up @@ -1471,13 +1487,13 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
}
}
}
ps.picture = picsbase.first;
anim = NULL;
while (ps.picture) {
if (ps.picture && ps.picture->anim && (anim != ps.picture->anim)) {
// to prevent divx crashes
anim = ps.picture->anim;
IMB_close_anim(anim);
while ((ps.picture = BLI_pophead(&picsbase))) {
if (ps.picture->anim) {
if ((ps.picture->next == NULL) ||
(ps.picture->next->anim != ps.picture->anim))
{
IMB_close_anim(ps.picture->anim);
}
}

if (ps.picture->ibuf) {
Expand All @@ -1487,7 +1503,8 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
MEM_freeN(ps.picture->mem);
}

ps.picture = ps.picture->next;
MEM_freeN((void *)ps.picture->name);
MEM_freeN(ps.picture);
}

/* cleanup */
Expand Down

0 comments on commit 94f401c

Please sign in to comment.