annotate src/dmtimeline.c @ 884:18cd96a27dee

API changes to be used in future.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Feb 2015 22:34:03 +0200
parents 27949209238b
children 985225a93aeb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
642
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 638
diff changeset
1 /*
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 638
diff changeset
2 * dmlib
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 638
diff changeset
3 * -- Timeline file loading and timeline processing/execution
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 638
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
863
27949209238b Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
5 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
642
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 638
diff changeset
6 */
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
7 #include "dmengine.h"
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
8
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
9
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
10 static BOOL dmLoadFloatValue(DMResource *res, DMFloat *val)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 char tmp[DT_FLOAT_STORE_SIZE + 1];
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
13 if (!dmf_read_str(res, &tmp, DT_FLOAT_STORE_SIZE))
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
14 return FALSE;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 tmp[DT_FLOAT_STORE_SIZE] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 *val = atof(tmp);
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
18 return TRUE;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
22 static int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points, int type)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 {
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
24 int point;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
25 Uint32 npoints;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
26
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
27 // Get number of points
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
28 if (!dmf_read_le32(res, &npoints))
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
29 return DMERR_FREAD;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
30
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
31 // Calculate and allocate space
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
32 points->npoints = npoints;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
33 points->nallocated = ((npoints / 16) + 1) * 16;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
396
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
35 points->points = dmCalloc(points->nallocated, sizeof(DMTimelinePoint));
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
36 if (points->points == NULL)
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
37 return DMERR_MALLOC;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
38
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
39 // Read points
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
40 for (point = 0; point < points->npoints; point++)
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
41 {
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
42 DMTimelinePoint *pt = &(points->points[point]);
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
43 Uint32 ptype, ptime;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
44 if (!dmf_read_le32(res, &ptype) ||
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
45 !dmf_read_le32(res, &ptime))
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
46 return DMERR_FREAD;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
47
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
48 switch (type)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
49 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
50 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
51 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
52 Uint32 tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
53 if (!dmf_read_le32(res, &tmp))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
54 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
55 pt->vint = tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
56 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
57 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
58
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
59 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
60 if (!dmLoadFloatValue(res, &pt->vfloat))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
61 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
62 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
63
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
64 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
65 if (!dmLoadFloatValue(res, &pt->vector.x) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
66 !dmLoadFloatValue(res, &pt->vector.y) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
67 !dmLoadFloatValue(res, &pt->vector.z) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
68 !dmLoadFloatValue(res, &pt->vector.W))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
69 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
70 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
71
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
72 case EFPT_MATRIX:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
73 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
74 int x, y;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
75 for (y = 0; y < DM_MATRIX_SIZE; y++)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
76 for (x = 0; x < DM_MATRIX_SIZE; x++)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
77 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
78 if (!dmLoadFloatValue(res, &(pt->matrix.m[y][x])))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
79 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
80 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
81 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
82 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
83 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
84
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
85 pt->type = ptype;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
86 pt->time = ptime;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
87 }
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
92 static int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
94 int err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 DMFTimelineEventParam hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 Uint16 len;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
98 if (!dmf_read_str(res, &hdr.name, sizeof(hdr.name)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
99 !dmf_read_le32(res, &hdr.type))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
101
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 param->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 param->type = hdr.type;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
107 switch (param->type)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 {
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
109 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
110 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
111 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
112 case EFPT_MATRIX:
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
113 if ((err = dmLoadTimelinePoints(res, &param->pts, param->type)) != DMERR_OK)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
114 return err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 break;
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
116
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 case EFPT_STRING:
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 if (!dmf_read_le16(res, &len))
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 param->vstr = dmMalloc((unsigned int)len + 1);
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
122 if (!dmf_read_str(res, param->vstr, len))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 param->vstr[len] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 break;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
133 static int dmLoadTimelineEvent(DMResource *res, DMTimelineEvent **pevent)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 int param;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 DMFTimelineEvent hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 DMTimelineEvent *event;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 if ((*pevent = event = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 // Get basic event data
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
142 if (!dmf_read_le32(res, &hdr.start) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
143 !dmf_read_le32(res, &hdr.duration) ||
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
144 !dmf_read_str(res, &hdr.effectName, sizeof(hdr.effectName)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
145 !dmf_read_le32(res, &hdr.nparams))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
147
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 hdr.effectName[sizeof(hdr.effectName) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 if (hdr.nparams > DT_MAX_EFFECT_PARAMS)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 dmError("Invalid number of parameters, %d > %d ('%s' @ %d:%d)\n",
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
153 hdr.nparams, DT_MAX_EFFECT_PARAMS, hdr.effectName, hdr.start, hdr.duration);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
157 event->start = hdr.start;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 event->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 event->nparams = hdr.nparams;
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
160 event->effect = engineFindEffect(hdr.effectName, hdr.nparams);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 if (event->effect == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 dmError("No matching registered effect found for '%s'.\n", hdr.effectName);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 if (event->params == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 dmError("Could not allocate memory for timeline event parameters.\n");
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 for (param = 0; param < event->nparams; param++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
185 static int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 curve->enabled = dmfgetc(res);
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
190 if ((err = dmLoadTimelinePoints(res, &(curve->points), EFPT_FLOAT)) != DMERR_OK)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
197 static int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 int event, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 DMFTimelineTrack hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 DMTimelineTrack *track;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
638
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
205 if (!dmf_read_le32(res, &hdr.index) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
206 !dmf_read_le32(res, &hdr.layer) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
207 !dmf_read_str(res, &hdr.name, sizeof(hdr.name)) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
208 !dmf_read_byte(res, &hdr.enabled) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
209 !dmf_read_le32(res, &hdr.nevents))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 if (hdr.nevents >= 4096)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 hdr.name[sizeof(hdr.name) - 1] = 0;
396
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
219 track->name = dm_strdup(hdr.name);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 track->enabled = hdr.enabled;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 track->nevents = hdr.nevents;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 for (event = 0; event < track->nevents; event++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 int dmLoadTimeline(DMResource *res, DMTimeline **ptl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 int track, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 DMFTimeline hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 DMTimeline *tl;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 // Read and check header
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
245 if (!dmf_read_str(res, &hdr.magic, sizeof(hdr.magic)))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
248 if (memcmp(hdr.magic, DT_MAGIC_ID, sizeof(hdr.magic)) != 0)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
251 if (!dmf_read_str(res, &hdr.name, sizeof(hdr.name)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
252 !dmf_read_le32(res, &hdr.ntracks) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
253 !dmf_read_le32(res, &hdr.duration))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 if (hdr.ntracks >= 64)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 // Allocate track pointers
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 tl->tracks = (DMTimelineTrack **) dmCalloc(hdr.ntracks, sizeof(DMTimelineTrack *));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 if (tl->tracks == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 // Copy rest
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 tl->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 tl->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 tl->ntracks = hdr.ntracks;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 // Read tracks
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 for (track = 0; track < tl->ntracks; track++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 if ((err = dmLoadTimelineTrack(res, &(tl->tracks[track]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 void dmFreeTimelinePoints(DMTimelinePoints *points)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 dmFree(points->points);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 points->points = NULL;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 points->npoints = points->nallocated = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
289 void dmFreeTimelineEventParam(DMTimelineEventParam *param)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
290 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
291 dmFree(param->name);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
292 dmFree(param->vstr);
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
293 dmFreeTimelinePoints(&(param->pts));
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
294 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
295
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
296
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
297 void dmFreeTimelineEvent(DMTimelineEvent *event)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
298 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
299 if (event != NULL)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
300 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
301 int param;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
302 for (param = 0; param < event->nparams; param++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
303 dmFreeTimelineEventParam(&(event->params[param]));
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
304 dmFree(event->params);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
305 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
306 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
307
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
308
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 void dmFreeTimelineTrack(DMTimelineTrack *track)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 if (track != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
313 int event;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
314
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 dmFree(track->name);
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
316
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
317 for (event = 0; event < track->nevents; event++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
318 dmFreeTimelineEvent(track->events[event]);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
319 dmFree(track->events);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
320
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 dmFreeTimelinePoints(&(track->composite.points));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 void dmFreeTimeline(DMTimeline *tl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 if (tl != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 int i;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 for (i = 0; i < tl->ntracks; i++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 dmFreeTimelineTrack(tl->tracks[i]);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 dmFree(tl->tracks);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 dmFree(tl->name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
340 static void dmFreePreparedEventGroup(DMPreparedEventGroup *group)
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
341 {
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
342 if (group != NULL)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
343 {
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
344 dmFree(group->events);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
345 dmFree(group);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
346 }
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
347 }
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
348
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
349
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
350 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
351 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
352 if (ptl != NULL)
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
353 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
354 int group;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
355 for (group = 0; group < ptl->ngroups; group++)
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
356 {
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
357 dmFreePreparedEventGroup(ptl->groups[group]);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
358 ptl->groups[group] = NULL;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
359 }
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
360
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
361 dmFree(ptl->groups);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
362 ptl->groups = NULL;
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
363 }
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
364 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
365
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
366
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 /* Prepare a loaded timeline for execution. Creates the "stacked" structure
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 * of timeline data for efficient rendering.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
370 int dmAddSplitPreparedEventGroup(DMPreparedEventGroup **groups, DMTimelineTrack *track, DMTimelineEvent *event)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
371 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
372 DMPreparedEventGroup *node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
373
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
374 for (node = *groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
375 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
376 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
377
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
378 return DMERR_OK;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
379 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
380
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
381
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
382 int dmPrepareTimeline(DMTimeline *tl, DMPreparedTimeline *ptl)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 {
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
384 int group, ntrack, event, err;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
385 DMPreparedEventGroup *groups = NULL, *node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
386
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
387 // Free previous data
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
388 dmFreePreparedTimelineData(ptl);
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
389
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
390 // Process tracks
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
391 for (ntrack = 0; ntrack < tl->ntracks; ntrack++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
392 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
393 DMTimelineTrack *track = tl->tracks[ntrack];
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
394 for (event = 0; event < track->nevents; event++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
395 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
396 if ((err = dmAddSplitPreparedEventGroup(&groups, track, track->events[event])) != DMERR_OK)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
397 return err;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
398 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
399 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
400
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
401 // Compute number of groups
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
402 ptl->ngroups = 0;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
403 for (node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
404 ptl->ngroups++;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
405
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
406 // Allocate linear array for fast access
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
407 ptl->groups = dmMalloc(sizeof(DMPreparedEventGroup) * ptl->ngroups);
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
408 if (ptl->groups == NULL)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
409 return DMERR_MALLOC;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
410
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
411 // Store pointers in the array
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
412 for (group = 0, node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
413 ptl->groups[group++] = node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
414
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 /* Seeks to specified position in the timeline. The execution function
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 * only handles monotonously increasing time, going backwards will not work
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 * there correctly, thus to seek freely this function must be used.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
423 int dmSeekTimeline(DMPreparedTimeline *tl, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 /* "Executes", or rather renders a frame on the specified timeline position.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 */
884
18cd96a27dee API changes to be used in future.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
431 int dmExecuteTimeline(DMPreparedTimeline *tl, DMEngineData *engine, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 }