annotate dmsimple.c @ 113:34ccf783ecca

Fix some warnings.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Oct 2012 10:27:13 +0300
parents 22ba0490733b
children 16fc6e6cf3b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmsimple.h"
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
2 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
3 #include <tremor/ivorbiscodec.h>
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
4 #include <tremor/ivorbisfile.h>
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
5 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 DMEngineData engine;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 DMFrameData frame;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
12 int engineShowProgress(int loaded, int total)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
13 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
14 int dx = 60,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
15 dh = 20,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
16 dw = engine.screen->w - (2 * dx),
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
17 dy = (engine.screen->h - dh) / 2;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
18
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
19 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
20 return DMERR_INIT_FAIL;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
21
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
22 // Draw the progress bar
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
23 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
24 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
25 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
26
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
27 if (total > 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
28 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
29 dmFillRect(engine.screen,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
30 dx+3, dy+3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
31 dx + 3 + ((dw - 3) * loaded) / total,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
32 dy + dh - 3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
33 dmMapRGB(engine.screen, 200,200,200));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
34 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
35
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
36 // Flip screen
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
37 if (SDL_MUSTLOCK(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
38 SDL_UnlockSurface(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
39
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
40 SDL_Flip(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
41 return DMERR_OK;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
42 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
43
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
44
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 int engineLoadResources()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 int err, loaded, total;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 err = dmres_preload(TRUE, &loaded, &total);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 // Show a nice progress bar while loading
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 if (total > 0 && (loaded % 2) == 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
56 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
57 return err;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 return err;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 int engineGetTick()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
67 return (frame.startTime - engine.startTime) + engine.adjustTime;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 float engineGetTimeDT()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 return (float) engineGetTick() / 1000.0f;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 int engineGetTimeDTi()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 return (float) engineGetTick() / 1000;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 int engineGetTime(int t)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
42
f47011b06d5c Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
85 return engineGetTick() - (1000 * t);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 int engineGetDT(int t)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 return engineGetTime(t) / 1000;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 static int engineResImageLoad(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 SDL_Surface *img = dmLoadImage(res);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 if (res != NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 res->rdata = img;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 return DMERR_OK;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 else
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 return dmferror(res);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
107
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 static void engineResImageFree(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 SDL_FreeSurface((SDL_Surface *)res->rdata);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
113 static BOOL engineResImageProbe(DMResource *res, const char *fext)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
114 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
115 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
116 return fext != NULL && (strcasecmp(fext, ".jpg") == 0 || strcasecmp(fext, ".png") == 0);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
117 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
118
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
119
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
120 #ifdef JSS_SUP_XM
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 static int engineResModuleLoad(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return jssLoadXM(res, (JSSModule **) &(res->rdata));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 static void engineResModuleFree(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 jssFreeModule((JSSModule *) res->rdata);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
131 static BOOL engineResModuleProbe(DMResource *res, const char *fext)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
132 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
133 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
134 return fext != NULL && (strcasecmp(fext, ".xm") == 0 || strcasecmp(fext, ".jmod") == 0);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
135 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
136 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
138
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
139 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
140 static size_t vorbisFileRead(void *ptr, size_t size, size_t nmemb, void *datasource)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
141 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
142 return dmfread(ptr, size, nmemb, (DMResource *) datasource);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
143 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
144
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
145 static int vorbisFileSeek(void *datasource, ogg_int64_t offset, int whence)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
147 return dmfseek((DMResource *) datasource, offset, whence);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
148 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
149
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
150 static int vorbisFileClose(void *datasource)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
151 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
152 (void) datasource;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
153 return 0;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
154 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
155
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
156 static long vorbisFileTell(void *datasource)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
157 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
158 return dmftell((DMResource *) datasource);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
159 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
160
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
161
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
162 static ov_callbacks vorbisFileCBS =
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
163 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
164 vorbisFileRead,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
165 vorbisFileSeek,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
166 vorbisFileClose,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
167 vorbisFileTell
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 };
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
170 static int engineResVorbisLoad(DMResource *res)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
172 OggVorbis_File vf;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
173
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
174 dmMsg(1, "vorbisfile '%s', %d bytes resource loading\n",
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
175 res->filename, res->dataSize);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
176
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
177 if (ov_open_callbacks(res, &vf, NULL, 0, vorbisFileCBS) < 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
178 return DMERR_FOPEN;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
179
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
180 res->rdataSize = ov_pcm_total(&vf, -1) * 2 * 2;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
181 if ((res->rdata = dmMalloc(res->rdataSize + 16)) == NULL)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
182 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
183 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
184 return DMERR_MALLOC;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
185 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
186
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
187 dmMsg(1, "rdataSize=%d bytes?\n", res->rdataSize);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
188
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
189 BOOL eof = FALSE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
190 int left = res->rdataSize;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
191 char *ptr = res->rdata;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
192 int current_section;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
193 while (!eof && left > 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
194 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
195 int ret = ov_read(&vf, ptr, left > 4096 ? 4096 : left, &current_section);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
196 if (ret == 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
197 eof = TRUE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
198 else
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
199 if (ret < 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
200 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
201 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
202 return DMERR_INVALID_DATA;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
203 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
204 else
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
205 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
206 left -= ret;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
207 ptr += ret;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
208 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
209 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
210
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
211 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
212 return DMERR_OK;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
213 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
214
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
215 static void engineResVorbisFree(DMResource *res)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
216 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
217 dmFree(res->rdata);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
218 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
219
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
220 static BOOL engineResVorbisProbe(DMResource *res, const char *fext)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
221 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
222 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
223 return fext != NULL && (strcasecmp(fext, ".ogg") == 0);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
224 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
225 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
226
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
227
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
228 static DMResourceDataOps engineResOps[] =
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
229 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
230 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
231 engineResImageProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
232 engineResImageLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
233 engineResImageFree
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
234 },
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
235
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
236 #ifdef JSS_SUP_XM
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
237 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
238 engineResModuleProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
239 engineResModuleLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
240 engineResModuleFree
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
241 },
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
242 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
243
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
244 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
245 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
246 engineResVorbisProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
247 engineResVorbisLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
248 engineResVorbisFree
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
249 },
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
250 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 };
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
253 static const int nengineResOps = sizeof(engineResOps) / sizeof(engineResOps[0]);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
254
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
255
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 static int engineClassifier(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
259 int i;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 char *fext;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 if (res == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 return DMERR_NULLPTR;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
265 fext = strrchr(res->filename, '.');
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
266 for (i = 0; i < nengineResOps; i++)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
268 DMResourceDataOps *rops = &engineResOps[i];
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
269 if (rops->probe != NULL && rops->probe(res, fext))
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
270 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
271 res->rops = rops;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
272 return DMERR_OK;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
273 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 return DMERR_OK;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 void *engineGetResource(const char *name)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 DMResource *res = dmres_find(name);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 if (res != NULL && res->rdata != NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 return res->rdata;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 else
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 dmError("Could not find resource '%s'.\n", name);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 return NULL;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
293 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
294 static void engineAudioCallbackDebug(void *userdata, Uint8 *stream, int len)
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
295 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
296 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
297 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
298 memset(stream, 0, len);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
299 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
300 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
301 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
302 JSSMixer *d = (JSSMixer *) userdata;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
303 if (d != NULL)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
304 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
305 int pos = ((engine.adjustTime * d->outFreq) / 1000) * jvmGetSampleSize(d) +
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
306 engine.audioSamples;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
307
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
308 memcpy(stream, engine.audioBuf + pos, len);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
309
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
310 engine.audioSamples += len;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
311 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
312 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
313 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
314
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
315 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
316
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
317 void engineAdjustTime(int adj)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
318 {
111
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
319 #ifdef DM_DEBUG
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
320 if (engine.optDebug)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
321 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
322 int tmp = engine.adjustTime + adj;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
323 if (tmp < 0)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
324 tmp = 0;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
325 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
326 if (tmp >= engine.demoDuration * 1000)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
327 tmp = engine.demoDuration * 1000;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
328
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
329 engine.pauseFlag = TRUE;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
330 engine.adjustTime = tmp;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
331 dmPrint(0, "adj=%d, adjtime=%d\n", adj, engine.adjustTime);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
332 }
111
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
333 #endif
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
334 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
335
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 static void engineAudioCallback(void *userdata, Uint8 *stream, int len)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 {
113
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
338 (void) userdata;
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
339
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
340 if (engine.paused)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 {
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
342 memset(stream, 0, len);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
343 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
344 else
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
345 #ifdef DM_USE_JSS
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
346 {
110
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
347 if (engine.dev != NULL)
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
348 jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev));
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
350 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
351 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
352 if (engine.audioPos + len >= engine.audio->rdataSize)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
353 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
354 engine.exitFlag = TRUE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
355 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
356 else
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
357 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
358 memcpy(stream, engine.audio->rdata + engine.audioPos, len);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
359 engine.audioPos += len;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
360 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
361 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 int main(int argc, char *argv[])
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 int err;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 BOOL initSDL = FALSE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 memset(&frame, 0, sizeof(frame));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 memset(&engine, 0, sizeof(engine));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 // Pre-initialization
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 if ((err = demoPreInit(argc, argv)) != DMERR_OK)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 // Initialize resource subsystem
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 dmPrint(1, "Initializing resources subsystem.\n");
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
379 if ((err = dmres_init(engine.optPackFilename, engine.optDataPath, engine.optResFlags, engineClassifier)) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 dmError("Could not initialize resource manager: %d, %s.\n", err, dmErrorStr(err));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 // Initialize SDL components
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 dmError("Could not initialize SDL: %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 initSDL = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 // Initialize JSS
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
394 engine.optAfmt.freq = 44100;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
395 engine.optAfmt.format = AUDIO_S16SYS;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
396 engine.optAfmt.channels = 2;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
397 engine.optAfmt.samples = 16*1024;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
398
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
399
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
400 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 jssInit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
403 switch (engine.optAfmt.format)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
404 {
110
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
405 case AUDIO_S16SYS: engine.jss_format = JSS_AUDIO_S16; break;
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
406 case AUDIO_U16SYS: engine.jss_format = JSS_AUDIO_U16; break;
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
407 case AUDIO_S8: engine.jss_format = JSS_AUDIO_S8; break;
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
408 case AUDIO_U8: engine.jss_format = JSS_AUDIO_U8; break;
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
409 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
411 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n",
110
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
412 engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
110
8db49a23b393 Fixes to make the JSS audio subsystem support work again in the engine framework.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
414 if ((engine.dev = jvmInit(engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq, JMIX_AUTO)) == NULL)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 dmError("jvmInit() returned NULL, voi perkele.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 if ((engine.plr = jmpInit(engine.dev)) == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 dmError("jmpInit() returned NULL\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
425 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 // Initialize SDL audio
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
428 dmPrint(1, "Trying to init SDL audio with: fmt=%d, chn=%d, freq=%d\n",
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
429 engine.optAfmt.format, engine.optAfmt.channels, engine.optAfmt.freq);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
431 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
432 if (engine.optDebug)
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
433 engine.optAfmt.callback = engineAudioCallbackDebug;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
434 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
435 #endif
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
436 engine.optAfmt.callback = engineAudioCallback;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
438 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 dmError("Couldn't open audio: %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 // Initialize SDL video
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 if (engine.screen == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 SDL_ShowCursor(SDL_DISABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 SDL_WM_SetCaption(dmProgDesc, dmProgName);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 // Load resources
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 if ((err = engineLoadResources()) != DMERR_OK)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 dmError("Error loading resources, %d: %s.\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 err, dmErrorStr(err));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 // Final initializations
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
468 if ((err = demoInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
471 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
472 if (engine.optDebug)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
473 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
474 Uint8 *ptr;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
475 int left = engine.dev->outFreq * engine.demoDuration;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
476 engine.audioBufSize = jvmGetSampleSize(engine.dev) * engine.dev->outFreq * engine.demoDuration;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
477 if ((engine.audioBuf = dmMalloc(engine.audioBufSize)) == NULL)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
478 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
479 dmError("Could not allocate audio stream buffer of %d bytes.\n",
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
480 engine.audioBufSize);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
481 goto error_exit;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
482 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
483
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
484 ptr = engine.audioBuf;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
485 while (left > 0)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
486 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
487 int length = left;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
488 if (length > 16*1024)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
489 length = 16*1024;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
490
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
491 jvmRenderAudio(engine.dev, ptr, length);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
492 ptr += jvmGetSampleSize(engine.dev) * length;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
493 left -= length;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
494 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
495 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
496 #endif
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
497
41
780300a8d322 Move SDL_PauseAudio(0) to the "engine" instead of the demo code.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
498 SDL_PauseAudio(0);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 engine.startTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 while (!engine.exitFlag)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 while (SDL_PollEvent(&engine.event))
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 switch (engine.event.type)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 case SDL_KEYDOWN:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 switch (engine.event.key.keysym.sym)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 case SDLK_ESCAPE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 case SDLK_SPACE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 engine.pauseFlag = !engine.pauseFlag;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
517 #ifdef DM_DEBUG
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
518 case SDLK_LEFT: engineAdjustTime(-500); break;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
519 case SDLK_RIGHT: engineAdjustTime( 500); break;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
520 case SDLK_UP: engineAdjustTime( 1000); break;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
521 case SDLK_DOWN: engineAdjustTime(-1000); break;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
522 #endif
109
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
523 case SDLK_RETURN:
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
524 if (engine.event.key.keysym.mod & KMOD_ALT)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
525 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
526 engine.optVFlags ^= SDL_FULLSCREEN;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
527 SDL_FreeSurface(engine.screen);
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
528 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
529 if (engine.screen == NULL)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
530 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
531 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
532 goto error_exit;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
533 }
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
534 }
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
535 break;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
536
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 default:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 case SDL_VIDEOEXPOSE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 case SDL_QUIT:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 // Draw frame
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 frame.startTime = SDL_GetTicks();
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
553 if (engine.pauseFlag != engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
554 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
555 engine.paused = engine.pauseFlag;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
556 engine.pauseTime = engineGetTick();
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
557 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
558
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
559 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
560 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
561 engine.startTime = frame.startTime - engine.pauseTime;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
562 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 dmError("Can't lock surface.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 // Call main tick
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 if ((err = demoMainTick()) != DMERR_OK)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 // Flip screen
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 if (SDL_MUSTLOCK(engine.screen) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 SDL_UnlockSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 SDL_Flip(engine.screen);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
579 SDL_Delay(engine.paused ? 100 : 20);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 // Get frame time, etc
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 frame.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 engine.currFrame++;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 engine.totalFrameTime += frame.endTime - frame.startTime;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 // Print benchmark results
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 engine.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 dmPrint(1, "%d frames in %d ms, fps = %1.3f\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 engine.currFrame, engine.endTime - engine.startTime,
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 error_exit:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 dmPrint(1, "Shutting down.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 SDL_ShowCursor(SDL_ENABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 SDL_PauseAudio(1);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 if (engine.screen)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 SDL_FreeSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
603 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 SDL_LockAudio();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 jmpClose(engine.plr);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 jvmClose(engine.dev);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 jssClose();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 SDL_UnlockAudio();
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
609 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 dmres_close();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
613 demoShutdown();
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
614
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 if (initSDL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 SDL_Quit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
618 demoQuit();
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 return 0;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 }