File: lab_ui_helpers.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (202 lines) | stat: -rw-r--r-- 4,454 bytes parent folder | download
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "lab_ui_helpers.h"

#include "cfile/cfile.h"
#include "lab/labv2_internal.h"


SCP_string get_ship_table_text(ship_info* sip)
{
	char line[256], line2[256], file_text[82];
	int i, j, n, found = 0, comment = 0, num_files = 0;
	SCP_vector<SCP_string> tbl_file_names;
	SCP_string result;

	auto fp = cfopen("ships.tbl", "r");
	Assert(fp);

	while (cfgets(line, 255, fp)) {
		while (line[strlen(line) - 1] == '\n')
			line[strlen(line) - 1] = 0;

		for (i = j = 0; line[i]; i++) {
			if (line[i] == '/' && line[i + 1] == '/')
				break;

			if (line[i] == '/' && line[i + 1] == '*') {
				comment = 1;
				i++;
				continue;
			}

			if (line[i] == '*' && line[i + 1] == '/') {
				comment = 0;
				i++;
				continue;
			}

			if (!comment)
				line2[j++] = line[i];
		}

		line2[j] = 0;
		if (!strnicmp(line2, "$Name:", 6)) {
			drop_trailing_white_space(line2);
			found = 0;
			i = 6;

			while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
				i++;

			if (!stricmp(line2 + i, sip->name)) {
				result += "-- ships.tbl  -------------------------------\r\n";
				found = 1;
			}
		}

		if (found) {
			result += line;
			result += "\r\n";
		}
	}

	cfclose(fp);

	// done with ships.tbl, so now check all modular ship tables...
	num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-shp.tbm"), CF_SORT_REVERSE);

	for (n = 0; n < num_files; n++) {
		tbl_file_names[n] += ".tbm";

		fp = cfopen(tbl_file_names[n].c_str(), "r");
		Assert(fp);

		memset(line, 0, sizeof(line));
		memset(line2, 0, sizeof(line2));
		found = 0;
		comment = 0;

		while (cfgets(line, 255, fp)) {
			while (line[strlen(line) - 1] == '\n')
				line[strlen(line) - 1] = 0;

			for (i = j = 0; line[i]; i++) {
				if (line[i] == '/' && line[i + 1] == '/')
					break;

				if (line[i] == '/' && line[i + 1] == '*') {
					comment = 1;
					i++;
					continue;
				}

				if (line[i] == '*' && line[i + 1] == '/') {
					comment = 0;
					i++;
					continue;
				}

				if (!comment)
					line2[j++] = line[i];
			}

			line2[j] = 0;
			if (!strnicmp(line2, "$Name:", 6)) {
				drop_trailing_white_space(line2);
				found = 0;
				i = 6;

				while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@')
					i++;

				if (!stricmp(line2 + i, sip->name)) {
					memset(file_text, 0, sizeof(file_text));
					snprintf(file_text,
						sizeof(file_text) - 1,
						"--  %s  -------------------------------\r\n",
						tbl_file_names[n].c_str());
					result += file_text;
					found = 1;
				}
			}

			if (found) {
				result += line;
				result += "\r\n";
			}
		}

		cfclose(fp);
	}

	return result;
}

SCP_string get_directory_or_vp(const char* path)
{
	SCP_string result(path);

	// Is this a mission in a directory?
	size_t found = result.find("data" DIR_SEPARATOR_STR "missions");

	if (found == std::string::npos) // Guess not
	{
		found = result.find(".vp");
	}

	const auto directory_name_pos = result.rfind(DIR_SEPARATOR_CHAR, found - strlen(DIR_SEPARATOR_STR) - 1);

	result = result.substr(directory_name_pos, found - directory_name_pos);

	found = result.find(DIR_SEPARATOR_CHAR);
	// Strip directory separators
	while (found != std::string::npos) {
		result.erase(found, strlen(DIR_SEPARATOR_STR));
		found = result.find(DIR_SEPARATOR_CHAR);
	}

	return result;
}
namespace ltp = lighting_profiles;
using namespace ltp;
bool graphics_options_changed()
{
	const auto& stored_settings = getLabManager()->graphicsSettings;

	if (stored_settings.ambient_factor != ltp::lab_get_ambient())
		return true;

	if (stored_settings.light_factor != ltp::lab_get_light())
		return true;

	if (stored_settings.emissive_factor != ltp::lab_get_emissive())
		return true;

	if (stored_settings.exposure_level != ltp::current_exposure())
		return true;

	if (stored_settings.tonemapper != ltp::current_tonemapper())
		return true;

	if (stored_settings.bloom_level != gr_bloom_intensity())
		return true;

	if (stored_settings.aa_mode != Gr_aa_mode)
		return true;

	if (stored_settings.ppcv.shoulder_angle != ltp::lab_get_ppc().shoulder_angle)
		return true;

	if (stored_settings.ppcv.shoulder_length != ltp::lab_get_ppc().shoulder_length)
		return true;

	if (stored_settings.ppcv.shoulder_strength != ltp::lab_get_ppc().shoulder_strength)
		return true;

	if (stored_settings.ppcv.toe_length != ltp::lab_get_ppc().toe_length)
		return true;

	if (stored_settings.ppcv.toe_strength != ltp::lab_get_ppc().toe_strength)
		return true;

	return false;
}