Skip to content

Commit 8166567

Browse files
committed
Sync-merge from main.
2 parents 94b8cee + e923049 commit 8166567

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

include/Termin8or/drawing/Texture.h

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace t8
5656

5757
struct Texture
5858
{
59+
int ver = 0;
5960
RC size;
6061
int area = 0;
6162
std::vector<char> characters;
@@ -225,15 +226,49 @@ namespace t8
225226
{
226227
if (section == 0)
227228
{
228-
std::istringstream iss(l);
229-
iss >> size.r >> size.c;
230-
area = size.r * size.c;
231-
characters.resize(area, ' ');
232-
fg_colors.resize(area, Color16::Default);
233-
bg_colors.resize(area, Color16::Transparent2);
234-
materials.resize(area, -1);
235-
section = 1;
236-
r = 0;
229+
if (!l.empty())
230+
{
231+
if (l.starts_with("VER"))
232+
{
233+
auto tokens = str::tokenize(l, { ' ' });
234+
if (tokens.size() == 2)
235+
{
236+
// Absence of VER line means it is version 1.
237+
int ver_parsed = std::stoi(tokens[1]);
238+
// Change from 1 to current version for making sure it is future-incompatible.
239+
static const int compatible_version_until_and_including = 1;
240+
if (ver_parsed <= compatible_version_until_and_including)
241+
ver = ver_parsed;
242+
else
243+
{
244+
std::cerr << "ERROR in Texture::load() : Incompatible texture version: version = " + tokens[1] << '\n';
245+
return false;
246+
}
247+
}
248+
else
249+
ver = 1; // Absence of VER line means it is version 1.
250+
}
251+
else
252+
{
253+
std::istringstream iss(l);
254+
iss >> size.r >> size.c;
255+
area = size.r * size.c;
256+
characters.resize(area, ' ');
257+
fg_colors.resize(area, Color16::Default);
258+
bg_colors.resize(area, Color16::Transparent2);
259+
materials.resize(area, -1);
260+
}
261+
r++;
262+
}
263+
else if (r == 1 || r == 2) // 2 if there is a VER line.
264+
{
265+
section = 1;
266+
r = 0;
267+
}
268+
else if (r > 2)
269+
{
270+
std::cerr << "ERROR in Texture::parse() : Incorrect number of header lines.\n";
271+
}
237272
}
238273
else if (section == 1)
239274
{

0 commit comments

Comments
 (0)