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] =
78 static const int sound_volume[SAMPLE_MAX] =
118 extern void tab_generate();
119 extern void ulaw_generate();
123 Bitmap *emc_bitmaps[2];
129 SetBitmaps_EM(emc_bitmaps);
131 objBitmap = emc_bitmaps[0];
132 sprBitmap = emc_bitmaps[1];
135 objPixmap = emc_bitmaps[0]->drawable;
136 sprPixmap = emc_bitmaps[1]->drawable;
138 objmaskBitmap = emc_bitmaps[0]->clip_mask;
139 sprmaskBitmap = emc_bitmaps[1]->clip_mask;
142 screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
147 spriteBitmap = XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
148 if (spriteBitmap == 0)
149 Error(ERR_EXIT, "failed to create sprite pixmap for EM engine");
152 objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset;
153 gcValues.graphics_exposures = False;
154 spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures,
157 Error(ERR_EXIT, "failed to create sprite GC for EM engine");
160 /* ----------------------------------------------------------------- */
162 #if defined(AUDIO_UNIX_NATIVE)
164 #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
168 char name[MAXNAME+2];
171 for (i = 0; i < SAMPLE_MAX; i++)
177 snprintf(name, MAXNAME+2, "%s/%s/%s", arg_basedir, EM_SND_DIR,
182 snprintf(name, MAXNAME+2, "%s/%s", EM_SND_DIR, sound_names[i]);
186 Error(ERR_EXIT, "buffer overflow when reading sounds directory");
188 if (read_sample(name, &sound_data[i], &sound_length[i]))
193 int mult = sound_volume[i] * 65536 / (100 * MIXER_MAX);
194 stop = sound_data[i] + sound_length[i];
195 for (ptr = sound_data[i]; ptr < stop; ptr++)
196 *ptr = (*ptr * mult) / 65536;
200 if (pipe(sound_pipe) == -1)
202 Error(ERR_WARN, "unable to create sound pipe for EM engine -- no sound");
210 Error(ERR_WARN, "unable to fork sound thread for EM engine -- no sound");
215 close(sound_pipe[sound_pid == 0]);
216 sound_pipe[sound_pid == 0] = -1;
218 _exit(sound_thread());
220 signal(SIGPIPE, SIG_IGN); /* dont crash if sound process dies */
223 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */
225 #endif /* AUDIO_UNIX_NATIVE */
232 /* pre-calculate some data */
236 progname = "emerald mine";
239 Error(ERR_EXIT, "em_open_all(): open_all() failed");
244 void em_close_all(void)
246 #if defined(AUDIO_UNIX_NATIVE)
251 kill(sound_pid, SIGTERM);
252 waitpid(sound_pid, 0, 0);
255 if (sound_pipe[0] != -1)
256 close(sound_pipe[0]);
257 if (sound_pipe[1] != -1)
258 close(sound_pipe[1]);
260 for (i = 0; i < SAMPLE_MAX; i++)
267 XFreeGC(display, spriteGC);
270 XFreePixmap(display, spriteBitmap);
274 /* ---------------------------------------------------------------------- */
276 extern unsigned int screen_x;
277 extern unsigned int screen_y;
279 void play_sound(int x, int y, int sample)
281 unsigned int left = screen_x / TILEX;
282 unsigned int top = screen_y / TILEY;
285 if (x == -1 && y == -1) /* play sound in the middle of the screen */
286 play[sample] = 0xffff;
287 else if ((unsigned int)(y - top) <= SCR_FIELDY &&
288 (unsigned int)(x - left) <= SCR_FIELDX)
289 play[sample] = (y << 8) | (x & 0xff);
291 if ((x == -1 && y == -1) || /* play sound in the middle of the screen */
292 ((unsigned int)(y - top) <= SCR_FIELDY &&
293 (unsigned int)(x - left) <= SCR_FIELDX))
298 void play_element_sound(int x, int y, int sample, int element)
300 play_sound(x, y, sample);
303 void sound_play(void)
308 for (i = 0; i < SAMPLE_MAX; i++)
310 PlayLevelSound_EM(0,0,0,0);
314 #if defined(AUDIO_UNIX_NATIVE)
315 if (sound_pipe[1] != -1)
317 if (write(sound_pipe[1], &play, sizeof(play)) == -1)
319 Error(ERR_WARN, "cannot write into pipe to child process -- no sounds");
321 if (sound_pipe[0] != -1)
323 close(sound_pipe[0]);
327 if (sound_pipe[1] != -1)
329 close(sound_pipe[1]);
337 memset(play, 0, sizeof(play));