From d9349f10d6d1972e87aea76d502703fae128a0e5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 14 Mar 2015 17:58:50 -0400 Subject: Removed some unnecessary parameters from methods --- src/components.cpp | 2 +- src/entityfactory.cpp | 6 +++--- src/entityfactory.h | 2 +- src/game.cpp | 16 +++++++++------- src/game.h | 5 +++-- src/map.cpp | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/components.cpp b/src/components.cpp index 954ac57..512fbed 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -596,7 +596,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli collider.send(game, msg); } else if (collision.type == Collision::Type::danger) { - game.playerDie(collider, map); + game.playerDie(); } return false; diff --git a/src/entityfactory.cpp b/src/entityfactory.cpp index bf137e2..47a1463 100644 --- a/src/entityfactory.cpp +++ b/src/entityfactory.cpp @@ -15,7 +15,7 @@ struct EntityData { static std::map factories; -std::shared_ptr EntityFactory::createNamedEntity(const std::string name, const Map& map) +std::shared_ptr EntityFactory::createNamedEntity(const std::string name) { auto it = factories.find(name); EntityData data = factories[name]; @@ -81,10 +81,10 @@ std::shared_ptr EntityFactory::createNamedEntity(const std::string name, { if (!strcmp(data.action, "save")) { - auto component = std::make_shared([&] (Game& game, Entity& collider) { + auto component = std::make_shared([&] (Game& game, Entity&) { playSound("../res/Pickup_Coin23.wav", 0.25); - game.saveGame(map, collider.position); + game.saveGame(); }); entity->addComponent(component); } diff --git a/src/entityfactory.h b/src/entityfactory.h index 7b8f399..870d6d5 100644 --- a/src/entityfactory.h +++ b/src/entityfactory.h @@ -8,7 +8,7 @@ class Map; class EntityFactory { public: - static std::shared_ptr createNamedEntity(const std::string name, const Map& map); + static std::shared_ptr createNamedEntity(const std::string name); }; #endif diff --git a/src/game.cpp b/src/game.cpp index dd8f956..6e79f75 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -123,6 +123,8 @@ void Game::loadMap(const Map& map) nextEntities.push_back(player); newWorld = true; + + currentMap = ↦ } void Game::detectCollision(Entity& collider, std::pair old_position) @@ -133,9 +135,9 @@ void Game::detectCollision(Entity& collider, std::pair old_posit } } -void Game::saveGame(const Map& map, std::pair position) +void Game::saveGame() { - save = {&map, position}; + save = {currentMap, player->position}; } void Game::schedule(double time, std::function callback) @@ -143,19 +145,19 @@ void Game::schedule(double time, std::function callback) scheduled.emplace_front(time, std::move(callback)); } -void Game::playerDie(Entity& player, const Map& curMap) +void Game::playerDie() { - player.send(*this, Message::Type::die); + player->send(*this, Message::Type::die); playSound("../res/Hit_Hurt5.wav", 0.25); schedule(0.75, [&] () { - if (curMap != *save.map) + if (*currentMap != *save.map) { loadMap(*save.map); } - player.position = save.position; - player.send(*this, Message::Type::stopDying); + player->position = save.position; + player->send(*this, Message::Type::stopDying); }); } diff --git a/src/game.h b/src/game.h index 065aca8..bc31912 100644 --- a/src/game.h +++ b/src/game.h @@ -30,9 +30,9 @@ class Game { void execute(GLFWwindow* window); void loadMap(const Map& map); void detectCollision(Entity& collider, std::pair old_position); - void saveGame(const Map& map, std::pair position); + void saveGame(); void schedule(double time, std::function callback); - void playerDie(Entity& player, const Map& curMap); + void playerDie(); private: friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); @@ -41,6 +41,7 @@ class Game { std::list> nextEntities; bool newWorld; std::shared_ptr player; + const Map* currentMap; Savefile save; std::list>> scheduled; bool shouldQuit = false; diff --git a/src/map.cpp b/src/map.cpp index 5201cf2..73eb2b4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -176,7 +176,7 @@ void Map::createEntities(std::list>& entities) const { for (auto data : this->entities) { - auto entity = EntityFactory::createNamedEntity(data.name, *this); + auto entity = EntityFactory::createNamedEntity(data.name); entity->position = data.position; entities.push_back(entity); -- cgit 1.4.1