annotate dmsimple.c @ 300:4972ca91d062

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 Oct 2012 17:55:15 +0300
parents 919e7de91758
children 713c8018c3ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmsimple.h"
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
2 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
3 #include <tremor/ivorbiscodec.h>
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
4 #include <tremor/ivorbisfile.h>
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
5 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 DMEngineData engine;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 DMFrameData frame;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
121
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
12 static DMOptArg optList[] =
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
13 {
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
14 { 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
15 { 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
16 { 2, 'f', "fs", "Fullscreen", OPT_NONE },
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
17 #ifdef DM_DEBUG
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
18 { 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
19 #endif
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
20 };
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
21
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
22 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
23
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 static void argShowHelp()
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 dmPrintBanner(stdout, dmProgName, "[options]");
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
29 dmArgsPrintHelp(stdout, optList, optListN);
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
30 }
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
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
33 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
34 {
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
35 (void) optArg;
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 switch (optN)
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 case 0:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
40 argShowHelp();
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
41 exit(0);
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
42 break;
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
43
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
44 case 1:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
45 dmVerbosity++;
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 2:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
49 engine.optVFlags |= SDL_FULLSCREEN;
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 #ifdef DM_DEBUG
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
53 case 3:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
54 engine.optDebug = TRUE;
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
55 break;
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
56 #endif
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
57
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
58 default:
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
59 dmError("Unknown option '%s'.\n", currArg);
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
60 return FALSE;
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
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
63 return TRUE;
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
64 }
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
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
67 int engineShowProgress(int loaded, int total)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
68 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
69 int dx = 60,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
70 dh = 20,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
71 dw = engine.screen->w - (2 * dx),
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
72 dy = (engine.screen->h - dh) / 2;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
73
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
74 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
75 return DMERR_INIT_FAIL;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
76
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
77 // Draw the progress bar
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
78 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
79 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
80 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
81
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
82 if (total > 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
83 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
84 dmFillRect(engine.screen,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
85 dx+3, dy+3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
86 dx + 3 + ((dw - 3) * loaded) / total,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
87 dy + dh - 3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
88 dmMapRGB(engine.screen, 200,200,200));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
89 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
90
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
91 // Flip screen
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
92 if (SDL_MUSTLOCK(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
93 SDL_UnlockSurface(engine.screen);
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 SDL_Flip(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
96 return DMERR_OK;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
97 }
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
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 int engineLoadResources()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 int err, loaded, total;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 err = dmres_preload(TRUE, &loaded, &total);
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 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS)
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 // Show a nice progress bar while loading
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 if (total > 0 && (loaded % 2) == 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
111 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
112 return err;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 return err;
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 int engineGetTick()
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 {
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
122 return (frame.startTime - engine.startTime) + engine.adjustTime;
32
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 float engineGetTimeDT()
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 return (float) engineGetTick() / 1000.0f;
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
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 int engineGetTimeDTi()
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 return (float) engineGetTick() / 1000;
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
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 int engineGetTime(int t)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
42
f47011b06d5c Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
140 return engineGetTick() - (1000 * t);
32
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 int engineGetDT(int t)
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 return engineGetTime(t) / 1000;
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
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 static int engineResImageLoad(DMResource *res)
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 SDL_Surface *img = dmLoadImage(res);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 if (res != NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 res->rdata = img;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 return DMERR_OK;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 else
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 return dmferror(res);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
162
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 static void engineResImageFree(DMResource *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 SDL_FreeSurface((SDL_Surface *)res->rdata);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
168 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
169 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
170 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
171 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
172 }
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
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
175 #ifdef JSS_SUP_XM
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 static int engineResModuleLoad(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 return jssLoadXM(res, (JSSModule **) &(res->rdata));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 static void engineResModuleFree(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 jssFreeModule((JSSModule *) res->rdata);
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
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
186 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
187 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
188 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
189 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
190 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
191 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
193
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
194 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
195 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
196 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
197 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
198 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
199
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
200 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
201 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
202 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
203 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
204
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
205 static int vorbisFileClose(void *datasource)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
206 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
207 (void) datasource;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
208 return 0;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
209 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
210
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
211 static long vorbisFileTell(void *datasource)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
212 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
213 return dmftell((DMResource *) datasource);
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
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 static ov_callbacks vorbisFileCBS =
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 vorbisFileRead,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
220 vorbisFileSeek,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
221 vorbisFileClose,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
222 vorbisFileTell
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 };
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
225 static int engineResVorbisLoad(DMResource *res)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
227 OggVorbis_File vf;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
228
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
229 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
230 res->filename, res->dataSize);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
231
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
232 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
233 return DMERR_FOPEN;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
234
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
235 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
236 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
237 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
238 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
239 return DMERR_MALLOC;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
240 }
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 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
243
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
244 BOOL eof = FALSE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
245 int left = res->rdataSize;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
246 char *ptr = res->rdata;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
247 int current_section;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
248 while (!eof && left > 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
249 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
250 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
251 if (ret == 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
252 eof = TRUE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
253 else
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
254 if (ret < 0)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
255 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
256 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
257 return DMERR_INVALID_DATA;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
258 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
259 else
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
260 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
261 left -= ret;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
262 ptr += ret;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
263 }
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
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
266 ov_clear(&vf);
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
267 return DMERR_OK;
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 static void engineResVorbisFree(DMResource *res)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
271 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
272 dmFree(res->rdata);
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
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
275 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
276 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
277 (void) res;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
278 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
279 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
280 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
281
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
282
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
283 static DMResourceDataOps engineResOps[] =
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
284 {
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 engineResImageProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
287 engineResImageLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
288 engineResImageFree
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
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
291 #ifdef JSS_SUP_XM
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
292 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
293 engineResModuleProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
294 engineResModuleLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
295 engineResModuleFree
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 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
298
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
299 #ifdef DM_USE_TREMOR
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 engineResVorbisProbe,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
302 engineResVorbisLoad,
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
303 engineResVorbisFree
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 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 };
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
308 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
309
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
310
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 static int engineClassifier(DMResource *res)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
313 int i;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 char *fext;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 if (res == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 return DMERR_NULLPTR;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
319 fext = strrchr(res->filename, '.');
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
320 for (i = 0; i < nengineResOps; i++)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
322 DMResourceDataOps *rops = &engineResOps[i];
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
323 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
324 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
325 res->rops = rops;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
326 return DMERR_OK;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
327 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 return DMERR_OK;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 }
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 void *engineGetResource(const char *name)
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 DMResource *res = dmres_find(name);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 if (res != NULL && res->rdata != NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 return res->rdata;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 else
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 dmError("Could not find resource '%s'.\n", name);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 return NULL;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 }
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
347 #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
348 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
349 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
350 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
351 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
352 memset(stream, 0, len);
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 else
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 JSSMixer *d = (JSSMixer *) userdata;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
357 if (d != NULL)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
358 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
359 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
360 engine.audioSamples;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
361
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
362 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
363
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
364 engine.audioSamples += len;
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 }
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
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
369 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
370
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
371 void engineAdjustTime(int adj)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
372 {
111
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
373 #ifdef DM_DEBUG
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
374 if (engine.optDebug)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
375 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
376 int tmp = engine.adjustTime + adj;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
377 if (tmp < 0)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
378 tmp = 0;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
379 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
380 if (tmp >= engine.demoDuration * 1000)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
381 tmp = engine.demoDuration * 1000;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
382
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
383 engine.pauseFlag = TRUE;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
384 engine.adjustTime = tmp;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
385 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
386 }
111
22ba0490733b Oops, another 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
387 #endif
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
388 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
389
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 static void engineAudioCallback(void *userdata, Uint8 *stream, int len)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 {
113
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
392 (void) userdata;
34ccf783ecca Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
393
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
394 if (engine.paused)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 {
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
396 memset(stream, 0, len);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
397 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
398 else
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
399 #ifdef DM_USE_JSS
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
400 {
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
401 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
402 jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev));
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
404 #endif
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
405 #ifdef DM_USE_TREMOR
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
406 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
407 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
408 engine.exitFlag = TRUE;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
409 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
410 else
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 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
413 engine.audioPos += len;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
414 }
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
415 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
277
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
419 #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
420 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
421 {
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
422 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
423
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
424 *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
425 *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
426 *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
427 *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
428 *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
429
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
430 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
431 }
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
432
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
433 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
434 {
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
435 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
436 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
437 *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
438 *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
439 *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
440 *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
441 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
442 }
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
443 #endif
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
444
2e04f6827a52 Add two new functions to the simple demoengine for getting some information
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
445
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 int main(int argc, char *argv[])
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 int err;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 BOOL initSDL = FALSE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 memset(&frame, 0, sizeof(frame));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 memset(&engine, 0, sizeof(engine));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 // Pre-initialization
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
455 if ((err = demoPreInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
121
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
458 if (!dmArgsProcess(argc, argv, optList, optListN,
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
459 argHandleOpt, NULL, FALSE))
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
460 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
461
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
462 dmPrint(0,
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
463 "%s\n"
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
464 "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
465 "%s\n",
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
466 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
467
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
468 dmPrint(0,
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
469 "Using libSDL, "
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
470 #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
471 "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
472 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
473 #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
474 ", 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
475 #else
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
476 " 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
477 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
478 "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
479
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 // Initialize resource subsystem
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 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
482 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
483 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 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
485 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 }
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 // Initialize SDL components
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
489 dmPrint(1, "Initializing libSDL.\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 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
491 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 dmError("Could not initialize SDL: %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 initSDL = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
497 // Initialize audio parts
126
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
498 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0)
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
499 {
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
500 // Defaults, if none seem to be set
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
501 engine.optAfmt.freq = 44100;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
502 engine.optAfmt.format = AUDIO_S16SYS;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
503 engine.optAfmt.channels = 2;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
504 engine.optAfmt.samples = 16*1024;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
505 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
506
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
507 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 jssInit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
510 switch (engine.optAfmt.format)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
511 {
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
512 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
513 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
514 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
515 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
516 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
518 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
519 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
520
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
521 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
522 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 dmError("jvmInit() returned NULL, voi perkele.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 }
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 if ((engine.plr = jmpInit(engine.dev)) == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 dmError("jmpInit() returned NULL\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
532 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 // Initialize SDL audio
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
535 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
536 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
537
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
538 #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
539 if (engine.optDebug)
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
540 engine.optAfmt.callback = engineAudioCallbackDebug;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
541 else
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
542 #endif
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
543 engine.optAfmt.callback = engineAudioCallback;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
545 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 {
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
547 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
548 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 // Initialize SDL video
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
552 if (engine.demoInitPreVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
553 (err = engine.demoInitPreVideo()) != DMERR_OK)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
554 {
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
555 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
556 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
557 }
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
558
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 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
560 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 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
563 if (engine.screen == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 }
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 SDL_ShowCursor(SDL_DISABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 SDL_WM_SetCaption(dmProgDesc, dmProgName);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
572 if (engine.demoInitPostVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
573 (err = engine.demoInitPostVideo()) != DMERR_OK)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
574 {
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
575 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
576 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
577 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 // Load resources
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
580 dmPrint(1, "Loading resources, please wait...\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 if ((err = engineLoadResources()) != DMERR_OK)
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 dmError("Error loading resources, %d: %s.\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 err, dmErrorStr(err));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 goto error_exit;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 // Final initializations
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
589 if ((err = engine.demoInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
592 #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
593 if (engine.optDebug)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
594 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
595 Uint8 *ptr;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
596 int left = engine.dev->outFreq * engine.demoDuration;
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
597 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
598 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
599 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
600 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
601 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
602 engine.audioBufSize);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
603 goto error_exit;
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
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
606 ptr = engine.audioBuf;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
607 while (left > 0)
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 int length = left;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
610 if (length > 16*1024)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
611 length = 16*1024;
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 jvmRenderAudio(engine.dev, ptr, length);
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
614 ptr += jvmGetSampleSize(engine.dev) * length;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
615 left -= length;
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 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
618 #endif
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
619
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
620 dmPrint(1, "Starting up.\n");
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
621
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
622 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
623 SDL_PauseAudio(0);
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
624 SDL_UnlockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
625
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 engine.startTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 while (!engine.exitFlag)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 while (SDL_PollEvent(&engine.event))
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 switch (engine.event.type)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 case SDL_KEYDOWN:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 switch (engine.event.key.keysym.sym)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 case SDLK_ESCAPE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 break;
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_SPACE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 engine.pauseFlag = !engine.pauseFlag;
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
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
644 #ifdef DM_DEBUG
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
645 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
646 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
647 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
648 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
649 #endif
109
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
650 case SDLK_RETURN:
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
651 if (engine.event.key.keysym.mod & KMOD_ALT)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
652 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
653 engine.optVFlags ^= SDL_FULLSCREEN;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
654 SDL_FreeSurface(engine.screen);
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
655 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
656 if (engine.screen == NULL)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
657 {
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
658 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
659 goto error_exit;
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
660 }
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 break;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
663
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 default:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 case SDL_VIDEOEXPOSE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 case SDL_QUIT:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 engine.exitFlag = TRUE;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 // Draw frame
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 frame.startTime = SDL_GetTicks();
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
680 if (engine.pauseFlag != engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
681 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
682 engine.paused = engine.pauseFlag;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
683 engine.pauseTime = engineGetTick();
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
684 }
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 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
687 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
688 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
689 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 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
692 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 dmError("Can't lock surface.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 }
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 // Call main tick
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
698 if ((err = engine.demoRender()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 goto error_exit;
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 // Flip screen
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 if (SDL_MUSTLOCK(engine.screen) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 SDL_UnlockSurface(engine.screen);
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 SDL_Flip(engine.screen);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
706 SDL_Delay(engine.paused ? 100 : 20);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 // Get frame time, etc
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 frame.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 engine.currFrame++;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 engine.totalFrameTime += frame.endTime - frame.startTime;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 // Print benchmark results
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 engine.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 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
717 engine.currFrame, engine.endTime - engine.startTime,
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 error_exit:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 dmPrint(1, "Shutting down.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 SDL_ShowCursor(SDL_ENABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 if (engine.screen)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 SDL_FreeSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
729 SDL_LockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
730 SDL_PauseAudio(1);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
731 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 jmpClose(engine.plr);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 jvmClose(engine.dev);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 jssClose();
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
735 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 SDL_UnlockAudio();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 dmres_close();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
740 if (engine.demoShutdown != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
741 engine.demoShutdown();
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
742
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 if (initSDL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 SDL_Quit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
746 if (engine.demoQuit != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
747 engine.demoQuit();
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 return 0;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 }