4851: Added direction enumeration for the editor r=def- a=Chairn

This is a similar work that was carried out by `@C0D3D3V` on introducing enumeration rather than magic numbers.

## 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 if it works standalone, system.c especially
- [ ] 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: Chairn <chairn.nq@hotmail.fr>
This commit is contained in:
bors[bot] 2022-03-21 09:01:18 +00:00 committed by GitHub
commit dfb0d7d269
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 95 deletions

View file

@ -496,6 +496,14 @@ enum
PROPTYPE_AUTOMAPPER,
};
enum
{
DIRECTION_LEFT = 1,
DIRECTION_RIGHT = 2,
DIRECTION_UP = 4,
DIRECTION_DOWN = 8,
};
typedef struct
{
int x, y;

View file

@ -631,46 +631,34 @@ void CLayerTiles::Shift(int Direction)
switch(Direction)
{
case 1:
{
// left
case DIRECTION_LEFT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTiles[y * m_Width], &m_pTiles[y * m_Width + o], (m_Width - o) * sizeof(CTile));
mem_zero(&m_pTiles[y * m_Width + (m_Width - o)], o * sizeof(CTile));
}
}
break;
case 2:
{
// right
break;
case DIRECTION_RIGHT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTiles[y * m_Width + o], &m_pTiles[y * m_Width], (m_Width - o) * sizeof(CTile));
mem_zero(&m_pTiles[y * m_Width], o * sizeof(CTile));
}
}
break;
case 4:
{
// up
break;
case DIRECTION_UP:
for(int y = 0; y < m_Height - o; ++y)
{
mem_copy(&m_pTiles[y * m_Width], &m_pTiles[(y + o) * m_Width], m_Width * sizeof(CTile));
mem_zero(&m_pTiles[(y + o) * m_Width], m_Width * sizeof(CTile));
}
}
break;
case 8:
{
// down
break;
case DIRECTION_DOWN:
for(int y = m_Height - 1; y >= o; --y)
{
mem_copy(&m_pTiles[y * m_Width], &m_pTiles[(y - o) * m_Width], m_Width * sizeof(CTile));
mem_zero(&m_pTiles[(y - o) * m_Width], m_Width * sizeof(CTile));
}
}
}
}
void CLayerTiles::ShowInfo()
@ -1153,46 +1141,34 @@ void CLayerTele::Shift(int Direction)
switch(Direction)
{
case 1:
{
// left
case DIRECTION_LEFT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTeleTile[y * m_Width], &m_pTeleTile[y * m_Width + o], (m_Width - o) * sizeof(CTeleTile));
mem_zero(&m_pTeleTile[y * m_Width + (m_Width - o)], o * sizeof(CTeleTile));
}
}
break;
case 2:
{
// right
break;
case DIRECTION_RIGHT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTeleTile[y * m_Width + o], &m_pTeleTile[y * m_Width], (m_Width - o) * sizeof(CTeleTile));
mem_zero(&m_pTeleTile[y * m_Width], o * sizeof(CTeleTile));
}
}
break;
case 4:
{
// up
break;
case DIRECTION_UP:
for(int y = 0; y < m_Height - o; ++y)
{
mem_copy(&m_pTeleTile[y * m_Width], &m_pTeleTile[(y + o) * m_Width], m_Width * sizeof(CTeleTile));
mem_zero(&m_pTeleTile[(y + o) * m_Width], m_Width * sizeof(CTeleTile));
}
}
break;
case 8:
{
// down
break;
case DIRECTION_DOWN:
for(int y = m_Height - 1; y >= o; --y)
{
mem_copy(&m_pTeleTile[y * m_Width], &m_pTeleTile[(y - o) * m_Width], m_Width * sizeof(CTeleTile));
mem_zero(&m_pTeleTile[(y - o) * m_Width], m_Width * sizeof(CTeleTile));
}
}
}
}
bool CLayerTele::IsEmpty(CLayerTiles *pLayer)
@ -1441,46 +1417,34 @@ void CLayerSpeedup::Shift(int Direction)
switch(Direction)
{
case 1:
{
// left
case DIRECTION_LEFT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pSpeedupTile[y * m_Width], &m_pSpeedupTile[y * m_Width + o], (m_Width - o) * sizeof(CSpeedupTile));
mem_zero(&m_pSpeedupTile[y * m_Width + (m_Width - o)], o * sizeof(CSpeedupTile));
}
}
break;
case 2:
{
// right
break;
case DIRECTION_RIGHT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pSpeedupTile[y * m_Width + o], &m_pSpeedupTile[y * m_Width], (m_Width - o) * sizeof(CSpeedupTile));
mem_zero(&m_pSpeedupTile[y * m_Width], o * sizeof(CSpeedupTile));
}
}
break;
case 4:
{
// up
break;
case DIRECTION_UP:
for(int y = 0; y < m_Height - o; ++y)
{
mem_copy(&m_pSpeedupTile[y * m_Width], &m_pSpeedupTile[(y + o) * m_Width], m_Width * sizeof(CSpeedupTile));
mem_zero(&m_pSpeedupTile[(y + o) * m_Width], m_Width * sizeof(CSpeedupTile));
}
}
break;
case 8:
{
// down
break;
case DIRECTION_DOWN:
for(int y = m_Height - 1; y >= o; --y)
{
mem_copy(&m_pSpeedupTile[y * m_Width], &m_pSpeedupTile[(y - o) * m_Width], m_Width * sizeof(CSpeedupTile));
mem_zero(&m_pSpeedupTile[(y - o) * m_Width], m_Width * sizeof(CSpeedupTile));
}
}
}
}
bool CLayerSpeedup::IsEmpty(CLayerTiles *pLayer)
@ -1785,46 +1749,34 @@ void CLayerSwitch::Shift(int Direction)
switch(Direction)
{
case 1:
{
// left
case DIRECTION_LEFT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pSwitchTile[y * m_Width], &m_pSwitchTile[y * m_Width + o], (m_Width - o) * sizeof(CSwitchTile));
mem_zero(&m_pSwitchTile[y * m_Width + (m_Width - o)], o * sizeof(CSwitchTile));
}
}
break;
case 2:
{
// right
break;
case DIRECTION_RIGHT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pSwitchTile[y * m_Width + o], &m_pSwitchTile[y * m_Width], (m_Width - o) * sizeof(CSwitchTile));
mem_zero(&m_pSwitchTile[y * m_Width], o * sizeof(CSwitchTile));
}
}
break;
case 4:
{
// up
break;
case DIRECTION_UP:
for(int y = 0; y < m_Height - o; ++y)
{
mem_copy(&m_pSwitchTile[y * m_Width], &m_pSwitchTile[(y + o) * m_Width], m_Width * sizeof(CSwitchTile));
mem_zero(&m_pSwitchTile[(y + o) * m_Width], m_Width * sizeof(CSwitchTile));
}
}
break;
case 8:
{
// down
break;
case DIRECTION_DOWN:
for(int y = m_Height - 1; y >= o; --y)
{
mem_copy(&m_pSwitchTile[y * m_Width], &m_pSwitchTile[(y - o) * m_Width], m_Width * sizeof(CSwitchTile));
mem_zero(&m_pSwitchTile[(y - o) * m_Width], m_Width * sizeof(CSwitchTile));
}
}
}
}
bool CLayerSwitch::IsEmpty(CLayerTiles *pLayer)
@ -2101,46 +2053,34 @@ void CLayerTune::Shift(int Direction)
switch(Direction)
{
case 1:
{
// left
case DIRECTION_LEFT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTuneTile[y * m_Width], &m_pTuneTile[y * m_Width + o], (m_Width - o) * sizeof(CTuneTile));
mem_zero(&m_pTuneTile[y * m_Width + (m_Width - o)], o * sizeof(CTuneTile));
}
}
break;
case 2:
{
// right
break;
case DIRECTION_RIGHT:
for(int y = 0; y < m_Height; ++y)
{
mem_move(&m_pTuneTile[y * m_Width + o], &m_pTuneTile[y * m_Width], (m_Width - o) * sizeof(CTuneTile));
mem_zero(&m_pTuneTile[y * m_Width], o * sizeof(CTuneTile));
}
}
break;
case 4:
{
// up
break;
case DIRECTION_UP:
for(int y = 0; y < m_Height - o; ++y)
{
mem_copy(&m_pTuneTile[y * m_Width], &m_pTuneTile[(y + o) * m_Width], m_Width * sizeof(CTuneTile));
mem_zero(&m_pTuneTile[(y + o) * m_Width], m_Width * sizeof(CTuneTile));
}
}
break;
case 8:
{
// down
break;
case DIRECTION_DOWN:
for(int y = m_Height - 1; y >= o; --y)
{
mem_copy(&m_pTuneTile[y * m_Width], &m_pTuneTile[(y - o) * m_Width], m_Width * sizeof(CTuneTile));
mem_zero(&m_pTuneTile[(y - o) * m_Width], m_Width * sizeof(CTuneTile));
}
}
}
}
bool CLayerTune::IsEmpty(CLayerTiles *pLayer)