# HG changeset patch # User Matti Hamalainen # Date 1350336564 -10800 # Node ID 882503ef7ab87516a07b6cd539e1965aa99209c3 # Parent cac13f180169a016b85924754ef92bcf4930e9c2 More work on timeline saving and loading. diff -r cac13f180169 -r 882503ef7ab8 dmtimeline.c --- a/dmtimeline.c Mon Oct 15 23:13:40 2012 +0300 +++ b/dmtimeline.c Tue Oct 16 00:29:24 2012 +0300 @@ -102,7 +102,7 @@ } -int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points) +int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points, int type) { int point; Uint32 npoints; @@ -125,10 +125,46 @@ DMTimelinePoint *pt = &(points->points[point]); Uint32 ptype, ptime; if (!dmf_read_le32(res, &ptype) || - !dmf_read_le32(res, &ptime) || - !dmLoadFloatValue(res, &pt->value)) + !dmf_read_le32(res, &ptime)) return DMERR_FREAD; + switch (type) + { + case EFPT_INT: + { + Uint32 tmp; + if (!dmf_read_le32(res, &tmp)) + return DMERR_FREAD; + pt->vint = tmp; + } + break; + + case EFPT_FLOAT: + if (!dmLoadFloatValue(res, &pt->vfloat)) + return DMERR_FREAD; + break; + + case EFPT_VECTOR: + if (!dmLoadFloatValue(res, &pt->vector.x) || + !dmLoadFloatValue(res, &pt->vector.y) || + !dmLoadFloatValue(res, &pt->vector.z) || + !dmLoadFloatValue(res, &pt->vector.W)) + return DMERR_FREAD; + break; + + case EFPT_MATRIX: + { + int x, y; + for (y = 0; y < DM_MATRIX_SIZE; y++) + for (x = 0; x < DM_MATRIX_SIZE; x++) + { + if (!dmLoadFloatValue(res, &(pt->matrix.m[y][x]))) + return DMERR_FREAD; + } + } + break; + } + pt->type = ptype; pt->time = ptime; } @@ -141,7 +177,6 @@ int err; DMFTimelineEventParam hdr; Uint16 len; - Uint32 tmp32; if (dmf_read_str(res, (Uint8 *) &hdr.name, sizeof(hdr.name)) != sizeof(hdr.name) || !dmf_read_le32(res, &hdr.type)) @@ -152,24 +187,16 @@ param->name = dm_strdup(hdr.name); param->type = hdr.type; - switch (hdr.type) + switch (param->type) { - case EFPT_POINTS: - if ((err = dmLoadTimelinePoints(res, ¶m->vpts)) != DMERR_OK) + case EFPT_INT: + case EFPT_FLOAT: + case EFPT_VECTOR: + case EFPT_MATRIX: + if ((err = dmLoadTimelinePoints(res, ¶m->vpts, param->type)) != DMERR_OK) return err; break; - - case EFPT_INT: - if (!dmf_read_le32(res, &tmp32)) - return DMERR_FREAD; - param->vint = tmp32; - break; - - case EFPT_FLOAT: - if (!dmLoadFloatValue(res, ¶m->vfloat)) - return DMERR_FREAD; - break; - + case EFPT_STRING: if (!dmf_read_le16(res, &len)) return DMERR_FREAD; @@ -243,7 +270,7 @@ int err; curve->enabled = dmfgetc(res); - if ((err = dmLoadTimelinePoints(res, &(curve->points))) != DMERR_OK) + if ((err = dmLoadTimelinePoints(res, &(curve->points), EFPT_FLOAT)) != DMERR_OK) return err; return DMERR_OK; diff -r cac13f180169 -r 882503ef7ab8 dmtimeline.h --- a/dmtimeline.h Mon Oct 15 23:13:40 2012 +0300 +++ b/dmtimeline.h Tue Oct 16 00:29:24 2012 +0300 @@ -3,6 +3,7 @@ #include "dmlib.h" #include "dmres.h" +#include "dmvecmat.h" #ifdef __cplusplus extern "C" { @@ -23,10 +24,11 @@ enum { - EFPT_POINTS, EFPT_INT, EFPT_FLOAT, EFPT_STRING, + EFPT_VECTOR, + EFPT_MATRIX, }; @@ -34,7 +36,11 @@ { int type; // Interpolation type (EFIT_*) between this and next point int time; // Offsets to event start, -1 == attach to event start, -2 = event end (if event) - DMFloat value; + + int vint; + DMFloat vfloat; + DMVector vector; + DMMatrix matrix; } DMTimelinePoint; @@ -51,8 +57,6 @@ int type; // Type (EFPT_*) char *vstr; - int vint; - DMFloat vfloat; DMTimelinePoints vpts; } DMTimelineEventParam; diff -r cac13f180169 -r 882503ef7ab8 dmtimelinew.c --- a/dmtimelinew.c Mon Oct 15 23:13:40 2012 +0300 +++ b/dmtimelinew.c Tue Oct 16 00:29:24 2012 +0300 @@ -10,7 +10,7 @@ } -int dmSaveTimelinePoints(DMResource *res, DMTimelinePoints *points) +int dmSaveTimelinePoints(DMResource *res, DMTimelinePoints *points, int type) { int point; Uint32 npoints; @@ -28,9 +28,41 @@ ptype = pt->type; ptime = pt->time; if (!dmf_write_le32(res, ptype) || - !dmf_write_le32(res, ptime) || - !dmSaveFloatValue(res, pt->value)) + !dmf_write_le32(res, ptime)) return DMERR_FWRITE; + + switch (type) + { + case EFPT_INT: + if (!dmf_write_le32(res, pt->vint)) + return DMERR_FWRITE; + break; + + case EFPT_FLOAT: + if (!dmSaveFloatValue(res, pt->vfloat)) + return DMERR_FWRITE; + break; + + case EFPT_VECTOR: + if (!dmSaveFloatValue(res, pt->vector.x) || + !dmSaveFloatValue(res, pt->vector.y) || + !dmSaveFloatValue(res, pt->vector.z) || + !dmSaveFloatValue(res, pt->vector.W)) + return DMERR_FWRITE; + break; + + case EFPT_MATRIX: + { + int x, y; + for (y = 0; y < DM_MATRIX_SIZE; y++) + for (x = 0; x < DM_MATRIX_SIZE; x++) + { + if (!dmSaveFloatValue(res, pt->matrix.m[y][x])) + return DMERR_FWRITE; + } + } + break; + } } return DMERR_OK; } @@ -41,7 +73,7 @@ int err; dmfputc(curve->enabled, res); - if ((err = dmSaveTimelinePoints(res, &(curve->points))) != DMERR_OK) + if ((err = dmSaveTimelinePoints(res, &(curve->points), EFPT_FLOAT)) != DMERR_OK) return err; return DMERR_OK; @@ -53,7 +85,6 @@ int err; DMFTimelineEventParam hdr; Uint16 len; - Uint32 tmp32; strncpy(hdr.name, param->name, sizeof(hdr.name)); hdr.type = param->type; @@ -64,22 +95,14 @@ switch (param->type) { - case EFPT_POINTS: - if ((err = dmSaveTimelinePoints(res, ¶m->vpts)) != DMERR_OK) + case EFPT_INT: + case EFPT_FLOAT: + case EFPT_VECTOR: + case EFPT_MATRIX: + if ((err = dmSaveTimelinePoints(res, ¶m->vpts, param->type)) != DMERR_OK) return err; break; - - case EFPT_INT: - tmp32 = param->vint; - if (!dmf_write_le32(res, tmp32)) - return DMERR_FWRITE; - break; - - case EFPT_FLOAT: - if (!dmSaveFloatValue(res, param->vfloat)) - return DMERR_FWRITE; - break; - + case EFPT_STRING: len = strlen(param->vstr); if (!dmf_write_le16(res, len)) @@ -108,7 +131,7 @@ !dmf_write_le32(res, hdr.duration) || dmf_write_str(res, (Uint8 *) hdr.effectName, sizeof(hdr.effectName)) != sizeof(hdr.effectName) || !dmf_write_le32(res, hdr.nparams)) - return DMERR_FREAD; + return DMERR_FWRITE; for (param = 0; param < event->nparams; param++) { @@ -258,8 +281,6 @@ pdst->name = dm_strdup(psrc->name); pdst->type = psrc->type; pdst->vstr = dm_strdup(psrc->vstr); - pdst->vint = psrc->vint; - pdst->vfloat = psrc->vfloat; if (psrc->vpts.points != NULL && psrc->vpts.npoints > 0) {