Mercurial > hg > dmlib
annotate dmsimple.c @ 336:13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 15 Oct 2012 14:34:06 +0300 |
parents | 2d19b5b8350c |
children | c6ec970dc3cf |
rev | line source |
---|---|
310
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1 #include <SDL.h> |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 #include "dmsimple.h" |
310
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
3 #include "dmargs.h" |
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
4 #include "dmimage.h" |
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
5 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
6 #ifdef DM_USE_TREMOR |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
7 #include <tremor/ivorbiscodec.h> |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
8 #include <tremor/ivorbisfile.h> |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
9 #endif |
32
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 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 DMEngineData engine; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 DMFrameData frame; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
16 static DMOptArg optList[] = |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
17 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
18 { 0, '?', "help", "Show this help", OPT_NONE }, |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
19 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
20 { 2, 'f', "fs", "Fullscreen", OPT_NONE }, |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
21 #ifdef DM_DEVEL |
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
22 { 3, 'd', "devel", "Development mode", OPT_NONE }, |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
23 #endif |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
24 }; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
25 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
26 const int optListN = sizeof(optList) / sizeof(optList[0]); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
27 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
28 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
29 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
30 static void argShowHelp() |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
31 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
32 dmPrintBanner(stdout, dmProgName, "[options]"); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
33 dmArgsPrintHelp(stdout, optList, optListN); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
34 } |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
35 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
36 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
37 static BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
38 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
39 (void) optArg; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
40 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
41 switch (optN) |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
42 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
43 case 0: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
44 argShowHelp(); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
45 exit(0); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
46 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
47 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
48 case 1: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
49 dmVerbosity++; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
50 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
51 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
52 case 2: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
53 engine.optVFlags |= SDL_FULLSCREEN; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
54 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
55 |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
56 #ifdef DM_DEVEL |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
57 case 3: |
335
2d19b5b8350c
Fix remains of the debug/devel changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
58 engine.optDevel = TRUE; |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
59 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
60 #endif |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
61 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
62 default: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
63 dmError("Unknown option '%s'.\n", currArg); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
64 return FALSE; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
65 } |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
66 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
67 return TRUE; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
68 } |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
69 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
70 |
40 | 71 int engineShowProgress(int loaded, int total) |
72 { | |
73 int dx = 60, | |
74 dh = 20, | |
75 dw = engine.screen->w - (2 * dx), | |
76 dy = (engine.screen->h - dh) / 2; | |
77 | |
78 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) | |
79 return DMERR_INIT_FAIL; | |
80 | |
81 // Draw the progress bar | |
82 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0)); | |
83 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255)); | |
84 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0)); | |
85 | |
86 if (total > 0) | |
87 { | |
88 dmFillRect(engine.screen, | |
89 dx+3, dy+3, | |
90 dx + 3 + ((dw - 3) * loaded) / total, | |
91 dy + dh - 3, | |
92 dmMapRGB(engine.screen, 200,200,200)); | |
93 } | |
94 | |
95 // Flip screen | |
96 if (SDL_MUSTLOCK(engine.screen) != 0) | |
97 SDL_UnlockSurface(engine.screen); | |
98 | |
99 SDL_Flip(engine.screen); | |
100 return DMERR_OK; | |
101 } | |
102 | |
103 | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 int engineLoadResources() |
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 int err, loaded, total; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 err = dmres_preload(TRUE, &loaded, &total); |
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 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS) |
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 // Show a nice progress bar while loading |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 if (total > 0 && (loaded % 2) == 0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 { |
40 | 115 if ((err = engineShowProgress(loaded, total)) != DMERR_OK) |
116 return err; | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 return err; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 } |
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 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 int engineGetTick() |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 { |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
126 return (frame.startTime - engine.startTime) + engine.adjustTime; |
32
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 |
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 float engineGetTimeDT() |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 return (float) engineGetTick() / 1000.0f; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 int engineGetTimeDTi() |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 return (float) engineGetTick() / 1000; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 int engineGetTime(int t) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 { |
42 | 144 return engineGetTick() - (1000 * t); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 int engineGetDT(int t) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 return engineGetTime(t) / 1000; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 static int engineResImageLoad(DMResource *res) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 SDL_Surface *img = dmLoadImage(res); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 if (res != NULL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 res->rdata = img; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 return DMERR_OK; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 else |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 return dmferror(res); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
166 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 static void engineResImageFree(DMResource *res) |
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 SDL_FreeSurface((SDL_Surface *)res->rdata); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 } |
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 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
|
173 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
174 (void) res; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
175 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
|
176 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
177 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
178 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
179 #ifdef JSS_SUP_XM |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 static int engineResModuleLoad(DMResource *res) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 return jssLoadXM(res, (JSSModule **) &(res->rdata)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 static void engineResModuleFree(DMResource *res) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 jssFreeModule((JSSModule *) res->rdata); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
190 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
|
191 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
192 (void) res; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
193 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
|
194 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
195 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
197 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
198 #ifdef DM_USE_TREMOR |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
199 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
|
200 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
201 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
|
202 } |
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 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
|
205 { |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
206 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
|
207 } |
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 static int vorbisFileClose(void *datasource) |
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 (void) datasource; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
212 return 0; |
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 long vorbisFileTell(void *datasource) |
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 return dmftell((DMResource *) datasource); |
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 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
221 static ov_callbacks vorbisFileCBS = |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
222 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
223 vorbisFileRead, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
224 vorbisFileSeek, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
225 vorbisFileClose, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
226 vorbisFileTell |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 }; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
229 static int engineResVorbisLoad(DMResource *res) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 { |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
231 OggVorbis_File vf; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
232 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
233 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
|
234 res->filename, res->dataSize); |
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 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
|
237 return DMERR_FOPEN; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
238 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
239 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
|
240 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
|
241 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
242 ov_clear(&vf); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
243 return DMERR_MALLOC; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
244 } |
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 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
|
247 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
248 BOOL eof = FALSE; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
249 int left = res->rdataSize; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
250 char *ptr = res->rdata; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
251 int current_section; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
252 while (!eof && left > 0) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
253 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
254 int ret = ov_read(&vf, ptr, left > 4096 ? 4096 : left, ¤t_section); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
255 if (ret == 0) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
256 eof = TRUE; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
257 else |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
258 if (ret < 0) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
259 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
260 ov_clear(&vf); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
261 return DMERR_INVALID_DATA; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
262 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
263 else |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
264 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
265 left -= ret; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
266 ptr += ret; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
267 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
268 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
269 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
270 ov_clear(&vf); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
271 return DMERR_OK; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
272 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
273 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
274 static void engineResVorbisFree(DMResource *res) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
275 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
276 dmFree(res->rdata); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
277 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
278 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
279 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
|
280 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
281 (void) res; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
282 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
|
283 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
284 #endif |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
285 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
286 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
287 static DMResourceDataOps engineResOps[] = |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
288 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
289 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
290 engineResImageProbe, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
291 engineResImageLoad, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
292 engineResImageFree |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
293 }, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
294 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
295 #ifdef JSS_SUP_XM |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
296 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
297 engineResModuleProbe, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
298 engineResModuleLoad, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
299 engineResModuleFree |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
300 }, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
301 #endif |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
302 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
303 #ifdef DM_USE_TREMOR |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
304 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
305 engineResVorbisProbe, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
306 engineResVorbisLoad, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
307 engineResVorbisFree |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
308 }, |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
309 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 }; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
312 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
|
313 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
314 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 static int engineClassifier(DMResource *res) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 { |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
317 int i; |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 char *fext; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 if (res == NULL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 return DMERR_NULLPTR; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
323 fext = strrchr(res->filename, '.'); |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
324 for (i = 0; i < nengineResOps; i++) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 { |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
326 DMResourceDataOps *rops = &engineResOps[i]; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
327 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
|
328 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
329 res->rops = rops; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
330 return DMERR_OK; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
331 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 return DMERR_OK; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 void *engineGetResource(const char *name) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 DMResource *res = dmres_find(name); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 if (res != NULL && res->rdata != NULL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 return res->rdata; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 else |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 dmError("Could not find resource '%s'.\n", name); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 return NULL; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
351 #if defined(DM_DEVEL) && defined(DM_USE_JSS) |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
352 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
|
353 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
354 if (engine.paused) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
355 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
356 memset(stream, 0, len); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
357 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
358 else |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
359 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
360 JSSMixer *d = (JSSMixer *) userdata; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
361 if (d != NULL) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
362 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
363 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
|
364 engine.audioSamples; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
365 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
366 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
|
367 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
368 engine.audioSamples += len; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
369 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
370 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
371 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
372 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
373 #endif |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
374 |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
375 void engineAdjustTime(int adj) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
376 { |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
377 #ifdef DM_DEVEL |
335
2d19b5b8350c
Fix remains of the debug/devel changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
378 if (engine.optDevel) |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
379 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
380 int tmp = engine.adjustTime + adj; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
381 if (tmp < 0) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
382 tmp = 0; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
383 else |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
384 if (tmp >= engine.demoDuration * 1000) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
385 tmp = engine.demoDuration * 1000; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
386 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
387 engine.pauseFlag = TRUE; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
388 engine.adjustTime = tmp; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
389 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
|
390 } |
111 | 391 #endif |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
392 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
393 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 static void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 { |
113 | 396 (void) userdata; |
397 | |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
398 if (engine.paused) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 { |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
400 memset(stream, 0, len); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
401 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
402 else |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
403 #ifdef DM_USE_JSS |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
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 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
|
406 jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev)); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 } |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
408 #endif |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
409 #ifdef DM_USE_TREMOR |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
410 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
|
411 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
412 engine.exitFlag = TRUE; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
413 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
414 else |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
415 { |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
416 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
|
417 engine.audioPos += len; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
418 } |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
419 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 } |
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 |
277
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
423 #ifdef DM_USE_JSS |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
424 void engineGetJSSInfo(BOOL *playing, int *order, JSSPattern **pat, int *npattern, int *row) |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
425 { |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
426 JSS_LOCK(engine.plr); |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
427 |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
428 *playing = engine.plr->isPlaying; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
429 *row = engine.plr->row; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
430 *pat = engine.plr->pattern; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
431 *npattern = engine.plr->npattern; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
432 *order = engine.plr->order; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
433 |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
434 JSS_UNLOCK(engine.plr); |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
435 } |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
436 |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
437 void engineGetJSSChannelInfo(const int channel, int *ninst, int *nextInst, int *freq, int *note) |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
438 { |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
439 JSS_LOCK(engine.plr); |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
440 JSSPlayerChannel *chn = &(engine.plr->channels[channel]); |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
441 *ninst = chn->ninstrument; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
442 *nextInst = chn->nextInstrument; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
443 *freq = chn->freq; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
444 *note = chn->note; |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
445 JSS_UNLOCK(engine.plr); |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
446 } |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
447 #endif |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
448 |
2e04f6827a52
Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents:
127
diff
changeset
|
449 |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
450 BOOL engineInitializeVideo() |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
451 { |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
452 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
453 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
454 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
455 SDL_FreeSurface(engine.screen); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
456 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
457 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
458 if (engine.screen == NULL) |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
459 { |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
460 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
461 return FALSE; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
462 } |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
463 return TRUE; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
464 } |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
465 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
466 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 int main(int argc, char *argv[]) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 int err; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 BOOL initSDL = FALSE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 memset(&frame, 0, sizeof(frame)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 memset(&engine, 0, sizeof(engine)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 // Pre-initialization |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
476 if ((err = demoPreInit()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
479 if (!dmArgsProcess(argc, argv, optList, optListN, |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
480 argHandleOpt, NULL, FALSE)) |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
481 return DMERR_INIT_FAIL; |
123
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
482 |
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
483 dmPrint(0, |
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
484 "%s\n" |
312 | 485 "%s\n" |
486 "TNSP simple demoengine initializing.\n", | |
123
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
487 dmProgDesc, dmProgAuthor); |
125
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
488 |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
489 dmPrint(0, |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
490 "Using libSDL, " |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
491 #ifdef DM_USE_TREMOR |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
492 "Tremor Vorbis codec" |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
493 #endif |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
494 #ifdef DM_USE_PACKFS |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
495 ", zlib and modified stb_image.\n" |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
496 #else |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
497 " and modified stb_image.\n" |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
498 #endif |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
499 "See README.txt for more information.\n"); |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
500 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 // Initialize resource subsystem |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 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
|
503 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
|
504 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
505 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
|
506 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 } |
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 // Initialize SDL components |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
510 dmPrint(1, "Initializing libSDL.\n"); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
511 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
|
512 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 dmError("Could not initialize SDL: %s\n", SDL_GetError()); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
515 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 initSDL = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
517 |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
518 // Initialize audio parts |
126
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
519 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0) |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
520 { |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
521 // Defaults, if none seem to be set |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
522 engine.optAfmt.freq = 44100; |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
523 engine.optAfmt.format = AUDIO_S16SYS; |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
524 engine.optAfmt.channels = 2; |
316 | 525 engine.optAfmt.samples = engine.optAfmt.freq / 16; |
126
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
526 } |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
527 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
528 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 jssInit(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
531 switch (engine.optAfmt.format) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
532 { |
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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
539 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
|
540 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
|
541 |
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
|
542 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
|
543 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 dmError("jvmInit() returned NULL, voi perkele.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
548 if ((engine.plr = jmpInit(engine.dev)) == NULL) |
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 dmError("jmpInit() returned NULL\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
551 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
552 } |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
553 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
555 // Initialize SDL audio |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
556 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
|
557 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
|
558 |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
559 #if defined(DM_DEVEL) && defined(DM_USE_JSS) |
335
2d19b5b8350c
Fix remains of the debug/devel changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
560 if (engine.optDevel) |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
561 engine.optAfmt.callback = engineAudioCallbackDebug; |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
562 else |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
563 #endif |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
564 engine.optAfmt.callback = engineAudioCallback; |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
565 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
566 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
567 { |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
568 dmError("Couldn't open SDL audio: %s\n", SDL_GetError()); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
569 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
570 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
571 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
572 // Initialize SDL video |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
573 if (engine.demoInitPreVideo != NULL && |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
574 (err = engine.demoInitPreVideo()) != DMERR_OK) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
575 { |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
576 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err)); |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
577 goto error_exit; |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
578 } |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
579 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
580 |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
581 if (!engineInitializeVideo()) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
582 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
583 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
584 SDL_ShowCursor(SDL_DISABLE); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
585 SDL_WM_SetCaption(dmProgDesc, dmProgName); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
586 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
587 if (engine.demoInitPostVideo != NULL && |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
588 (err = engine.demoInitPostVideo()) != DMERR_OK) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
589 { |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
590 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err)); |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
591 goto error_exit; |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
592 } |
32
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 // Load resources |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
595 dmPrint(1, "Loading resources, please wait...\n"); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
596 if ((err = engineLoadResources()) != DMERR_OK) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
597 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
598 dmError("Error loading resources, %d: %s.\n", |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
599 err, dmErrorStr(err)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
600 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
601 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
602 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
603 // Final initializations |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
604 if ((err = engine.demoInit()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
605 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
606 |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
607 #if defined(DM_DEVEL) && defined(DM_USE_JSS) |
335
2d19b5b8350c
Fix remains of the debug/devel changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
608 if (engine.optDevel) |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
609 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
610 Uint8 *ptr; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
611 int left = engine.dev->outFreq * engine.demoDuration; |
335
2d19b5b8350c
Fix remains of the debug/devel changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
612 dmPrint(1, "Development mode enabled, pre-rendering audio."); |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
613 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
|
614 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
|
615 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
616 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
|
617 engine.audioBufSize); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
618 goto error_exit; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
619 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
620 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
621 ptr = engine.audioBuf; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
622 while (left > 0) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
623 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
624 int length = left; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
625 if (length > 16*1024) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
626 length = 16*1024; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
627 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
628 jvmRenderAudio(engine.dev, ptr, length); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
629 ptr += jvmGetSampleSize(engine.dev) * length; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
630 left -= length; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
631 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
632 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
633 #endif |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
634 |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
635 dmPrint(1, "Starting up.\n"); |
278 | 636 |
637 SDL_LockAudio(); | |
41
780300a8d322
Move SDL_PauseAudio(0) to the "engine" instead of the demo code.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
638 SDL_PauseAudio(0); |
278 | 639 SDL_UnlockAudio(); |
640 | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
641 engine.startTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
642 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
643 while (!engine.exitFlag) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
644 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
645 while (SDL_PollEvent(&engine.event)) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
646 switch (engine.event.type) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
647 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
648 case SDL_KEYDOWN: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
649 switch (engine.event.key.keysym.sym) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
650 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
651 case SDLK_ESCAPE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
652 engine.exitFlag = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
653 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
654 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
655 case SDLK_SPACE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
656 engine.pauseFlag = !engine.pauseFlag; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
657 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
658 |
333
230cc7c6564d
Rename DM_DEBUG compile time define to DM_DEVEL, for development mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
332
diff
changeset
|
659 #ifdef DM_DEVEL |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 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
|
664 #endif |
336
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
665 case SDLK_f: |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
666 engine.optVFlags ^= SDL_FULLSCREEN; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
667 if (!engineInitializeVideo()) |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
668 goto error_exit; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
669 break; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
670 |
109
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
671 case SDLK_RETURN: |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
672 if (engine.event.key.keysym.mod & KMOD_ALT) |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
673 { |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
674 engine.optVFlags ^= SDL_FULLSCREEN; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
675 if (!engineInitializeVideo()) |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
676 goto error_exit; |
109
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
677 } |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
678 break; |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
679 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 default: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
681 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
683 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
684 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
685 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
686 case SDL_VIDEOEXPOSE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
687 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
688 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
689 case SDL_QUIT: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
690 engine.exitFlag = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
691 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
692 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
693 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 // Draw frame |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 frame.startTime = SDL_GetTicks(); |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
696 if (engine.pauseFlag != engine.paused) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
697 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
698 engine.paused = engine.pauseFlag; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
699 engine.pauseTime = engineGetTick(); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
700 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
701 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
702 if (engine.paused) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
703 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
704 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
|
705 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
706 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 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
|
708 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
709 dmError("Can't lock surface.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
710 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
712 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
713 // Call main tick |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
714 if ((err = engine.demoRender()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
715 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
716 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 // Flip screen |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 if (SDL_MUSTLOCK(engine.screen) != 0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
719 SDL_UnlockSurface(engine.screen); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
721 SDL_Flip(engine.screen); |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
722 SDL_Delay(engine.paused ? 100 : 20); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
723 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 // Get frame time, etc |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
725 frame.endTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 engine.currFrame++; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
727 engine.totalFrameTime += frame.endTime - frame.startTime; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
729 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
730 // Print benchmark results |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
731 engine.endTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 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
|
733 engine.currFrame, engine.endTime - engine.startTime, |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 error_exit: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
739 dmPrint(1, "Shutting down.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
740 SDL_ShowCursor(SDL_ENABLE); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
742 if (engine.screen) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
743 SDL_FreeSurface(engine.screen); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
744 |
278 | 745 SDL_LockAudio(); |
746 SDL_PauseAudio(1); | |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
747 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
748 jmpClose(engine.plr); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 jvmClose(engine.dev); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
750 jssClose(); |
278 | 751 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
752 SDL_UnlockAudio(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
753 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 dmres_close(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
755 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
756 if (engine.demoShutdown != NULL) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
757 engine.demoShutdown(); |
94
4bbfc0274b29
Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
758 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
759 if (initSDL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
760 SDL_Quit(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
761 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
762 if (engine.demoQuit != NULL) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
763 engine.demoQuit(); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
764 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
765 return 0; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
766 } |