18 #ifndef AGX_SIMULATION_CONTROLLER_H 19 #define AGX_SIMULATION_CONTROLLER_H 21 #include <agx/config/AGX_USE_WEBSOCKETS.h> 23 #if AGX_USE_WEBSOCKETS() 73 SimulationController();
95 void clearSimulation();
116 void startRunLoopThread();
123 void play(
bool wasTemporarilyPaused =
false);
130 void pause(
bool isTemporarilyPaused =
false);
137 void singleStep(
bool asynchronous =
true );
142 void setRepeat(
bool repeat );
143 bool getRepeat()
const;
149 void setRealTimeSync(
bool realTime );
150 bool getRealTimeSync()
const;
177 bool openJournal(
const agx::String& journalPath=
"Journal.agxJournal",
const agx::String& sessionName=
"",
bool loadScene=
true,
bool attach=
true );
179 bool sanityCheck()
const;
188 bool truncate(
agx::UInt firstFrameToRemove);
199 void setSaveSceneToDisk(
bool flag );
204 bool getSaveSceneToDisk()
const;
210 void signalSceneChanged();
212 bool checkAndResetPlotSavedState();
218 void setEnableSimulationStatisticsListener(
bool flag );
220 bool getEnableSimulationStatisticsListener( )
const;
234 bool deleteSessionFromDisk(
const agx::String& sessionName );
238 bool stopRecording(
bool resetScene=
true,
bool blocking=
false);
241 bool isTrackRunning()
const;
242 bool isRecording()
const;
243 bool isRunning()
const;
249 bool renameRecording(
const agx::String& sessionName );
268 agx::UInt getAccumulatedNumFrames()
const;
297 agx::Real getFirstFrameTimeStamp()
const;
312 bool endPlayback(
bool resetScene =
true);
314 void registerStartPlaybackSignalCallback(CallbackWrapper_Real* callback);
315 void registerStartRecordingSignalCallback(CallbackWrapper_Real* callback);
316 void registerStopPlaybackSignalCallback(CallbackWrapper_Real* callback);
317 void registerStopRecordingSignalCallback(CallbackWrapper_Real* callback);
319 void registerPreStepSignalCallback( CallbackWrapper_Real* callback );
320 void registerPostStepSignalCallback(CallbackWrapper_Real* callback);
321 void registerPlaySignalCallback( CallbackWrapper* callback );
322 void registerPauseSignalCallback( CallbackWrapper* callback );
323 void registerRealTimeSignalCallback( CallbackWrapper_Bool* callback );
324 void registerJumpSignalCallback( CallbackWrapper_Real* callback );
325 void registerErrorSignalCallback( CallbackWrapper_String* callback );
328 void unregisterPreStepSignalCallback( CallbackWrapper_Real* callback );
329 void unregisterPostStepSignalCallback(CallbackWrapper_Real* callback);
331 void unregisterStartPlaybackSignalCallback(CallbackWrapper_Real* callback);
332 void unregisterStartRecordingSignalCallback(CallbackWrapper_Real* callback);
333 void unregisterStopPlaybackSignalCallback(CallbackWrapper_Real* callback);
334 void unregisterStopRecordingSignalCallback(CallbackWrapper_Real* callback);
355 void requestExclusiveAccess();
356 void relinquishExclusiveAccess();
365 bool getContacts( std::vector<agx::Vec3>& contactPoints, std::vector<agx::Vec3>& normals, std::vector<agx::Real>& depths )
const;
376 size_t calculateDirectSolvedContacts()
const;
379 virtual ~SimulationController();
395 bool httpPlaySimulation(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
396 bool httpPauseSimulation(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
397 bool httpEnableRealTimeSync(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
398 bool httpDisableRealTimeSync(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
401 bool httpEnableRecording(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
402 bool httpDisableRecording(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
403 bool httpListJournals(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
404 bool httpLoadJournal(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
405 bool httpUnloadJournal(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
406 bool httpSetPlaybackPosition(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
409 bool httpAttachRemoteViewer(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
413 bool httpGetControlChannel(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
414 bool httpInitSynchronizationSocket(agxIO::RemoteCommandServer *server, mg_connection *connection,
const agxIO::RemoteCommandServer::QueryArgumentTable& arguments);
416 void signalStartPlayback();
417 void signalStartRecording();
418 void signalStopPlayback();
419 void signalStopRecording();
422 void signalPreStep();
423 void signalPostStep();
426 void signalRealTime();
433 void webSocketClientConnected( agxNet::WebSocket* client );
434 void webSocketClientDisconnected( agxNet::WebSocket* client );
435 void webSocketMessageReceived( agxNet::WebSocket *socket,
agx::UInt8* payload,
size_t size );
436 void sendWebSocketMessage(
const agxJson::Value& eMessage);
479 agxNet::WebSocketRefVector m_webSocketClients;
480 agxNet::WebSocketServerRef m_webSocketServer;
484 agxSDK::RunLoopThread* m_runLoopThread;
527 enum PlaybackMode {FROM_SIMULATION, FROM_JOURNAL} m_playbackMode;
551 agxNet::WebSocket::ControlChannelRef m_controlChannel;
552 void controlChannelSocketConnectedCallback( agxNet::WebSocket::ControlChannel* channel, agxNet::WebSocket* socket );
553 agxNet::WebSocket::ControlChannel::SocketEvent::CallbackType m_controlChannelSocketConnectedCallback;
554 agxNet::WebSocket::ControlChannel::SocketEvent::CallbackType m_controlChannelSocketDisconnectedCallback;
557 agxJson::Value& createArrayElement( agxJson::Value& eParent,
const char* groupName );
558 void signalPlaybackStarting();
559 void signalPlaybackEnding();
561 agx::JournalReaderRef m_journalReader;
563 bool m_simulationStatisticsListenerEnabled;
564 bool m_saveSimulationToDisk;
566 bool m_shouldSignalStartPlayback;
567 bool m_shouldSignalStartRecording;
568 bool m_shouldSignalStopPlayback;
569 bool m_shouldSignalStopRecording;
570 bool m_shouldJumpAfterStop;
572 bool m_isTemporarilyPaused;
583 ScopedStepLock( SimulationController* simulationController );
586 ScopedStepLock(
const ScopedStepLock& ) {};
587 void operator=(
const ScopedStepLock& ) {};
589 SimulationController* m_simulationController;
599 AGX_FORCE_INLINE bool SimulationController::getRealTimeSync()
const {
return m_realTime; }
601 AGX_FORCE_INLINE bool SimulationController::isRecording()
const {
return m_isRecording; }
602 AGX_FORCE_INLINE bool SimulationController::isRunning()
const {
return m_autoStep; }
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::ref_ptr< Track > TrackRef
#define AGXPHYSICS_EXPORT
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
#define AGX_DECLARE_POINTER_TYPES(type)
Representation of a name string.
agx::ref_ptr< Journal > JournalRef
Block synchronization primitive.
Base class providing referencing counted objects.
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
Callback1< const agx::String & > SceneLoaderCallback
A callback that will be called when starting playback from a recording.
Contains classes for low level data storage for AGX.
GLenum GLuint GLenum GLsizei const GLchar * message
std::recursive_mutex ReentrantMutex
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
An event with no arguments.
An event with one argument.