You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// No break to execute immediatly the AddingRooms state
79
+
}
80
+
case EState::AddingRooms: {
81
+
DungeonLog_Debug("--- AddingRooms State");
69
82
70
-
// Build the list of rooms
71
-
TQueueOrStack<URoom*> roomStack(listMode);
72
-
roomStack.Push(root);
73
-
URoom* currentRoom = nullptr;
74
-
TArray<URoom*> newRooms;
75
-
while (!roomStack.IsEmpty())
83
+
TArray<URoom*> NewRooms;
84
+
int BatchCount = RoomBatchSize;
85
+
while (!PendingRooms.IsEmpty() && BatchCount > 0)
76
86
{
77
-
currentRoom = roomStack.Pop();
78
-
check(IsValid(currentRoom)); // currentRoom should always be valid
87
+
--BatchCount;
88
+
URoom* CurrentRoom = PendingRooms.Pop();
89
+
check(IsValid(CurrentRoom)); // CurrentRoom should always be valid
79
90
80
-
if (!AddNewRooms(*currentRoom, newRooms))
91
+
if (!AddNewRooms(*CurrentRoom, NewRooms))
92
+
{
93
+
// Stop generation here
94
+
DungeonLog_Debug("--- Stopping generation as AddNewRooms returned false.");
95
+
PendingRooms.Empty();
81
96
break;
97
+
}
82
98
83
-
for (URoom* room : newRooms)
99
+
DungeonLog_Debug("--- %d rooms added to the dungeon.", NewRooms.Num());
100
+
for (URoom* room : NewRooms)
84
101
{
85
-
roomStack.Push(room);
102
+
PendingRooms.Push(room);
86
103
}
87
104
}
88
105
106
+
if (!PendingRooms.IsEmpty())
107
+
{
108
+
DungeonLog_Debug("--- Still pending rooms, yielding.");
109
+
}
110
+
else
111
+
{
112
+
DungeonLog_Debug("--- No more pending rooms, finalizing.");
113
+
CurrentState = EState::Finalizing;
114
+
}
115
+
// Proceed to next tick
116
+
YieldGeneration();
117
+
break;
118
+
}
119
+
case EState::Finalizing:
120
+
DungeonLog_Debug("--- Finalizing State");
89
121
// Initialize the dungeon by eg. altering the room instances
90
122
FinalizeDungeon();
91
-
92
-
ValidDungeon = IsValidDungeon();
93
-
} while (TriesLeft > 0 && !ValidDungeon);
94
-
95
-
if (!ValidDungeon)
96
-
{
97
-
DungeonLog_Error("Generated dungeon is not valid after %d tries. Make sure your ChooseNextRoomData and IsValidDungeon functions are correct.", Dungeon::MaxGenerationTryBeforeGivingUp());
123
+
CurrentState = EState::Idle;
124
+
if (!IsValidDungeon())
125
+
{
126
+
DungeonLog_Debug("--- Dungeon is not valid, tries left: %d", CurrentTriesLeft);
127
+
if (CurrentTriesLeft <= 0)
128
+
{
129
+
DungeonLog_Error("Generated dungeon is not valid after %d tries. Make sure your ChooseNextRoomData and IsValidDungeon functions are correct.", Dungeon::MaxGenerationTryBeforeGivingUp());
130
+
returnfalse;
131
+
}
132
+
else
133
+
{
134
+
CurrentState = EState::Initializing;
135
+
YieldGeneration();
136
+
}
137
+
}
138
+
break;
139
+
default:
140
+
DungeonLog_Error("CurrentState value is not supported.");
0 commit comments