aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/star_control/star_control_sub7.cpp
blob: f7b86337fa6135e576f6312584bf4d3b19b0f296 (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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "titanic/star_control/star_control_sub7.h"
#include "titanic/star_control/star_control_sub12.h"

namespace Titanic {

void CStarControlSub7::draw(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStarControlSub5 *sub5) {
	if (_data.empty())
		return;

	FPose pose = sub12->proc23();
	double threshold = sub12->proc25();
	FPoint center((double)surfaceArea->_width * 0.5,
		surfaceArea->_height * 0.5);
	FVector newV;

	uint savedPixel = surfaceArea->_pixel;
	surfaceArea->_pixel = 0xffff;
	surfaceArea->setColorFromPixel();

	for (uint idx = 0; idx < _data.size(); ++idx) {
		const CBaseStarEntry &star = _data[idx];

		newV._x = pose._row1._x * star._position._x + pose._row3._x * star._position._z
			+ pose._row2._x * star._position._y + pose._vector._x;
		newV._y = pose._row1._y * star._position._x + pose._row3._y * star._position._z
			+ pose._row2._y * star._position._x + pose._vector._y;
		newV._z = pose._row1._z * star._position._x + pose._row3._z * star._position._z
			+ pose._row2._z * star._position._y + pose._vector._z; 

		if (newV._z > threshold) {
			FVector vTemp;
			sub12->proc28(2, newV, vTemp);

			FRect r1(center._x + vTemp._x, center._y + vTemp._y,
				center._x + vTemp._x + 4.0, center._y + vTemp._y + 4.0);
			surfaceArea->fillRect(r1);

			FRect r2(r1.right, r1.bottom, r1.right + 4.0, r1.top);
			surfaceArea->fillRect(r2);

			FRect r3(r2.right, r1.top, r1.right, r1.top - 4.0);
			surfaceArea->fillRect(r3);

			FRect r4(r1.right, r1.top - 4.0, r1.left, r1.top);
			surfaceArea->fillRect(r4);
		}
	}

	surfaceArea->_pixel = savedPixel;
	surfaceArea->setColorFromPixel();
}

bool CStarControlSub7::addStar(const CBaseStarEntry *entry) {
	// iterate through the existing stars
	for (uint idx = 0; idx < _data.size(); ++idx) {
		CBaseStarEntry &star = _data[idx];
		if (star == *entry) {
			// Found a matching star at the exact same position, so remove it instead
			_data.remove_at(idx);
			return true;
		}
	}

	// No existing match
	if (_data.size() == 32)
		// Out of space, so delete oldest star
		_data.remove_at(0);

	// Add new star
	_data.push_back(*entry);
	return true;
}

} // End of namespace Titanic