Skip to content

Commit

Permalink
Refactor|libcommon: Moved sound sequence savegame io to sn_sonix.cpp
Browse files Browse the repository at this point in the history
Doing this in an external module is not a good idea as it demands
exposing knowledge of the sequence-internal representation/state.
  • Loading branch information
danij-deng committed Jan 25, 2014
1 parent b21270b commit 2717c88
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 151 deletions.
92 changes: 6 additions & 86 deletions doomsday/plugins/common/src/p_saveg.cpp
Expand Up @@ -4737,90 +4737,6 @@ static void readSoundTargets()
#endif
}

static void writeSoundSequences()
{
#if __JHEXEN__
SV_BeginSegment(ASEG_SOUNDS);

SV_WriteLong(ActiveSequences);
for(seqnode_t *node = SequenceListHead; node; node = node->next)
{
SV_WriteByte(1); // Write a version byte.

SV_WriteLong(node->sequence);
SV_WriteLong(node->delayTics);
SV_WriteLong(node->volume);
SV_WriteLong(SN_GetSequenceOffset(node->sequence, node->sequencePtr));
SV_WriteLong(node->currentSoundID);

int i = 0;
if(node->mobj)
{
for(; i < numpolyobjs; ++i)
{
if(node->mobj == (mobj_t *) Polyobj_ById(i))
{
break;
}
}
}

int difference;
if(i == numpolyobjs)
{
// The sound's emitter is the sector, not the polyobj itself.
difference = P_ToIndex(Sector_AtPoint_FixedPrecision(node->mobj->origin));
SV_WriteLong(0); // 0 -- sector sound origin.
}
else
{
SV_WriteLong(1); // 1 -- polyobj sound origin
difference = i;
}

SV_WriteLong(difference);
}
#endif
}

static void readSoundSequences()
{
#if __JHEXEN__
SV_AssertSegment(ASEG_SOUNDS);

// Reload and restart all sound sequences
int numSequences = SV_ReadLong();

for(int i = 0; i < numSequences; ++i)
{
/*int ver =*/ (mapVersion >= 3)? SV_ReadByte() : 0;

int sequence = SV_ReadLong();
int delayTics = SV_ReadLong();
int volume = SV_ReadLong();
int seqOffset = SV_ReadLong();

int soundID = SV_ReadLong();
int polySnd = SV_ReadLong();
int secNum = SV_ReadLong();

mobj_t *sndMobj = 0;
if(!polySnd)
{
sndMobj = (mobj_t*)P_GetPtr(DMU_SECTOR, secNum, DMU_EMITTER);
}
else
{
Polyobj *po = Polyobj_ById(secNum);
if(po) sndMobj = (mobj_t*) po;
}

SN_StartSequence(sndMobj, sequence);
SN_ChangeNodeData(i, seqOffset, delayTics, volume, soundID);
}
#endif
}

static void writeScripts()
{
#if __JHEXEN__
Expand Down Expand Up @@ -4996,7 +4912,9 @@ static void writeMap()
writeMapElements();
writeThinkers();
writeScripts();
writeSoundSequences();
#if __JHEXEN__
SN_WriteSequences();
#endif
writeMisc();
writeBrain();
writeSoundTargets();
Expand Down Expand Up @@ -5031,7 +4949,9 @@ static void readMap()
readMapElements();
readThinkers();
readScripts();
readSoundSequences();
#if __JHEXEN__
SN_ReadSequences(mapVersion);
#endif
readMisc();
readBrain();
readSoundTargets();
Expand Down
19 changes: 4 additions & 15 deletions doomsday/plugins/hexen/include/s_sequence.h
Expand Up @@ -67,21 +67,6 @@ typedef enum {
SEQTYPE_NUMSEQ
} seqtype_t;

typedef struct seqnode_s {
int* sequencePtr;
int sequence;
mobj_t* mobj;
int currentSoundID;
int delayTics;
int volume;
int stopSound;
struct seqnode_s* prev;
struct seqnode_s* next;
} seqnode_t;

DENG_EXTERN_C int ActiveSequences;
DENG_EXTERN_C seqnode_t* SequenceListHead;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -91,6 +76,7 @@ extern "C" {
*/
void SndSeqParser(Str const *path);

int SN_ActiveSequenceCount(void);
void SN_StartSequence(mobj_t *mobj, int sequence);
void SN_StartSequenceInSec(Sector *sector, int seqBase);
void SN_StartSequenceName(mobj_t *mobj, char const *name);
Expand All @@ -105,6 +91,9 @@ int SN_GetSequenceOffset(int sequence, int *sequencePtr);
*/
void SN_ChangeNodeData(int nodeNum, int seqOffset, int delayTics, int volume, int currentSoundID);

void SN_WriteSequences();
void SN_ReadSequences(int mapVersion);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/hexen/src/p_mapinfo.cpp
Expand Up @@ -48,7 +48,7 @@ static void setMusicCDTrack(char const *musicId, int track)

void MapInfoParser(Str const *path)
{
memset(&MapInfo, 0, sizeof(MapInfo));
std::memset(&MapInfo, 0, sizeof(MapInfo));

// Configure the defaults
mapinfo_t defMapInfo;
Expand Down

0 comments on commit 2717c88

Please sign in to comment.