annotate src/dmtimeline.c @ 1102:e06abfde6c39

Cosmetics pass: Remove excess whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Mar 2015 23:22:36 +0200
parents 985225a93aeb
children 28fe5b0925dc
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;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
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;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
38
324
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;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
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;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
63
346
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 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
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;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
149
320
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 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
152 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
153 "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
154 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
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 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
163 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
164 "No matching registered effect found for '%s'.\n",
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
165 hdr.effectName);
320
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 if (event->params == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
171 return dmError(DMERR_MALLOC,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
172 "Could not allocate memory for timeline event parameters.\n");
320
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 for (param = 0; param < event->nparams; param++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 return err;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
186 static int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 curve->enabled = dmfgetc(res);
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
191 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
192 return err;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
193
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
198 static int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 int event, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 DMFTimelineTrack hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 DMTimelineTrack *track;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
638
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
206 if (!dmf_read_le32(res, &hdr.index) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
207 !dmf_read_le32(res, &hdr.layer) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
208 !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
209 !dmf_read_byte(res, &hdr.enabled) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
210 !dmf_read_le32(res, &hdr.nevents))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 if (hdr.nevents >= 4096)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 hdr.name[sizeof(hdr.name) - 1] = 0;
396
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
220 track->name = dm_strdup(hdr.name);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 track->enabled = hdr.enabled;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 track->nevents = hdr.nevents;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 for (event = 0; event < track->nevents; event++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 return err;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 int dmLoadTimeline(DMResource *res, DMTimeline **ptl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 int track, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 DMFTimeline hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 DMTimeline *tl;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 // 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
246 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
247 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
249 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
250 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
252 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
253 !dmf_read_le32(res, &hdr.ntracks) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
254 !dmf_read_le32(res, &hdr.duration))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 if (hdr.ntracks >= 64)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 // Allocate track pointers
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 tl->tracks = (DMTimelineTrack **) dmCalloc(hdr.ntracks, sizeof(DMTimelineTrack *));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 if (tl->tracks == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 // Copy rest
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 tl->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 tl->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 tl->ntracks = hdr.ntracks;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 // Read tracks
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 for (track = 0; track < tl->ntracks; track++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 if ((err = dmLoadTimelineTrack(res, &(tl->tracks[track]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
277
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 void dmFreeTimelinePoints(DMTimelinePoints *points)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 dmFree(points->points);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 points->points = NULL;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 points->npoints = points->nallocated = 0;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
290 void dmFreeTimelineEventParam(DMTimelineEventParam *param)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
291 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
292 dmFree(param->name);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
293 dmFree(param->vstr);
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
294 dmFreeTimelinePoints(&(param->pts));
328
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
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
298 void dmFreeTimelineEvent(DMTimelineEvent *event)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
299 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
300 if (event != NULL)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
301 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
302 int param;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
303 for (param = 0; param < event->nparams; param++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
304 dmFreeTimelineEventParam(&(event->params[param]));
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
305 dmFree(event->params);
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
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
309
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 void dmFreeTimelineTrack(DMTimelineTrack *track)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 if (track != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 {
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
314 int event;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
315
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 dmFree(track->name);
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
317
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
318 for (event = 0; event < track->nevents; event++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
319 dmFreeTimelineEvent(track->events[event]);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
320 dmFree(track->events);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
321
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 dmFreeTimelinePoints(&(track->composite.points));
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 void dmFreeTimeline(DMTimeline *tl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 if (tl != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 int i;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 for (i = 0; i < tl->ntracks; i++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 dmFreeTimelineTrack(tl->tracks[i]);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 dmFree(tl->tracks);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 dmFree(tl->name);
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
341 static void dmFreePreparedEventGroup(DMPreparedEventGroup *group)
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
342 {
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
343 if (group != NULL)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
344 {
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
345 dmFree(group->events);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
346 dmFree(group);
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
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
351 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
352 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
353 if (ptl != NULL)
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
354 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
355 int group;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
356 for (group = 0; group < ptl->ngroups; group++)
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
357 {
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
358 dmFreePreparedEventGroup(ptl->groups[group]);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
359 ptl->groups[group] = NULL;
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
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
362 dmFree(ptl->groups);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
363 ptl->groups = NULL;
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
364 }
330
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
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
367
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 /* Prepare a loaded timeline for execution. Creates the "stacked" structure
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 * of timeline data for efficient rendering.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
371 int dmAddSplitPreparedEventGroup(DMPreparedEventGroup **groups, DMTimelineTrack *track, DMTimelineEvent *event)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
372 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
373 DMPreparedEventGroup *node;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
374
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
375 for (node = *groups; node != NULL; node = node->next)
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 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
378
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
379 return DMERR_OK;
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
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
383 int dmPrepareTimeline(DMTimeline *tl, DMPreparedTimeline *ptl)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 {
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
385 int group, ntrack, event, err;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
386 DMPreparedEventGroup *groups = NULL, *node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
387
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
388 // Free previous data
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
389 dmFreePreparedTimelineData(ptl);
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
390
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
391 // Process tracks
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
392 for (ntrack = 0; ntrack < tl->ntracks; ntrack++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
393 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
394 DMTimelineTrack *track = tl->tracks[ntrack];
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
395 for (event = 0; event < track->nevents; event++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
396 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
397 if ((err = dmAddSplitPreparedEventGroup(&groups, track, track->events[event])) != DMERR_OK)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
398 return err;
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 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
401
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
402 // Compute number of groups
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
403 ptl->ngroups = 0;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
404 for (node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
405 ptl->ngroups++;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
406
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
407 // Allocate linear array for fast access
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
408 ptl->groups = dmMalloc(sizeof(DMPreparedEventGroup) * ptl->ngroups);
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
409 if (ptl->groups == NULL)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
410 return DMERR_MALLOC;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
411
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
412 // Store pointers in the array
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
413 for (group = 0, node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
414 ptl->groups[group++] = node;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
415
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 /* Seeks to specified position in the timeline. The execution function
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 * only handles monotonously increasing time, going backwards will not work
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 * 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
423 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
424 int dmSeekTimeline(DMPreparedTimeline *tl, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 /* "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
431 */
884
18cd96a27dee API changes to be used in future.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
432 int dmExecuteTimeline(DMPreparedTimeline *tl, DMEngineData *engine, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 }