summaryrefslogtreecommitdiffstats
path: root/src/Generating/Prefab.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-03-28 16:36:33 +0100
committermadmaxoft <github@xoft.cz>2014-03-28 16:36:33 +0100
commit910e770a18520a96a5823b24b4b6a41068499414 (patch)
tree58dd8d84bd8c7d5209be85b373b7cf9c3ecbbb93 /src/Generating/Prefab.cpp
parentDebuggers: Deactivated the chunk generator callback. (diff)
downloadcuberite-910e770a18520a96a5823b24b4b6a41068499414.tar
cuberite-910e770a18520a96a5823b24b4b6a41068499414.tar.gz
cuberite-910e770a18520a96a5823b24b4b6a41068499414.tar.bz2
cuberite-910e770a18520a96a5823b24b4b6a41068499414.tar.lz
cuberite-910e770a18520a96a5823b24b4b6a41068499414.tar.xz
cuberite-910e770a18520a96a5823b24b4b6a41068499414.tar.zst
cuberite-910e770a18520a96a5823b24b4b6a41068499414.zip
Diffstat (limited to 'src/Generating/Prefab.cpp')
-rw-r--r--src/Generating/Prefab.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp
index 145c875a1..1af1faec1 100644
--- a/src/Generating/Prefab.cpp
+++ b/src/Generating/Prefab.cpp
@@ -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);
}