2015-09-13 01:48:13 +02:00
|
|
|
#include "bladerunner/lights.h"
|
|
|
|
|
|
|
|
namespace BladeRunner {
|
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
Lights::Lights(BladeRunnerEngine *vm) {
|
2016-09-10 18:16:17 +02:00
|
|
|
_vm = vm;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
_ambientLightColor.r = 1.0;
|
|
|
|
_ambientLightColor.g = 0.0;
|
|
|
|
_ambientLightColor.b = 0.0;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-20 00:33:06 +02:00
|
|
|
_lights = nullptr;
|
2016-09-26 23:38:35 +02:00
|
|
|
_lightsCount = 0;
|
2016-09-10 18:16:17 +02:00
|
|
|
_frame = 0;
|
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
Lights::~Lights() {
|
2016-09-10 18:16:17 +02:00
|
|
|
reset();
|
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
void Lights::read(Common::ReadStream *stream, int framesCount) {
|
2016-09-10 18:16:17 +02:00
|
|
|
_ambientLightColor.r = stream->readFloatLE();
|
|
|
|
_ambientLightColor.g = stream->readFloatLE();
|
|
|
|
_ambientLightColor.b = stream->readFloatLE();
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
_lightsCount = stream->readUint32LE();
|
|
|
|
int i;
|
2016-09-26 23:38:35 +02:00
|
|
|
for (i = 0; i < _lightsCount; i++) {
|
2016-09-10 18:16:17 +02:00
|
|
|
Light *light;
|
|
|
|
int type = stream->readUint32LE();
|
2016-09-26 23:38:35 +02:00
|
|
|
switch (type) {
|
2016-09-10 18:16:17 +02:00
|
|
|
case 1:
|
|
|
|
light = new Light1();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
light = new Light2();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
light = new Light3();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
light = new Light4();
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
light = new Light5();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
light = new Light();
|
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
light->read(stream, framesCount, _frame, 0);
|
|
|
|
light->_next = _lights;
|
|
|
|
_lights = light;
|
2015-09-13 01:48:13 +02:00
|
|
|
}
|
2016-09-10 18:16:17 +02:00
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
void Lights::removeAnimated() {
|
2016-09-10 18:33:04 +02:00
|
|
|
Light **nextLight;
|
2016-09-26 23:38:35 +02:00
|
|
|
Light *light;
|
2016-09-10 18:33:04 +02:00
|
|
|
|
|
|
|
nextLight = &this->_lights;
|
|
|
|
light = this->_lights;
|
2016-09-26 23:38:35 +02:00
|
|
|
if (light) {
|
|
|
|
do {
|
|
|
|
if (light->_animated) {
|
2016-09-10 18:33:04 +02:00
|
|
|
*nextLight = light->_next;
|
|
|
|
delete light;
|
2016-09-26 23:38:35 +02:00
|
|
|
} else {
|
2016-09-10 18:33:04 +02:00
|
|
|
nextLight = &light->_next;
|
|
|
|
}
|
|
|
|
light = *nextLight;
|
|
|
|
} while (*nextLight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
void Lights::readVqa(Common::ReadStream *stream) {
|
2016-09-10 18:33:04 +02:00
|
|
|
removeAnimated();
|
|
|
|
if (stream->eos())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int framesCount = stream->readUint32LE();
|
|
|
|
int count = stream->readUint32LE();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
int lightType = stream->readUint32LE();
|
2016-09-26 23:38:35 +02:00
|
|
|
Light *light;
|
|
|
|
switch (lightType) {
|
|
|
|
case 5:
|
|
|
|
light = new Light5();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
light = new Light4();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
light = new Light3();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
light = new Light2();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
light = new Light1();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
light = new Light();
|
2016-09-10 18:33:04 +02:00
|
|
|
}
|
|
|
|
light->readVqa(stream, framesCount, _frame, 1);
|
|
|
|
light->_next = _lights;
|
|
|
|
_lights = light;
|
|
|
|
}
|
2016-09-10 18:16:17 +02:00
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
void Lights::setupFrame(int frame) {
|
2016-09-10 18:16:17 +02:00
|
|
|
Light *light;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
if (frame == _frame)
|
|
|
|
return;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
if (!_lights)
|
|
|
|
return;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
for (light = _lights; light; light = light->_next) {
|
2016-09-10 18:16:17 +02:00
|
|
|
light->setupFrame(frame);
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
void Lights::reset() {
|
2016-09-10 18:16:17 +02:00
|
|
|
Light *light;
|
|
|
|
Light *nextLight;
|
2015-09-13 01:48:13 +02:00
|
|
|
|
2016-09-10 18:16:17 +02:00
|
|
|
if (!_lights)
|
|
|
|
return;
|
|
|
|
|
2016-09-26 23:38:35 +02:00
|
|
|
do {
|
2016-09-10 18:16:17 +02:00
|
|
|
light = _lights;
|
|
|
|
nextLight = light->_next;
|
|
|
|
delete light;
|
|
|
|
_lights = nextLight;
|
|
|
|
} while (nextLight);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace BladeRunner
|