Skip to content

Commit

Permalink
Various C++20 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmz committed Oct 31, 2023
1 parent a65640f commit 7a19ef7
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 225 deletions.
8 changes: 5 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Checks: 'clang-diagnostic-*,
,performance-*,
,readability-*,
,modernize-*,
,-modernize-use-trailing-return-type,
,-modernize-use-auto,
,-readability-uppercase-literal-suffix,
,-readability-else-after-return,
,-modernize-redundant-void-arg,
,-modernize-use-trailing-return-type,
,-readability-magic-numbers,
,-readability-named-parameter,
,-readability-identifier-length,
,-readability-else-after-return,
,-readability-uppercase-literal-suffix,
,-clang-analyzer-cplusplus.InnerPointer,
,-cplusplus.InnerPointer,
,-clang-diagnostic-ignored-optimization-argument,
Expand Down
16 changes: 14 additions & 2 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ if(NOT OSP_USE_SYSTEM_SDL)
SET(SDL_MMX OFF CACHE BOOL "" FORCE) # Old. Superceeded by SSE1, not supported by osp-magnum.
SET(SDL_ASSEMBLY OFF CACHE BOOL "" FORCE) # Presumably not actually needed. Lets try more for portability than speed...

SET(SDL_IBUS OFF CACHE BOOL "" FORCE)
SET(SDL_TEST OFF CACHE BOOL "" FORCE)
SET(SDL_EVENTS OFF CACHE BOOL "" FORCE)
SET(SDL_SYSTEM_ICONV OFF CACHE BOOL "" FORCE)

SET(SDL_DBUS ON CACHE BOOL "" FORCE)
SET(SDL_LIBUDEV ON CACHE BOOL "" FORCE)

##
# SDL Audio backend settings
##
Expand Down Expand Up @@ -84,6 +92,8 @@ if(NOT OSP_USE_SYSTEM_SDL)
# SDL Video backend settings
##
SET(SDL_VIDEO ON CACHE BOOL "" FORCE)
SET(SDL_VIVANTE OFF CACHE BOOL "" FORCE)
SET(SDL_OFFSCREEN OFF CACHE BOOL "" FORCE)

# Enabled video settings
SET(SDL_OPENGL ON CACHE BOOL "" FORCE)
Expand All @@ -108,8 +118,10 @@ if(NOT OSP_USE_SYSTEM_SDL)
SET(SDL_FILE ON CACHE BOOL "" FORCE) # Needed for Mac OSX
SET(SDL_LOADSO ON CACHE BOOL "" FORCE)

SET(SDL_JOYSTICK ON CACHE BOOL "" FORCE)
SET(SDL_VIRTUAL_JOYSTICK ON CACHE BOOL "" FORCE)
SET(SDL_HIDAPI OFF CACHE BOOL "" FORCE)
SET(SDL_HIDAPI_JOYSTICK OFF CACHE BOOL "" FORCE)
SET(SDL_JOYSTICK OFF CACHE BOOL "" FORCE)
SET(SDL_VIRTUAL_JOYSTICK OFF CACHE BOOL "" FORCE)

SET(LIBSAMPLERATE ON CACHE BOOL "" FORCE)
SET(LIBSAMPLERATE_SHARED ON CACHE BOOL "" FORCE)
Expand Down
21 changes: 12 additions & 9 deletions src/adera/ShipResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
* SOFTWARE.
*/
#pragma once
#include <string>
#include <assert.h>

//#include <osp/Active/machines.h>
#include <osp/CommonMath.h>
#include <osp/CommonPhysics.h>

#include <string>

#include <cassert>
#include <cstdint>

namespace adera::active::machines
{

Expand Down Expand Up @@ -86,7 +89,7 @@ struct ShipResourceType
const std::string m_displayName;

// 1/(QPU) is the smallest representable quantity of this resource; must be a power of 2
const uint64_t m_quantaPerUnit;
const std::uint64_t m_quantaPerUnit;

// The volume (in m^3) of one unit of this resource
const float m_volumePerUnit;
Expand All @@ -98,35 +101,35 @@ struct ShipResourceType
const float m_density;

// Compute the volume of the specified quantity of resource
constexpr double resource_volume(uint64_t quantity) const
constexpr double resource_volume(std::uint64_t quantity) const
{
double units = static_cast<double>(quantity) / m_quantaPerUnit;
return units * m_volumePerUnit;
}

// Compute the mass of the specified quantity of resource
constexpr double resource_mass(uint64_t quantity) const
constexpr double resource_mass(std::uint64_t quantity) const
{
double units = static_cast<double>(quantity) / m_quantaPerUnit;
return units * m_massPerUnit;
}

// Compute the quantity of resource that fits in the specified volume
constexpr uint64_t resource_capacity(double volume) const
constexpr std::uint64_t resource_capacity(double volume) const
{
double units = volume / m_volumePerUnit;
return static_cast<uint64_t>(units * m_quantaPerUnit);
return static_cast<std::uint64_t>(units * m_quantaPerUnit);
}

// Compute the quantity of resource that masses the specified amount
constexpr uint64_t resource_quantity(double mass) const
constexpr std::uint64_t resource_quantity(double mass) const
{
double units = mass / m_massPerUnit;
return static_cast<uint64_t>(units * m_quantaPerUnit);
}

ShipResourceType(std::string identifier, std::string displayName,
uint64_t quantaPerUnit, float volume, float mass, float density)
std::uint64_t quantaPerUnit, float volume, float mass, float density)
: m_identifier(std::move(identifier))
, m_displayName(std::move(displayName))
, m_quantaPerUnit(quantaPerUnit)
Expand Down
10 changes: 6 additions & 4 deletions src/adera/activescene/VehicleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <osp/util/logging.h>
#include <osp/vehicles/ImporterData.h>

#include <ranges>

namespace adera
{

Expand Down Expand Up @@ -66,7 +68,7 @@ void VehicleBuilder::set_prefabs(std::initializer_list<SetPrefab> const& setPref
}
}

WeldId VehicleBuilder::weld(osp::ArrayView<PartToWeld const> toWeld)
WeldId VehicleBuilder::weld(std::span<PartToWeld const> toWeld)
{
WeldId const weld = m_data->m_weldIds.create();
m_data->m_weldToParts.ids_reserve(m_data->m_weldIds.capacity());
Expand All @@ -79,15 +81,15 @@ WeldId VehicleBuilder::weld(osp::ArrayView<PartToWeld const> toWeld)

m_data->m_partToWeld[set.m_part] = weld;
(*pPartInWeld) = set.m_part;
std::advance(pPartInWeld, 1);
++pPartInWeld;
}

return weld;
}

void VehicleBuilder::index_prefabs()
{
for (unsigned int i = 0; i < m_pResources->ids(gc_importer).capacity(); ++i)
for (auto const i : std::views::iota(0u, m_pResources->ids(gc_importer).capacity()))
{
auto const resId = osp::ResId(i);
if ( ! m_pResources->ids(gc_importer).exists(resId))
Expand All @@ -101,7 +103,7 @@ void VehicleBuilder::index_prefabs()
continue; // No prefab data
}

for (osp::PrefabId j = 0; j < pPrefabData->m_prefabNames.size(); ++j)
for (osp::PrefabId const j : std::views::iota(0u, pPrefabData->m_prefabNames.size()))
{
osp::ResIdOwner_t owner = m_pResources->owner_create(gc_importer, resId);

Expand Down
8 changes: 5 additions & 3 deletions src/adera/activescene/VehicleBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
#include <entt/core/any.hpp>
#include <entt/container/dense_map.hpp>

#include <cstdint>
#include <array>
#include <optional>
#include <vector>
#include <span>

#include <cstdint>

namespace adera
{
Expand Down Expand Up @@ -133,11 +135,11 @@ class VehicleBuilder
void set_prefabs(std::initializer_list<SetPrefab> const& setPrefab);


WeldId weld(osp::ArrayView<PartToWeld const> toWeld);
WeldId weld(std::span<PartToWeld const> toWeld);

WeldId weld(std::initializer_list<PartToWeld const> const& toWeld)
{
return weld(osp::arrayView(toWeld));
return weld(std::span{toWeld});
}

osp::Matrix4 align_attach(PartId partA, std::string_view attachA,
Expand Down
22 changes: 11 additions & 11 deletions src/adera/drawing/CameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ struct ACtxCameraController

ACtxCameraController(osp::input::UserInputHandler &rInput)
: m_controls(&rInput)
, m_btnOrbit( m_controls.button_subscribe("cam_orbit"))
, m_btnRotUp( m_controls.button_subscribe("ui_up"))
, m_btnRotDn( m_controls.button_subscribe("ui_dn"))
, m_btnRotLf( m_controls.button_subscribe("ui_lf"))
, m_btnRotRt( m_controls.button_subscribe("ui_rt"))
, m_btnMovFd( m_controls.button_subscribe("cam_fd"))
, m_btnMovBk( m_controls.button_subscribe("cam_bk"))
, m_btnMovLf( m_controls.button_subscribe("cam_lf"))
, m_btnMovRt( m_controls.button_subscribe("cam_rt"))
, m_btnMovUp( m_controls.button_subscribe("cam_up"))
, m_btnMovDn( m_controls.button_subscribe("cam_dn"))
, m_btnOrbit(m_controls.button_subscribe("cam_orbit"))
, m_btnRotUp(m_controls.button_subscribe("ui_up"))
, m_btnRotDn(m_controls.button_subscribe("ui_dn"))
, m_btnRotLf(m_controls.button_subscribe("ui_lf"))
, m_btnRotRt(m_controls.button_subscribe("ui_rt"))
, m_btnMovFd(m_controls.button_subscribe("cam_fd"))
, m_btnMovBk(m_controls.button_subscribe("cam_bk"))
, m_btnMovLf(m_controls.button_subscribe("cam_lf"))
, m_btnMovRt(m_controls.button_subscribe("cam_rt"))
, m_btnMovUp(m_controls.button_subscribe("cam_up"))
, m_btnMovDn(m_controls.button_subscribe("cam_dn"))
{ }
ACtxCameraController(ACtxCameraController const& copy) = delete;
ACtxCameraController(ACtxCameraController&& move) = default;
Expand Down
10 changes: 6 additions & 4 deletions src/adera/drawing_gl/flat_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <Magnum/Shaders/FlatGL.h>

#include <iterator>

namespace adera::shader
{

Expand Down Expand Up @@ -109,11 +111,11 @@ inline void sync_drawent_flat(osp::draw::DrawEnt ent, ArgsForSyncDrawEntFlat con
}
}

template<typename ITA_T, typename ITB_T>
template<std::input_iterator IT_T, std::sentinel_for<IT_T> SENT_T>
void sync_drawent_flat(
ITA_T const& first,
ITB_T const& last,
ArgsForSyncDrawEntFlat const args)
IT_T const& first,
SENT_T const& last,
ArgsForSyncDrawEntFlat const args)
{
std::for_each(first, last, [&args] (osp::draw::DrawEnt const ent)
{
Expand Down
10 changes: 6 additions & 4 deletions src/adera/drawing_gl/phong_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <Magnum/Shaders/PhongGL.h>

#include <iterator>

namespace adera::shader
{

Expand Down Expand Up @@ -110,11 +112,11 @@ inline void sync_drawent_phong(osp::draw::DrawEnt ent, ArgsForSyncDrawEntPhong c
}
}

template<typename ITA_T, typename ITB_T>
template<std::input_iterator IT_T, std::sentinel_for<IT_T> SENT_T>
void sync_drawent_phong(
ITA_T const& first,
ITB_T const& last,
ArgsForSyncDrawEntPhong const args)
IT_T const& first,
SENT_T const& last,
ArgsForSyncDrawEntPhong const args)
{
std::for_each(first, last, [&args] (osp::draw::DrawEnt const ent)
{
Expand Down
8 changes: 5 additions & 3 deletions src/adera/drawing_gl/visualizer_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <Magnum/Shaders/MeshVisualizerGL.h>

#include <iterator>

namespace adera::shader
{

Expand Down Expand Up @@ -82,10 +84,10 @@ inline void sync_drawent_visualizer(
}
}
}
template <typename ITA_T, typename ITB_T>
template<std::input_iterator IT_T, std::sentinel_for<IT_T> SENT_T>
static void sync_drawent_visualizer(
ITA_T const& first,
ITB_T const& last,
IT_T const& first,
SENT_T const& last,
osp::draw::DrawEntSet_t const& hasMaterial,
osp::draw::RenderGroup::DrawEnts_t& rStorage,
ACtxDrawMeshVisualizer& rData)
Expand Down
4 changes: 3 additions & 1 deletion src/osp/activescene/active_ent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@

#include "../core/strong_id.h"

#include <cstdint>

namespace osp::active
{

using ActiveEnt = StrongId<uint32_t, struct DummyForActiveEnt>;
using ActiveEnt = StrongId<std::uint32_t, struct DummyForActiveEnt>;

} // namespace osp::active
23 changes: 13 additions & 10 deletions src/osp/activescene/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <longeron/id_management/registry_stl.hpp> // for lgrn::IdRegistryStl

#include <string>
#include <iterator>

#include <cstdint>

namespace osp::active
{
Expand All @@ -58,23 +61,23 @@ struct ACompName
std::string m_name;
};

using TreePos_t = uint32_t;
using TreePos_t = std::uint32_t;

struct ACtxSceneGraph
{
// N-ary tree structure represented as an array of descendant counts. Each node's subtree of
// descendants is positioned directly after it within the array.
// Example for tree structure "A( B(C(D)), E(F(G(H,I))) )"
// * Descendant Count array: [A:8, B:2, C:1, D:0, E:4, F:3, G:2, H:0, I:0]
osp::KeyedVec<TreePos_t, ActiveEnt> m_treeToEnt{{lgrn::id_null<ActiveEnt>()}};
osp::KeyedVec<TreePos_t, uint32_t> m_treeDescendants{std::initializer_list<uint32_t>{0}};
osp::KeyedVec<TreePos_t, ActiveEnt> m_treeToEnt{{lgrn::id_null<ActiveEnt>()}};
osp::KeyedVec<TreePos_t, std::uint32_t> m_treeDescendants{std::initializer_list<uint32_t>{0}};

osp::KeyedVec<ActiveEnt, ActiveEnt> m_entParent;
osp::KeyedVec<ActiveEnt, TreePos_t> m_entToTreePos;
osp::KeyedVec<ActiveEnt, ActiveEnt> m_entParent;
osp::KeyedVec<ActiveEnt, TreePos_t> m_entToTreePos;

std::vector<TreePos_t> m_delete;
std::vector<TreePos_t> m_delete;

void resize(std::size_t ents)
void resize(std::size_t const ents)
{
m_treeToEnt .reserve(ents);
m_treeDescendants .reserve(ents);
Expand All @@ -96,8 +99,8 @@ struct ACtxBasic
ACompTransformStorage_t m_transform;
};

template<typename IT_T>
void update_delete_basic(ACtxBasic &rCtxBasic, IT_T first, IT_T const& last)
template<std::input_iterator IT_T, std::sentinel_for<IT_T> SENT_T>
void update_delete_basic(ACtxBasic &rCtxBasic, IT_T first, SENT_T const& last)
{
while (first != last)
{
Expand All @@ -109,7 +112,7 @@ void update_delete_basic(ACtxBasic &rCtxBasic, IT_T first, IT_T const& last)

}

std::advance(first, 1);
++first;
}
}

Expand Down
Loading

0 comments on commit 7a19ef7

Please sign in to comment.