1 /* 2000-08-10T18:03:54Z
3 * open X11 display and sound
35 char play[SAMPLE_MAX];
37 #if defined(AUDIO_UNIX_NATIVE)
38 static int sound_pid = -1;
39 int sound_pipe[2] = { -1, -1 }; /* for communication */
40 short *sound_data[SAMPLE_MAX]; /* pointer to sound data */
41 long sound_length[SAMPLE_MAX]; /* length of sound data */
43 static const char *sound_names[SAMPLE_MAX] =
77 static const int sound_volume[SAMPLE_MAX] =
116 extern void tab_generate();
117 extern void ulaw_generate();
121 Bitmap *emc_bitmaps[2];
127 SetBitmaps_EM(emc_bitmaps);
129 objBitmap = emc_bitmaps[0];
130 sprBitmap = emc_bitmaps[1];
133 objPixmap = emc_bitmaps[0]->drawable;
134 sprPixmap = emc_bitmaps[1]->drawable;
136 objmaskBitmap = emc_bitmaps[0]->clip_mask;
137 sprmaskBitmap = emc_bitmaps[1]->clip_mask;
140 screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
145 spriteBitmap = XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
146 if (spriteBitmap == 0)
147 Error(ERR_EXIT, "failed to create sprite pixmap for EM engine");
150 objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset;
151 gcValues.graphics_exposures = False;
152 spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures,
155 Error(ERR_EXIT, "failed to create sprite GC for EM engine");
158 /* ----------------------------------------------------------------- */
160 #if defined(AUDIO_UNIX_NATIVE)
162 #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
166 char name[MAXNAME+2];
169 for (i = 0; i < SAMPLE_MAX; i++)
175 snprintf(name, MAXNAME+2, "%s/%s/%s", arg_basedir, EM_SND_DIR,
180 snprintf(name, MAXNAME+2, "%s/%s", EM_SND_DIR, sound_names[i]);
184 Error(ERR_EXIT, "buffer overflow when reading sounds directory");
186 if (read_sample(name, &sound_data[i], &sound_length[i]))
191 int mult = sound_volume[i] * 65536 / (100 * MIXER_MAX);
192 stop = sound_data[i] + sound_length[i];
193 for (ptr = sound_data[i]; ptr < stop; ptr++)
194 *ptr = (*ptr * mult) / 65536;
198 if (pipe(sound_pipe) == -1)
200 Error(ERR_WARN, "unable to create sound pipe for EM engine -- no sound");
208 Error(ERR_WARN, "unable to fork sound thread for EM engine -- no sound");
213 close(sound_pipe[sound_pid == 0]);
214 sound_pipe[sound_pid == 0] = -1;
216 _exit(sound_thread());
218 signal(SIGPIPE, SIG_IGN); /* dont crash if sound process dies */
221 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */
223 #endif /* AUDIO_UNIX_NATIVE */
230 /* pre-calculate some data */
234 progname = "emerald mine";
237 Error(ERR_EXIT, "em_open_all(): open_all() failed");
242 void em_close_all(void)
244 #if defined(AUDIO_UNIX_NATIVE)
249 kill(sound_pid, SIGTERM);
250 waitpid(sound_pid, 0, 0);
253 if (sound_pipe[0] != -1)
254 close(sound_pipe[0]);
255 if (sound_pipe[1] != -1)
256 close(sound_pipe[1]);
258 for (i = 0; i < SAMPLE_MAX; i++)
265 XFreeGC(display, spriteGC);
268 XFreePixmap(display, spriteBitmap);
272 /* ---------------------------------------------------------------------- */
274 extern unsigned int screen_x;
275 extern unsigned int screen_y;
277 void play_sound(int x, int y, int sample)
279 unsigned int left = screen_x / TILEX;
280 unsigned int top = screen_y / TILEY;
283 if (x == -1 && y == -1) /* play sound in the middle of the screen */
284 play[sample] = 0xffff;
285 else if ((unsigned int)(y - top) <= SCR_FIELDY &&
286 (unsigned int)(x - left) <= SCR_FIELDX)
287 play[sample] = (y << 8) | (x & 0xff);
289 if ((x == -1 && y == -1) || /* play sound in the middle of the screen */
290 ((unsigned int)(y - top) <= SCR_FIELDY &&
291 (unsigned int)(x - left) <= SCR_FIELDX))
296 void sound_play(void)
301 for (i = 0; i < SAMPLE_MAX; i++)
303 PlayLevelSound_EM(0,0,0,0);
307 #if defined(AUDIO_UNIX_NATIVE)
308 if (sound_pipe[1] != -1)
310 if (write(sound_pipe[1], &play, sizeof(play)) == -1)
312 Error(ERR_WARN, "cannot write into pipe to child process -- no sounds");
314 if (sound_pipe[0] != -1)
316 close(sound_pipe[0]);
320 if (sound_pipe[1] != -1)
322 close(sound_pipe[1]);
330 memset(play, 0, sizeof(play));