Mercurial > hg > dmlib
annotate dmengine.h @ 395:530db8fa4569
Implement functions for copying timelines and timeline components.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 07:21:39 +0300 |
parents | a7ee3567f718 |
children | 0f290af63fc1 |
rev | line source |
---|---|
372 | 1 #ifndef DMENGINE_H |
2 #define DMENGINE_H | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 #include "dmlib.h" |
310
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
5 #include <SDL_events.h> |
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
6 #include <SDL_audio.h> |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "dmres.h" |
368 | 8 #include "dmvecmat.h" |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
10 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "jss.h" |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 #include "jssmod.h" |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #include "jssmix.h" |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include "jssplr.h" |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
15 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
317 | 18 #ifdef __cplusplus |
19 extern "C" { | |
20 #endif | |
21 | |
22 | |
368 | 23 #define DT_MAGIC_ID "SDMETLNE" |
24 #define DT_MAX_EFFECT_PARAMS 16 | |
25 #define DT_MAX_NAME_LENGTH 32 | |
26 #define DT_FLOAT_STORE_SIZE 16 | |
27 | |
28 | |
29 enum | |
30 { | |
31 EFIT_SET, // No interpolation, just "set" the value | |
32 EFIT_LINEAR, // Linear interpolation | |
33 EFIT_SMOOTH, // Smoothstep interpolation | |
34 }; | |
35 | |
36 enum | |
37 { | |
38 EFPT_INT, | |
39 EFPT_FLOAT, | |
40 EFPT_STRING, | |
41 EFPT_VECTOR, | |
42 EFPT_MATRIX, | |
43 }; | |
44 | |
45 | |
46 typedef struct | |
47 { | |
48 int type; // Interpolation type (EFIT_*) between this and next point | |
49 int time; // Offsets to event start, -1 == attach to event start, -2 = event end (if event) | |
50 | |
51 int vint; | |
52 DMFloat vfloat; | |
53 DMVector vector; | |
54 DMMatrix matrix; | |
55 } DMTimelinePoint; | |
56 | |
57 | |
58 typedef struct | |
59 { | |
60 int npoints, nallocated; | |
61 DMTimelinePoint *points; | |
62 } DMTimelinePoints; | |
63 | |
64 | |
65 typedef struct | |
66 { | |
67 char *name; // Name / description of the parameter | |
68 int type; // Type (EFPT_*) | |
69 | |
70 DMTimelinePoints pts; | |
71 char *vstr; | |
72 | |
73 // Current values (interpolated) | |
74 int vint; | |
75 DMFloat vfloat; | |
76 DMVector vvector; | |
77 DMMatrix vmatrix; | |
78 } DMTimelineEventParam; | |
79 | |
80 | |
81 typedef struct | |
82 { | |
83 char name[DT_MAX_NAME_LENGTH]; | |
84 Uint32 type; | |
85 } DMFTimelineEventParam; | |
86 | |
87 | |
88 struct DMEngineData; | |
89 | |
90 | |
91 typedef struct | |
92 { | |
93 char * name; | |
94 int type; | |
95 | |
96 int (*init)(struct DMEngineData *, void **data); | |
97 void (*shutdown)(struct DMEngineData *, void *data); | |
98 int (*render)(SDL_Surface *screen, void *data, const DMTimelineEventParam *params, const int time); | |
99 | |
100 int nparams; | |
101 DMTimelineEventParam params[DT_MAX_EFFECT_PARAMS]; | |
102 } DMEffect; | |
103 | |
104 | |
105 typedef struct | |
106 { | |
107 Uint32 start, duration; | |
108 char effectName[DT_MAX_NAME_LENGTH]; | |
109 Uint32 nparams; | |
110 } DMFTimelineEvent; | |
111 | |
112 | |
113 typedef struct | |
114 { | |
115 int start, duration; | |
116 DMEffect *effect; | |
117 int nparams; | |
118 DMTimelineEventParam *params; | |
119 } DMTimelineEvent; | |
120 | |
121 | |
122 typedef struct | |
123 { | |
124 BOOL enabled; | |
125 DMTimelinePoints points; | |
126 } DMTimelineCurve; | |
127 | |
128 | |
129 typedef struct | |
130 { | |
131 char name[DT_MAX_NAME_LENGTH]; | |
132 Uint8 enabled; | |
133 Uint32 nevents; | |
134 } DMFTimelineTrack; | |
135 | |
136 | |
137 typedef struct | |
138 { | |
139 char *name; // Name of the timeline track | |
140 BOOL enabled; // Enabled? | |
141 | |
142 int nevents, nallocated; // Number of events | |
143 DMTimelineEvent **events; // Events | |
144 | |
145 DMTimelineCurve composite; // Composite curve (transparency of the "layer") | |
146 } DMTimelineTrack; | |
147 | |
148 | |
149 typedef struct | |
150 { | |
151 char magic[8]; | |
152 char name[DT_MAX_NAME_LENGTH]; | |
153 Uint32 ntracks; | |
154 Uint32 duration; | |
155 } DMFTimeline; | |
156 | |
157 | |
158 typedef struct | |
159 { | |
160 char *name; | |
161 int ntracks, nallocated, duration; | |
162 DMTimelineTrack **tracks; | |
163 } DMTimeline; | |
164 | |
165 | |
166 typedef struct | |
167 { | |
168 DMTimelineTrack *track; | |
169 DMTimelineEvent *event; | |
170 } DMPreparedEvent; | |
171 | |
172 | |
173 typedef struct _DMPreparedEventGroup | |
174 { | |
175 int start, end, nevents, nallocated; | |
176 DMPreparedEvent *events; | |
177 | |
178 struct _DMPreparedEventGroup *next, *prev; | |
179 } DMPreparedEventGroup; | |
180 | |
181 | |
182 typedef struct | |
183 { | |
184 int duration, ngroups, pos; | |
185 DMPreparedEventGroup **groups; | |
186 } DMPreparedTimeline; | |
187 | |
188 | |
367 | 189 typedef struct DMEngineData |
359
59045853853d
Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents:
354
diff
changeset
|
190 { |
59045853853d
Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents:
354
diff
changeset
|
191 DMResourceLib *resources; |
368 | 192 void **effectData; |
359
59045853853d
Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents:
354
diff
changeset
|
193 |
354 | 194 DMResource *timeline; |
345
cac13f180169
Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
195 DMTimeline *tl; |
cac13f180169
Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
196 DMPreparedTimeline *ptl; |
cac13f180169
Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
197 |
361 | 198 int frameTime, frameCount, |
199 startTime, endTime, | |
390
a7ee3567f718
Remove adjustTime variable, it is not needed anymore.
Matti Hamalainen <ccr@tnsp.org>
parents:
382
diff
changeset
|
200 pauseTime; |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
201 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
202 BOOL pauseFlag, paused, exitFlag; |
361 | 203 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 SDL_Surface *screen; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 SDL_Event event; |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
206 SDL_AudioSpec optAfmt; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
207 int optScrWidth, optScrHeight, optVFlags, optBitDepth, optResFlags; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
208 char *optDataPath, *optPackFilename; |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
210 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 JSSMixer *dev; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 JSSPlayer *plr; |
110
8db49a23b393
Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
213 int jss_format; |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
214 #endif |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
215 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
216 #ifdef DM_USE_TREMOR |
359
59045853853d
Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents:
354
diff
changeset
|
217 DMResource *audioRes; |
113 | 218 size_t audioPos; |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
219 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
221 int (*demoInit)(struct DMEngineData *); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
222 int (*demoInitPreVideo)(struct DMEngineData *); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
223 int (*demoInitPostVideo)(struct DMEngineData *); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
224 int (*demoRender)(struct DMEngineData *); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
225 void (*demoShutdown)(struct DMEngineData *); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
226 void (*demoQuit)(struct DMEngineData *); |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
227 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 } DMEngineData; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
382
371edff7dc3d
Fix extern variables to match what are actually declared in dmengine.c
Matti Hamalainen <ccr@tnsp.org>
parents:
375
diff
changeset
|
231 extern DMEffect *engineEffects; |
371edff7dc3d
Fix extern variables to match what are actually declared in dmengine.c
Matti Hamalainen <ccr@tnsp.org>
parents:
375
diff
changeset
|
232 extern int nengineEffects, nengineEffectsAlloc; |
368 | 233 |
234 | |
235 // Effect registration | |
236 int engineRegisterEffect(const DMEffect *ef); | |
371
56bd2693472f
Oops, the function prototypes were incorrect.
Matti Hamalainen <ccr@tnsp.org>
parents:
368
diff
changeset
|
237 int engineInitializeEffects(DMEngineData *); |
56bd2693472f
Oops, the function prototypes were incorrect.
Matti Hamalainen <ccr@tnsp.org>
parents:
368
diff
changeset
|
238 void engineShutdownEffects(DMEngineData *); |
368 | 239 DMEffect *engineFindEffect(const char *name, const int nparams); |
240 DMEffect *engineFindEffectByName(const char *name); | |
241 | |
242 | |
243 // Basic timeline handling | |
244 int dmLoadTimeline(DMResource *res, DMTimeline **tl); | |
245 void dmFreeTimeline(DMTimeline *tl); | |
246 | |
247 void dmFreeTimelinePoints(DMTimelinePoints *points); | |
248 void dmFreeTimelineEventParam(DMTimelineEventParam *param); | |
249 void dmFreeTimelineEvent(DMTimelineEvent *event); | |
250 void dmFreeTimelineTrack(DMTimelineTrack *track); | |
251 | |
252 | |
253 // Execution related | |
254 int dmPrepareTimeline(DMTimeline *tl, DMPreparedTimeline *ptl); | |
255 void dmFreePreparedTimelineData(DMPreparedTimeline *ptl); | |
256 | |
257 int dmSeekTimeline(DMPreparedTimeline *tl, int time); | |
258 int dmExecuteTimeline(DMPreparedTimeline *tl, SDL_Surface *screen, int time); | |
259 | |
260 | |
261 // Editing/saving related functions | |
395
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
262 int dmCopyTimelinePoints(const DMTimelinePoints *src, DMTimelinePoints *dst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
263 int dmCopyTimelineEventParam(const DMTimelineEventParam *src, DMTimelineEventParam *dst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
264 int dmCopyTimelineEvent(const DMTimelineEvent *src, DMTimelineEvent **pdst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
265 int dmCopyTimelineCurve(const DMTimelineCurve *src, DMTimelineCurve *dst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
266 int dmCopyTimelineTrack(const DMTimelineTrack *src, DMTimelineTrack **pdst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
267 int dmCopyTimeline(const DMTimeline *src, DMTimeline **pdst); |
530db8fa4569
Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
268 |
368 | 269 int dmSaveTimeline(DMResource *res, DMTimeline *tl); |
270 | |
271 int dmTimelineNew(DMTimeline **tl, const char *name); | |
272 int dmTimelineAddTrack(DMTimeline *tl, DMTimelineTrack **track, const char *name); | |
273 int dmTimelineTrackAddEvent(DMTimelineTrack *track, int start, int duration, DMTimelineEvent **pev); | |
274 int dmTimelineEventSetEffect(DMTimelineEvent *event, const char *name); | |
275 | |
276 DMTimelineEvent *dmTimelineGetEventAt(DMTimelineTrack *track, int time); | |
277 | |
278 | |
279 // Resource helpers | |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
280 #define engineGetResImage(eng, x, name) \ |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 do { \ |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
282 if ((x = (SDL_Surface *) engineGetResource(eng, name)) == NULL) \ |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 return DMERR_INIT_FAIL; \ |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 } while (0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
286 #define engineGetResModule(eng, x, name) \ |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 do { \ |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
288 if ((x = (JSSModule *) engineGetResource(eng, name)) == NULL) \ |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 return DMERR_INIT_FAIL; \ |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 } while (0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 |
367 | 292 #define engineFindResource(eng, name) dmres_find((eng)->resources, name) |
293 | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
295 int engineClassifier(DMResource *res); |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
296 void * engineGetResource(DMEngineData *eng, const char *name); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
297 int engineGetTime(DMEngineData *eng, int t); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
298 int engineGetTimeDTi(DMEngineData *eng); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
299 int engineGetTick(DMEngineData *eng); |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
300 float engineGetTimeDT(DMEngineData *eng); |
368 | 301 |
302 // Implemented in actual demo code | |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
361
diff
changeset
|
303 int demoPreInit(DMEngineData *eng); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 |
317 | 305 |
306 #ifdef __cplusplus | |
307 } | |
308 #endif | |
309 | |
372 | 310 #endif // DMENGINE_H |