1
0
Fork 0

Fixed Prefab's rotations.

This commit is contained in:
madmaxoft 2014-03-28 16:36:33 +01:00
parent 7cc44d4d8b
commit 910e770a18
2 changed files with 39 additions and 7 deletions

View File

@ -21,11 +21,33 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
m_AllowedRotations(a_Def.m_AllowedRotations),
m_MergeStrategy(a_Def.m_MergeStrategy)
{
m_BlockArea.Create(m_Size);
m_BlockArea[0].Create(m_Size);
CharMap cm;
ParseCharMap(cm, a_Def.m_CharMap);
ParseBlockImage(cm, a_Def.m_Image);
ParseConnectors(a_Def.m_Connectors);
// 1 CCW rotation:
if ((m_AllowedRotations & 0x01) != 0)
{
m_BlockArea[1].CopyFrom(m_BlockArea[0]);
m_BlockArea[1].RotateCCW();
}
// 2 rotations are the same as mirroring twice; mirroring is faster because it has no reallocations
if ((m_AllowedRotations & 0x02) != 0)
{
m_BlockArea[2].CopyFrom(m_BlockArea[0]);
m_BlockArea[2].MirrorXY();
m_BlockArea[2].MirrorYZ();
}
// 3 CCW rotations = 1 CW rotation:
if ((m_AllowedRotations & 0x04) != 0)
{
m_BlockArea[3].CopyFrom(m_BlockArea[0]);
m_BlockArea[3].RotateCW();
}
}
@ -38,7 +60,7 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const
int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width;
int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width;
Placement.Move(-ChunkStartX, 0, -ChunkStartZ);
a_Dest.WriteBlockArea(m_BlockArea, Placement.x, Placement.y, Placement.z, m_MergeStrategy);
a_Dest.WriteBlockArea(m_BlockArea[a_Placement->GetNumCCWRotations()], Placement.x, Placement.y, Placement.z, m_MergeStrategy);
}
@ -112,7 +134,7 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma
ASSERT(MappedValue != -1); // Using a letter not defined in the CharMap?
BLOCKTYPE BlockType = MappedValue >> 4;
NIBBLETYPE BlockMeta = MappedValue & 0x0f;
m_BlockArea.SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta);
m_BlockArea[0].SetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta);
}
}
}
@ -195,7 +217,9 @@ cCuboid cPrefab::GetHitBox(void) const
bool cPrefab::CanRotateCCW(int a_NumRotations) const
{
return ((m_AllowedRotations & (1 << (a_NumRotations % 4))) != 0);
// Either zero rotations
// Or the proper bit in m_AllowedRotations is set
return (a_NumRotations == 0) || ((m_AllowedRotations & (1 << ((a_NumRotations + 3) % 4))) != 0);
}

View File

@ -22,6 +22,13 @@ declared in this file as well; the Gallery server exports areas in this format.
// fwd:
class cChunkDesc;
class cPrefab :
public cPiece
{
@ -51,8 +58,9 @@ protected:
typedef int CharMap[256];
/** The cBlockArea that contains the block definitions for the prefab */
cBlockArea m_BlockArea;
/** The cBlockArea that contains the block definitions for the prefab.
The index identifies the number of CCW rotations applied (0 = no rotation, 1 = 1 CCW rotation, ...). */
cBlockArea m_BlockArea[4];
/** The size of the prefab */
Vector3i m_Size;
@ -79,7 +87,7 @@ protected:
/** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. */
void ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef);
/** Parses the Image in the definition into m_BlockArea's block types and metas, using the specified CharMap. */
/** Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap. */
void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage);
/** Parses the connectors definition text into m_Connectors member. */