1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "bladerunner/lights.h"
24
25 namespace BladeRunner {
26
Lights(BladeRunnerEngine * vm)27 Lights::Lights(BladeRunnerEngine *vm) {
28 _vm = vm;
29
30 _ambientLightColor.r = 1.0;
31 _ambientLightColor.g = 0.0;
32 _ambientLightColor.b = 0.0;
33
34 _frame = 0;
35 }
36
~Lights()37 Lights::~Lights() {
38 reset();
39 }
40
read(Common::ReadStream * stream,int frameCount)41 void Lights::read(Common::ReadStream *stream, int frameCount) {
42 _ambientLightColor.r = stream->readFloatLE();
43 _ambientLightColor.g = stream->readFloatLE();
44 _ambientLightColor.b = stream->readFloatLE();
45
46 uint _lightCount = stream->readUint32LE();
47 for (uint i = 0; i < _lightCount; ++i) {
48 Light *light;
49 int type = stream->readUint32LE();
50 switch (type) {
51 case 1:
52 light = new Light1();
53 break;
54 case 2:
55 light = new Light2();
56 break;
57 case 3:
58 light = new Light3();
59 break;
60 case 4:
61 light = new Light4();
62 break;
63 case 5:
64 light = new LightAmbient();
65 break;
66 default:
67 light = new Light();
68 }
69
70 light->read(stream, frameCount, _frame, 0);
71 _lights.push_back(light);
72 }
73 }
74
removeAnimated()75 void Lights::removeAnimated() {
76 for (int i = (int)(_lights.size() - 1); i >= 0; --i) {
77 if (_lights[i]->_animated) {
78 delete _lights.remove_at(i);
79 }
80 }
81 }
82
readVqa(Common::ReadStream * stream)83 void Lights::readVqa(Common::ReadStream *stream) {
84 removeAnimated();
85 if (stream->eos()) {
86 return;
87 }
88
89 int frameCount = stream->readUint32LE();
90 int count = stream->readUint32LE();
91 for (int i = 0; i < count; ++i) {
92 int lightType = stream->readUint32LE();
93 Light *light;
94 switch (lightType) {
95 case 5:
96 light = new LightAmbient();
97 break;
98 case 4:
99 light = new Light4();
100 break;
101 case 3:
102 light = new Light3();
103 break;
104 case 2:
105 light = new Light2();
106 break;
107 case 1:
108 light = new Light1();
109 break;
110 default:
111 light = new Light();
112 }
113 light->readVqa(stream, frameCount, _frame, 1);
114 _lights.push_back(light);
115 }
116 }
117
setupFrame(int frame)118 void Lights::setupFrame(int frame) {
119 if (frame == _frame) {
120 return;
121 }
122
123 for (uint i = 0; i < _lights.size(); ++i) {
124 _lights[i]->setupFrame(frame);
125 }
126 }
127
reset()128 void Lights::reset() {
129 for (int i = (int)(_lights.size() - 1); i >= 0; --i) {
130 delete _lights.remove_at(i);
131 }
132 _lights.clear();
133 }
134
135 } // End of namespace BladeRunner
136