Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 66ad6bce9bb7
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ae37e2baffea
Choose a head ref
  • 11 commits
  • 12 files changed
  • 1 contributor

Commits on Mar 9, 2020

  1. Copy the full SHA
    32bfed7 View commit details
  2. Formatting.

    pleroy committed Mar 9, 2020
    Copy the full SHA
    307dddc View commit details

Commits on Mar 10, 2020

  1. Get the flags in the adapter.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    df01269 View commit details
  2. New Flags class and new API.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    862274b View commit details
  3. Test the flags.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    a1df67c View commit details
  4. Interfacing.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    5d54fff View commit details
  5. Formatting.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    63a8354 View commit details
  6. Missing dependency.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    82f9a63 View commit details
  7. Lint.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    2ae783b View commit details
  8. Lint never stops.

    pleroy committed Mar 10, 2020
    Copy the full SHA
    7730cc7 View commit details

Commits on Mar 11, 2020

  1. Merge pull request #2488 from pleroy/Flags

    Another attempt at having flags in the save
    pleroy authored Mar 11, 2020
    Copy the full SHA
    ae37e2b View commit details
3 changes: 3 additions & 0 deletions base/base.vcxproj
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
<ClInclude Include="file.hpp" />
<ClInclude Include="file_body.hpp" />
<ClInclude Include="fingerprint2011.hpp" />
<ClInclude Include="flags.hpp" />
<ClInclude Include="function.hpp" />
<ClInclude Include="function_body.hpp" />
<ClInclude Include="get_line.hpp" />
@@ -69,6 +70,8 @@
<ClCompile Include="bundle.cpp" />
<ClCompile Include="bundle_test.cpp" />
<ClCompile Include="disjoint_sets_test.cpp" />
<ClCompile Include="flags.cpp" />
<ClCompile Include="flags_test.cpp" />
<ClCompile Include="function_test.cpp" />
<ClCompile Include="hexadecimal_test.cpp" />
<ClCompile Include="not_null_test.cpp" />
9 changes: 9 additions & 0 deletions base/base.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -179,6 +179,9 @@
<ClInclude Include="traits.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="flags.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="not_null_test.cpp">
@@ -229,5 +232,11 @@
<ClCompile Include="base64_test.cpp">
<Filter>Test Files</Filter>
</ClCompile>
<ClCompile Include="flags.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="flags_test.cpp">
<Filter>Test Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
46 changes: 46 additions & 0 deletions base/flags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "base/flags.hpp"

#include <map>
#include <set>
#include <string>

namespace principia {
namespace base {

void Flags::Clear() {
flags_.clear();
}

void Flags::Set(std::string_view const name, std::string_view const value) {
flags_.emplace(std::string(name), std::string(value));
}

bool Flags::IsPresent(std::string_view const name) {
return flags_.find(std::string(name)) != flags_.end();
}

bool Flags::IsPresent(std::string_view const name,
std::string_view const value) {
auto const pair = flags_.equal_range(std::string(name));
std::set<std::string> values;
for (auto it = pair.first; it != pair.second; ++it) {
if (it->second == value) {
return true;
}
}
return false;
}

std::set<std::string> Flags::Values(std::string_view const name) {
auto const pair = flags_.equal_range(std::string(name));
std::set<std::string> values;
for (auto it = pair.first; it != pair.second; ++it) {
values.insert(it->second);
}
return values;
}

std::multimap<std::string, std::string> Flags::flags_;

} // namespace base
} // namespace principia
34 changes: 34 additions & 0 deletions base/flags.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <map>
#include <set>
#include <string>
#include <string_view>

namespace principia {
namespace base {

class Flags {
public:
// Remove all the flags.
static void Clear();

// Sets a flag with the given |name| and |value|.
static void Set(std::string_view name, std::string_view value);

// Returns true if a flag with the given |name| was set (with any value).
static bool IsPresent(std::string_view name);

// Returns true if a flag with the given |name| and |value| was set.
static bool IsPresent(std::string_view name, std::string_view value);

// Returns the values associated with the flag with a given |name|. Returns
// an empty set if there is no flag with the |name|.
static std::set<std::string> Values(std::string_view name);

private:
static std::multimap<std::string, std::string> flags_;
};

} // namespace base
} // namespace principia
34 changes: 34 additions & 0 deletions base/flags_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "base/flags.hpp"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace principia {
namespace base {

using ::testing::ElementsAre;
using ::testing::IsEmpty;

TEST(FlagsTest, Basics) {
Flags::Set("zfp", "yes");
Flags::Set("hex", "");
Flags::Set("gipfeli", "on");
Flags::Set("gipfeli", "off");
EXPECT_TRUE(Flags::IsPresent("zfp"));
EXPECT_TRUE(Flags::IsPresent("hex"));
EXPECT_TRUE(Flags::IsPresent("gipfeli"));
EXPECT_FALSE(Flags::IsPresent("decimal"));
EXPECT_TRUE(Flags::IsPresent("zfp", "yes"));
EXPECT_TRUE(Flags::IsPresent("hex", ""));
EXPECT_TRUE(Flags::IsPresent("gipfeli", "on"));
EXPECT_TRUE(Flags::IsPresent("gipfeli", "off"));
EXPECT_FALSE(Flags::IsPresent("gipfeli", "n/a"));
EXPECT_FALSE(Flags::IsPresent("decimal", "0"));
EXPECT_THAT(Flags::Values("zfp"), ElementsAre("yes"));
EXPECT_THAT(Flags::Values("hex"), ElementsAre(""));
EXPECT_THAT(Flags::Values("gipfeli"), ElementsAre("off", "on"));
EXPECT_THAT(Flags::Values("decimal"), IsEmpty());
}

} // namespace base
} // namespace principia
15 changes: 15 additions & 0 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
#include "base/base64.hpp"
#include "base/encoder.hpp"
#include "base/fingerprint2011.hpp"
#include "base/flags.hpp"
#include "base/hexadecimal.hpp"
#include "base/macros.hpp"
#include "base/not_null.hpp"
@@ -66,6 +67,7 @@ using base::Base64Encoder;
using base::check_not_null;
using base::Encoder;
using base::Fingerprint2011;
using base::Flags;
using base::HexadecimalEncoder;
using base::make_not_null_unique;
using base::PullSerializer;
@@ -415,6 +417,12 @@ QP __cdecl principia__CelestialWorldDegreesOfFreedom(Plugin const* const plugin,
FromGameTime(*plugin, time))));
}

void __cdecl principia__ClearFlags() {
journal::Method<journal::ClearFlags> m;
Flags::Clear();
return m.Return();
}

void __cdecl principia__ClearWorldRotationalReferenceFrame(
Plugin* const plugin) {
journal::Method<journal::ClearWorldRotationalReferenceFrame> m({plugin});
@@ -1042,6 +1050,13 @@ void __cdecl principia__SetBufferedLogging(int const max_severity) {
return m.Return();
}

void __cdecl principia__SetFlag(char const* const name,
char const* const value) {
journal::Method<journal::SetFlag> m({name, value});
Flags::Set(name, value);
return m.Return();
}

void __cdecl principia__SetMainBody(Plugin* const plugin, int const index) {
journal::Method<journal::SetMainBody> m({plugin, index});
CHECK_NOTNULL(plugin);
1 change: 1 addition & 0 deletions ksp_plugin/ksp_plugin.vcxproj
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
<ClInclude Include="vessel.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base\flags.cpp" />
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\base\version.generated.cc" />
<ClCompile Include="..\journal\profiles.cpp" />
3 changes: 3 additions & 0 deletions ksp_plugin/ksp_plugin.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -169,6 +169,9 @@
<ClCompile Include="interface_part.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\base\flags.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\serialization\journal.proto" />
11 changes: 11 additions & 0 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ private enum UnityLayers {
"principia_numerics_blueprint";
private const string principia_override_version_check_config_name_ =
"principia_override_version_check";
private const string flags_ = "flags";

private KSP.UI.Screens.ApplicationLauncherButton toolbar_button_;
// Whether the user has hidden the UI.
@@ -2156,6 +2157,16 @@ private void Cleanup() {
Interface.DeletePlugin(ref plugin_);
previous_display_mode_ = null;
navball_changed_ = true;

// Load the flags.
Interface.ClearFlags();
ConfigNode flags = GameDatabase.Instance.GetAtMostOneNode(flags_);
ConfigNode[] individual_flags = flags.GetNodes();
foreach (ConfigNode individual_flag in individual_flags) {
foreach (String value in individual_flag.GetValues()) {
Interface.SetFlag(individual_flag.name, value);
}
}
}

private void UpdateRenderingFrame(
1 change: 1 addition & 0 deletions ksp_plugin_test/ksp_plugin_test.vcxproj
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
<Import Project="$(SolutionDir)principia.props" />
<ItemGroup>
<ClCompile Include="..\astronomy\standard_product_3.cpp" />
<ClCompile Include="..\base\flags.cpp" />
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\base\version.generated.cc" />
<ClCompile Include="..\journal\profiles.cpp" />
3 changes: 3 additions & 0 deletions ksp_plugin_test/ksp_plugin_test.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -188,6 +188,9 @@
<ClCompile Include="..\ksp_plugin\interface_part.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\base\flags.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="mock_plugin.hpp">
19 changes: 18 additions & 1 deletion serialization/journal.proto
Original file line number Diff line number Diff line change
@@ -219,7 +219,7 @@ message OrbitAnalysis {
}

message Method {
extensions 5000 to 5999; // Last used: 5165.
extensions 5000 to 5999; // Last used: 5167.
}

message AdvanceTime {
@@ -361,6 +361,12 @@ message CelestialWorldDegreesOfFreedom {
optional Return return = 3;
}

message ClearFlags {
extend Method {
optional ClearFlags extension = 5167;
}
}

message ClearTargetVessel {
extend Method {
optional ClearTargetVessel extension = 5122;
@@ -1902,6 +1908,17 @@ message SetBufferedLogging {
optional In in = 1;
}

message SetFlag {
extend Method {
optional SetFlag extension = 5166;
}
message In {
required string name = 1;
required string value = 2;
}
optional In in = 1;
}

message SetMainBody {
extend Method {
optional SetMainBody extension = 5097;