Mercurial > hg > dmlib
annotate dmsimple.c @ 342:c6ec970dc3cf
Separate some demo engine parts to two different modules.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 15 Oct 2012 21:25:51 +0300 |
parents | 13dba73cf28e |
children | cac13f180169 |
rev | line source |
---|---|
310
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
1 #include <SDL.h> |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
2 #include "dmengine.h" |
310
713c8018c3ce
Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
3 #include "dmargs.h" |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
5 static DMOptArg optList[] = |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
6 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
7 { 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
|
8 { 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
|
9 { 2, 'f', "fs", "Fullscreen", OPT_NONE }, |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
10 }; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
11 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
12 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
|
13 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
14 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
15 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
16 static void argShowHelp() |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
17 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
18 dmPrintBanner(stdout, dmProgName, "[options]"); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
19 dmArgsPrintHelp(stdout, optList, optListN); |
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 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
23 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
|
24 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
25 (void) optArg; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
26 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
27 switch (optN) |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
28 { |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
29 case 0: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
30 argShowHelp(); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
31 exit(0); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
32 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
33 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
34 case 1: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
35 dmVerbosity++; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
36 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
37 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
38 case 2: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
39 engine.optVFlags |= SDL_FULLSCREEN; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
40 break; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
41 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
42 default: |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
43 dmError("Unknown option '%s'.\n", currArg); |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
44 return FALSE; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
45 } |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
46 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
47 return TRUE; |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
48 } |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
49 |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
50 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
51 static void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
52 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
53 (void) userdata; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
54 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
55 if (engine.paused) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
56 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
57 memset(stream, 0, len); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
58 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
59 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
60 #ifdef DM_USE_JSS |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
61 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
62 if (engine.dev != NULL) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
63 jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev)); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
64 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
65 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
66 #ifdef DM_USE_TREMOR |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
67 if (engine.audioPos + len >= engine.audio->rdataSize) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
68 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
69 engine.exitFlag = TRUE; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
70 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
71 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
72 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
73 memcpy(stream, engine.audio->rdata + engine.audioPos, len); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
74 engine.audioPos += len; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
75 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
76 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
77 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
78 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
79 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
80 static int engineShowProgress(int loaded, int total) |
40 | 81 { |
82 int dx = 60, | |
83 dh = 20, | |
84 dw = engine.screen->w - (2 * dx), | |
85 dy = (engine.screen->h - dh) / 2; | |
86 | |
87 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) | |
88 return DMERR_INIT_FAIL; | |
89 | |
90 // Draw the progress bar | |
91 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0)); | |
92 dmFillRect(engine.screen, dx, dy, dx+dw, dy+dh, dmMapRGB(engine.screen, 255,255,255)); | |
93 dmFillRect(engine.screen, dx+1, dy+1, dx+dw-1, dy+dh-1, dmMapRGB(engine.screen, 0,0,0)); | |
94 | |
95 if (total > 0) | |
96 { | |
97 dmFillRect(engine.screen, | |
98 dx+3, dy+3, | |
99 dx + 3 + ((dw - 3) * loaded) / total, | |
100 dy + dh - 3, | |
101 dmMapRGB(engine.screen, 200,200,200)); | |
102 } | |
103 | |
104 // Flip screen | |
105 if (SDL_MUSTLOCK(engine.screen) != 0) | |
106 SDL_UnlockSurface(engine.screen); | |
107 | |
108 SDL_Flip(engine.screen); | |
109 return DMERR_OK; | |
110 } | |
111 | |
112 | |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
113 static int engineLoadResources() |
32
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 int err, loaded, total; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 err = dmres_preload(TRUE, &loaded, &total); |
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 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 // Show a nice progress bar while loading |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 if (total > 0 && (loaded % 2) == 0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 { |
40 | 124 if ((err = engineShowProgress(loaded, total)) != DMERR_OK) |
125 return err; | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 return err; |
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 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
133 static BOOL engineInitializeVideo() |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
134 { |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
135 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
136 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
137 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
138 SDL_FreeSurface(engine.screen); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
139 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
140 engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
141 if (engine.screen == NULL) |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
142 { |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
143 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
144 return FALSE; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
145 } |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
146 return TRUE; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
147 } |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
148 |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
149 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 int main(int argc, char *argv[]) |
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 int err; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 BOOL initSDL = FALSE; |
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 memset(&frame, 0, sizeof(frame)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 memset(&engine, 0, sizeof(engine)); |
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 // Pre-initialization |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
159 if ((err = demoPreInit()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
121
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
162 if (!dmArgsProcess(argc, argv, optList, optListN, |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
163 argHandleOpt, NULL, FALSE)) |
16fc6e6cf3b5
Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
164 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
|
165 |
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
166 dmPrint(0, |
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
167 "%s\n" |
312 | 168 "%s\n" |
169 "TNSP simple demoengine initializing.\n", | |
123
6f7356f3b91c
Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents:
122
diff
changeset
|
170 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
|
171 |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
172 dmPrint(0, |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
173 "Using libSDL, " |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
174 #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
|
175 "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
|
176 #endif |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
177 #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
|
178 ", 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
|
179 #else |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
180 " 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
|
181 #endif |
5102ec9e9bce
Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
182 "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
|
183 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 // Initialize resource subsystem |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 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
|
186 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
|
187 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 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
|
189 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 // Initialize SDL components |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
193 dmPrint(1, "Initializing libSDL.\n"); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 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
|
195 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 dmError("Could not initialize SDL: %s\n", SDL_GetError()); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 initSDL = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
201 // Initialize audio parts |
126
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
202 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0) |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
203 { |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
204 // Defaults, if none seem to be set |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
205 engine.optAfmt.freq = 44100; |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
206 engine.optAfmt.format = AUDIO_S16SYS; |
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
207 engine.optAfmt.channels = 2; |
316 | 208 engine.optAfmt.samples = engine.optAfmt.freq / 16; |
126
97488948215c
Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
209 } |
105
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 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 jssInit(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
214 switch (engine.optAfmt.format) |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
215 { |
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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
222 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
|
223 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
|
224 |
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
|
225 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
|
226 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 dmError("jvmInit() returned NULL, voi perkele.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 if ((engine.plr = jmpInit(engine.dev)) == NULL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 dmError("jmpInit() returned NULL\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 } |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
236 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 // Initialize SDL audio |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
239 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
|
240 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
|
241 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
242 engine.optAfmt.callback = engineAudioCallback; |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
244 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 { |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
246 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
|
247 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 // Initialize SDL video |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
251 if (engine.demoInitPreVideo != NULL && |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
252 (err = engine.demoInitPreVideo()) != DMERR_OK) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
253 { |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
254 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err)); |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
255 goto error_exit; |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
256 } |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
257 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
259 if (!engineInitializeVideo()) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 SDL_ShowCursor(SDL_DISABLE); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 SDL_WM_SetCaption(dmProgDesc, dmProgName); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
265 if (engine.demoInitPostVideo != NULL && |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
266 (err = engine.demoInitPostVideo()) != DMERR_OK) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
267 { |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
268 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err)); |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
269 goto error_exit; |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
270 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 // Load resources |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
273 dmPrint(1, "Loading resources, please wait...\n"); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 if ((err = engineLoadResources()) != DMERR_OK) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 dmError("Error loading resources, %d: %s.\n", |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 err, dmErrorStr(err)); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 // Final initializations |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
282 if ((err = engine.demoInit()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 |
122
5ba672ebe014
Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
285 dmPrint(1, "Starting up.\n"); |
278 | 286 |
287 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
|
288 SDL_PauseAudio(0); |
278 | 289 SDL_UnlockAudio(); |
290 | |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 engine.startTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 while (!engine.exitFlag) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 while (SDL_PollEvent(&engine.event)) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 switch (engine.event.type) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 case SDL_KEYDOWN: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 switch (engine.event.key.keysym.sym) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 case SDLK_ESCAPE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 engine.exitFlag = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 case SDLK_SPACE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 engine.pauseFlag = !engine.pauseFlag; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 |
336
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
309 case SDLK_f: |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
310 engine.optVFlags ^= SDL_FULLSCREEN; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
311 if (!engineInitializeVideo()) |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
312 goto error_exit; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
313 break; |
13dba73cf28e
Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
314 |
109
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
315 case SDLK_RETURN: |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
316 if (engine.event.key.keysym.mod & KMOD_ALT) |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
317 { |
332
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
318 engine.optVFlags ^= SDL_FULLSCREEN; |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
319 if (!engineInitializeVideo()) |
d4802335cbbc
Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
320 goto error_exit; |
109
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
321 } |
3de6301dcfe1
Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
322 break; |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
323 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 default: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 break; |
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 case SDL_VIDEOEXPOSE: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 break; |
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 case SDL_QUIT: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 engine.exitFlag = TRUE; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 break; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 // Draw frame |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 frame.startTime = SDL_GetTicks(); |
93
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
340 if (engine.pauseFlag != engine.paused) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
341 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
342 engine.paused = engine.pauseFlag; |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
343 engine.pauseTime = engineGetTick(); |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
344 } |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
345 |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
346 if (engine.paused) |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
347 { |
15fdd5573344
Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
348 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
|
349 } |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 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
|
352 { |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 dmError("Can't lock surface.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 // Call main tick |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
358 if ((err = engine.demoRender()) != DMERR_OK) |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 goto error_exit; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 // Flip screen |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 if (SDL_MUSTLOCK(engine.screen) != 0) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 SDL_UnlockSurface(engine.screen); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 SDL_Flip(engine.screen); |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
366 SDL_Delay(engine.paused ? 100 : 20); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 // Get frame time, etc |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 frame.endTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 engine.currFrame++; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 engine.totalFrameTime += frame.endTime - frame.startTime; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 } |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 // Print benchmark results |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 engine.endTime = SDL_GetTicks(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 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
|
377 engine.currFrame, engine.endTime - engine.startTime, |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 error_exit: |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 dmPrint(1, "Shutting down.\n"); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 SDL_ShowCursor(SDL_ENABLE); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 if (engine.screen) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 SDL_FreeSurface(engine.screen); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 |
278 | 389 SDL_LockAudio(); |
390 SDL_PauseAudio(1); | |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
391 #ifdef DM_USE_JSS |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 jmpClose(engine.plr); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 jvmClose(engine.dev); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 jssClose(); |
278 | 395 #endif |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 SDL_UnlockAudio(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 dmres_close(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
400 if (engine.demoShutdown != NULL) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
401 engine.demoShutdown(); |
94
4bbfc0274b29
Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
402 |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 if (initSDL) |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 SDL_Quit(); |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 |
127
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
406 if (engine.demoQuit != NULL) |
ab4086db7dad
Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
407 engine.demoQuit(); |
32
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 return 0; |
d1a6833a5d67
Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 } |