streamline the way command line arguments are used

This commit is contained in:
Joseph Aquino 2025-09-29 19:01:24 -04:00
parent cdda33f786
commit cb31a38427
3 changed files with 12 additions and 40 deletions

View File

@ -45,10 +45,11 @@ struct Player
class Game class Game
{ {
public: public:
Game(); Game() = delete;
Game(bool useImgui_in);
void run(); void run();
void runNoImgui();
private: private:
void imgui(); void imgui();
@ -118,5 +119,6 @@ private:
Color brickColor{}; Color brickColor{};
Color playerColor{}; Color playerColor{};
Color specialBrickColor{}; Color specialBrickColor{};
bool useImgui;
static constexpr unsigned int numPhysicsUpdates{4}; static constexpr unsigned int numPhysicsUpdates{4};
}; };

View File

@ -25,7 +25,7 @@ Player::Player(sf::Vector2f position_in)
{ } { }
Game::Game() Game::Game(bool useImgui_in)
: window({sf::VideoMode({ 1920u, 1080u }), "project-breakout"}) : window({sf::VideoMode({ 1920u, 1080u }), "project-breakout"})
, font("assets/fonts/ChakraPetch-Regular.ttf") , font("assets/fonts/ChakraPetch-Regular.ttf")
, lives(font) , lives(font)
@ -38,6 +38,7 @@ Game::Game()
, brickBreakSound(brickBreakSoundBuffer) , brickBreakSound(brickBreakSoundBuffer)
, failSound(failSoundBuffer) , failSound(failSoundBuffer)
, volume(10) , volume(10)
, useImgui(useImgui_in)
{ {
if (!ImGui::SFML::Init(window)) return; if (!ImGui::SFML::Init(window)) return;
@ -664,7 +665,10 @@ void Game::run()
checkEndGame(); checkEndGame();
if (useImgui)
{
imgui(); imgui();
}
render(); render();
@ -672,32 +676,3 @@ void Game::run()
ImGui::SFML::Shutdown(); ImGui::SFML::Shutdown();
} }
void Game::runNoImgui()
{
while(window.isOpen())
{
ImGui::SFML::Update(window, clock.restart());
input();
for (size_t i = 0; i <= numPhysicsUpdates; i++)
{
updateEntities();
movement();
collision();
soundSystem();
scoreSystem();
}
checkEndGame();
render();
}
ImGui::SFML::Shutdown();
}

View File

@ -2,7 +2,6 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
Game game;
// parse command-line arguments // parse command-line arguments
bool useImgui{true}; bool useImgui{true};
@ -14,12 +13,8 @@ int main(int argc, char* argv[])
} }
} }
if (useImgui) Game game(useImgui);
{
game.run(); game.run();
}
else
{
game.runNoImgui();
}
} }