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

Reorganize directory structure and other clean-ups #246

Merged
merged 11 commits into from
Sep 25, 2023

Conversation

Capital-Asterisk
Copy link
Contributor

It was getting difficult to navigate as lots of code was in the wrong place. This reorganizes the directory structure and moves some code around to stay sane.

The src/osp directory now has 10 subdirectories: core, tasks, universe, scientific, vehicles, link, activescene, drawing, util, drawing_gl which depend on each other in a clean way:
ospdirs
src/osp, src/adera, and src/ospnewton is used 'as a library' by the test application src/testapp to make the executable.

Other important changes:

  • Added "StrongId" class to replace enum classes used as 'strong typedefs for Ids. These have the benefit of being default-initialized to their respective 'null' values instead of zero or undefined.
  • Added copy/move macros as shorthands for defining copy/move constructors and assignment operators

@Capital-Asterisk Capital-Asterisk force-pushed the reorganize-lol branch 2 times, most recently from 898dcc8 to 078f6ff Compare September 25, 2023 00:08
src/testapp/sessions/universe.cpp Fixed Show fixed Hide fixed
src/testapp/sessions/universe.cpp Fixed Show fixed Hide fixed
Comment on lines +37 to +90
/**
* @brief Integer wrapper intended for identifiers usable as container indices/keys
*
* Default-initialized to null (max int value)
*
* @tparam INT_T Wrapped integer type, usually unsigned
* @tparam DUMMY_T Dummy used to make separate unique types, avoids needing inheritance
*/
template <typename INT_T, typename DUMMY_T>
struct StrongId
{
using entity_type = INT_T; // Name used for entt compatibility

constexpr StrongId() noexcept = default;
constexpr StrongId(StrongId const& copy) noexcept
: m_value{copy.m_value}
{ };
constexpr explicit StrongId(INT_T const value) noexcept
: m_value{value}
{ };

constexpr explicit operator std::size_t() const noexcept
{
return m_value;
}

constexpr explicit operator INT_T() const noexcept
{
return m_value;
}

constexpr auto operator<=>(StrongId const&) const = default;

INT_T m_value{ lgrn::id_null<StrongId>() };
};

} // namespace osp

// std::hash support for unordered containers
template <typename INT_T, typename DUMMY_T>
struct std::hash<osp::StrongId<INT_T, DUMMY_T>> {
constexpr auto operator() (osp::StrongId<INT_T, DUMMY_T> const& key) const
{
return key.m_value;
}
};

// Longeron++ underlying_int_type
template<typename TYPE_T>
struct lgrn::underlying_int_type< TYPE_T, std::enable_if_t< std::is_integral_v<typename TYPE_T::entity_type> > >
{
using type = typename TYPE_T::entity_type;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New StrongId class. Adding move constructors breaks on msvc for some reason, but move constructors don't really have an effect anyways.

@jonesmz jonesmz merged commit 2ed0579 into TheOpenSpaceProgram:master Sep 25, 2023
20 of 22 checks passed
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.

2 participants