From a9141af545dae3f4de474a3243223eed4bbd345c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 11 Jun 2020 09:15:44 +0200 Subject: [PATCH] - backend update. --- source/CMakeLists.txt | 5 +--- source/blood/src/screen.cpp | 7 +---- source/common/audio/sound/s_sound.cpp | 2 +- source/common/audio/sound/s_soundinternal.h | 6 ++++ source/common/console/c_cvars.cpp | 19 ++++++++++++ source/common/console/c_cvars.h | 5 ++++ source/common/console/c_dispatch.cpp | 3 +- .../{core/input => common/engine}/m_joy.cpp | 25 ++++++++-------- source/{core/input => common/engine}/m_joy.h | 4 +-- source/common/filesystem/filesystem.cpp | 2 +- source/common/objects/dobject.h | 2 -- source/common/rendering/gl/gl_shader.cpp | 3 ++ source/common/rendering/gl_load/gl_system.h | 2 +- .../rendering/vulkan/shaders/vk_shader.cpp | 3 ++ .../thirdparty/vk_mem_alloc/vk_mem_alloc.h | 2 +- .../textures/formats/multipatchtexture.h | 2 +- source/common/textures/gametexture.cpp | 2 +- source/common/textures/gametexture.h | 10 +------ source/common/textures/hires/hqresize.cpp | 11 +++---- source/common/textures/hw_material.h | 5 ++++ .../textures/multipatchtexturebuilder.cpp | 13 ++++---- source/common/textures/texturemanager.cpp | 14 ++++----- source/common/textures/textures.h | 1 + source/common/utility/m_alloc.cpp | 30 +++++++++++++++++-- source/common/utility/m_alloc.h | 2 +- source/common/utility/palette.cpp | 2 +- source/core/palette.cpp | 4 +-- wadsrc/static/shaders/glsl/main.fp | 10 +++++++ 28 files changed, 128 insertions(+), 68 deletions(-) rename source/{core/input => common/engine}/m_joy.cpp (92%) rename source/{core/input => common/engine}/m_joy.h (97%) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 905210d34..dd88dbe88 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -914,6 +914,7 @@ set (PCH_SOURCES common/engine/renderstyle.cpp common/engine/v_colortables.cpp common/engine/serializer.cpp + common/engine/m_joy.cpp common/engine/m_random.cpp common/objects/dobject.cpp common/objects/dobjgc.cpp @@ -983,10 +984,6 @@ set (PCH_SOURCES core/menu/messagebox.cpp core/menu/optionmenu.cpp core/menu/resolutionmenu.cpp - - #core/input/i_joystick.cpp - #core/input/i_input.cpp - core/input/m_joy.cpp ) if( ${HAVE_VM_JIT} ) diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp index a84b61d91..2ef9c6057 100644 --- a/source/blood/src/screen.cpp +++ b/source/blood/src/screen.cpp @@ -110,12 +110,7 @@ void scrLoadPalette(void) numshades = 64; paletteloaded |= PALETTE_MAIN; scrLoadPLUs(); - paletteloaded |= PALETTE_SHADE; - Printf("Loading translucency table\n"); - DICTNODE *pTrans = gSysRes.Lookup("TRANS", "TLU"); - if (!pTrans) - ThrowError("TRANS.TLU not found"); - paletteloaded |= PALETTE_TRANSLUC; + paletteloaded |= PALETTE_SHADE | PALETTE_TRANSLUC; enginePostInit(); diff --git a/source/common/audio/sound/s_sound.cpp b/source/common/audio/sound/s_sound.cpp index 04a564913..81bdf047a 100644 --- a/source/common/audio/sound/s_sound.cpp +++ b/source/common/audio/sound/s_sound.cpp @@ -378,7 +378,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, FVector3 pos, vel; FRolloffInfo *rolloff; - if (sound_id <= 0 || volume <= 0 || nosfx || nosound ) + if (sound_id <= 0 || volume <= 0 || nosfx || nosound || blockNewSounds) return NULL; // prevent crashes. diff --git a/source/common/audio/sound/s_soundinternal.h b/source/common/audio/sound/s_soundinternal.h index 5ecb6ee48..777833895 100644 --- a/source/common/audio/sound/s_soundinternal.h +++ b/source/common/audio/sound/s_soundinternal.h @@ -238,6 +238,7 @@ protected: TArray S_SoundCurve; TMap ResIdMap; TArray S_rnd; + bool blockNewSounds = false; private: void LinkChannel(FSoundChan* chan, FSoundChan** head); @@ -268,6 +269,11 @@ public: } void EvictAllChannels(); + void BlockNewSounds(bool on) + { + blockNewSounds = on; + } + virtual int SoundSourceIndex(FSoundChan* chan) { return 0; } virtual void SetSource(FSoundChan* chan, int index) {} diff --git a/source/common/console/c_cvars.cpp b/source/common/console/c_cvars.cpp index 5b15a7ebc..fe951d65c 100644 --- a/source/common/console/c_cvars.cpp +++ b/source/common/console/c_cvars.cpp @@ -1600,3 +1600,22 @@ CCMD (archivecvar) } } +void C_ListCVarsWithoutDescription() +{ + FBaseCVar* var = CVars; + int count = 0; + + while (var) + { + if (var->GetDescription().IsEmpty()) + { + Printf("%s\n", var->GetName()); + } + var = var->m_Next; + } +} + +CCMD(listcvarswithoutdescription) +{ + C_ListCVarsWithoutDescription(); +} diff --git a/source/common/console/c_cvars.h b/source/common/console/c_cvars.h index d1b0e6506..6218cb956 100644 --- a/source/common/console/c_cvars.h +++ b/source/common/console/c_cvars.h @@ -143,6 +143,10 @@ public: void SetArchiveBit () { Flags |= CVAR_ARCHIVE; } void MarkUnsafe(); void MarkSafe() { Flags &= ~CVAR_UNSAFECONTEXT; } + void AddDescription(const FString& label) + { + if (Description.IsEmpty()) Description = label; + } int ToInt() { @@ -214,6 +218,7 @@ private: friend void C_SetCVarsToDefaults (void); friend void FilterCompactCVars (TArray &cvars, uint32_t filter); friend void C_DeinitConsole(); + friend void C_ListCVarsWithoutDescription(); }; // Returns a string with all cvars whose flags match filter. In compact mode, diff --git a/source/common/console/c_dispatch.cpp b/source/common/console/c_dispatch.cpp index 6b4680e35..38ef90831 100644 --- a/source/common/console/c_dispatch.cpp +++ b/source/common/console/c_dispatch.cpp @@ -50,6 +50,7 @@ #include "c_cvars.h" #include "c_buttons.h" #include "findfile.h" +#include "gstrings.h" // MACROS ------------------------------------------------------------------ @@ -300,7 +301,7 @@ void C_DoCommand (const char *cmd, int keynum) } else { // Get the variable's value - if (var->GetDescription().Len()) Printf("%s\n", var->GetDescription().GetChars()); + if (var->GetDescription().Len()) Printf("%s\n", GStrings.localize(var->GetDescription())); Printf ("\"%s\" is \"%s\"\n", var->GetName(), var->GetHumanString()); } } diff --git a/source/core/input/m_joy.cpp b/source/common/engine/m_joy.cpp similarity index 92% rename from source/core/input/m_joy.cpp rename to source/common/engine/m_joy.cpp index cd0fb56e0..c20b406c7 100644 --- a/source/core/input/m_joy.cpp +++ b/source/common/engine/m_joy.cpp @@ -38,6 +38,7 @@ #include "gameconfigfile.h" #include "d_event.h" #include "cmdlib.h" +#include "printf.h" // MACROS ------------------------------------------------------------------ @@ -124,23 +125,23 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy) numaxes = joy->GetNumAxes(); for (int i = 0; i < numaxes; ++i) { - axislen = snprintf(key, countof(key), "Axis%u", i); + axislen = mysnprintf(key, countof(key), "Axis%u", i); - snprintf(key + axislen, countof(key) - axislen, "deadzone"); + mysnprintf(key + axislen, countof(key) - axislen, "deadzone"); value = GameConfig->GetValueForKey(key); if (value != NULL) { joy->SetAxisDeadZone(i, (float)atof(value)); } - snprintf(key + axislen, countof(key) - axislen, "scale"); + mysnprintf(key + axislen, countof(key) - axislen, "scale"); value = GameConfig->GetValueForKey(key); if (value != NULL) { joy->SetAxisScale(i, (float)atof(value)); } - snprintf(key + axislen, countof(key) - axislen, "map"); + mysnprintf(key + axislen, countof(key) - axislen, "map"); value = GameConfig->GetValueForKey(key); if (value != NULL) { @@ -173,30 +174,30 @@ void M_SaveJoystickConfig(IJoystickConfig *joy) GameConfig->ClearCurrentSection(); if (!joy->IsSensitivityDefault()) { - snprintf(value, countof(value), "%g", joy->GetSensitivity()); + mysnprintf(value, countof(value), "%g", joy->GetSensitivity()); GameConfig->SetValueForKey("Sensitivity", value); } numaxes = joy->GetNumAxes(); for (int i = 0; i < numaxes; ++i) { - axislen = snprintf(key, countof(key), "Axis%u", i); + axislen = mysnprintf(key, countof(key), "Axis%u", i); if (!joy->IsAxisDeadZoneDefault(i)) { - snprintf(key + axislen, countof(key) - axislen, "deadzone"); - snprintf(value, countof(value), "%g", joy->GetAxisDeadZone(i)); + mysnprintf(key + axislen, countof(key) - axislen, "deadzone"); + mysnprintf(value, countof(value), "%g", joy->GetAxisDeadZone(i)); GameConfig->SetValueForKey(key, value); } if (!joy->IsAxisScaleDefault(i)) { - snprintf(key + axislen, countof(key) - axislen, "scale"); - snprintf(value, countof(value), "%g", joy->GetAxisScale(i)); + mysnprintf(key + axislen, countof(key) - axislen, "scale"); + mysnprintf(value, countof(value), "%g", joy->GetAxisScale(i)); GameConfig->SetValueForKey(key, value); } if (!joy->IsAxisMapDefault(i)) { - snprintf(key + axislen, countof(key) - axislen, "map"); - snprintf(value, countof(value), "%d", joy->GetAxisMap(i)); + mysnprintf(key + axislen, countof(key) - axislen, "map"); + mysnprintf(value, countof(value), "%d", joy->GetAxisMap(i)); GameConfig->SetValueForKey(key, value); } } diff --git a/source/core/input/m_joy.h b/source/common/engine/m_joy.h similarity index 97% rename from source/core/input/m_joy.h rename to source/common/engine/m_joy.h index 90cea3e14..016aa78d6 100644 --- a/source/core/input/m_joy.h +++ b/source/common/engine/m_joy.h @@ -1,7 +1,7 @@ #ifndef M_JOY_H #define M_JOY_H -#include +#include "basics.h" #include "tarray.h" #include "c_cvars.h" @@ -18,7 +18,7 @@ enum EJoyAxis }; // Generic configuration interface for a controller. -struct IJoystickConfig +struct NOVTABLE IJoystickConfig { virtual ~IJoystickConfig() = 0; diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index 12b1d197a..d411ab32f 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -1386,7 +1386,7 @@ FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache) if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !alwayscache && !(rl->Flags & LUMPF_COMPRESSED)) { int fileno = fileSystem.GetFileContainer(lump); - const char *filename = fileSystem.GetResourceFileName(fileno); + const char *filename = fileSystem.GetResourceFileFullName(fileno); FileReader fr; if (fr.OpenFile(filename, rl->GetFileOffset(), rl->LumpSize)) { diff --git a/source/common/objects/dobject.h b/source/common/objects/dobject.h index 98d9106a2..f9c0c0b0a 100644 --- a/source/common/objects/dobject.h +++ b/source/common/objects/dobject.h @@ -266,14 +266,12 @@ private: void *operator new(size_t len, nonew&) { - GC::AllocBytes += len; return M_Malloc(len); } public: void operator delete (void *mem, nonew&) { - GC::AllocBytes -= _msize(mem); M_Free(mem); } diff --git a/source/common/rendering/gl/gl_shader.cpp b/source/common/rendering/gl/gl_shader.cpp index 0505a1d2e..fdcad50ab 100644 --- a/source/common/rendering/gl/gl_shader.cpp +++ b/source/common/rendering/gl/gl_shader.cpp @@ -306,6 +306,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * uniform sampler2D texture6; uniform sampler2D texture7; uniform sampler2D texture8; + uniform sampler2D texture9; + uniform sampler2D texture10; + uniform sampler2D texture11; // timer data uniform float timer; diff --git a/source/common/rendering/gl_load/gl_system.h b/source/common/rendering/gl_load/gl_system.h index 0ad2f3303..6b40d73c0 100644 --- a/source/common/rendering/gl_load/gl_system.h +++ b/source/common/rendering/gl_load/gl_system.h @@ -14,7 +14,7 @@ #include #include #include -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) #include #endif #include diff --git a/source/common/rendering/vulkan/shaders/vk_shader.cpp b/source/common/rendering/vulkan/shaders/vk_shader.cpp index 7f9fa9a6f..cff13547f 100644 --- a/source/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/source/common/rendering/vulkan/shaders/vk_shader.cpp @@ -183,6 +183,9 @@ static const char *shaderBindings = R"( layout(set = 1, binding = 5) uniform sampler2D texture6; layout(set = 1, binding = 6) uniform sampler2D texture7; layout(set = 1, binding = 7) uniform sampler2D texture8; + layout(set = 1, binding = 8) uniform sampler2D texture9; + layout(set = 1, binding = 9) uniform sampler2D texture10; + layout(set = 1, binding = 10) uniform sampler2D texture11; // This must match the PushConstants struct layout(push_constant) uniform PushConstants diff --git a/source/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h b/source/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h index 53ce163bf..30f2494a7 100644 --- a/source/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h +++ b/source/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h @@ -2229,7 +2229,7 @@ remove them if not needed. #include // for std::mutex #include // for std::atomic -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) #include // for aligned_alloc() #endif diff --git a/source/common/textures/formats/multipatchtexture.h b/source/common/textures/formats/multipatchtexture.h index 5c75fa474..d8f271333 100644 --- a/source/common/textures/formats/multipatchtexture.h +++ b/source/common/textures/formats/multipatchtexture.h @@ -170,6 +170,6 @@ public: } void AddTexturesLumps(int lump1, int lump2, int patcheslump); - void ParseTexture(FScanner &sc, ETextureType usetype); + void ParseTexture(FScanner &sc, ETextureType usetype, int deflump); void ResolveAllPatches(); }; diff --git a/source/common/textures/gametexture.cpp b/source/common/textures/gametexture.cpp index 66775d1e2..29d1ee2dd 100644 --- a/source/common/textures/gametexture.cpp +++ b/source/common/textures/gametexture.cpp @@ -389,7 +389,7 @@ void FGameTexture::SetSpriteRect() void FGameTexture::CleanHardwareData(bool full) { - Base->CleanHardwareTextures(); + if (full) Base->CleanHardwareTextures(); for (auto mat : Material) if (mat) mat->DeleteDescriptors(); } diff --git a/source/common/textures/gametexture.h b/source/common/textures/gametexture.h index e6b3461cf..c624fa9f5 100644 --- a/source/common/textures/gametexture.h +++ b/source/common/textures/gametexture.h @@ -241,10 +241,6 @@ public: DisplayHeight = h; ScaleX = TexelWidth / w; ScaleY = TexelHeight / h; - if (shouldUpscaleFlag < 2) - { - shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2; - } // compensate for roundoff errors if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); @@ -271,10 +267,6 @@ public: { ScaleX = x; ScaleY = y; - if (shouldUpscaleFlag < 2) - { - shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2; - } DisplayWidth = TexelWidth / x; DisplayHeight = TexelHeight / y; } @@ -374,7 +366,7 @@ enum EUpscaleFlags extern int upscalemask; void UpdateUpscaleMask(); -int calcShouldUpscale(FGameTexture* tex); +void calcShouldUpscale(FGameTexture* tex); inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType) { // This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere. diff --git a/source/common/textures/hires/hqresize.cpp b/source/common/textures/hires/hqresize.cpp index fe5beda4e..e8b457ee1 100644 --- a/source/common/textures/hires/hqresize.cpp +++ b/source/common/textures/hires/hqresize.cpp @@ -502,20 +502,21 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA // //=========================================================================== -int calcShouldUpscale(FGameTexture *tex) +void calcShouldUpscale(FGameTexture *tex) { + tex->SetUpscaleFlag(0); // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. const int maxInputSize = gl_texture_hqresize_maxinputsize; if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize) - return 0; + return; // [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!) if (tex->isHardwareCanvas()) - return 0; + return; // already scaled? if (tex->GetScaleX() >= 2.f || tex->GetScaleY() > 2.f) - return 0; + return; - return CTF_Upscale; + tex->SetUpscaleFlag(1); } \ No newline at end of file diff --git a/source/common/textures/hw_material.h b/source/common/textures/hw_material.h index e8c013d2b..75a77e35a 100644 --- a/source/common/textures/hw_material.h +++ b/source/common/textures/hw_material.h @@ -48,6 +48,11 @@ public: return sourcetex; } + void ClearLayers() + { + mTextureLayers.Resize(1); + } + void AddTextureLayer(FTexture *tex, bool allowscale) { mTextureLayers.Push({ tex, allowscale }); diff --git a/source/common/textures/multipatchtexturebuilder.cpp b/source/common/textures/multipatchtexturebuilder.cpp index 89d4adaf3..2557d848c 100644 --- a/source/common/textures/multipatchtexturebuilder.cpp +++ b/source/common/textures/multipatchtexturebuilder.cpp @@ -606,7 +606,7 @@ void FMultipatchTextureBuilder::ParsePatch(FScanner &sc, BuildInfo &info, TexPar // //========================================================================== -void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) +void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType, int deflump) { BuildInfo &buildinfo = BuiltTextures[BuiltTextures.Reserve(1)]; @@ -637,6 +637,7 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) sc.MustGetStringName(","); sc.MustGetNumber(); buildinfo.Height = sc.Number; + buildinfo.DefinitionLump = deflump; bool offset2set = false; if (sc.CheckString("{")) @@ -778,13 +779,10 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) TexMan.ListTextures(buildinfo.Inits[i].TexName, list, true); for (int i = list.Size() - 1; i >= 0; i--) { - if (list[i] != buildinfo.texture->GetID()) + auto gtex = TexMan.GetGameTexture(list[i]); + if (gtex && gtex != buildinfo.texture && gtex->GetTexture() && gtex->GetTexture()->GetImage() && !dynamic_cast(gtex->GetTexture()->GetImage())) { - auto gtex = TexMan.GetGameTexture(list[i]); - if (gtex && !dynamic_cast(gtex->GetTexture())) - { - texno = list[i]; - } + texno = list[i]; break; } } @@ -911,6 +909,7 @@ void FMultipatchTextureBuilder::ResolveAllPatches() { auto img = new FMultiPatchTexture(buildinfo.Width, buildinfo.Height, buildinfo.Parts, buildinfo.bComplex, buildinfo.textual); auto itex = new FImageTexture(img); + itex->SetSourceLump(buildinfo.DefinitionLump); AddImageToTexture(itex, buildinfo); } BuiltTextures.Delete(i); diff --git a/source/common/textures/texturemanager.cpp b/source/common/textures/texturemanager.cpp index f0163ab33..73918db92 100644 --- a/source/common/textures/texturemanager.cpp +++ b/source/common/textures/texturemanager.cpp @@ -106,7 +106,7 @@ void FTextureManager::DeleteAll() // This must not, under any circumstances, delete the wipe textures, because // all CCMDs triggering a flush can be executed while a wipe is in progress // -// This now also deletes the software textures because having the software +// This now also deletes the software textures because the software // renderer can also use the texture scalers and that is the // main reason to call this outside of the destruction code. // @@ -120,8 +120,8 @@ void FTextureManager::FlushAll() { Textures[i].Texture->CleanHardwareData(); delete Textures[i].Texture->GetSoftwareTexture(); - Textures[i].Texture->SetSoftwareTexture(nullptr); calcShouldUpscale(Textures[i].Texture); + Textures[i].Texture->SetSoftwareTexture(nullptr); } } } @@ -782,23 +782,23 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build } else if (sc.Compare("texture")) { - build.ParseTexture(sc, ETextureType::Override); + build.ParseTexture(sc, ETextureType::Override, lump); } else if (sc.Compare("sprite")) { - build.ParseTexture(sc, ETextureType::Sprite); + build.ParseTexture(sc, ETextureType::Sprite, lump); } else if (sc.Compare("walltexture")) { - build.ParseTexture(sc, ETextureType::Wall); + build.ParseTexture(sc, ETextureType::Wall, lump); } else if (sc.Compare("flat")) { - build.ParseTexture(sc, ETextureType::Flat); + build.ParseTexture(sc, ETextureType::Flat, lump); } else if (sc.Compare("graphic")) { - build.ParseTexture(sc, ETextureType::MiscPatch); + build.ParseTexture(sc, ETextureType::MiscPatch, lump); } else if (sc.Compare("#include")) { diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index 9fc99bda9..f8fd763cf 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -253,6 +253,7 @@ public: bool isCanvas() const { return bHasCanvas; } int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. + void SetSourceLump(int sl) { SourceLump = sl; } bool FindHoles(const unsigned char * buffer, int w, int h); void CopySize(FTexture* BaseTexture) diff --git a/source/common/utility/m_alloc.cpp b/source/common/utility/m_alloc.cpp index 8e3b89ab6..8ab7b6fcc 100644 --- a/source/common/utility/m_alloc.cpp +++ b/source/common/utility/m_alloc.cpp @@ -38,14 +38,14 @@ #elif defined(__APPLE__) #include #include -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__DragonFly__) #include #else #include #endif #include "engineerrors.h" -#include "m_alloc.h" +#include "dobject.h" #ifndef _MSC_VER #define _NORMAL_BLOCK 0 @@ -62,16 +62,22 @@ void *M_Malloc(size_t size) if (block == NULL) I_FatalError("Could not malloc %zu bytes", size); + GC::AllocBytes += _msize(block); return block; } void *M_Realloc(void *memblock, size_t size) { + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } void *block = realloc(memblock, size); if (block == NULL) { I_FatalError("Could not realloc %zu bytes", size); } + GC::AllocBytes += _msize(block); return block; } #else @@ -86,6 +92,7 @@ void *M_Malloc(size_t size) *sizeStore = size; block = sizeStore+1; + GC::AllocBytes += _msize(block); return block; } @@ -94,6 +101,10 @@ void *M_Realloc(void *memblock, size_t size) if(memblock == NULL) return M_Malloc(size); + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } void *block = realloc(((size_t*) memblock)-1, size+sizeof(size_t)); if (block == NULL) { @@ -104,6 +115,7 @@ void *M_Realloc(void *memblock, size_t size) *sizeStore = size; block = sizeStore+1; + GC::AllocBytes += _msize(block); return block; } #endif @@ -120,16 +132,22 @@ void *M_Malloc_Dbg(size_t size, const char *file, int lineno) if (block == NULL) I_FatalError("Could not malloc %zu bytes in %s, line %d", size, file, lineno); + GC::AllocBytes += _msize(block); return block; } void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) { + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } void *block = _realloc_dbg(memblock, size, _NORMAL_BLOCK, file, lineno); if (block == NULL) { I_FatalError("Could not realloc %zu bytes in %s, line %d", size, file, lineno); } + GC::AllocBytes += _msize(block); return block; } #else @@ -144,6 +162,7 @@ void *M_Malloc_Dbg(size_t size, const char *file, int lineno) *sizeStore = size; block = sizeStore+1; + GC::AllocBytes += _msize(block); return block; } @@ -152,6 +171,10 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) if(memblock == NULL) return M_Malloc_Dbg(size, file, lineno); + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } void *block = _realloc_dbg(((size_t*) memblock)-1, size+sizeof(size_t), _NORMAL_BLOCK, file, lineno); if (block == NULL) @@ -163,6 +186,7 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) *sizeStore = size; block = sizeStore+1; + GC::AllocBytes += _msize(block); return block; } #endif @@ -173,6 +197,7 @@ void M_Free (void *block) { if (block != NULL) { + GC::AllocBytes -= _msize(block); free(block); } } @@ -181,6 +206,7 @@ void M_Free (void *block) { if(block != NULL) { + GC::AllocBytes -= _msize(block); free(((size_t*) block)-1); } } diff --git a/source/common/utility/m_alloc.h b/source/common/utility/m_alloc.h index 76c4947bc..14e9cbb9a 100644 --- a/source/common/utility/m_alloc.h +++ b/source/common/utility/m_alloc.h @@ -40,7 +40,7 @@ #if defined(__APPLE__) #include #define _msize(p) malloc_size(p) -#elif defined(__solaris__) || defined(__OpenBSD__) +#elif defined(__solaris__) || defined(__OpenBSD__) || defined(__DragonFly__) #define _msize(p) (*((size_t*)(p)-1)) #elif !defined(_WIN32) #include diff --git a/source/common/utility/palette.cpp b/source/common/utility/palette.cpp index f4876b4b9..f2a2987b3 100644 --- a/source/common/utility/palette.cpp +++ b/source/common/utility/palette.cpp @@ -444,7 +444,7 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap) for (i = 0; i < 256; ++i) { - sortcopy[i] = BaseColors[i] | (i << 24); + sortcopy[i] = (BaseColors[i] & 0xffffff) | (i << 24); } qsort(sortcopy, 256, 4, sortforremap); for (i = 255; i > 0; --i) diff --git a/source/core/palette.cpp b/source/core/palette.cpp index dfa4cbf79..6e9b06298 100644 --- a/source/core/palette.cpp +++ b/source/core/palette.cpp @@ -107,7 +107,6 @@ void paletteLoadFromDisk(void) // LameDuke and Witchaven use an older variant. if (fil.GetLength() == 41600) { - fil.Seek(-2, FileReader::SeekCur); numshades = 32; } else @@ -129,8 +128,7 @@ void paletteLoadFromDisk(void) if (buffer.Size() != length) return; lookups.setTable(0, buffer.Data()); - paletteloaded |= PALETTE_SHADE; - paletteloaded |= PALETTE_TRANSLUC; + paletteloaded |= PALETTE_SHADE | PALETTE_TRANSLUC; } //========================================================================== diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 048579eee..009427dd2 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -308,6 +308,16 @@ float R_DoomLightingEquation(float light) { z = pixelpos.w; } + + if ((uPalLightLevels >> 16) == 5) // gl_lightmode 5: Build software lighting emulation. + { + // This is a lot more primitive than Doom's lighting... + float numShades = float(uPalLightLevels & 255); + float curshade = (1.0 - light) * (numShades - 1.0); + float visibility = max(uGlobVis * uLightFactor * z, 0.0); + float shade = clamp((curshade + visibility), 0.0, numShades - 1.0); + return clamp(shade * uLightDist, 0.0, 1.0); + } float colormap = R_DoomColormap(light, z);