Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Keenuts committed Apr 18, 2024
1 parent 3fab909 commit 114434d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions include/ppx/command_line_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class CliOptions
// not counting multiple appearances of the same flag such as: --assets-path a --assets-path b
size_t GetNumUniqueOptions() const { return mAllOptions.size(); }

// Returns true if the given option is present in the commandline. False otherwise.
bool HasOption(const std::string& optionName) const
{
return mAllOptions.cend() != mAllOptions.find(optionName);
}

// Tries to parse the option string into the type of the default value and return it.
// If the value fails to be converted, return the specified default value.
// Warning: If this is called instead of the vector overload for multiple-value flags,
Expand Down
9 changes: 7 additions & 2 deletions include/ppx/knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ class KnobFlag final
{
public:
KnobFlag(const std::string& flagName, T defaultValue)
: Knob(flagName, false)
: Knob(flagName, false), mDirty(false)
{
SetValue(defaultValue);
}

KnobFlag(const std::string& flagName, T defaultValue, T minValue, T maxValue)
: Knob(flagName, false)
: Knob(flagName, false), mDirty(false)
{
static_assert(std::is_arithmetic_v<T>, "KnobFlag can only be defined with min/max when it's of arithmetic type");
PPX_ASSERT_MSG(minValue < maxValue, "invalid range to initialize KnobFlag");
Expand All @@ -400,6 +400,8 @@ class KnobFlag final

T GetValue() const { return mValue; }

bool IsDefaultValue() const { return mDirty; }

void SetValidator(std::function<bool(T)> validatorFunc) { mValidatorFunc = validatorFunc; }

private:
Expand All @@ -418,6 +420,8 @@ class KnobFlag final

void UpdateFromFlags(const CliOptions& opts) override
{
if (opts.HasOption(mFlagName))
mDirty = true;
SetValue(opts.GetOptionValueOrDefault(mFlagName, mValue));
}

Expand All @@ -438,6 +442,7 @@ class KnobFlag final
private:
T mValue;
std::function<bool(T)> mValidatorFunc;
bool mDirty;
};

// KnobManager holds the knobs in an application
Expand Down
10 changes: 5 additions & 5 deletions include/ppx/xr_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct XrComponentCreateInfo
bool enableDebug = false;
bool enableQuadLayer = false;
bool enableDepthSwapchain = false;
XrComponentResolution resolution = {0, 0};
std::optional<XrComponentResolution> resolution = (XrComponentResolution){0, 0};
XrComponentResolution uiResolution = {0, 0};

std::vector<std::string> requiredExtensions = {};
Expand Down Expand Up @@ -174,16 +174,16 @@ class XrComponent
{
if (mConfigViews.empty())
return 0;
if (mCreateInfo.resolution.width > 0)
return mCreateInfo.resolution.width;
if (mCreateInfo.resolution.has_value())
return mCreateInfo.resolution->width;
return mConfigViews[0].recommendedImageRectWidth;
}
uint32_t GetHeight() const
{
if (mConfigViews.empty())
return 0;
if (mCreateInfo.resolution.height > 0)
return mCreateInfo.resolution.height;
if (mCreateInfo.resolution.has_value())
return mCreateInfo.resolution->height;
return mConfigViews[0].recommendedImageRectHeight;
}
uint32_t GetUIWidth() const
Expand Down
5 changes: 3 additions & 2 deletions src/ppx/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,9 @@ void Application::InitializeXRComponentBeforeGrfxDeviceInit()
createInfo.enableDebug = mSettings.grfx.enableDebug;
createInfo.enableQuadLayer = mSettings.enableImGui;
createInfo.enableDepthSwapchain = mSettings.xr.enableDepthSwapchain;
createInfo.resolution.width = GetWindowWidth();
createInfo.resolution.height = GetWindowHeight();
if (!mStandardOpts.pResolution->IsDefaultValue()) {
createInfo.resolution = (XrComponentResolution){GetWindowWidth(), GetWindowHeight()};
}
createInfo.uiResolution.width = mSettings.xr.uiWidth;
createInfo.uiResolution.height = mSettings.xr.uiHeight;
createInfo.requiredExtensions = mStandardOpts.pXrRequiredExtensions->GetValue();
Expand Down

0 comments on commit 114434d

Please sign in to comment.