Skip to content

Commit

Permalink
Supports Sub Level Streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
shun126 committed Apr 2, 2023
1 parent d15ae8f commit 4ab8110
Show file tree
Hide file tree
Showing 33 changed files with 940 additions and 674 deletions.
7 changes: 7 additions & 0 deletions Source/DungeonGenerator/Private/Core/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,13 @@ namespace dungeon
, Grid::CreateFloor(parameter.GetRandom(), room->GetIdentifier().Get())
, Grid::CreateDeck(parameter.GetRandom(), room->GetIdentifier().Get())
);

const FVector center = (FVector(min) + FVector(max)) / 2;
const FVector dataSize(room->GetDataWidth(), room->GetDataDepth(), room->GetDataHeight());
const FVector dataHalfSize = dataSize / 2;
const FIntVector dataMin = FIntVector(center - dataHalfSize);
const FIntVector dataMax = dataMin + FIntVector(dataSize);
mVoxel->NoMeshGeneration(dataMin, dataMax);
}

// 通路の距離が短い順に並べ替える
Expand Down
4 changes: 2 additions & 2 deletions Source/DungeonGenerator/Private/Core/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace dungeon
}
}

void OnQueryParts(std::function<void(const std::shared_ptr<const Room>&)> func) noexcept
void OnQueryParts(std::function<void(const std::shared_ptr<Room>&)> func) noexcept
{
mQueryParts = func;
}
Expand Down Expand Up @@ -322,7 +322,7 @@ namespace dungeon

std::vector<Aisle> mAisles;

std::function<void(const std::shared_ptr<const Room>&)> mQueryParts;
std::function<void(const std::shared_ptr<Room>&)> mQueryParts;

uint8_t mDistance = 0;

Expand Down
5 changes: 4 additions & 1 deletion Source/DungeonGenerator/Private/Core/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ namespace dungeon
/*
自身からtoGridを見た時に床が生成されるか判定します
*/
bool Grid::CanBuildFloor(const Grid& toGrid) const noexcept
bool Grid::CanBuildFloor(const Grid& toGrid, const bool checkNoMeshGeneration) const noexcept
{
if (checkNoMeshGeneration && IsNoMeshGeneration())
return false;

if (IsKindOfRoomType())
{
return
Expand Down
25 changes: 20 additions & 5 deletions Source/DungeonGenerator/Private/Core/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace dungeon
/**
無効な識別子か判定します?
*/
bool IsInvalidIdetifier() const noexcept;
bool IsInvalidIdentifier() const noexcept;

/**
小道具を取得します
Expand Down Expand Up @@ -194,10 +194,11 @@ namespace dungeon
// 判定補助関数
/**
自身からtoGridを見た時に床が生成されるか判定します
\param[in] toGrid 参照先グリッド(通常は一つ下のグリッド)
\param[in] toGrid 参照先グリッド(通常は一つ下のグリッド)
\param[in] checkNoMeshGeneration メッシュ生成禁止判定
\return trueならば床の生成が可能
*/
bool CanBuildFloor(const Grid& toGrid) const noexcept;
bool CanBuildFloor(const Grid& toGrid, const bool checkNoMeshGeneration) const noexcept;

/**
斜面が生成されるか判定します
Expand Down Expand Up @@ -246,6 +247,19 @@ namespace dungeon
*/
bool CanBuildGate(const Grid& toGrid, const Direction::Index direction) const noexcept;

/**
メッシュ生成禁止に設定します
\param[in] noMeshGeneration メッシュ生成禁止
*/
void SetNoMeshGeneration(const bool noMeshGeneration);

/**
メッシュ生成禁止か取得します
\return trueならメッシュ生成禁止
*/
bool IsNoMeshGeneration() const noexcept;





Expand All @@ -260,9 +274,10 @@ namespace dungeon
private:
static constexpr uint16_t InvalidIdentifier = static_cast<uint16_t>(~0);

Type mType; //!< グリッドの種類
bool mNoMeshGeneration = false;
Type mType;
Props mProps;
Direction mDirection; //!< グリッドの方向
Direction mDirection;
uint16_t mIdentifier = InvalidIdentifier;
};
}
Expand Down
12 changes: 11 additions & 1 deletion Source/DungeonGenerator/Private/Core/Grid.inl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace dungeon
mIdentifier = identifier;
}

inline bool Grid::IsInvalidIdetifier() const noexcept
inline bool Grid::IsInvalidIdentifier() const noexcept
{
return mIdentifier == InvalidIdentifier;
}
Expand All @@ -95,4 +95,14 @@ namespace dungeon
{
mProps = props;
}

inline void Grid::SetNoMeshGeneration(const bool noMeshGeneration)
{
mNoMeshGeneration = noMeshGeneration;
}

inline bool Grid::IsNoMeshGeneration() const noexcept
{
return mNoMeshGeneration;
}
}
22 changes: 18 additions & 4 deletions Source/DungeonGenerator/Private/Core/Math/Random.inl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ namespace dungeon
}
else
{
const size_t value = Get<T>();
return value % to;
if (to != 0)
{
const size_t value = Get<T>();
return value % to;
}
else
{
return 0;
}
}
}

Expand All @@ -154,8 +161,15 @@ namespace dungeon
}
else
{
const size_t value = Get<T>();
return from + value % (to - from);
if (from != to)
{
const size_t value = Get<T>();
return from + value % (to - from);
}
else
{
return from;
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions Source/DungeonGenerator/Private/Core/Room.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ namespace dungeon



uint32_t GetDataWidth() const noexcept { return mDataWidth; }
uint32_t GetDataDepth() const noexcept { return mDataDepth; }
uint32_t GetDataHeight() const noexcept { return mDataHeight; }

void SetDataSize(const uint32_t dataWidth, const uint32_t dataDepth, const uint32_t dataHeight)
{
mDataWidth = dataWidth;
mDataDepth = dataDepth;
mDataHeight = dataHeight;
}


private:
int32_t mX;
int32_t mY;
Expand All @@ -301,6 +313,10 @@ namespace dungeon
uint32_t mDepth;
uint32_t mHeight;

uint32_t mDataWidth = 0;
uint32_t mDataDepth = 0;
uint32_t mDataHeight = 0;

Identifier mIdentifier;

Parts mParts = Parts::Unidentified;
Expand Down
31 changes: 30 additions & 1 deletion Source/DungeonGenerator/Private/Core/Voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@ namespace dungeon
}
}

void Voxel::NoMeshGeneration(const FIntVector& min, const FIntVector& max) noexcept
{
FIntVector min_;
min_.X = math::Clamp(min.X, 0, static_cast<int32_t>(mWidth));
min_.Y = math::Clamp(min.Y, 0, static_cast<int32_t>(mDepth));
min_.Z = math::Clamp(min.Z, 0, static_cast<int32_t>(mHeight));

FIntVector max_;
max_.X = math::Clamp(max.X, 0, static_cast<int32_t>(mWidth));
max_.Y = math::Clamp(max.Y, 0, static_cast<int32_t>(mDepth));
max_.Z = math::Clamp(max.Z, 0, static_cast<int32_t>(mHeight));

if (min_.X > max_.X) std::swap(min_.X, max_.X);
if (min_.Y > max_.Y) std::swap(min_.Y, max_.Y);
if (min_.Z > max_.Z) std::swap(min_.Z, max_.Z);

for (int32_t z = min_.Z; z < max_.Z; ++z)
{
for (int32_t y = min_.Y; y < max_.Y; ++y)
{
for (int32_t x = min_.X; x < max_.X; ++x)
{
const size_t index = Index(x, y, z);
mGrids.get()[index].SetNoMeshGeneration(true);
}
}
}
}

bool Voxel::SearchGateLocation(FIntVector& result, const FIntVector& start, const FIntVector& goal, const PathGoalCondition& goalCondition, const Identifier& identifier) noexcept
{
GateFinder gateFinder(start, goal);
Expand Down Expand Up @@ -251,7 +280,7 @@ namespace dungeon
Grid& grid = mGrids.get()[index];

// 識別子が無効なら通路
if (grid.IsInvalidIdetifier())
if (grid.IsInvalidIdentifier())
{
grid.SetIdentifier(identifier.Get());
}
Expand Down
2 changes: 2 additions & 0 deletions Source/DungeonGenerator/Private/Core/Voxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace dungeon
*/
void Rectangle(const FIntVector& min, const FIntVector& max, const Grid& fillGrid, const Grid& floorGrid) noexcept;

void NoMeshGeneration(const FIntVector& min, const FIntVector& max) noexcept;

/**
門を生成可能な場所を探します
\param[out] result FIntVector
Expand Down
20 changes: 0 additions & 20 deletions Source/DungeonGenerator/Private/DungeonDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ All Rights Reserved.

#include "DungeonDoor.h"

ADungeonDoor::ADungeonDoor(const FObjectInitializer& initializer)
: Super(initializer)
{
}

void ADungeonDoor::Initialize(const EDungeonRoomProps props)
{
Finalize();
Expand All @@ -29,18 +24,3 @@ void ADungeonDoor::Finalize()
mState = State::Finalized;
}
}

void ADungeonDoor::Reset()
{
OnReset();
}

EDungeonRoomProps ADungeonDoor::GetRoomProps() const
{
return Props;
}

void ADungeonDoor::SetRoomProps(const EDungeonRoomProps props)
{
Props = props;
}

0 comments on commit 4ab8110

Please sign in to comment.