diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 182712349..443acb293 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -749,7 +749,6 @@ void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints, void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2) { RenderCommand dg; - int method = 0; if (!img || !img->isValid()) return; @@ -835,13 +834,13 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu dg.mFlags = DTF_Wrap; float fs = 1.f / float(flatscale); - bool flipc = false; float sw = GetClassicFlatScalarWidth(); float sh = GetClassicFlatScalarHeight(); switch (local_origin) { + default: case 0: fU1 = float(left) / (float)src->GetDisplayWidth() * fs; fV1 = float(top) / (float)src->GetDisplayHeight() * fs; diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index 4a99b8cac..a7d213cb4 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -144,7 +144,7 @@ int GetUIScale(F2DDrawer *drawer, int altval) // Default should try to scale to 640x400 int vscale = drawer->GetHeight() / 400; int hscale = drawer->GetWidth() / 640; - scaleval = clamp(vscale, 1, hscale); + scaleval = max(1, min(vscale, hscale)); } else scaleval = uiscale; @@ -165,7 +165,7 @@ int GetConScale(F2DDrawer* drawer, int altval) // Default should try to scale to 640x400 int vscale = drawer->GetHeight() / 800; int hscale = drawer->GetWidth() / 1280; - scaleval = clamp(vscale, 1, hscale); + scaleval = max(1, min(vscale, hscale)); } else scaleval = (uiscale+1) / 2; @@ -671,7 +671,6 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double { INTBOOL boolval; int intval; - bool translationset = false; bool fillcolorset = false; if (!fortext) @@ -1016,10 +1015,16 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double case DTA_CenterOffsetRel: assert(fortext == false); if (fortext) return false; - if (ListGetInt(tags)) + intval = ListGetInt(tags); + if (intval == 1) { - parms->left = img->GetDisplayLeftOffset() + img->GetDisplayWidth() * 0.5; - parms->top = img->GetDisplayTopOffset() + img->GetDisplayHeight() * 0.5; + parms->left = img->GetDisplayLeftOffset() + (img->GetDisplayWidth() * 0.5); + parms->top = img->GetDisplayTopOffset() + (img->GetDisplayHeight() * 0.5); + } + else if (intval == 2) + { + parms->left = img->GetDisplayLeftOffset() + floor(img->GetDisplayWidth() * 0.5); + parms->top = img->GetDisplayTopOffset() + floor(img->GetDisplayHeight() * 0.5); } break; diff --git a/src/common/audio/music/music.cpp b/src/common/audio/music/music.cpp index 1b36041da..d8766ae90 100644 --- a/src/common/audio/music/music.cpp +++ b/src/common/audio/music/music.cpp @@ -603,13 +603,13 @@ static void CheckReplayGain(const char *musicname, EMidiDevice playertype, const { float* sbuf = (float*)readbuffer.Data(); int numsamples = fmt.mBufferSize / 8; - auto index = lbuffer.Reserve(numsamples); + auto addr = lbuffer.Reserve(numsamples); rbuffer.Reserve(numsamples); for (int i = 0; i < numsamples; i++) { - lbuffer[index + i] = sbuf[i * 2] * 32768.f; - rbuffer[index + i] = sbuf[i * 2 + 1] * 32768.f; + lbuffer[addr + i] = sbuf[i * 2] * 32768.f; + rbuffer[addr + i] = sbuf[i * 2 + 1] * 32768.f; } } float accTime = lbuffer.Size() / (float)fmt.mSampleRate; @@ -684,8 +684,6 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force) return true; } - int lumpnum = -1; - int length = 0; ZMusic_MusicStream handle = nullptr; MidiDeviceSetting* devp = MidiDevices.CheckKey(musicname); diff --git a/src/common/audio/sound/oalsound.cpp b/src/common/audio/sound/oalsound.cpp index 4ef36cb4d..f3c46746d 100644 --- a/src/common/audio/sound/oalsound.cpp +++ b/src/common/audio/sound/oalsound.cpp @@ -329,7 +329,6 @@ public: virtual FString GetStats() { FString stats; - size_t pos = 0, len = 0; ALfloat volume; ALint offset; ALint processed; diff --git a/src/common/audio/sound/s_environment.cpp b/src/common/audio/sound/s_environment.cpp index c5f1a5cf7..7a2dbd9a5 100644 --- a/src/common/audio/sound/s_environment.cpp +++ b/src/common/audio/sound/s_environment.cpp @@ -530,7 +530,7 @@ void S_ReadReverbDef (FScanner &sc) { const ReverbContainer *def; ReverbContainer *newenv; - REVERB_PROPERTIES props; + REVERB_PROPERTIES props = {}; char *name; int id1, id2, i, j; bool inited[NUM_REVERB_FIELDS]; diff --git a/src/common/audio/sound/s_reverbedit.cpp b/src/common/audio/sound/s_reverbedit.cpp index 398d4f2f5..9787ffa8c 100644 --- a/src/common/audio/sound/s_reverbedit.cpp +++ b/src/common/audio/sound/s_reverbedit.cpp @@ -309,7 +309,6 @@ DEFINE_ACTION_FUNCTION(DReverbEdit, GetValue) } } ACTION_RETURN_FLOAT(v); - return 1; } DEFINE_ACTION_FUNCTION(DReverbEdit, SetValue) @@ -337,14 +336,12 @@ DEFINE_ACTION_FUNCTION(DReverbEdit, SetValue) } ACTION_RETURN_FLOAT(v); - return 1; } DEFINE_ACTION_FUNCTION(DReverbEdit, GrayCheck) { PARAM_PROLOGUE; ACTION_RETURN_BOOL(CurrentEnv->Builtin); - return 1; } DEFINE_ACTION_FUNCTION(DReverbEdit, GetSelectedEnvironment) diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 46119a322..5201891c0 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -164,7 +164,6 @@ void SoundEngine::CacheSound (sfxinfo_t *sfx) { if (GSnd && !sfx->bTentative) { - sfxinfo_t *orig = sfx; while (!sfx->bRandomHeader && sfx->link != sfxinfo_t::NO_LINK) { sfx = &S_sfx[sfx->link]; @@ -1085,13 +1084,14 @@ void SoundEngine::SetPitch(FSoundChan *chan, float pitch) // Is a sound being played by a specific emitter? //========================================================================== -int SoundEngine::GetSoundPlayingInfo (int sourcetype, const void *source, int sound_id) +int SoundEngine::GetSoundPlayingInfo (int sourcetype, const void *source, int sound_id, int chann) { int count = 0; if (sound_id > 0) { for (FSoundChan *chan = Channels; chan != NULL; chan = chan->NextChan) { + if (chann != -1 && chann != chan->EntChannel) continue; if (chan->OrgID == sound_id && (sourcetype == SOURCE_Any || (chan->SourceType == sourcetype && chan->Source == source))) @@ -1104,6 +1104,7 @@ int SoundEngine::GetSoundPlayingInfo (int sourcetype, const void *source, int so { for (FSoundChan* chan = Channels; chan != NULL; chan = chan->NextChan) { + if (chann != -1 && chann != chan->EntChannel) continue; if ((sourcetype == SOURCE_Any || (chan->SourceType == sourcetype && chan->Source == source))) { count++; diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index d35cb524a..13ca33e7a 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -249,9 +249,6 @@ public: blockNewSounds = on; } - virtual int SoundSourceIndex(FSoundChan* chan) { return 0; } - virtual void SetSource(FSoundChan* chan, int index) {} - virtual void StopChannel(FSoundChan* chan); sfxinfo_t* LoadSound(sfxinfo_t* sfx); const sfxinfo_t* GetSfx(unsigned snd) @@ -303,7 +300,7 @@ public: bool IsSourcePlayingSomething(int sourcetype, const void* actor, int channel, int sound_id = -1); // Stop and resume music, during game PAUSE. - int GetSoundPlayingInfo(int sourcetype, const void* source, int sound_id); + int GetSoundPlayingInfo(int sourcetype, const void* source, int sound_id, int chan = -1); void UnloadAllSounds(); void Reset(); void MarkUsed(int num); diff --git a/src/common/console/c_console.cpp b/src/common/console/c_console.cpp index b40708808..8d4f8b44a 100644 --- a/src/common/console/c_console.cpp +++ b/src/common/console/c_console.cpp @@ -331,16 +331,16 @@ void C_DeinitConsole () // at runtime.) for (size_t i = 0; i < countof(Commands); ++i) { - FConsoleCommand *cmd = Commands[i]; + FConsoleCommand *command = Commands[i]; - while (cmd != NULL) + while (command != NULL) { - FConsoleCommand *next = cmd->m_Next; - if (cmd->IsAlias()) + FConsoleCommand *nextcmd = command->m_Next; + if (command->IsAlias()) { - delete cmd; + delete command; } - cmd = next; + command = nextcmd; } } diff --git a/src/common/console/c_cvars.cpp b/src/common/console/c_cvars.cpp index 7e5bd94ba..6510d561e 100644 --- a/src/common/console/c_cvars.cpp +++ b/src/common/console/c_cvars.cpp @@ -333,6 +333,7 @@ UCVarValue FBaseCVar::FromBool (bool value, ECVarType type) break; default: + ret.Int = 0; break; } @@ -363,6 +364,7 @@ UCVarValue FBaseCVar::FromInt (int value, ECVarType type) break; default: + ret.Int = 0; break; } @@ -395,6 +397,7 @@ UCVarValue FBaseCVar::FromFloat (float value, ECVarType type) break; default: + ret.Int = 0; break; } @@ -456,6 +459,7 @@ UCVarValue FBaseCVar::FromString (const char *value, ECVarType type) break; default: + ret.Int = 0; break; } @@ -1426,12 +1430,12 @@ void C_ArchiveCVars (FConfigFile *f, uint32_t filter) cvar = cvar->m_Next; } qsort(cvarlist.Data(), cvarlist.Size(), sizeof(FBaseCVar*), cvarcmp); - for (auto cvar : cvarlist) + for (auto cv : cvarlist) { - const char* const value = (cvar->Flags & CVAR_ISDEFAULT) - ? cvar->GetGenericRep(CVAR_String).String - : cvar->SafeValue.GetChars(); - f->SetValueForKey(cvar->GetName(), value); + const char* const value = (cv->Flags & CVAR_ISDEFAULT) + ? cv->GetGenericRep(CVAR_String).String + : cv->SafeValue.GetChars(); + f->SetValueForKey(cv->GetName(), value); } } @@ -1643,7 +1647,6 @@ CCMD (archivecvar) void C_ListCVarsWithoutDescription() { FBaseCVar* var = CVars; - int count = 0; while (var) { diff --git a/src/common/console/c_dispatch.cpp b/src/common/console/c_dispatch.cpp index 004c5be3e..76e0f19e2 100644 --- a/src/common/console/c_dispatch.cpp +++ b/src/common/console/c_dispatch.cpp @@ -282,8 +282,8 @@ void C_DoCommand (const char *cmd, int keynum) } else { - auto cmd = new FStoredCommand(com, beg); - delayedCommandQueue.AddCommand(cmd); + auto command = new FStoredCommand(com, beg); + delayedCommandQueue.AddCommand(command); } } } @@ -373,8 +373,8 @@ void AddCommandString (const char *text, int keynum) // Note that deferred commands lose track of which key // (if any) they were pressed from. *brkpt = ';'; - auto cmd = new FWaitingCommand(brkpt, tics, UnsafeExecutionContext); - delayedCommandQueue.AddCommand(cmd); + auto command = new FWaitingCommand(brkpt, tics, UnsafeExecutionContext); + delayedCommandQueue.AddCommand(command); } return; } @@ -851,8 +851,8 @@ CCMD (key) for (i = 1; i < argv.argc(); ++i) { - unsigned int key = MakeKey (argv[i]); - Printf (" 0x%08x\n", key); + unsigned int hash = MakeKey (argv[i]); + Printf (" 0x%08x\n", hash); } } } @@ -1014,7 +1014,6 @@ void FExecList::AddPullins(TArray &wads, FConfigFile *config) const FExecList *C_ParseExecFile(const char *file, FExecList *exec) { char cmd[4096]; - int retval = 0; FileReader fr; diff --git a/src/common/engine/i_net.cpp b/src/common/engine/i_net.cpp index 64fd4acaf..40bedd562 100644 --- a/src/common/engine/i_net.cpp +++ b/src/common/engine/i_net.cpp @@ -736,7 +736,7 @@ bool HostGame (int i) { // If we send the packets eight times to each guest, // hopefully at least one of them will get through. - for (int i = 8; i != 0; --i) + for (int ii = 8; ii != 0; --ii) { PreSend (&packet, 2, &sendaddress[node]); } diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index 73fb2bdb9..9648f2528 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -234,7 +234,7 @@ void PaletteContainer::UpdateTranslation(int trans, FRemapTable* remap) int PaletteContainer::AddTranslation(int slot, FRemapTable* remap, int count) { - uint32_t id; + uint32_t id = 0; for (int i = 0; i < count; i++) { auto newremap = AddRemap(&remap[i]); @@ -265,7 +265,7 @@ FRemapTable *PaletteContainer::TranslationToTable(int translation) unsigned int type = GetTranslationType(translation); unsigned int index = GetTranslationIndex(translation); - if (type < 0 || type >= TranslationTables.Size() || index >= NumTranslations(type)) + if (type >= TranslationTables.Size() || index >= NumTranslations(type)) { return uniqueRemaps[0]; // this is the identity table. } @@ -649,7 +649,6 @@ bool FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) bool FRemapTable::AddToTranslation(const char *range) { int start,end; - bool desaturated = false; FScanner sc; sc.OpenMem("translation", range, int(strlen(range))); diff --git a/src/common/engine/sc_man.cpp b/src/common/engine/sc_man.cpp index 29b0b445b..68bc8542d 100644 --- a/src/common/engine/sc_man.cpp +++ b/src/common/engine/sc_man.cpp @@ -1131,9 +1131,7 @@ FString FScanner::TokenName (int token, const char *string) } else { - FString work; - work.Format ("Unknown(%d)", token); - return work; + work.Format("Unknown(%d)", token); } return work; } diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index 505bd044d..f123fb42d 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -290,6 +290,28 @@ bool FSerializer::BeginObject(const char *name) // //========================================================================== +bool FSerializer::HasObject(const char* name) +{ + if (isReading()) + { + auto val = r->FindKey(name); + if (val != nullptr) + { + if (val->IsObject()) + { + return true; + } + } + } + return false; +} + +//========================================================================== +// +// +// +//========================================================================== + void FSerializer::EndObject() { if (isWriting()) @@ -619,7 +641,6 @@ void FSerializer::ReadObjects(bool hubtravel) if (BeginObject(nullptr)) { FString clsname; // do not deserialize the class type directly so that we can print appropriate errors. - int pindex = -1; Serialize(*this, "classtype", clsname, nullptr); PClass *cls = PClass::FindClass(clsname); @@ -643,6 +664,7 @@ void FSerializer::ReadObjects(bool hubtravel) if (!founderrors) { // Reset to start; + unsigned size = r->mObjects.Size(); r->mObjects.Last().mIndex = 0; for (unsigned i = 0; i < r->mDObjects.Size(); i++) @@ -652,7 +674,6 @@ void FSerializer::ReadObjects(bool hubtravel) { if (obj != nullptr) { - int pindex = -1; try { obj->SerializeUserVars(*this); @@ -660,6 +681,7 @@ void FSerializer::ReadObjects(bool hubtravel) } catch (CRecoverableError &err) { + r->mObjects.Clamp(size); // close all inner objects. // In case something in here throws an error, let's continue and deal with it later. Printf(TEXTCOLOR_RED "'%s'\n while restoring %s\n", err.GetMessage(), obj ? obj->GetClass()->TypeName.GetChars() : "invalid object"); mErrors++; diff --git a/src/common/engine/serializer.h b/src/common/engine/serializer.h index 400a6f4aa..4797ca20d 100644 --- a/src/common/engine/serializer.h +++ b/src/common/engine/serializer.h @@ -85,6 +85,7 @@ public: void ReadObjects(bool hubtravel); bool BeginObject(const char *name); void EndObject(); + bool HasObject(const char* name); bool BeginArray(const char *name); void EndArray(); unsigned GetSize(const char *group); @@ -234,7 +235,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString *def); FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def); -template +template >*/> FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) { DObject *v = static_cast(value); @@ -301,6 +302,11 @@ FSerializer& Serialize(FSerializer& arc, const char* key, FixedBitArray& v return arc.SerializeMemory(key, value.Storage(), value.StorageSize()); } +inline FSerializer& Serialize(FSerializer& arc, const char* key, BitArray& value, BitArray* def) +{ + return arc.SerializeMemory(key, value.Storage().Data(), value.Storage().Size()); +} + template<> FSerializer& Serialize(FSerializer& arc, const char* key, PClass*& clst, PClass** def); template<> FSerializer& Serialize(FSerializer& arc, const char* key, FFont*& font, FFont** def); template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **def); diff --git a/src/common/filesystem/file_directory.cpp b/src/common/filesystem/file_directory.cpp index 8c7b57876..9d215784d 100644 --- a/src/common/filesystem/file_directory.cpp +++ b/src/common/filesystem/file_directory.cpp @@ -41,8 +41,6 @@ #include "printf.h" #include "findfile.h" - - //========================================================================== // // Zip Lump diff --git a/src/common/filesystem/file_wad.cpp b/src/common/filesystem/file_wad.cpp index 054b0721a..216fab58b 100644 --- a/src/common/filesystem/file_wad.cpp +++ b/src/common/filesystem/file_wad.cpp @@ -308,14 +308,14 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name // We have found no F_START but one or more F_END markers. // mark all lumps before the last F_END marker as potential flats. unsigned int end = markers[markers.Size()-1].index; - for(unsigned int i = 0; i < end; i++) + for(unsigned int ii = 0; ii < end; ii++) { - if (Lumps[i].LumpSize == 4096) + if (Lumps[ii].LumpSize == 4096) { // We can't add this to the flats namespace but // it needs to be flagged for the texture manager. - DPrintf(DMSG_NOTIFY, "Marking %s as potential flat\n", Lumps[i].getName()); - Lumps[i].Flags |= LUMPF_MAYBEFLAT; + DPrintf(DMSG_NOTIFY, "Marking %s as potential flat\n", Lumps[ii].getName()); + Lumps[ii].Flags |= LUMPF_MAYBEFLAT; } } } @@ -428,18 +428,19 @@ void FWadFile::SkinHack () namespc++; } } + // needless to say, this check is entirely useless these days as map names can be more diverse.. if ((lump->getName()[0] == 'M' && lump->getName()[1] == 'A' && lump->getName()[2] == 'P' && lump->getName()[3] >= '0' && lump->getName()[3] <= '9' && lump->getName()[4] >= '0' && lump->getName()[4] <= '9' && - lump->getName()[5] >= '\0') + lump->getName()[5] == '\0') || (lump->getName()[0] == 'E' && lump->getName()[1] >= '0' && lump->getName()[1] <= '9' && lump->getName()[2] == 'M' && lump->getName()[3] >= '0' && lump->getName()[3] <= '9' && - lump->getName()[4] >= '\0')) + lump->getName()[4] == '\0')) { hasmap = true; } diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index 47932334d..6151925a0 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -218,7 +218,6 @@ void FileSystem::InitMultipleFiles (TArray &filenames, bool quiet, Lump for(unsigned i=0;i