mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-05 00:36:57 +00:00
SLUDGE: Use a byte array instead of a double array for the Z-Buffer
This commit is contained in:
parent
e774d8ba96
commit
00e72a1700
@ -149,7 +149,7 @@ bool GraphicsManager::initGfx() {
|
||||
initGraphics(_winWidth, _winHeight, _vm->getScreenPixelFormat());
|
||||
_renderSurface.create(_winWidth, _winHeight, *_vm->getScreenPixelFormat());
|
||||
|
||||
_zBufferSurface = new double[_winWidth * _winHeight];
|
||||
_zBufferSurface = new uint8[_winWidth * _winHeight];
|
||||
|
||||
if (!killResizeBackdrop(_winWidth, _winHeight))
|
||||
return fatal("Couldn't allocate memory for backdrop");
|
||||
|
@ -158,8 +158,8 @@ public:
|
||||
void saveZBuffer(Common::WriteStream *stream);
|
||||
bool loadZBuffer(Common::SeekableReadStream *stream);
|
||||
|
||||
void drawSpriteToZBuffer(int x, int y, double depth, const Graphics::Surface &surface);
|
||||
void fillZBuffer(double d);
|
||||
void drawSpriteToZBuffer(int x, int y, uint8 depth, const Graphics::Surface &surface);
|
||||
void fillZBuffer(uint8 d);
|
||||
|
||||
// Colors
|
||||
void setBlankColor(int r, int g, int b) { _currentBlankColour = _renderSurface.format.RGBToColor(r & 255, g & 255, b & 255);};
|
||||
@ -209,7 +209,7 @@ private:
|
||||
Graphics::Surface _renderSurface;
|
||||
|
||||
// Z Buffer Surface
|
||||
double *_zBufferSurface = nullptr;
|
||||
uint8 *_zBufferSurface = nullptr;
|
||||
|
||||
// Snapshot
|
||||
Graphics::Surface _snapshotSurface;
|
||||
|
@ -462,7 +462,7 @@ bool GraphicsManager::scaleSprite(Sprite &single, const SpritePalette &fontPal,
|
||||
y2 = y1 + diffY;
|
||||
}
|
||||
|
||||
float z;
|
||||
uint8 z;
|
||||
|
||||
if (useZB && _zBuffer->numPanels) {
|
||||
int i;
|
||||
@ -472,9 +472,9 @@ bool GraphicsManager::scaleSprite(Sprite &single, const SpritePalette &fontPal,
|
||||
break;
|
||||
}
|
||||
}
|
||||
z = 0.999 - (double)i * (1.0 / 128.0);
|
||||
z = ((i + 1) * 2) + 1;
|
||||
} else {
|
||||
z = -0.5;
|
||||
z = 0xFF;
|
||||
}
|
||||
|
||||
Graphics::Surface *blitted = &single.surface;
|
||||
@ -537,7 +537,7 @@ void GraphicsManager::fixScaleSprite(int x, int y, Sprite &single, const SpriteP
|
||||
x1 = x - (int)((mirror ? (float)(single.surface.w - (single.xhot + 1)) : (float)single.xhot) * scale);
|
||||
int y1 = y - (int)((single.yhot - thisPerson->floaty) * scale);
|
||||
|
||||
float z;
|
||||
uint8 z;
|
||||
|
||||
if (useZB && _zBuffer->numPanels) {
|
||||
int i;
|
||||
@ -547,9 +547,9 @@ void GraphicsManager::fixScaleSprite(int x, int y, Sprite &single, const SpriteP
|
||||
break;
|
||||
}
|
||||
}
|
||||
z = 0.999 - (double)i * (1.0 / 128.0);
|
||||
z = ((i + 1) * 2) + 1;
|
||||
} else {
|
||||
z = -0.5;
|
||||
z = 0xFF;
|
||||
}
|
||||
|
||||
Graphics::Surface *blitted = &single.surface;
|
||||
|
@ -157,15 +157,11 @@ bool GraphicsManager::setZBuffer(int num) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphicsManager::fillZBuffer(double d) {
|
||||
for (uint y = 0; y < _winHeight; y++) {
|
||||
for (uint x = 0; x < _winWidth; x++) {
|
||||
_zBufferSurface[y*_winWidth + x] = d;
|
||||
}
|
||||
}
|
||||
void GraphicsManager::fillZBuffer(uint8 d) {
|
||||
memset(_zBufferSurface, d, _winHeight * _winWidth);
|
||||
}
|
||||
|
||||
void GraphicsManager::drawSpriteToZBuffer(int x, int y, double depth, const Graphics::Surface &surface) {
|
||||
void GraphicsManager::drawSpriteToZBuffer(int x, int y, uint8 depth, const Graphics::Surface &surface) {
|
||||
|
||||
for (uint y1 = 0; y1 < (uint)surface.h; y1++) {
|
||||
for (uint x1 = 0; x1 < (uint)surface.w; x1++) {
|
||||
@ -176,7 +172,7 @@ void GraphicsManager::drawSpriteToZBuffer(int x, int y, double depth, const Grap
|
||||
byte *target = (byte *)_renderSurface.getBasePtr(x1 + x, y1 + y);
|
||||
const byte *source = (const byte *)surface.getBasePtr(x1, y1);
|
||||
|
||||
if (depth <= _zBufferSurface[(y1 + y) * _sceneWidth + (x1 + x)]) {
|
||||
if (depth > _zBufferSurface[(y1 + y) * _sceneWidth + (x1 + x)]) {
|
||||
|
||||
if (source[0] == 0xff) {
|
||||
// Completely opaque, so copy RGB values over
|
||||
@ -195,23 +191,22 @@ void GraphicsManager::drawZBuffer(int x, int y, bool upsidedown) {
|
||||
if (!_zBuffer->numPanels || !_zBuffer->tex)
|
||||
return;
|
||||
|
||||
fillZBuffer(1.0);
|
||||
int i;
|
||||
fillZBuffer(0);
|
||||
|
||||
for (uint y1 = y; y1 < _zBuffer->height + y; y1++) {
|
||||
for (uint x1 = x; x1 < _zBuffer->width + x; x1++) {
|
||||
|
||||
double z = 1.0f;
|
||||
uint8 z = 0;
|
||||
|
||||
if (upsidedown) {
|
||||
z = 1.0 - (double)_zBuffer->tex[(_zBuffer->height - y1) * _zBuffer->width + x1] * (1.0 / 128.0);
|
||||
z = (_zBuffer->tex[(_zBuffer->height - y1) * _zBuffer->width + x1] + 1) * 2;
|
||||
} else {
|
||||
z = 1.0 - (double)_zBuffer->tex[y1 * _zBuffer->width + x1] * (1.0 / 128.0);
|
||||
z = (_zBuffer->tex[y1 * _zBuffer->width + x1] + 1) * 2;
|
||||
}
|
||||
|
||||
if ( z < _zBufferSurface[y1 * _winWidth + x1]) {
|
||||
|
||||
if ( z > _zBufferSurface[y1 * _winWidth + x1])
|
||||
_zBufferSurface[y1 * _winWidth + x1] = z;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user