annotate dmtimeline.c @ 352:5eafdc396fa4

Add null pointer check to dmFreePreparedTimelineData().
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Oct 2012 01:24:00 +0300
parents 834f3b686ad3
children 08ea68abb1f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
93 static 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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
105 static int dmLoadTimelinePoints(DMResource *res, DMTimelinePoints *points, int type)
320
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) ||
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
128 !dmf_read_le32(res, &ptime))
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
129 return DMERR_FREAD;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
130
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
131 switch (type)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
132 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
133 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
134 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
135 Uint32 tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
136 if (!dmf_read_le32(res, &tmp))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
137 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
138 pt->vint = tmp;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
139 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
140 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
141
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
142 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
143 if (!dmLoadFloatValue(res, &pt->vfloat))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
144 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
145 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
146
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
147 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
148 if (!dmLoadFloatValue(res, &pt->vector.x) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
149 !dmLoadFloatValue(res, &pt->vector.y) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
150 !dmLoadFloatValue(res, &pt->vector.z) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
151 !dmLoadFloatValue(res, &pt->vector.W))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
152 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
153 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
154
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
155 case EFPT_MATRIX:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
156 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
157 int x, y;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
158 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
159 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
160 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
161 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
162 return DMERR_FREAD;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
163 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
164 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
165 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
166 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
167
324
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
168 pt->type = ptype;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
169 pt->time = ptime;
f2b65aa474c9 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
170 }
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
175 static int dmLoadTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
177 int err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 DMFTimelineEventParam hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 Uint16 len;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
181 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
182 !dmf_read_le32(res, &hdr.type))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
184
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 hdr.name[sizeof(hdr.name) - 1] = 0;
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 param->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 param->type = hdr.type;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
190 switch (param->type)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 {
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
192 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
193 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
194 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
195 case EFPT_MATRIX:
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
196 if ((err = dmLoadTimelinePoints(res, &param->pts, param->type)) != DMERR_OK)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
197 return err;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 break;
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
199
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 case EFPT_STRING:
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 if (!dmf_read_le16(res, &len))
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 param->vstr = dmMalloc((unsigned int)len + 1);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 if (dmf_read_str(res, (Uint8 *) param->vstr, len) != len)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 return DMERR_FREAD;
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 param->vstr[len] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 break;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
216 static int dmLoadTimelineEvent(DMResource *res, DMTimelineEvent **pevent)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 int param;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 DMFTimelineEvent hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 DMTimelineEvent *event;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 if ((*pevent = event = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 // Get basic event data
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
225 if (!dmf_read_le32(res, &hdr.start) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
226 !dmf_read_le32(res, &hdr.duration) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
227 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
228 !dmf_read_le32(res, &hdr.nparams))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 return DMERR_FREAD;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
230
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 hdr.effectName[sizeof(hdr.effectName) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 if (hdr.nparams > DT_MAX_EFFECT_PARAMS)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 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
236 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
237 return DMERR_INVALID_DATA;
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
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
240 event->start = hdr.start;
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 event->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 event->nparams = hdr.nparams;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 event->effect = dmFindEffect(hdr.effectName, hdr.nparams);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 if (event->effect == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 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
247 return DMERR_INVALID_DATA;
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
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 if (event->params == NULL)
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 dmError("Could not allocate memory for timeline event parameters.\n");
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 for (param = 0; param < event->nparams; param++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 if ((err = dmLoadTimelineEventParam(res, &(event->params[param]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 }
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 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
268 static int dmLoadTimelineCurve(DMResource *res, DMTimelineCurve *curve)
320
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 int err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 curve->enabled = dmfgetc(res);
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
273 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
274 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
280 static int dmLoadTimelineTrack(DMResource *res, DMTimelineTrack **ptrack)
320
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 int event, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 DMFTimelineTrack hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 DMTimelineTrack *track;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 return DMERR_MALLOC;
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 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
289 return DMERR_FREAD;
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 hdr.enabled = dmfgetc(res);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 if (!dmf_read_le32(res, &hdr.nevents))
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 if (hdr.nevents >= 4096)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 if ((track->events = dmCalloc(hdr.nevents, sizeof(DMTimelineEvent *))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 track->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 track->enabled = hdr.enabled;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 track->nevents = hdr.nevents;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 for (event = 0; event < track->nevents; event++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 if ((err = dmLoadTimelineEvent(res, &(track->events[event]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 if ((err = dmLoadTimelineCurve(res, &(track->composite))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 return err;
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 return DMERR_OK;
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 int dmLoadTimeline(DMResource *res, DMTimeline **ptl)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 int track, err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 DMFTimeline hdr;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 DMTimeline *tl;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 return DMERR_MALLOC;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 // Read and check header
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 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
329 return DMERR_FREAD;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
331 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
332 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
334 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
335 !dmf_read_le32(res, &hdr.ntracks) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
336 !dmf_read_le32(res, &hdr.duration))
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 return DMERR_FREAD;
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 if (hdr.ntracks >= 64)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 return DMERR_INVALID_DATA;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 // Allocate track pointers
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 tl->tracks = (DMTimelineTrack **) dmCalloc(hdr.ntracks, sizeof(DMTimelineTrack *));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 if (tl->tracks == NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 return DMERR_MALLOC;
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 // Copy rest
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 hdr.name[sizeof(hdr.name) - 1] = 0;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 tl->name = dm_strdup(hdr.name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 tl->duration = hdr.duration;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 tl->ntracks = hdr.ntracks;
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 // Read tracks
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 for (track = 0; track < tl->ntracks; track++)
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 if ((err = dmLoadTimelineTrack(res, &(tl->tracks[track]))) != DMERR_OK)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 return err;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 }
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 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362
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 void dmFreeTimelinePoints(DMTimelinePoints *points)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 dmFree(points->points);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 points->points = NULL;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 points->npoints = points->nallocated = 0;
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
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
372 void dmFreeTimelineEventParam(DMTimelineEventParam *param)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
373 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
374 dmFree(param->name);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
375 dmFree(param->vstr);
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
376 dmFreeTimelinePoints(&(param->pts));
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
377 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
378
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
379
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
380 void dmFreeTimelineEvent(DMTimelineEvent *event)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
381 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
382 if (event != NULL)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
383 {
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
384 int param;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
385 for (param = 0; param < event->nparams; param++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
386 dmFreeTimelineEventParam(&(event->params[param]));
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
387 dmFree(event->params);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
388 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
389 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
390
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
391
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 void dmFreeTimelineTrack(DMTimelineTrack *track)
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 if (track != NULL)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 {
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
396 int event;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
397
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 dmFree(track->name);
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
399
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
400 for (event = 0; event < track->nevents; event++)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
401 dmFreeTimelineEvent(track->events[event]);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
402 dmFree(track->events);
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
403
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 dmFreeTimelinePoints(&(track->composite.points));
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 void dmFreeTimeline(DMTimeline *tl)
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 if (tl != NULL)
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 int i;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 for (i = 0; i < tl->ntracks; i++)
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 dmFreeTimelineTrack(tl->tracks[i]);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 dmFree(tl->tracks);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 dmFree(tl->name);
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 }
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
423 static void dmFreePreparedEventGroup(DMPreparedEventGroup *group)
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
424 {
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
425 if (group != NULL)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
426 {
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
427 dmFree(group->events);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
428 dmFree(group);
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
429 }
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
430 }
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
431
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
432
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
433 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl)
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
434 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
435 if (ptl != NULL)
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
436 {
352
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
437 int group;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
438 for (group = 0; group < ptl->ngroups; group++)
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
439 {
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
440 dmFreePreparedEventGroup(ptl->groups[group]);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
441 ptl->groups[group] = NULL;
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
442 }
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
443
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
444 dmFree(ptl->groups);
5eafdc396fa4 Add null pointer check to dmFreePreparedTimelineData().
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
445 ptl->groups = NULL;
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
446 }
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
447 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
448
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
449
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 /* Prepare a loaded timeline for execution. Creates the "stacked" structure
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 * of timeline data for efficient rendering.
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
453 int dmAddSplitPreparedEventGroup(DMPreparedEventGroup **groups, DMTimelineTrack *track, DMTimelineEvent *event)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
454 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
455 DMPreparedEventGroup *node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
456
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
457 for (node = *groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
458 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
459 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
460
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
461 return DMERR_OK;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
462 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
463
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
464
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
465 int dmPrepareTimeline(DMTimeline *tl, DMPreparedTimeline *ptl)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 {
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
467 int group, ntrack, event, err;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
468 DMPreparedEventGroup *groups = NULL, *node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
469
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
470 // Free previous data
340
1c5e7d66312d Work on prepared timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 330
diff changeset
471 dmFreePreparedTimelineData(ptl);
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
472
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
473 // Process tracks
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
474 for (ntrack = 0; ntrack < tl->ntracks; ntrack++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
475 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
476 DMTimelineTrack *track = tl->tracks[ntrack];
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
477 for (event = 0; event < track->nevents; event++)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
478 {
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
479 if ((err = dmAddSplitPreparedEventGroup(&groups, track, track->events[event])) != DMERR_OK)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
480 return err;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
481 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
482 }
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
483
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
484 // Compute number of groups
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
485 ptl->ngroups = 0;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
486 for (node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
487 ptl->ngroups++;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
488
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
489 // Allocate linear array for fast access
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
490 ptl->groups = dmMalloc(sizeof(DMPreparedEventGroup) * ptl->ngroups);
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
491 if (ptl->groups == NULL)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
492 return DMERR_MALLOC;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
493
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
494 // Store pointers in the array
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
495 for (group = 0, node = groups; node != NULL; node = node->next)
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
496 ptl->groups[group++] = node;
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
497
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 /* Seeks to specified position in the timeline. The execution function
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 * only handles monotonously increasing time, going backwards will not work
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 * 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
505 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
506 int dmSeekTimeline(DMPreparedTimeline *tl, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 }
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 /* "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
513 */
330
af04394e9620 And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
514 int dmExecuteTimeline(DMPreparedTimeline *tl, SDL_Surface *screen, int time)
320
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 {
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 return DMERR_OK;
fc79b57d4646 Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 }