mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-17 01:31:25 +00:00
Move TexMan.GetCanvas and GetTextureCanvas to common
This commit is contained in:
parent
753822359e
commit
e2778ba442
9 changed files with 56 additions and 43 deletions
|
@ -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<FCanvas*> 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<FCanvasTexture*>(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<FCanvas>();
|
||||
canvasTex->Canvas->Tex = canvasTex;
|
||||
canvasTex->Canvas->Drawer.SetSize(tex->GetTexelWidth(), tex->GetTexelHeight());
|
||||
AllCanvases.Push(canvasTex->Canvas);
|
||||
}
|
||||
return canvasTex->Canvas;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "hw_texcontainer.h"
|
||||
#include "floatrect.h"
|
||||
#include "refcounted.h"
|
||||
#include <memory>
|
||||
|
||||
typedef TMap<int, bool> SpriteHits;
|
||||
class FImageSource;
|
||||
|
|
|
@ -2926,7 +2926,6 @@ static void Doom_CastSpriteIDToString(FString* a, unsigned int b)
|
|||
|
||||
|
||||
extern DThinker* NextToThink;
|
||||
extern TArray<FCanvas*> 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++)
|
||||
|
|
|
@ -110,31 +110,6 @@ void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fo
|
|||
}
|
||||
}
|
||||
|
||||
TArray<FCanvas*> 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<FCanvasTexture*>(tex->GetTexture());
|
||||
if (!canvasTex->Canvas)
|
||||
{
|
||||
canvasTex->Canvas = Create<FCanvas>();
|
||||
canvasTex->Canvas->Tex = canvasTex;
|
||||
canvasTex->Canvas->Drawer.SetSize(tex->GetTexelWidth(), tex->GetTexelHeight());
|
||||
AllCanvases.Push(canvasTex->Canvas);
|
||||
}
|
||||
return canvasTex->Canvas;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FCanvasTextureInfo :: UpdateAll
|
||||
|
|
|
@ -24,5 +24,3 @@ struct FCanvasTextureInfo
|
|||
void Mark();
|
||||
|
||||
};
|
||||
|
||||
extern TArray<FCanvas*> AllCanvases;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue