From de98b9c61d35890ad85694f52a66f249dc4fee5e Mon Sep 17 00:00:00 2001 From: CobaltXII Date: Mon, 31 Dec 2018 19:26:12 -0500 Subject: [PATCH] It is possible to specify the level location using the command line --- src/main.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4336e0d..a8c226c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,21 @@ By CobaltXII int main(int argc, char** argv) { + // Take command line arguments. + + std::string path_to_level = "level.dat"; + + if (argc == 2) + { + path_to_level = std::string(argv[1]); + } + else if (argc != 1) + { + std::cout << "Usage: " << argv[0] << " [path-to-level]" << std::endl; + + exit(16); + } + // Initialize SDL. if (SDL_Init(SDL_INIT_EVERYTHING)) @@ -143,7 +158,7 @@ int main(int argc, char** argv) // If the save file exists, load the_world from the save file. Otherwise, // generate a new world and save it to the save file. - if (std::ifstream("level.dat").good()) + if (std::ifstream(path_to_level).good()) { load_world_from_file ( @@ -153,7 +168,7 @@ int main(int argc, char** argv) player_y, player_z, - "level.dat" + path_to_level ); } else @@ -174,7 +189,7 @@ int main(int argc, char** argv) player_y, player_z, - "level.dat" + path_to_level ); } @@ -550,7 +565,7 @@ int main(int argc, char** argv) player_y, player_z, - "level.dat" + path_to_level ); // Destroy all Minceraft related objects.