1
0

cPrefab can be constructed in code.

This commit is contained in:
madmaxoft 2014-05-15 00:12:01 +02:00
parent 9c8e8ef7ae
commit 3660ce6834
2 changed files with 51 additions and 0 deletions

View File

@ -136,6 +136,33 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
ParseConnectors(a_Def.m_Connectors);
ParseDepthWeight(a_Def.m_DepthWeight);
AddRotatedBlockAreas();
}
cPrefab::cPrefab(const cBlockArea & a_Image, int a_AllowedRotations) :
m_Size(a_Image.GetSize()),
m_AllowedRotations(a_AllowedRotations),
m_MergeStrategy(cBlockArea::msOverwrite),
m_ShouldExtendFloor(false),
m_DefaultWeight(1),
m_AddWeightIfSame(0)
{
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);
AddRotatedBlockAreas();
}
void cPrefab::AddRotatedBlockAreas(void)
{
// 1 CCW rotation:
if ((m_AllowedRotations & 0x01) != 0)
{
@ -257,6 +284,15 @@ int cPrefab::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cC
void cPrefab::AddConnector(int a_RelX, int a_RelY, int a_RelZ, eBlockFace a_Direction, int a_Type)
{
m_Connectors.push_back(cConnector(a_RelX, a_RelY, a_RelZ, a_Type, a_Direction));
}
void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
{
ASSERT(a_CharMapDef != NULL);

View File

@ -84,8 +84,13 @@ public:
int m_AddWeightIfSame;
};
/** Creates a prefab from the provided definition. */
cPrefab(const sDef & a_Def);
/** Creates a prefab based on the given BlockArea and allowed rotations. */
cPrefab(const cBlockArea & a_Image, int a_AllowedRotations);
/** Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece. */
void Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const;
@ -98,6 +103,12 @@ public:
/** Returns the unmodified DefaultWeight property for the piece. */
int GetDefaultWeight(void) const { return m_DefaultWeight; }
/** Sets the AddWeightIfSame member, that is used to modify the weight when the previous piece is the same prefab */
void SetAddWeightIfSame(int a_AddWeightIfSame) { m_AddWeightIfSame = a_AddWeightIfSame; }
/** Adds the specified connector to the list of connectors this piece supports. */
void AddConnector(int a_RelX, int a_RelY, int a_RelZ, eBlockFace a_Direction, int a_Type);
protected:
/** Packs complete definition of a single block, for per-letter assignment. */
@ -160,6 +171,10 @@ protected:
virtual cCuboid GetHitBox(void) const override;
virtual bool CanRotateCCW(int a_NumRotations) const override;
/** Based on the m_AllowedRotations, adds rotated cBlockAreas to the m_BlockArea array.
To be called only from this class's constructor! */
void AddRotatedBlockAreas(void);
/** 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);