Commit 36f38d60 authored by Steven Fuller's avatar Steven Fuller

Mostly documentation updates.

Removed OpenAL code again.
parent 859b876f
......@@ -22,11 +22,6 @@ OBJS += sd_null.o
#OBJS += sd_oss.o fmopl.o
#CFLAGS += -D_REENTRANT
#LFLAGS += -lpthread
#OBJS += sd_oal.o fmopl.o
#CFLAGS += -D_REENTRANT -I/home/relnev/cvs/oal/include/
#LFLAGS += -lpthread -ldl -L/home/relnev/cvs/oal/linux/src/ -lopenal # /home/relnev/cvs/oal/linux/src/libopenal.a
#LFLAGS += -lpthread /home/relnev/ElectricFence-2.2.2/libefence.a
CFLAGS += `sdl-config --cflags`
......
Just some random facts/thoughts/ideas/musings:
* Wolfenstein 3D for:
- PC (released, of course) [May 5, 1992]
- PC [May 5, 1992]
- PC (Spear of Destiny) [September 18, 1992]
- SNES
- Macintosh
......@@ -24,6 +24,7 @@ Just some random facts/thoughts/ideas/musings:
- Windows
WolfGL: http://www.sourceforge.net/projects/wolfgl/
Wolf DX: http://www.phoebe.co.uk/glwolf/
NewWolf: http://wolfgl.narod.ru/
- Acorn/Archemedes
* PC source released August(?) ??, 1995:
......
TODO: I still need to write this file
NOTE: save games and configuration files now have version fields. Version
0xFFFFFFFF is only for non-release/debug/snapshot versions (in other words,
the file formats may change at any time).
......@@ -7,6 +9,15 @@ How to use:
About:
Thanks:
* id Software
* David Haslam
* Ryan Gordon
* Bill Heineman
* Dan Olson
* Leonardo Zide
* Tatsuyuki Satoh
* Chuck Mason
* And everyone who has emailed me about this code! Thanks!
-----
Steven Fuller
......
......@@ -16,7 +16,7 @@ M M - add music (would need to RE the sound lib)
B I - complete savegame, config formats
M I - add SDL
B R - decide if to keep SVGA/X11 targets
B M - configure scripts?
B M - configure scripts? (autoconf/automake/etc)
B M - port to dreamcast?
B M - add compression to savegames/config
B I - play through game (w/ sound and music) to make sure things work
......@@ -30,19 +30,23 @@ B I - add mouse support
B M - add joystick/gamepad support
P I - fill in the new fizzlefade function
P I - add sound "emulation" to the necessary targets so WaitSoundDone works
B R - autoconf/automake
P R - change boolean SD_PlaySound to void SD_PlaySound
P M - position pushwall sounds
P M - id_ca.c cache code: fix/readd/rewrite the "garbage collection" system
P M - rewrite id_ca.c: uniform memory handling system
P M - either move id_heads into wl_def or split header files apart
P R - rewrite fmopl.c to avoid licensing issues
P R - remove CA_LoadAllSounds now that the sound code does everything
B I - README, etc.
B M - Code Documentation
P M - rename visable to visible
B M - change the commandline handling (use something like getopt?)
P R - rewrite RLEWexpand to not use words
B M - openal support
Complete:
P I - fix or remove fizzle fade
- Removed [nice, but very hacky effect]
P R - openal sound
- almost complete
------------------------------------------------------------------------------
* what exactly is the point of all the DigiMode checks in wl_act2.c?
* add ylookup?
......@@ -53,7 +57,6 @@ example (is this reproducible?)
* use static and const where appropriate
* clean up header files, especially wl_def.h, where some declarations aren't
in the right place
* change the current parameter handling code to something like getopt
* remove check for debugmode?
* check filehandling (ex, file missing, bad file type, and such)
PlayDemoFromFile specifically
......@@ -61,7 +64,6 @@ PlayDemoFromFile specifically
- probably due to waiting for sounds to finish
* split wl_draw into two files (draw independent, draw dependent)
* when window loses focus, it should clear the keys
* rename visable to visible
------------------------------------------------------------------------------
fix:
void ControlMovement(objtype *ob) (wl_agent.c)
......@@ -82,6 +84,17 @@ Sound Menu:
- On [AdLib/OPL2]
- Off
------------------------------------------------------------------------------
Where to Look for/Save Files:
~/.wolf3d
cwd
/usr/games/share
$ENVIRONMENT_VARIABLE
Need to establish where to look, order to look, strict/lenient loading (load
all files from the determined game directory, or look in order for each
file), and where to put savegames and config files.
------------------------------------------------------------------------------
Save game header:
8 bytes: WOLF3D, 0, 0
4 bytes: SAV, 0
......
......@@ -715,14 +715,6 @@ void CA_CacheMap(int mapnum)
/* ======================================================================== */
void CA_UpLevel()
{
}
void CA_DownLevel()
{
}
void MM_Startup()
{
}
......
......@@ -43,9 +43,6 @@ void CA_CacheMap(int mapnum);
void CA_CacheGrChunk(int chunk);
void CA_UnCacheGrChunk(int chunk);
void CA_UpLevel();
void CA_DownLevel();
/* ======================================================================= */
void MM_Startup();
......
#include "wl_def.h"
#include <unistd.h>
#include <pthread.h>
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include "fmopl.h"
/* old stuff */
boolean AdLibPresent, SoundBlasterPresent;
SDMode SoundMode, MusicMode;
SDSMode DigiMode;
static boolean SD_Started;
/* AdLib Sound:
longword length;
word priority;
byte mChar, cChar, mScale, cScale, mAttack, cAttack, mSus, cSus,
mWave, cWave, nConn, voice, mode, unused[3];
byte block, data[];
*/
/* AdLib Music:
word length, data[];
(data is organized in reg|val (word) and tic count (word) pairs)
*/
/* PC Sound:
longword length;
word priority;
byte data[];
*/
/* new stuff */
static int NumPCM;
struct _PCMSound
{
byte *data;
int length;
int used;
ALuint handle;
} static *PCMSound;
struct _SoundData
{
int priority;
/* PCM */
struct _PCMSound *pcm;
/* AdLib */
int alength;
byte mChar, cChar, mScale, cScale,
mAttack, cAttack, mSus, cSus,
mWave, cWave, nConn;
byte block;
byte *adata;
} static SoundData[LASTSOUND];
static ALuint AdBuf[4];
struct _MusicData
{
int length;
word *regval;
word *count;
} static MusicData[LASTMUSIC];
#define CHANNELS 5 /* channel 0: adlib */
/* channel 1: local sounds */
/* channel 2+ positioned sounds */
struct _SoundChan {
int id; /* what is making the sound */
int sound; /* what is the sound */
int priority; /* priority of this sound */
int type; /* adlib or pcm? */
int pos; /* internal variable for soundplayer */
ALuint handle; /* OpenAL source handle */
} static SoundChan[CHANNELS];
/* how to do streaming buffer:
queue say 4 buffers of a certain size and play
now, run your updating loop:
unqueue buffers that have finished
generate new data and fill these buffers
queue the buffers with the new data
since "Applications can have multiple threads that share one more or contexts.
In other words, AL and ALC are threadsafe.", the streaming code can be
implemented as a second thread
*/
/* threads:
main thread handles pcm channels/sounds
sound thread handles adlib channels/sounds
sound thread sets priority to -1 if a sound is not playing
potential thread contention with both main and sound threads
accessing channel 0's information, but:
1. it's not done in any loops
2. any data mismatch won't affect the game (at least I think so)
*/
static pthread_t hSoundThread;
static pthread_mutex_t SoundMutex;
#define SOUND_START 0 /* play this adlib sound */
#define SOUND_STARTD 1 /* play this pcm sound */
#define SOUND_STOP 2 /* stop all sounds */
#define MUSIC_START 3 /* play this song */
#define MUSIC_STOP 4 /* stop music */
#define MUSIC_PAUSE 5 /* pause music */
#define MUSIC_UNPAUSE 6 /* unpause music */
#define ST_SHUTDOWN 7 /* shutdown thread */
struct _SoundMessage
{
int type; /* what is it? (see above) */
int item; /* what to play (if anything) */
struct _SoundMessage *next;
};
struct _SoundMessage *SoundMessage;
static void SendSTMessage(int type, int item)
{
struct _SoundMessage *t;
pthread_mutex_lock(&SoundMutex);
MM_GetPtr((memptr)&t, sizeof(struct _SoundMessage));
t->type = type;
t->item = item;
t->next = SoundMessage;
SoundMessage = t;
pthread_mutex_unlock(&SoundMutex);
}
static boolean ReceiveSTMessage(int *type, int *item)
{
boolean retr = false;
pthread_mutex_lock(&SoundMutex);
if (SoundMessage) {
struct _SoundMessage *p, *t;
p = NULL;
t = SoundMessage;
while (t->next) {
p = t;
t = t->next;
}
if (p) {
p->next = NULL;
} else {
SoundMessage = NULL;
}
*type = t->type;
*item = t->item;
MM_FreePtr((memptr)&t);
retr = true;
} else {
retr = false;
}
pthread_mutex_unlock(&SoundMutex);
return retr;
}
static void *SoundThread(void *data)
{
FM_OPL *OPL;
byte *s;
int type, item;
int i;
OPL = OPLCreate(OPL_TYPE_YM3812, 3579545, 44100);
OPLWrite(OPL, 0x01, 0x20); /* Set WSE=1 */
OPLWrite(OPL, 0x08, 0x00); /* Set CSM=0 & SEL=0 */
MM_GetPtr((memptr)&s, 63*2*5);
alGenBuffers(4, AdBuf);
for (i = 0; i < 4; i++)
alBufferData(AdBuf[i], AL_FORMAT_MONO16, s, 63*5, 44100);
alSourceQueueBuffers(SoundChan[0].handle, 4, AdBuf);
for (;;) {
while (ReceiveSTMessage(&type, &item)) {
switch (type) {
case SOUND_START:
break;
case SOUND_STOP:
break;
case MUSIC_START:
break;
case MUSIC_STOP:
break;
case MUSIC_PAUSE:
break;
case MUSIC_UNPAUSE:
break;
case ST_SHUTDOWN:
/* TODO: free the openal stuff allocated in this thread */
OPLDestroy(OPL);
return NULL;
}
}
/* Do Stuff */
usleep(1);
}
return NULL;
}
void SD_Startup()
{
byte *p, *s;
int len, l, i, c;
if (SD_Started)
return;
alutInit(NULL, 0);
InitDigiMap();
p = PM_GetPage(ChunksInFile - 1); /* get pcm size table */
/* find how many full sounds there are */
c = PMSoundStart;
for (i = 0; i < 1024; i++) {
if (c >= (ChunksInFile - 1))
break;
len = p[i*4+2] | (p[i*4+3] << 8);
/* convert len into amount of pages used */
c += (len + (PMPageSize - 1)) / PMPageSize;
}
NumPCM = i;
MM_GetPtr((memptr)&PCMSound, sizeof(struct _PCMSound) * NumPCM);
for (i = 0; i < NumPCM; i++) {
PCMSound[i].length = len = p[i*4+2] | (p[i*4+3] << 8);
PCMSound[i].used = 0;
if (len) {
MM_GetPtr((memptr)&(PCMSound[i].data), len);
c = p[i*4+0] | (p[i*4+1] << 8);
s = PCMSound[i].data;
while (len > 0) {
l = (len >= PMPageSize) ? PMPageSize : len;
memcpy(s, PM_GetSoundPage(c), l);
PM_FreePage(c);
c++;
s += PMPageSize;
len -= PMPageSize;
}
} else {
PCMSound[i].data = NULL;
PCMSound[i].handle = -1;
}
}
for (i = 0; i < LASTSOUND; i++) {
CA_CacheAudioChunk(STARTADLIBSOUNDS + i);
s = audiosegs[STARTADLIBSOUNDS + i];
if (s) {
SoundData[i].alength = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24);
SoundData[i].priority = s[4] | (s[5] << 8);
/* Rest of AdLib Sound stuff here */
if (DigiMap[i] != -1) {
struct _PCMSound *pcm = &PCMSound[DigiMap[i]];
if (pcm->used || pcm->data) {
SoundData[i].pcm = pcm;
if (!pcm->used) {
pcm->used = 1;
alGenBuffers(1, &(pcm->handle));
alBufferData(pcm->handle, AL_FORMAT_MONO8, pcm->data, pcm->length, 7000);
if (alGetError() != AL_NO_ERROR) {
fprintf(stderr, "AL error: trying to load pcm sound %d (sound %d)\n", DigiMap[i], i);
alDeleteBuffers(1, &(pcm->handle));
pcm->handle = -1;
} else {
MM_FreePtr((memptr)&(pcm->data));
pcm->data = NULL;
}
}
} else {
SoundData[i].pcm = NULL;
}
} else {
SoundData[i].pcm = NULL;
}
} else {
SoundData[i].priority = 0;
SoundData[i].alength = 0;
SoundData[i].pcm = NULL;
}
}
SoundChan[0].id = -1;
SoundChan[0].priority = -1;
for (i = 0; i < CHANNELS; i++) {
alGenSources(1, &(SoundChan[i].handle));
SoundChan[i].id = -1;
SoundChan[i].priority = -1;
alSourcei(SoundChan[i].handle, AL_SOURCE_RELATIVE, AL_FALSE);
/* alSourcef(SoundChan[i].handle, AL_ROLLOFF_FACTOR, 1.0f); */
}
alSourcei(SoundChan[0].handle, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcef(SoundChan[0].handle, AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(SoundChan[1].handle, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcef(SoundChan[i].handle, AL_ROLLOFF_FACTOR, 0.0f);
MusicData[0].length = 0; /* silence warnings for now */
SoundMessage = NULL;
pthread_mutex_init(&SoundMutex, NULL);
if (pthread_create(&hSoundThread, NULL, SoundThread, NULL) != 0) {
perror("pthread_create");
}
SD_Started = true;
}
void SD_Shutdown()
{
if (!SD_Started)
return;
SendSTMessage(ST_SHUTDOWN, 0);
/* TODO: deallocate everything here */
SD_Started = false;
}
boolean SD_PlaySound(soundnames sound)
{
struct _SoundData *s = &SoundData[sound];
ALint val;
if (s->pcm) {
if (s->pcm->handle != -1) {
alGetSourceiv(SoundChan[1].handle, AL_SOURCE_STATE, &val);
if ((val != AL_PLAYING) || (s->priority >= SoundChan[1].priority)) {
SoundChan[1].sound = sound;
SoundChan[1].priority = s->priority;
alSourceStop(SoundChan[1].handle);
alSourcei(SoundChan[1].handle, AL_BUFFER, s->pcm->handle);
alSourcePlay(SoundChan[1].handle);
}
return false;
}
}
if (s->priority >= SoundChan[0].priority)
SendSTMessage(SOUND_START, sound);
return false;
}
void PlaySoundLocGlobal(word sound, int id, fixed gx, fixed gy)
{
struct _SoundData *s = &SoundData[sound];
ALfloat fval[3];
ALint val;
int i;
if (s->pcm) {
if (s->pcm->handle != -1) {
for (i = 2; i < CHANNELS; i++) {
if (id == SoundChan[i].id)
break;
}
if (i == CHANNELS) {
for (i = 2; i < CHANNELS; i++) {
alGetSourceiv(SoundChan[i].handle, AL_SOURCE_STATE, &val);
if (val != AL_PLAYING)
break;
}
}
if (i == CHANNELS) {
for (i = 2; i < CHANNELS; i++) {
if (s->priority >= SoundChan[i].priority)
break;
}
}
if (i != CHANNELS) {
SoundChan[i].id = id;
SoundChan[i].sound = sound;
SoundChan[i].priority = s->priority;
fval[0] = (ALfloat)gx / 32768.0f;
fval[1] = 0.0f;
fval[2] = (ALfloat)gy / 32768.0f;
alSourceStop(SoundChan[i].handle);
alSourcei(SoundChan[i].handle, AL_BUFFER, s->pcm->handle);
alSourcefv(SoundChan[i].handle, AL_POSITION, fval);
alSourcePlay(SoundChan[i].handle);
}
return;
}
}
/* Just play the AdLib version */
SD_PlaySound(sound);
}
void UpdateSoundLoc(fixed x, fixed y, int angle)
{
ALfloat val[6];
val[0] = (ALfloat)x / 32768.0f;
val[1] = 0.0f;
val[2] = (ALfloat)y / 32768.0f;
alListenerfv(AL_POSITION, val);
val[0] = -cos(angle * PI / 180.0f);
val[1] = 0.0f;
val[2] = -sin(angle * PI / 180.0f);
val[3] = 0.0f;
val[4] = 1.0f;
val[5] = 0.0f;
alListenerfv(AL_ORIENTATION, val);
}
void SD_StopSound()
{
int i;
SendSTMessage(SOUND_STOP, 0);
for (i = 1; i < CHANNELS; i++) {
SoundChan[i].id = -1;
SoundChan[i].sound = -1;
SoundChan[i].priority = -1;
alSourceStop(SoundChan[i].handle);
}
}
word SD_SoundPlaying()
{
ALint val;
int i;
if (SoundChan[0].priority != -1)
return SoundChan[0].sound;
for (i = 1; i < CHANNELS; i++) {
alGetSourceiv(SoundChan[i].handle, AL_SOURCE_STATE, &val);
if (val == AL_PLAYING)
return SoundChan[i].sound;
}
return false;
}
void SD_WaitSoundDone()
{
while (SD_SoundPlaying())
;
}
void SD_MusicOn()
{
SendSTMessage(MUSIC_UNPAUSE, 0);
}
void SD_MusicOff()
{
SendSTMessage(MUSIC_PAUSE, 0);
}
void SD_StartMusic(int music)
{
SendSTMessage(MUSIC_START, music);
}
void SD_SetDigiDevice(SDSMode mode)
{
}
boolean SD_SetSoundMode(SDMode mode)
{
return false;
}
boolean SD_SetMusicMode(SMMode mode)
{
return false;
}
......@@ -2446,13 +2446,10 @@ void A_StartDeathCam(objtype *ob)
FizzleFade(false, 70, 127);
CA_UpLevel();
CacheLump(LEVELEND_LUMP_START, LEVELEND_LUMP_END);
Write(0, 7, STR_SEEAGAIN);
CA_DownLevel();
VW_UpdateScreen();
IN_UserInput(300);
......
......@@ -661,8 +661,6 @@ void HelpScreens()
int artnum;
char *text;
CA_UpLevel();
artnum = helpextern;
CA_CacheGrChunk(artnum);
text = (char *)grsegs[artnum];
......@@ -674,7 +672,6 @@ void HelpScreens()
VW_FadeOut();
FreeMusic();
CA_DownLevel();
}
//
......@@ -687,8 +684,6 @@ void EndText()
ClearMemory();
CA_UpLevel();
artnum = endextern+gamestate.episode;
CA_CacheGrChunk(artnum);
text = (char *)grsegs[artnum];
......@@ -702,7 +697,6 @@ void EndText()
IN_ClearKeysDown();
FreeMusic();
CA_DownLevel();
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment