annotate dmengine.c @ 763:ad512e54c689

Fix 10L in engine base code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 May 2013 06:36:54 +0300
parents bb14d7907eb2
children 954b1b392c8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
642
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
1 /*
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
2 * dmlib
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
3 * -- Demo engine / editor common code and definitions
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
5 * (C) Copyright 2012-2013 Tecnic Software productions (TNSP)
0888971cbff8 Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents: 573
diff changeset
6 */
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmengine.h"
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmimage.h"
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #ifdef DM_USE_TREMOR
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <tremor/ivorbiscodec.h>
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include <tremor/ivorbisfile.h>
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 DMEngineData engine;
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
18 DMEffect *engineEffects = NULL;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
19 int nengineEffects = 0, nengineEffectsAlloc = 0;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
20
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
21
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
22 int engineRegisterEffect(const DMEffect *ef)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
23 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
24 if (ef == NULL)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
25 return DMERR_NULLPTR;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
26
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
27 // Allocate more space for effects
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
28 if (nengineEffects + 1 >= nengineEffectsAlloc)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
29 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
30 nengineEffectsAlloc += 16;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
31 engineEffects = dmRealloc(engineEffects, sizeof(DMEffect) * nengineEffectsAlloc);
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
32 if (engineEffects == NULL)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
33 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
34 dmError("Could not expand effects structure.\n");
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
35 return DMERR_INIT_FAIL;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
36 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
37 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
38
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
39 // Copy effects structure
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
40 memcpy(engineEffects + nengineEffects, ef, sizeof(DMEffect));
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
41 nengineEffects++;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
42
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
43 return DMERR_OK;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
44 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
45
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
46
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
47 int engineInitializeEffects(DMEngineData *engine)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
48 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
49 int i, res;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
50
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
51 dmFree(engine->effectData);
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
52 engine->effectData = dmCalloc(nengineEffectsAlloc, sizeof(void *));
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
53 if (engine->effectData == NULL)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
54 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
55 dmError("Could not expand effects data structure.\n");
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
56 return DMERR_INIT_FAIL;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
57 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
58
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
59 for (i = 0; i < nengineEffects; i++)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
60 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
61 if (engineEffects[i].init != NULL &&
369
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
62 (res = engineEffects[i].init(engine, &(engine->effectData[i]))) != DMERR_OK)
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
63 return res;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
64 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
65
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
66 return DMERR_OK;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
67 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
68
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
69
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
70 void engineShutdownEffects(DMEngineData *engine)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
71 {
369
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
72 if (engine != NULL && engine->effectData != NULL)
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
73 {
369
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
74 int i;
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
75 for (i = 0; i < nengineEffects; i++)
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
76 {
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
77 if (engineEffects[i].shutdown != NULL)
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
78 engineEffects[i].shutdown(engine, engine->effectData[i]);
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
79 }
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
80 dmFree(engine->effectData);
e1c984404b6b Re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
81 engine->effectData = NULL;
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
82 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
83 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
84
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
85
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
86 DMEffect *engineFindEffect(const char *name, const int nparams)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
87 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
88 int i;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
89 for (i = 0; i < nengineEffects; i++)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
90 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
91 if (strcmp(engineEffects[i].name, name) == 0 &&
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
92 engineEffects[i].nparams == nparams)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
93 return &engineEffects[i];
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
94 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
95 return NULL;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
96 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
97
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
98
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
99 DMEffect *engineFindEffectByName(const char *name)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
100 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
101 int i;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
102 for (i = 0; i < nengineEffects; i++)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
103 {
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
104 if (strcmp(engineEffects[i].name, name) == 0)
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
105 return &engineEffects[i];
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
106 }
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
107 return NULL;
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 367
diff changeset
108 }
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 static int engineResImageLoad(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 SDL_Surface *img = dmLoadImage(res);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 if (res != NULL)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
116 res->resData = img;
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 return DMERR_OK;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 return dmferror(res);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 static void engineResImageFree(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
126 SDL_FreeSurface((SDL_Surface *)res->resData);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 static BOOL engineResImageProbe(DMResource *res, const char *fext)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 (void) res;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 return fext != NULL && (strcasecmp(fext, ".jpg") == 0 || strcasecmp(fext, ".png") == 0);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 #ifdef JSS_SUP_XM
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 static int engineResModuleLoad(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
139 return jssLoadXM(res, (JSSModule **) &(res->resData));
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 static void engineResModuleFree(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
144 jssFreeModule((JSSModule *) res->resData);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 static BOOL engineResModuleProbe(DMResource *res, const char *fext)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 (void) res;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 return fext != NULL && (strcasecmp(fext, ".xm") == 0 || strcasecmp(fext, ".jmod") == 0);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 #ifdef DM_USE_TREMOR
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 static size_t vorbisFileRead(void *ptr, size_t size, size_t nmemb, void *datasource)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 return dmfread(ptr, size, nmemb, (DMResource *) datasource);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 static int vorbisFileSeek(void *datasource, ogg_int64_t offset, int whence)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 return dmfseek((DMResource *) datasource, offset, whence);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 static int vorbisFileClose(void *datasource)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 (void) datasource;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 return 0;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 static long vorbisFileTell(void *datasource)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 return dmftell((DMResource *) datasource);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 static ov_callbacks vorbisFileCBS =
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 vorbisFileRead,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 vorbisFileSeek,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 vorbisFileClose,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 vorbisFileTell
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 };
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 static int engineResVorbisLoad(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 OggVorbis_File vf;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 dmMsg(1, "vorbisfile '%s', %d bytes resource loading\n",
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
191 res->filename, res->rawSize);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 if (ov_open_callbacks(res, &vf, NULL, 0, vorbisFileCBS) < 0)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 return DMERR_FOPEN;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
196 res->resSize = ov_pcm_total(&vf, -1) * 2 * 2;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
197 if ((res->resData = dmMalloc(res->resSize + 16)) == NULL)
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 ov_clear(&vf);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 return DMERR_MALLOC;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
203 dmMsg(1, "rdataSize=%d bytes?\n", res->resSize);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 BOOL eof = FALSE;
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
206 int left = res->resSize;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
207 char *ptr = res->resData;
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 int current_section;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 while (!eof && left > 0)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 int ret = ov_read(&vf, ptr, left > 4096 ? 4096 : left, &current_section);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 if (ret == 0)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 eof = TRUE;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 if (ret < 0)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 ov_clear(&vf);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 return DMERR_INVALID_DATA;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 left -= ret;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 ptr += ret;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 ov_clear(&vf);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 return DMERR_OK;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 static void engineResVorbisFree(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
233 dmFree(res->resData);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 static BOOL engineResVorbisProbe(DMResource *res, const char *fext)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 (void) res;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 return fext != NULL && (strcasecmp(fext, ".ogg") == 0);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 static DMResourceDataOps engineResOps[] =
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 engineResImageProbe,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 engineResImageLoad,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 engineResImageFree
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 },
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 #ifdef JSS_SUP_XM
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 engineResModuleProbe,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 engineResModuleLoad,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 engineResModuleFree
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 },
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 #ifdef DM_USE_TREMOR
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 engineResVorbisProbe,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 engineResVorbisLoad,
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 engineResVorbisFree
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 },
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 };
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 static const int nengineResOps = sizeof(engineResOps) / sizeof(engineResOps[0]);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 int engineClassifier(DMResource *res)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 int i;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 char *fext;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 if (res == NULL)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 return DMERR_NULLPTR;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 fext = strrchr(res->filename, '.');
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 for (i = 0; i < nengineResOps; i++)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 DMResourceDataOps *rops = &engineResOps[i];
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 if (rops->probe != NULL && rops->probe(res, fext))
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 res->rops = rops;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 return DMERR_OK;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 return DMERR_OK;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
366
38e10b5f4e09 Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
295 void *engineGetResource(DMEngineData *eng, const char *name)
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
366
38e10b5f4e09 Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
297 DMResource *res;
38e10b5f4e09 Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
298 if (eng != NULL &&
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
299 (res = dmResourceFind(eng->resources, name)) != NULL &&
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
300 res->resData != NULL)
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 642
diff changeset
301 return res->resData;
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 dmError("Could not find resource '%s'.\n", name);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 return NULL;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 #ifdef DM_USE_JSS
366
38e10b5f4e09 Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
311 void engineGetJSSInfo(DMEngineData *eng, BOOL *playing, int *order, JSSPattern **pat, int *npattern, int *row)
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
763
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
313 JSS_LOCK(eng->jssPlr);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314
763
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
315 *playing = eng->jssPlr->isPlaying;
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
316 *row = eng->jssPlr->row;
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
317 *pat = eng->jssPlr->pattern;
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
318 *npattern = eng->jssPlr->npattern;
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
319 *order = eng->jssPlr->order;
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
763
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
321 JSS_UNLOCK(eng->jssPlr);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
366
38e10b5f4e09 Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
324 void engineGetJSSChannelInfo(DMEngineData *eng, const int channel, int *ninst, int *nextInst, int *freq, int *note)
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 {
763
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
326 JSS_LOCK(eng->jssPlr);
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
327 JSSPlayerChannel *chn = &(eng->jssPlr->channels[channel]);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 *ninst = chn->ninstrument;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 *nextInst = chn->nextInstrument;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 *freq = chn->freq;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 *note = chn->note;
763
ad512e54c689 Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
332 JSS_UNLOCK(eng->jssPlr);
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 #endif
367
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
335
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
336
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
337 int engineGetTick(DMEngineData *engine)
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
338 {
390
a7ee3567f718 Remove adjustTime variable, it is not needed anymore.
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
339 return engine->frameTime - engine->startTime;
367
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
340 }
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
341
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
342
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
343 float engineGetTimeDT(DMEngineData *engine)
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
344 {
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
345 return (float) engineGetTick(engine) / 1000.0f;
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
346 }
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
347
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
348
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
349 int engineGetTimeDTi(DMEngineData *engine)
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
350 {
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
351 return (float) engineGetTick(engine) / 1000;
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
352 }
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
353
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
354
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
355 int engineGetTime(DMEngineData *engine, int t)
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
356 {
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
357 return engineGetTick(engine) - (1000 * t);
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
358 }
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
359
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
360
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
361 int engineGetDT(DMEngineData *engine, int t)
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
362 {
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
363 return engineGetTime(engine, t) / 1000;
9875c65029af Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
364 }