Mercurial > hg > dmlib
annotate dmtimeline.c @ 396:1712cc35e9a1
Fixes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 07:21:54 +0300 |
parents | 08ea68abb1f8 |
children | 525f7af644c4 |
rev | line source |
---|---|
368 | 1 #include "dmengine.h" |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
2 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
3 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
4 static BOOL dmLoadFloatValue(DMResource *res, DMFloat *val) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 char tmp[DT_FLOAT_STORE_SIZE + 1]; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 if (dmf_read_str(res, (Uint8 *) tmp, DT_FLOAT_STORE_SIZE) != DT_FLOAT_STORE_SIZE) |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
8 return FALSE; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 tmp[DT_FLOAT_STORE_SIZE] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 *val = atof(tmp); |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
12 return TRUE; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
16 static int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points, int type) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 { |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
18 int point; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
19 Uint32 npoints; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
20 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
21 // Get number of points |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
22 if (!dmf_read_le32(res, &npoints)) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
23 return DMERR_FREAD; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
24 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
25 // Calculate and allocate space |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
26 points->npoints = npoints; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
27 points->nallocated = ((npoints / 16) + 1) * 16; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
396 | 29 points->points = dmCalloc(points->nallocated, sizeof(DMTimelinePoint)); |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
30 if (points->points == NULL) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
31 return DMERR_MALLOC; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
32 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
33 // Read points |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
34 for (point = 0; point < points->npoints; point++) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
35 { |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
36 DMTimelinePoint *pt = &(points->points[point]); |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
37 Uint32 ptype, ptime; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
38 if (!dmf_read_le32(res, &ptype) || |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
39 !dmf_read_le32(res, &ptime)) |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
40 return DMERR_FREAD; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
41 |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
42 switch (type) |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
43 { |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
44 case EFPT_INT: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
45 { |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
46 Uint32 tmp; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
47 if (!dmf_read_le32(res, &tmp)) |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
48 return DMERR_FREAD; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
49 pt->vint = tmp; |
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 break; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
52 |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
53 case EFPT_FLOAT: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
54 if (!dmLoadFloatValue(res, &pt->vfloat)) |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
55 return DMERR_FREAD; |
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_VECTOR: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
59 if (!dmLoadFloatValue(res, &pt->vector.x) || |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
60 !dmLoadFloatValue(res, &pt->vector.y) || |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
61 !dmLoadFloatValue(res, &pt->vector.z) || |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
62 !dmLoadFloatValue(res, &pt->vector.W)) |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
63 return DMERR_FREAD; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
64 break; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
65 |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
66 case EFPT_MATRIX: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
67 { |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
68 int x, y; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
69 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
|
70 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
|
71 { |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
72 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
|
73 return DMERR_FREAD; |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
74 } |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
75 } |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
76 break; |
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 |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
79 pt->type = ptype; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
80 pt->time = ptime; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
81 } |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
86 static int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 { |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
88 int err; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 DMFTimelineEventParam hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 Uint16 len; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
92 if (dmf_read_str(res, (Uint8 *) &hdr.name, sizeof(hdr.name)) != sizeof(hdr.name) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
93 !dmf_read_le32(res, &hdr.type)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 return DMERR_FREAD; |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
95 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 hdr.name[sizeof(hdr.name) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 param->name = dm_strdup(hdr.name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 param->type = hdr.type; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
101 switch (param->type) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 { |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
103 case EFPT_INT: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
104 case EFPT_FLOAT: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
105 case EFPT_VECTOR: |
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
106 case EFPT_MATRIX: |
347 | 107 if ((err = dmLoadTimelinePoints(res, ¶m->pts, param->type)) != DMERR_OK) |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
108 return err; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 break; |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
110 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 case EFPT_STRING: |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 if (!dmf_read_le16(res, &len)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 param->vstr = dmMalloc((unsigned int)len + 1); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 if (dmf_read_str(res, (Uint8 *) param->vstr, len) != len) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 param->vstr[len] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 break; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 return DMERR_OK; |
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
127 static int dmLoadTimelineEvent(DMResource *res, DMTimelineEvent **pevent) |
320
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 int param; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 DMFTimelineEvent hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 DMTimelineEvent *event; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 if ((*pevent = event = dmMalloc0(sizeof(DMTimelineEvent))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 return DMERR_MALLOC; |
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 // Get basic event data |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
136 if (!dmf_read_le32(res, &hdr.start) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
137 !dmf_read_le32(res, &hdr.duration) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
138 dmf_read_str(res, (Uint8 *) &hdr.effectName, sizeof(hdr.effectName)) != sizeof(hdr.effectName) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
139 !dmf_read_le32(res, &hdr.nparams)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 return DMERR_FREAD; |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
141 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 hdr.effectName[sizeof(hdr.effectName) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 if (hdr.nparams > DT_MAX_EFFECT_PARAMS) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 dmError("Invalid number of parameters, %d > %d ('%s' @ %d:%d)\n", |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
147 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
|
148 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
151 event->start = hdr.start; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 event->duration = hdr.duration; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 event->nparams = hdr.nparams; |
368 | 154 event->effect = engineFindEffect(hdr.effectName, hdr.nparams); |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 if (event->effect == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 dmError("No matching registered effect found for '%s'.\n", hdr.effectName); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 if (event->params == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 dmError("Could not allocate memory for timeline event parameters.\n"); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 return DMERR_MALLOC; |
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 for (param = 0; param < event->nparams; param++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 int err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 return err; |
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 return DMERR_OK; |
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
179 static int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve) |
320
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 int err; |
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 curve->enabled = dmfgetc(res); |
346
882503ef7ab8
More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
184 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
|
185 return err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
191 static int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 int event, err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 DMFTimelineTrack hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 DMTimelineTrack *track; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 if (dmf_read_str(res, (Uint8 *) &hdr.name, sizeof(hdr.name)) != sizeof(hdr.name)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 hdr.enabled = dmfgetc(res); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 if (!dmf_read_le32(res, &hdr.nevents)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 if (hdr.nevents >= 4096) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 hdr.name[sizeof(hdr.name) - 1] = 0; |
396 | 213 track->name = dm_strdup(hdr.name); |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 track->enabled = hdr.enabled; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 track->nevents = hdr.nevents; |
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 for (event = 0; event < track->nevents; event++) |
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 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 return err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 return err; |
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 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 int dmLoadTimeline(DMResource *res, DMTimeline **ptl) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 int track, err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 DMFTimeline hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 DMTimeline *tl; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 // Read and check header |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 if (dmf_read_str(res, (Uint8 *) &hdr.magic, sizeof(hdr.magic)) != sizeof(hdr.magic)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
242 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
|
243 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
245 if (dmf_read_str(res, (Uint8 *) &hdr.name, sizeof(hdr.name)) != sizeof(hdr.name) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
246 !dmf_read_le32(res, &hdr.ntracks) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
247 !dmf_read_le32(res, &hdr.duration)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 if (hdr.ntracks >= 64) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 // Allocate track pointers |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 tl->tracks = (DMTimelineTrack **) dmCalloc(hdr.ntracks, sizeof(DMTimelineTrack *)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 if (tl->tracks == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 // Copy rest |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 hdr.name[sizeof(hdr.name) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 tl->name = dm_strdup(hdr.name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 tl->duration = hdr.duration; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 tl->ntracks = hdr.ntracks; |
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 // Read tracks |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 for (track = 0; track < tl->ntracks; track++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 if ((err = dmLoadTimelineTrack(res, &(tl->tracks[track]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 return err; |
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 return DMERR_OK; |
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 void dmFreeTimelinePoints(DMTimelinePoints *points) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 dmFree(points->points); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 points->points = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 points->npoints = points->nallocated = 0; |
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 |
328 | 283 void dmFreeTimelineEventParam(DMTimelineEventParam *param) |
284 { | |
285 dmFree(param->name); | |
286 dmFree(param->vstr); | |
347 | 287 dmFreeTimelinePoints(&(param->pts)); |
328 | 288 } |
289 | |
290 | |
291 void dmFreeTimelineEvent(DMTimelineEvent *event) | |
292 { | |
293 if (event != NULL) | |
294 { | |
295 int param; | |
296 for (param = 0; param < event->nparams; param++) | |
297 dmFreeTimelineEventParam(&(event->params[param])); | |
298 dmFree(event->params); | |
299 } | |
300 } | |
301 | |
302 | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 void dmFreeTimelineTrack(DMTimelineTrack *track) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 if (track != NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 { |
328 | 307 int event; |
308 | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 dmFree(track->name); |
328 | 310 |
311 for (event = 0; event < track->nevents; event++) | |
312 dmFreeTimelineEvent(track->events[event]); | |
313 dmFree(track->events); | |
314 | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 dmFreeTimelinePoints(&(track->composite.points)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 void dmFreeTimeline(DMTimeline *tl) |
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 if (tl != NULL) |
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 int i; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 for (i = 0; i < tl->ntracks; i++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 dmFreeTimelineTrack(tl->tracks[i]); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 dmFree(tl->tracks); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 dmFree(tl->name); |
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 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 |
350
834f3b686ad3
More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
334 static void dmFreePreparedEventGroup(DMPreparedEventGroup *group) |
330 | 335 { |
340
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
336 if (group != NULL) |
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
337 { |
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
338 dmFree(group->events); |
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
339 dmFree(group); |
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 } |
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
342 |
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 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl) |
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
345 { |
352
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
346 if (ptl != NULL) |
340
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
347 { |
352
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
348 int group; |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
349 for (group = 0; group < ptl->ngroups; group++) |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
350 { |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
351 dmFreePreparedEventGroup(ptl->groups[group]); |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
352 ptl->groups[group] = NULL; |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
353 } |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
354 |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
355 dmFree(ptl->groups); |
5eafdc396fa4
Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
356 ptl->groups = NULL; |
340
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
357 } |
330 | 358 } |
359 | |
360 | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 /* Prepare a loaded timeline for execution. Creates the "stacked" structure |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 * of timeline data for efficient rendering. |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 */ |
330 | 364 int dmAddSplitPreparedEventGroup(DMPreparedEventGroup **groups, DMTimelineTrack *track, DMTimelineEvent *event) |
365 { | |
366 DMPreparedEventGroup *node; | |
367 | |
368 for (node = *groups; node != NULL; node = node->next) | |
369 { | |
370 } | |
371 | |
372 return DMERR_OK; | |
373 } | |
374 | |
375 | |
376 int dmPrepareTimeline(DMTimeline *tl, DMPreparedTimeline *ptl) | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 { |
330 | 378 int group, ntrack, event, err; |
379 DMPreparedEventGroup *groups = NULL, *node; | |
380 | |
381 // Free previous data | |
340
1c5e7d66312d
Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
382 dmFreePreparedTimelineData(ptl); |
330 | 383 |
384 // Process tracks | |
385 for (ntrack = 0; ntrack < tl->ntracks; ntrack++) | |
386 { | |
387 DMTimelineTrack *track = tl->tracks[ntrack]; | |
388 for (event = 0; event < track->nevents; event++) | |
389 { | |
390 if ((err = dmAddSplitPreparedEventGroup(&groups, track, track->events[event])) != DMERR_OK) | |
391 return err; | |
392 } | |
393 } | |
394 | |
395 // Compute number of groups | |
396 ptl->ngroups = 0; | |
397 for (node = groups; node != NULL; node = node->next) | |
398 ptl->ngroups++; | |
399 | |
400 // Allocate linear array for fast access | |
401 ptl->groups = dmMalloc(sizeof(DMPreparedEventGroup) * ptl->ngroups); | |
402 if (ptl->groups == NULL) | |
403 return DMERR_MALLOC; | |
404 | |
405 // Store pointers in the array | |
406 for (group = 0, node = groups; node != NULL; node = node->next) | |
407 ptl->groups[group++] = node; | |
408 | |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 /* Seeks to specified position in the timeline. The execution function |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 * only handles monotonously increasing time, going backwards will not work |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 * 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
|
416 */ |
330 | 417 int dmSeekTimeline(DMPreparedTimeline *tl, int time) |
320
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 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 /* "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
|
424 */ |
330 | 425 int dmExecuteTimeline(DMPreparedTimeline *tl, SDL_Surface *screen, int time) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 } |