changeset 324:f2b65aa474c9

More work on the timeline code.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 14 Oct 2012 16:13:31 +0300
parents e468ff7d0058
children 41889c480291
files dmtimeline.c dmtimeline.h
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dmtimeline.c	Sun Oct 14 14:30:53 2012 +0300
+++ b/dmtimeline.c	Sun Oct 14 16:13:31 2012 +0300
@@ -78,21 +78,48 @@
 }
 
 
-int dmLoadFloatValue(DMResource *res, DMFloat *val)
+BOOL dmLoadFloatValue(DMResource *res, DMFloat *val)
 {
     char tmp[DT_FLOAT_STORE_SIZE + 1];
     if (dmf_read_str(res, (Uint8 *) tmp, DT_FLOAT_STORE_SIZE) != DT_FLOAT_STORE_SIZE)
-        return DMERR_FREAD;
+        return FALSE;
 
     tmp[DT_FLOAT_STORE_SIZE] = 0;
     *val = atof(tmp);
-    return DMERR_OK;
+    return TRUE;
 }
 
 
 int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points)
 {
+    int point;
+    Uint32 npoints;
+
+    // Get number of points
+    if (!dmf_read_le32(res, &npoints))
+        return DMERR_FREAD;
+
+    // Calculate and allocate space
+    points->npoints = npoints;
+    points->nallocated = ((npoints / 16) + 1) * 16;
     
+    points->points = dmCalloc(npoints, sizeof(DMTimelinePoint));
+    if (points->points == NULL)
+        return DMERR_MALLOC;
+    
+    // Read points
+    for (point = 0; point < points->npoints; point++)
+    {
+        DMTimelinePoint *pt = &(points->points[point]);
+        Uint32 ptype, ptime;
+        if (!dmf_read_le32(res, &ptype) ||
+            !dmf_read_le32(res, &ptime) ||
+            !dmLoadFloatValue(res, &pt->value))
+            return DMERR_FREAD;
+        
+        pt->type = ptype;
+        pt->time = ptime;
+    }
     return DMERR_OK;
 }
 
@@ -100,7 +127,6 @@
 int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
 {
     DMFTimelineEventParam hdr;
-    int err;
     Uint16 len;
     Uint32 tmp32;
 
@@ -126,8 +152,8 @@
             break;
         
         case EFPT_FLOAT:
-            if ((err = dmLoadFloatValue(res, &param->vfloat)) != DMERR_OK)
-                return err;
+            if (!dmLoadFloatValue(res, &param->vfloat))
+                return DMERR_FREAD;
             break;
         
         case EFPT_STRING:
--- a/dmtimeline.h	Sun Oct 14 14:30:53 2012 +0300
+++ b/dmtimeline.h	Sun Oct 14 16:13:31 2012 +0300
@@ -13,6 +13,7 @@
 #define DT_MAX_NAME_LENGTH    32
 #define DT_FLOAT_STORE_SIZE   16
 
+
 enum
 {
     EFIT_SET,    // No interpolation, just "set" the value