Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading mod maps only #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,18 +798,27 @@ static void LoadNextMap()
SERVER_COMMAND(UTIL_VarArgs("map \"%s\"\n", mapName.c_str()));
}

static void LoadAllMaps()
// If modOnly is set to false all maps from the base game plus the mod will be
// loaded. If set to true, only the maps present in the mod maps directory will
// be loaded.
static void LoadMaps(bool modOnly)
{
if (!g_MapsToLoad.empty())
{
pmove->Con_Printf("Already loading all maps (%d remaining)\nUse sv_stop_loading_all_maps to stop\n",
pmove->Con_Printf("Already loading maps (%d remaining)\nUse sv_stop_loading_maps to stop\n",
static_cast<int>(g_MapsToLoad.size()));
return;
}

FileFindHandle_t handle = FILESYSTEM_INVALID_FIND_HANDLE;

const char* fileName = g_pFileSystem->FindFirst("maps/*.bsp", &handle);
const char* fileName = nullptr;
if (modOnly) {
auto dir = std::string(FileSystem_GetModDirectoryName()) + "/maps/*.bsp";
fileName = g_pFileSystem->FindFirst(dir.c_str(), &handle);
} else {
fileName = g_pFileSystem->FindFirst("maps/*.bsp", &handle);
}

if (fileName != nullptr)
{
Expand Down Expand Up @@ -866,11 +875,23 @@ static void LoadAllMaps()
}
}

static void LoadModMaps()
{
LoadMaps(true);
}

static void LoadAllMaps()
{
LoadMaps(false);
}

void InitMapLoadingUtils()
{
g_engfuncs.pfnAddServerCommand("sv_load_mod_maps", &LoadModMaps);
g_engfuncs.pfnAddServerCommand("sv_load_all_maps", &LoadAllMaps);

// Escape hatch in case the command is executed in error.
g_engfuncs.pfnAddServerCommand("sv_stop_loading_all_maps", []()
g_engfuncs.pfnAddServerCommand("sv_stop_loading_maps", []()
{ g_MapsToLoad.clear(); });
}

Expand Down