Mercurial > hg > dmlib
diff dmtimelinew.c @ 346:882503ef7ab8
More work on timeline saving and loading.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 16 Oct 2012 00:29:24 +0300 |
parents | dd7b1356d726 |
children | f248defe7484 |
line wrap: on
line diff
--- 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) {