Skip to content

Commit

Permalink
No more copies in callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Oct 9, 2024
1 parent a56b5f9 commit 63f4403
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 57 deletions.
6 changes: 3 additions & 3 deletions app/bench/src/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ namespace VTX::Bench
inline static const float VELOCITY_ZOOM_MIN = 10.f;
inline static const float VELOCITY_ZOOM_MAX = 1000.f;

Util::Callback<Mat4f> callbackMatrixView;
Util::Callback<Mat4f> callbackMatrixProjection;
Util::Callback<Vec3f> callbackTranslation;
Util::Callback<Mat4f &> callbackMatrixView;
Util::Callback<Mat4f &> callbackMatrixProjection;
Util::Callback<Vec3f &> callbackTranslation;
Util::Callback<float, float> callbackClipInfos;
Util::Callback<bool> callbackPerspective;

Expand Down
6 changes: 3 additions & 3 deletions app/bench/src/input_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ namespace VTX::Bench

Util::Callback<> onClose;
Util::Callback<size_t, size_t> onResize;
Util::Callback<Vec3i> onTranslate;
Util::Callback<Vec2i> onRotate;
Util::Callback<Vec3i &> onTranslate;
Util::Callback<Vec2i &> onRotate;
Util::Callback<int> onZoom;
Util::Callback<Vec2i> onMouseMotion;
Util::Callback<const Vec2i &> onMouseMotion;
Util::Callback<> onRestore;
Util::Callback<size_t, size_t> onMousePick;
Util::Callback<SDL_Scancode> onKeyPressed;
Expand Down
3 changes: 2 additions & 1 deletion app/bench/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace VTX::Bench
{
_camera.callbackMatrixView += [ & ]( const Mat4f & p_matrix ) { _proxyCamera.onMatrixView(); };
_camera.callbackMatrixProjection += [ & ]( const Mat4f & p_matrix ) { _proxyCamera.onMatrixProjection(); };
_camera.callbackTranslation += [ & ]( const Vec3f p_position ) { _proxyCamera.onCameraPosition( p_position ); };
_camera.callbackTranslation +=
[ & ]( const Vec3f & p_position ) { _proxyCamera.onCameraPosition( p_position ); };
_camera.callbackClipInfos +=
[ & ]( const float p_near, const float p_far ) { _proxyCamera.onCameraNearFar( p_near, p_far ); };
_camera.callbackPerspective +=
Expand Down
2 changes: 1 addition & 1 deletion dev/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def requirements(self):
self.requires("stb/cci.20230920")
self.requires("entt/3.13.2")
self.requires("pybind11/2.12.0")
self.requires("qt/6.6.3")
self.requires("qt/6.7.3")
self.requires("eigen/3.4.0")
self.requires("gromacs/2024.0")
self.requires("fmt/10.2.1")
Expand Down
4 changes: 2 additions & 2 deletions lib/app/include/app/application/selection/selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ namespace VTX::App::Application::Selection

std::string toString() const;

Util::Callback<SelectionData> onSelect;
Util::Callback<SelectionData> onDeselect;
Util::Callback<const SelectionData &> onSelect;
Util::Callback<const SelectionData &> onDeselect;
Util::Callback<const SelectionData *> onCurrentObjectChange;

private:
Expand Down
4 changes: 2 additions & 2 deletions lib/app/include/app/component/render/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ namespace VTX::App::Component::Render

void print() const;

Util::Callback<Mat4f> onMatrixViewChange;
Util::Callback<Mat4f> onMatrixProjectionChange;
Util::Callback<Mat4f &> onMatrixViewChange;
Util::Callback<Mat4f &> onMatrixProjectionChange;
Util::Callback<float, float> onClipInfosChange;
Util::Callback<PROJECTION> onProjectionChange;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace VTX::App::Component::Scene
void removeUpdateFunction( const std::string & p_key );

// Callbacks
Util::Callback<std::string> onName;
Util::Callback<std::string_view> onName;

private:
int _persistentId = -1;
Expand Down
4 changes: 2 additions & 2 deletions lib/app/include/app/component/scene/selectable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace VTX::App::Component::Scene

std::unique_ptr<Application::Selection::SelectionData> instantiateSelectionData() const;

Util::Callback<Application::Selection::SelectionData> onSelect;
Util::Callback<Application::Selection::SelectionData> onDeselect;
Util::Callback<const Application::Selection::SelectionData &> onSelect;
Util::Callback<const Application::Selection::SelectionData &> onDeselect;

private:
std::unique_ptr<Application::Selection::SelectionData> _defaultSelectionDataGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace VTX::App::Component::Scene

void applyTransform( const Util::Math::Transform & p_transform );

Util::Callback<Util::Math::Transform> onTransform;
Util::Callback<Util::Math::Transform &> onTransform;

private:
void _updateRotation();
Expand Down
6 changes: 3 additions & 3 deletions lib/app/include/app/vtx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace VTX::App
inline static Util::Callback<> onStop;

// Progress dialog callbacks.
inline static Util::Callback<std::string> onStartBlockingOperation;
inline static Util::Callback<float> onUpdateBlockingOperation;
inline static Util::Callback<> onEndBlockingOperation;
inline static Util::Callback<std::string_view> onStartBlockingOperation;
inline static Util::Callback<float> onUpdateBlockingOperation;
inline static Util::Callback<> onEndBlockingOperation;

// TODO: thread callbacks?

Expand Down
2 changes: 0 additions & 2 deletions lib/app/src/app/entity/scene/scene_item_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace VTX::App::Entity::Scene
Component::Scene::SceneItemComponent & sceneItemComponent
= MAIN_REGISTRY().getComponent<Component::Scene::SceneItemComponent>( p_entity );

assert( MAIN_REGISTRY().hasComponent<Component::Chemistry::Molecule>( sceneItemComponent ) );

scene->referenceItem( sceneItemComponent );
}
} // namespace VTX::App::Entity::Scene
2 changes: 1 addition & 1 deletion lib/app/test/entt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_CASE( "VTX_APP - Full sequence", "[integration]" )

CallbackTest renameTest = CallbackTest();

sceneItem.onName += [ &renameTest ]( const std::string & p_name ) { renameTest.checked = true; };
sceneItem.onName += [ &renameTest ]( const std::string_view p_name ) { renameTest.checked = true; };
sceneItem.setName( "Zouzou" );

REQUIRE( sceneItem.getName() == "Zouzou" );
Expand Down
12 changes: 6 additions & 6 deletions lib/renderer/include/renderer/proxy/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace VTX::Renderer::Proxy
const float cameraFar;
const bool isPerspective;

Util::Callback<> onMatrixView;
Util::Callback<> onMatrixProjection;
Util::Callback<Vec3f> onCameraPosition;
Util::Callback<Vec2i> onMousePosition;
Util::Callback<float, float> onCameraNearFar;
Util::Callback<bool> onPerspective;
Util::Callback<> onMatrixView;
Util::Callback<> onMatrixProjection;
Util::Callback<const Vec3f &> onCameraPosition;
Util::Callback<const Vec2i &> onMousePosition;
Util::Callback<float, float> onCameraNearFar;
Util::Callback<bool> onPerspective;
};

} // namespace VTX::Renderer::Proxy
Expand Down
30 changes: 16 additions & 14 deletions lib/renderer/include/renderer/proxy/molecule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ namespace VTX::Renderer::Proxy

const uint idDefaultRepresentation = 0;

Util::Callback<> onTransform; // Move/rotate.
Util::Callback<bool> onVisible; // Show/hide the whole molecule.
Util::Callback<bool> onSelect; // Select/deselect the whole molecule.
Util::Callback<uchar> onRepresentation; // Change the representation of the whole molecule.
Util::Callback<> onRemove; // Remove proxy.
Util::Callback<> onAtomPositions; // Update dynamics.
Util::Callback<std::vector<uchar>> onAtomColors; // Update colors (ATOM/CHAIN/RESIDUE)...
Util::Callback<std::vector<uchar>> onResidueColors; // Update colors (ATOM/CHAIN/RESIDUE)...

Util::Callback<Util::Math::RangeList<uint>, bool> onAtomVisibilities; // Update atom visibility with ranges.
Util::Callback<Util::Math::RangeList<uint>, bool> onAtomSelections; // Update atom selection with ranges.
Util::Callback<Util::Math::RangeList<uint>, uchar>
Util::Callback<> onTransform; // Move/rotate.
Util::Callback<bool> onVisible; // Show/hide the whole molecule.
Util::Callback<bool> onSelect; // Select/deselect the whole molecule.
Util::Callback<uchar> onRepresentation; // Change the representation of the whole molecule.
Util::Callback<> onRemove; // Remove proxy.
Util::Callback<> onAtomPositions; // Update dynamics.
Util::Callback<std::vector<uchar> &> onAtomColors; // Update colors (ATOM/CHAIN/RESIDUE)...
Util::Callback<std::vector<uchar> &> onResidueColors; // Update colors (ATOM/CHAIN/RESIDUE)...

Util::Callback<const Util::Math::RangeList<uint> &, bool>
onAtomVisibilities; // Update atom visibility with ranges.
Util::Callback<const Util::Math::RangeList<uint> &, bool>
onAtomSelections; // Update atom selection with ranges.
Util::Callback<const Util::Math::RangeList<uint> &, uchar>
onAtomRepresentations; // Update atom representations with ranges.
Util::Callback<Util::Math::RangeList<uint>, uchar> onAtomColorsRange;
Util::Callback<Util::Math::RangeList<uint>, uchar> onResidueColorsRange;
Util::Callback<const Util::Math::RangeList<uint> &, uchar> onAtomColorsRange;
Util::Callback<const Util::Math::RangeList<uint> &, uchar> onResidueColorsRange;
};

} // namespace VTX::Renderer::Proxy
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/qt/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def requirements(self):
self.requires("vtx_app/1.0")
self.requires("vtx_renderer/1.0")
self.requires("vtx_core/1.0")
self.requires("qt/6.6.3", transitive_headers=True)
self.requires("qt/6.7.3", transitive_headers=True)

def config_options(self):
if self.settings.os == "Windows":
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/qt/include/ui/qt/dialog/progress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VTX::UI::QT::Dialog
class Progress : public BaseWidget<Progress, QProgressDialog>
{
public:
Progress( const std::string & p_text, std::optional<std::function<void( void )>> p_onCancel = std::nullopt );
Progress( const std::string_view p_text, std::optional<std::function<void( void )>> p_onCancel = std::nullopt );

inline void setValue( const float p_value )
{
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/qt/include/ui/qt/dock_widget/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace VTX::UI::QT::DockWidget
App::SCENE().onSceneItemAdded += [ this ]( const SceneItemComponent & p_item )
{
using namespace App;
assert( MAIN_REGISTRY().hasComponent<Component::Chemistry::Molecule>( p_item ) );

if ( App::MAIN_REGISTRY().hasComponent<App::Component::Chemistry::Molecule>( p_item ) )
{
auto & molecule = App::MAIN_REGISTRY().getComponent<App::Component::Chemistry::Molecule>( p_item );
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/qt/src/ui/qt/dialog/progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace VTX::UI::QT::Dialog
{

Progress::Progress( const std::string & p_text, std::optional<std::function<void( void )>> p_onCancel ) :
Progress::Progress( const std::string_view p_text, std::optional<std::function<void( void )>> p_onCancel ) :
BaseWidget<Progress, QProgressDialog>( APP_QT::getMainWindow() )
{
setWindowModality( Qt::WindowModal );
setWindowFlags( Qt::Window | Qt::FramelessWindowHint );

// Set text.
setLabelText( p_text.c_str() );
setLabelText( p_text.data() );
setFixedSize( 300, 100 );

// Set options.
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/qt/src/ui/qt/widget/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ namespace VTX::UI::QT::Widget
_defaultGeometry = saveGeometry();
_defaultState = saveState();


// Connect progress dialog.
APP::onStartBlockingOperation += [ this ]( const std::string & p_text )
APP::onStartBlockingOperation += [ this ]( const std::string_view p_text )
{
// TODO:: don't delete and recreate.
_progressDialog = new Dialog::Progress( p_text );
Expand Down
4 changes: 2 additions & 2 deletions lib/util/include/util/callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace VTX::Util
class Callback
{
public:
using Func = std::function<void( const Args... )>;
using Func = std::function<void( Args... )>;

Callback() = default;

Expand All @@ -38,7 +38,7 @@ namespace VTX::Util
{
for ( const auto & callback : _callbacks )
{
callback.second( std::forward<Args>( p_args )... );
callback.second( p_args... );
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/util/include/util/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace VTX
// Log info sent by callback
struct LogInfo
{
LOG_LEVEL level;
std::string date;
std::string message;
LOG_LEVEL level;
std::string date;
std::string_view message;
};

class Logger final
Expand All @@ -49,7 +49,7 @@ namespace VTX
static void flush();
static void stop();

inline static Util::Callback<LogInfo> onPrintLog;
inline static Util::Callback<const LogInfo &> onPrintLog;
};

} // namespace Util
Expand Down
5 changes: 3 additions & 2 deletions lib/util/src/util/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ namespace
{
std::string pointTimeToStr( const std::chrono::system_clock::time_point & p_timePoint )
{
const std::string timePointStr = fmt::format( "{:%T}", p_timePoint );
const std::string timePointStr( fmt::format( "{:%T}", p_timePoint ) );
return timePointStr.substr( 0, 8 );
}

VTX::Util::LogInfo spdLogLogMsgToLogInfo( const spdlog::details::log_msg & p_msg )
{
return { VTX::Util::LOG_LEVEL( int( p_msg.level ) ),
pointTimeToStr( p_msg.time ),
std::string( p_msg.payload.begin(), p_msg.payload.end() ) };
std::string_view( p_msg.payload.begin(), p_msg.payload.end() ) };
}
} // namespace

Expand Down

0 comments on commit 63f4403

Please sign in to comment.