MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GenerateDummyLevel

Function GenerateDummyLevel

TombEngine/Specific/winmain.cpp:193–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193bool GenerateDummyLevel(const std::string& levelPath)
194{
195 // Try loading embedded resource "data.bin"
196 HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(IDR_TITLELEVEL), "BIN");
197 if (hResource == NULL)
198 {
199 TENLog("Embedded title level file not found.", LogLevel::Error);
200 return false;
201 }
202
203 // Load resource into memory.
204 HGLOBAL hGlobal = LoadResource(NULL, hResource);
205 if (hGlobal == NULL)
206 {
207 TENLog("Failed to load embedded title level file.", LogLevel::Error);
208 return false;
209 }
210
211 // Lock resource to get data pointer.
212 void* pData = LockResource(hGlobal);
213 DWORD dwSize = SizeofResource(NULL, hResource);
214
215 // Write resource data to file.
216 try
217 {
218 auto dir = std::filesystem::path(levelPath).parent_path();
219 if (!dir.empty())
220 std::filesystem::create_directories(dir);
221
222 auto outFile = std::ofstream(levelPath, std::ios::binary);
223 if (!outFile)
224 throw std::ios_base::failure("Failed to create title level file.");
225
226 outFile.write(reinterpret_cast<const char*>(pData), dwSize);
227 if (!outFile)
228 throw std::ios_base::failure("Failed to write to title level file.");
229
230 outFile.close();
231 }
232 catch (const std::exception& ex)
233 {
234 TENLog("Error while generating title level file: " + std::string(ex.what()), LogLevel::Error);
235 return false;
236 }
237
238 return true;
239}
240
241unsigned CALLBACK ConsoleInput(void*)
242{

Callers 1

LoadLevelFileFunction · 0.85

Calls 5

TENLogFunction · 0.85
emptyMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected