From 25d933883a24c97b67f90ae6839ce3d6b8d630d5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:07:21 -0700 Subject: Removed unneeded assert Fixed CID 43610 --- src/Generating/Prefab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index c0c9e8a13..44d5097de 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -283,7 +283,7 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) if ((NumElements >= 3) && !CharDef[2].empty()) { BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str()); - ASSERT((BlockMeta >= 0) && (BlockMeta <= 15)); + ASSERT((BlockMeta <= 15)); } a_CharMapOut[Src].m_BlockMeta = BlockMeta; } // for itr - Lines[] -- cgit v1.2.3 From e4af9a21af44a7c5d4e02ac17a1b694858c8a39d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 5 May 2014 22:28:54 +0200 Subject: Prefabs can specify that they don't want flooring. Previously the flag was ignored. --- src/Generating/Prefab.cpp | 63 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 44d5097de..0f20603be 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -174,44 +174,47 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) - int MaxX = Image.GetSizeX(); - int MaxZ = Image.GetSizeZ(); - for (int z = 0; z < MaxZ; z++) + if (m_ShouldExtendFloor) { - int RelZ = Placement.z + z; - if ((RelZ < 0) || (RelZ >= cChunkDef::Width)) + int MaxX = Image.GetSizeX(); + int MaxZ = Image.GetSizeZ(); + for (int z = 0; z < MaxZ; z++) { - // Z coord outside the chunk - continue; - } - for (int x = 0; x < MaxX; x++) - { - int RelX = Placement.x + x; - if ((RelX < 0) || (RelX >= cChunkDef::Width)) - { - // X coord outside the chunk - continue; - } - BLOCKTYPE BlockType; - NIBBLETYPE BlockMeta; - Image.GetRelBlockTypeMeta(x, 0, z, BlockType, BlockMeta); - if ((BlockType == E_BLOCK_AIR) || (BlockType == E_BLOCK_SPONGE)) + int RelZ = Placement.z + z; + if ((RelZ < 0) || (RelZ >= cChunkDef::Width)) { - // Do not expand air nor sponge blocks + // Z coord outside the chunk continue; } - for (int y = Placement.y - 1; y >= 0; y--) + for (int x = 0; x < MaxX; x++) { - BLOCKTYPE ExistingBlock = a_Dest.GetBlockType(RelX, y, RelZ); - if (ExistingBlock != E_BLOCK_AIR) + int RelX = Placement.x + x; + if ((RelX < 0) || (RelX >= cChunkDef::Width)) + { + // X coord outside the chunk + continue; + } + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + Image.GetRelBlockTypeMeta(x, 0, z, BlockType, BlockMeta); + if ((BlockType == E_BLOCK_AIR) || (BlockType == E_BLOCK_SPONGE)) { - // End the expansion for this column, reached the end - break; + // Do not expand air nor sponge blocks + continue; } - a_Dest.SetBlockTypeMeta(RelX, y, RelZ, BlockType, BlockMeta); - } // for y - } // for x - } // for z + for (int y = Placement.y - 1; y >= 0; y--) + { + BLOCKTYPE ExistingBlock = a_Dest.GetBlockType(RelX, y, RelZ); + if (ExistingBlock != E_BLOCK_AIR) + { + // End the expansion for this column, reached the end + break; + } + a_Dest.SetBlockTypeMeta(RelX, y, RelZ, BlockType, BlockMeta); + } // for y + } // for x + } // for z + } } -- cgit v1.2.3 From 3660ce68343ad2e867e49d1650f61fc0eb85ac23 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 15 May 2014 00:12:01 +0200 Subject: cPrefab can be constructed in code. --- src/Generating/Prefab.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 0f20603be..9aef7a94b 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -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); -- cgit v1.2.3 From 7004043c6164c6b22346f94489cb823f9495738f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 17 May 2014 21:54:04 +0200 Subject: Village houses are height-adjusted onto the terrain. --- src/Generating/Prefab.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 9aef7a94b..506e1c2cc 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -191,13 +191,21 @@ void cPrefab::AddRotatedBlockAreas(void) void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const +{ + Draw(a_Dest, a_Placement->GetCoords(), a_Placement->GetNumCCWRotations()); +} + + + + +void cPrefab::Draw(cChunkDesc & a_Dest, const Vector3i & a_Placement, int a_NumRotations) const { // Draw the basic image: - Vector3i Placement = a_Placement->GetCoords(); + Vector3i Placement(a_Placement); int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width; int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; Placement.Move(-ChunkStartX, 0, -ChunkStartZ); - const cBlockArea & Image = m_BlockArea[a_Placement->GetNumCCWRotations()]; + const cBlockArea & Image = m_BlockArea[a_NumRotations]; a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) -- cgit v1.2.3 From 96a22cd82c350b1205985a9b8e01f5e6c11f069a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 24 May 2014 15:03:39 +0200 Subject: Added Japanese village prefabs. --- src/Generating/Prefab.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 506e1c2cc..05979507a 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -292,6 +292,15 @@ int cPrefab::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cC +void cPrefab::SetDefaultWeight(int a_DefaultWeight) +{ + m_DefaultWeight = a_DefaultWeight; +} + + + + + 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)); -- cgit v1.2.3 From 1a742a2b52d32bd22cd57b4d462bee312717e010 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 25 May 2014 23:50:16 +0200 Subject: Added support for Miners' Village. The village contains both prefabs that snap to ground and prefabs that connect strictly via connectors. Fixes #1027. --- src/Generating/Prefab.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 05979507a..e41907325 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -127,7 +127,8 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_MergeStrategy(a_Def.m_MergeStrategy), m_ShouldExtendFloor(a_Def.m_ShouldExtendFloor), m_DefaultWeight(a_Def.m_DefaultWeight), - m_AddWeightIfSame(a_Def.m_AddWeightIfSame) + m_AddWeightIfSame(a_Def.m_AddWeightIfSame), + m_MoveToGround(a_Def.m_MoveToGround) { m_BlockArea[0].Create(m_Size); CharMap cm; @@ -149,7 +150,8 @@ cPrefab::cPrefab(const cBlockArea & a_Image, int a_AllowedRotations) : m_MergeStrategy(cBlockArea::msOverwrite), m_ShouldExtendFloor(false), m_DefaultWeight(1), - m_AddWeightIfSame(0) + 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); -- cgit v1.2.3 From 24137e282bc97497bcf8c50745d2d45da59b1a27 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 26 May 2014 10:05:51 +0200 Subject: Fixed prefab test initialization. --- src/Generating/Prefab.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index e41907325..2ab1455b9 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -108,6 +108,9 @@ static const cPrefab::sDef g_TestPrefabDef = // AddWeightIfSame: 1000, + + // MoveToGround: + false, }; static cPrefab g_TestPrefab(g_TestPrefabDef); -- cgit v1.2.3 From 82dcc0b4db030f2a463a990652e0d75b67bdf835 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 22 Jun 2014 21:30:06 +0200 Subject: Prefabs don't draw into chunk if they don't intersect. --- src/Generating/Prefab.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 2ab1455b9..7d876909a 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -211,6 +211,17 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const Vector3i & a_Placement, int a_NumR int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; Placement.Move(-ChunkStartX, 0, -ChunkStartZ); const cBlockArea & Image = m_BlockArea[a_NumRotations]; + + // If the placement is outside this chunk, bail out: + if ( + (Placement.x > cChunkDef::Width) || (Placement.x + Image.GetSizeX() < 0) || + (Placement.z > cChunkDef::Width) || (Placement.z + Image.GetSizeZ() < 0) + ) + { + return; + } + + // Write the image: a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) -- cgit v1.2.3 From 5e198c673009cf8ca9d92cf59848999bc96bbc37 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:50:58 +0200 Subject: Basic style fixes. --- src/Generating/Prefab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating/Prefab.cpp') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 7d876909a..6da3c3d10 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -181,7 +181,7 @@ void cPrefab::AddRotatedBlockAreas(void) 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) -- cgit v1.2.3