Skip to content

Commit 296a6c2

Browse files
committed
-
1 parent e50ce83 commit 296a6c2

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

src/CarnageGame.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "MemoryManager.h"
1010

1111
static const char* InputsConfigPath = "config/inputs.json";
12+
static const char* GTA1MapFileExtension = ".CMP";
1213

1314
//////////////////////////////////////////////////////////////////////////
1415

@@ -23,11 +24,45 @@ bool CarnageGame::Initialize()
2324
SetInputActionsFromConfig();
2425

2526
gGameRules.LoadDefaults();
27+
28+
// scan all gta1 maps
29+
std::vector<std::string> gtaMapNames;
30+
for (const std::string& currSearchPlace: gFiles.mSearchPlaces)
31+
{
32+
cxx::enum_files(currSearchPlace, [&gtaMapNames](const std::string& curr)
33+
{
34+
if (cxx::get_file_extension(curr) == GTA1MapFileExtension)
35+
{
36+
gtaMapNames.push_back(curr);
37+
}
38+
});
39+
}
40+
41+
if (gtaMapNames.size())
42+
{
43+
gConsole.LogMessage(eLogMessage_Info, "Found GTA1 maps:");
44+
for (const std::string& currMapname: gtaMapNames)
45+
{
46+
gConsole.LogMessage(eLogMessage_Info, " - %s", currMapname.c_str());
47+
}
48+
}
49+
else
50+
{
51+
gConsole.LogMessage(eLogMessage_Warning, "No GTA1 maps found within search places");
52+
}
53+
2654
if (gSystem.mStartupParams.mDebugMapName.empty())
2755
{
28-
gSystem.mStartupParams.mDebugMapName.set_content("NYC.CMP");
56+
// try load first found map
57+
if (gtaMapNames.size())
58+
{
59+
gSystem.mStartupParams.mDebugMapName = gtaMapNames[0].c_str();
60+
}
2961
}
3062

63+
if (gSystem.mStartupParams.mDebugMapName.empty())
64+
return false;
65+
3166
gGameMap.LoadFromFile(gSystem.mStartupParams.mDebugMapName.c_str());
3267
gSpriteManager.Cleanup();
3368
gRenderManager.mMapRenderer.BuildMapMesh();

src/GameMapManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ bool GameMapManager::LoadFromFile(const char* filename)
6666
{
6767
Cleanup();
6868

69+
gConsole.LogMessage(eLogMessage_Info, "Loading map '%s'", filename);
70+
6971
std::ifstream file;
7072
if (!gFiles.OpenBinaryFile(filename, file))
7173
{

src/GraphicsDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,8 @@ void GraphicsDevice::QueryGraphicsDeviceCaps()
11321132
glCheckError();
11331133

11341134
gConsole.LogMessage(eLogMessage_Info, "Graphics Device caps:");
1135-
gConsole.LogMessage(eLogMessage_Info, "- max array texture layers: %d", mCaps.mMaxArrayTextureLayers);
1136-
gConsole.LogMessage(eLogMessage_Info, "- max texture buffer size: %d bytes", mCaps.mMaxTextureBufferSize);
1135+
gConsole.LogMessage(eLogMessage_Info, " - max array texture layers: %d", mCaps.mMaxArrayTextureLayers);
1136+
gConsole.LogMessage(eLogMessage_Info, " - max texture buffer size: %d bytes", mCaps.mMaxTextureBufferSize);
11371137
}
11381138

11391139
void GraphicsDevice::ActivateTextureUnit(eTextureUnit textureUnit)

src/path_utils.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,34 @@ bool ensure_path_exists(std::string pathto)
8080
return filesystem::create_directories(sourcePath);
8181
}
8282

83+
void enum_files(std::string pathto, enum_files_proc enumproc)
84+
{
85+
filesystem::path sourcePath {pathto};
86+
if (!filesystem::exists(sourcePath))
87+
return;
88+
89+
filesystem::directory_iterator iter_directory_end;
90+
for (filesystem::directory_iterator iter_directory(sourcePath);
91+
iter_directory != iter_directory_end; ++iter_directory)
92+
{
93+
const filesystem::path& currentFile = iter_directory->path();
94+
enumproc(currentFile.filename().generic_string());
95+
}
96+
}
97+
98+
void enum_files_recursive(std::string pathto, enum_files_proc enumproc)
99+
{
100+
filesystem::path sourcePath {pathto};
101+
if (!filesystem::exists(sourcePath))
102+
return;
103+
104+
filesystem::recursive_directory_iterator iter_directory_end;
105+
for (filesystem::recursive_directory_iterator iter_directory(sourcePath);
106+
iter_directory != iter_directory_end; ++iter_directory)
107+
{
108+
const filesystem::path& currentFile = iter_directory->path();
109+
enumproc(currentFile.filename().generic_string());
110+
}
111+
}
112+
83113
} // namespace cxx

src/path_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace cxx
44
{
5+
using enum_files_proc = std::function<void (const std::string&)>;
6+
57
// extract parent directory for element
68
// @param sourcePath: Path
79
std::string get_parent_directory(std::string pathto);
@@ -36,4 +38,10 @@ namespace cxx
3638
// create directories in path
3739
bool ensure_path_exists(std::string pathto);
3840

41+
// enumerate files and directories at specific location
42+
// @param pathto: Location
43+
// @param enumproc: Enumeration callback
44+
void enum_files(std::string pathto, enum_files_proc enumproc);
45+
void enum_files_recursive(std::string pathto, enum_files_proc enumproc);
46+
3947
} // namespace cxx

0 commit comments

Comments
 (0)