pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
Model::PhysicsWorker Class Reference

Runs the physics simulation in a separate thread to keep the UI responsive. More...

#include <physics_worker.hpp>

Inheritance diagram for Model::PhysicsWorker:
Inheritance graph
Collaboration diagram for Model::PhysicsWorker:
Collaboration graph

Public Slots

void startSimulation ()
 Starts the simulation loop. More...
 
void performSingleStep ()
 Performs a single step of the physics simulation and emits the results. More...
 
void stopSimulation ()
 Stops the simulation loop. This should be called before cleanup to prevent new steps from being scheduled. More...
 

Signals

void updatedBodyData (const Vector3dVec &positions, const QuaterniondVec &quaternions, const Vector3dVec &torques, const Vector3dVec &alphas, std::size_t iteration)
 Emitted after each simulation step with the updated state of all bodies. More...
 
void simulationFinished ()
 Emitted when the simulation has completed all iterations.
 

Public Member Functions

 PhysicsWorker (const Configuration::SimulationConfig &config, QObject *in_parent=nullptr)
 Constructs the physics worker. More...
 
 ~PhysicsWorker () override
 Destructor. More...
 
void cleanup ()
 Triggers cleanup tasks before the worker is destroyed. More...
 
std::vector< ConstBodyProxygetInitialBodies () const
 Provides read-only access to the initial list of body proxies. More...
 

Private Attributes

std::unique_ptr< Spacespace_
 The simulation space containing all bodies and physics logic. More...
 
std::size_t iterationCount_
 The current simulation iteration count. More...
 
std::size_t maxIterations_
 The maximum number of iterations to run. More...
 
bool isRunning_
 A flag to control the execution of the simulation loop. More...
 

Detailed Description

Runs the physics simulation in a separate thread to keep the UI responsive.

This worker object owns the Space instance and communicates with the main (GUI) thread via signals and slots.

Definition at line 34 of file physics_worker.hpp.

Constructor & Destructor Documentation

◆ PhysicsWorker()

Model::PhysicsWorker::PhysicsWorker ( const Configuration::SimulationConfig &  config,
QObject *  in_parent = nullptr 
)
explicit

Constructs the physics worker.

Parameters
configThe simulation configuration.
in_parentThe parent QObject, if any.

Definition at line 21 of file physics_worker.cpp.

◆ ~PhysicsWorker()

Model::PhysicsWorker::~PhysicsWorker ( )
overridedefault

Destructor.

Destructor. The definition must be in the .cpp file where Space is fully defined.

Member Function Documentation

◆ cleanup()

void Model::PhysicsWorker::cleanup ( )

Triggers cleanup tasks before the worker is destroyed.

Instructs the Space object to print its final profiling report.

This is primarily used to instruct the Space object to print its final profiling report.

Definition at line 43 of file physics_worker.cpp.

◆ getInitialBodies()

std::vector< ConstBodyProxy > Model::PhysicsWorker::getInitialBodies ( ) const

Provides read-only access to the initial list of body proxies.

Returns
A vector of const proxies to the initially created bodies.

Definition at line 52 of file physics_worker.cpp.

◆ performSingleStep

void Model::PhysicsWorker::performSingleStep ( )
slot

Performs a single step of the physics simulation and emits the results.

Definition at line 76 of file physics_worker.cpp.

Here is the caller graph for this function:

◆ startSimulation

void Model::PhysicsWorker::startSimulation ( )
slot

Starts the simulation loop.

This slot is connected to the QThread's started signal.

Definition at line 66 of file physics_worker.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopSimulation

void Model::PhysicsWorker::stopSimulation ( )
slot

Stops the simulation loop. This should be called before cleanup to prevent new steps from being scheduled.

Definition at line 99 of file physics_worker.cpp.

◆ updatedBodyData

void Model::PhysicsWorker::updatedBodyData ( const Vector3dVec &  positions,
const QuaterniondVec &  quaternions,
const Vector3dVec &  torques,
const Vector3dVec &  alphas,
std::size_t  iteration 
)
signal

Emitted after each simulation step with the updated state of all bodies.

Parameters
positionsA vector of all body positions.
quaternionsA vector of all body orientations.
torquesA vector of all body torques.
alphasA vector of all body angular accelerations.
iterationThe current simulation iteration number.
Here is the caller graph for this function:

Member Data Documentation

◆ isRunning_

bool Model::PhysicsWorker::isRunning_
private

A flag to control the execution of the simulation loop.

Definition at line 111 of file physics_worker.hpp.

◆ iterationCount_

std::size_t Model::PhysicsWorker::iterationCount_
private

The current simulation iteration count.

Definition at line 107 of file physics_worker.hpp.

◆ maxIterations_

std::size_t Model::PhysicsWorker::maxIterations_
private

The maximum number of iterations to run.

Definition at line 109 of file physics_worker.hpp.

◆ space_

std::unique_ptr<Space> Model::PhysicsWorker::space_
private

The simulation space containing all bodies and physics logic.

Definition at line 105 of file physics_worker.hpp.


The documentation for this class was generated from the following files: