home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trixter's Scene Collection
/
trixter.zip
/
trixter
/
Demos
/
KD_DREAM.ZIP
/
SRC.ZIP
/
DREAMS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-30
|
36KB
|
1,339 lines
#include <math.h>
#include <malloc.h>
#include <wgt5.h>
#include <wgtvesa.h>
#include <stdlib.h>
#include <direct.h>
#include <string.h>
#include <pr.h>
#include "e:\seal\test\audio\include\audio.h"
#ifdef __3DFX__
#include <glide.h>
#include <pr3dfx.h>
#endif
/*
Dreams
For The Party 6
Started on Dec. 17/1996
Finished on Dec. 23/1996
Note that some parts work on the 3Dfx but not all
(mirrors and motion blur).
Written by Chris Egerter
egerter@egerter.com www.egerter.com
*/
PR_DWORD device; /* Video output device */
PR_DWORD ticks=0; /* Total number of ticks passed */
PR_DWORD global_ticks=0;
PR_DWORD secret = 0;
PR_DWORD demo_sound; /* 1 if sound is on */
PR_DWORD sound_config = 0; /* 1 if manual configuration is used */
PR_DWORD fading = 0;
PR_DWORD song_row, song_patt; /* Song row and pattern */
color fadepal[256];
PR_DWORD vwidth; /* Viewport size */
PR_DWORD vheight;
PR_VIEWPORT viewport; /* Our viewport structure */
PR_VIEWPORT mirrorview; /* Our mirror viewport */
PR_CAMERA *newcam; /* One camera */
PR_LIGHTLIST userlights; /* A bunch of lights */
AUDIOINFO info;
AUDIOCAPS caps;
LPAUDIOMODULE lpModule;
UINT rc, nDevId;
void InitializeSound (void)
/* Loads in the song and wave files */
{
int i;
char szText[80];
PR_DWORD sound_device, sound_bits, sound_mode, sound_rate;
/* initialize audio library */
AInitialize ();
/* open audio device */
info.nDeviceId = AUDIO_DEVICE_MAPPER;
info.wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO;
info.nSampleRate = 22050;
if (sound_config)
{
/* show registered device drivers */
printf("List of registered devices:\n");
for (nDevId = 1; nDevId < AGetAudioNumDevs(); nDevId++) {
AGetAudioDevCaps(nDevId, &caps);
printf(" %2d. %s\n", nDevId, caps.szProductName);
}
printf("\n");
printf ("Choose a sound device: ");
scanf ("%i", &sound_device);
info.nDeviceId = sound_device;
printf("\n\n");
printf ("0. 8 bit\n");
printf ("1. 16 bit\n");
printf ("Choose the bit quality: ");
scanf ("%i", &sound_bits);
if (sound_bits == 1)
info.wFormat = AUDIO_FORMAT_16BITS;
else
info.wFormat = AUDIO_FORMAT_8BITS;
printf("\n\n");
printf ("0. Mono\n");
printf ("1. Stereo\n");
printf ("Choose the mode: ");
scanf ("%i", &sound_mode);
if (sound_bits == 1)
info.wFormat |= AUDIO_FORMAT_STEREO;
else
info.wFormat |= AUDIO_FORMAT_MONO;
printf("\n\n");
printf ("0. 16000\n");
printf ("1. 22050\n");
printf ("2. 44100\n");
printf ("Choose the sample rate (22050 recommended): ");
scanf ("%i", &sound_rate);
if (sound_rate == 0)
info.nSampleRate = 16000;
else if (sound_rate == 2)
info.nSampleRate = 44100;
else
info.nSampleRate = 22050;
}
if ((rc = AOpenAudio(&info)) != AUDIO_ERROR_NONE) {
AGetErrorText(rc, szText, sizeof(szText) - 1);
printf("ERROR: %s\n", szText);
exit(1);
}
else {
AGetAudioDevCaps(info.nDeviceId, &caps);
printf("Using %s.\n", caps.szProductName);
printf("Audio device initialized at %d bits %s %u Hz\n",
info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8,
info.wFormat & AUDIO_FORMAT_STEREO ?
"stereo" : "mono", info.nSampleRate);
}
/* load module and waveform file */
ALoadModuleFile ("bm_green.xm", &lpModule, 0);
/* open voices for module and waveforms */
AOpenVoices (lpModule->nTracks);
delay (1000);
}
void DeinitSound (void)
/* Stop the music and any waves that are playing, and frees the
sound data */
{
int i;
/* stop playing the module */
AStopModule ();
ACloseVoices ();
/* release the module */
AFreeModuleFile (lpModule);
/* close audio device */
ACloseAudio ();
}
/* ---------------------------------------------------------------------- */
/* Initialize the video output device */
/* ---------------------------------------------------------------------- */
void InitializeDevices (void)
{
#ifdef __3DFX__
if ((device == DEVICE_3DFX) || (device == DEVICE_ANY))
device = PR_Detect3Dfx ();
#endif
if ((device == DEVICE_SVGA) || (device == DEVICE_ANY))
device = PR_DetectSVGA (); /* Attempt to find the device */
if ((device == DEVICE_VGA) || (device == DEVICE_ANY))
device = PR_DetectVGA (); /* Attempt to find the device */
#ifdef __3DFX__
if (device == DEVICE_3DFX)
{
PR_Initialize3Dfx ();
atexit (PR_Shutdown3Dfx);
}
#endif
if (device == DEVICE_SVGA)
{
PR_InitializeSVGA ();
atexit (PR_ShutdownSVGA);
}
else if (device == DEVICE_VGA)
{
PR_InitializeVGA ();
}
}
/* ---------------------------------------------------------------------- */
/* Sets the fade palette to white */
/* ---------------------------------------------------------------------- */
void WhitePalette (void)
{
PR_DWORD i;
for (i = 0; i < 256; i++)
wsetrgb (i, 63, 63, 63, fadepal);
wsetpalette (0, 255, fadepal);
}
/* ---------------------------------------------------------------------- */
/* Sets the global palette to black */
/* ---------------------------------------------------------------------- */
void BlackPalette (void)
{
PR_DWORD i;
for (i = 0; i < 256; i++)
wsetrgb (i, 0, 0, 0, global_palette);
}
/* ---------------------------------------------------------------------- */
/* Sets the global palette to 4/3 */
/* ---------------------------------------------------------------------- */
void BrightPalette (void)
{
PR_DWORD i;
for (i = 0; i < 256; i++)
{
fadepal[i].r = (PR_REAL)global_palette[i].r * 1.5;
fadepal[i].g = (PR_REAL)global_palette[i].g * 1.5;
fadepal[i].b = (PR_REAL)global_palette[i].b * 1.5;
if (fadepal[i].r > 63)
fadepal[i].r = 63;
if (fadepal[i].g > 63)
fadepal[i].g = 63;
if (fadepal[i].b > 63)
fadepal[i].b = 63;
}
}
/* ---------------------------------------------------------------------- */
/* Decreases each color in fade pal until it reaches the color in */
/* global_palette */
/* ---------------------------------------------------------------------- */
void DecPalette (void)
{
PR_DWORD i;
for (i = 0; i < 256; i++)
{
if (fadepal[i].r > global_palette[i].r)
fadepal[i].r--;
if (fadepal[i].g > global_palette[i].g)
fadepal[i].g--;
if (fadepal[i].b > global_palette[i].b)
fadepal[i].b--;
}
wsetpalette (0, 255, fadepal);
}
/* ---------------------------------------------------------------------- */
/* Timer Interrupt */
/* ---------------------------------------------------------------------- */
void timerproc (void)
{
ticks++;
global_ticks++;
if (fading)
DecPalette ();
if (demo_sound)
AUpdateAudio ();
}
/* ---------------------------------------------------------------------- */
/* Sets to 320x200 mode */
/* ---------------------------------------------------------------------- */
void SetVideoMode (void)
{
#ifdef __3DFX__
vwidth = 640;
vheight = 480;
#else
vwidth = 320;
vheight = 200;
#endif
PR_SetMode (vwidth, vheight, 60);
PR_OpenViewport (&viewport, 1, 1, vwidth-2, vheight-2, VIEW_PLAIN);
PR_SetViewport (&viewport);
PRGFX_Clip (active_viewport.topx,
active_viewport.topy,
active_viewport.bottomx,
active_viewport.bottomy);
}
/* ---------------------------------------------------------------------- */
/* Make a list of lights */
/* ---------------------------------------------------------------------- */
void InitializeLights (void)
{
/* Initialize the lights */
PR_AllocLights