Draw outdated point cache in a lighter color
[blender.git] / source / blender / editors / space_time / space_time.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_time/space_time.c
28  *  \ingroup sptime
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_dlrbTree.h"
42 #include "BLI_utildefines.h"
43
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.h"
47 #include "BKE_pointcache.h"
48
49 #include "ED_anim_api.h"
50 #include "ED_keyframes_draw.h"
51 #include "ED_screen.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "BIF_gl.h"
57 #include "BIF_glutil.h"
58
59 #include "UI_resources.h"
60 #include "UI_view2d.h"
61
62 #include "ED_space_api.h"
63 #include "ED_markers.h"
64
65 #include "time_intern.h"
66
67 /* ************************ main time area region *********************** */
68
69 static void time_draw_sfra_efra(Scene *scene, View2D *v2d)
70 {       
71         /* draw darkened area outside of active timeline 
72          * frame range used is preview range or scene range 
73          */
74         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
75         glEnable(GL_BLEND);
76         glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
77                 
78         if (PSFRA < PEFRA) {
79                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
80                 glRectf((float)PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
81         }
82         else {
83                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
84         }
85         glDisable(GL_BLEND);
86
87         UI_ThemeColorShade(TH_BACK, -60);
88         /* thin lines where the actual frames are */
89         fdrawline((float)PSFRA, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
90         fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
91 }
92
93 #define CACHE_DRAW_HEIGHT   3.0f
94
95 static void time_draw_cache(SpaceTime *stime, Object *ob)
96 {
97         PTCacheID *pid;
98         ListBase pidlist;
99         SpaceTimeCache *stc = stime->caches.first;
100         float yoffs = 0.f;
101         
102         if (!(stime->cache_display & TIME_CACHE_DISPLAY) || (!ob))
103                 return;
104
105         BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
106
107         /* iterate over pointcaches on the active object, 
108          * add spacetimecache and vertex array for each */
109         for (pid = pidlist.first; pid; pid = pid->next) {
110                 float col[4], *fp;
111                 int i, sta = pid->cache->startframe, end = pid->cache->endframe;
112                 int len = (end - sta + 1) * 4;
113
114                 switch (pid->type) {
115                         case PTCACHE_TYPE_SOFTBODY:
116                                 if (!(stime->cache_display & TIME_CACHE_SOFTBODY)) continue;
117                                 break;
118                         case PTCACHE_TYPE_PARTICLES:
119                                 if (!(stime->cache_display & TIME_CACHE_PARTICLES)) continue;
120                                 break;
121                         case PTCACHE_TYPE_CLOTH:
122                                 if (!(stime->cache_display & TIME_CACHE_CLOTH)) continue;
123                                 break;
124                         case PTCACHE_TYPE_SMOKE_DOMAIN:
125                         case PTCACHE_TYPE_SMOKE_HIGHRES:
126                                 if (!(stime->cache_display & TIME_CACHE_SMOKE)) continue;
127                                 break;
128                         case PTCACHE_TYPE_DYNAMICPAINT:
129                                 if (!(stime->cache_display & TIME_CACHE_DYNAMICPAINT)) continue;
130                                 break;
131                 }
132
133                 if (pid->cache->cached_frames == NULL)
134                         continue;
135
136                 /* make sure we have stc with correct array length */
137                 if (stc == NULL || MEM_allocN_len(stc->array) != len * 2 * sizeof(float)) {
138                         if (stc) {
139                                 MEM_freeN(stc->array);
140                         }
141                         else {
142                                 stc = MEM_callocN(sizeof(SpaceTimeCache), "spacetimecache");
143                                 BLI_addtail(&stime->caches, stc);
144                         }
145
146                         stc->array = MEM_callocN(len * 2 * sizeof(float), "SpaceTimeCache array");
147                 }
148
149                 /* fill the vertex array with a quad for each cached frame */
150                 for (i = sta, fp = stc->array; i <= end; i++) {
151                         if (pid->cache->cached_frames[i - sta]) {
152                                 fp[0] = (float)i - 0.5f;
153                                 fp[1] = 0.0;
154                                 fp += 2;
155                                 
156                                 fp[0] = (float)i - 0.5f;
157                                 fp[1] = 1.0;
158                                 fp += 2;
159                                 
160                                 fp[0] = (float)i + 0.5f;
161                                 fp[1] = 1.0;
162                                 fp += 2;
163                                 
164                                 fp[0] = (float)i + 0.5f;
165                                 fp[1] = 0.0;
166                                 fp += 2;
167                         }
168                 }
169                 
170                 glPushMatrix();
171                 glTranslatef(0.0, (float)V2D_SCROLL_HEIGHT + yoffs, 0.0);
172                 glScalef(1.0, CACHE_DRAW_HEIGHT, 0.0);
173                 
174                 switch (pid->type) {
175                         case PTCACHE_TYPE_SOFTBODY:
176                                 col[0] = 1.0;   col[1] = 0.4;   col[2] = 0.02;
177                                 col[3] = 0.1;
178                                 break;
179                         case PTCACHE_TYPE_PARTICLES:
180                                 col[0] = 1.0;   col[1] = 0.1;   col[2] = 0.02;
181                                 col[3] = 0.1;
182                                 break;
183                         case PTCACHE_TYPE_CLOTH:
184                                 col[0] = 0.1;   col[1] = 0.1;   col[2] = 0.75;
185                                 col[3] = 0.1;
186                                 break;
187                         case PTCACHE_TYPE_SMOKE_DOMAIN:
188                         case PTCACHE_TYPE_SMOKE_HIGHRES:
189                                 col[0] = 0.2;   col[1] = 0.2;   col[2] = 0.2;
190                                 col[3] = 0.1;
191                                 break;
192                         case PTCACHE_TYPE_DYNAMICPAINT:
193                                 col[0] = 1.0;   col[1] = 0.1;   col[2] = 0.75;
194                                 col[3] = 0.1;
195                                 break;
196                         default:
197                                 BLI_assert(0);
198                                 col[0] = 1.0;   col[1] = 0.0;   col[2] = 1.0;
199                                 col[3] = 0.1;
200                 }
201                 glColor4fv(col);
202                 
203                 glEnable(GL_BLEND);
204                 
205                 glRectf((float)sta, 0.0, (float)end, 1.0);
206                 
207                 col[3] = 0.4f;
208                 if (pid->cache->flag & PTCACHE_BAKED) {
209                         col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f;
210                 }
211                 else if (pid->cache->flag & PTCACHE_OUTDATED) {
212                         col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f;
213                 }
214                 glColor4fv(col);
215                 
216                 glEnableClientState(GL_VERTEX_ARRAY);
217                 glVertexPointer(2, GL_FLOAT, 0, stc->array);
218                 glDrawArrays(GL_QUADS, 0, (fp - stc->array) / 2);
219                 glDisableClientState(GL_VERTEX_ARRAY);
220                 
221                 glDisable(GL_BLEND);
222                 
223                 glPopMatrix();
224                 
225                 yoffs += CACHE_DRAW_HEIGHT;
226
227                 stc = stc->next;
228         }
229
230         BLI_freelistN(&pidlist);
231
232         /* free excessive caches */
233         while (stc) {
234                 SpaceTimeCache *tmp = stc->next;
235                 BLI_remlink(&stime->caches, stc);
236                 MEM_freeN(stc->array);
237                 MEM_freeN(stc);
238                 stc = tmp;
239         }
240 }
241
242 static void time_cache_free(SpaceTime *stime)
243 {
244         SpaceTimeCache *stc;
245         
246         for (stc = stime->caches.first; stc; stc = stc->next) {
247                 if (stc->array) {
248                         MEM_freeN(stc->array);
249                         stc->array = NULL;
250                 }
251         }
252         
253         BLI_freelistN(&stime->caches);
254 }
255
256 static void time_cache_refresh(SpaceTime *stime)
257 {
258         /* Free previous caches to indicate full refresh */
259         time_cache_free(stime);
260 }
261
262 /* helper function - find actkeycolumn that occurs on cframe, or the nearest one if not found */
263 static ActKeyColumn *time_cfra_find_ak(ActKeyColumn *ak, float cframe)
264 {
265         ActKeyColumn *akn = NULL;
266         
267         /* sanity checks */
268         if (ak == NULL)
269                 return NULL;
270         
271         /* check if this is a match, or whether it is in some subtree */
272         if (cframe < ak->cfra)
273                 akn = time_cfra_find_ak(ak->left, cframe);
274         else if (cframe > ak->cfra)
275                 akn = time_cfra_find_ak(ak->right, cframe);
276                 
277         /* if no match found (or found match), just use the current one */
278         if (akn == NULL)
279                 return ak;
280         else
281                 return akn;
282 }
283
284 /* helper for time_draw_keyframes() */
285 static void time_draw_idblock_keyframes(View2D *v2d, ID *id, short onlysel)
286 {
287         bDopeSheet ads = {NULL};
288         DLRBT_Tree keys;
289         ActKeyColumn *ak;
290         
291         /* init binarytree-list for getting keyframes */
292         BLI_dlrbTree_init(&keys);
293         
294         /* init dopesheet settings */
295         if (onlysel)
296                 ads.filterflag |= ADS_FILTER_ONLYSEL;
297         
298         /* populate tree with keyframe nodes */
299         switch (GS(id->name)) {
300                 case ID_SCE:
301                         scene_to_keylist(&ads, (Scene *)id, &keys, NULL);
302                         break;
303                 case ID_OB:
304                         ob_to_keylist(&ads, (Object *)id, &keys, NULL);
305                         break;
306         }
307                 
308         /* build linked-list for searching */
309         BLI_dlrbTree_linkedlist_sync(&keys);
310         
311         /* start drawing keyframes 
312          *      - we use the binary-search capabilities of the tree to only start from 
313          *        the first visible keyframe (last one can then be easily checked)
314          *      - draw within a single GL block to be faster
315          */
316         glBegin(GL_LINES);
317         for (ak = time_cfra_find_ak(keys.root, v2d->cur.xmin);
318              (ak) && (ak->cfra <= v2d->cur.xmax);
319              ak = ak->next)
320         {
321                 glVertex2f(ak->cfra, v2d->tot.ymin);
322                 glVertex2f(ak->cfra, v2d->tot.ymax);
323         }
324         glEnd(); // GL_LINES
325                 
326         /* free temp stuff */
327         BLI_dlrbTree_free(&keys);
328 }
329
330 /* draw keyframe lines for timeline */
331 static void time_draw_keyframes(const bContext *C, SpaceTime *stime, ARegion *ar)
332 {
333         Scene *scene = CTX_data_scene(C);
334         Object *ob = CTX_data_active_object(C);
335         View2D *v2d = &ar->v2d;
336         short onlysel = (stime->flag & TIME_ONLYACTSEL);
337         
338         /* draw scene keyframes first 
339          *      - don't try to do this when only drawing active/selected data keyframes,
340          *        since this can become quite slow
341          */
342         if (scene && onlysel == 0) {
343                 /* set draw color */
344                 glColor3ub(0xDD, 0xA7, 0x00);
345                 time_draw_idblock_keyframes(v2d, (ID *)scene, onlysel);
346         }
347         
348         /* draw keyframes from selected objects 
349          *  - only do the active object if in posemode (i.e. showing only keyframes for the bones)
350          *    OR the onlysel flag was set, which means that only active object's keyframes should
351          *    be considered
352          */
353         glColor3ub(0xDD, 0xD7, 0x00);
354         
355         if (ob && ((ob->mode == OB_MODE_POSE) || onlysel)) {
356                 /* draw keyframes for active object only */
357                 time_draw_idblock_keyframes(v2d, (ID *)ob, onlysel);
358         }
359         else {
360                 short active_done = FALSE;
361                 
362                 /* draw keyframes from all selected objects */
363                 CTX_DATA_BEGIN (C, Object *, obsel, selected_objects)
364                 {
365                         /* last arg is 0, since onlysel doesn't apply here... */
366                         time_draw_idblock_keyframes(v2d, (ID *)obsel, 0);
367                         
368                         /* if this object is the active one, set flag so that we don't draw again */
369                         if (obsel == ob)
370                                 active_done = TRUE;
371                 }
372                 CTX_DATA_END;
373                 
374                 /* if active object hasn't been done yet, draw it... */
375                 if (ob && (active_done == 0))
376                         time_draw_idblock_keyframes(v2d, (ID *)ob, 0);
377         }
378 }
379
380 /* ---------------- */
381
382 static void time_refresh(const bContext *UNUSED(C), ScrArea *sa)
383 {
384         /* find the main timeline region and refresh cache display*/
385         ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
386         if (ar) {
387                 SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
388                 time_cache_refresh(stime);
389         }
390 }
391
392 /* editor level listener */
393 static void time_listener(ScrArea *sa, wmNotifier *wmn)
394 {
395
396         /* mainly for updating cache display */
397         switch (wmn->category) {
398                 case NC_OBJECT:
399                         switch (wmn->data) {
400                                 case ND_BONE_ACTIVE:
401                                 case ND_POINTCACHE:
402                                 case ND_MODIFIER:
403                                 case ND_PARTICLE:
404                                         ED_area_tag_refresh(sa);
405                                         ED_area_tag_redraw(sa);
406                                         break;
407                         }
408                         break;
409                 case NC_SCENE:
410                         switch (wmn->data) {
411                                 case ND_OB_ACTIVE:
412                                 case ND_FRAME:
413                                         ED_area_tag_refresh(sa);
414                                         break;
415                                 case ND_FRAME_RANGE:
416                                 {
417                                         ARegion *ar;
418                                         Scene *scene = wmn->reference;
419
420                                         for (ar = sa->regionbase.first; ar; ar = ar->next) {
421                                                 if (ar->regiontype == RGN_TYPE_WINDOW) {
422                                                         ar->v2d.tot.xmin = (float)(SFRA - 4);
423                                                         ar->v2d.tot.xmax = (float)(EFRA + 4);
424                                                         break;
425                                                 }
426                                         }
427                                 }
428                                 break;
429                         }
430                 case NC_SPACE:
431                         switch (wmn->data) {
432                                 case ND_SPACE_CHANGED:
433                                         ED_area_tag_refresh(sa);
434                                         break;
435                         }
436                 case NC_WM:
437                         switch (wmn->data) {
438                                 case ND_FILEREAD:
439                                         ED_area_tag_refresh(sa);
440                                         break;
441                         }
442         }
443 }
444
445 /* ---------------- */
446
447 /* add handlers, stuff you only do once or on area/region changes */
448 static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
449 {
450         wmKeyMap *keymap;
451         
452         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
453         
454         /* own keymap */
455         keymap = WM_keymap_find(wm->defaultconf, "Timeline", SPACE_TIME, 0);
456         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
457 }
458
459 static void time_main_area_draw(const bContext *C, ARegion *ar)
460 {
461         /* draw entirely, view changes should be handled here */
462         Scene *scene = CTX_data_scene(C);
463         SpaceTime *stime = CTX_wm_space_time(C);
464         Object *obact = CTX_data_active_object(C);
465         View2D *v2d = &ar->v2d;
466         View2DGrid *grid;
467         View2DScrollers *scrollers;
468         int unit, flag = 0;
469         
470         /* clear and setup matrix */
471         UI_ThemeClearColor(TH_BACK);
472         glClear(GL_COLOR_BUFFER_BIT);
473         
474         UI_view2d_view_ortho(v2d);
475         
476         /* grid */
477         unit = (stime->flag & TIME_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
478         grid = UI_view2d_grid_calc(scene, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
479         UI_view2d_grid_draw(v2d, grid, (V2D_VERTICAL_LINES | V2D_VERTICAL_AXIS));
480         UI_view2d_grid_free(grid);
481         
482         /* start and end frame */
483         time_draw_sfra_efra(scene, v2d);
484         
485         /* current frame */
486         flag = DRAWCFRA_WIDE; /* this is only really needed on frames where there's a keyframe, but this will do... */
487         if ((stime->flag & TIME_DRAWFRAMES) == 0)  flag |= DRAWCFRA_UNIT_SECONDS;
488         if (stime->flag & TIME_CFRA_NUM)           flag |= DRAWCFRA_SHOW_NUMBOX;
489         ANIM_draw_cfra(C, v2d, flag);
490         
491         UI_view2d_view_ortho(v2d);
492         
493         /* keyframes */
494         time_draw_keyframes(C, stime, ar);
495         
496         /* markers */
497         UI_view2d_view_orthoSpecial(ar, v2d, 1);
498         draw_markers_time(C, 0);
499         
500         /* caches */
501         time_draw_cache(stime, obact);
502         
503         /* reset view matrix */
504         UI_view2d_view_restore(C);
505         
506         /* scrollers */
507         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
508         UI_view2d_scrollers_draw(C, v2d, scrollers);
509         UI_view2d_scrollers_free(scrollers);
510 }
511
512 static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
513 {
514         /* context changes */
515         switch (wmn->category) {
516                 case NC_SPACE:
517                         if (wmn->data == ND_SPACE_TIME)
518                                 ED_region_tag_redraw(ar);
519                         break;
520
521                 case NC_ANIMATION:
522                         ED_region_tag_redraw(ar);
523                         break;
524                 
525                 case NC_SCENE:
526                         switch (wmn->data) {
527                                 case ND_OB_SELECT:
528                                 case ND_OB_ACTIVE:
529                                 case ND_FRAME:
530                                 case ND_FRAME_RANGE:
531                                 case ND_KEYINGSET:
532                                 case ND_RENDER_OPTIONS:
533                                         ED_region_tag_redraw(ar);
534                                         break;
535                         }
536         }
537 }
538
539 /* ************************ header time area region *********************** */
540
541 /* add handlers, stuff you only do once or on area/region changes */
542 static void time_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
543 {
544         ED_region_header_init(ar);
545 }
546
547 static void time_header_area_draw(const bContext *C, ARegion *ar)
548 {
549         ED_region_header(C, ar);
550 }
551
552 static void time_header_area_listener(ARegion *ar, wmNotifier *wmn)
553 {
554         /* context changes */
555         switch (wmn->category) {
556                 case NC_SCREEN:
557                         if (wmn->data == ND_ANIMPLAY)
558                                 ED_region_tag_redraw(ar);
559                         break;
560
561                 case NC_SCENE:
562                         switch (wmn->data) {
563                                 case ND_OB_SELECT:
564                                 case ND_FRAME:
565                                 case ND_FRAME_RANGE:
566                                 case ND_KEYINGSET:
567                                 case ND_RENDER_OPTIONS:
568                                         ED_region_tag_redraw(ar);
569                                         break;
570                         }
571
572                 case NC_SPACE:
573                         if (wmn->data == ND_SPACE_TIME)
574                                 ED_region_tag_redraw(ar);
575                         break;
576         }
577 }
578
579 /* ******************** default callbacks for time space ***************** */
580
581 static SpaceLink *time_new(const bContext *C)
582 {
583         Scene *scene = CTX_data_scene(C);
584         ARegion *ar;
585         SpaceTime *stime;
586
587         stime = MEM_callocN(sizeof(SpaceTime), "inittime");
588
589         stime->spacetype = SPACE_TIME;
590         stime->flag |= TIME_DRAWFRAMES;
591
592         /* header */
593         ar = MEM_callocN(sizeof(ARegion), "header for time");
594         
595         BLI_addtail(&stime->regionbase, ar);
596         ar->regiontype = RGN_TYPE_HEADER;
597         ar->alignment = RGN_ALIGN_BOTTOM;
598         
599         /* main area */
600         ar = MEM_callocN(sizeof(ARegion), "main area for time");
601         
602         BLI_addtail(&stime->regionbase, ar);
603         ar->regiontype = RGN_TYPE_WINDOW;
604         
605         ar->v2d.tot.xmin = (float)(SFRA - 4);
606         ar->v2d.tot.ymin = 0.0f;
607         ar->v2d.tot.xmax = (float)(EFRA + 4);
608         ar->v2d.tot.ymax = 50.0f;
609         
610         ar->v2d.cur = ar->v2d.tot;
611
612         ar->v2d.min[0] = 1.0f;
613         ar->v2d.min[1] = 50.0f;
614
615         ar->v2d.max[0] = MAXFRAMEF;
616         ar->v2d.max[1] = 50.0;
617
618         ar->v2d.minzoom = 0.1f;
619         ar->v2d.maxzoom = 10.0;
620
621         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
622         ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
623         ar->v2d.keepofs |= V2D_LOCKOFS_Y;
624         ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
625
626
627         return (SpaceLink *)stime;
628 }
629
630 /* not spacelink itself */
631 static void time_free(SpaceLink *sl)
632 {
633         SpaceTime *stime = (SpaceTime *)sl;
634         
635         time_cache_free(stime);
636 }
637 /* spacetype; init callback in ED_area_initialize() */
638 /* init is called to (re)initialize an existing editor (file read, screen changes) */
639 /* validate spacedata, add own area level handlers */
640 static void time_init(wmWindowManager *UNUSED(wm), ScrArea *sa)
641 {
642         SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
643         
644         time_cache_free(stime);
645         
646         /* enable all cache display */
647         stime->cache_display |= TIME_CACHE_DISPLAY;
648         stime->cache_display |= (TIME_CACHE_SOFTBODY | TIME_CACHE_PARTICLES);
649         stime->cache_display |= (TIME_CACHE_CLOTH | TIME_CACHE_SMOKE | TIME_CACHE_DYNAMICPAINT);
650 }
651
652 static SpaceLink *time_duplicate(SpaceLink *sl)
653 {
654         SpaceTime *stime = (SpaceTime *)sl;
655         SpaceTime *stimen = MEM_dupallocN(stime);
656         
657         stimen->caches.first = stimen->caches.last = NULL;
658         
659         return (SpaceLink *)stimen;
660 }
661
662 /* only called once, from space_api/spacetypes.c */
663 /* it defines all callbacks to maintain spaces */
664 void ED_spacetype_time(void)
665 {
666         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype time");
667         ARegionType *art;
668         
669         st->spaceid = SPACE_TIME;
670         strncpy(st->name, "Timeline", BKE_ST_MAXNAME);
671         
672         st->new = time_new;
673         st->free = time_free;
674         st->init = time_init;
675         st->duplicate = time_duplicate;
676         st->operatortypes = time_operatortypes;
677         st->keymap = NULL;
678         st->listener = time_listener;
679         st->refresh = time_refresh;
680         
681         /* regions: main window */
682         art = MEM_callocN(sizeof(ARegionType), "spacetype time region");
683         art->regionid = RGN_TYPE_WINDOW;
684         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
685         
686         art->init = time_main_area_init;
687         art->draw = time_main_area_draw;
688         art->listener = time_main_area_listener;
689         art->keymap = time_keymap;
690         BLI_addhead(&st->regiontypes, art);
691         
692         /* regions: header */
693         art = MEM_callocN(sizeof(ARegionType), "spacetype time region");
694         art->regionid = RGN_TYPE_HEADER;
695         art->prefsizey = HEADERY;
696         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
697         
698         art->init = time_header_area_init;
699         art->draw = time_header_area_draw;
700         art->listener = time_header_area_listener;
701         BLI_addhead(&st->regiontypes, art);
702                 
703         BKE_spacetype_register(st);
704 }