annotate dmsimple.c @ 354:ba284f5e7ea5

More work on editor, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Oct 2012 01:49:15 +0300
parents a8f00ee363e1
children 59045853853d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
310
713c8018c3ce Fix includes in the dmsimple engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 278
diff changeset
1 #include <SDL.h>
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
345
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
51 int engineGetTick()
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
52 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
53 return (frame.startTime - engine.startTime) + engine.adjustTime;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
54 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
55
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
56
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
57 float engineGetTimeDT()
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
58 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
59 return (float) engineGetTick() / 1000.0f;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
60 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
61
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
62
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
63 int engineGetTimeDTi()
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
64 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
65 return (float) engineGetTick() / 1000;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
66 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
67
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
68
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
69 int engineGetTime(int t)
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
70 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
71 return engineGetTick() - (1000 * t);
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
72 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
73
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
74
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
75 int engineGetDT(int t)
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
76 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
77 return engineGetTime(t) / 1000;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
78 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
79
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
80
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
81 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
82 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
83 (void) userdata;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
84
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
85 if (engine.paused)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
86 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
87 memset(stream, 0, len);
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
88 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
89 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
90 #ifdef DM_USE_JSS
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
91 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
92 if (engine.dev != NULL)
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
93 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
94 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
95 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
96 #ifdef DM_USE_TREMOR
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
97 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
98 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
99 engine.exitFlag = TRUE;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
100 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
101 else
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
102 {
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
103 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
104 engine.audioPos += len;
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
105 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
106 #endif
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
107 }
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
108
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
109
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
110 static int engineShowProgress(int loaded, int total)
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
111 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
112 int dx = 60,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
113 dh = 20,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
114 dw = engine.screen->w - (2 * dx),
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
115 dy = (engine.screen->h - dh) / 2;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
116
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
117 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
118 return DMERR_INIT_FAIL;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
119
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
120 // Draw the progress bar
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
121 dmClearSurface(engine.screen, dmMapRGBA(engine.screen, 0,0,0,0));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
122 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
123 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
124
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
125 if (total > 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
126 {
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
127 dmFillRect(engine.screen,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
128 dx+3, dy+3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
129 dx + 3 + ((dw - 3) * loaded) / total,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
130 dy + dh - 3,
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
131 dmMapRGB(engine.screen, 200,200,200));
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
132 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
133
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
134 // Flip screen
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
135 if (SDL_MUSTLOCK(engine.screen) != 0)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
136 SDL_UnlockSurface(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
137
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
138 SDL_Flip(engine.screen);
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
139 return DMERR_OK;
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
140 }
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
141
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
142
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
143 static int engineLoadResources()
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 int err, loaded, total;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 err = dmres_preload(TRUE, &loaded, &total);
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 while ((err = dmres_preload(FALSE, &loaded, &total)) == DMERR_PROGRESS)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 // Show a nice progress bar while loading
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 if (total > 0 && (loaded % 2) == 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 {
40
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
154 if ((err = engineShowProgress(loaded, total)) != DMERR_OK)
a239b7d4e13b Modularize progress meter.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
155 return err;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 }
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 return err;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
163 static BOOL engineInitializeVideo()
332
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
164 {
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
165 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
166 engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags);
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
167
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
168 SDL_FreeSurface(engine.screen);
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
169
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
170 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
171 if (engine.screen == NULL)
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
172 {
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
173 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
174 return FALSE;
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
175 }
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
176 return TRUE;
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
177 }
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
178
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
179
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 int main(int argc, char *argv[])
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 int err;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 BOOL initSDL = FALSE;
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 memset(&frame, 0, sizeof(frame));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 memset(&engine, 0, sizeof(engine));
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 // Pre-initialization
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
189 if ((err = demoPreInit()) != DMERR_OK)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
121
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
192 if (!dmArgsProcess(argc, argv, optList, optListN,
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
193 argHandleOpt, NULL, FALSE))
16fc6e6cf3b5 Move option handling to the simple demo engine.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
194 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
195
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
196 dmPrint(0,
6f7356f3b91c Add engine startup messages showing prod name and "TNSP simple demoengine blurb".
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
197 "%s\n"
312
99dc5d012081 Change startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 310
diff changeset
198 "%s\n"
99dc5d012081 Change startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 310
diff changeset
199 "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
200 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
201
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
202 dmPrint(0,
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
203 "Using libSDL, "
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
204 #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
205 "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
206 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
207 #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
208 ", 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
209 #else
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
210 " 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
211 #endif
5102ec9e9bce Add a blurb about used features/3rd party code (zlib, Tremor, SDL).
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
212 "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
213
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 // Initialize resource subsystem
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 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
216 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
217 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 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
219 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 // Initialize SDL components
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
223 dmPrint(1, "Initializing libSDL.\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 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
225 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 dmError("Could not initialize SDL: %s\n", SDL_GetError());
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 initSDL = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
231 // Initialize audio parts
126
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
232 if (engine.optAfmt.freq == 0 && engine.optAfmt.channels == 0)
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
233 {
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
234 // Defaults, if none seem to be set
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
235 engine.optAfmt.freq = 44100;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
236 engine.optAfmt.format = AUDIO_S16SYS;
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
237 engine.optAfmt.channels = 2;
316
a03e604f4e75 Adjust audio buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 312
diff changeset
238 engine.optAfmt.samples = engine.optAfmt.freq / 16;
126
97488948215c Allow setting audio format settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
239 }
105
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 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 jssInit();
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 switch (engine.optAfmt.format)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
245 {
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
246 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
247 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
248 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
249 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
250 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
252 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
253 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
254
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
255 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
256 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 dmError("jvmInit() returned NULL, voi perkele.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 if ((engine.plr = jmpInit(engine.dev)) == NULL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 dmError("jmpInit() returned NULL\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
266 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 // Initialize SDL audio
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
269 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
270 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
271
342
c6ec970dc3cf Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents: 336
diff changeset
272 engine.optAfmt.callback = engineAudioCallback;
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
274 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 {
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
276 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
277 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 // Initialize SDL video
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
281 if (engine.demoInitPreVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
282 (err = engine.demoInitPreVideo()) != DMERR_OK)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
283 {
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
284 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
285 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
286 }
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
287
332
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
288 if (!engineInitializeVideo())
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 SDL_ShowCursor(SDL_DISABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 SDL_WM_SetCaption(dmProgDesc, dmProgName);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
294 if (engine.demoInitPostVideo != NULL &&
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
295 (err = engine.demoInitPostVideo()) != DMERR_OK)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
296 {
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
297 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
298 goto error_exit;
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
299 }
32
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 // Load resources
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
302 dmPrint(1, "Loading resources, please wait...\n");
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 if ((err = engineLoadResources()) != DMERR_OK)
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 dmError("Error loading resources, %d: %s.\n",
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 err, dmErrorStr(err));
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 // Final initializations
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
311 if ((err = engine.demoInit()) != DMERR_OK)
354
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
312 {
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
313 dmError("Failure in demoInit(), %d: %s\n",
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
314 err, dmErrorStr(err));
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 goto error_exit;
354
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
316 }
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
317
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
318 // Initialize effects
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
319 if ((err = dmInitializeEffects()) != DMERR_OK)
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
320 {
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
321 dmError("Effects initialization failed, %d: %s\n",
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
322 err, dmErrorStr(err));
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
323 goto error_exit;
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
324 }
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
325
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
326 // Use a timeline, if set
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
327 if (engine.timeline != NULL)
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
328 {
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
329 if ((err = dmLoadTimeline(engine.timeline, &engine.tl)) != DMERR_OK)
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
330 {
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
331 dmError("Error loading timeline, %d: %s\n", err,
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
332 dmErrorStr(err));
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
333 goto error_exit;
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
334 }
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
335
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
336 if ((err = dmPrepareTimeline(engine.tl, engine.ptl)) != DMERR_OK)
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
337 {
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
338 dmError("Error creating prepared timeline, %d: %s\n",
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
339 err, dmErrorStr(err));
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
340 goto error_exit;
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
341 }
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
342 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343
122
5ba672ebe014 Add some verbose engine startup messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
344 dmPrint(1, "Starting up.\n");
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
345
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
346 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
347 SDL_PauseAudio(0);
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
348 SDL_UnlockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
349
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 engine.startTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 while (!engine.exitFlag)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 while (SDL_PollEvent(&engine.event))
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 switch (engine.event.type)
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 case SDL_KEYDOWN:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 switch (engine.event.key.keysym.sym)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 case SDLK_ESCAPE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 case SDLK_SPACE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 engine.pauseFlag = !engine.pauseFlag;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
336
13dba73cf28e Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
368 case SDLK_f:
13dba73cf28e Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
369 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
370 if (!engineInitializeVideo())
13dba73cf28e Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
371 goto error_exit;
13dba73cf28e Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
372 break;
13dba73cf28e Add 'F' key to fullscreen toggling, in addition to alt+enter.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
373
109
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
374 case SDLK_RETURN:
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
375 if (engine.event.key.keysym.mod & KMOD_ALT)
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
376 {
332
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
377 engine.optVFlags ^= SDL_FULLSCREEN;
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
378 if (!engineInitializeVideo())
d4802335cbbc Clean up video (re)initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 316
diff changeset
379 goto error_exit;
109
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
380 }
3de6301dcfe1 Implement fullscrene toggling via alt+enter
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
381 break;
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
382
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 default:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 break;
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
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 case SDL_VIDEOEXPOSE:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 case SDL_QUIT:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 engine.exitFlag = TRUE;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 break;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 // Draw frame
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 frame.startTime = SDL_GetTicks();
93
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
399 if (engine.pauseFlag != engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
400 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
401 engine.paused = engine.pauseFlag;
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
402 engine.pauseTime = engineGetTick();
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
403 }
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
404
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
405 if (engine.paused)
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
406 {
15fdd5573344 Add simple (and buggy / not really working) debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
407 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
408 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 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
411 {
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 dmError("Can't lock surface.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 goto error_exit;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 // Call main tick
345
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
417 if (engine.demoRender != NULL)
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
418 {
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
419 if ((err = engine.demoRender()) != DMERR_OK)
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
420 goto error_exit;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
421 }
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
422 else
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
423 {
351
a8f00ee363e1 Should've used engineGetTick() instead of engineGetTime(). Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 345
diff changeset
424 if ((err = dmExecuteTimeline(engine.ptl, engine.screen, engineGetTick())) != DMERR_OK)
345
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
425 goto error_exit;
cac13f180169 Work towards timeline support.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
426 }
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 // Flip screen
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 if (SDL_MUSTLOCK(engine.screen) != 0)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 SDL_UnlockSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 SDL_Flip(engine.screen);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
433 SDL_Delay(engine.paused ? 100 : 20);
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 // Get frame time, etc
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 frame.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 engine.currFrame++;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 engine.totalFrameTime += frame.endTime - frame.startTime;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 }
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 // Print benchmark results
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 engine.endTime = SDL_GetTicks();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 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
444 engine.currFrame, engine.endTime - engine.startTime,
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 (float) (engine.currFrame * 1000.0f) / (float) engine.totalFrameTime);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
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 error_exit:
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 dmPrint(1, "Shutting down.\n");
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 SDL_ShowCursor(SDL_ENABLE);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 if (engine.screen)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 SDL_FreeSurface(engine.screen);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
456 SDL_LockAudio();
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
457 SDL_PauseAudio(1);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
458 #ifdef DM_USE_JSS
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 jmpClose(engine.plr);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 jvmClose(engine.dev);
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 jssClose();
278
919e7de91758 Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 277
diff changeset
462 #endif
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 SDL_UnlockAudio();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464
354
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
465 dmFreeTimeline(engine.tl);
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
466 dmFreePreparedTimelineData(engine.ptl);
ba284f5e7ea5 More work on editor, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 351
diff changeset
467 dmShutdownEffects();
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 dmres_close();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
470 if (engine.demoShutdown != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
471 engine.demoShutdown();
94
4bbfc0274b29 Change some function names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
472
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 if (initSDL)
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 SDL_Quit();
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475
127
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
476 if (engine.demoQuit != NULL)
ab4086db7dad Various improvements in modularity.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
477 engine.demoQuit();
32
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 return 0;
d1a6833a5d67 Added a simple demo engine core.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 }