aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/lights.cpp
blob: 7a6be94c6ddc332f47f150c62397e7c0a3d903fa (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#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 = NULL;
	_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();

	_lightsCount = stream->readUint32LE();
	int i;
	for (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 Light5();
			break;
		default:
			light = new Light();
		}

		light->read(stream, framesCount, _frame, 0);
		light->_next = _lights;
		_lights = 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);
	}
}

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 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();
		}
		light->readVqa(stream, framesCount, _frame, 1);
		light->_next = _lights;
		_lights = light;
	}
}

void Lights::setupFrame(int frame)
{
	Light *light;

	if (frame == _frame)
		return;

	if (!_lights)
		return;

	for (light = _lights; light; light = light->_next)
	{
		light->setupFrame(frame);
	}
}

void Lights::reset()
{
	Light *light;
	Light *nextLight;

	if (!_lights)
		return;

	do
	{
		light = _lights;
		nextLight = light->_next;
		delete light;
		_lights = nextLight;
	} while (nextLight);
}

} // End of namespace BladeRunner