summaryrefslogtreecommitdiffstats
path: root/src/Generating/Prefab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Generating/Prefab.cpp')
-rw-r--r--src/Generating/Prefab.cpp59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp
index 761986690..e5e6a1e06 100644
--- a/src/Generating/Prefab.cpp
+++ b/src/Generating/Prefab.cpp
@@ -166,6 +166,45 @@ cPrefab::cPrefab(const cBlockArea & a_Image, int a_AllowedRotations) :
+cPrefab::cPrefab(const cBlockArea & a_Image) :
+ m_Size(a_Image.GetSize()),
+ m_AllowedRotations(0),
+ m_MergeStrategy(cBlockArea::msOverwrite),
+ m_ShouldExtendFloor(false),
+ m_DefaultWeight(1),
+ m_AddWeightIfSame(0),
+ m_MoveToGround(false)
+{
+ m_HitBox.p1.Set(0, 0, 0);
+ m_HitBox.p2.Set(m_Size.x - 1, m_Size.y - 1, m_Size.z - 1);
+ m_BlockArea[0].CopyFrom(a_Image);
+}
+
+
+
+
+
+cPrefab::cPrefab(const AString & a_BlockDefinitions, const AString & a_BlockData, int a_SizeX, int a_SizeY, int a_SizeZ) :
+ m_Size(a_SizeX, a_SizeY, a_SizeZ),
+ m_AllowedRotations(0),
+ m_MergeStrategy(cBlockArea::msOverwrite),
+ m_ShouldExtendFloor(false),
+ m_DefaultWeight(1),
+ m_AddWeightIfSame(0),
+ m_MoveToGround(false)
+{
+ m_HitBox.p1.Set(0, 0, 0);
+ m_HitBox.p2.Set(m_Size.x - 1, m_Size.y - 1, m_Size.z - 1);
+ m_BlockArea[0].Create(m_Size);
+ CharMap cm;
+ ParseCharMap(cm, a_BlockDefinitions.c_str());
+ ParseBlockImage(cm, a_BlockData.c_str());
+}
+
+
+
+
+
void cPrefab::AddRotatedBlockAreas(void)
{
// 1 CCW rotation:
@@ -326,6 +365,16 @@ void cPrefab::AddConnector(int a_RelX, int a_RelY, int a_RelZ, eBlockFace a_Dire
+void cPrefab::SetAllowedRotations(int a_AllowedRotations)
+{
+ m_AllowedRotations = a_AllowedRotations;
+ AddRotatedBlockAreas();
+}
+
+
+
+
+
void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
{
ASSERT(a_CharMapDef != nullptr);
@@ -348,13 +397,13 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
LOGWARNING("Bad prefab CharMap definition line: \"%s\", skipping.", itr->c_str());
continue;
}
- unsigned char Src = (unsigned char)CharDef[0][0];
+ unsigned char Src = static_cast<unsigned char>(CharDef[0][0]);
ASSERT(a_CharMapOut[Src].m_BlockMeta == 16); // This letter has not been assigned yet?
- a_CharMapOut[Src].m_BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str());
+ a_CharMapOut[Src].m_BlockType = static_cast<BLOCKTYPE>(atoi(CharDef[1].c_str()));
NIBBLETYPE BlockMeta = 0;
if ((NumElements >= 3) && !CharDef[2].empty())
{
- BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str());
+ BlockMeta = static_cast<NIBBLETYPE>(atoi(CharDef[2].c_str()));
ASSERT((BlockMeta <= 15));
}
a_CharMapOut[Src].m_BlockMeta = BlockMeta;
@@ -372,7 +421,7 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma
{
for (int z = 0; z < m_Size.z; z++)
{
- const unsigned char * BlockImage = (const unsigned char *)a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x;
+ const unsigned char * BlockImage = reinterpret_cast<const unsigned char *>(a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x);
for (int x = 0; x < m_Size.x; x++)
{
const sBlockTypeDef & MappedValue = a_CharMap[BlockImage[x]];
@@ -424,7 +473,7 @@ void cPrefab::ParseConnectors(const char * a_ConnectorsDef)
m_Connectors.push_back(cPiece::cConnector(
atoi(Coords[0].c_str()), atoi(Coords[1].c_str()), atoi(Coords[2].c_str()), // Connector pos
atoi(Defs[0].c_str()), // Connector type
- (eBlockFace)BlockFace
+ static_cast<eBlockFace>(BlockFace)
));
} // for itr - Lines[]
}