diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 02c252468..529c98323 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -41,6 +41,7 @@ #include "v_draw.h" #include "v_video.h" #include "fcolormap.h" +#include "texturemanager.h" static F2DDrawer drawer = F2DDrawer(); F2DDrawer* twod = &drawer; @@ -1228,3 +1229,48 @@ F2DVertexBuffer::F2DVertexBuffer() }; mVertexBuffer->SetFormat(1, 3, sizeof(F2DDrawer::TwoDVertex), format); } + +//========================================================================== +// +// +// +//========================================================================== + +TArray AllCanvases; + +class InitTextureCanvasGC +{ +public: + InitTextureCanvasGC() + { + GC::AddMarkerFunc([]() { + for (auto canvas : AllCanvases) + GC::Mark(canvas); + }); + } +}; + +FCanvas* GetTextureCanvas(const FString& texturename) +{ + FTextureID textureid = TexMan.CheckForTexture(texturename, ETextureType::Wall, FTextureManager::TEXMAN_Overridable); + if (textureid.isValid()) + { + // Only proceed if the texture is a canvas texture. + auto tex = TexMan.GetGameTexture(textureid); + if (tex && tex->GetTexture()->isCanvas()) + { + FCanvasTexture* canvasTex = static_cast(tex->GetTexture()); + if (!canvasTex->Canvas) + { + static InitTextureCanvasGC initCanvasGC; // Does the common code have a natural init function this could be moved to? + + canvasTex->Canvas = Create(); + canvasTex->Canvas->Tex = canvasTex; + canvasTex->Canvas->Drawer.SetSize(tex->GetTexelWidth(), tex->GetTexelHeight()); + AllCanvases.Push(canvasTex->Canvas); + } + return canvasTex->Canvas; + } + } + return nullptr; +} diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 7754cca22..bc7d08db7 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -552,6 +552,15 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, UseGamePalette, UseGamePalette) ACTION_RETURN_INT(UseGamePalette(texid)); } +FCanvas* GetTextureCanvas(const FString& texturename); + +DEFINE_ACTION_FUNCTION(_TexMan, GetCanvas) +{ + PARAM_PROLOGUE; + PARAM_STRING(texturename); + ACTION_RETURN_POINTER(GetTextureCanvas(texturename)); +} + //===================================================================================== // // FFont exports diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 30700cca5..da2c7a167 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -44,7 +44,6 @@ #include "hw_texcontainer.h" #include "floatrect.h" #include "refcounted.h" -#include typedef TMap SpriteHits; class FImageSource; diff --git a/src/d_main.cpp b/src/d_main.cpp index 7b90b5fc4..df1051af5 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2926,7 +2926,6 @@ static void Doom_CastSpriteIDToString(FString* a, unsigned int b) extern DThinker* NextToThink; -extern TArray AllCanvases; static void GC_MarkGameRoots() { @@ -2934,8 +2933,6 @@ static void GC_MarkGameRoots() GC::Mark(staticEventManager.LastEventHandler); for (auto Level : AllLevels()) Level->Mark(); - for (auto canvas : AllCanvases) - GC::Mark(canvas); // Mark players. for (int i = 0; i < MAXPLAYERS; i++) diff --git a/src/r_data/r_canvastexture.cpp b/src/r_data/r_canvastexture.cpp index 3986aff97..c12d42e76 100644 --- a/src/r_data/r_canvastexture.cpp +++ b/src/r_data/r_canvastexture.cpp @@ -110,31 +110,6 @@ void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fo } } -TArray AllCanvases; - -FCanvas* GetTextureCanvas(const FString& texturename) -{ - FTextureID textureid = TexMan.CheckForTexture(texturename, ETextureType::Wall, FTextureManager::TEXMAN_Overridable); - if (textureid.isValid()) - { - // Only proceed if the texture is a canvas texture. - auto tex = TexMan.GetGameTexture(textureid); - if (tex && tex->GetTexture()->isCanvas()) - { - FCanvasTexture* canvasTex = static_cast(tex->GetTexture()); - if (!canvasTex->Canvas) - { - canvasTex->Canvas = Create(); - canvasTex->Canvas->Tex = canvasTex; - canvasTex->Canvas->Drawer.SetSize(tex->GetTexelWidth(), tex->GetTexelHeight()); - AllCanvases.Push(canvasTex->Canvas); - } - return canvasTex->Canvas; - } - } - return nullptr; -} - //========================================================================== // // FCanvasTextureInfo :: UpdateAll diff --git a/src/r_data/r_canvastexture.h b/src/r_data/r_canvastexture.h index 7ea137504..22f5a730f 100644 --- a/src/r_data/r_canvastexture.h +++ b/src/r_data/r_canvastexture.h @@ -24,5 +24,3 @@ struct FCanvasTextureInfo void Mark(); }; - -extern TArray AllCanvases; diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 61afa2f33..94baffd9f 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -102,17 +102,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraTextureAspectRatio, SetCameraTex return 0; } -FCanvas* GetTextureCanvas(const FString& texturename); - -DEFINE_ACTION_FUNCTION(_TexMan, GetCanvas) -{ - PARAM_PROLOGUE; - PARAM_STRING(texturename); - FCanvas* canvas = GetTextureCanvas(texturename); - if (numret > 0) ret[0].SetPointer(canvas); - return numret; -} - //===================================================================================== // // sector_t exports diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 2abfce6ed..34a00cdd4 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -28,7 +28,6 @@ extend struct TexMan { native static void SetCameraToTexture(Actor viewpoint, String texture, double fov); native static void SetCameraTextureAspectRatio(String texture, double aspectScale, bool useTextureRatio = true); - native static Canvas GetCanvas(String texture); deprecated("3.8", "Use Level.ReplaceTextures() instead") static void ReplaceTextures(String from, String to, int flags) { level.ReplaceTextures(from, to, flags); diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 118ba51db..a37369847 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -307,6 +307,7 @@ struct TexMan native static int CheckRealHeight(TextureID tex); native static bool OkForLocalization(TextureID patch, String textSubstitute); native static bool UseGamePalette(TextureID tex); + native static Canvas GetCanvas(String texture); } /*