Skip to content

Commit

Permalink
Adjust center position according to room and sublevel size
Browse files Browse the repository at this point in the history
  • Loading branch information
shun126 committed Apr 3, 2023
1 parent 1606dfe commit 94ad47e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Source/DungeonGenerator/Private/DungeonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ bool UDungeonGenerator::CreateImpl_AddRoomAsset(const UDungeonGenerateParameter*
break;
}

const FVector centerPosition = room->GetGroundCenter() * parameter->GetGridSize();
FVector centerPosition = room->GetGroundCenter() * parameter->GetGridSize();
if ((room->GetWidth() & 1) != (dungeonRoomLocator.GetWidth() & 1))
{
centerPosition.X += parameter->GetGridSize() / 2;
}
if ((room->GetDepth() & 1) != (dungeonRoomLocator.GetDepth() & 1))
{
centerPosition.Y += parameter->GetGridSize() / 2;
}
if (RequestStreamLevel(dungeonRoomLocator.GetLevelPath(), centerPosition))
{
room->SetDataSize(dungeonRoomLocator.GetWidth(), dungeonRoomLocator.GetDepth(), dungeonRoomLocator.GetHeight());
Expand Down Expand Up @@ -1048,6 +1056,7 @@ void UDungeonGenerator::LoadStreamLevel(const FSoftObjectPath& levelPath, const
if (bSuccess)
{
mLoadedStreamLevels.Emplace(levelPath);
DUNGEON_GENERATOR_LOG(TEXT("Load Level (%s)"), *levelPath.GetLongPackageName());
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Source/DungeonGenerator/Public/DungeonRoomLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ struct DUNGEONGENERATOR_API FDungeonRoomLocator
FSoftObjectPath LevelPath;

UPROPERTY(EditAnywhere, Category = "DungeonGenerator", meta = (ClampMin = 1))
int32 Width;
int32 Width = 1;

UPROPERTY(EditAnywhere, Category = "DungeonGenerator", meta = (ClampMin = 1))
int32 Depth;
int32 Depth = 1;

UPROPERTY(EditAnywhere, Category = "DungeonGenerator", meta = (ClampMin = 1))
int32 Height;
int32 Height = 1;

UPROPERTY(EditAnywhere, Category = "DungeonGenerator")
EDungeonRoomSizeCondition WidthCondition = EDungeonRoomSizeCondition::Equal;
Expand Down

0 comments on commit 94ad47e

Please sign in to comment.