Mercurial > hg > dmlib
annotate dmtimeline.c @ 327:2964947674d1
More work on the timeline code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 14 Oct 2012 23:36:06 +0300 |
parents | f2b65aa474c9 |
children | dd7b1356d726 |
rev | line source |
---|---|
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #include "dmtimeline.h" |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 DMEffect *dmEffects = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 int ndmEffects = 0, ndmEffectsAlloc = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 void **dmEffectData = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 int dmRegisterEffect(const DMEffect *ef) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 if (ef == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 return DMERR_NULLPTR; |
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 // Allocate more space for effects |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 if (ndmEffects + 1 >= ndmEffectsAlloc) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 ndmEffectsAlloc += 16; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 dmEffects = dmRealloc(dmEffects, sizeof(DMEffect) * ndmEffectsAlloc); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 if (dmEffects == NULL) |
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 dmError("Could not expand effects structure.\n"); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 return DMERR_INIT_FAIL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 dmEffectData = dmRealloc(dmEffectData, sizeof(void *) * ndmEffectsAlloc); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 if (dmEffectData == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 dmError("Could not expand effects data structure.\n"); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 return DMERR_INIT_FAIL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 // Copy effects structure |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 memcpy(dmEffects + ndmEffects, ef, sizeof(DMEffect)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 dmEffectData[ndmEffects] = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 ndmEffects++; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 int dmInitializeEffects() |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 int i, res; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 for (i = 0; i < ndmEffects; i++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 if (dmEffects[i].init != NULL && |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 (res = dmEffects[i].init(&dmEffectData[i])) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 return res; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 void dmShutdownEffects() |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 int i; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 for (i = 0; i < ndmEffects; i++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 if (dmEffects[i].shutdown != NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 dmEffects[i].shutdown(dmEffectData[i]); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 DMEffect *dmFindEffect(const char *name, const int nparams) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 int i; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 for (i = 0; i < ndmEffects; i++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 if (strcmp(dmEffects[i].name, name) == 0 && |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 dmEffects[i].nparams == nparams) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 return &dmEffects[i]; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 return NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
81 DMEffect *dmFindEffectByName(const char *name) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
82 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
83 int i; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
84 for (i = 0; i < ndmEffects; i++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
85 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
86 if (strcmp(dmEffects[i].name, name) == 0) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
87 return &dmEffects[i]; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
88 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
89 return NULL; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
90 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
91 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
92 |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
93 BOOL dmLoadFloatValue(DMResource *res, DMFloat *val) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 char tmp[DT_FLOAT_STORE_SIZE + 1]; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 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
|
97 return FALSE; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 tmp[DT_FLOAT_STORE_SIZE] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 *val = atof(tmp); |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
101 return TRUE; |
320
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
107 int point; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
108 Uint32 npoints; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
109 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
110 // Get number of points |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
111 if (!dmf_read_le32(res, &npoints)) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
112 return DMERR_FREAD; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
113 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
114 // Calculate and allocate space |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
115 points->npoints = npoints; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
116 points->nallocated = ((npoints / 16) + 1) * 16; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
118 points->points = dmCalloc(npoints, sizeof(DMTimelinePoint)); |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
119 if (points->points == NULL) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
120 return DMERR_MALLOC; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
121 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
122 // Read points |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
123 for (point = 0; point < points->npoints; point++) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
124 { |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
125 DMTimelinePoint *pt = &(points->points[point]); |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
126 Uint32 ptype, ptime; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
127 if (!dmf_read_le32(res, &ptype) || |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
128 !dmf_read_le32(res, &ptime) || |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
129 !dmLoadFloatValue(res, &pt->value)) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
130 return DMERR_FREAD; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
131 |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
132 pt->type = ptype; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
133 pt->time = ptime; |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
134 } |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 |
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 int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 { |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
141 int err; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 DMFTimelineEventParam hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 Uint16 len; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 Uint32 tmp32; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
146 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
|
147 !dmf_read_le32(res, &hdr.type)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 return DMERR_FREAD; |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
149 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 hdr.name[sizeof(hdr.name) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 param->name = dm_strdup(hdr.name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 param->type = hdr.type; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 switch (hdr.type) |
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 case EFPT_POINTS: |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
158 if ((err = dmLoadTimelinePoints(res, ¶m->vpts)) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
159 return err; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 break; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 case EFPT_INT: |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 if (!dmf_read_le32(res, &tmp32)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 param->vint = tmp32; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 break; |
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 case EFPT_FLOAT: |
324
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
169 if (!dmLoadFloatValue(res, ¶m->vfloat)) |
f2b65aa474c9
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
170 return DMERR_FREAD; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 break; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 case EFPT_STRING: |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 if (!dmf_read_le16(res, &len)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 return DMERR_FREAD; |
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 param->vstr = dmMalloc((unsigned int)len + 1); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 if (dmf_read_str(res, (Uint8 *) param->vstr, len) != len) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 return DMERR_FREAD; |
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 param->vstr[len] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 break; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 return DMERR_OK; |
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 |
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 int dmLoadTimelineEvent(DMResource *res, DMTimelineEvent **pevent) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 int param; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 DMFTimelineEvent hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 DMTimelineEvent *event; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 if ((*pevent = event = dmMalloc0(sizeof(DMTimelineEvent))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 // Get basic event data |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
198 if (!dmf_read_le32(res, &hdr.start) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
199 !dmf_read_le32(res, &hdr.duration) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
200 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
|
201 !dmf_read_le32(res, &hdr.nparams)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 return DMERR_FREAD; |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
203 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 hdr.effectName[sizeof(hdr.effectName) - 1] = 0; |
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.nparams > DT_MAX_EFFECT_PARAMS) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 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
|
209 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
|
210 return DMERR_INVALID_DATA; |
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 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
213 event->start = hdr.start; |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 event->duration = hdr.duration; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 event->nparams = hdr.nparams; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 event->effect = dmFindEffect(hdr.effectName, hdr.nparams); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 if (event->effect == NULL) |
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 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
|
220 return DMERR_INVALID_DATA; |
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 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 if (event->params == NULL) |
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 dmError("Could not allocate memory for timeline event parameters.\n"); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 return DMERR_MALLOC; |
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 for (param = 0; param < event->nparams; param++) |
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 err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 return err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 int err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 curve->enabled = dmfgetc(res); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 if ((err = dmLoadTimelinePoints(res, &(curve->points))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 return err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 |
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 int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 int event, err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 DMFTimelineTrack hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 DMTimelineTrack *track; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 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
|
262 return DMERR_FREAD; |
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 hdr.enabled = dmfgetc(res); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 if (!dmf_read_le32(res, &hdr.nevents)) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 if (hdr.nevents >= 4096) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 return DMERR_INVALID_DATA; |
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 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 return DMERR_MALLOC; |
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 hdr.name[sizeof(hdr.name) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 track->name = dm_strdup(hdr.name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 track->enabled = hdr.enabled; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 track->nevents = hdr.nevents; |
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 for (event = 0; event < track->nevents; event++) |
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 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 return err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 return err; |
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 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 int dmLoadTimeline(DMResource *res, DMTimeline **ptl) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 int track, err; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 DMFTimeline hdr; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 DMTimeline *tl; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 return DMERR_MALLOC; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 // Read and check header |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 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
|
302 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
304 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
|
305 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
307 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
|
308 !dmf_read_le32(res, &hdr.ntracks) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
324
diff
changeset
|
309 !dmf_read_le32(res, &hdr.duration)) |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 return DMERR_FREAD; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 if (hdr.ntracks >= 64) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 return DMERR_INVALID_DATA; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 // Allocate track pointers |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 tl->tracks = (DMTimelineTrack **) dmCalloc(hdr.ntracks, sizeof(DMTimelineTrack *)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 if (tl->tracks == NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 return DMERR_MALLOC; |
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 // Copy rest |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 hdr.name[sizeof(hdr.name) - 1] = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 tl->name = dm_strdup(hdr.name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 tl->duration = hdr.duration; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 tl->ntracks = hdr.ntracks; |
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 // Read tracks |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 for (track = 0; track < tl->ntracks; track++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 if ((err = dmLoadTimelineTrack(res, &(tl->tracks[track]))) != DMERR_OK) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 return err; |
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 return DMERR_OK; |
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 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 void dmFreeTimelinePoints(DMTimelinePoints *points) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 dmFree(points->points); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 points->points = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 points->npoints = points->nallocated = 0; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 void dmFreeTimelineTrack(DMTimelineTrack *track) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 if (track != NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 dmFree(track->name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 track->name = NULL; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 dmFreeTimelinePoints(&(track->composite.points)); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 void dmFreeTimeline(DMTimeline *tl) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 if (tl != NULL) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 int i; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 for (i = 0; i < tl->ntracks; i++) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 dmFreeTimelineTrack(tl->tracks[i]); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 dmFree(tl->tracks); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 dmFree(tl->name); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 dmFree(tl->pevents); |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 /* Prepare a loaded timeline for execution. Creates the "stacked" structure |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 * of timeline data for efficient rendering. |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 */ |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 int dmPrepareTimeline(DMTimeline *tl) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 /* Seeks to specified position in the timeline. The execution function |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 * only handles monotonously increasing time, going backwards will not work |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 * 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
|
383 */ |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 int dmSeekTimeline(DMTimeline *tl, int time) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 /* "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
|
391 */ |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 int dmExecuteTimeline(DMTimeline *tl, SDL_Surface *screen, int time) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 } |