diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-05 17:35:12 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-05 17:35:12 (GMT) |
| commit | 4ce22e4e7705224a9b4c1b9bfa8886de0029a3e3 (patch) | |
| tree | d9c02db57d9a20709758d7b771ee60ea9cbe4e88 /src | |
| parent | 30f8049efc6efc086509d235df413e4932dab83e (diff) | |
| download | powder-4ce22e4e7705224a9b4c1b9bfa8886de0029a3e3.zip powder-4ce22e4e7705224a9b4c1b9bfa8886de0029a3e3.tar.gz | |
Wall Edge option, fixes #70
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/Client.cpp | 84 | ||||
| -rw-r--r-- | src/client/Client.h | 4 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 17 | ||||
| -rw-r--r-- | src/options/OptionsController.cpp | 4 | ||||
| -rw-r--r-- | src/options/OptionsController.h | 1 | ||||
| -rw-r--r-- | src/options/OptionsModel.cpp | 10 | ||||
| -rw-r--r-- | src/options/OptionsModel.h | 2 | ||||
| -rw-r--r-- | src/options/OptionsView.cpp | 21 | ||||
| -rw-r--r-- | src/options/OptionsView.h | 1 | ||||
| -rw-r--r-- | src/simulation/Simulation.cpp | 36 | ||||
| -rw-r--r-- | src/simulation/Simulation.h | 3 |
11 files changed, 176 insertions, 7 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 5d1e439..64abe0e 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1692,6 +1692,34 @@ int Client::GetPrefInteger(std::string property, int defaultValue) return defaultValue; } +unsigned int Client::GetPrefUInteger(std::string property, unsigned int defaultValue) +{ + try + { + std::stringstream defHexInt; + defHexInt << std::hex << defaultValue; + + std::string hexString = GetPrefString(property, defHexInt.str()); + unsigned int finalValue = defaultValue; + + std::stringstream hexInt; + hexInt << hexString; + + hexInt >> std::hex >> finalValue; + + return finalValue; + } + catch (json::Exception & e) + { + + } + catch(exception & e) + { + + } + return defaultValue; +} + vector<string> Client::GetPrefStringArray(std::string property) { try @@ -1780,6 +1808,40 @@ vector<int> Client::GetPrefIntegerArray(std::string property) return vector<int>(); } +vector<unsigned int> Client::GetPrefUIntegerArray(std::string property) +{ + try + { + json::Array value = GetPref(property); + vector<unsigned int> intArray; + for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter) + { + try + { + json::String cValue = *iter; + unsigned int finalValue = 0; + + std::string hexString = cValue.Value(); + std::stringstream hexInt; + hexInt << std::hex << hexString; + hexInt >> finalValue; + + intArray.push_back(finalValue); + } + catch (json::Exception & e) + { + + } + } + return intArray; + } + catch (json::Exception & e) + { + + } + return vector<unsigned int>(); +} + vector<bool> Client::GetPrefBoolArray(std::string property) { try @@ -1841,6 +1903,14 @@ void Client::SetPref(std::string property, int value) SetPref(property, intValue); } +void Client::SetPref(std::string property, unsigned int value) +{ + std::stringstream hexInt; + hexInt << std::hex << value; + json::UnknownElement intValue = json::String(hexInt.str()); + SetPref(property, intValue); +} + void Client::SetPref(std::string property, vector<string> value) { json::Array newArray; @@ -1888,6 +1958,20 @@ void Client::SetPref(std::string property, vector<int> value) SetPref(property, newArrayValue); } +void Client::SetPref(std::string property, vector<unsigned int> value) +{ + json::Array newArray; + for(vector<unsigned int>::iterator iter = value.begin(); iter != value.end(); ++iter) + { + std::stringstream hexInt; + hexInt << std::hex << *iter; + + newArray.Insert(json::String(hexInt.str())); + } + json::UnknownElement newArrayValue = newArray; + SetPref(property, newArrayValue); +} + void Client::SetPref(std::string property, bool value) { json::UnknownElement boolValue = json::Boolean(value); diff --git a/src/client/Client.h b/src/client/Client.h index bea6ffc..9bb9d5f 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -133,18 +133,22 @@ public: std::string GetPrefString(std::string property, std::string defaultValue); double GetPrefNumber(std::string property, double defaultValue); int GetPrefInteger(std::string property, int defaultValue); + unsigned int GetPrefUInteger(std::string property, unsigned int defaultValue); vector<string> GetPrefStringArray(std::string property); vector<double> GetPrefNumberArray(std::string property); vector<int> GetPrefIntegerArray(std::string property); + vector<unsigned int> GetPrefUIntegerArray(std::string property); vector<bool> GetPrefBoolArray(std::string property); bool GetPrefBool(std::string property, bool defaultValue); void SetPref(std::string property, std::string value); void SetPref(std::string property, double value); void SetPref(std::string property, int value); + void SetPref(std::string property, unsigned int value); void SetPref(std::string property, vector<string> value); void SetPref(std::string property, vector<double> value); void SetPref(std::string property, vector<int> value); + void SetPref(std::string property, vector<unsigned int> value); void SetPref(std::string property, vector<bool> value); void SetPref(std::string property, bool value); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 91d6a4f..a53bba2 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -33,16 +33,16 @@ GameModel::GameModel(): //Load config into renderer try { - ren->SetColourMode(Client::Ref().GetPrefNumber("Renderer.ColourMode", 0)); + ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0)); - vector<double> tempArray = Client::Ref().GetPrefNumberArray("Renderer.DisplayModes"); + vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes"); if(tempArray.size()) { std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end()); ren->SetDisplayMode(displayModes); } - tempArray = Client::Ref().GetPrefNumberArray("Renderer.RenderModes"); + tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes"); if(tempArray.size()) { std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end()); @@ -54,6 +54,9 @@ GameModel::GameModel(): } + //Load config into simulation + sim->SetEdgeMode(Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0)); + //Load last user if(Client::Ref().GetAuthUser().ID) { @@ -84,13 +87,15 @@ GameModel::GameModel(): GameModel::~GameModel() { //Save to config: - Client::Ref().SetPref("Renderer.ColourMode", (double)ren->GetColourMode()); + Client::Ref().SetPref("Renderer.ColourMode", ren->GetColourMode()); std::vector<unsigned int> displayModes = ren->GetDisplayMode(); - Client::Ref().SetPref("Renderer.DisplayModes", std::vector<double>(displayModes.begin(), displayModes.end())); + Client::Ref().SetPref("Renderer.DisplayModes", std::vector<unsigned int>(displayModes.begin(), displayModes.end())); std::vector<unsigned int> renderModes = ren->GetRenderMode(); - Client::Ref().SetPref("Renderer.RenderModes", std::vector<double>(renderModes.begin(), renderModes.end())); + Client::Ref().SetPref("Renderer.RenderModes", std::vector<unsigned int>(renderModes.begin(), renderModes.end())); + + Client::Ref().SetPref("Simulation.EdgeMode", sim->edgeMode); Client::Ref().SetPref("Decoration.Red", (int)colour.Red); Client::Ref().SetPref("Decoration.Green", (int)colour.Green); diff --git a/src/options/OptionsController.cpp b/src/options/OptionsController.cpp index f007316..7fa3309 100644 --- a/src/options/OptionsController.cpp +++ b/src/options/OptionsController.cpp @@ -46,6 +46,10 @@ void OptionsController::SetAirMode(int airMode) { model->SetAirMode(airMode); } +void OptionsController::SetEdgeMode(int airMode) +{ + model->SetEdgeMode(airMode); +} OptionsView * OptionsController::GetView() { diff --git a/src/options/OptionsController.h b/src/options/OptionsController.h index 19f0e9b..821eb68 100644 --- a/src/options/OptionsController.h +++ b/src/options/OptionsController.h @@ -28,6 +28,7 @@ public: void SetWaterEqualisation(bool state); void SetGravityMode(int gravityMode); void SetAirMode(int airMode); + void SetEdgeMode(int airMode); void Exit(); OptionsView * GetView(); virtual ~OptionsController(); diff --git a/src/options/OptionsModel.cpp b/src/options/OptionsModel.cpp index b24a513..6fe9a79 100644 --- a/src/options/OptionsModel.cpp +++ b/src/options/OptionsModel.cpp @@ -75,6 +75,16 @@ void OptionsModel::SetAirMode(int airMode) notifySettingsChanged(); } +int OptionsModel::GetEdgeMode() +{ + return sim->edgeMode; +} +void OptionsModel::SetEdgeMode(int edgeMode) +{ + sim->SetEdgeMode(edgeMode); + notifySettingsChanged(); +} + int OptionsModel::GetGravityMode() { return sim->gravityMode; diff --git a/src/options/OptionsModel.h b/src/options/OptionsModel.h index 8f83fc8..c7fa6a0 100644 --- a/src/options/OptionsModel.h +++ b/src/options/OptionsModel.h @@ -30,6 +30,8 @@ public: void SetWaterEqualisation(bool state); int GetAirMode(); void SetAirMode(int airMode); + int GetEdgeMode(); + void SetEdgeMode(int edgeMode); int GetGravityMode(); void SetGravityMode(int gravityMode); virtual ~OptionsModel(); diff --git a/src/options/OptionsView.cpp b/src/options/OptionsView.cpp index 1e0aea7..002bc8d 100644 --- a/src/options/OptionsView.cpp +++ b/src/options/OptionsView.cpp @@ -12,7 +12,7 @@ #include "interface/DropDown.h" OptionsView::OptionsView(): - ui::Window(ui::Point(-1, -1), ui::Point(300, 206)){ + ui::Window(ui::Point(-1, -1), ui::Point(300, 226)){ ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options"); tempLabel->SetTextColour(style::Colour::InformationTitle); @@ -118,6 +118,24 @@ OptionsView::OptionsView(): tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(tempLabel); + class EdgeModeChanged: public ui::DropDownAction + { + OptionsView * v; + public: + EdgeModeChanged(OptionsView * v): v(v) { } + virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetEdgeMode(option.second); } + }; + + edgeMode = new ui::DropDown(ui::Point(Size.X-88, 186), ui::Point(80, 16)); + AddComponent(edgeMode); + edgeMode->AddOption(std::pair<std::string, int>("Void", 0)); + edgeMode->AddOption(std::pair<std::string, int>("Solid", 1)); + edgeMode->SetActionCallback(new EdgeModeChanged(this)); + + tempLabel = new ui::Label(ui::Point(8, 186), ui::Point(Size.X-96, 16), "Edge Mode"); + tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + AddComponent(tempLabel); + class CloseAction: public ui::ButtonAction { @@ -145,6 +163,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender) waterEqualisation->SetChecked(sender->GetWaterEqualisation()); airMode->SetOption(sender->GetAirMode()); gravityMode->SetOption(sender->GetGravityMode()); + edgeMode->SetOption(sender->GetEdgeMode()); } void OptionsView::AttachController(OptionsController * c_) diff --git a/src/options/OptionsView.h b/src/options/OptionsView.h index 5103f23..821413d 100644 --- a/src/options/OptionsView.h +++ b/src/options/OptionsView.h @@ -24,6 +24,7 @@ class OptionsView: public ui::Window { ui::Checkbox * waterEqualisation; ui::DropDown * airMode; ui::DropDown * gravityMode; + ui::DropDown * edgeMode; public: OptionsView(); void NotifySettingsChanged(OptionsModel * sender); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 4fb9ac2..64969e1 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -750,6 +750,41 @@ int Simulation::create_part_add_props(int p, int x, int y, int tv, int rx, int r return p; } +void Simulation::SetEdgeMode(int newEdgeMode) +{ + edgeMode = newEdgeMode; + switch(edgeMode) + { + case 0: + for(int i = 0; i<(XRES/CELL); i++) + { + bmap[0][i] = 0; + bmap[YRES/CELL-1][i] = 0; + } + for(int i = 1; i<((YRES/CELL)-1); i++) + { + bmap[i][0] = 0; + bmap[i][XRES/CELL-1] = 0; + } + break; + case 1: + int i; + for(i=0; i<(XRES/CELL); i++) + { + bmap[0][i] = WL_WALL; + bmap[YRES/CELL-1][i] = WL_WALL; + } + for(i=1; i<((YRES/CELL)-1); i++) + { + bmap[i][0] = WL_WALL; + bmap[i][XRES/CELL-1] = WL_WALL; + } + break; + default: + SetEdgeMode(0); + } +} + void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, int colA_, int mode) { int rp; @@ -1801,6 +1836,7 @@ void Simulation::clear_sim(void) grav->Clear(); if(air) air->Clear(); + SetEdgeMode(edgeMode); } void Simulation::init_can_move() { diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index e4f4311..9b10df2 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -102,6 +102,7 @@ public: int photons[YRES][XRES]; int pmap_count[YRES][XRES]; // + int edgeMode; int gravityMode; //int airMode; int legacy_enable; @@ -156,6 +157,8 @@ public: void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert); void clear_area(int area_x, int area_y, int area_w, int area_h); + void SetEdgeMode(int newEdgeMode); + int Tool(int x, int y, int tool, float strength); int ToolBrush(int x, int y, int tool, Brush * cBrush); void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush); |
