From a134d9ed517ef4173c1e8c19e77d652d52fe9258 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Thu, 7 Mar 2013 16:57:53 +0000 Subject: [PATCH] Speedup for Grease Pencil animators. Saving and loading gpencil was using different order for the individual list items. On a 120 Mb gpencil project (yes, animators!) loading time went down from 1 minute to a second or two. Note that this to have effect, you need to save once. Developer note: check this commit, it uses a new writelist function. You can speedup stuff tremendously with keeping saved and read data in sync. --- source/blender/blenloader/intern/writefile.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 5d6e79c0716..538f6368730 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -380,6 +380,17 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* if (len) mywrite(wd, adr, len); } +/* use this to force writing of lists in same order as reading (using link_list) */ +static void writelist(WriteData *wd, int filecode, const char *structname, ListBase *lb) +{ + Link *link = lb->first; + + while (link) { + writestruct(wd, filecode, structname, 1, link); + link = link->next; + } +} + /* *************** writing some direct data structs used in more code parts **************** */ /*These functions are used by blender's .blend system for file saving/loading.*/ void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd); @@ -2335,16 +2346,16 @@ static void write_gpencils(WriteData *wd, ListBase *lb) writestruct(wd, ID_GD, "bGPdata", 1, gpd); /* write grease-pencil layers to file */ + writelist(wd, DATA, "bGPDlayer", &gpd->layers); for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { - writestruct(wd, DATA, "bGPDlayer", 1, gpl); /* write this layer's frames to file */ + writelist(wd, DATA, "bGPDframe", &gpl->frames); for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { - writestruct(wd, DATA, "bGPDframe", 1, gpf); /* write strokes */ + writelist(wd, DATA, "bGPDstroke", &gpf->strokes); for (gps= gpf->strokes.first; gps; gps= gps->next) { - writestruct(wd, DATA, "bGPDstroke", 1, gps); writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); } }