annotate src/dmtimeline.c @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents 7190f4fbc0dd
children 9807ae37ad69
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 Uint32 npoints;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
25
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
26 // Get number of points
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
27 if (!dmf_read_le32(res, &npoints))
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
28 return DMERR_FREAD;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
29
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
30 // Calculate and allocate space
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
31 points->npoints = npoints;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
32 points->nallocated = ((npoints / 16) + 1) * 16;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
33
396
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
34 points->points = dmCalloc(points->nallocated, sizeof(DMTimelinePoint));
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
35 if (points->points == NULL)
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
36 return DMERR_MALLOC;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
37
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
38 // Read points
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
39 for (int point = 0; point < points->npoints; point++)
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
40 {
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
41 DMTimelinePoint *pt = &(points->points[point]);
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
42 Uint32 ptype, ptime;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
43 if (!dmf_read_le32(res, &ptype) ||
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
44 !dmf_read_le32(res, &ptime))
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
45 return DMERR_FREAD;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
46
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
47 switch (type)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
48 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
49 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
50 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
51 Uint32 tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
52 if (!dmf_read_le32(res, &tmp))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
53 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
54 pt->vint = tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
55 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
56 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
57
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
58 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
59 if (!dmLoadFloatValue(res, &pt->vfloat))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
60 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
61 break;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
62
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
63 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
64 if (!dmLoadFloatValue(res, &pt->vector.x) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
65 !dmLoadFloatValue(res, &pt->vector.y) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
66 !dmLoadFloatValue(res, &pt->vector.z) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
67 !dmLoadFloatValue(res, &pt->vector.W))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
68 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
69 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
70
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
71 case EFPT_MATRIX:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
72 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
73 int x, y;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
74 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
75 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
76 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
77 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
78 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
79 }
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 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
82 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
83
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
84 pt->type = ptype;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
85 pt->time = ptime;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
86 }
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
91 static int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
93 int err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 DMFTimelineEventParam hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 Uint16 len;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
97 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
98 !dmf_read_le32(res, &hdr.type))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
100
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 param->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 param->type = hdr.type;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
106 switch (param->type)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 {
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
108 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
109 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
110 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
111 case EFPT_MATRIX:
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
112 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
113 return err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 break;
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
115
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 case EFPT_STRING:
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 if (!dmf_read_le16(res, &len))
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 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
121 if (!dmf_read_str(res, param->vstr, len))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 param->vstr[len] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 break;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 }
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 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
132 static int dmLoadTimelineEvent(DMResource *res, DMTimelineEvent **pevent)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 DMFTimelineEvent hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 DMTimelineEvent *event;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 if ((*pevent = event = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 // Get basic event data
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
140 if (!dmf_read_le32(res, &hdr.start) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
141 !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
142 !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
143 !dmf_read_le32(res, &hdr.nparams))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
145
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 hdr.effectName[sizeof(hdr.effectName) - 1] = 0;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
147
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 if (hdr.nparams > DT_MAX_EFFECT_PARAMS)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
150 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
151 "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
152 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
153 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
155 event->start = hdr.start;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 event->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 event->nparams = hdr.nparams;
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
158 event->effect = engineFindEffect(hdr.effectName, hdr.nparams);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 if (event->effect == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
161 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
162 "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
163 hdr.effectName);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
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 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if (event->params == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
169 return dmError(DMERR_MALLOC,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
170 "Could not allocate memory for timeline event parameters.\n");
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
173 for (int param = 0; param < event->nparams; param++)
320
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 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 }
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 return DMERR_OK;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
184 static int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 int err;
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 curve->enabled = dmfgetc(res);
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
189 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
190 return err;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
191
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
196 static int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 {
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
198 int err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 DMFTimelineTrack hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 DMTimelineTrack *track;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
638
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
204 if (!dmf_read_le32(res, &hdr.index) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
205 !dmf_read_le32(res, &hdr.layer) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
206 !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
207 !dmf_read_byte(res, &hdr.enabled) ||
b22db2832f3e Some work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
208 !dmf_read_le32(res, &hdr.nevents))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 if (hdr.nevents >= 4096)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 hdr.name[sizeof(hdr.name) - 1] = 0;
396
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
218 track->name = dm_strdup(hdr.name);
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 track->enabled = hdr.enabled;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 track->nevents = hdr.nevents;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
222 for (int event = 0; event < track->nevents; event++)
320
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 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 }
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 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 return DMERR_OK;
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
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 int dmLoadTimeline(DMResource *res, DMTimeline **ptl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 {
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
237 int err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 DMFTimeline hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 DMTimeline *tl;
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
240
320
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
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
271 for (int track = 0; track < tl->ntracks; track++)
320
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 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
276
320
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 {
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
301 for (int param = 0; param < event->nparams; param++)
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
302 dmFreeTimelineEventParam(&(event->params[param]));
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
303 dmFree(event->params);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
304 }
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
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 void dmFreeTimelineTrack(DMTimelineTrack *track)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 if (track != NULL)
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 dmFree(track->name);
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
313
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
314 for (int event = 0; event < track->nevents; event++)
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
315 dmFreeTimelineEvent(track->events[event]);
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
316
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
317 dmFree(track->events);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
318
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 dmFreeTimelinePoints(&(track->composite.points));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
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 void dmFreeTimeline(DMTimeline *tl)
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 if (tl != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 {
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
328 for (int track = 0; track < tl->ntracks; track++)
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
329 dmFreeTimelineTrack(tl->tracks[track]);
320
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 dmFree(tl->tracks);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 dmFree(tl->name);
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 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
337 static void dmFreePreparedEventGroup(DMPreparedEventGroup *group)
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
338 {
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
339 if (group != NULL)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
340 {
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
341 dmFree(group->events);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
342 dmFree(group);
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 }
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
345
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 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
348 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
349 if (ptl != NULL)
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
350 {
1359
28fe5b0925dc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
351 for (int group = 0; group < ptl->ngroups; group++)
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
352 {
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
353 dmFreePreparedEventGroup(ptl->groups[group]);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
354 ptl->groups[group] = NULL;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
355 }
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 dmFree(ptl->groups);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
358 ptl->groups = NULL;
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
359 }
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
360 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
361
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
362
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 /* Prepare a loaded timeline for execution. Creates the "stacked" structure
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 * of timeline data for efficient rendering.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
366 int dmAddSplitPreparedEventGroup(DMPreparedEventGroup **groups, DMTimelineTrack *track, DMTimelineEvent *event)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
367 {
1993
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
368 (void) groups;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
369 (void) track;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
370 (void) event;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
371
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
372 /*
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
373 DMPreparedEventGroup *node;
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 }
1993
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
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 {
1993
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
426 (void) tl;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
427 (void) time;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
428
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
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 /* "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
434 */
884
18cd96a27dee API changes to be used in future.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
435 int dmExecuteTimeline(DMPreparedTimeline *tl, DMEngineData *engine, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 {
1993
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
437 (void) tl;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
438 (void) engine;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
439 (void) time;
7190f4fbc0dd Silence some unused function argument warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1359
diff changeset
440
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 }