1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-16 17:48:29 +02:00

Fix regression with platv values not parsed as 2.2-and-prev

So, platv is a room property that controls the speed of custom entity
platforms in the room (unless, of course, they're created with
createentity). Problem is, this is how 2.2-and-previous coding standards
were:

    ed.level[game.roomx-100+((game.roomy-100)*ed.maxwidth)]

Overly long, verbose, not entirely clear unless you already know what it
means? Copy-pasted over and over due to all of the above? Surely a
recipe for not making any coding errors!

Ironically enough, copy-pasting is basically the best approach here
(short of refactoring the whole thing, like I did in
945d5f244a), since if you don't ACTUALLY
copy-paste and just re-type it on your own, you'll end up making more
mistakes. Like what happened here:

    ed.level[game.roomx-100+((game.roomy-100)*ed.mapwidth)].platv

Do you see the mistake...? Yeah, mapwidth (with a P) instead of maxwidth
(with an X). You'd have to look closely to find it.

So what does this mean for platv? Well, it means that it multiples the
y-coordinate of the room by the map width instead of the max width (20),
like every other room property. So that means if your map width is less
than 20, like say, map width 10, the platv value for (2,2) will be
stored in (2,1)'s room properties instead of (2,2)'s. Because if you go
off of map width, the room index for (2,2) is 2 + 2 * 10 = 22, but if
you go off of max width, the room index for (2,1) is 2 + 1 * 20 = 22.

Now this wouldn't be bad, except for another 2.2-and-previous
standard... kind of just not exposing things directly to the end user.
Whether that's simply not documenting something (as in the case of
ifwarp and warpdir, which by all measures were completely intended to be
used in custom levels but just simply were never known properly until I
discovered how to use them in 2019), or in this case, not giving any way
for the user to fiddle with platv from the in-game editor. Because if
there was a way to do that, and someone decided to test to see if platv
worked okay, they would discover something was up.

So... since I refactored room properties in
945d5f244a, I kind of broke platv by
fixing it. Now levels that relied on platv being the broken way don't
work.

How do I fix it, and thus break it again? Well, I'll do what I did for
scripts - handle the scrambling when reading and writing the level, and
keep things sane at least internally.

Thus: editorclass::load() will unscramble platv data in the right way,
and editorclass::save() will re-scramble platv in the right way too.
This commit is contained in:
Misa 2021-08-18 19:19:33 -07:00
parent a13d26d866
commit 208382a8d1

View File

@ -2039,6 +2039,45 @@ next:
}
}
if (mapwidth < maxwidth)
{
/* Unscramble platv, since it was stored incorrectly
* in 2.2 and previous... */
size_t i;
int x = 0;
int y = 0;
int temp_platv[numrooms];
for (i = 0; i < numrooms; ++i)
{
temp_platv[i] = level[i].platv;
}
for (i = 0; i < numrooms; ++i)
{
if (x < mapwidth)
{
const int platv_idx = x + y * mapwidth;
if (INBOUNDS_ARR(platv_idx, temp_platv))
{
level[i].platv = temp_platv[platv_idx];
}
}
else
{
level[i].platv = 4; /* default */
}
++x;
if (x >= maxwidth)
{
x = 0;
++y;
}
}
}
gethooks();
version=2;
@ -2147,6 +2186,40 @@ bool editorclass::save(std::string& _path)
}
msg = xml::update_element_delete_contents(data, "levelMetaData");
int temp_platv[numrooms];
SDL_memset(temp_platv, 4 /* default */, sizeof(temp_platv));
if (mapwidth < maxwidth)
{
/* Re-scramble platv, since it was stored incorrectly
* in 2.2 and previous... */
size_t i;
int x = 0;
int y = 0;
for (i = 0; i < numrooms; ++i)
{
if (x < mapwidth)
{
const int platv_idx = x + y * mapwidth;
if (INBOUNDS_ARR(platv_idx, temp_platv))
{
temp_platv[platv_idx] = level[i].platv;
}
}
++x;
if (x >= mapwidth)
{
/* Skip to next actual row. */
i += maxwidth - mapwidth;
x = 0;
++y;
}
}
}
for(size_t i = 0; i < SDL_arraysize(level); i++)
{
tinyxml2::XMLElement *edlevelclassElement = doc.NewElement( "edLevelClass" );
@ -2156,7 +2229,7 @@ bool editorclass::save(std::string& _path)
edlevelclassElement->SetAttribute( "platy1", level[i].platy1);
edlevelclassElement->SetAttribute( "platx2", level[i].platx2);
edlevelclassElement->SetAttribute( "platy2", level[i].platy2);
edlevelclassElement->SetAttribute( "platv", level[i].platv);
edlevelclassElement->SetAttribute( "platv", temp_platv[i]);
edlevelclassElement->SetAttribute( "enemyx1", level[i].enemyx1);
edlevelclassElement->SetAttribute( "enemyy1", level[i].enemyy1);
edlevelclassElement->SetAttribute( "enemyx2", level[i].enemyx2);