diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 19933cb3c..0ed9cf041 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -1023,7 +1023,7 @@ void GameController::OpenStamps() void GameController::OpenOptions() { - options = new OptionsController(gameModel->GetSimulation(), new OptionsCallback(this)); + options = new OptionsController(gameModel, new OptionsCallback(this)); ui::Engine::Ref().ShowWindow(options->GetView()); } diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 55f8e9c06..15dfad1d9 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -29,7 +29,8 @@ GameModel::GameModel(): colour(255, 0, 0, 255), toolStrength(1.0f), activeColourPreset(-1), - activeMenu(NULL) + activeMenu(NULL), + edgeMode(0) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); @@ -75,7 +76,8 @@ GameModel::GameModel(): } //Load config into simulation - sim->SetEdgeMode(Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0)); + edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0); + sim->SetEdgeMode(edgeMode); //Load last user if(Client::Ref().GetAuthUser().ID) @@ -350,6 +352,17 @@ Tool * GameModel::GetToolFromIdentifier(std::string identifier) return NULL; } +void GameModel::SetEdgeMode(int edgeMode) +{ + this->edgeMode = edgeMode; + sim->SetEdgeMode(edgeMode); +} + +int GameModel::GetEdgeMode() +{ + return this->edgeMode; +} + std::deque GameModel::GetHistory() { return history; @@ -512,8 +525,8 @@ void GameModel::SetSave(SaveInfo * newSave) sim->grav->start_grav_async(); else sim->grav->stop_grav_async(); - sim->clear_sim(); sim->SetEdgeMode(0); + sim->clear_sim(); ren->ClearAccumulation(); sim->Load(saveData); } @@ -541,8 +554,8 @@ void GameModel::SetSaveFile(SaveFile * newSave) { sim->grav->stop_grav_async(); } - sim->clear_sim(); sim->SetEdgeMode(0); + sim->clear_sim(); ren->ClearAccumulation(); sim->Load(saveData); } @@ -733,6 +746,20 @@ void GameModel::ClearSimulation() { sim->clear_sim(); ren->ClearAccumulation(); + + //Load defaults + SetPaused(false); + sim->gravityMode = 0; + sim->air->airMode = 0; + sim->legacy_enable = false; + sim->water_equal_test = false; + sim->grav->stop_grav_async(); + sim->SetEdgeMode(edgeMode); + sim->clear_sim(); + ren->ClearAccumulation(); + + notifySaveChanged(); + UpdateQuickOptions(); } void GameModel::SetStamp(GameSave * save) diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 10b4b1cc7..2ca8c2cd3 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -68,6 +68,8 @@ private: bool colourSelector; ui::Colour colour; + int edgeMode; + std::string infoTip; std::string toolTip; //bool zoomEnabled; @@ -100,6 +102,9 @@ public: Tool * GetToolFromIdentifier(std::string identifier); + void SetEdgeMode(int edgeMode); + int GetEdgeMode(); + void SetActiveColourPreset(int preset); int GetActiveColourPreset(); diff --git a/src/options/OptionsController.cpp b/src/options/OptionsController.cpp index add8cf7b8..579ad7303 100644 --- a/src/options/OptionsController.cpp +++ b/src/options/OptionsController.cpp @@ -8,12 +8,13 @@ #include "OptionsController.h" #include "dialogues/ErrorMessage.h" -OptionsController::OptionsController(Simulation * sim, ControllerCallback * callback_): +OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * callback_): callback(callback_), + gModel(gModel_), HasExited(false) { view = new OptionsView(); - model = new OptionsModel(sim); + model = new OptionsModel(gModel); model->AddObserver(view); view->AttachController(this); diff --git a/src/options/OptionsController.h b/src/options/OptionsController.h index 862a0e23c..43db1f8ab 100644 --- a/src/options/OptionsController.h +++ b/src/options/OptionsController.h @@ -13,15 +13,17 @@ #include "OptionsView.h" #include "OptionsModel.h" +class GameModel; class OptionsModel; class OptionsView; class OptionsController { + GameModel * gModel; OptionsView * view; OptionsModel * model; ControllerCallback * callback; public: bool HasExited; - OptionsController(Simulation * sim, ControllerCallback * callback_); + OptionsController(GameModel * gModel_, ControllerCallback * callback_); void SetHeatSimulation(bool state); void SetAmbientHeatSimulation(bool state); void SetNewtonianGravity(bool state); diff --git a/src/options/OptionsModel.cpp b/src/options/OptionsModel.cpp index be88d9bd1..f9cef2fc4 100644 --- a/src/options/OptionsModel.cpp +++ b/src/options/OptionsModel.cpp @@ -6,10 +6,12 @@ */ #include "simulation/Air.h" +#include "game/GameModel.h" #include "OptionsModel.h" -OptionsModel::OptionsModel(Simulation * sim_) { - sim = sim_; +OptionsModel::OptionsModel(GameModel * gModel_) { + gModel = gModel_; + sim = gModel->GetSimulation(); } void OptionsModel::AddObserver(OptionsView* view) @@ -77,11 +79,11 @@ void OptionsModel::SetAirMode(int airMode) int OptionsModel::GetEdgeMode() { - return sim->edgeMode; + return gModel->GetEdgeMode(); } void OptionsModel::SetEdgeMode(int edgeMode) { - sim->SetEdgeMode(edgeMode); + gModel->SetEdgeMode(edgeMode); notifySettingsChanged(); } diff --git a/src/options/OptionsModel.h b/src/options/OptionsModel.h index b011fef02..52b7fa5fa 100644 --- a/src/options/OptionsModel.h +++ b/src/options/OptionsModel.h @@ -11,14 +11,16 @@ #include "OptionsView.h" #include "simulation/Simulation.h" +class GameModel; class Simulation; class OptionsView; class OptionsModel { + GameModel * gModel; Simulation * sim; std::vector observers; void notifySettingsChanged(); public: - OptionsModel(Simulation * sim_); + OptionsModel(GameModel * gModel); void AddObserver(OptionsView* view); bool GetHeatSimulation(); void SetHeatSimulation(bool state);