From 37778e5f82f02eb417642390a36587a970e5479c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 25 Mar 2014 22:10:53 +0100 Subject: Added a basic cPrefab class. Can be defined in the source by GalExport's cpp output. --- src/Generating/Prefab.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/Generating/Prefab.h (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h new file mode 100644 index 000000000..6596b906b --- /dev/null +++ b/src/Generating/Prefab.h @@ -0,0 +1,83 @@ + +// Prefab.h + +/* +Declares the cPrefab class, representing a cPiece descendant for the cPieceGenerator that +uses a prefabricate in a cBlockArea for drawing itself. +The class can be constructed from data that is stored directly in the executable, in a sPrefabDef structure +declared in this file as well; the Gallery server exports areas in this format. +*/ + + + + + +#pragma once + +#include "PieceGenerator.h" +#include "../BlockArea.h" + + + + + + +class cPrefab : + public cPiece +{ +public: + struct sDef + { + int m_SizeX; + int m_SizeY; + int m_SizeZ; + const char * m_CharMap; + const char * m_Image; + // TODO: Connectors + }; + + cPrefab(const sDef & a_Def); + + /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ + void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + +protected: + /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ + typedef int CharMap[256]; + + + /** The cBlockArea that contains the block definitions for the prefab */ + cBlockArea m_BlockArea; + + /** The size of the prefab */ + Vector3i m_Size; + + /** The hitbox of the prefab. In first version is the same as the m_BlockArea dimensions */ + cCuboid m_HitBox; + + /** The connectors through which the piece connects to other pieces */ + cConnectors m_Connectors; + + /** Bitmask, bit N set -> N rotations CCW supported */ + int m_AllowedRotations; + + /** The merge strategy to use when drawing the prefab into a block area */ + cBlockArea::eMergeStrategy m_MergeStrategy; + + + // cPiece overrides: + virtual cConnectors GetConnectors(void) const override; + virtual Vector3i GetSize(void) const override; + virtual cCuboid GetHitBox(void) const override; + virtual bool CanRotateCCW(int a_NumRotations) const override; + + /** 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. */ + void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage); +}; + + + + -- cgit v1.2.3 From 8c2c4f2463fcc429d336019fa0fd39098eb7d97f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Mar 2014 22:01:01 +0100 Subject: Prefabs support connectors, rotations and merge strategy. --- src/Generating/Prefab.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 6596b906b..3733166ab 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -33,13 +33,18 @@ public: int m_SizeZ; const char * m_CharMap; const char * m_Image; - // TODO: Connectors + const char * m_Connectors; + int m_AllowedRotations; + cBlockArea::eMergeStrategy m_MergeStrategy; }; cPrefab(const sDef & a_Def); /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + + /** Returns true if the prefab has any connector of the specified type. */ + bool HasConnectorType(int a_ConnectorType) const; protected: /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ @@ -76,6 +81,9 @@ protected: /** Parses the Image in the definition into m_BlockArea'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. */ + void ParseConnectors(const char * a_ConnectorsDef); }; -- cgit v1.2.3 From 7b585290fccd3dc074b1f9feef0af754ab3dd632 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Mar 2014 23:03:57 +0100 Subject: cPrefab can draw itself into a cChunkDesc. --- src/Generating/Prefab.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 3733166ab..ec95c909b 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -40,8 +40,8 @@ public: cPrefab(const sDef & a_Def); - /** Draws the prefab into the specified block area, according to the placement stored in the PlacedPiece. */ - void Draw(cBlockArea & a_Dest, const cPlacedPiece * a_Placement); + /** 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; /** Returns true if the prefab has any connector of the specified type. */ bool HasConnectorType(int a_ConnectorType) const; -- cgit v1.2.3 From a2c4def518b0021a7575c9a9517f4f824369fe6d Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 28 Mar 2014 14:59:40 +0100 Subject: Add missing ChunkDesc import. --- src/Generating/Prefab.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index ec95c909b..c80de21b2 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -16,7 +16,7 @@ declared in this file as well; the Gallery server exports areas in this format. #include "PieceGenerator.h" #include "../BlockArea.h" - +#include "ChunkDesc.h" -- cgit v1.2.3 From 910e770a18520a96a5823b24b4b6a41068499414 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Mar 2014 16:36:33 +0100 Subject: Fixed Prefab's rotations. --- src/Generating/Prefab.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index ec95c909b..d6ab5658f 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -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. */ -- cgit v1.2.3 From d64d9145d1d84caaf21a906d5924c3855988fa33 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 29 Mar 2014 22:56:16 +0100 Subject: cPrefab now uses a struct for block type definition in CharMap. As suggested by worktycho in 7b585290fccd3dc074b1f9feef0af754ab3dd632, instead of packing the two values into a single int, they're packed into a struct. Also added a test code for the prefab parsing in SELF_TEST. --- src/Generating/Prefab.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/Generating/Prefab.h') diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 0b254c03b..04c4f09da 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -53,8 +53,15 @@ public: bool HasConnectorType(int a_ConnectorType) const; protected: + /** Packs complete definition of a single block, for per-letter assignment. */ + struct sBlockTypeDef + { + BLOCKTYPE m_BlockType; + NIBBLETYPE m_BlockMeta; + }; + /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ - typedef int CharMap[256]; + typedef sBlockTypeDef CharMap[256]; /** The cBlockArea that contains the block definitions for the prefab. -- cgit v1.2.3