Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--Add Configuration State Flags - Part 1 #2396

Merged
merged 21 commits into from
May 21, 2024
Merged

--Add Configuration State Flags - Part 1 #2396

merged 21 commits into from
May 21, 2024

Conversation

jturner65
Copy link
Contributor

@jturner65 jturner65 commented May 16, 2024

Motivation and Context

This is the first of 2 PRs to handle this functionality. The 2nd PR will handle making sure configuration filepaths do not get saved to JSON with inappropriate path information.

This PR is intended to expand the capabilities of the Configurations without incurring much cost by providing status flags for each ConfigValue that reside within the 4 byte gap the current _type field causes due to 8 byte alignment.

  • Modifies the ConfigValType (int) _type field to be u_int64_t _typeAndFlags, where the lower 32 bits correspond to the previous _type value and the higher 32 bits are used to record state of the ConfigValue, along with necessary plumbing to consume the type value in the same way as before.

  • Adds ConfigValStatus enum (u_int64_t) to hold bit flags representing state of the ConfigValue. Currently 3 flags are supported, ConfigValStatus::isDefault , ConfigValStatus::isHidden and ConfigValStatus::isTranslated.
    -- isDefault : represents programmatic initialization of a value, as opposed to it being set intentionally from a file or user input.
    -- isHidden : represents a value being used internally and not part of the actual Configuration data hierarchy. These values we never want to write to file or expose to a user unless for debugging purposes.
    -- isTranslated : represents a value that is stored as a string but is translated, currently to enum values, upon consumption.

  • Adds "init" setters that set the ConfigValStatus::isDefault bit of the ConfigValue's _typeAndFlags variable to 1, while the legacy "set" setters set it to 0.

  • Adds "hidden" setters that will set the ConfigValStatus::isHidden bit. The Attributes that consume this bit have as their keys double-underscore + Hungarian notation names, to make them obvious compared to the standard camel-case format of non-hidden values.

  • All existing Attributes constructors have their default value setting changed from using variants of "set" to using the new "init" and "setHidden" setters where appropriate.

  • A check on the "isDefault" and "isHidden" flags is added when before writing to JSON.

Not only will these features prevent the unnecessary writing to disk of default fields, but they can also be used to prevent configurations being written in a potentially damaging or indeterminant state due to modifications done internally as part of the program's flow.

Also adds a repathing tool in the io namespace :

io::getPathRelativeToAbsPath(const std::string& toRelPath,
                                     const std::string& absPath)

which converts the absolute path toRelPath to be relative to the given target absPath

How Has This Been Tested

Locally c++ and python tests pass

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@jturner65 jturner65 requested a review from aclegg3 May 16, 2024 20:56
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label May 16, 2024
Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let's see downstream tests pass before merging to prevent issues with nightly.

I like that the per-property setters were replaced with a generic API.
Should also make searching for these easier.

//
// ==== AssetType ====
// Describes the type of asset used for rendering, collsions, or semantics
py::enum_<metadata::attributes::AssetType>(m, "AssetType")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bind these? Does python need access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getters provide this value as an enum. This does remind me, though , that this needs to be read only now, since we don't want manual manipulation of this as it could break things in arcane ways. The whole asset-type component system needs to be removed, since it has been obviated by various config settings.

src/esp/core/Configuration.h Outdated Show resolved Hide resolved
init("use_bounding_box_for_collision", false);
init("join_collision_meshes", false);

init("semantic_id", 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "unknown" or could it be a random class?
Should probably reserve the default for unknown.
Doesn't have to be this PR, just thought I'd mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This semantic ID being set to 0 corresponds to the stage.

If ConfigVal values are set programmatically to defaults, the process should use "init" instead of "set". This will make sure the isDefaultVal flag is set to true, and consequently not writing those values to file when requested to.
Values set by the existing "set" methods will always be written to file.
Nearly all the values set in the constructors of the various attributes are defaults that are expected to be overwritten only if necessary.  Writing these to file is redundant and can, in certain circumstances,  cause written JSONs to be in an inappropriate state.
A hidden value would be a pertinent configuration value that is set programmatically and only used internally. These values should not be written to file or exposed to the user except perhaps for debugging.
Not sure if this could even happen (a situation could arise where two different instances could have their _data arrays both be pointers to the same memory location, but just in case.
Hidden fields are set and used internally and will generally not be written to file or exposed to the user except in a debugging capacity. Their labels in Configurations should be camel-case with 2 leading underscores, to help differentiate them from non-hidden fields.
binding value should not have lost "orient_" prefix
'Force_flat_shading should be considered a hidden value, only used internally.
This means a config value is translated by consuming code to some other representation, (i.e. an enum) before it is consumed. These values are stored internally and in files as strings, but require the implementation of custom read functionality to make sure the value read is within the acceptable bounds supported by the program.
@jturner65 jturner65 merged commit 3ec0c52 into main May 21, 2024
10 checks passed
@jturner65 jturner65 deleted the ConfigVals_Part1 branch May 21, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants