forked from rosebudai/OpenRCT2-Web
Use PaletteIndex in RenderTarget (#25948)
This commit is contained in:
1 parent
4ad964c03d
commit
4878894a7e
28 files changed
+139
-125
No files matched your search
@@ -272,7 +272,7 @@ private:
|
||||
SDL_RenderPresent(_sdlRenderer);
|
||||
}
|
||||
|
||||
void CopyBitsToTexture(SDL_Texture* texture, uint8_t* src, int32_t width, int32_t height, const uint32_t* palette)
|
||||
void CopyBitsToTexture(SDL_Texture* texture, PaletteIndex* src, int32_t width, int32_t height, const uint32_t* palette)
|
||||
{
|
||||
void* pixels;
|
||||
int32_t pitch;
|
||||
@@ -284,7 +284,7 @@ private:
|
||||
uint32_t* dst = static_cast<uint32_t*>(pixels);
|
||||
for (int32_t i = width * height; i > 0; i--)
|
||||
{
|
||||
*dst++ = palette[*src++];
|
||||
*dst++ = palette[EnumValue(*src++)];
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -296,8 +296,8 @@ private:
|
||||
{
|
||||
for (int32_t x = width; x > 0; x--)
|
||||
{
|
||||
const uint8_t lower = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
|
||||
const uint8_t upper = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
|
||||
const uint8_t lower = *reinterpret_cast<const uint8_t*>(&palette[EnumValue(*src++)]);
|
||||
const uint8_t upper = *reinterpret_cast<const uint8_t*>(&palette[EnumValue(*src++)]);
|
||||
*dst++ = (lower << 8) | upper;
|
||||
}
|
||||
dst = reinterpret_cast<uint16_t*>(reinterpret_cast<uint8_t*>(dst) + padding);
|
||||
@@ -310,7 +310,7 @@ private:
|
||||
{
|
||||
for (int32_t x = width; x > 0; x--)
|
||||
{
|
||||
*dst++ = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
|
||||
*dst++ = *reinterpret_cast<const uint8_t*>(&palette[EnumValue(*src++)]);
|
||||
}
|
||||
dst += padding;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ private:
|
||||
uint32_t _height = 0;
|
||||
uint32_t _pitch = 0;
|
||||
size_t _bitsSize = 0;
|
||||
std::unique_ptr<uint8_t[]> _bits;
|
||||
std::unique_ptr<PaletteIndex[]> _bits;
|
||||
|
||||
RenderTarget _mainRT = {};
|
||||
|
||||
@@ -485,8 +485,8 @@ public:
|
||||
framebuffer.GetPixels(_mainRT);
|
||||
|
||||
int32_t stride = _mainRT.LineStride();
|
||||
uint8_t* to = _mainRT.bits + y * stride + x;
|
||||
uint8_t* from = _mainRT.bits + (y - dy) * stride + x - dx;
|
||||
PaletteIndex* to = _mainRT.bits + y * stride + x;
|
||||
PaletteIndex* from = _mainRT.bits + (y - dy) * stride + x - dx;
|
||||
|
||||
if (dy > 0)
|
||||
{
|
||||
@@ -552,10 +552,10 @@ private:
|
||||
{
|
||||
size_t newBitsSize = pitch * height;
|
||||
|
||||
auto newBits = std::make_unique<uint8_t[]>(newBitsSize);
|
||||
auto newBits = std::make_unique<PaletteIndex[]>(newBitsSize);
|
||||
if (_bits == nullptr)
|
||||
{
|
||||
std::fill_n(newBits.get(), newBitsSize, 0);
|
||||
std::fill_n(newBits.get(), newBitsSize, PaletteIndex::transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -565,8 +565,8 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t* src = _bits.get();
|
||||
uint8_t* dst = newBits.get();
|
||||
PaletteIndex* src = _bits.get();
|
||||
PaletteIndex* dst = newBits.get();
|
||||
|
||||
uint32_t minWidth = std::min(_width, width);
|
||||
uint32_t minHeight = std::min(_height, height);
|
||||
@@ -575,7 +575,7 @@ private:
|
||||
std::copy_n(src, minWidth, dst);
|
||||
if (pitch - minWidth > 0)
|
||||
{
|
||||
std::fill_n(dst + minWidth, pitch - minWidth, 0);
|
||||
std::fill_n(dst + minWidth, pitch - minWidth, PaletteIndex::transparent);
|
||||
}
|
||||
src += _pitch;
|
||||
dst += pitch;
|
||||
|
||||
@@ -184,14 +184,14 @@ void OpenGLFramebuffer::GetPixels(Drawing::RenderTarget& rt) const
|
||||
{
|
||||
assert(rt.width == _width && rt.height == _height);
|
||||
|
||||
auto pixels = std::make_unique<uint8_t[]>(_width * _height);
|
||||
auto pixels = std::make_unique<Drawing::PaletteIndex[]>(_width * _height);
|
||||
glCall(glBindTexture, GL_TEXTURE_2D, _texture);
|
||||
glCall(glPixelStorei, GL_PACK_ALIGNMENT, 1);
|
||||
glCall(glGetTexImage, GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, pixels.get());
|
||||
|
||||
// Flip pixels vertically on copy
|
||||
uint8_t* src = pixels.get() + ((_height - 1) * _width);
|
||||
uint8_t* dst = rt.bits;
|
||||
Drawing::PaletteIndex* src = pixels.get() + ((_height - 1) * _width);
|
||||
Drawing::PaletteIndex* dst = rt.bits;
|
||||
for (int32_t y = 0; y < _height; y++)
|
||||
{
|
||||
std::copy_n(src, _width, dst);
|
||||
@@ -204,10 +204,10 @@ void OpenGLFramebuffer::SetPixels(const Drawing::RenderTarget& rt)
|
||||
{
|
||||
assert(rt.width == _width && rt.height == _height);
|
||||
|
||||
auto pixels = std::make_unique<uint8_t[]>(_width * _height);
|
||||
auto pixels = std::make_unique<Drawing::PaletteIndex[]>(_width * _height);
|
||||
// Flip pixels vertically on copy
|
||||
uint8_t* dst = pixels.get() + ((_height - 1) * _width);
|
||||
uint8_t* src = rt.bits;
|
||||
Drawing::PaletteIndex* dst = pixels.get() + ((_height - 1) * _width);
|
||||
Drawing::PaletteIndex* src = rt.bits;
|
||||
for (int32_t y = 0; y < _height; y++)
|
||||
{
|
||||
std::copy_n(src, _width, dst);
|
||||
|
||||
@@ -213,7 +213,7 @@ void TextureCache::GeneratePaletteTexture()
|
||||
// Init no-op palette
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
rt.bits[i] = i;
|
||||
rt.bits[i] = static_cast<PaletteIndex>(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < kPaletteTotalOffsets; ++i)
|
||||
@@ -390,8 +390,8 @@ void TextureCache::FreeTextures()
|
||||
RenderTarget TextureCache::CreateRT(int32_t width, int32_t height)
|
||||
{
|
||||
size_t numPixels = width * height;
|
||||
auto pixels8 = new uint8_t[numPixels];
|
||||
std::fill_n(pixels8, numPixels, 0);
|
||||
auto pixels8 = new PaletteIndex[numPixels];
|
||||
std::fill_n(pixels8, numPixels, PaletteIndex::transparent);
|
||||
|
||||
RenderTarget rt;
|
||||
rt.bits = pixels8;
|
||||
|
||||
@@ -449,7 +449,7 @@ namespace OpenRCT2::Scripting
|
||||
if (createNewImage)
|
||||
{
|
||||
auto bufferSize = size.width * size.height;
|
||||
rt.bits = new uint8_t[bufferSize];
|
||||
rt.bits = new PaletteIndex[bufferSize];
|
||||
std::memset(rt.bits, 0, bufferSize);
|
||||
|
||||
drawingEngine->BeginDraw();
|
||||
@@ -461,7 +461,7 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
else
|
||||
{
|
||||
rt.bits = g1->offset;
|
||||
rt.bits = reinterpret_cast<PaletteIndex*>(g1->offset);
|
||||
}
|
||||
|
||||
auto dukG = GetObjectAsDukValue(ctx, std::make_shared<ScGraphicsContext>(ctx, rt));
|
||||
@@ -477,7 +477,7 @@ namespace OpenRCT2::Scripting
|
||||
delete[] g1->offset;
|
||||
newg1 = *g1;
|
||||
}
|
||||
newg1.offset = rt.bits;
|
||||
newg1.offset = reinterpret_cast<uint8_t*>(rt.bits);
|
||||
newg1.width = size.width;
|
||||
newg1.height = size.height;
|
||||
newg1.flags = {};
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::unique_ptr<TrackDesign> _trackDesign;
|
||||
std::string _trackPath;
|
||||
std::string _trackName;
|
||||
std::vector<uint8_t> _trackDesignPreviewPixels;
|
||||
TrackDesignPreviewBuffer _trackDesignPreviewPixels{};
|
||||
|
||||
public:
|
||||
void setupTrack(const utf8* path, std::unique_ptr<TrackDesign> trackDesign)
|
||||
@@ -79,7 +79,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
_trackDesign = std::move(trackDesign);
|
||||
_trackPath = path;
|
||||
_trackName = GetNameFromTrackPath(path);
|
||||
_trackDesignPreviewPixels.resize(4 * kTrackPreviewImageSize);
|
||||
std::fill(_trackDesignPreviewPixels.begin(), _trackDesignPreviewPixels.end(), PaletteIndex::transparent);
|
||||
|
||||
UpdatePreview();
|
||||
invalidate();
|
||||
@@ -97,8 +97,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
_trackPath.clear();
|
||||
_trackName.clear();
|
||||
_trackDesignPreviewPixels.clear();
|
||||
_trackDesignPreviewPixels.shrink_to_fit();
|
||||
_trackDesign = nullptr;
|
||||
}
|
||||
|
||||
@@ -162,7 +160,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
Rectangle::fill(rt, { screenPos, screenPos + ScreenCoordsXY{ 369, 216 } }, colour);
|
||||
|
||||
G1Element g1temp = {};
|
||||
g1temp.offset = _trackDesignPreviewPixels.data() + (_currentTrackPieceDirection * kTrackPreviewImageSize);
|
||||
g1temp.offset = reinterpret_cast<uint8_t*>(
|
||||
_trackDesignPreviewPixels.data() + (_currentTrackPieceDirection * kTrackPreviewImageSize));
|
||||
g1temp.width = 370;
|
||||
g1temp.height = 217;
|
||||
g1temp.flags = { G1Flag::hasTransparency };
|
||||
@@ -361,7 +360,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
private:
|
||||
void UpdatePreview()
|
||||
{
|
||||
TrackDesignDrawPreview(*_trackDesign, _trackDesignPreviewPixels.data(), !gTrackDesignSceneryToggle);
|
||||
TrackDesignDrawPreview(*_trackDesign, _trackDesignPreviewPixels, !gTrackDesignSceneryToggle);
|
||||
}
|
||||
|
||||
void InstallTrackDesign()
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::vector<uint16_t> _filteredTrackIds;
|
||||
uint16_t _loadedTrackDesignIndex;
|
||||
std::unique_ptr<TrackDesign> _loadedTrackDesign;
|
||||
std::vector<uint8_t> _trackDesignPreviewPixels;
|
||||
TrackDesignPreviewBuffer _trackDesignPreviewPixels{};
|
||||
bool _selectedItemIsBeingUpdated;
|
||||
bool _reloadTrackDesigns;
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
_loadedTrackDesign = TrackDesignImport(path.c_str());
|
||||
if (_loadedTrackDesign != nullptr)
|
||||
{
|
||||
TrackDesignDrawPreview(*_loadedTrackDesign, _trackDesignPreviewPixels.data(), !gTrackDesignSceneryToggle);
|
||||
TrackDesignDrawPreview(*_loadedTrackDesign, _trackDesignPreviewPixels, !gTrackDesignSceneryToggle);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -238,7 +238,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
gTrackDesignSceneryToggle = false;
|
||||
WindowPushOthersRight(*this);
|
||||
_currentTrackPieceDirection = 2;
|
||||
_trackDesignPreviewPixels.resize(4 * kTrackPreviewImageSize);
|
||||
std::fill(_trackDesignPreviewPixels.begin(), _trackDesignPreviewPixels.end(), PaletteIndex::transparent);
|
||||
|
||||
_loadedTrackDesign = nullptr;
|
||||
_loadedTrackDesignIndex = kTrackDesignIndexUnloaded;
|
||||
@@ -256,8 +256,6 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
// Dispose track design and preview
|
||||
_loadedTrackDesign = nullptr;
|
||||
_trackDesignPreviewPixels.clear();
|
||||
_trackDesignPreviewPixels.shrink_to_fit();
|
||||
|
||||
// Dispose track list
|
||||
_trackDesigns.clear();
|
||||
@@ -510,7 +508,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
screenPos = windowPos + ScreenCoordsXY{ tdWidget.midX(), tdWidget.midY() };
|
||||
|
||||
G1Element g1temp = {};
|
||||
g1temp.offset = _trackDesignPreviewPixels.data() + (_currentTrackPieceDirection * kTrackPreviewImageSize);
|
||||
g1temp.offset = reinterpret_cast<uint8_t*>(
|
||||
_trackDesignPreviewPixels.data() + (_currentTrackPieceDirection * kTrackPreviewImageSize));
|
||||
g1temp.width = 370;
|
||||
g1temp.height = 217;
|
||||
g1temp.flags = { G1Flag::hasTransparency };
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
bool SpriteImageExport(const G1Element& spriteElement, u8string_view outPath)
|
||||
{
|
||||
const size_t pixelBufferSize = static_cast<size_t>(spriteElement.width) * spriteElement.height;
|
||||
auto pixelBuffer = std::make_unique<uint8_t[]>(pixelBufferSize);
|
||||
auto pixelBuffer = std::make_unique<PaletteIndex[]>(pixelBufferSize);
|
||||
auto pixels = pixelBuffer.get();
|
||||
|
||||
RenderTarget rt;
|
||||
@@ -142,7 +142,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
ImageId(), PaletteMap::GetDefault(), spriteElement, 0, 0, spriteElement.width, spriteElement.height, pixels);
|
||||
GfxSpriteToBuffer(rt, args);
|
||||
|
||||
auto const pixels8 = rt.bits;
|
||||
auto const pixels8 = reinterpret_cast<uint8_t*>(rt.bits);
|
||||
auto const pixelsLen = rt.LineStride() * rt.WorldHeight();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -9,14 +9,17 @@
|
||||
|
||||
#include "../core/Guard.hpp"
|
||||
#include "Drawing.h"
|
||||
#include "PaletteIndex.h"
|
||||
|
||||
using OpenRCT2::Drawing::PaletteIndex;
|
||||
|
||||
#ifdef __AVX2__
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
void MaskAvx2(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
if (width == 32)
|
||||
{
|
||||
@@ -48,8 +51,8 @@ void MaskAvx2(
|
||||
#endif
|
||||
|
||||
void MaskAvx2(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
OpenRCT2::Guard::Fail("AVX2 function called on a CPU that doesn't support AVX2");
|
||||
}
|
||||
|
||||
@@ -392,15 +392,15 @@ static void ReadAndConvertGxDat(IStream* stream, size_t count, bool is_rctc, G1E
|
||||
}
|
||||
|
||||
void MaskScalar(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
for (int32_t yy = 0; yy < height; yy++)
|
||||
{
|
||||
for (int32_t xx = 0; xx < width; xx++)
|
||||
{
|
||||
uint8_t colour = (*colourSrc) & (*maskSrc);
|
||||
if (colour != 0)
|
||||
auto colour = static_cast<PaletteIndex>((*colourSrc) & (*maskSrc));
|
||||
if (colour != PaletteIndex::transparent)
|
||||
{
|
||||
*dst = colour;
|
||||
}
|
||||
@@ -417,7 +417,7 @@ void MaskScalar(
|
||||
|
||||
static void MaskMagnify(
|
||||
const ZoomLevel zoom, int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
uint8_t* RESTRICT dst, int32_t maskStride, int32_t colourStride, int32_t dstStride, int32_t srcX, int32_t srcY)
|
||||
PaletteIndex* RESTRICT dst, int32_t maskStride, int32_t colourStride, int32_t dstStride, int32_t srcX, int32_t srcY)
|
||||
{
|
||||
for (int32_t y = 0; y < height; y++)
|
||||
{
|
||||
@@ -426,8 +426,8 @@ static void MaskMagnify(
|
||||
{
|
||||
auto srcMask = maskSrc + (maskStride * zoom.ApplyTo(srcY + y) + zoom.ApplyTo(srcX + x));
|
||||
auto srcColour = colourSrc + (colourStride * zoom.ApplyTo(srcY + y) + zoom.ApplyTo(srcX + x));
|
||||
const uint8_t colour = (*srcColour) & (*srcMask);
|
||||
if (colour != 0)
|
||||
const auto colour = static_cast<PaletteIndex>((*srcColour) & (*srcMask));
|
||||
if (colour != PaletteIndex::transparent)
|
||||
{
|
||||
*dst = colour;
|
||||
}
|
||||
@@ -824,7 +824,7 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
|
||||
const int32_t offsetY = rt.y - spriteTopLeft.y;
|
||||
const int32_t srcX = std::max(0, offsetX);
|
||||
const int32_t srcY = std::max(0, offsetY);
|
||||
uint8_t* dst = rt.bits + std::max(0, -offsetX) + std::max(0, -offsetY) * rt.LineStride();
|
||||
PaletteIndex* dst = rt.bits + std::max(0, -offsetX) + std::max(0, -offsetY) * rt.LineStride();
|
||||
|
||||
DrawSpriteArgs args(imageId, paletteMap, *g1, srcX, srcY, width, height, dst);
|
||||
GfxSpriteToBuffer(rt, args);
|
||||
@@ -941,7 +941,7 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
|
||||
|
||||
dest_start_x = zoomLevel.ApplyInversedTo(dest_start_x);
|
||||
|
||||
uint8_t* dest_pointer = rt.bits;
|
||||
PaletteIndex* dest_pointer = rt.bits;
|
||||
// Move the pointer to the start point of the destination
|
||||
dest_pointer += (zoomLevel.ApplyInversedTo(rt.WorldWidth()) + rt.pitch) * dest_start_y + dest_start_x;
|
||||
|
||||
@@ -1008,7 +1008,7 @@ void FASTCALL GfxDrawSpriteRawMaskedSoftware(
|
||||
if (width < 0 || height < 0)
|
||||
return;
|
||||
|
||||
uint8_t* dst = rt.bits + (left - rt.x) + ((top - rt.y) * rt.LineStride());
|
||||
PaletteIndex* dst = rt.bits + (left - rt.x) + ((top - rt.y) * rt.LineStride());
|
||||
int32_t skipX = left - offsetCoords.x;
|
||||
int32_t skipY = top - offsetCoords.y;
|
||||
if (zoom < ZoomLevel{ 0 })
|
||||
|
||||
@@ -58,11 +58,11 @@ struct DrawSpriteArgs
|
||||
int32_t SrcY;
|
||||
int32_t Width;
|
||||
int32_t Height;
|
||||
uint8_t* DestinationBits;
|
||||
OpenRCT2::Drawing::PaletteIndex* DestinationBits;
|
||||
|
||||
DrawSpriteArgs(
|
||||
ImageId image, const OpenRCT2::Drawing::PaletteMap& palMap, const OpenRCT2::G1Element& sourceImage, int32_t srcX,
|
||||
int32_t srcY, int32_t width, int32_t height, uint8_t* destinationBits)
|
||||
int32_t srcY, int32_t width, int32_t height, OpenRCT2::Drawing::PaletteIndex* destinationBits)
|
||||
: Image(image)
|
||||
, PalMap(palMap)
|
||||
, SourceImage(sourceImage)
|
||||
@@ -180,5 +180,5 @@ void FASTCALL GfxDrawSpriteRawMaskedSoftware(
|
||||
size_t G1CalculateDataSize(const OpenRCT2::G1Element* g1);
|
||||
|
||||
void MaskScalar(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
OpenRCT2::Drawing::PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
@@ -499,8 +499,8 @@ static auto GetMaskFunction()
|
||||
static const auto MaskFunc = GetMaskFunction();
|
||||
|
||||
void MaskFn(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
MaskFunc(width, height, maskSrc, colourSrc, dst, maskWrap, colourWrap, dstWrap);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace OpenRCT2::Drawing
|
||||
{
|
||||
struct IDrawingEngine;
|
||||
enum class FilterPaletteID : int32_t;
|
||||
enum class PaletteIndex : uint8_t;
|
||||
} // namespace OpenRCT2::Drawing
|
||||
|
||||
namespace OpenRCT2::Drawing
|
||||
@@ -129,15 +130,15 @@ void TTFDrawString(
|
||||
bool noFormatting, FontStyle fontStyle, TextDarkness darkness);
|
||||
|
||||
void MaskSse4_1(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
OpenRCT2::Drawing::PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
void MaskAvx2(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
OpenRCT2::Drawing::PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
|
||||
void MaskFn(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
OpenRCT2::Drawing::PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||
|
||||
std::optional<uint32_t> GetPaletteG1Index(OpenRCT2::Drawing::FilterPaletteID paletteId);
|
||||
std::optional<OpenRCT2::Drawing::PaletteMap> GetPaletteMapForColour(OpenRCT2::Drawing::FilterPaletteID paletteId);
|
||||
|
||||
@@ -1025,7 +1025,7 @@ namespace OpenRCT2::Drawing::LightFx
|
||||
}
|
||||
|
||||
void RenderToTexture(
|
||||
const Viewport& vp, void* dstPixels, uint32_t dstPitch, uint8_t* bits, uint32_t width, uint32_t height,
|
||||
const Viewport& vp, void* dstPixels, uint32_t dstPitch, PaletteIndex* bits, uint32_t width, uint32_t height,
|
||||
const uint32_t* palette, const uint32_t* lightPalette)
|
||||
{
|
||||
UpdateViewportSettings(vp);
|
||||
@@ -1045,9 +1045,9 @@ namespace OpenRCT2::Drawing::LightFx
|
||||
uint32_t* dst = reinterpret_cast<uint32_t*>(reinterpret_cast<uintptr_t>(dstPixels) + dstOffset);
|
||||
for (uint32_t x = 0; x < width; x++)
|
||||
{
|
||||
uint8_t* src = &bits[y * width + x];
|
||||
uint32_t darkColour = palette[*src];
|
||||
uint32_t lightColour = lightPalette[*src];
|
||||
PaletteIndex src = bits[y * width + x];
|
||||
uint32_t darkColour = palette[EnumValue(src)];
|
||||
uint32_t lightColour = lightPalette[EnumValue(src)];
|
||||
uint8_t lightIntensity = lightBits[y * width + x];
|
||||
|
||||
uint32_t colour = 0;
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace OpenRCT2
|
||||
namespace OpenRCT2::Drawing
|
||||
{
|
||||
struct RenderTarget;
|
||||
}
|
||||
enum class PaletteIndex : uint8_t;
|
||||
} // namespace OpenRCT2::Drawing
|
||||
|
||||
namespace OpenRCT2::Drawing::LightFx
|
||||
{
|
||||
@@ -72,7 +73,7 @@ namespace OpenRCT2::Drawing::LightFx
|
||||
|
||||
void ApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b);
|
||||
void RenderToTexture(
|
||||
const Viewport& vp, void* dstPixels, uint32_t dstPitch, uint8_t* bits, uint32_t width, uint32_t height,
|
||||
const Viewport& vp, void* dstPixels, uint32_t dstPitch, Drawing::PaletteIndex* bits, uint32_t width, uint32_t height,
|
||||
const uint32_t* palette, const uint32_t* lightPalette);
|
||||
|
||||
} // namespace OpenRCT2::Drawing::LightFx
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Drawing
|
||||
enum class PaletteIndex : uint8_t
|
||||
{
|
||||
transparent = 0,
|
||||
fontFill = 1,
|
||||
|
||||
pi10 = 10, // Black (0-dark), Dark grey (0)
|
||||
pi11 = 11, // Black (middark)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace OpenRCT2::Drawing
|
||||
{
|
||||
uint8_t* RenderTarget::GetBitsOffset(const ScreenCoordsXY& pos) const
|
||||
PaletteIndex* RenderTarget::GetBitsOffset(const ScreenCoordsXY& pos) const
|
||||
{
|
||||
return bits + pos.x + pos.y * LineStride();
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
namespace OpenRCT2::Drawing
|
||||
{
|
||||
struct IDrawingEngine;
|
||||
enum class PaletteIndex : uint8_t;
|
||||
|
||||
struct RenderTarget
|
||||
{
|
||||
uint8_t* bits{};
|
||||
PaletteIndex* bits{};
|
||||
int32_t x{};
|
||||
int32_t y{};
|
||||
int32_t width{};
|
||||
@@ -35,7 +36,7 @@ namespace OpenRCT2::Drawing
|
||||
|
||||
IDrawingEngine* DrawingEngine{};
|
||||
|
||||
uint8_t* GetBitsOffset(const ScreenCoordsXY& pos) const;
|
||||
PaletteIndex* GetBitsOffset(const ScreenCoordsXY& pos) const;
|
||||
RenderTarget Crop(const ScreenCoordsXY& pos, const ScreenSize& size) const;
|
||||
|
||||
[[nodiscard]] constexpr int32_t WorldX() const
|
||||
|
||||
@@ -9,14 +9,17 @@
|
||||
|
||||
#include "../core/Guard.hpp"
|
||||
#include "Drawing.h"
|
||||
#include "PaletteIndex.h"
|
||||
|
||||
using OpenRCT2::Drawing::PaletteIndex;
|
||||
|
||||
#ifdef __SSE4_1__
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
void MaskSse4_1(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
if (width == 32)
|
||||
{
|
||||
@@ -62,8 +65,8 @@ void MaskSse4_1(
|
||||
#endif
|
||||
|
||||
void MaskSse4_1(
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc,
|
||||
PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap)
|
||||
{
|
||||
OpenRCT2::Guard::Fail("SSE 4.1 function called on a CPU that doesn't support SSE 4.1");
|
||||
}
|
||||
|
||||
@@ -52,15 +52,15 @@ namespace OpenRCT2::Drawing::ScrollingText
|
||||
|
||||
static void initialiseCharacterBitmaps(uint32_t glyphStart, uint16_t count)
|
||||
{
|
||||
uint8_t drawingSurface[64];
|
||||
PaletteIndex drawingSurface[64];
|
||||
RenderTarget rt;
|
||||
rt.bits = reinterpret_cast<uint8_t*>(&drawingSurface);
|
||||
rt.bits = drawingSurface;
|
||||
rt.width = 8;
|
||||
rt.height = 8;
|
||||
|
||||
for (int32_t i = 0; i < count; i++)
|
||||
{
|
||||
std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00);
|
||||
std::fill_n(drawingSurface, sizeof(drawingSurface), PaletteIndex::transparent);
|
||||
GfxDrawSpriteSoftware(rt, ImageId(glyphStart + (EnumValue(FontStyle::tiny) * count) + i), { -1, 0 });
|
||||
|
||||
for (int32_t x = 0; x < 8; x++)
|
||||
@@ -69,8 +69,8 @@ namespace OpenRCT2::Drawing::ScrollingText
|
||||
for (int32_t y = 0; y < 8; y++)
|
||||
{
|
||||
val >>= 1;
|
||||
uint8_t pixel = rt.bits[x + y * 8];
|
||||
if (pixel == 1)
|
||||
PaletteIndex pixel = rt.bits[x + y * 8];
|
||||
if (pixel == PaletteIndex::fontFill)
|
||||
{
|
||||
val |= 0x80;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void X8WeatherDrawer::Draw(
|
||||
uint32_t pixelOffset = rt.LineStride() * y + x;
|
||||
uint8_t patternYPos = patternStartYOffset % patternYSpace;
|
||||
|
||||
uint8_t* screenBits = rt.bits;
|
||||
PaletteIndex* screenBits = rt.bits;
|
||||
|
||||
// Stores the colours of changed pixels
|
||||
WeatherPixel* newPixels = &_weatherPixels[_weatherPixelsCount];
|
||||
@@ -78,8 +78,8 @@ void X8WeatherDrawer::Draw(
|
||||
auto patternPixel = pattern[patternYPos * 2 + 1];
|
||||
for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace)
|
||||
{
|
||||
uint8_t current_pixel = screenBits[xPixelOffset];
|
||||
screenBits[xPixelOffset] = patternPixel;
|
||||
PaletteIndex current_pixel = screenBits[xPixelOffset];
|
||||
screenBits[xPixelOffset] = static_cast<PaletteIndex>(patternPixel);
|
||||
_weatherPixelsCount++;
|
||||
|
||||
// Store colour and position
|
||||
@@ -99,7 +99,7 @@ void X8WeatherDrawer::Restore(RenderTarget& rt)
|
||||
if (_weatherPixelsCount > 0)
|
||||
{
|
||||
uint32_t numPixels = rt.LineStride() * rt.height;
|
||||
uint8_t* bits = rt.bits;
|
||||
PaletteIndex* bits = rt.bits;
|
||||
for (uint32_t i = 0; i < _weatherPixelsCount; i++)
|
||||
{
|
||||
WeatherPixel weatherPixel = _weatherPixels[i];
|
||||
@@ -226,8 +226,8 @@ void X8DrawingEngine::CopyRect(int32_t x, int32_t y, int32_t width, int32_t heig
|
||||
height += tmargin + bmargin;
|
||||
|
||||
int32_t stride = _mainRT.LineStride();
|
||||
uint8_t* to = _mainRT.bits + y * stride + x;
|
||||
uint8_t* from = _mainRT.bits + (y - dy) * stride + x - dx;
|
||||
PaletteIndex* to = _mainRT.bits + y * stride + x;
|
||||
PaletteIndex* from = _mainRT.bits + (y - dy) * stride + x - dx;
|
||||
|
||||
if (dy > 0)
|
||||
{
|
||||
@@ -279,10 +279,10 @@ RenderTarget* X8DrawingEngine::getRT()
|
||||
void X8DrawingEngine::ConfigureBits(uint32_t width, uint32_t height, uint32_t pitch)
|
||||
{
|
||||
size_t newBitsSize = pitch * height;
|
||||
uint8_t* newBits = new uint8_t[newBitsSize];
|
||||
PaletteIndex* newBits = new PaletteIndex[newBitsSize];
|
||||
if (_bits == nullptr)
|
||||
{
|
||||
std::fill_n(newBits, newBitsSize, 0);
|
||||
std::fill_n(newBits, newBitsSize, PaletteIndex::transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -292,8 +292,8 @@ void X8DrawingEngine::ConfigureBits(uint32_t width, uint32_t height, uint32_t pi
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t* src = _bits;
|
||||
uint8_t* dst = newBits;
|
||||
PaletteIndex* src = _bits;
|
||||
PaletteIndex* dst = newBits;
|
||||
|
||||
uint32_t minWidth = std::min(_width, width);
|
||||
uint32_t minHeight = std::min(_height, height);
|
||||
@@ -302,7 +302,7 @@ void X8DrawingEngine::ConfigureBits(uint32_t width, uint32_t height, uint32_t pi
|
||||
std::copy_n(src, minWidth, dst);
|
||||
if (pitch - minWidth > 0)
|
||||
{
|
||||
std::fill_n(dst + minWidth, pitch - minWidth, 0);
|
||||
std::fill_n(dst + minWidth, pitch - minWidth, PaletteIndex::transparent);
|
||||
}
|
||||
src += _pitch;
|
||||
dst += pitch;
|
||||
@@ -375,11 +375,11 @@ void X8DrawingContext::Clear(RenderTarget& rt, PaletteIndex paletteIndex)
|
||||
|
||||
int32_t w = rt.width;
|
||||
int32_t h = rt.height;
|
||||
uint8_t* ptr = rt.bits;
|
||||
PaletteIndex* ptr = rt.bits;
|
||||
|
||||
for (int32_t y = 0; y < h; y++)
|
||||
{
|
||||
std::fill_n(ptr, w, EnumValue(paletteIndex));
|
||||
std::fill_n(ptr, w, paletteIndex);
|
||||
ptr += w + rt.pitch;
|
||||
}
|
||||
}
|
||||
@@ -437,10 +437,10 @@ void X8DrawingContext::FillRect(
|
||||
if (crossHatch)
|
||||
{
|
||||
// Cross hatching
|
||||
uint8_t* dst = startY * rt.LineStride() + startX + rt.bits;
|
||||
PaletteIndex* dst = startY * rt.LineStride() + startX + rt.bits;
|
||||
for (int32_t i = 0; i < height; i++)
|
||||
{
|
||||
uint8_t* nextdst = dst + rt.LineStride();
|
||||
PaletteIndex* nextdst = dst + rt.LineStride();
|
||||
uint32_t p = Numerics::ror32(crosskPattern, 1);
|
||||
p = (p & 0xFFFF0000) | width;
|
||||
|
||||
@@ -450,7 +450,7 @@ void X8DrawingContext::FillRect(
|
||||
p = p ^ 0x80000000;
|
||||
if (p & 0x80000000)
|
||||
{
|
||||
*dst = EnumValue(paletteIndex);
|
||||
*dst = paletteIndex;
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
@@ -460,10 +460,10 @@ void X8DrawingContext::FillRect(
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t* dst = startY * rt.LineStride() + startX + rt.bits;
|
||||
PaletteIndex* dst = startY * rt.LineStride() + startX + rt.bits;
|
||||
for (int32_t i = 0; i < height; i++)
|
||||
{
|
||||
std::fill_n(dst, width, EnumValue(paletteIndex));
|
||||
std::fill_n(dst, width, paletteIndex);
|
||||
dst += rt.LineStride();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRCT2
|
||||
struct WeatherPixel
|
||||
{
|
||||
uint32_t Position;
|
||||
uint8_t Colour;
|
||||
PaletteIndex Colour;
|
||||
};
|
||||
|
||||
static constexpr uint32_t kMaxWeatherPixels = 0xFFFE;
|
||||
@@ -64,7 +64,7 @@ namespace OpenRCT2
|
||||
uint32_t _height = 0;
|
||||
uint32_t _pitch = 0;
|
||||
size_t _bitsSize = 0;
|
||||
uint8_t* _bits = nullptr;
|
||||
PaletteIndex* _bits = nullptr;
|
||||
|
||||
RenderTarget _mainRT = {};
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ uint8_t gScreenshotCountdown = 0;
|
||||
|
||||
static bool WriteRTToFile(std::string_view path, const RenderTarget& rt, const GamePalette& palette)
|
||||
{
|
||||
auto const pixels8 = rt.bits;
|
||||
auto const pixels8 = reinterpret_cast<uint8_t*>(rt.bits);
|
||||
auto const pixelsLen = rt.LineStride() * rt.height;
|
||||
try
|
||||
{
|
||||
@@ -233,7 +233,7 @@ static RenderTarget CreateRT(const Viewport& viewport)
|
||||
RenderTarget rt;
|
||||
rt.width = viewport.width;
|
||||
rt.height = viewport.height;
|
||||
rt.bits = new (std::nothrow) uint8_t[rt.width * rt.height];
|
||||
rt.bits = new (std::nothrow) PaletteIndex[rt.width * rt.height];
|
||||
if (rt.bits == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Giant screenshot failed, unable to allocate memory for image.");
|
||||
|
||||
@@ -231,7 +231,7 @@ namespace OpenRCT2
|
||||
drawingEngine->BeginDraw();
|
||||
|
||||
Drawing::RenderTarget rt{
|
||||
.bits = reinterpret_cast<uint8_t*>(image.pixels),
|
||||
.bits = image.pixels,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = image.width,
|
||||
|
||||
@@ -287,10 +287,10 @@ namespace OpenRCT2
|
||||
constexpr uint8_t kCentreX = kWidth / 2;
|
||||
constexpr uint8_t kCentreY = kHeight / 2;
|
||||
|
||||
uint8_t bitmap[kHeight][kWidth] = { 0 };
|
||||
Drawing::PaletteIndex bitmap[kHeight][kWidth]{};
|
||||
|
||||
Drawing::RenderTarget rt = {
|
||||
.bits = reinterpret_cast<uint8_t*>(bitmap),
|
||||
.bits = reinterpret_cast<Drawing::PaletteIndex*>(bitmap),
|
||||
.x = -(kWidth / 2),
|
||||
.y = -(kHeight / 2),
|
||||
.width = kWidth,
|
||||
@@ -310,7 +310,7 @@ namespace OpenRCT2
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[j][kCentreX - i] != 0)
|
||||
if (bitmap[j][kCentreX - i] != Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteWidth = i;
|
||||
break;
|
||||
@@ -322,7 +322,7 @@ namespace OpenRCT2
|
||||
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[j][kCentreX + i] != 0)
|
||||
if (bitmap[j][kCentreX + i] != Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteWidth = i;
|
||||
break;
|
||||
@@ -339,7 +339,7 @@ namespace OpenRCT2
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[kCentreY - i][j] != 0)
|
||||
if (bitmap[kCentreY - i][j] != Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteHeightNegative = i;
|
||||
break;
|
||||
@@ -356,7 +356,7 @@ namespace OpenRCT2
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[kCentreY + i][j] != 0)
|
||||
if (bitmap[kCentreY + i][j] != Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteHeightPositive = i;
|
||||
break;
|
||||
|
||||
@@ -51,10 +51,10 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
|
||||
constexpr uint8_t kCentreX = kWidth / 2;
|
||||
constexpr uint8_t kCentreY = kHeight / 2;
|
||||
|
||||
uint8_t bitmap[kHeight][kWidth] = { 0 };
|
||||
OpenRCT2::Drawing::PaletteIndex bitmap[kHeight][kWidth]{};
|
||||
|
||||
OpenRCT2::Drawing::RenderTarget rt = {
|
||||
.bits = reinterpret_cast<uint8_t*>(bitmap),
|
||||
.bits = reinterpret_cast<OpenRCT2::Drawing::PaletteIndex*>(bitmap),
|
||||
.x = -(kWidth / 2),
|
||||
.y = -(kHeight / 2),
|
||||
.width = kWidth,
|
||||
@@ -73,7 +73,7 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[j][kCentreX - i] != 0)
|
||||
if (bitmap[j][kCentreX - i] != OpenRCT2::Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteWidth = i;
|
||||
break;
|
||||
@@ -85,7 +85,7 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
|
||||
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[j][kCentreX + i] != 0)
|
||||
if (bitmap[j][kCentreX + i] != OpenRCT2::Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteWidth = i;
|
||||
break;
|
||||
@@ -102,7 +102,7 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[kCentreY - i][j] != 0)
|
||||
if (bitmap[kCentreY - i][j] != OpenRCT2::Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteHeightNegative = i;
|
||||
break;
|
||||
@@ -119,7 +119,7 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
|
||||
{
|
||||
for (int32_t j = 0; j < kWidth; j++)
|
||||
{
|
||||
if (bitmap[kCentreY + i][j] != 0)
|
||||
if (bitmap[kCentreY + i][j] != OpenRCT2::Drawing::PaletteIndex::transparent)
|
||||
{
|
||||
spriteHeightPositive = i;
|
||||
break;
|
||||
|
||||
@@ -2069,7 +2069,7 @@ bool TrackDesignSceneryElement::operator!=(const TrackDesignSceneryElement& rhs)
|
||||
*
|
||||
* rct2: 0x006D1EF0
|
||||
*/
|
||||
void TrackDesignDrawPreview(TrackDesign& td, uint8_t* pixels, bool placeScenery)
|
||||
void TrackDesignDrawPreview(TrackDesign& td, TrackDesignPreviewBuffer& pixels, bool placeScenery)
|
||||
{
|
||||
StashMap();
|
||||
TrackDesignPreviewClearMap();
|
||||
@@ -2085,7 +2085,7 @@ void TrackDesignDrawPreview(TrackDesign& td, uint8_t* pixels, bool placeScenery)
|
||||
TrackDesignGameStateData updatedGameStateData = td.gameStateData;
|
||||
if (!TrackDesignPlacePreview(tds, td, &ride, updatedGameStateData, placeScenery))
|
||||
{
|
||||
std::fill_n(pixels, kTrackPreviewImageSize * 4, 0x00);
|
||||
std::fill(std::begin(pixels), std::end(pixels), PaletteIndex::transparent);
|
||||
UnstashMap();
|
||||
return;
|
||||
}
|
||||
@@ -2138,7 +2138,7 @@ void TrackDesignDrawPreview(TrackDesign& td, uint8_t* pixels, bool placeScenery)
|
||||
rt.width = 370;
|
||||
rt.height = 217;
|
||||
rt.pitch = 0;
|
||||
rt.bits = pixels;
|
||||
rt.bits = pixels.data();
|
||||
|
||||
auto drawingEngine = std::make_unique<X8DrawingEngine>(GetContext()->GetUiContext());
|
||||
rt.DrawingEngine = drawingEngine.get();
|
||||
@@ -2146,10 +2146,10 @@ void TrackDesignDrawPreview(TrackDesign& td, uint8_t* pixels, bool placeScenery)
|
||||
drawingEngine->BeginDraw();
|
||||
|
||||
const ScreenCoordsXY offset = { size_x / 2, size_y / 2 };
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
for (Direction direction = 0; direction < kNumOrthogonalDirections; direction++)
|
||||
{
|
||||
view.viewPos = Translate3DTo2DWithZ(i, centre) - offset;
|
||||
view.rotation = i;
|
||||
view.viewPos = Translate3DTo2DWithZ(direction, centre) - offset;
|
||||
view.rotation = direction;
|
||||
ViewportRender(rt, &view);
|
||||
|
||||
rt.bits += kTrackPreviewImageSize;
|
||||
|
||||
@@ -28,6 +28,11 @@ enum class ViewportInteractionItem : uint8_t;
|
||||
|
||||
constexpr uint32_t kTrackPreviewImageSize = 370 * 217;
|
||||
|
||||
namespace OpenRCT2::Drawing
|
||||
{
|
||||
enum class PaletteIndex : uint8_t;
|
||||
}
|
||||
|
||||
enum class TrackPlaceOperation : uint8_t
|
||||
{
|
||||
drawOutlines,
|
||||
@@ -249,7 +254,8 @@ int32_t TrackDesignGetZPlacement(const TrackDesign& td, Ride& ride, const Coords
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Track design preview
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void TrackDesignDrawPreview(TrackDesign& td, uint8_t* pixels, bool placeScenery);
|
||||
using TrackDesignPreviewBuffer = std::array<OpenRCT2::Drawing::PaletteIndex, kTrackPreviewImageSize * kNumOrthogonalDirections>;
|
||||
void TrackDesignDrawPreview(TrackDesign& td, TrackDesignPreviewBuffer& pixels, bool placeScenery);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Track design saving
|
||||
|
||||
Reference in new issue
Block a user