From d4f6764c1c84afc19381fe3ce7c1a30511bae308 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Wed, 24 Apr 2024 10:25:22 -0500 Subject: [PATCH 1/9] Zones now have modifiable names with max length of 31. --- .../SimulationParametersSpot.h | 5 +++- source/Gui/SimulationParametersWindow.cpp | 27 ++++++++++++++++--- source/Gui/SimulationParametersWindow.h | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/source/EngineInterface/SimulationParametersSpot.h b/source/EngineInterface/SimulationParametersSpot.h index e8907fd19..e91e035f1 100644 --- a/source/EngineInterface/SimulationParametersSpot.h +++ b/source/EngineInterface/SimulationParametersSpot.h @@ -86,8 +86,11 @@ union SpotShapeData RectangularSpot rectangularSpot; }; +static constexpr size_t SIM_PARAM_SPOT_NAME_LENGTH = 32; + struct SimulationParametersSpot { + char name[SIM_PARAM_SPOT_NAME_LENGTH]{}; uint32_t color = 0; float posX = 0; float posY = 0; @@ -139,7 +142,7 @@ struct SimulationParametersSpot } } - return color == other.color && posX == other.posX && posY == other.posY && velX == other.velX && velY == other.velY + return (strcmp(name, other.name) == 0) && color == other.color && posX == other.posX && posY == other.posY && velX == other.velX && velY == other.velY && fadeoutRadius == other.fadeoutRadius && values == other.values && activatedValues == other.activatedValues && shapeType == other.shapeType; } bool operator!=(SimulationParametersSpot const& other) const { return !operator==(other); } diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index bc845d96b..ffeb979ec 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -72,6 +72,11 @@ _SimulationParametersWindow::_SimulationParametersWindow( for (int i = 0; i < CellFunction_Count; ++i) { _cellFunctionStrings.emplace_back(Const::CellFunctionToStringMap.at(i)); } + + for (int i = 0; i < MAX_SPOTS; ++i) { + _zoneNameStrings.emplace_back(""); + } + } _SimulationParametersWindow::~_SimulationParametersWindow() @@ -101,8 +106,12 @@ void _SimulationParametersWindow::processIntern() SimulationParametersSpot _SimulationParametersWindow::createSpot(SimulationParameters const& simParameters, int index) { - auto worldSize = _simController->getWorldSize(); SimulationParametersSpot spot; + + strcpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, std::string("Zone " + std::to_string(index)).c_str()); + + auto worldSize = _simController->getWorldSize(); + spot.posX = toFloat(worldSize.x / 2); spot.posY = toFloat(worldSize.y / 2); @@ -184,6 +193,7 @@ void _SimulationParametersWindow::processTabWidget( origParameters.spots[index] = createSpot(parameters, index); ++parameters.numSpots; ++origParameters.numSpots; + _zoneNameStrings[index] = parameters.spots[index].name; _simController->setSimulationParameters(parameters); _simController->setOriginalSimulationParameters(origParameters); } @@ -199,15 +209,15 @@ void _SimulationParametersWindow::processTabWidget( for (int tab = 0; tab < parameters.numSpots; ++tab) { SimulationParametersSpot& spot = parameters.spots[tab]; SimulationParametersSpot const& origSpot = origParameters.spots[tab]; - std::string name = "Zone " + std::to_string(tab + 1); - if (ImGui::BeginTabItem(name.c_str(), &open, ImGuiTabItemFlags_None)) { - processSpot(spot, origSpot, parameters); + if (ImGui::BeginTabItem(std::string(_zoneNameStrings[tab] + "###" + std::to_string(tab)).c_str(), &open, ImGuiTabItemFlags_None)) { + processSpot(tab,spot, origSpot, parameters); ImGui::EndTabItem(); } //delete spot if (!open) { for (int i = tab; i < parameters.numSpots - 1; ++i) { + _zoneNameStrings[i] = _zoneNameStrings[i + 1]; parameters.spots[i] = parameters.spots[i + 1]; origParameters.spots[i] = origParameters.spots[i + 1]; } @@ -1442,6 +1452,7 @@ void _SimulationParametersWindow::processBase( } void _SimulationParametersWindow::processSpot( + int tab, SimulationParametersSpot& spot, SimulationParametersSpot const& origSpot, SimulationParameters const& parameters) @@ -1449,6 +1460,14 @@ void _SimulationParametersWindow::processSpot( if (ImGui::BeginChild("##", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) { auto worldSize = _simController->getWorldSize(); + if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("General"))) { + if(AlienImGui::InputText(AlienImGui::InputTextParameters().name("Name").textWidth(RightColumnWidth), _zoneNameStrings[tab])){ + strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, _zoneNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); + _zoneNameStrings[tab] = _zoneNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); + } + AlienImGui::EndTreeNode(); + } + /** * Colors and location */ diff --git a/source/Gui/SimulationParametersWindow.h b/source/Gui/SimulationParametersWindow.h index c27ba3f0a..b6cc8ad01 100644 --- a/source/Gui/SimulationParametersWindow.h +++ b/source/Gui/SimulationParametersWindow.h @@ -21,7 +21,7 @@ class _SimulationParametersWindow : public _AlienWindow void processToolbar(); void processTabWidget(SimulationParameters& parameters, SimulationParameters const& lastParameters, SimulationParameters& origParameters); void processBase(SimulationParameters& parameters, SimulationParameters const& origParameters); - void processSpot(SimulationParametersSpot& spot, SimulationParametersSpot const& origSpot, SimulationParameters const& parameters); + void processSpot(int tab, SimulationParametersSpot& spot, SimulationParametersSpot const& origSpot, SimulationParameters const& parameters); void processAddonList(SimulationParameters& parameters, SimulationParameters const& lastParameters, SimulationParameters const& origParameters); void onOpenParameters(); @@ -41,6 +41,7 @@ class _SimulationParametersWindow : public _AlienWindow std::optional _sessionId; bool _focusBaseTab = false; std::vector _cellFunctionStrings; + std::vector _zoneNameStrings; bool _featureListOpen = false; float _featureListHeight = 200.0f; From 10c1dd70376ba386a238b76d65eea0e9b6eefe30 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Wed, 24 Apr 2024 10:54:06 -0500 Subject: [PATCH 2/9] Missing import --- source/EngineInterface/SimulationParametersSpot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/EngineInterface/SimulationParametersSpot.h b/source/EngineInterface/SimulationParametersSpot.h index e91e035f1..cf55da7a8 100644 --- a/source/EngineInterface/SimulationParametersSpot.h +++ b/source/EngineInterface/SimulationParametersSpot.h @@ -1,7 +1,7 @@ #pragma once #include - +#include #include "SimulationParametersSpotActivatedValues.h" #include "SimulationParametersSpotValues.h" From 8ec873a818bf5f7b897d73690fdc46fb25245030 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Wed, 24 Apr 2024 10:55:44 -0500 Subject: [PATCH 3/9] Make base impossible to close --- source/Gui/SimulationParametersWindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index ffeb979ec..497f4bbde 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -200,8 +200,7 @@ void _SimulationParametersWindow::processTabWidget( AlienImGui::Tooltip("Add parameter zone"); } - bool open = true; - if (ImGui::BeginTabItem("Base", &open, _focusBaseTab ? ImGuiTabItemFlags_SetSelected : ImGuiTabItemFlags_None)) { + if (ImGui::BeginTabItem("Base", nullptr, _focusBaseTab ? ImGuiTabItemFlags_SetSelected : ImGuiTabItemFlags_None)) { processBase(parameters, origParameters); ImGui::EndTabItem(); } From 507d6e96e8a5ac3cd5e29d10162e8e4a71323776 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Fri, 26 Apr 2024 01:38:54 -0500 Subject: [PATCH 4/9] Support reordering zone tabs and fix multiple tabs closing bug --- source/Gui/SimulationParametersWindow.cpp | 36 ++++++++++++++--------- source/Gui/SimulationParametersWindow.h | 7 +++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index 497f4bbde..26e4038e8 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -73,10 +73,11 @@ _SimulationParametersWindow::_SimulationParametersWindow( _cellFunctionStrings.emplace_back(Const::CellFunctionToStringMap.at(i)); } + _serialTabID = 0; for (int i = 0; i < MAX_SPOTS; ++i) { - _zoneNameStrings.emplace_back(""); + _spotNameStrings.emplace_back(""); + _spotTabIDs.emplace_back(std::to_string(0)); } - } _SimulationParametersWindow::~_SimulationParametersWindow() @@ -183,7 +184,7 @@ void _SimulationParametersWindow::processTabWidget( if (ImGui::BeginChild("##", ImVec2(0, 0), false)) { - if (ImGui::BeginTabBar("##Parameters", ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_FittingPolicyResizeDown)) { + if (ImGui::BeginTabBar("##Parameters", ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_Reorderable)) { //add spot if (parameters.numSpots < MAX_SPOTS) { @@ -193,30 +194,35 @@ void _SimulationParametersWindow::processTabWidget( origParameters.spots[index] = createSpot(parameters, index); ++parameters.numSpots; ++origParameters.numSpots; - _zoneNameStrings[index] = parameters.spots[index].name; + + _spotNameStrings[index] = parameters.spots[index].name; + _spotTabIDs[index] = std::to_string(_serialTabID); + ++_serialTabID; + _simController->setSimulationParameters(parameters); _simController->setOriginalSimulationParameters(origParameters); } AlienImGui::Tooltip("Add parameter zone"); } - if (ImGui::BeginTabItem("Base", nullptr, _focusBaseTab ? ImGuiTabItemFlags_SetSelected : ImGuiTabItemFlags_None)) { + if (ImGui::BeginTabItem("Base", nullptr, _focusBaseTab ? ImGuiTabItemFlags_SetSelected : ImGuiTabItemFlags_NoReorder)) { processBase(parameters, origParameters); ImGui::EndTabItem(); } - - for (int tab = 0; tab < parameters.numSpots; ++tab) { + for (int tab = 0; tab < parameters.numSpots;) { SimulationParametersSpot& spot = parameters.spots[tab]; SimulationParametersSpot const& origSpot = origParameters.spots[tab]; - if (ImGui::BeginTabItem(std::string(_zoneNameStrings[tab] + "###" + std::to_string(tab)).c_str(), &open, ImGuiTabItemFlags_None)) { + + bool open = true; + + if (ImGui::BeginTabItem(std::string(_spotNameStrings[tab] + "###" + _spotTabIDs[tab]).c_str(), &open, ImGuiTabItemFlags_None)) { processSpot(tab,spot, origSpot, parameters); ImGui::EndTabItem(); } - - //delete spot if (!open) { for (int i = tab; i < parameters.numSpots - 1; ++i) { - _zoneNameStrings[i] = _zoneNameStrings[i + 1]; + _spotNameStrings[i] = _spotNameStrings[i + 1]; + _spotTabIDs[i] = _spotTabIDs[i+1]; parameters.spots[i] = parameters.spots[i + 1]; origParameters.spots[i] = origParameters.spots[i + 1]; } @@ -224,6 +230,8 @@ void _SimulationParametersWindow::processTabWidget( --origParameters.numSpots; _simController->setSimulationParameters(parameters); _simController->setOriginalSimulationParameters(origParameters); + }else{ + ++tab; } } @@ -1460,9 +1468,9 @@ void _SimulationParametersWindow::processSpot( auto worldSize = _simController->getWorldSize(); if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("General"))) { - if(AlienImGui::InputText(AlienImGui::InputTextParameters().name("Name").textWidth(RightColumnWidth), _zoneNameStrings[tab])){ - strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, _zoneNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); - _zoneNameStrings[tab] = _zoneNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); + if(AlienImGui::InputText(AlienImGui::InputTextParameters().name("Name").textWidth(RightColumnWidth), _spotNameStrings[tab])){ + strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, _spotNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); + _spotNameStrings[tab] = _spotNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); } AlienImGui::EndTreeNode(); } diff --git a/source/Gui/SimulationParametersWindow.h b/source/Gui/SimulationParametersWindow.h index b6cc8ad01..5777e13b1 100644 --- a/source/Gui/SimulationParametersWindow.h +++ b/source/Gui/SimulationParametersWindow.h @@ -41,8 +41,11 @@ class _SimulationParametersWindow : public _AlienWindow std::optional _sessionId; bool _focusBaseTab = false; std::vector _cellFunctionStrings; - std::vector _zoneNameStrings; - + + std::vector _spotNameStrings; + std::vector _spotTabIDs; + int _serialTabID; + bool _featureListOpen = false; float _featureListHeight = 200.0f; }; \ No newline at end of file From 1de2d086db45bebba3d26b55e26bca55cf86f792 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Fri, 26 Apr 2024 06:37:01 -0500 Subject: [PATCH 5/9] Support zone name (de)/serialization. Truncate imgui string before copy. --- source/EngineInterface/AuxiliaryDataParserService.cpp | 9 +++++++++ source/Gui/SimulationParametersWindow.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/EngineInterface/AuxiliaryDataParserService.cpp b/source/EngineInterface/AuxiliaryDataParserService.cpp index 6a4948154..3cde87274 100644 --- a/source/EngineInterface/AuxiliaryDataParserService.cpp +++ b/source/EngineInterface/AuxiliaryDataParserService.cpp @@ -768,6 +768,15 @@ namespace std::string base = "simulation parameters.spots." + std::to_string(index) + "."; auto& spot = parameters.spots[index]; auto& defaultSpot = defaultParameters.spots[index]; + + std::string currentName(spot.name); + std::string defaultName(defaultSpot.name); + encodeDecodeProperty(tree, currentName, defaultName, base + "name", parserTask); + + if (parserTask == ParserTask::Decode){ + strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, currentName.c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); + } + encodeDecodeProperty(tree, spot.color, defaultSpot.color, base + "color", parserTask); encodeDecodeProperty(tree, spot.posX, defaultSpot.posX, base + "pos.x", parserTask); encodeDecodeProperty(tree, spot.posY, defaultSpot.posY, base + "pos.y", parserTask); diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index 26e4038e8..70bb422df 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -1469,8 +1469,8 @@ void _SimulationParametersWindow::processSpot( if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("General"))) { if(AlienImGui::InputText(AlienImGui::InputTextParameters().name("Name").textWidth(RightColumnWidth), _spotNameStrings[tab])){ + _spotNameStrings[tab] = _spotNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, _spotNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); - _spotNameStrings[tab] = _spotNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); } AlienImGui::EndTreeNode(); } @@ -2177,6 +2177,11 @@ void _SimulationParametersWindow::onOpenParameters() if (!SerializerService::deserializeSimulationParametersFromFile(parameters, firstFilename.string())) { MessageDialog::getInstance().information("Open simulation parameters", "The selected file could not be opened."); } else { + for(int spot = 0; spot < parameters.numSpots; ++spot){ + _spotNameStrings[spot] = std::string(parameters.spots[spot].name, SIM_PARAM_SPOT_NAME_LENGTH); + _spotTabIDs[spot] = std::to_string(_serialTabID); + ++_serialTabID; + } _simController->setSimulationParameters(parameters); } }); From 42cca56030042a367a54d04dd30e6db3bbcd7153 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Sat, 27 Apr 2024 01:23:36 -0500 Subject: [PATCH 6/9] Fix reorder on deserialization bug - c string was copied into std::string with null char since constructor had a count parameter, causing truncation when concatenating with the ID in the imgui label. --- source/Gui/SimulationParametersWindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index 70bb422df..e295b7054 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -214,8 +214,8 @@ void _SimulationParametersWindow::processTabWidget( SimulationParametersSpot const& origSpot = origParameters.spots[tab]; bool open = true; - - if (ImGui::BeginTabItem(std::string(_spotNameStrings[tab] + "###" + _spotTabIDs[tab]).c_str(), &open, ImGuiTabItemFlags_None)) { + std::string label = std::string(_spotNameStrings[tab] + std::string("###") + _spotTabIDs[tab]); + if (ImGui::BeginTabItem(label.c_str(), &open, ImGuiTabItemFlags_None)) { processSpot(tab,spot, origSpot, parameters); ImGui::EndTabItem(); } @@ -2178,7 +2178,7 @@ void _SimulationParametersWindow::onOpenParameters() MessageDialog::getInstance().information("Open simulation parameters", "The selected file could not be opened."); } else { for(int spot = 0; spot < parameters.numSpots; ++spot){ - _spotNameStrings[spot] = std::string(parameters.spots[spot].name, SIM_PARAM_SPOT_NAME_LENGTH); + _spotNameStrings[spot] = std::string(parameters.spots[spot].name); _spotTabIDs[spot] = std::to_string(_serialTabID); ++_serialTabID; } From dd631dc8e36f499df671482c590f488ce46cc00a Mon Sep 17 00:00:00 2001 From: Will Allen Date: Sun, 28 Apr 2024 22:55:02 -0500 Subject: [PATCH 7/9] Add copy/paste and browser download support for zone names, give default names to legacy save files. --- source/Gui/SimulationParametersWindow.cpp | 26 ++++++++++++++++++++--- source/Gui/SimulationParametersWindow.h | 5 ++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index a3a0cee3f..bd69507ed 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -158,6 +158,8 @@ void _SimulationParametersWindow::processToolbar() ImGui::SameLine(); if (AlienImGui::ToolbarButton(ICON_FA_COPY)) { _copiedParameters = _simController->getSimulationParameters(); + _copiedSpotNameStrings = _spotNameStrings; + _copiedSpotTabIDs = _spotTabIDs; printOverlayMessage("Simulation parameters copied"); } AlienImGui::Tooltip("Copy simulation parameters"); @@ -167,6 +169,8 @@ void _SimulationParametersWindow::processToolbar() if (AlienImGui::ToolbarButton(ICON_FA_PASTE)) { _simController->setSimulationParameters(*_copiedParameters); _simController->setOriginalSimulationParameters(*_copiedParameters); + _spotNameStrings = _copiedSpotNameStrings; + _spotTabIDs = _copiedSpotTabIDs; printOverlayMessage("Simulation parameters pasted"); } ImGui::EndDisabled(); @@ -181,6 +185,25 @@ void _SimulationParametersWindow::processTabWidget( SimulationParameters& origParameters) { auto currentSessionId = _simController->getSessionId(); + + bool sessionChanged = (!_sessionId.has_value() || (currentSessionId != *_sessionId)); + _focusBaseTab = sessionChanged; + + if (sessionChanged){ + for (int i = 0; i < parameters.numSpots; ++i) { + // Legacy support: version <= 4.9 do not have names for zones + if (strcmp(parameters.spots[i].name, "") == 0){ + _spotNameStrings[i] = std::string("Zone ") + std::to_string(i); + }else{ + _spotNameStrings[i] = parameters.spots[i].name; + } + _spotTabIDs[i] = std::to_string(_serialTabID); + ++_serialTabID; + } + } + + _sessionId= currentSessionId; + if (ImGui::BeginChild("##", ImVec2(0, 0), false)) { @@ -239,9 +262,6 @@ void _SimulationParametersWindow::processTabWidget( } } ImGui::EndChild(); - - _focusBaseTab = !_sessionId.has_value() || currentSessionId != *_sessionId; - _sessionId= currentSessionId; } void _SimulationParametersWindow::processBase( diff --git a/source/Gui/SimulationParametersWindow.h b/source/Gui/SimulationParametersWindow.h index 5777e13b1..9941e2e7a 100644 --- a/source/Gui/SimulationParametersWindow.h +++ b/source/Gui/SimulationParametersWindow.h @@ -41,9 +41,12 @@ class _SimulationParametersWindow : public _AlienWindow std::optional _sessionId; bool _focusBaseTab = false; std::vector _cellFunctionStrings; - + std::vector _spotNameStrings; std::vector _spotTabIDs; + std::vector _copiedSpotNameStrings; + std::vector _copiedSpotTabIDs; + int _serialTabID; bool _featureListOpen = false; From 77512b53feeffb8164d047bf2d8391197fcd5dad Mon Sep 17 00:00:00 2001 From: Will Allen Date: Mon, 29 Apr 2024 00:02:30 -0500 Subject: [PATCH 8/9] Update strcmp include for linux --- source/EngineInterface/SimulationParametersSpot.h | 2 +- source/Gui/SimulationParametersWindow.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/source/EngineInterface/SimulationParametersSpot.h b/source/EngineInterface/SimulationParametersSpot.h index cf55da7a8..b21725088 100644 --- a/source/EngineInterface/SimulationParametersSpot.h +++ b/source/EngineInterface/SimulationParametersSpot.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include "SimulationParametersSpotActivatedValues.h" #include "SimulationParametersSpotValues.h" diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index bd69507ed..aa435d444 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -1,5 +1,7 @@ #include "SimulationParametersWindow.h" +#include + #include #include #include From 742138522754bba97703ca82832fa9fb3ad98914 Mon Sep 17 00:00:00 2001 From: Will Allen Date: Mon, 29 Apr 2024 00:49:57 -0500 Subject: [PATCH 9/9] gcc does not support _s strcpy variants --- source/EngineInterface/AuxiliaryDataParserService.cpp | 5 ++++- source/Gui/SimulationParametersWindow.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/source/EngineInterface/AuxiliaryDataParserService.cpp b/source/EngineInterface/AuxiliaryDataParserService.cpp index 3cde87274..88a6a0ecd 100644 --- a/source/EngineInterface/AuxiliaryDataParserService.cpp +++ b/source/EngineInterface/AuxiliaryDataParserService.cpp @@ -1,3 +1,5 @@ +#include + #include "AuxiliaryDataParserService.h" #include "GeneralSettings.h" @@ -774,7 +776,8 @@ namespace encodeDecodeProperty(tree, currentName, defaultName, base + "name", parserTask); if (parserTask == ParserTask::Decode){ - strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, currentName.c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); + currentName = currentName.substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); // Leave space for null byte + strncpy(spot.name, currentName.c_str(), SIM_PARAM_SPOT_NAME_LENGTH); } encodeDecodeProperty(tree, spot.color, defaultSpot.color, base + "color", parserTask); diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index aa435d444..59af5cfb3 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -111,7 +111,7 @@ SimulationParametersSpot _SimulationParametersWindow::createSpot(SimulationParam { SimulationParametersSpot spot; - strcpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, std::string("Zone " + std::to_string(index)).c_str()); + strncpy(spot.name, std::string("Zone " + std::to_string(index)).c_str(), SIM_PARAM_SPOT_NAME_LENGTH); auto worldSize = _simController->getWorldSize(); @@ -1491,8 +1491,8 @@ void _SimulationParametersWindow::processSpot( if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("General"))) { if(AlienImGui::InputText(AlienImGui::InputTextParameters().name("Name").textWidth(RightColumnWidth), _spotNameStrings[tab])){ - _spotNameStrings[tab] = _spotNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); - strncpy_s(spot.name, SIM_PARAM_SPOT_NAME_LENGTH, _spotNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH - 1); + _spotNameStrings[tab] = _spotNameStrings[tab].substr(0, SIM_PARAM_SPOT_NAME_LENGTH - 1); // Leave space for null byte + strncpy(spot.name, _spotNameStrings[tab].c_str(), SIM_PARAM_SPOT_NAME_LENGTH); } AlienImGui::EndTreeNode(); }