From 47bfbb5e0825c01a80c813f3f08f0f5a86674e98 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 14:18:19 +0100 Subject: [PATCH] - Make BuildTexture inherit from worldtexture. - handle WorldTextures that can change their content automatically. --- src/textures/buildtexture.cpp | 67 +++-------------------------------- src/textures/worldtexture.cpp | 6 +++- 2 files changed, 9 insertions(+), 64 deletions(-) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index dd95455531..7223286675 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -48,18 +48,14 @@ // //========================================================================== -class FBuildTexture : public FTexture +class FBuildTexture : public FWorldTexture { public: FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top); - ~FBuildTexture (); - - const uint8_t *GetColumn (unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + uint8_t *MakeTexture(FRenderStyle style) override { return const_cast(Pixels); } // This is only to make it compile for now and will be changed later. protected: const uint8_t *Pixels; - Span **Spans; }; @@ -70,8 +66,9 @@ protected: //========================================================================== FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int height, int left, int top) -: Pixels (pixels), Spans (NULL) +: Pixels (pixels) { + PixelsAreStatic = 3; Width = width; Height = height; LeftOffset = left; @@ -81,62 +78,6 @@ FBuildTexture::FBuildTexture (int tilenum, const uint8_t *pixels, int width, int UseType = TEX_Build; } -//========================================================================== -// -// -// -//========================================================================== - -FBuildTexture::~FBuildTexture () -{ - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FBuildTexture::GetPixels () -{ - return Pixels; -} - -//========================================================================== -// -// -// -//========================================================================== - -const uint8_t *FBuildTexture::GetColumn (unsigned int column, const Span **spans_out) -{ - if (column >= Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - //=========================================================================== // // AddTiles diff --git a/src/textures/worldtexture.cpp b/src/textures/worldtexture.cpp index 0370bf3e81..8968902360 100644 --- a/src/textures/worldtexture.cpp +++ b/src/textures/worldtexture.cpp @@ -91,7 +91,7 @@ void FWorldTexture::Unload () // //========================================================================== -const uint8_t *FWorldTexture::GetColumn (unsigned int column, const Span **spans_out) +const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_out) { GetPixels(); if ((unsigned)column >= (unsigned)Width) @@ -124,6 +124,10 @@ const uint8_t *FWorldTexture::GetColumn (unsigned int column, const Span **spans const uint8_t *FWorldTexture::GetPixels () { + if (CheckModified()) + { + Unload(); + } if (Pixeldata[0] == nullptr) { Pixeldata[0] = MakeTexture (LegacyRenderStyles[STYLE_Normal]);