From c7f7341f69b4f1b44c82b3693d7f51d9b570df46 Mon Sep 17 00:00:00 2001 From: Peter Kohaut Date: Thu, 29 Sep 2016 01:15:07 +0200 Subject: BLADERUNNER: fixed lightning --- engines/bladerunner/bladerunner.cpp | 2 +- engines/bladerunner/light.cpp | 174 ++++++++++++++++----------------- engines/bladerunner/light.h | 22 ++--- engines/bladerunner/lights.cpp | 63 ++++-------- engines/bladerunner/lights.h | 4 +- engines/bladerunner/slice_renderer.cpp | 114 ++++++++++----------- 6 files changed, 171 insertions(+), 208 deletions(-) (limited to 'engines') diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp index 41f1bb55d3..88d441db6c 100644 --- a/engines/bladerunner/bladerunner.cpp +++ b/engines/bladerunner/bladerunner.cpp @@ -723,7 +723,7 @@ void BladeRunnerEngine::handleMouseClick(int x, int y) { if (sceneObjectId == -1) { _actors[0]->loopWalkToXYZ(mousePosition); - debug("Clicked on nothing"); + debug("Clicked on nothing %f, %f, %f", mousePosition.x, mousePosition.y, mousePosition.z); return; } else if (sceneObjectId >= 0 && sceneObjectId <= 73) { handleMouseClickActor(x, y, sceneObjectId); diff --git a/engines/bladerunner/light.cpp b/engines/bladerunner/light.cpp index 39dc3e3a27..562936f75b 100644 --- a/engines/bladerunner/light.cpp +++ b/engines/bladerunner/light.cpp @@ -1,5 +1,6 @@ #include "bladerunner/light.h" #include "common/util.h" +#include "common/debug.h" namespace BladeRunner { @@ -23,25 +24,25 @@ void Light::read(Common::ReadStream *stream, int framesCount, int frame, int ani _animationData = new float[size / sizeof(float)]; stream->read(_animationData, size); - _m11ptr = _animationData; - _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); - _m13ptr = _m12ptr + (_animatedParameters & 0x2 ? framesCount : 1); - _m14ptr = _m13ptr + (_animatedParameters & 0x4 ? framesCount : 1); - _m21ptr = _m14ptr + (_animatedParameters & 0x8 ? framesCount : 1); - _m22ptr = _m21ptr + (_animatedParameters & 0x10 ? framesCount : 1); - _m23ptr = _m22ptr + (_animatedParameters & 0x20 ? framesCount : 1); - _m24ptr = _m23ptr + (_animatedParameters & 0x40 ? framesCount : 1); - _m31ptr = _m24ptr + (_animatedParameters & 0x80 ? framesCount : 1); - _m32ptr = _m31ptr + (_animatedParameters & 0x100 ? framesCount : 1); - _m33ptr = _m32ptr + (_animatedParameters & 0x200 ? framesCount : 1); - _m34ptr = _m33ptr + (_animatedParameters & 0x400 ? framesCount : 1); - _colorRPtr = _m34ptr + (_animatedParameters & 0x800 ? framesCount : 1); - _colorGPtr = _colorRPtr + (_animatedParameters & 0x1000 ? framesCount : 1); - _colorBPtr = _colorGPtr + (_animatedParameters & 0x2000 ? framesCount : 1); - _field16ptr = _colorGPtr + (_animatedParameters & 0x4000 ? framesCount : 1); - _field17ptr = _field16ptr + (_animatedParameters & 0x8000 ? framesCount : 1); - _field18ptr = _field17ptr + (_animatedParameters & 0x10000 ? framesCount : 1); - _field19ptr = _field18ptr + (_animatedParameters & 0x20000 ? framesCount : 1); + _m11ptr = _animationData; + _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); + _m13ptr = _m12ptr + (_animatedParameters & 0x2 ? framesCount : 1); + _m14ptr = _m13ptr + (_animatedParameters & 0x4 ? framesCount : 1); + _m21ptr = _m14ptr + (_animatedParameters & 0x8 ? framesCount : 1); + _m22ptr = _m21ptr + (_animatedParameters & 0x10 ? framesCount : 1); + _m23ptr = _m22ptr + (_animatedParameters & 0x20 ? framesCount : 1); + _m24ptr = _m23ptr + (_animatedParameters & 0x40 ? framesCount : 1); + _m31ptr = _m24ptr + (_animatedParameters & 0x80 ? framesCount : 1); + _m32ptr = _m31ptr + (_animatedParameters & 0x100 ? framesCount : 1); + _m33ptr = _m32ptr + (_animatedParameters & 0x200 ? framesCount : 1); + _m34ptr = _m33ptr + (_animatedParameters & 0x400 ? framesCount : 1); + _colorRPtr = _m34ptr + (_animatedParameters & 0x800 ? framesCount : 1); + _colorGPtr = _colorRPtr + (_animatedParameters & 0x1000 ? framesCount : 1); + _colorBPtr = _colorGPtr + (_animatedParameters & 0x2000 ? framesCount : 1); + _falloffStartPtr = _colorBPtr + (_animatedParameters & 0x4000 ? framesCount : 1); + _falloffEndPtr = _falloffStartPtr + (_animatedParameters & 0x8000 ? framesCount : 1); + _angleStartPtr = _falloffEndPtr + (_animatedParameters & 0x10000 ? framesCount : 1); + _angleEndPtr = _angleStartPtr + (_animatedParameters & 0x20000 ? framesCount : 1); setupFrame(frame); } @@ -57,83 +58,82 @@ void Light::readVqa(Common::ReadStream *stream, int framesCount, int frame, int _animationData = new float[size / sizeof(float)]; stream->read(_animationData, size); - _m11ptr = _animationData; - _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); - _m13ptr = _m12ptr + (_animatedParameters & 0x2 ? framesCount : 1); - _m14ptr = _m13ptr + (_animatedParameters & 0x4 ? framesCount : 1); - _m21ptr = _m14ptr + (_animatedParameters & 0x8 ? framesCount : 1); - _m22ptr = _m21ptr + (_animatedParameters & 0x10 ? framesCount : 1); - _m23ptr = _m22ptr + (_animatedParameters & 0x20 ? framesCount : 1); - _m24ptr = _m23ptr + (_animatedParameters & 0x40 ? framesCount : 1); - _m31ptr = _m24ptr + (_animatedParameters & 0x80 ? framesCount : 1); - _m32ptr = _m31ptr + (_animatedParameters & 0x100 ? framesCount : 1); - _m33ptr = _m32ptr + (_animatedParameters & 0x200 ? framesCount : 1); - _m34ptr = _m33ptr + (_animatedParameters & 0x400 ? framesCount : 1); - _colorRPtr = _m34ptr + (_animatedParameters & 0x800 ? framesCount : 1); - _colorGPtr = _colorRPtr + (_animatedParameters & 0x1000 ? framesCount : 1); - _colorBPtr = _colorGPtr + (_animatedParameters & 0x2000 ? framesCount : 1); - _field16ptr = _colorGPtr + (_animatedParameters & 0x4000 ? framesCount : 1); - _field17ptr = _field16ptr + (_animatedParameters & 0x8000 ? framesCount : 1); - _field18ptr = _field17ptr + (_animatedParameters & 0x10000 ? framesCount : 1); - _field19ptr = _field18ptr + (_animatedParameters & 0x20000 ? framesCount : 1); + _m11ptr = _animationData; + _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); + _m13ptr = _m12ptr + (_animatedParameters & 0x2 ? framesCount : 1); + _m14ptr = _m13ptr + (_animatedParameters & 0x4 ? framesCount : 1); + _m21ptr = _m14ptr + (_animatedParameters & 0x8 ? framesCount : 1); + _m22ptr = _m21ptr + (_animatedParameters & 0x10 ? framesCount : 1); + _m23ptr = _m22ptr + (_animatedParameters & 0x20 ? framesCount : 1); + _m24ptr = _m23ptr + (_animatedParameters & 0x40 ? framesCount : 1); + _m31ptr = _m24ptr + (_animatedParameters & 0x80 ? framesCount : 1); + _m32ptr = _m31ptr + (_animatedParameters & 0x100 ? framesCount : 1); + _m33ptr = _m32ptr + (_animatedParameters & 0x200 ? framesCount : 1); + _m34ptr = _m33ptr + (_animatedParameters & 0x400 ? framesCount : 1); + _colorRPtr = _m34ptr + (_animatedParameters & 0x800 ? framesCount : 1); + _colorGPtr = _colorRPtr + (_animatedParameters & 0x1000 ? framesCount : 1); + _colorBPtr = _colorGPtr + (_animatedParameters & 0x2000 ? framesCount : 1); + _falloffStartPtr = _colorBPtr + (_animatedParameters & 0x4000 ? framesCount : 1); + _falloffEndPtr = _falloffStartPtr + (_animatedParameters & 0x8000 ? framesCount : 1); + _angleStartPtr = _falloffEndPtr + (_animatedParameters & 0x10000 ? framesCount : 1); + _angleEndPtr = _angleStartPtr + (_animatedParameters & 0x20000 ? framesCount : 1); setupFrame(frame); } void Light::setupFrame(int frame) { int offset = frame % _framesCount; - _matrix._m[0][0] = (_animatedParameters & 0x1 ? _m11ptr[offset] : *_m11ptr); - _matrix._m[0][1] = (_animatedParameters & 0x2 ? _m12ptr[offset] : *_m12ptr); - _matrix._m[0][2] = (_animatedParameters & 0x4 ? _m13ptr[offset] : *_m13ptr); - _matrix._m[0][3] = (_animatedParameters & 0x8 ? _m14ptr[offset] : *_m14ptr); - _matrix._m[1][0] = (_animatedParameters & 0x10 ? _m21ptr[offset] : *_m21ptr); - _matrix._m[1][1] = (_animatedParameters & 0x20 ? _m22ptr[offset] : *_m22ptr); - _matrix._m[1][2] = (_animatedParameters & 0x40 ? _m23ptr[offset] : *_m23ptr); - _matrix._m[1][3] = (_animatedParameters & 0x80 ? _m24ptr[offset] : *_m24ptr); - _matrix._m[2][0] = (_animatedParameters & 0x100 ? _m31ptr[offset] : *_m31ptr); - _matrix._m[2][1] = (_animatedParameters & 0x200 ? _m32ptr[offset] : *_m32ptr); - _matrix._m[2][2] = (_animatedParameters & 0x400 ? _m33ptr[offset] : *_m33ptr); - _matrix._m[2][3] = (_animatedParameters & 0x800 ? _m34ptr[offset] : *_m34ptr); - _color.r = (_animatedParameters & 0x1000 ? _colorRPtr[offset] : *_colorRPtr); - _color.g = (_animatedParameters & 0x2000 ? _colorGPtr[offset] : *_colorGPtr); - _color.b = (_animatedParameters & 0x4000 ? _colorBPtr[offset] : *_colorBPtr); - _field16 = (_animatedParameters & 0x8000 ? _field16ptr[offset] : *_field16ptr); - _field17 = (_animatedParameters & 0x10000 ? _field17ptr[offset] : *_field17ptr); - _field18 = (_animatedParameters & 0x20000 ? _field18ptr[offset] : *_field18ptr); - _field19 = (_animatedParameters & 0x40000 ? _field19ptr[offset] : *_field19ptr); - + _matrix._m[0][0] = (_animatedParameters & 0x1 ? _m11ptr[offset] : *_m11ptr); + _matrix._m[0][1] = (_animatedParameters & 0x2 ? _m12ptr[offset] : *_m12ptr); + _matrix._m[0][2] = (_animatedParameters & 0x4 ? _m13ptr[offset] : *_m13ptr); + _matrix._m[0][3] = (_animatedParameters & 0x8 ? _m14ptr[offset] : *_m14ptr); + _matrix._m[1][0] = (_animatedParameters & 0x10 ? _m21ptr[offset] : *_m21ptr); + _matrix._m[1][1] = (_animatedParameters & 0x20 ? _m22ptr[offset] : *_m22ptr); + _matrix._m[1][2] = (_animatedParameters & 0x40 ? _m23ptr[offset] : *_m23ptr); + _matrix._m[1][3] = (_animatedParameters & 0x80 ? _m24ptr[offset] : *_m24ptr); + _matrix._m[2][0] = (_animatedParameters & 0x100 ? _m31ptr[offset] : *_m31ptr); + _matrix._m[2][1] = (_animatedParameters & 0x200 ? _m32ptr[offset] : *_m32ptr); + _matrix._m[2][2] = (_animatedParameters & 0x400 ? _m33ptr[offset] : *_m33ptr); + _matrix._m[2][3] = (_animatedParameters & 0x800 ? _m34ptr[offset] : *_m34ptr); + _color.r = (_animatedParameters & 0x1000 ? _colorRPtr[offset] : *_colorRPtr); + _color.g = (_animatedParameters & 0x2000 ? _colorGPtr[offset] : *_colorGPtr); + _color.b = (_animatedParameters & 0x4000 ? _colorBPtr[offset] : *_colorBPtr); + _falloffStart = (_animatedParameters & 0x8000 ? _falloffStartPtr[offset] : *_falloffStartPtr); + _falloffEnd = (_animatedParameters & 0x10000 ? _falloffEndPtr[offset] : *_falloffEndPtr); + _angleStart = (_animatedParameters & 0x20000 ? _angleStartPtr[offset] : *_angleStartPtr); + _angleEnd = (_animatedParameters & 0x40000 ? _angleEndPtr[offset] : *_angleEndPtr); } float Light::calculate(Vector3 start, Vector3 end) { - return calculateCoeficient(_matrix * start, _matrix * end, _field16, _field17); + return calculateCoefficient(_matrix * start, _matrix * end, _falloffStart, _falloffEnd); } void Light::calculateColor(Color *outColor, Vector3 position) { Vector3 positionT = _matrix * position; - float att = attenuation(_field16, _field17, positionT.length()); + float att = attenuation(_falloffStart, _falloffEnd, positionT.length()); outColor->r = _color.r * att; outColor->g = _color.g * att; outColor->b = _color.b * att; } -float Light::calculateCoeficient(Vector3 start, Vector3 end, float a3, float a4) { - if (a4 == 0.0f) { +float Light::calculateCoefficient(Vector3 start, Vector3 end, float falloffStart, float falloffEnd) { + if (falloffEnd == 0.0f) { return 1.0e30f; } - if (a3 >= start.length() && a3 >= end.length()) { + if (falloffStart >= start.length() && falloffStart >= end.length()) { return 1.0e30f; } float v40 = (end - start).length(); float v31 = 0.0f; if (v40 != 0.0f) { - Vector3 v27 = Vector3::cross(start, end); + Vector3 v27 = Vector3::cross(start, (end - start)); v31 = v27.length() / v40; } - if (v31 < a4) { - return 1.0f / (1.0f - (v31 / a4)); + if (v31 < falloffEnd) { + return 1.0f / (1.0f - (v31 / falloffEnd)); } return 1.0e30f; } @@ -147,7 +147,7 @@ float Light::attenuation(float min, float max, float distance) { float x = (max - distance) / (max - min); return x * x * (3.0f - 2.0f * x); } - if (min > distance) { + if (distance < min) { return 1.0f; } return 0.0f; @@ -158,15 +158,15 @@ float Light1::calculate(Vector3 start, Vector3 end) { end = _matrix * end; float v40 = 0.0f; - if (_field17 != 0.0f) { - v40 = calculateCoeficient(start, end, _field16, _field17); + if (_falloffEnd != 0.0f) { + v40 = calculateCoefficient(start, end, _falloffStart, _falloffEnd); } float v41 = atan2(start.length(), -start.z); float v42 = atan2(end.length(), -end.z); float v43; - if ((_field18 >= v41 && _field18 >= v42) || (_field19 <= v41 && _field19 <= v42)) { + if ((_angleStart >= v41 && _angleStart >= v42) || (_angleEnd <= v41 && _angleEnd <= v42)) { v43 = 1.0e30f; } else { v43 = 2.0; @@ -186,9 +186,9 @@ void Light1::calculateColor(Color *outColor, Vector3 position) { outColor->b = 0.0f; if (positionT.z < 0.0f) { - float v12 = attenuation(_field18, _field19, atan2(sqrt(positionT.x * positionT.x + positionT.y * positionT.y), -positionT.z)); - float v13 = attenuation(_field16, _field17, positionT.length()); - + float v12 = attenuation(_angleStart, _angleEnd, atan2(sqrt(positionT.x * positionT.x + positionT.y * positionT.y), -positionT.z)); + float v13 = attenuation(_falloffStart, _falloffEnd, positionT.length()); + outColor->r = v12 * v13 * _color.r; outColor->g = v12 * v13 * _color.g; outColor->b = v12 * v13 * _color.b; @@ -200,8 +200,8 @@ float Light2::calculate(Vector3 start, Vector3 end) { end = _matrix * end; float v54 = 0.0f; - if (_field17 != 0.0f) { - v54 = calculateCoeficient(start, end, _field16, _field17); + if (_falloffEnd != 0.0f) { + v54 = calculateCoefficient(start, end, _falloffStart, _falloffEnd); } float v55 = atan2(fabs(start.x), -start.z); @@ -210,7 +210,7 @@ float Light2::calculate(Vector3 start, Vector3 end) { float v56 = atan2(fabs(end.y), -end.z); float v59; - if ((_field18 >= v55 && _field18 >= v57 && _field18 >= v58 && _field18 >= v56) || (_field19 <= v55 && _field19 <= v57 && _field19 <= v58 && _field19 <= v56)) { + if ((_angleStart >= v55 && _angleStart >= v57 && _angleStart >= v58 && _angleStart >= v56) || (_angleEnd <= v55 && _angleEnd <= v57 && _angleEnd <= v58 && _angleEnd <= v56)) { v59 = 1.0e30f; } else { v59 = 2.0f; @@ -230,9 +230,9 @@ void Light2::calculateColor(Color *outColor, Vector3 position) { outColor->b = 0.0f; if (positionT.z < 0.0f) { - float v11 = attenuation(_field18, _field19, atan2(fabs(positionT.y), -positionT.z)); - float v12 = attenuation(_field18, _field19, atan2(fabs(positionT.x), -positionT.z)); - float v13 = attenuation(_field16, _field17, positionT.length()); + float v11 = attenuation(_angleStart, _angleEnd, atan2(fabs(positionT.y), -positionT.z)); + float v12 = attenuation(_angleStart, _angleEnd, atan2(fabs(positionT.x), -positionT.z)); + float v13 = attenuation(_falloffStart, _falloffEnd, positionT.length()); outColor->r = v11 * v12 * v13 * _color.r; outColor->g = v11 * v12 * v13 * _color.g; @@ -248,8 +248,8 @@ void Light3::calculateColor(Color *outColor, Vector3 position) { outColor->b = 0.0f; if (positionT.z < 0.0f) { - float v12 = attenuation(_field18, _field19, sqrt(positionT.x * positionT.x + positionT.y * positionT.y)); - float v13 = attenuation(_field16, _field17, positionT.length()); + float v12 = attenuation(_angleStart, _angleEnd, sqrt(positionT.x * positionT.x + positionT.y * positionT.y)); + float v13 = attenuation(_falloffStart, _falloffEnd, positionT.length()); outColor->r = v12 * v13 * _color.r; outColor->g = v12 * v13 * _color.g; @@ -265,21 +265,21 @@ void Light4::calculateColor(Color *outColor, Vector3 position) { outColor->b = 0.0f; if (positionT.z < 0.0f) { - float v11 = attenuation(_field18, _field19, fabs(positionT.y)); - float v12 = attenuation(_field18, _field19, fabs(positionT.x)); - float v13 = attenuation(_field16, _field17, positionT.length()); - + float v11 = attenuation(_angleStart, _angleEnd, fabs(positionT.y)); + float v12 = attenuation(_angleStart, _angleEnd, fabs(positionT.x)); + float v13 = attenuation(_falloffStart, _falloffEnd, positionT.length()); + outColor->r = v11 * v12 * v13 * _color.r; outColor->g = v11 * v12 * v13 * _color.g; outColor->b = v11 * v12 * v13 * _color.b; } } -float Light5::calculate(Vector3 start, Vector3 end) { +float LightAmbient::calculate(Vector3 start, Vector3 end) { return 1.0e30f; } -void Light5::calculateColor(Color *outColor, Vector3 position) { +void LightAmbient::calculateColor(Color *outColor, Vector3 position) { outColor->r = _color.r; outColor->g = _color.g; outColor->b = _color.b; diff --git a/engines/bladerunner/light.h b/engines/bladerunner/light.h index 9c2cdcb45c..29e0dd758d 100644 --- a/engines/bladerunner/light.h +++ b/engines/bladerunner/light.h @@ -51,10 +51,10 @@ protected: int _animatedParameters; Matrix4x3 _matrix; Color _color; - float _field16; - float _field17; - float _field18; - float _field19; + float _falloffStart; + float _falloffEnd; + float _angleStart; + float _angleEnd; float *_animationData; float *_m11ptr; float *_m12ptr; @@ -71,11 +71,11 @@ protected: float *_colorRPtr; float *_colorGPtr; float *_colorBPtr; - float *_field16ptr; - float *_field17ptr; - float *_field18ptr; - float *_field19ptr; - Light *_next; + float *_falloffStartPtr; + float *_falloffEndPtr; + float *_angleStartPtr; + float *_angleEndPtr; +// Light *_next; public: Light(); @@ -90,7 +90,7 @@ public: virtual void calculateColor(Color *outColor, Vector3 position); protected: - float calculateCoeficient(Vector3 start, Vector3 end, float a3, float a4); + float calculateCoefficient(Vector3 start, Vector3 end, float a3, float a4); float attenuation(float min, float max, float distance); }; @@ -112,7 +112,7 @@ class Light4 : public Light { void calculateColor(Color *outColor, Vector3 position); }; -class Light5 : public Light { +class LightAmbient : public Light { float calculate(Vector3 start, Vector3 end); void calculateColor(Color *outColor, Vector3 position); }; diff --git a/engines/bladerunner/lights.cpp b/engines/bladerunner/lights.cpp index 0d6a1be175..e8660a27db 100644 --- a/engines/bladerunner/lights.cpp +++ b/engines/bladerunner/lights.cpp @@ -8,9 +8,9 @@ Lights::Lights(BladeRunnerEngine *vm) { _ambientLightColor.r = 1.0; _ambientLightColor.g = 0.0; _ambientLightColor.b = 0.0; - - _lights = nullptr; + _lightsCount = 0; + _lights.clear(); _frame = 0; } @@ -42,34 +42,22 @@ void Lights::read(Common::ReadStream *stream, int framesCount) { light = new Light4(); break; case 5: - light = new Light5(); + light = new LightAmbient(); break; default: light = new Light(); } light->read(stream, framesCount, _frame, 0); - light->_next = _lights; - _lights = light; + _lights.push_back(light); } } void Lights::removeAnimated() { - Light **nextLight; - Light *light; - - nextLight = &this->_lights; - light = this->_lights; - if (light) { - do { - if (light->_animated) { - *nextLight = light->_next; - delete light; - } else { - nextLight = &light->_next; - } - light = *nextLight; - } while (*nextLight); + for (int i = (int)(_lights.size() - 1); i > 0; i--) { + if (_lights[i]->_animated) { + delete _lights.remove_at(i); + } } } @@ -85,7 +73,7 @@ void Lights::readVqa(Common::ReadStream *stream) { Light *light; switch (lightType) { case 5: - light = new Light5(); + light = new LightAmbient(); break; case 4: light = new Light4(); @@ -101,40 +89,27 @@ void Lights::readVqa(Common::ReadStream *stream) { break; default: light = new Light(); - } + } light->readVqa(stream, framesCount, _frame, 1); - light->_next = _lights; - _lights = light; + _lights.push_back(light); } } void Lights::setupFrame(int frame) { - Light *light; - - if (frame == _frame) - return; - - if (!_lights) + if (frame == _frame) { return; + } - for (light = _lights; light; light = light->_next) { - light->setupFrame(frame); + for (uint i = 0; i < _lights.size(); i++) { + _lights[i]->setupFrame(frame); } } void Lights::reset() { - Light *light; - Light *nextLight; - - if (!_lights) - return; - - do { - light = _lights; - nextLight = light->_next; - delete light; - _lights = nextLight; - } while (nextLight); + for (int i = (int)(_lights.size() - 1); i > 0; i--) { + delete _lights.remove_at(i); + } + _lights.clear(); } } // End of namespace BladeRunner diff --git a/engines/bladerunner/lights.h b/engines/bladerunner/lights.h index 2ba95b9060..486e6905e7 100644 --- a/engines/bladerunner/lights.h +++ b/engines/bladerunner/lights.h @@ -41,8 +41,8 @@ class Lights { Color _ambientLightColor; - int _lightsCount; - Light *_lights; + int _lightsCount; + Common::Array _lights; int _frame; //char gap[28]; diff --git a/engines/bladerunner/slice_renderer.cpp b/engines/bladerunner/slice_renderer.cpp index 8dad519feb..301f329794 100644 --- a/engines/bladerunner/slice_renderer.cpp +++ b/engines/bladerunner/slice_renderer.cpp @@ -363,9 +363,9 @@ void SliceRenderer::drawFrame(int animationId, int animationFrame, Vector3 posit ); SliceRendererLights sliceRendererLights = SliceRendererLights(_lights); - - _lights->setupFrame(_view._frame); - _setEffects->setupFrame(_view._frame); + + _lights->setupFrame(_frame); + _setEffects->setupFrame(_frame); float sliceLine = sliceLineIterator.line(); @@ -460,7 +460,7 @@ void SliceRenderer::drawSlice(int slice, uint16 *frameLinePtr, uint16 *zbufLineP continue; uint32 lastVertex = vertexCount - 1; - int lastVertexX = MAX((_m11lookup[p[3*lastVertex]] + _m12lookup[p[3*lastVertex+1]] + _m13) >> 16, 0); + int lastVertexX = MAX((_m11lookup[p[3 * lastVertex]] + _m12lookup[p[3 * lastVertex + 1]] + _m13) >> 16, 0); int previousVertexX = lastVertexX; @@ -473,13 +473,13 @@ void SliceRenderer::drawSlice(int slice, uint16 *frameLinePtr, uint16 *zbufLineP if (vertexZ >= 0 && vertexZ < 65536) { Color256 color = palette.color[p[2]]; - float hackMul = 8.0f; //not part of game + color.r = (int)(_setEffectColor.r + _lightsColor.r * color.r) >> 16; + color.g = (int)(_setEffectColor.g + _lightsColor.g * color.g) >> 16; + color.b = (int)(_setEffectColor.b + _lightsColor.b * color.b) >> 16; - color.r = (int)(_setEffectColor.r + hackMul * _lightsColor.r * color.r) >> 13; // >> 16, - color.g = (int)(_setEffectColor.g + hackMul * _lightsColor.g * color.g) >> 13; - color.b = (int)(_setEffectColor.b + hackMul * _lightsColor.b * color.b) >> 13; + int bladeToScummVmConstant = 256 / 32; - int color555 = _pixelFormat.RGBToColor(color.r/* * 8*/, color.g/* * 8*/, color.b/* * 8*/); + int color555 = _pixelFormat.RGBToColor(CLIP(color.r * bladeToScummVmConstant, 0, 255), CLIP(color.g * bladeToScummVmConstant, 0, 255), CLIP(color.b * bladeToScummVmConstant, 0, 255)); for (int x = previousVertexX; x != vertexX; ++x) { if (vertexZ < zbufLinePtr[x]) { @@ -530,34 +530,27 @@ void SliceRenderer::SliceRendererLights::calculateColorBase(Vector3 position1, V _finalColor.b = 0.0f; _hmm3 = 0; if (_lights) { - Light *light = _lights->_lights; - int i = 0; - if (light) { - do { - if (i < 20) { - float v8 = light->calculate(position1, position2/*, height*/); - - this->_hmm2[i] = v8; - this->_hmm[i] = v8; - - Color v22; - light->calculateColor(&v22, position1); - _colors[i] = v22; - _finalColor.r += v22.r; - _finalColor.g += v22.g; - _finalColor.b += v22.b; - } - else - { - Color v23; - light->calculateColor(&v23, position1); - _finalColor.r += v23.r; - _finalColor.g += v23.g; - _finalColor.b += v23.b; - } - light = light->_next; - i++; - } while (light); + for(uint i = 0; i < _lights->_lights.size(); i++) { + Light *light = _lights->_lights[i]; + if (i < 20) { + float v8 = light->calculate(position1, position2/*, height*/); + + this->_hmm2[i] = v8; + this->_hmm[i] = v8; + + Color v22; + light->calculateColor(&v22, position1); + _colors[i] = v22; + _finalColor.r += v22.r; + _finalColor.g += v22.g; + _finalColor.b += v22.b; + } else { + Color v23; + light->calculateColor(&v23, position1); + _finalColor.r += v23.r; + _finalColor.g += v23.g; + _finalColor.b += v23.b; + } } _finalColor.r += _lights->_ambientLightColor.r; @@ -572,34 +565,29 @@ void SliceRenderer::SliceRendererLights::calculateColorSlice(Vector3 position) { _finalColor.b = 0.0f; if (_lights) { - Light *light = _lights->_lights; - int i = 0; - if (light) { - do { - if (i < 20) { - _hmm[i] = _hmm[i] - 1.0f; - - if (_hmm[i] <= 0.0f) { - do { - _hmm[i] = _hmm[i] + _hmm2[i]; - } while (_hmm[i] <= 0.0f); - light->calculateColor(&_colors[i], position); - _hmm3++; - } - _finalColor.r += _colors[i].r; - _finalColor.g += _colors[i].g; - _finalColor.b += _colors[i].b; - } else { - Color color; - light->calculateColor(&color, position); + for (uint i = 0; i < _lights->_lights.size(); i++) { + Light *light = _lights->_lights[i]; + if (i < 20) { + _hmm[i] = _hmm[i] - 1.0f; + + if (_hmm[i] <= 0.0f) { + do { + _hmm[i] = _hmm[i] + _hmm2[i]; + } while (_hmm[i] <= 0.0f); + light->calculateColor(&_colors[i], position); _hmm3++; - _finalColor.r += color.r; - _finalColor.g += color.g; - _finalColor.b += color.b; } - light = light->_next; - i++; - } while (light); + _finalColor.r += _colors[i].r; + _finalColor.g += _colors[i].g; + _finalColor.b += _colors[i].b; + } else { + Color color; + light->calculateColor(&color, position); + _hmm3++; + _finalColor.r += color.r; + _finalColor.g += color.g; + _finalColor.b += color.b; + } } _finalColor.r += _lights->_ambientLightColor.r; _finalColor.g += _lights->_ambientLightColor.g; -- cgit v1.2.3