more semi-tested multiplayer changes and sound callback fix

git-svn-id: https://svn.eduke32.com/eduke32@1582 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-01-05 21:53:14 +00:00
parent f543a69ab8
commit 4917be2439
5 changed files with 473 additions and 465 deletions

View file

@ -25,8 +25,8 @@
// 1.5.0 BETA 2
#ifndef QLZ_COMPRESSION_LEVEL
#define QLZ_COMPRESSION_LEVEL 1
//#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 1
#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 3
#define QLZ_STREAMING_BUFFER 0

View file

@ -280,12 +280,12 @@ typedef struct {
int16_t i;
} SOUNDOWNER;
#define SOUNDMAX 8
#define MAXSOUNDINSTANCES 8
typedef struct {
int32_t length, num, soundsiz; // 12b
char *filename, *ptr, *filename1; // 12b/24b
SOUNDOWNER SoundOwner[SOUNDMAX]; // 32b
SOUNDOWNER SoundOwner[MAXSOUNDINSTANCES]; // 32b
int16_t ps,pe,vo; // 6b
char pr,m; // 2b
} sound_t;
@ -535,17 +535,6 @@ typedef struct {
int8_t velmult, filler; // 2b
} projectile_t;
// extern char gotz;
typedef struct {
/* int32_t x;
int32_t y;
int32_t z; */
int16_t ang, oldang, angdir, angdif;
} spriteinterpolate;
// spriteinterpolate sprpos[MAXSPRITES];
typedef struct {
intptr_t temp_data[10]; // 40b/80b sometimes used to hold pointers to con code

View file

@ -968,8 +968,8 @@ void Net_ParseServerPacket(ENetEvent * event)
packbuf = Bcalloc(1, packbufleng+1);
packbufleng = qlz_decompress((char *)&event->packet->data[1], (char *)(packbuf), state_decompress);
Bmemcpy(&ticrandomseed, &packbuf[j], sizeof(ticrandomseed));
j += sizeof(ticrandomseed);
ticrandomseed = *(int32_t *)&packbuf[j];
j += sizeof(int32_t);
ud.pause_on = packbuf[j++];
TRAVERSE_CONNECT(i)
@ -982,7 +982,7 @@ void Net_ParseServerPacket(ENetEvent * event)
if (i == myconnectindex && !g_player[i].ps->dead_flag)
{
j += (sizeof(input_t) - sizeof(loc.filler)) +
(sizeof(vec3_t) * 2) + // position and velocity
(sizeof(vec3_t) * 3) + // position and velocity
(sizeof(int16_t) * 3); // ang and horiz
goto process;
}
@ -996,23 +996,22 @@ void Net_ParseServerPacket(ENetEvent * event)
if (TEST_SYNC_KEY(nsyn[i].bits,SK_GAMEQUIT)) g_player[i].playerquitflag = 0;
g_player[i].movefifoend++;
Bmemcpy(&g_player[i].ps->oposx, &g_player[i].ps->posx, sizeof(vec3_t));
// Bmemcpy(&g_player[i].ps->oposx, &g_player[i].ps->posx, sizeof(vec3_t));
Bmemcpy(&g_player[i].ps->posx, &packbuf[j], sizeof(vec3_t));
Bmemcpy(&g_player[i].ps->posx, &packbuf[j], sizeof(vec3_t) * 2);
updatesectorz(g_player[i].ps->posx, g_player[i].ps->posy, g_player[i].ps->posz,
&g_player[i].ps->cursectnum);
changespritesect(g_player[i].ps->i, g_player[i].ps->cursectnum);
Bmemcpy(&sprite[g_player[i].ps->i], &packbuf[j], sizeof(vec3_t));
sprite[g_player[i].ps->i].z += PHEIGHT;
j += sizeof(vec3_t);
j += sizeof(vec3_t) * 2;
Bmemcpy(&g_player[i].ps->posxv, &packbuf[j], sizeof(vec3_t));
j += sizeof(vec3_t);
Bmemcpy(&g_player[i].ps->oang, &g_player[i].ps->ang, sizeof(int16_t));
Bmemcpy(&g_player[i].ps->ang, &packbuf[j], sizeof(int16_t));
sprite[g_player[i].ps->i].ang = *(int16_t *)&packbuf[j];
g_player[i].ps->oang = g_player[i].ps->ang;
g_player[i].ps->ang = sprite[g_player[i].ps->i].ang = *(int16_t *)&packbuf[j];
j += sizeof(int16_t);
Bmemcpy(&g_player[i].ps->ohoriz, &g_player[i].ps->horiz, sizeof(int16_t) * 2);
@ -1505,14 +1504,14 @@ void Net_ParseClientPacket(ENetEvent * event)
break;
}
Bmemcpy(&g_player[other].ps->oposx, &g_player[other].ps->posx, sizeof(vec3_t));
Bmemcpy(&g_player[other].ps->posx, &packbuf[j], sizeof(vec3_t));
// Bmemcpy(&g_player[other].ps->oposx, &g_player[other].ps->posx, sizeof(vec3_t));
Bmemcpy(&g_player[other].ps->posx, &packbuf[j], sizeof(vec3_t) * 2);
updatesectorz(g_player[other].ps->posx, g_player[other].ps->posy, g_player[other].ps->posz,
&g_player[other].ps->cursectnum);
Bmemcpy(&sprite[g_player[other].ps->i], &packbuf[j], sizeof(vec3_t));
sprite[g_player[other].ps->i].z += PHEIGHT;
changespritesect(g_player[other].ps->i, g_player[other].ps->cursectnum);
j += sizeof(vec3_t);
j += sizeof(vec3_t) * 2;
Bmemcpy(&g_player[other].ps->posxv, &packbuf[j], sizeof(vec3_t));
j += sizeof(vec3_t);
@ -1839,12 +1838,12 @@ void Net_GetPackets(void)
switch (event.type)
{
case ENET_EVENT_TYPE_RECEIVE:
/*
initprintf ("A packet of length %u was received from player %d on channel %u.\n",
event.packet -> dataLength,
event.peer -> data,
event.channelID);
*/
// channelID 1 is the map state transfer from the server
if (event.channelID == 1)
{
@ -1899,6 +1898,9 @@ void Net_GetPackets(void)
break;
case ENET_EVENT_TYPE_DISCONNECT:
g_netDisconnect = 1;
numplayers = playerswhenstarted = ud.multimode = 1;
myconnectindex = screenpeek = 0;
G_BackToMenu();
switch (event.data)
{
case DISC_BAD_PASSWORD:
@ -1921,126 +1923,28 @@ void Net_GetPackets(void)
}
}
void faketimerhandler(void)
void Net_UpdateClients(void)
{
int32_t i, j;
// short who;
input_t *nsyn;
input_t * osyn = (input_t *)&inputfifo[1][0];
input_t * nsyn = (input_t *)&inputfifo[0][0];
int16_t i, nexti, k = 0, l;
int32_t j;
if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
if (!net_server || numplayers < 2)
{
qe = 1;
G_GameExit("Quick Exit.");
}
sampletimer();
MUSIC_Update();
if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return;
ototalclock += TICSPERFRAME;
Net_GetPackets();
getinput(myconnectindex);
avgfvel += loc.fvel;
avgsvel += loc.svel;
avgavel += loc.avel;
avghorz += loc.horz;
avgbits |= loc.bits;
avgextbits |= loc.extbits;
nsyn = &inputfifo[0][myconnectindex];
nsyn[0].fvel = avgfvel;
nsyn[0].svel = avgsvel;
nsyn[0].avel = avgavel;
nsyn[0].horz = avghorz;
nsyn[0].bits = avgbits;
nsyn[0].extbits = avgextbits;
avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
g_player[myconnectindex].movefifoend++;
if (numplayers < 2)
{
if ((net_server || ud.multimode > 1) && ud.playerai)
TRAVERSE_CONNECT(i)
if (i != myconnectindex)
{
//clearbufbyte(&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input_t),0L);
computergetinput(i,&inputfifo[0][i]);
}
}
if (net_client) //Slave
{
int32_t jj = 0;
packbuf[0] = PACKET_SLAVE_TO_MASTER;
j = 1;
nsyn = (input_t *)&inputfifo[0][myconnectindex];
Bmemcpy(&packbuf[j], &nsyn[0], sizeof(input_t));
j += sizeof(input_t)-sizeof(loc.filler);
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->posx, sizeof(vec3_t));
j += sizeof(vec3_t);
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->posxv, sizeof(vec3_t));
j += sizeof(vec3_t);
*(int16_t *)&packbuf[j] = g_player[myconnectindex].ps->ang;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->horiz, sizeof(int16_t) * 2);
j += sizeof(int16_t) * 2;
i = g_player[myconnectindex].ps->i;
packbuf[(jj = j++)] = 0;
if (T5 >= (intptr_t)&script[0] && T5 < (intptr_t)(&script[g_scriptSize]))
{
packbuf[jj] |= 2;
T5 -= (intptr_t)&script[0];
}
Bmemcpy(&packbuf[j], &T5, sizeof(T5));
j += sizeof(T5);
if (packbuf[jj] & 2) T5 += (intptr_t)&script[0];
{
char buf[1024];
j = qlz_compress((char *)(packbuf)+1, (char *)buf, j, state_compress);
Bmemcpy((char *)(packbuf)+1, (char *)buf, j);
j++;
}
packbuf[j++] = myconnectindex;
enet_peer_send(net_peer, 1, enet_packet_create(packbuf, j, 0));
movefifosendplc++;
if (net_server)
Bmemcpy(&osyn[0], &nsyn[0], sizeof(input_t));
return;
}
if (net_server)
{
input_t * osyn = (input_t *)&inputfifo[1][0];
int16_t i, nexti, k = 0, l;
//MASTER -> SLAVE packet
packbuf[0] = PACKET_MASTER_TO_SLAVE;
j = 1;
ticrandomseed = randomseed;
Bmemcpy(&packbuf[j], &ticrandomseed, sizeof(ticrandomseed));
j += sizeof(ticrandomseed);
*(int32_t *)&packbuf[j] = ticrandomseed;
j += sizeof(int32_t);
packbuf[j++] = ud.pause_on;
nsyn = (input_t *)&inputfifo[0][0];
TRAVERSE_CONNECT(i)
{
if (g_player[i].playerquitflag == 0) continue;
@ -2053,8 +1957,8 @@ void faketimerhandler(void)
Bmemcpy(&packbuf[j], &nsyn[i], sizeof(input_t)-sizeof(loc.filler));
j += sizeof(input_t)-sizeof(loc.filler);
Bmemcpy(&packbuf[j], &g_player[i].ps->posx, sizeof(vec3_t));
j += sizeof(vec3_t);
Bmemcpy(&packbuf[j], &g_player[i].ps->posx, sizeof(vec3_t) * 2);
j += sizeof(vec3_t) * 2;
Bmemcpy(&packbuf[j], &g_player[i].ps->posxv, sizeof(vec3_t));
j += sizeof(vec3_t);
@ -2148,17 +2052,16 @@ void faketimerhandler(void)
{
peractorvals[ii][i] = aGameVars[ii].val.plValues[i];
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = ii;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &aGameVars[ii].val.plValues[i], sizeof(int32_t));
*(int32_t *)&packbuf[j] = aGameVars[ii].val.plValues[i];
j += sizeof(int32_t);
kk++;
}
}
if (kk > 64) break;
}
ii = MAXGAMEVARS;
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = MAXGAMEVARS;
j += sizeof(int16_t);
}
i = l;
@ -2174,17 +2077,16 @@ void faketimerhandler(void)
{
perplayervals[ii][i] = aGameVars[ii].val.plValues[i];
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = ii;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &aGameVars[ii].val.plValues[i], sizeof(int32_t));
*(int32_t *)&packbuf[j] = aGameVars[ii].val.plValues[i];
j += sizeof(int32_t);
kk++;
}
}
if (kk > 64) break;
}
ii = MAXGAMEVARS;
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = MAXGAMEVARS;
j += sizeof(int16_t);
}
}
@ -2199,7 +2101,7 @@ void faketimerhandler(void)
for (zz = 0; (unsigned)zz < (sizeof(net_lists)/sizeof(net_lists[0])); zz++)
TRAVERSE_SPRITE_STAT(headspritestat[net_lists[zz]], i, nexti)
{
if (totalclock > (lastupdate[i] + (TICSPERFRAME * 6)))
if (totalclock > (lastupdate[i] + TICRATE))
{
l = crc32once((uint8_t *)&sprite[i], sizeof(spritetype));
@ -2210,7 +2112,7 @@ void faketimerhandler(void)
/*initprintf("updating sprite %d (%d)\n",i,sprite[i].picnum);*/
spritecrc[i] = l;
lastupdate[i] = totalclock;
Bmemcpy(&packbuf[j], &i, sizeof(int16_t));
*(int16_t *)&packbuf[j] = i;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &sprite[i], sizeof(spritetype));
j += sizeof(spritetype);
@ -2250,24 +2152,23 @@ void faketimerhandler(void)
{
peractorvals[ii][i] = aGameVars[ii].val.plValues[i];
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = ii;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &aGameVars[ii].val.plValues[i], sizeof(int32_t));
*(int32_t *)&packbuf[j] = aGameVars[ii].val.plValues[i];
j += sizeof(int32_t);
kk++;
}
}
if (kk > 64) break;
}
ii = MAXGAMEVARS;
Bmemcpy(&packbuf[j], &ii, sizeof(int16_t));
*(int16_t *)&packbuf[j] = MAXGAMEVARS;
j += sizeof(int16_t);
}
k++;
}
}
if (k > 4) break;
if (k > 8) break;
}
packbuf[zj] = k;
k = 0;
@ -2275,7 +2176,7 @@ void faketimerhandler(void)
packbuf[(zj = j++)] = 0;
for (i = numsectors-1; i >= 0; i--)
{
if (totalclock > (lastsectupdate[i] + (TICSPERFRAME * 12)))
if (totalclock > (lastsectupdate[i] + TICRATE))
{
l = crc32once((uint8_t *)&sector[i], sizeof(sectortype));
@ -2283,7 +2184,7 @@ void faketimerhandler(void)
{
sectcrc[i] = l;
lastsectupdate[i] = totalclock;
Bmemcpy(&packbuf[j], &i, sizeof(int16_t));
*(int16_t *)&packbuf[j] = i;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &sector[i], sizeof(sectortype));
j += sizeof(sectortype);
@ -2298,7 +2199,7 @@ void faketimerhandler(void)
packbuf[(zj = j++)] = 0;
for (i = numwalls-1; i >= 0; i--)
{
if (totalclock > (lastwallupdate[i] + (TICSPERFRAME * 12)))
if (totalclock > (lastwallupdate[i] + TICRATE))
{
l = crc32once((uint8_t *)&wall[i], sizeof(walltype));
@ -2306,7 +2207,7 @@ void faketimerhandler(void)
{
wallcrc[i] = l;
lastwallupdate[i] = totalclock;
Bmemcpy(&packbuf[j], &i, sizeof(int16_t));
*(int16_t *)&packbuf[j] = i;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &wall[i], sizeof(walltype));
j += sizeof(walltype);
@ -2332,6 +2233,55 @@ void faketimerhandler(void)
enet_host_broadcast(net_server, 0, enet_packet_create(packbuf, j, 0));
movefifosendplc++;
}
void faketimerhandler(void)
{
int32_t i;
input_t *nsyn;
if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
{
qe = 1;
G_GameExit("Quick Exit.");
}
sampletimer();
MUSIC_Update();
if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return;
ototalclock += TICSPERFRAME;
Net_GetPackets();
getinput(myconnectindex);
avgfvel += loc.fvel;
avgsvel += loc.svel;
avgavel += loc.avel;
avghorz += loc.horz;
avgbits |= loc.bits;
avgextbits |= loc.extbits;
nsyn = &inputfifo[0][myconnectindex];
nsyn[0].fvel = avgfvel;
nsyn[0].svel = avgsvel;
nsyn[0].avel = avgavel;
nsyn[0].horz = avghorz;
nsyn[0].bits = avgbits;
nsyn[0].extbits = avgextbits;
avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
g_player[myconnectindex].movefifoend++;
if (numplayers < 2)
{
if ((net_server || ud.multimode > 1) && ud.playerai)
TRAVERSE_CONNECT(i)
if (i != myconnectindex)
{
//clearbufbyte(&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input_t),0L);
computergetinput(i,&inputfifo[0][i]);
}
}
}
@ -12656,6 +12606,60 @@ static int32_t G_DoMoveThings(void)
{
G_AnimateWalls();
A_MoveCyclers();
Net_UpdateClients();
}
if (net_client) //Slave
{
int32_t jj = 0;
input_t *nsyn = (input_t *)&inputfifo[0][myconnectindex];
packbuf[0] = PACKET_SLAVE_TO_MASTER;
j = 1;
Bmemcpy(&packbuf[j], &nsyn[0], sizeof(input_t) - sizeof(loc.filler));
j += sizeof(input_t) - sizeof(loc.filler);
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->posx, sizeof(vec3_t) * 2);
j += sizeof(vec3_t) * 2;
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->posxv, sizeof(vec3_t));
j += sizeof(vec3_t);
*(int16_t *)&packbuf[j] = g_player[myconnectindex].ps->ang;
j += sizeof(int16_t);
Bmemcpy(&packbuf[j], &g_player[myconnectindex].ps->horiz, sizeof(int16_t) * 2);
j += sizeof(int16_t) * 2;
i = g_player[myconnectindex].ps->i;
packbuf[(jj = j++)] = 0;
if (T5 >= (intptr_t)&script[0] && T5 < (intptr_t)(&script[g_scriptSize]))
{
packbuf[jj] |= 2;
T5 -= (intptr_t)&script[0];
}
Bmemcpy(&packbuf[j], &T5, sizeof(T5));
j += sizeof(T5);
if (packbuf[jj] & 2) T5 += (intptr_t)&script[0];
{
char buf[1024];
j = qlz_compress((char *)(packbuf)+1, (char *)buf, j, state_compress);
Bmemcpy((char *)(packbuf)+1, (char *)buf, j);
j++;
}
packbuf[j++] = myconnectindex;
enet_peer_send(net_peer, 1, enet_packet_create(packbuf, j, 0));
movefifosendplc++;
}
return 0;

View file

@ -794,6 +794,8 @@ void P_ResetStatus(int32_t snum)
p->movement_lock = 0;
p->frag_ps = snum;
P_UpdateScreenPal(p);
X_OnEvent(EVENT_RESETPLAYER, p->i, snum, -1);
}

View file

@ -416,6 +416,7 @@ int32_t S_LoadSound(uint32_t num)
allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_soundlocks[num]);
kread(fp, g_sounds[num].ptr , l);
kclose(fp);
return 1;
}
@ -432,7 +433,7 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
ud.config.FXDevice < 0 ||
((g_sounds[num].m&8) && ud.lockout) ||
ud.config.SoundToggle == 0 ||
g_sounds[num].num >= SOUNDMAX ||
g_sounds[num].num >= MAXSOUNDINSTANCES ||
FX_VoiceAvailable(g_sounds[num].pr) == 0 ||
(g_player[myconnectindex].ps->timebeforeexit > 0 && g_player[myconnectindex].ps->timebeforeexit <= GAMETICSPERSEC*3) ||
g_player[myconnectindex].ps->gm&MODE_MENU) return -1;
@ -441,10 +442,15 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
{
voice = S_PlaySound(num);
if (voice >= FX_Ok && g_sounds[num].num < SOUNDMAX && i >= 0 && i < MAXSPRITES)
if (voice >= FX_Ok && g_sounds[num].num < MAXSOUNDINSTANCES && i >= 0 && i < MAXSPRITES)
{
g_sounds[num].SoundOwner[g_sounds[num].num].i = i;
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
int32_t l = 0;
while (l < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[l].voice > 0)
l++;
g_sounds[num].SoundOwner[l].i = i;
g_sounds[num].SoundOwner[l].voice = voice;
g_sounds[num].num++;
}
@ -461,7 +467,7 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
else if (!(ud.config.VoiceToggle&1))
return -1;
for (j=g_maxSoundPos; j>=0; j--)
for (k=0; k<g_sounds[j].num; k++)
for (k=0; k<MAXSOUNDINSTANCES; k++)
if ((g_sounds[j].num > 0) && (g_sounds[j].m&4))
return -1;
}
@ -550,25 +556,33 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
if (sndist < ((255-LOUDESTVOLUME)<<6))
sndist = ((255-LOUDESTVOLUME)<<6);
{
int32_t l = 0;
while (l < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[l].voice > 0)
l++;
if (g_sounds[num].m&1)
{
if (g_sounds[num].num > 0) return -1;
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,(num * MAXSOUNDINSTANCES) + l);
}
else
{
voice = FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,sndang>>4,sndist>>6, g_sounds[num].pr, num);
voice = FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,sndang>>4,sndist>>6, g_sounds[num].pr,
(num * MAXSOUNDINSTANCES) + l);
}
if (voice >= FX_Ok)
{
g_sounds[num].SoundOwner[g_sounds[num].num].i = i;
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
g_sounds[num].SoundOwner[l].i = i;
g_sounds[num].SoundOwner[l].voice = voice;
g_sounds[num].num++;
}
else g_soundlocks[num]--;
}
return (voice);
}
@ -614,11 +628,11 @@ int32_t S_PlaySound(int32_t num)
if (g_sounds[num].m&1)
{
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz,num);
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz,num * MAXSOUNDINSTANCES);
}
else
{
voice = FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
voice = FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num * MAXSOUNDINSTANCES);
}
if (voice >= FX_Ok) return voice;
@ -645,11 +659,15 @@ void S_StopSound(int32_t num)
{
if (g_sounds[num].num > 0)
{
int32_t j=g_sounds[num].num-1;
int32_t j=MAXSOUNDINSTANCES-1;
for (; j>=0; j--)
{
if (g_sounds[num].SoundOwner[j].voice)
{
FX_StopSound(g_sounds[num].SoundOwner[j].voice);
g_sounds[num].SoundOwner[j].voice = 0;
}
// S_TestSoundCallback(num);
}
}
@ -662,13 +680,17 @@ void S_StopEnvSound(int32_t num,int32_t i)
{
if (g_sounds[num].num > 0)
{
int32_t j=g_sounds[num].num-1;
int32_t j=MAXSOUNDINSTANCES-1;
for (; j>=0; j--)
{
if (g_sounds[num].SoundOwner[j].i == i)
{
if (g_sounds[num].SoundOwner[j].voice)
{
FX_StopSound(g_sounds[num].SoundOwner[j].voice);
g_sounds[num].SoundOwner[j].voice = 0;
}
// S_TestSoundCallback(num);
}
}
@ -701,13 +723,13 @@ void S_Pan3D(void)
do
{
for (k=g_sounds[j].num-1; k>=0; k--)
for (k=MAXSOUNDINSTANCES-1; k>=0; k--)
{
i = g_sounds[j].SoundOwner[k].i;
if (i < 0 || i >= MAXSPRITES)
if (i < 0 || i >= MAXSPRITES || g_sounds[j].SoundOwner[k].voice < 1)
{
OSD_Printf(OSD_ERROR "S_Pan3D(): INTERNAL ERROR: invalid id %d!\n",i);
// OSD_Printf(OSD_ERROR "S_Pan3D(): INTERNAL ERROR: invalid id %d!\n",i);
k--;
continue;
}
@ -768,44 +790,35 @@ void S_Pan3D(void)
void S_TestSoundCallback(uint32_t num)
{
int32_t tempi,tempj,tempk;
if ((int32_t) num == MUSIC_ID)
{
if ((int32_t)num == MUSIC_ID)
return;
}
if((int32_t)num < 0)
// negative index is RTS playback
if ((int32_t)num < 0)
{
if(lumplockbyte[-(int32_t)num] >= 200)
if (lumplockbyte[-(int32_t)num] >= 200)
lumplockbyte[-(int32_t)num]--;
return;
}
tempk = g_sounds[num].num;
{
int32_t j = num & (MAXSOUNDINSTANCES-1);
num = (num - j) / MAXSOUNDINSTANCES;
if (tempk > 0)
if (g_sounds[num].num > 0)
{
if ((g_sounds[num].m&16) == 0)
for (tempj=0; tempj<tempk; tempj++)
{
tempi = g_sounds[num].SoundOwner[tempj].i;
if (sprite[tempi].picnum == MUSICANDSFX && sector[sprite[tempi].sectnum].lotag < 3 && sprite[tempi].lotag < 999)
{
ActorExtra[tempi].temp_data[0] = 0;
if ((tempj + 1) < tempk)
{
g_sounds[num].SoundOwner[tempj].voice = g_sounds[num].SoundOwner[tempk-1].voice;
g_sounds[num].SoundOwner[tempj].i = g_sounds[num].SoundOwner[tempk-1].i;
}
break;
}
}
int32_t i = g_sounds[num].SoundOwner[j].i;
// OSD_Printf("removing sound %d index %d from spr %d\n",num,j,i);
if (sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
ActorExtra[i].temp_data[0] = 0;
g_sounds[num].SoundOwner[j].i = -1;
g_sounds[num].SoundOwner[j].voice = 0;
g_sounds[num].num--;
g_sounds[num].SoundOwner[tempk-1].i = -1;
}
}
g_soundlocks[num]--;
}
@ -831,7 +844,7 @@ int32_t A_CheckSoundPlaying(int32_t i, int32_t num)
if (g_sounds[num].num > 0)
{
for (j=g_sounds[num].num-1; j>=0; j--)
for (j=MAXSOUNDINSTANCES-1; j>=0; j--)
if (g_sounds[num].SoundOwner[j].i == i)
{
return 1;