annotate dmsimple.c @ 310:713c8018c3ce

Fix includes in the dmsimple engine.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Oct 2012 11:38:40 +0300
parents 919e7de91758
children 99dc5d012081
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 },
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
21 #ifdef DM_DEBUG
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
22 { 3, 'd', "debug", "Debug mode", OPT_NONE },
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
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
56 #ifdef DM_DEBUG
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
57 case 3:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
58 engine.optDebug = TRUE;
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
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
71 int engineShowProgress(int loaded, int total)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
72 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
73 int dx = 60,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
74 dh = 20,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
75 dw = engine.screen->w - (2 * dx),
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
76 dy = (engine.screen->h - dh) / 2;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
77
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
78 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
79 return DMERR_INIT_FAIL;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
80
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
81 // Draw the progress bar
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
82 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
83 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
84 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
85
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
86 if (total > 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
87 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
88 dmFillRect(engine.screen,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
89 dx+3, dy+3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
90 dx + 3 + ((dw - 3) * loaded) / total,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
91 dy + dh - 3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
92 dmMapRGB(engine.screen, 200,200,200));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
93 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
94
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
95 // Flip screen
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
96 if (SDL_MUSTLOCK(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
97 SDL_UnlockSurface(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
98
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
99 SDL_Flip(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
100 return DMERR_OK;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
101 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
102
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
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
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
115 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
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
f47011b06d5c Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
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, &current_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
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
351 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
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 {
111
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
377 #ifdef DM_DEBUG
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
378 if (engine.optDebug)
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
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
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
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
396 (void) userdata;
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
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
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 int main(int argc, char *argv[])
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 int err;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 BOOL initSDL = FALSE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 memset(&frame, 0, sizeof(frame));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 memset(&engine, 0, sizeof(engine));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 // Pre-initialization
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
459 if ((err = demoPreInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461
121
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
462 if (!dmArgsProcess(argc, argv, optList, optListN,
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
463 argHandleOpt, NULL, FALSE))
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
464 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
465
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
466 dmPrint(0,
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
467 "%s\n"
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
468 "TNSP simple demoengine initializing.\n"
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
469 "%s\n",
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
470 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
471
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
472 dmPrint(0,
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
473 "Using libSDL, "
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
474 #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
475 "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
476 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
477 #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
478 ", 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
479 #else
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
480 " 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
481 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
482 "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
483
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 // Initialize resource subsystem
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 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
486 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
487 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 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
489 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 // Initialize SDL components
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
493 dmPrint(1, "Initializing libSDL.\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 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
495 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 dmError("Could not initialize SDL: %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 initSDL = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
501 // Initialize audio parts
126
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
502 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0)
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
503 {
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
504 // Defaults, if none seem to be set
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
505 engine.optAfmt.freq = 44100;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
506 engine.optAfmt.format = AUDIO_S16SYS;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
507 engine.optAfmt.channels = 2;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
508 engine.optAfmt.samples = 16*1024;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
509 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
510
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
511 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 jssInit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
514 switch (engine.optAfmt.format)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
515 {
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
516 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
517 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
518 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
519 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
520 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
522 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
523 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
524
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
525 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
526 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 dmError("jvmInit() returned NULL, voi perkele.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 if ((engine.plr = jmpInit(engine.dev)) == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 dmError("jmpInit() returned NULL\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
536 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 // Initialize SDL audio
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
539 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
540 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
541
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
542 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
543 if (engine.optDebug)
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
544 engine.optAfmt.callback = engineAudioCallbackDebug;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
545 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
546 #endif
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
547 engine.optAfmt.callback = engineAudioCallback;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
549 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 {
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
551 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
552 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 }
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 video
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
556 if (engine.demoInitPreVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
557 (err = engine.demoInitPreVideo()) != DMERR_OK)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
558 {
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
559 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
560 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
561 }
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
562
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 if (engine.screen == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 goto error_exit;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 SDL_ShowCursor(SDL_DISABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 SDL_WM_SetCaption(dmProgDesc, dmProgName);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
576 if (engine.demoInitPostVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
577 (err = engine.demoInitPostVideo()) != DMERR_OK)
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 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
580 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
581 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 // Load resources
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
584 dmPrint(1, "Loading resources, please wait...\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 if ((err = engineLoadResources()) != DMERR_OK)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 dmError("Error loading resources, %d: %s.\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 err, dmErrorStr(err));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 // Final initializations
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
593 if ((err = engine.demoInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
596 #if defined(DM_DEBUG) && defined(DM_USE_JSS)
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
597 if (engine.optDebug)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
598 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
599 Uint8 *ptr;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
600 int left = engine.dev->outFreq * engine.demoDuration;
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
601 dmPrint(1, "DEBUG 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
602 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
603 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
604 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
605 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
606 engine.audioBufSize);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
607 goto error_exit;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
608 }
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 ptr = engine.audioBuf;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
611 while (left > 0)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
612 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
613 int length = left;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
614 if (length > 16*1024)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
615 length = 16*1024;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
616
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
617 jvmRenderAudio(engine.dev, ptr, length);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
618 ptr += jvmGetSampleSize(engine.dev) * length;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
619 left -= length;
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 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
622 #endif
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
623
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
624 dmPrint(1, "Starting up.\n");
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
625
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
626 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
627 SDL_PauseAudio(0);
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
628 SDL_UnlockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
629
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 engine.startTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 while (!engine.exitFlag)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 while (SDL_PollEvent(&engine.event))
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 switch (engine.event.type)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 case SDL_KEYDOWN:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 switch (engine.event.key.keysym.sym)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 case SDLK_ESCAPE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 case SDLK_SPACE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 engine.pauseFlag = !engine.pauseFlag;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
648 #ifdef DM_DEBUG
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
649 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
650 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
651 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
652 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
653 #endif
109
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
654 case SDLK_RETURN:
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
655 if (engine.event.key.keysym.mod & KMOD_ALT)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
656 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
657 engine.optVFlags ^= SDL_FULLSCREEN;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
658 SDL_FreeSurface(engine.screen);
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
659 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
660 if (engine.screen == NULL)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
661 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
662 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
663 goto error_exit;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
664 }
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
665 }
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
666 break;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
667
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 default:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 case SDL_VIDEOEXPOSE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 case SDL_QUIT:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 // Draw frame
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 frame.startTime = SDL_GetTicks();
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
684 if (engine.pauseFlag != engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
685 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
686 engine.paused = engine.pauseFlag;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
687 engine.pauseTime = engineGetTick();
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
688 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
689
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
690 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
691 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
692 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
693 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 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
696 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 dmError("Can't lock surface.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 // Call main tick
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
702 if ((err = engine.demoRender()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 // Flip screen
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 if (SDL_MUSTLOCK(engine.screen) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 SDL_UnlockSurface(engine.screen);
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 SDL_Flip(engine.screen);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
710 SDL_Delay(engine.paused ? 100 : 20);
32
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 // Get frame time, etc
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 frame.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 engine.currFrame++;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 engine.totalFrameTime += frame.endTime - frame.startTime;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 // Print benchmark results
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 engine.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 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
721 engine.currFrame, engine.endTime - engine.startTime,
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime);
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 error_exit:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 dmPrint(1, "Shutting down.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 SDL_ShowCursor(SDL_ENABLE);
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 if (engine.screen)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 SDL_FreeSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
733 SDL_LockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
734 SDL_PauseAudio(1);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
735 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 jmpClose(engine.plr);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 jvmClose(engine.dev);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 jssClose();
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
739 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 SDL_UnlockAudio();
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 dmres_close();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
744 if (engine.demoShutdown != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
745 engine.demoShutdown();
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
746
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 if (initSDL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 SDL_Quit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
750 if (engine.demoQuit != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
751 engine.demoQuit();
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 return 0;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 }