aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/lights.cpp
blob: a996c2819cb2a787e702251e54819db536080786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "bladerunner/lights.h"

namespace BladeRunner {

Lights::Lights(BladeRunnerEngine *vm) {
	_vm = vm;

	_ambientLightColor.r = 1.0;
	_ambientLightColor.g = 0.0;
	_ambientLightColor.b = 0.0;
	
	_lights.clear();
	_frame = 0;
}

Lights::~Lights() {
	reset();
}

void Lights::read(Common::ReadStream *stream, int framesCount) {
	_ambientLightColor.r = stream->readFloatLE();
	_ambientLightColor.g = stream->readFloatLE();
	_ambientLightColor.b = stream->readFloatLE();

	uint _lightsCount = stream->readUint32LE();
	for (uint i = 0; i < _lightsCount; i++) {
		Light *light;
		int type = stream->readUint32LE();
		switch (type) {
		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 LightAmbient();
			break;
		default:
			light = new Light();
		}

		light->read(stream, framesCount, _frame, 0);
		_lights.push_back(light);
	}
}

void Lights::removeAnimated() {
	for (int i = (int)(_lights.size() - 1); i >= 0; i--) {
		if (_lights[i]->_animated) {
			delete _lights.remove_at(i);
		}
	}
}

void Lights::readVqa(Common::ReadStream *stream) {
	removeAnimated();
	if (stream->eos())
		return;

	int framesCount = stream->readUint32LE();
	int count = stream->readUint32LE();
	for (int i = 0; i < count; i++) {
		int lightType = stream->readUint32LE();
		Light *light;
		switch (lightType) {
		case 5:
			light = new LightAmbient();
			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();
		}		
		light->readVqa(stream, framesCount, _frame, 1);
		_lights.push_back(light);
	}
}

void Lights::setupFrame(int frame) {
	if (frame == _frame) {
		return;
	}

	for (uint i = 0; i < _lights.size(); i++) {
		_lights[i]->setupFrame(frame);
	}
}

void Lights::reset() {
	for (int i = (int)(_lights.size() - 1); i >= 0; i--) {
		delete _lights.remove_at(i);
	}
	_lights.clear();
}

} // End of namespace BladeRunner