6132: Make tileflag names consistent and intuitive r=def- a=Patiga

- `TILEFLAG_VFLIP` -> `TILEFLAG_FLIP_HORIZONTAL`
- `TILEFLAG_HFLIP` -> `TILEFLAG_FLIP_VERTICAL`

According to the native editor, the "Tiled" editor and image search, a horizontal flip should be associated with switching left and right, modifying the x coordinate.

I did not just switch the letters `H` and `V` to create compiler errors where the original constants are used.

Whenever I was working with tileflags, the naming caused me to have no idea what I was doing. I mostly had to resort to opening the resulting map in the editor to see what the code does. This change aims to make the naming intuitive and also consistent with the map editor.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Patiga <dev@patiga.eu>
This commit is contained in:
bors[bot] 2022-12-14 12:59:40 +00:00 committed by GitHub
commit 609178dd84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 40 deletions

View file

@ -229,7 +229,7 @@ void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, bool
unsigned char x3 = x0;
unsigned char y3 = y0 + 1;
if(Flags & TILEFLAG_VFLIP)
if(Flags & TILEFLAG_FLIP_HORIZONTAL)
{
x0 = x2;
x1 = x3;
@ -237,7 +237,7 @@ void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, bool
x3 = x0;
}
if(Flags & TILEFLAG_HFLIP)
if(Flags & TILEFLAG_FLIP_VERTICAL)
{
y0 = y3;
y2 = y1;

View file

@ -364,7 +364,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color
y3 = y0 + 1;
}
if(Flags & TILEFLAG_VFLIP)
if(Flags & TILEFLAG_FLIP_HORIZONTAL)
{
x0 = x2;
x1 = x3;
@ -372,7 +372,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color
x3 = x0;
}
if(Flags & TILEFLAG_HFLIP)
if(Flags & TILEFLAG_FLIP_VERTICAL)
{
y0 = y3;
y2 = y1;
@ -923,7 +923,7 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float
float x3 = Nudge + Px0 / TexSize + Frac;
float y3 = Nudge + Py1 / TexSize - Frac;
if(Flags & TILEFLAG_VFLIP)
if(Flags & TILEFLAG_FLIP_HORIZONTAL)
{
x0 = x2;
x1 = x3;
@ -931,7 +931,7 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float
x3 = x0;
}
if(Flags & TILEFLAG_HFLIP)
if(Flags & TILEFLAG_FLIP_VERTICAL)
{
y0 = y3;
y2 = y1;

View file

@ -160,7 +160,7 @@ enum
static int GetMoveRestrictionsRaw(int Direction, int Tile, int Flags)
{
Flags = Flags & (TILEFLAG_VFLIP | TILEFLAG_HFLIP | TILEFLAG_ROTATE);
Flags = Flags & (TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL | TILEFLAG_ROTATE);
switch(Tile)
{
case TILE_STOP:
@ -171,10 +171,10 @@ static int GetMoveRestrictionsRaw(int Direction, int Tile, int Flags)
case ROTATION_180: return CANTMOVE_UP;
case ROTATION_270: return CANTMOVE_RIGHT;
case TILEFLAG_HFLIP ^ ROTATION_0: return CANTMOVE_UP;
case TILEFLAG_HFLIP ^ ROTATION_90: return CANTMOVE_RIGHT;
case TILEFLAG_HFLIP ^ ROTATION_180: return CANTMOVE_DOWN;
case TILEFLAG_HFLIP ^ ROTATION_270: return CANTMOVE_LEFT;
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_0: return CANTMOVE_UP;
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_90: return CANTMOVE_RIGHT;
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_180: return CANTMOVE_DOWN;
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_270: return CANTMOVE_LEFT;
}
break;
case TILE_STOPS:
@ -182,13 +182,13 @@ static int GetMoveRestrictionsRaw(int Direction, int Tile, int Flags)
{
case ROTATION_0:
case ROTATION_180:
case TILEFLAG_HFLIP ^ ROTATION_0:
case TILEFLAG_HFLIP ^ ROTATION_180:
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_0:
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_180:
return CANTMOVE_DOWN | CANTMOVE_UP;
case ROTATION_90:
case ROTATION_270:
case TILEFLAG_HFLIP ^ ROTATION_90:
case TILEFLAG_HFLIP ^ ROTATION_270:
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_90:
case TILEFLAG_FLIP_VERTICAL ^ ROTATION_270:
return CANTMOVE_LEFT | CANTMOVE_RIGHT;
}
break;

View file

@ -118,9 +118,9 @@ void CAutoMapper::Load(const char *pTileName)
if(str_length(aOrientation1) > 0)
{
if(!str_comp(aOrientation1, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_VFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation1, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_HFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation1, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
@ -128,9 +128,9 @@ void CAutoMapper::Load(const char *pTileName)
if(str_length(aOrientation2) > 0)
{
if(!str_comp(aOrientation2, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_VFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation2, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_HFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation2, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
@ -138,9 +138,9 @@ void CAutoMapper::Load(const char *pTileName)
if(str_length(aOrientation3) > 0)
{
if(!str_comp(aOrientation3, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_VFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation3, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_HFLIP;
NewIndexRule.m_Flag |= TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation3, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
@ -205,9 +205,9 @@ void CAutoMapper::Load(const char *pTileName)
{
NewIndexInfo.m_TestFlag = true;
if(!str_comp(aOrientation1, "XFLIP"))
NewIndexInfo.m_Flag = TILEFLAG_VFLIP;
NewIndexInfo.m_Flag = TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation1, "YFLIP"))
NewIndexInfo.m_Flag = TILEFLAG_HFLIP;
NewIndexInfo.m_Flag = TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation1, "ROTATE"))
NewIndexInfo.m_Flag = TILEFLAG_ROTATE;
else if(!str_comp(aOrientation1, "NONE"))
@ -230,9 +230,9 @@ void CAutoMapper::Load(const char *pTileName)
else if(str_length(aOrientation2) > 0 && NewIndexInfo.m_Flag != 0)
{
if(!str_comp(aOrientation2, "XFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_VFLIP;
NewIndexInfo.m_Flag |= TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation2, "YFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_HFLIP;
NewIndexInfo.m_Flag |= TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation2, "ROTATE"))
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
}
@ -251,9 +251,9 @@ void CAutoMapper::Load(const char *pTileName)
else if(str_length(aOrientation3) > 0 && NewIndexInfo.m_Flag != 0)
{
if(!str_comp(aOrientation3, "XFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_VFLIP;
NewIndexInfo.m_Flag |= TILEFLAG_FLIP_HORIZONTAL;
else if(!str_comp(aOrientation3, "YFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_HFLIP;
NewIndexInfo.m_Flag |= TILEFLAG_FLIP_VERTICAL;
else if(!str_comp(aOrientation3, "ROTATE"))
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
}
@ -493,7 +493,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO
{
int CheckTile = CheckY * pLayer->m_Width + CheckX;
CheckIndex = pReadLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_VFLIP | TILEFLAG_HFLIP);
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL);
}
else
{

View file

@ -86,7 +86,7 @@ void CLayerTiles::PrepareForSave()
{
for(int y = 0; y < m_Height; y++)
for(int x = 0; x < m_Width; x++)
m_pTiles[y * m_Width + x].m_Flags &= TILEFLAG_VFLIP | TILEFLAG_HFLIP | TILEFLAG_ROTATE;
m_pTiles[y * m_Width + x].m_Flags &= TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL | TILEFLAG_ROTATE;
if(m_Image != -1 && m_Color.a == 255)
{
@ -541,7 +541,7 @@ void CLayerTiles::BrushFlipX()
if(!Rotate && !IsRotatableTile(m_pTiles[y * m_Width + x].m_Index))
m_pTiles[y * m_Width + x].m_Flags = 0;
else
m_pTiles[y * m_Width + x].m_Flags ^= (m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE) ? TILEFLAG_HFLIP : TILEFLAG_VFLIP;
m_pTiles[y * m_Width + x].m_Flags ^= (m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE) ? TILEFLAG_FLIP_VERTICAL : TILEFLAG_FLIP_HORIZONTAL;
}
void CLayerTiles::BrushFlipY()
@ -557,7 +557,7 @@ void CLayerTiles::BrushFlipY()
if(!Rotate && !IsRotatableTile(m_pTiles[y * m_Width + x].m_Index))
m_pTiles[y * m_Width + x].m_Flags = 0;
else
m_pTiles[y * m_Width + x].m_Flags ^= (m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE) ? TILEFLAG_VFLIP : TILEFLAG_HFLIP;
m_pTiles[y * m_Width + x].m_Flags ^= (m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE) ? TILEFLAG_FLIP_HORIZONTAL : TILEFLAG_FLIP_VERTICAL;
}
void CLayerTiles::BrushRotate(float Amount)
@ -582,7 +582,7 @@ void CLayerTiles::BrushRotate(float Amount)
else
{
if(pDst->m_Flags & TILEFLAG_ROTATE)
pDst->m_Flags ^= (TILEFLAG_HFLIP | TILEFLAG_VFLIP);
pDst->m_Flags ^= (TILEFLAG_FLIP_VERTICAL | TILEFLAG_FLIP_HORIZONTAL);
pDst->m_Flags ^= TILEFLAG_ROTATE;
}
}
@ -666,8 +666,8 @@ void CLayerTiles::ShowInfo()
str_format(aBuf, sizeof(aBuf), m_pEditor->m_ShowTileHexInfo ? "%02X" : "%i", m_pTiles[c].m_Index);
m_pEditor->Graphics()->QuadsText(x * 32, y * 32, 16.0f, aBuf);
char aFlags[4] = {m_pTiles[c].m_Flags & TILEFLAG_VFLIP ? 'V' : ' ',
m_pTiles[c].m_Flags & TILEFLAG_HFLIP ? 'H' : ' ',
char aFlags[4] = {m_pTiles[c].m_Flags & TILEFLAG_FLIP_HORIZONTAL ? 'H' : ' ',
m_pTiles[c].m_Flags & TILEFLAG_FLIP_VERTICAL ? 'V' : ' ',
m_pTiles[c].m_Flags & TILEFLAG_ROTATE ? 'R' : ' ',
0};
m_pEditor->Graphics()->QuadsText(x * 32, y * 32 + 16, 16.0f, aFlags);
@ -1763,7 +1763,7 @@ void CLayerSwitch::BrushRotate(float Amount)
if(IsRotatableTile(pDst2->m_Index))
{
if(pDst2->m_Flags & TILEFLAG_ROTATE)
pDst2->m_Flags ^= (TILEFLAG_HFLIP | TILEFLAG_VFLIP);
pDst2->m_Flags ^= (TILEFLAG_FLIP_VERTICAL | TILEFLAG_FLIP_HORIZONTAL);
pDst2->m_Flags ^= TILEFLAG_ROTATE;
}
}

View file

@ -192,15 +192,15 @@ enum
LAYER_TUNE,
NUM_LAYERS,
//Flags
TILEFLAG_VFLIP = 1,
TILEFLAG_HFLIP = 2,
TILEFLAG_FLIP_HORIZONTAL = 1,
TILEFLAG_FLIP_VERTICAL = 2,
TILEFLAG_OPAQUE = 4,
TILEFLAG_ROTATE = 8,
//Rotation
ROTATION_0 = 0,
ROTATION_90 = TILEFLAG_ROTATE,
ROTATION_180 = (TILEFLAG_VFLIP | TILEFLAG_HFLIP),
ROTATION_270 = (TILEFLAG_VFLIP | TILEFLAG_HFLIP | TILEFLAG_ROTATE),
ROTATION_180 = (TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL),
ROTATION_270 = (TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL | TILEFLAG_ROTATE),
LAYERFLAG_DETAIL = 1,
TILESLAYERFLAG_GAME = 1,

View file

@ -254,7 +254,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos, int Layer, int Flags, int Nu
Dir = 0;
else if(Flags == (TILEFLAG_ROTATE))
Dir = 1;
else if(Flags == (TILEFLAG_VFLIP | TILEFLAG_HFLIP))
else if(Flags == (TILEFLAG_FLIP_HORIZONTAL | TILEFLAG_FLIP_VERTICAL))
Dir = 2;
else
Dir = 3;