commit 647f12da
Fixed some warnings and moved the argument parsing out from the main function
Changed files
| M | source/code/DialogBox.cpp before |
| M | source/code/ScoresDisplay.cpp before |
| M | source/code/main.cpp before |
| M | source/code/menudef.cpp before |
diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp
index f8ae13b..6c6b2a2 100644
--- a/source/code/DialogBox.cpp
+++ b/source/code/DialogBox.cpp
@@ -95,18 +95,18 @@ bool DialogBox::IsActive() {
void DialogBox::Draw(SDL_Renderer* target) {
- backgroundImage.Draw(screen, SDL_GetTicks(), 0, 0);
- DrawRectYellow(screen, x, y, 200, 600);
- nf_button_font.draw(screen, x+300, y+20, NFont::CENTER, "%s", header.c_str());
- nf_button_font.draw(screen, x+150, y+140, NFont::CENTER, _("Enter to accept"));
- nf_button_font.draw(screen, x+450, y+140, NFont::CENTER, _("Esc to cancel"));
- DrawRectWhite(screen, x+26, y+64, 54, 600-2*26);
- NFont_Write(screen, x+40, y+76,rk->GetString());
+ backgroundImage.Draw(target, SDL_GetTicks(), 0, 0);
+ DrawRectYellow(target, x, y, 200, 600);
+ nf_button_font.draw(target, x+300, y+20, NFont::CENTER, "%s", header.c_str());
+ nf_button_font.draw(target, x+150, y+140, NFont::CENTER, _("Enter to accept"));
+ nf_button_font.draw(target, x+450, y+140, NFont::CENTER, _("Esc to cancel"));
+ DrawRectWhite(target, x+26, y+64, 54, 600-2*26);
+ NFont_Write(target, x+40, y+76,rk->GetString());
std::string strHolder = rk->GetString();
strHolder.erase((int)rk->CharsBeforeCursor());
if (((SDL_GetTicks()/600)%2)==1) {
- NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
+ NFont_Write(target, x+40+nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
}
}
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp
index 443551d..027dd64 100644
--- a/source/code/ScoresDisplay.cpp
+++ b/source/code/ScoresDisplay.cpp
@@ -134,7 +134,7 @@ bool ScoresDisplay::IsActive() {
return isActive;
}
-void ScoresDisplay::Draw(SDL_Renderer* target) {
+void ScoresDisplay::Draw(SDL_Renderer*) {
switch (page) {
case 0:
//Highscores, endless
@@ -168,6 +168,7 @@ void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
if (page>=numberOfPages) {
page = 0;
}
+ processed = true;
}
if (isRightEvent(event)) {
@@ -175,10 +176,12 @@ void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
if (page<0) {
page = numberOfPages-1;
}
+ processed = true;
}
if (isConfirmEvent(event) || isEscapeEvent(event)) {
isActive = false;
+ processed = true;
}
}
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 0e675a8..06f90fc 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -1131,14 +1131,129 @@ static void StartTwoPlayerVs() {
player2->name = player2name;
}
+struct globalConfig {
+ string savepath;
+ vector<string> search_paths;
+ string puzzleName;
+};
+
+static void ParseArguments(int argc, char* argv[], globalConfig& conf) {
+ int consoleWidth = boost::program_options::options_description::m_default_line_length;
+ const char* columnsEnv = getenv("COLUMNS"); // Allows using "COLUMNS=300 help2man" for generating the man page without bad line breaks.
+ if (columnsEnv) {
+ consoleWidth = sago::StrToLong(columnsEnv);
+ }
+ const char* commandname = "blockattack";
+ if (argv[0]) {
+ //NULL on Windows
+ commandname = argv[0];
+ }
+ boost::program_options::options_description desc("Options", consoleWidth);
+ desc.add_options()
+ ("help,h", "Displays this message")
+ ("version", "Display the version information")
+ ("config,c", boost::program_options::value<vector<string> >(), "Read a config file with the values. Can be given multiple times")
+ ("nosound", "Disables the sound. Can be used if sound errors prevents you from starting")
+ ("priority", "Causes the game to not sleep between frames.")
+ ("verbose-basic", "Enables basic verbose messages")
+ ("verbose-game-controller", "Enables verbose messages regarding controllers")
+ ("print-search-path", "Prints the search path and quits")
+ ("puzzle-level-file", boost::program_options::value<string>(), "Sets the default puzzle file to load")
+ ("puzzle-single-level", boost::program_options::value<int>(), "Start the specific puzzle level directly")
+ ("bind-text-domain", boost::program_options::value<string>(), SPrintStringF("Overwrites the bind text domain used for finding translations. "
+ "Default: \"%s\"", LOCALEDIR).c_str())
+ ("homepath", boost::program_options::value<string>(), SPrintStringF("Set the home folder where settings are saved. The directory will be created if it does not exist."
+ " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str())
+
+ ;
+ boost::program_options::variables_map vm;
+ try {
+ boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
+ boost::program_options::notify(vm);
+ }
+ catch (exception& e) {
+ cerr << e.what() << "\n";
+ cerr << desc << "\n";
+ throw;
+ }
+ if (vm.count("config")) {
+ vector<string> config_filenames = vm["config"].as<vector<string> >();
+ for ( const string& s : config_filenames) {
+ std::ifstream config_file(s);
+ store(parse_config_file(config_file, desc), vm);
+ notify(vm);
+ }
+ }
+ if (vm.count("bind-text-domain")) {
+ string s = vm["bind-text-domain"].as<string>();
+ bindtextdomain (PACKAGE, s.c_str());
+ }
+ if (vm.count("homepath")) {
+ string s = vm["homepath"].as<string>();
+ setPathToSaveFiles(s);
+ conf.savepath = getPathToSaveFiles();
+ }
+ if (vm.count("help")) {
+ cout << SPrintStringF("Block Attack - Rise of the blocks %s\n\n"
+ "Block Attack - Rise of the Blocks is a puzzle/blockfall game inspired by Tetris Attack for the SNES.\n\n"
+ "%s\n\n", VERSION_NUMBER, "www.blockattack.net");
+ cout << "Usage: "<< commandname << " [OPTION]..." << "\n";
+ cout << desc << "\n";
+ cout << "Examples:" << "\n";
+ cout << "\tblockattack \tStart the game normally" << "\n";
+ cout << "\tblockattack --nosound\tStart the game without sound. Can be used if sound problems prevents the game from starting" << "\n";
+ cout << "\n";
+ cout << "Report bugs to the issue tracker here: <https://github.com/blockattack/blockattack-game/issues>" << "\n";
+ exit(0);
+ }
+ if (vm.count("version")) {
+ cout << "blockattack " << VERSION_NUMBER << "\n";
+ cout << "\n";
+ cout << "Copyright (C) 2005-2016 Poul Sander" << "\n";
+ cout << "License GPLv2+: GNU GPL version 2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> or later <http://gnu.org/licenses/gpl.html>" << "\n";
+ cout << "This is free software: you are free to change and redistribute it." << "\n";
+ cout << "There is NO WARRANTY, to the extent permitted by law." << "\n";
+ exit(0);
+ }
+ if (vm.count("nosound")) {
+ NoSound = true;
+ }
+ if (vm.count("priority")) {
+ highPriority = true;
+ }
+ if (vm.count("verbose-basic")) {
+ verboseLevel++;
+ }
+ if (vm.count("verbose-game-controller")) {
+ GameControllerSetVerbose(true);
+ }
+ if (vm.count("print-search-path")) {
+ for (const string& s : conf.search_paths) {
+ cout << s << "\n";
+ }
+ cout << conf.savepath << "\n";
+ exit(0);
+ }
+ if (vm.count("puzzle-single-level")) {
+ singlePuzzle = true;
+ singlePuzzleNr = vm["puzzle-single-level"].as<int>();
+ }
+
+ if (vm.count("puzzle-level-file")) {
+ conf.puzzleName = vm["puzzle-level-file"].as<string>();
+ }
+
+}
+
//Warning: the arguments to main must be "int argc, char* argv[]" NO CONST! or SDL_main will fail to find it
int main(int argc, char* argv[]) {
try {
//Init the file system abstraction layer
PHYSFS_init(argv[0]);
- vector<string> search_paths;
- FsSearchParthMainAppend(search_paths);
- string savepath = getPathToSaveFiles();
+ globalConfig config;
+ config.puzzleName = "puzzle.levels";
+ FsSearchParthMainAppend(config.search_paths);
+ config.savepath = getPathToSaveFiles();
highPriority = false; //if true the game will take most resources, but increase framerate.
bFullscreen = false;
//Set default Config variables:
@@ -1146,111 +1261,11 @@ int main(int argc, char* argv[]) {
bindtextdomain (PACKAGE, LOCALEDIR);
bind_textdomain_codeset(PACKAGE, "utf-8");
textdomain (PACKAGE);
- int consoleWidth = boost::program_options::options_description::m_default_line_length;
- const char* columnsEnv = getenv("COLUMNS"); // Allows using "COLUMNS=300 help2man" for generating the man page without bad line breaks.
- if (columnsEnv) {
- consoleWidth = sago::StrToLong(columnsEnv);
- }
- const char* commandname = "blockattack";
- if (argv[0]) {
- //NULL on Windows
- commandname = argv[0];
- }
- boost::program_options::options_description desc("Options", consoleWidth);
- desc.add_options()
- ("help,h", "Displays this message")
- ("version", "Display the version information")
- ("config,c", boost::program_options::value<vector<string> >(), "Read a config file with the values. Can be given multiple times")
- ("nosound", "Disables the sound. Can be used if sound errors prevents you from starting")
- ("priority", "Causes the game to not sleep between frames.")
- ("verbose-basic", "Enables basic verbose messages")
- ("verbose-game-controller", "Enables verbose messages regarding controllers")
- ("print-search-path", "Prints the search path and quits")
- ("puzzle-level-file", boost::program_options::value<string>(), "Sets the default puzzle file to load")
- ("puzzle-single-level", boost::program_options::value<int>(), "Start the specific puzzle level directly")
- ("bind-text-domain", boost::program_options::value<string>(), SPrintStringF("Overwrites the bind text domain used for finding translations. "
- "Default: \"%s\"", LOCALEDIR).c_str())
- ("homepath", boost::program_options::value<string>(), SPrintStringF("Set the home folder where settings are saved. The directory will be created if it does not exist."
- " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str())
-
- ;
- boost::program_options::variables_map vm;
- try {
- boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
- boost::program_options::notify(vm);
- }
- catch (exception& e) {
- cerr << e.what() << "\n";
- cerr << desc << "\n";
- throw;
- }
- if (vm.count("config")) {
- vector<string> config_filenames = vm["config"].as<vector<string> >();
- for ( const string& s : config_filenames) {
- std::ifstream config_file(s);
- store(parse_config_file(config_file, desc), vm);
- notify(vm);
- }
- }
- if (vm.count("bind-text-domain")) {
- string s = vm["bind-text-domain"].as<string>();
- bindtextdomain (PACKAGE, s.c_str());
- }
- if (vm.count("homepath")) {
- string s = vm["homepath"].as<string>();
- setPathToSaveFiles(s);
- savepath = getPathToSaveFiles();
- }
- if (vm.count("help")) {
- cout << SPrintStringF("Block Attack - Rise of the blocks %s\n\n"
- "Block Attack - Rise of the Blocks is a puzzle/blockfall game inspired by Tetris Attack for the SNES.\n\n"
- "%s\n\n", VERSION_NUMBER, "www.blockattack.net");
- cout << "Usage: "<< commandname << " [OPTION]..." << "\n";
- cout << desc << "\n";
- cout << "Examples:" << "\n";
- cout << "\tblockattack \tStart the game normally" << "\n";
- cout << "\tblockattack --nosound\tStart the game without sound. Can be used if sound problems prevents the game from starting" << "\n";
- cout << "\n";
- cout << "Report bugs to the issue tracker here: <https://github.com/blockattack/blockattack-game/issues>" << "\n";
- return 0;
- }
- if (vm.count("version")) {
- cout << "blockattack " << VERSION_NUMBER << "\n";
- cout << "\n";
- cout << "Copyright (C) 2005-2016 Poul Sander" << "\n";
- cout << "License GPLv2+: GNU GPL version 2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> or later <http://gnu.org/licenses/gpl.html>" << "\n";
- cout << "This is free software: you are free to change and redistribute it." << "\n";
- cout << "There is NO WARRANTY, to the extent permitted by law." << "\n";
- return 0;
- }
- if (vm.count("nosound")) {
- NoSound = true;
- }
- if (vm.count("priority")) {
- highPriority = true;
- }
- if (vm.count("verbose-basic")) {
- verboseLevel++;
- }
- if (vm.count("verbose-game-controller")) {
- GameControllerSetVerbose(true);
- }
- if (vm.count("print-search-path")) {
- for (const string& s : search_paths) {
- cout << s << "\n";
- }
- cout << savepath << "\n";
- return 0;
- }
- if (vm.count("puzzle-single-level")) {
- singlePuzzle = true;
- singlePuzzleNr = vm["puzzle-single-level"].as<int>();
- }
+ ParseArguments(argc, argv, config);
OsCreateSaveFolder();
- PhysFsSetSearchPath(search_paths, savepath);
+ PhysFsSetSearchPath(config.search_paths, config.savepath);
//Os create folders must be after the paramters because they can change the home folder
PhysFsCreateFolders();
-
SoundEnabled = true;
MusicEnabled = true;
twoPlayers = false; //true if two players splitscreen
@@ -1258,16 +1273,9 @@ int main(int argc, char* argv[]) {
theTopScoresTimeTrial = Highscore("timetrial");
drawBalls = true;
puzzleLoaded = false;
-
theBallManager = BallManager();
theExplosionManager = ExplosionManager();
-
- PuzzleSetName("puzzle.levels");
- if (vm.count("puzzle-level-file")) {
- string s = vm["puzzle-level-file"].as<string>();
- PuzzleSetName(s);
- }
-
+ PuzzleSetName(config.puzzleName);
//Init SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
sago::SagoFatalErrorF("Unable to init SDL: %s", SDL_GetError());
@@ -1278,9 +1286,6 @@ int main(int argc, char* argv[]) {
InitGameControllers();
TTF_Init();
atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc)
-
- //SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
-
theTextManager = TextManager();
//Open Audio
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp
index 3e0729a..f3467ac 100644
--- a/source/code/menudef.cpp
+++ b/source/code/menudef.cpp
@@ -99,33 +99,33 @@ void InitMenues() {
standardButton.thefont = &nf_scoreboard_font;
}
+#define UNUSED __attribute__((unused))
-
-static void runSinglePlayerEndless(Button* b) {
+static void runSinglePlayerEndless(Button* b UNUSED) {
runGame(Gametype::SinglePlayerEndless, 0);
}
-static void runSinglePlayerTimeTrial(Button* b) {
+static void runSinglePlayerTimeTrial(Button* b UNUSED) {
runGame(Gametype::SinglePlayerTimeTrial, 0);
}
-static void runStageClear(Button* b) {
+static void runStageClear(Button* b UNUSED) {
runGame(Gametype::StageClear, 0);
}
-static void runSinglePlayerPuzzle(Button* b) {
+static void runSinglePlayerPuzzle(Button* b UNUSED) {
runGame(Gametype::Puzzle, 0);
}
-static void runSinglePlayerVs(Button* b) {
+static void runSinglePlayerVs(Button* b UNUSED) {
runGame(Gametype::SinglePlayerVs, b->iGeneric1);
}
-static void runTwoPlayerTimeTrial(Button* b) {
+static void runTwoPlayerTimeTrial(Button* b UNUSED) {
runGame(Gametype::TwoPlayerTimeTrial, 0);
}
-static void runTwoPlayerVs(Button* b) {
+static void runTwoPlayerVs(Button* b UNUSED) {
runGame(Gametype::TwoPlayerVs, 0);
}
@@ -145,19 +145,19 @@ static void buttonActionFullscreen(Button* b) {
ResetFullscreen();
}
-static void buttonActionPlayer1Name(Button* b) {
+static void buttonActionPlayer1Name(Button* b UNUSED) {
if ( OpenDialogbox(200, 100, player1name, _("Enter player 1 name:")) ) {
return; //must save if true
}
}
-static void buttonActionPlayer2Name(Button* b) {
+static void buttonActionPlayer2Name(Button* b UNUSED) {
if ( OpenDialogbox(200, 100, player2name, _("Enter player 2 name:")) ) {
return; //must save if true
}
}
-static void buttonActionHighscores(Button* b) {
+static void buttonActionHighscores(Button* b UNUSED) {
OpenScoresDisplay();
}
@@ -178,15 +178,15 @@ static void ChangeKeysMenu(long playernumber) {
km.run();
}
-static void ChangeKeysMenu1(Button* b) {
+static void ChangeKeysMenu1(Button* b UNUSED) {
ChangeKeysMenu(0);
}
-static void ChangeKeysMenu2(Button* b) {
+static void ChangeKeysMenu2(Button* b UNUSED) {
ChangeKeysMenu(2);
}
-static void ConfigureMenu(Button* b) {
+static void ConfigureMenu(Button* b UNUSED) {
Menu cm(screen,_("Configuration"),true);
Button bMusic,bSound,buttonFullscreen,bPlayer1Name,bPlayer2Name;
Button bPlayer1Keys, bPlayer2Keys;
@@ -214,7 +214,7 @@ static void ConfigureMenu(Button* b) {
cm.run();
}
-static void SinglePlayerVsMenu(Button* b) {
+static void SinglePlayerVsMenu(Button* b UNUSED) {
Menu spvs(screen,_("Single player VS"),true);
Button d1,d2,d3,d4,d5,d6,d7;
d1.setAction(runSinglePlayerVs);
@@ -255,7 +255,7 @@ static void SinglePlayerVsMenu(Button* b) {
spvs.run();
}
-static void MultiplayerMenu(Button* b) {
+static void MultiplayerMenu(Button* b UNUSED) {
Menu mm(screen,_("Multiplayer"),true);
Button bTT, bVs;
bTT.setLabel(_("Two player - time trial"));