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

♻️ 💥 Fix memory ownership #6

Merged
merged 4 commits into from
Jan 14, 2024
Merged

♻️ 💥 Fix memory ownership #6

merged 4 commits into from
Jan 14, 2024

Conversation

linkdd
Copy link
Owner

@linkdd linkdd commented Jan 14, 2024

Actual behavior

The use of std::shared_ptr was unfortunate. I initially had trouble with std::unique_ptr:

  • it is impossible to iterate over an std::initializer_list<std::unique_ptr<T>> as it always make a copy
  • the constructor of std::vector<std::unique_ptr<T>> make use of std::initializer_list

Desired behavior

The data should be owned by the modules, and std::shared_ptr does not indicate that.

Changes

FSM:

  • ♻️ 💥 Use std::unique_ptr instead of std::shared_ptr
  • ✨ Add state_trait concept
  • ♻️ 💥 The simple_machine::set_state() transition now accepts a value that satisfies state_trait, it will be copied in an internal std::unique_ptr
  • ✨ Add a simple_machine::clear_state() transition
  • ♻️ 💥 The stack_machine::push_state() transition now accepts a value that satisfies state_trait, it will be copied in an internal std::unique_ptr

Behavior Tree:

  • ♻️ 💥 Use std::unique_ptr instead of std::shared_ptr
  • ✨ Add node_trait concept
  • 🔥 💥 Remove all make() static methods
  • ♻️ 💥 Replace std::initializer_list with std::vector
  • ✨ Add node_list() template function helper to create the std::vector using a parameter pack

Utility AI:

  • ♻️ 💥 Use std::unique_ptr instead of std::shared_ptr
  • ✨ Add action_trait concept
  • ♻️ 💥 Replace std::initializer_list with std::vector
  • ✨ Add action_list() template function helper to create the std::vector using a parameter pack

GOAP:

  • ♻️ 💥 Use std::unique_ptr instead of std::shared_ptr
  • ✨ Add action_trait concept
  • ♻️ 💥 Replace std::initializer_list with std::vector
  • ✨ Add action_list() template function helper to create the std::vector using a parameter pack
  • ♻️ The plan now takes ownership of the action list given to the planner, the queue is a queue of indices into the action list, this allows to forge a reference to a std::unique_ptr (since an action can appear multiple times in a plan)

@linkdd linkdd self-assigned this Jan 14, 2024
@linkdd linkdd changed the title ♻️ Fix memory ownership ♻️ 💥 Fix memory ownership Jan 14, 2024
@linkdd linkdd merged commit 675fdd6 into main Jan 14, 2024
3 checks passed
@linkdd linkdd deleted the fix-memory-ownership branch January 14, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant