Well, at present the Windows code for the actual game almost compiles. The current goal is to undo all the things that Ormus did to make this job difficult.
Basically, remove as many as possible of the dependencies of the source files in the tools and classes folders on source files not in those folders. (With the exception that files in the classes folder may depend on files in the tools folder.) In this commit, several changes were made. - Project file modified, may need further modification. - Many files renamed to match the Mac version. - #include statements for system headers changed to use <> instead of "" (some already did, but many didn't). - xxx.h headers replaced with cxxx headers where appropriate. - Most sound-related variables moved from globvars.cpp to soundvars.cpp. - The files originally named graphutil and gutils have been merged. - Changed TRUE/FALSE to true/false. - Changed exlsound to soundtool and mostly removed dependencies on the main game files; the exception is that it still uses mainPtr (which probably can't be helped) and print_nums (which should probably be incorporated into the MessageBox string). - Possibly other things that were forgotten. For some reason this commit also includes changes recently committed into the branch for osx. git-svn-id: http://openexile.googlecode.com/svn/trunk@121 4ebdad44-0ea0-11de-aab3-ff745001d230
This commit is contained in:
@@ -5,71 +5,19 @@
|
||||
* Created by Celtic Minstrel on 16/04/09.
|
||||
*
|
||||
*/
|
||||
#include <cmath>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <Carbon/Carbon.h>
|
||||
#elif defined(WIN32)
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "soundtool.h"
|
||||
|
||||
Handle sound_handles[NUM_SOUNDS];
|
||||
bool play_sounds = true;
|
||||
short last_played = 10000;
|
||||
|
||||
bool always_asynch[100] = {
|
||||
false,false,false,false,false,
|
||||
false,true,false,false,false,
|
||||
false,false,false,false,false, // 10
|
||||
false,false,false,false,false,
|
||||
false,false,false,false,true, // 20
|
||||
true,false,false,false,false,
|
||||
false,false,false,false,true, // 30
|
||||
false,false,true,false,true,
|
||||
false,true,true,true,true, // 40
|
||||
true,true,true,true,true,
|
||||
true,false,false,false,false, // 50
|
||||
true,false,false,false,false,
|
||||
false,true,false,false,false, // 60
|
||||
false,false,false,false,false,
|
||||
false,false,false,false,false, // 70
|
||||
false,true,true,true,true,
|
||||
true,true,true,true,false, // 80
|
||||
true,false,false,false,false,
|
||||
false,true,false,false,false, // 90
|
||||
false,false,false,false,false
|
||||
};
|
||||
bool load_when_play[100] = {
|
||||
0,0,1,1,1,1,0,1,1,1,
|
||||
0,0,0,1,0,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,0,1,1,
|
||||
1,1,1,1,0,1,1,0,1,1,
|
||||
1,1,1,1,1,1,1,0,0,0,
|
||||
0,1,1,1,1,0,1,1,1,1,
|
||||
1,0,1,1,1,1,1,1,1,0,
|
||||
0,0,0,0,0,0,1,1,1,1,
|
||||
1,1,1,1,1,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,1,0
|
||||
};
|
||||
|
||||
short sound_delay[100] = {
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,25,25,0,0,0,0,
|
||||
0,0,0,0,8,0,0,8,0,0,
|
||||
0,0,0,10,20,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,13,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
//Allocate SndChannelPtr chan[4] as a global variable.
|
||||
//Allocate char numchannel = 3; (This gives 4 channels, = 2 gives 3 etc...
|
||||
//Allocate char channel; This is just used as a counter so each sound is played by the next
|
||||
//channel in line. You can have up to 4 sounds playing at once.
|
||||
|
||||
SndChannelPtr chan[4];
|
||||
char numchannel = 3;
|
||||
char channel;
|
||||
short snd_played[4] = {-1,-1,-1,-1};
|
||||
|
||||
bool sound_going(short which_s) {
|
||||
short i;
|
||||
|
||||
@@ -79,6 +27,7 @@ bool sound_going(short which_s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
pascal void snd_channel_callback(SndChannelPtr theChannel,SndCommand* theCommand) {
|
||||
long theA5;
|
||||
short channel = -1,i,which_sound;
|
||||
@@ -104,6 +53,7 @@ pascal void snd_channel_callback(SndChannelPtr theChannel,SndCommand* theCommand
|
||||
theA5 = SetA5(theA5);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_snd_tool(){
|
||||
short i,t;
|
||||
@@ -124,12 +74,13 @@ void init_snd_tool(){
|
||||
|
||||
}
|
||||
|
||||
void play_sound(short which, short how_many_times){ // if < 0, play asynch
|
||||
if (!play_sounds) return;
|
||||
void play_sound(short which, short how_many_times) { // if < 0, play asynch
|
||||
#if defined(__APPLE__)
|
||||
Handle sndhandle;
|
||||
unsigned long dummy;
|
||||
OSErr err;
|
||||
SndCommand theCommand;
|
||||
if (!play_sounds || how_many_times == 0) return;
|
||||
|
||||
if (abs(which) > NUM_SOUNDS) {
|
||||
//char msg[50];
|
||||
@@ -183,9 +134,134 @@ void play_sound(short which, short how_many_times){ // if < 0, play asynch
|
||||
Delay(sound_delay[-1 * which],&dummy);
|
||||
if(how_many_times > 1)
|
||||
play_sound(which, how_many_times - 1);
|
||||
#elif defined(WIN32)
|
||||
short i,num_fails = 0;
|
||||
char snd_name[30];
|
||||
bool asyn = false,a_sound_did_get_played = false;
|
||||
bool not_asyn = false,check_sound;
|
||||
HRSRC h;
|
||||
if ((sounds_missing) || (!play_sounds) || (how_many_times == 0))
|
||||
return;
|
||||
|
||||
if (which < 0) {
|
||||
asyn = true;
|
||||
which = which * -1;
|
||||
}
|
||||
if (which >= 1000) {
|
||||
which -= 1000;
|
||||
not_asyn = true;
|
||||
}
|
||||
|
||||
if (which >= 100)
|
||||
return;
|
||||
|
||||
if ((always_asynch[which] == true) &&
|
||||
((can_ignore[which] == 1) || (can_ignore[which] >= 3)))
|
||||
asyn = true;
|
||||
if ((can_ignore[which] > 0) && (can_ignore[which] < 5) && (party.stuff_done[305][5] == 1))
|
||||
return;
|
||||
if ((can_ignore[which] != 1) && (can_ignore[which] < 3))
|
||||
asyn = false;
|
||||
if ((party.stuff_done[305][5] == 1) && (can_ignore[which] < 5))
|
||||
asyn = false;
|
||||
if (not_asyn == true)
|
||||
asyn = false;
|
||||
|
||||
if ((load_when_play[which] == true) && (sound_handles[which] == NULL)) {
|
||||
asyn = false;
|
||||
sprintf((char *)snd_name,"#%d",which + 1);
|
||||
h = FindResource(hModule,snd_name,"#100");
|
||||
|
||||
sound_handles[which] = LoadResource(hModule,h);
|
||||
snds[which] = (char *) LockResource(sound_handles[which]);
|
||||
|
||||
}
|
||||
|
||||
if (store_last_sound_played == 6)
|
||||
sndPlaySound(NULL,0);
|
||||
|
||||
if (asyn == true) {
|
||||
if (can_ignore[which] >= 4)
|
||||
check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP);
|
||||
else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY);
|
||||
|
||||
while (check_sound == false) {
|
||||
|
||||
if (can_ignore[store_last_sound_played] == 4) {// then sound goes away
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
num_fails++;
|
||||
if (num_fails < 40)
|
||||
sound_pause(25);
|
||||
else {
|
||||
MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error a. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
print_nums(111,which,num_fails);
|
||||
sounds_fucked = true;
|
||||
return;
|
||||
}
|
||||
sndPlaySound(NULL,0);
|
||||
|
||||
if (can_ignore[which] >= 4)
|
||||
check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP);
|
||||
else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY);
|
||||
}
|
||||
a_sound_did_get_played = true;
|
||||
}
|
||||
else {
|
||||
if (can_ignore[which] >= 4)
|
||||
check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP);
|
||||
else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY);
|
||||
while (check_sound == false) {
|
||||
if (can_ignore[store_last_sound_played] == 4) {// then sound goes away
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
num_fails++;
|
||||
if (num_fails < 40)
|
||||
sound_pause(25);
|
||||
else {
|
||||
MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error b. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
print_nums(222,which,num_fails);
|
||||
sounds_fucked = true;
|
||||
return;
|
||||
}
|
||||
sndPlaySound(NULL,0);
|
||||
|
||||
if (can_ignore[which] >= 4)
|
||||
check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP);
|
||||
else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY);
|
||||
}
|
||||
a_sound_did_get_played = true;
|
||||
}
|
||||
|
||||
store_last_sound_played = which;
|
||||
|
||||
if ((load_when_play[which] == true) && (asyn == false))
|
||||
sound_handles[which] = NULL;
|
||||
|
||||
for (i = 0; i < NUM_SOUNDS; i++)
|
||||
if ((load_when_play[which] == true) && (sound_handles[which] != NULL)
|
||||
&& (a_sound_did_get_played == true) && (i != which))
|
||||
{
|
||||
sound_handles[i] = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void one_sound(short which){
|
||||
#ifdef WIN32
|
||||
void kill_sound()
|
||||
{
|
||||
sndPlaySound(NULL,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void one_sound(short which)
|
||||
{
|
||||
if (which == last_played)
|
||||
return;
|
||||
play_sound(which);
|
||||
@@ -200,3 +276,75 @@ void flip_sound()
|
||||
{
|
||||
play_sounds = (play_sounds == true) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
void sound_pause(long len) {
|
||||
long t1,t2;
|
||||
|
||||
t1 = (long) GetCurrentTime();
|
||||
t2 = t1;
|
||||
while (t2 - t1 < len) {
|
||||
t2 = (long)GetCurrentTime();
|
||||
}
|
||||
}
|
||||
|
||||
void load_sounds(HMODULE handle)
|
||||
{
|
||||
short i,t,err;
|
||||
HRSRC h;
|
||||
char snd_name[20];
|
||||
WAVEOUTCAPS wavecaps;
|
||||
|
||||
hModule = handle;
|
||||
|
||||
t = waveOutGetNumDevs();
|
||||
if (t == 0) {
|
||||
sounds_missing = true;
|
||||
return;
|
||||
}
|
||||
err = waveOutGetDevCaps(0,&wavecaps,sizeof(WAVEOUTCAPS));
|
||||
if (err != 0) {
|
||||
sounds_missing = true;
|
||||
switch (err) {
|
||||
case MMSYSERR_BADDEVICEID:
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - No sound device detected. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
case MMSYSERR_NODRIVER:
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - No driver installed. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
case MMSYSERR_NOMEM :
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - can't find enough memory. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
case MMSYSERR_ALLOCATED:
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - sound card already allocated. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
case MMSYSERR_ERROR:
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - internal error. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
default:
|
||||
MessageBox(mainPtr,"Cannot initialize sounds - unidentified error. Game can still be played, but quietly.",
|
||||
"Sound Error",MB_OK | MB_ICONEXCLAMATION);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_SOUNDS; i++) {
|
||||
sound_handles[i] = NULL;
|
||||
if (load_when_play[i] == false) {
|
||||
sprintf((char *)snd_name,"#%d",i + 1);
|
||||
h = FindResource(handle,snd_name,"#100");
|
||||
|
||||
sound_handles[i] = LoadResource(handle,h);
|
||||
snds[i] = (char*) LockResource(sound_handles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -8,13 +8,41 @@
|
||||
|
||||
#ifndef _SOUNDTOOL_H
|
||||
#define _SOUNDTOOL_H
|
||||
#define NUM_SOUNDS 99
|
||||
const int NUM_SOUNDS = 100;
|
||||
|
||||
typedef unsigned short snd_num_t;
|
||||
void init_snd_tool();
|
||||
void play_sound(short which, short how_many_times = 1);
|
||||
void one_sound(short which);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
void clear_sound_memory();
|
||||
void flip_sound();
|
||||
|
||||
extern Handle sound_handles[NUM_SOUNDS];
|
||||
extern SndChannelPtr chan[4];
|
||||
extern char numchannel;
|
||||
extern char channel;
|
||||
extern short snd_played[4];
|
||||
#elif defined(WIN32)
|
||||
#include <windows.h> // for HMODULE
|
||||
void load_sounds (HMODULE handle);
|
||||
void sound_pause(long len);
|
||||
void kill_sound();
|
||||
|
||||
extern short can_ignore[100];
|
||||
extern bool sounds_missing;
|
||||
HGLOBAL sound_handles[NUM_SOUNDS];
|
||||
char* snds[NUM_SOUNDS];
|
||||
#else
|
||||
#error Invalid platform
|
||||
#endif
|
||||
|
||||
extern bool play_sounds;
|
||||
extern short last_played;
|
||||
extern bool always_async[100];
|
||||
extern bool load_when_play[100];
|
||||
extern short sound_delay[100];
|
||||
extern short store_last_sound_played;
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user