Skip to content

Commit

Permalink
Callbacks wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Mar 13, 2024
1 parent e548219 commit e6d7e40
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 66 deletions.
4 changes: 1 addition & 3 deletions lib/app/src/app/component/render/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ namespace VTX::App::Component::Render

_transform = &transformComponent;

_transform->onTransformChanged.addCallback(
this, [ this ]( const Util::Math::Transform & ) { _updateViewMatrix(); }
);
_transform->onTransform += [ this ]( const Util::Math::Transform & ) { _updateViewMatrix(); }

_updateViewMatrix();
_updateProjectionMatrix();
Expand Down
4 changes: 1 addition & 3 deletions lib/app/src/app/component/scene/aabb_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ namespace VTX::App::Component::Scene

_linkedTransform = &transformComponent;

_linkedTransform->onTransformChanged.addCallback(
this, [ this ]( const Util::Math::Transform & ) { _worldAabb.invalidate(); }
);
_linkedTransform->onTransform += [ this ]( const Util::Math::Transform & ) { _worldAabb.invalidate(); }
}
}

Expand Down
28 changes: 14 additions & 14 deletions lib/app/src/app/component/scene/transform_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ namespace VTX::App::Component::Scene
void Transform::setPosition( const Vec3f & p_position )
{
_transformReference->setTranslation( p_position );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::setPosition( const Mat4f & p_positionMat )
{
_transformReference->setTranslation( p_positionMat );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::localMove( const Vec3f & p_translation )
{
Expand All @@ -47,12 +47,12 @@ namespace VTX::App::Component::Scene
localTranslation = Util::Math::castMat3( _rotation ) * localTranslation;

_transformReference->setTranslation( _transformReference->getTranslationVector() + localTranslation );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::globalMove( const Vec3f & p_translation )
{
_transformReference->setTranslation( _transformReference->getTranslationVector() + p_translation );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::moveFront( const float p_distance ) { localMove( Internal::FRONT_AXIS * p_distance ); }
void Transform::moveRight( const float p_distance ) { localMove( Internal::RIGHT_AXIS * p_distance ); }
Expand All @@ -63,21 +63,21 @@ namespace VTX::App::Component::Scene
_transformReference->setRotation( p_euler );
_updateRotation();

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::setRotation( const Quatf & p_quat )
{
_transformReference->setRotation( p_quat );
_updateRotation( p_quat );

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::setRotation( const Mat4f & p_rotationMat )
{
_transformReference->setRotation( p_rotationMat );
_updateRotation();

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}

void Transform::localRotate( const Vec3f & p_euler )
Expand All @@ -90,7 +90,7 @@ namespace VTX::App::Component::Scene
_transformReference->rotate( p_angle, p_axis );
_updateRotation();

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::rotatePitch( const float p_angle ) { localRotate( Internal::RIGHT_AXIS * p_angle ); }
void Transform::rotateYaw( const float p_angle ) { localRotate( Internal::UP_AXIS * p_angle ); }
Expand All @@ -99,17 +99,17 @@ namespace VTX::App::Component::Scene
void Transform::setScale( const float & p_scale )
{
_transformReference->setScale( p_scale );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::setScale( const Vec3f & p_scaleVec )
{
_transformReference->setScale( p_scaleVec );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::setScale( const Mat4f & p_scaleMat )
{
_transformReference->setScale( p_scaleMat );
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}

Vec3f Transform::getPosition() const { return _transformReference->getTranslationVector(); }
Expand All @@ -131,7 +131,7 @@ namespace VTX::App::Component::Scene
_transformReference->setRotation( p_rotation );
_updateRotation( p_rotation );

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}
void Transform::set( const Vec3f & p_position, const Quatf & p_rotation, const Vec3f & p_scale )
{
Expand All @@ -141,7 +141,7 @@ namespace VTX::App::Component::Scene

_updateRotation( p_rotation );

onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}

void Transform::setRotationAround( const Quatf & p_rotation, const Vec3f & p_target, const float p_distance )
Expand Down Expand Up @@ -172,7 +172,7 @@ namespace VTX::App::Component::Scene
void Transform::applyTransform( const Util::Math::Transform & p_transform )
{
*_transformReference = p_transform;
onTransformChanged( *_transformReference );
onTransform( *_transformReference );
}

} // namespace VTX::App::Component::Scene
4 changes: 2 additions & 2 deletions lib/app/src/app/core/worker/base_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace VTX::App::Core::Worker
}
void BaseThread::stop()
{
progressCallback.clear();
onProgress.clear();

if ( _thread.joinable() )
_thread.detach();
Expand All @@ -60,7 +60,7 @@ namespace VTX::App::Core::Worker
if ( _progress != clampedValue )
{
_progress = clampedValue;
progressCallback.call( _progress );
onProgress( _progress );
}
}

Expand Down
51 changes: 27 additions & 24 deletions lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,29 @@ namespace VTX::App
_renderer = std::make_unique<Renderer::Facade>( 1920, 1080, Util::Filesystem::getExecutableDir() / "shaders" );

// Regsiter loop events
_updateCallback.addCallback( this, []( const float p_elapsedTime ) { SCENE().update( p_elapsedTime ); } );
onUpdateCallback += []( const float p_elapsedTime ) { SCENE().update( p_elapsedTime ); }

_postUpdateCallback.addCallback( this, []( const float p_elapsedTime ) { THREADING().lateUpdate(); } );
onPostUpdateCallback
+=
[]( const float p_elapsedTime ) { THREADING().lateUpdate(); }

// Event manager - Useless: nothing is delayed.
//_updateCallback.addCallback(
// this, []( const float p_elapsedTime ) { Event::EventManager::get().update( p_elapsedTime ); }
//);
// Event manager - Useless: nothing is delayed.
//_updateCallback.addCallback(
// this, []( const float p_elapsedTime ) { Event::EventManager::get().update( p_elapsedTime ); }
//);

// Useless while delayed actions are disabled
//_updateCallback.addCallback( this, []( const float p_elapsedTime ) { VTX_ACTION().update( p_elapsedTime ); }
//);
// Useless while delayed actions are disabled
//_updateCallback.addCallback( this, []( const float p_elapsedTime ) { VTX_ACTION().update( p_elapsedTime );
//}
//);

// TODO: use camera callbacks.
//_preRenderCallback.addCallback( this, [ this ]( const float p_elapsedTime ) { _applyCameraUniforms(); } );
//_renderCallback.addCallback(
// this, [ this ]( const float p_elapsedTime ) { _renderer->render( p_elapsedTime ); }
//);
// TODO: use camera callbacks.
//_preRenderCallback.addCallback( this, [ this ]( const float p_elapsedTime ) { _applyCameraUniforms(); } );
//_renderCallback.addCallback(
// this, [ this ]( const float p_elapsedTime ) { _renderer->render( p_elapsedTime ); }
//);

_tickChrono.start();
_tickChrono.start();

_handleArgs( p_args );

Expand Down Expand Up @@ -109,34 +112,34 @@ namespace VTX::App

frameInfo.set(
Internal::Monitoring::PRE_UPDATE_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _preUpdateCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onPreUpdate( p_elapsedTime ); } )
);
frameInfo.set(
Internal::Monitoring::UPDATE_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _updateCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onUpdate( p_elapsedTime ); } )
);
frameInfo.set(
Internal::Monitoring::LATE_UPDATE_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _lateUpdateCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onLateUpdate( p_elapsedTime ); } )
);
frameInfo.set(
Internal::Monitoring::POST_UPDATE_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _postUpdateCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onPostUpdate( p_elapsedTime ); } )
);

// if ( _renderer->getRenderGraph().isBuilt() )
{
frameInfo.set(
Internal::Monitoring::PRE_RENDER_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _preRenderCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onPreRender( p_elapsedTime ); } )
);
frameInfo.set(
Internal::Monitoring::RENDER_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _renderCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onRender p_elapsedTime ); } )
);
frameInfo.set(
Internal::Monitoring::POST_RENDER_DURATION_KEY,
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { _postRenderCallback.call( p_elapsedTime ); } )
Util::CHRONO_CPU( [ this, p_elapsedTime ]() { onPostRender( p_elapsedTime ); } )
);
}

Expand All @@ -145,8 +148,8 @@ namespace VTX::App
Util::CHRONO_CPU(
[ this, p_elapsedTime ]()
{
_endOfFrameOneShotCallback.call();
_endOfFrameOneShotCallback.clear();
onEndOfFrameOneShot();
onEndOfFrameOneShot.clear();
}
)
);
Expand Down
18 changes: 7 additions & 11 deletions lib/app/test/src/entt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ TEST_CASE( "VTX_APP - Full sequence", "[integration]" )
Test::Util::App::initApp();

CallbackTest addSceneItemTest = CallbackTest();
SCENE().onSceneItemAddedCallback().addCallback(
&addSceneItemTest,
[ &addSceneItemTest ]( Component::Scene::SceneItemComponent & p_sceneItem )
{ addSceneItemTest.checked = !p_sceneItem.getName().empty(); }
);
SCENE().onSceneItemAdded += [ &addSceneItemTest ]( Component::Scene::SceneItemComponent & p_sceneItem )
{ addSceneItemTest.checked = !p_sceneItem.getName().empty(); }

// Create MoleculeEntity
const FilePath moleculePath = IO::Internal::Filesystem::getInternalDataDir() / moleculePathname;
Action::Scene::LoadMolecule openAction = Action::Scene::LoadMolecule( moleculePath );
const FilePath moleculePath
= IO::Internal::Filesystem::getInternalDataDir() / moleculePathname;
Action::Scene::LoadMolecule openAction = Action::Scene::LoadMolecule( moleculePath );
openAction.execute();

REQUIRE( addSceneItemTest.checked );
Expand All @@ -89,10 +87,8 @@ TEST_CASE( "VTX_APP - Full sequence", "[integration]" )

CallbackTest renameTest = CallbackTest();

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

REQUIRE( sceneItem.getName() == "Zouzou" );
REQUIRE( renameTest.checked );
Expand Down
17 changes: 8 additions & 9 deletions lib/app/test/src/workers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ TEST_CASE( "VTX_APP - Workers", "[integration]" )

float lastProgress = 0.f;

thread.progressCallback.addCallback(
&thread,
[ lastProgress ]( float p_progress ) mutable
{
CHECK( lastProgress < p_progress );
lastProgress = p_progress;
}
);
thread.onProgress +=
[ lastProgress ]( const float p_progress ) mutable
{
CHECK( lastProgress < p_progress );
lastProgress = p_progress;
}

Core::Worker::BaseThread & threadToWait = THREADING().createThread( asyncOp );
Core::Worker::BaseThread & threadToWait
= THREADING().createThread( asyncOp );
CHECK( !threadToWait.isFinished() );

Util::Chrono chrono = Util::Chrono();
Expand Down

0 comments on commit e6d7e40

Please sign in to comment.