From b5dc5ceb3c7656a762bf92650b04d06472065ee2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Apr 2017 14:48:33 +0200 Subject: [PATCH 1/5] - removed some unused static variables --- src/c_console.cpp | 1 - src/c_consolebuffer.cpp | 1 - src/gl/compatibility/gl_20.cpp | 2 -- src/gl/scene/gl_flats.cpp | 2 +- src/gl/scene/gl_portal.cpp | 2 -- src/p_acs.cpp | 1 - src/zstrformat.cpp | 1 - 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/c_console.cpp b/src/c_console.cpp index ff3f86b20c..12be598180 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -1809,7 +1809,6 @@ static const char bar2[] = TEXTCOLOR_RED "\n\35\36\36\36\36\36\36\36\36\36\36\36 "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_GREEN "\n"; static const char bar3[] = TEXTCOLOR_RED "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; -static const char logbar[] = "\n<------------------------------->\n"; void C_MidPrint (FFont *font, const char *msg) { diff --git a/src/c_consolebuffer.cpp b/src/c_consolebuffer.cpp index 3f64f34e4b..0b501a7748 100644 --- a/src/c_consolebuffer.cpp +++ b/src/c_consolebuffer.cpp @@ -239,7 +239,6 @@ static const char bar2[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\3 "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_GREEN "\n"; static const char bar3[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; -static const char logbar[] = "\n<------------------------------->\n"; void FConsoleBuffer::AddMidText(const char *string, bool bold, FILE *Logfile) { diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index c8b561bc68..d29823b759 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -130,8 +130,6 @@ void gl_PatchMenu() void gl_SetTextureMode(int type) { - static float white[] = {1.f,1.f,1.f,1.f}; - if (type == TM_MASK) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 0d14378af1..c7ab0eeb28 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -66,7 +66,7 @@ CVAR(Int, gl_breaksec, -1, 0) // information // //========================================================================== -static float tics; + void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture) { // only manipulate the texture matrix if needed. diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 38ce807993..468ecefc26 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -310,8 +310,6 @@ inline void GLPortal::ClearClipper() drawer->clipper.Clear(); - static int call=0; - // Set the clipper to the minimal visible area drawer->clipper.SafeAddClipRange(0,0xffffffff); for (unsigned int i = 0; i < lines.Size(); i++) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 5af056e3e5..8565bc42ab 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -8869,7 +8869,6 @@ scriptwait: { static const char bar[] = TEXTCOLOR_ORANGE "\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36" "\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n"; - static const char logbar[] = "\n<------------------------------->\n"; char consolecolor[3]; consolecolor[0] = '\x1c'; diff --git a/src/zstrformat.cpp b/src/zstrformat.cpp index 65ed889aec..05b31e59a4 100644 --- a/src/zstrformat.cpp +++ b/src/zstrformat.cpp @@ -113,7 +113,6 @@ static const char hexits[16] = {'0','1','2','3','4','5','6','7','8','9','a','b', static const char HEXits[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; static const char spaces[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; static const char zeroes[17] = {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','.'}; -static const char dotchar = '.'; namespace StringFormat { From 21af612224a2a16f50a3b186c5dfb0e50f0818f8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Apr 2017 20:51:06 +0200 Subject: [PATCH 2/5] - avoid double loading sound data for monoization. --- src/s_sound.cpp | 92 ++++++++++++++------------ src/s_sound.h | 4 +- src/sound/i_sound.cpp | 14 ++-- src/sound/i_sound.h | 13 +++- src/sound/i_soundinternal.h | 2 +- src/sound/oalsound.cpp | 117 ++++++++++++++++++++++++++++++---- src/sound/oalsound.h | 3 +- src/sound/sndfile_decoder.cpp | 6 +- src/sound/sndfile_decoder.h | 2 +- 9 files changed, 189 insertions(+), 64 deletions(-) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index ccf5f554a3..7f1d9dfb96 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -126,7 +126,7 @@ extern float S_GetMusicVolume (const char *music); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static void S_LoadSound3D(sfxinfo_t *sfx); +static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer); static bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range, AActor *actor, int channel); static bool S_IsChannelUsed(AActor *actor, int channel, int *seen); static void S_ActivatePlayList(bool goBack); @@ -577,7 +577,10 @@ void S_CacheSound (sfxinfo_t *sfx) } else { - S_LoadSound(sfx); + // Since we do not know in what format the sound will be used, we have to cache both. + FSoundLoadBuffer SoundBuffer; + S_LoadSound(sfx, &SoundBuffer); + S_LoadSound3D(sfx, &SoundBuffer); sfx->bUsed = true; } } @@ -906,6 +909,7 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO FSoundChan *chan; FVector3 pos, vel; FRolloffInfo *rolloff; + FSoundLoadBuffer SoundBuffer; if (sound_id <= 0 || volume <= 0 || nosfx || nosound ) return NULL; @@ -1050,7 +1054,7 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO } // Make sure the sound is loaded. - sfx = S_LoadSound(sfx); + sfx = S_LoadSound(sfx, &SoundBuffer); // The empty sound never plays. if (sfx->lumpnum == sfx_empty) @@ -1150,7 +1154,7 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO if (attenuation > 0) { - S_LoadSound3D(sfx); + S_LoadSound3D(sfx, &SoundBuffer); SoundListener listener; S_SetListener(listener, players[consoleplayer].camera); chan = (FSoundChan*)GSnd->StartSound3D (sfx->data3d, &listener, float(volume), rolloff, float(attenuation), pitch, basepriority, pos, vel, channel, startflags, NULL); @@ -1213,12 +1217,13 @@ void S_RestartSound(FSoundChan *chan) FSoundChan *ochan; sfxinfo_t *sfx = &S_sfx[chan->SoundID]; + FSoundLoadBuffer SoundBuffer; // If this is a singular sound, don't play it if it's already playing. if (sfx->bSingular && S_CheckSingular(chan->SoundID)) return; - sfx = S_LoadSound(sfx); + sfx = S_LoadSound(sfx, &SoundBuffer); // The empty sound never plays. if (sfx->lumpnum == sfx_empty) @@ -1247,7 +1252,7 @@ void S_RestartSound(FSoundChan *chan) return; } - S_LoadSound3D(sfx); + S_LoadSound3D(sfx, &SoundBuffer); SoundListener listener; S_SetListener(listener, players[consoleplayer].camera); @@ -1392,7 +1397,7 @@ void S_PlaySound(AActor *a, int chan, FSoundID sid, float vol, float atten, bool // //========================================================================== -sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) +sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) { if (GSnd->IsNull()) return sfx; @@ -1452,7 +1457,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) // If that fails, let the sound system try and figure it out. else { - snd = GSnd->LoadSound(sfxdata, size); + snd = GSnd->LoadSound(sfxdata, size, false, pBuffer); } delete[] sfxdata; @@ -1474,7 +1479,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) return sfx; } -static void S_LoadSound3D(sfxinfo_t *sfx) +static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) { if (GSnd->IsNull()) return; @@ -1483,40 +1488,47 @@ static void S_LoadSound3D(sfxinfo_t *sfx) DPrintf(DMSG_NOTIFY, "Loading monoized sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]); - int size = Wads.LumpLength(sfx->lumpnum); - if(size <= 0) return; + if (pBuffer->mBuffer.Size() > 0) + { + GSnd->LoadSoundBuffered(pBuffer, true); + } + else + { + int size = Wads.LumpLength(sfx->lumpnum); + if (size <= 0) return; - FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); - uint8_t *sfxdata = new uint8_t[size]; - wlump.Read(sfxdata, size); - int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); - std::pair snd; + FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); + uint8_t *sfxdata = new uint8_t[size]; + wlump.Read(sfxdata, size); + int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); + std::pair snd; - // If the sound is voc, use the custom loader. - if (strncmp ((const char *)sfxdata, "Creative Voice File", 19) == 0) - { - snd = GSnd->LoadSoundVoc(sfxdata, size, true); - } - // If the sound is raw, just load it as such. - else if (sfx->bLoadRAW) - { - snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart, true); - } - // Otherwise, try the sound as DMX format. - else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8) - { - int frequency = LittleShort(((uint16_t *)sfxdata)[1]); - if (frequency == 0) frequency = 11025; - snd = GSnd->LoadSoundRaw(sfxdata+8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true); - } - // If that fails, let the sound system try and figure it out. - else - { - snd = GSnd->LoadSound(sfxdata, size, true); - } - delete[] sfxdata; + // If the sound is voc, use the custom loader. + if (strncmp((const char *)sfxdata, "Creative Voice File", 19) == 0) + { + snd = GSnd->LoadSoundVoc(sfxdata, size, true); + } + // If the sound is raw, just load it as such. + else if (sfx->bLoadRAW) + { + snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart, true); + } + // Otherwise, try the sound as DMX format. + else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8) + { + int frequency = LittleShort(((uint16_t *)sfxdata)[1]); + if (frequency == 0) frequency = 11025; + snd = GSnd->LoadSoundRaw(sfxdata + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true); + } + // If that fails, let the sound system try and figure it out. + else + { + snd = GSnd->LoadSound(sfxdata, size, true, pBuffer); + } + delete[] sfxdata; - sfx->data3d = snd.first; + sfx->data3d = snd.first; + } } //========================================================================== diff --git a/src/s_sound.h b/src/s_sound.h index 4d67c05147..3a64ba76f3 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -212,6 +212,7 @@ struct FSoundChan : public FISoundChannel float Point[3]; // Sound is not attached to any source. }; }; + extern FSoundChan *Channels; void S_ReturnChannel(FSoundChan *chan); @@ -299,6 +300,7 @@ void S_PlaySound(AActor *a, int chan, FSoundID sid, float vol, float atten, bool #define ATTN_IDLE 1.001f #define ATTN_STATIC 3.f // diminish very rapidly with distance +struct FSoundLoadBuffer; int S_PickReplacement (int refid); void S_CacheRandomSound (sfxinfo_t *sfx); @@ -384,7 +386,7 @@ int S_AddPlayerSoundExisting (const char *playerclass, const int gender, int ref void S_MarkPlayerSounds (const char *playerclass); void S_ShrinkPlayerSoundLists (); void S_UnloadSound (sfxinfo_t *sfx); -sfxinfo_t *S_LoadSound(sfxinfo_t *sfx); +sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer = nullptr); unsigned int S_GetMSLength(FSoundID sound); void S_ParseMusInfo(); bool S_ParseTimeTag(const char *tag, bool *as_samples, unsigned int *time); diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index e0b0dd2800..939734e2f8 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -120,7 +120,7 @@ public: void SetMusicVolume (float volume) { } - std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize) + std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer) { SoundHandle retval = { NULL }; return std::make_pair(retval, true); @@ -576,6 +576,12 @@ std::pair SoundRenderer::LoadSoundVoc(uint8_t *sfxdata, int le return retval; } +std::pair SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize) +{ + SoundHandle retval = { NULL }; + return std::make_pair(retval, true); +} + SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) { SoundDecoder *decoder = NULL; @@ -604,14 +610,14 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) // Default readAll implementation, for decoders that can't do anything better -TArray SoundDecoder::readAll() +TArray SoundDecoder::readAll() { - TArray output; + TArray output; unsigned total = 0; unsigned got; output.Resize(total+32768); - while((got=(unsigned)read(&output[total], output.Size()-total)) > 0) + while((got=(unsigned)read((char*)&output[total], output.Size()-total)) > 0) { total += got; output.Resize(total*2); diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index ed6473bd84..d6c4a7d787 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -87,6 +87,16 @@ typedef bool (*SoundStreamCallback)(SoundStream *stream, void *buff, int len, vo struct SoundDecoder; class MIDIDevice; +struct FSoundLoadBuffer +{ + TArray mBuffer; + uint32_t loop_start; + uint32_t loop_end; + ChannelConfig chans; + SampleType type; + int srate; +}; + class SoundRenderer { public: @@ -97,9 +107,10 @@ public: virtual void SetSfxVolume (float volume) = 0; virtual void SetMusicVolume (float volume) = 0; // Returns a pair containing a sound handle and a boolean indicating the sound can be used in 3D. - virtual std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize=false) = 0; + virtual std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize=false, FSoundLoadBuffer *pBuffer = nullptr) = 0; std::pair LoadSoundVoc(uint8_t *sfxdata, int length, bool monoize=false); virtual std::pair LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1, bool monoize = false) = 0; + virtual std::pair LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize); virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index 47d2b923e3..b1ff4efce1 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -131,7 +131,7 @@ struct SoundDecoder virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0; virtual size_t read(char *buffer, size_t bytes) = 0; - virtual TArray readAll(); + virtual TArray readAll(); virtual bool seek(size_t ms_offset, bool ms, bool mayrestart) = 0; virtual size_t getSampleOffset() = 0; virtual size_t getSampleLength() { return 0; } diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index d9b53b0d58..30aa8b3e12 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -1205,7 +1205,7 @@ std::pair OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass); -std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize) +std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer) { SoundHandle retval = { NULL }; MemoryReader reader((const char*)sfxdata, length); @@ -1223,29 +1223,30 @@ std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int } std::unique_ptr decoder(CreateDecoder(&reader)); - if(!decoder) return std::make_pair(retval, true); + if (!decoder) return std::make_pair(retval, true); decoder->getInfo(&srate, &chans, &type); int samplesize = 1; - if(chans == ChannelConfig_Mono || monoize) + if (chans == ChannelConfig_Mono || monoize) { - if(type == SampleType_UInt8) format = AL_FORMAT_MONO8, samplesize = 1; - if(type == SampleType_Int16) format = AL_FORMAT_MONO16, samplesize = 2; + if (type == SampleType_UInt8) format = AL_FORMAT_MONO8, samplesize = 1; + if (type == SampleType_Int16) format = AL_FORMAT_MONO16, samplesize = 2; } - else if(chans == ChannelConfig_Stereo) + else if (chans == ChannelConfig_Stereo) { - if(type == SampleType_UInt8) format = AL_FORMAT_STEREO8, samplesize = 2; - if(type == SampleType_Int16) format = AL_FORMAT_STEREO16, samplesize = 4; + if (type == SampleType_UInt8) format = AL_FORMAT_STEREO8, samplesize = 2; + if (type == SampleType_Int16) format = AL_FORMAT_STEREO16, samplesize = 4; } - if(format == AL_NONE) + if (format == AL_NONE) { Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans), - GetSampleTypeName(type)); + GetSampleTypeName(type)); return std::make_pair(retval, true); } - TArray data = decoder->readAll(); + TArray data = decoder->readAll(); + if(chans != ChannelConfig_Mono && monoize) { size_t chancount = GetChannelCount(chans); @@ -1289,7 +1290,7 @@ std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int } if (!startass) loop_start = Scale(loop_start, srate, 1000); - if (!endass) loop_end = Scale(loop_end, srate, 1000); + if (!endass && loop_end != ~0u) loop_end = Scale(loop_end, srate, 1000); const uint32_t samples = data.Size() / samplesize; if (loop_start > samples) loop_start = 0; if (loop_end > samples) loop_end = samples; @@ -1302,6 +1303,98 @@ std::pair OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int // no console messages here, please! } + retval.data = MAKE_PTRID(buffer); + if (pBuffer != nullptr) + { + pBuffer->mBuffer = std::move(data); + pBuffer->loop_start = loop_start; + pBuffer->loop_end = loop_end; + pBuffer->chans = chans; + pBuffer->type = type; + pBuffer->srate = srate; + } + return std::make_pair(retval, (chans == ChannelConfig_Mono || monoize)); +} + +std::pair OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *pBuffer, bool monoize) +{ + SoundHandle retval = { NULL }; + ALenum format = AL_NONE; + int srate = pBuffer->srate; + auto type = pBuffer->type; + auto chans = pBuffer->chans; + uint32_t loop_start = pBuffer->loop_start, loop_end = pBuffer->loop_end; + + if (chans == ChannelConfig_Mono || monoize) + { + if (type == SampleType_UInt8) format = AL_FORMAT_MONO8; + if (type == SampleType_Int16) format = AL_FORMAT_MONO16; + } + else if (chans == ChannelConfig_Stereo) + { + if (type == SampleType_UInt8) format = AL_FORMAT_STEREO8; + if (type == SampleType_Int16) format = AL_FORMAT_STEREO16; + } + + if (format == AL_NONE) + { + Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans), + GetSampleTypeName(type)); + return std::make_pair(retval, true); + } + + TArray &data = pBuffer->mBuffer; + + if (pBuffer->chans == ChannelConfig_Stereo && monoize) + { + size_t chancount = GetChannelCount(chans); + size_t frames = data.Size() / chancount / + (type == SampleType_Int16 ? 2 : 1); + if (type == SampleType_Int16) + { + short *sfxdata = (short*)&data[0]; + for (size_t i = 0; i < frames; i++) + { + int sum = 0; + for (size_t c = 0; c < chancount; c++) + sum += sfxdata[i*chancount + c]; + sfxdata[i] = short(sum / chancount); + } + } + else if (type == SampleType_UInt8) + { + uint8_t *sfxdata = (uint8_t*)&data[0]; + for (size_t i = 0; i < frames; i++) + { + int sum = 0; + for (size_t c = 0; c < chancount; c++) + sum += sfxdata[i*chancount + c] - 128; + sfxdata[i] = uint8_t((sum / chancount) + 128); + } + } + data.Resize(unsigned(data.Size() / chancount)); + } + + ALenum err; + ALuint buffer = 0; + alGenBuffers(1, &buffer); + alBufferData(buffer, format, &data[0], data.Size(), srate); + if ((err = getALError()) != AL_NO_ERROR) + { + Printf("Failed to buffer data: %s\n", alGetString(err)); + alDeleteBuffers(1, &buffer); + getALError(); + return std::make_pair(retval, true); + } + + // the loop points were already validated by the previous load. + if ((loop_start > 0 || loop_end > 0) && loop_end > loop_start && AL.SOFT_loop_points) + { + ALint loops[2] = { static_cast(loop_start), static_cast(loop_end) }; + DPrintf(DMSG_NOTIFY, "Setting loop points %d -> %d\n", loops[0], loops[1]); + alBufferiv(buffer, AL_LOOP_POINTS_SOFT, loops); + // no console messages here, please! + } retval.data = MAKE_PTRID(buffer); return std::make_pair(retval, (chans == ChannelConfig_Mono || monoize)); diff --git a/src/sound/oalsound.h b/src/sound/oalsound.h index 82cb4a736f..212ba5c46e 100644 --- a/src/sound/oalsound.h +++ b/src/sound/oalsound.h @@ -87,7 +87,8 @@ public: virtual void SetSfxVolume(float volume); virtual void SetMusicVolume(float volume); - virtual std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize); + virtual std::pair LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *buffer); + virtual std::pair LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize); virtual std::pair LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1, bool monoize = false); virtual void UnloadSound(SoundHandle sfx); virtual unsigned int GetMSLength(SoundHandle sfx); diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index b403b46ed9..a46f0146b3 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -175,16 +175,16 @@ size_t SndFileDecoder::read(char *buffer, size_t bytes) return total * SndInfo.channels * 2; } -TArray SndFileDecoder::readAll() +TArray SndFileDecoder::readAll() { if(SndInfo.frames <= 0) return SoundDecoder::readAll(); int framesize = 2 * SndInfo.channels; - TArray output; + TArray output; output.Resize((unsigned)(SndInfo.frames * framesize)); - size_t got = read(&output[0], output.Size()); + size_t got = read((char*)&output[0], output.Size()); output.Resize((unsigned)got); return output; diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h index 53fa6e6a9e..0d5c83a417 100644 --- a/src/sound/sndfile_decoder.h +++ b/src/sound/sndfile_decoder.h @@ -16,7 +16,7 @@ struct SndFileDecoder : public SoundDecoder virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); virtual size_t read(char *buffer, size_t bytes); - virtual TArray readAll(); + virtual TArray readAll(); virtual bool seek(size_t ms_offset, bool ms, bool mayrestart); virtual size_t getSampleOffset(); virtual size_t getSampleLength(); From 22b70dd2220e84d573472455d25edd4ea88a5662 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Apr 2017 10:08:24 +0200 Subject: [PATCH 3/5] - fixed: For the last block in an MP3 the buffer address was incorrectly incremented. --- src/sound/musicformats/music_libsndfile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index e8a6132789..91951c18b0 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -333,8 +333,8 @@ bool SndFileSong::Read(SoundStream *stream, void *vbuff, int ilen, void *userdat size_t endlen = song->Decoder->read(buff, endblock); if (endlen != 0) { - buff = buff + endblock; - len -= endblock; + buff = buff + endlen; + len -= endlen; song->Decoder->seek(song->Loop_Start, false, true); } else From c3f9b4a5eeb7b04b10a204735f9d08da5c138181 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Apr 2017 10:23:31 +0200 Subject: [PATCH 4/5] - silenced a few float truncation warnings that get printed in developer mode. --- wadsrc/static/zscript/menu/optionmenuitems.txt | 4 ++-- wadsrc/static/zscript/statscreen/statscreen.txt | 2 +- wadsrc/static/zscript/statscreen/statscreen_coop.txt | 2 +- wadsrc/static/zscript/statscreen/statscreen_dm.txt | 2 +- wadsrc/static/zscript/statusbar/statusbar.txt | 4 ++-- wadsrc/static/zscript/statusbar/strife_sbar.txt | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wadsrc/static/zscript/menu/optionmenuitems.txt b/wadsrc/static/zscript/menu/optionmenuitems.txt index 4ec0fcc6aa..a778dc682f 100644 --- a/wadsrc/static/zscript/menu/optionmenuitems.txt +++ b/wadsrc/static/zscript/menu/optionmenuitems.txt @@ -1244,7 +1244,7 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider { drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor); - int Selection = GetSliderValue(); + int Selection = int(GetSliderValue()); if ((Selection == 0 || Selection == -1) && mClickVal <= 0) { String text = Selection == 0? TextZero : Selection == -1? TextNegOne : ""; @@ -1260,7 +1260,7 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider override bool MouseEvent(int type, int x, int y) { - int value = GetSliderValue(); + int value = int(GetSliderValue()); switch (type) { case Menu.MOUSE_Click: diff --git a/wadsrc/static/zscript/statscreen/statscreen.txt b/wadsrc/static/zscript/statscreen/statscreen.txt index 92d6abb7d3..de6e3d28c4 100644 --- a/wadsrc/static/zscript/statscreen/statscreen.txt +++ b/wadsrc/static/zscript/statscreen/statscreen.txt @@ -192,7 +192,7 @@ class StatusScreen abstract play version("2.5") { let size = TexMan.GetScaledSize(pinfo.mPatch); screen.DrawTexture(pinfo.mPatch, true, midx - size.X * CleanXfac/2, y, DTA_CleanNoMove, true); - return y + (size.Y * CleanYfac); + return y + int(size.Y * CleanYfac); } else { diff --git a/wadsrc/static/zscript/statscreen/statscreen_coop.txt b/wadsrc/static/zscript/statscreen/statscreen_coop.txt index a38d924a22..7393877b6a 100644 --- a/wadsrc/static/zscript/statscreen/statscreen_coop.txt +++ b/wadsrc/static/zscript/statscreen/statscreen_coop.txt @@ -221,7 +221,7 @@ class CoopStatusScreen : StatusScreen // Use the readyico height if it's bigger. Vector2 readysize = TexMan.GetScaledSize(readyico); Vector2 readyoffset = TexMan.GetScaledOffset(readyico); - height = readysize.Y - readyoffset.Y; + height = int(readysize.Y - readyoffset.Y); maxiconheight = MAX(height, maxiconheight); height = SmallFont.GetHeight() * CleanYfac; lineheight = MAX(height, maxiconheight * CleanYfac); diff --git a/wadsrc/static/zscript/statscreen/statscreen_dm.txt b/wadsrc/static/zscript/statscreen/statscreen_dm.txt index a8c7119eec..8807fb19cf 100644 --- a/wadsrc/static/zscript/statscreen/statscreen_dm.txt +++ b/wadsrc/static/zscript/statscreen/statscreen_dm.txt @@ -158,7 +158,7 @@ class DeathmatchStatusScreen : StatusScreen // Use the readyico height if it's bigger. Vector2 readysize = TexMan.GetScaledSize(readyico); Vector2 readyoffset = TexMan.GetScaledOffset(readyico); - height = readysize.Y - readyoffset.Y; + height = int(readysize.Y - readyoffset.Y); maxiconheight = MAX(height, maxiconheight); height = SmallFont.GetHeight() * CleanYfac; lineheight = MAX(height, maxiconheight * CleanYfac); diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index c5fd4a9caa..b1aa96f31b 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -774,9 +774,9 @@ class BaseStatusBar native ui } String mapname = level.FormatMapName(crdefault); - BrokenLines lines = SmallFont.BreakLines(mapname, SCREENWIDTH / scale.X); + BrokenLines lines = SmallFont.BreakLines(mapname, int(SCREENWIDTH / scale.X)); int numlines = lines.Count(); - int finalwidth = SmallFont.StringWidth(lines.StringAt(numlines-1)) * scale.X; + int finalwidth = int(SmallFont.StringWidth(lines.StringAt(numlines-1)) * scale.X); // calculate the top of the statusbar including any protrusion and transform it from status bar to screen space. double tmp, hres; diff --git a/wadsrc/static/zscript/statusbar/strife_sbar.txt b/wadsrc/static/zscript/statusbar/strife_sbar.txt index 8a7717e99e..866c4a32a3 100644 --- a/wadsrc/static/zscript/statusbar/strife_sbar.txt +++ b/wadsrc/static/zscript/statusbar/strife_sbar.txt @@ -266,7 +266,7 @@ class StrifeStatusBar : BaseStatusBar { double tmp, h; [tmp, tmp, h] = StatusbarToRealCoords(0, 0, 8); - DrawPopScreen (GetTopOfStatusBar() - h, TicFrac); + DrawPopScreen (int(GetTopOfStatusBar() - h), TicFrac); } DrawImage("INVBACK", (0, 168), DI_ITEM_OFFSETS); From 694b48423aecddad90d7c0cc7e3b0005ed42a5f3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Apr 2017 10:52:00 +0200 Subject: [PATCH 5/5] - fixed initialization of classes so that AllActorClasses only gets initialized when the game knows what is an actor and what is not. This could result in lost states for weapons because the weapon class did not get added to the array. --- src/dobjtype.cpp | 18 +++++++++++++----- src/dobjtype.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index ad745843e3..5f109e418c 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -220,6 +220,14 @@ void PClass::StaticInit () { ((ClassReg *)*probe)->RegisterClass (); } + probe.Reset(); + for(auto cls : AllClasses) + { + if (cls->IsDescendantOf(RUNTIME_CLASS(AActor))) + { + PClassActor::AllActorClasses.Push(static_cast(cls)); + } + } // Keep built-in classes in consistant order. I did this before, though // I'm not sure if this is really necessary to maintain any sort of sync. @@ -344,7 +352,7 @@ PClass *ClassReg::RegisterClass() PClass *cls = new PClass; SetupClass(cls); - cls->InsertIntoHash(); + cls->InsertIntoHash(true); if (ParentType != nullptr) { cls->ParentClass = ParentType->RegisterClass(); @@ -379,7 +387,7 @@ void ClassReg::SetupClass(PClass *cls) // //========================================================================== -void PClass::InsertIntoHash () +void PClass::InsertIntoHash (bool native) { auto k = ClassMap.CheckKey(TypeName); if (k != nullptr) @@ -390,7 +398,7 @@ void PClass::InsertIntoHash () { ClassMap[TypeName] = this; } - if (IsDescendantOf(RUNTIME_CLASS(AActor))) + if (!native && IsDescendantOf(RUNTIME_CLASS(AActor))) { PClassActor::AllActorClasses.Push(static_cast(this)); } @@ -690,7 +698,7 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size) if (!notnew) { - type->InsertIntoHash(); + type->InsertIntoHash(false); } return type; } @@ -759,7 +767,7 @@ PClass *PClass::FindClassTentative(FName name) Derive(type, name); type->Size = TentativeClass; - type->InsertIntoHash(); + type->InsertIntoHash(false); return type; } diff --git a/src/dobjtype.h b/src/dobjtype.h index 22d44a2348..12a6ae287f 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -75,7 +75,7 @@ public: // The rest are all functions and static data ---------------- PClass(); ~PClass(); - void InsertIntoHash(); + void InsertIntoHash(bool native); DObject *CreateNew(); PClass *CreateDerivedClass(FName name, unsigned int size);