AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
SimulationTrack.FrameWriter.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxData/Frame.h>
20#include <agxData/FrameIO.h>
21#include <memory>
22#include <agx/DynamicBitSet.h>
23#include <agx/Statistics.h>
25#include <agxSDK/Simulation.h>
28
29namespace agxCollide
30{
31 class Geometry;
32}
33
34namespace agxSDK
35{
36 class Assembly;
37
40 {
41 public:
42 SimulationFrameWriter(Simulation *simulation, bool passive = false);
43
44 virtual void writeFrame(const agxData::Frame *frame) override;
45
46 virtual void forceFlush() override;
47
48 agx::Task *getUpdateTask() { return m_updateTask; }
49
50 void setBlocking(bool blocking) { m_blocking = blocking; }
51
52 // Bypass thread synchronization
53 void writeFrameImpl(const agxData::Frame *frame);
54
55
56 protected:
58
59 private:
60 void writeIncrementalArchive(const agxData::Buffer *archiveData, agx::UInt64 skipFrame, agxSDK::Assembly *assembly);
61 void updateCallback();
62 void write(const agx::Component *component, const agxData::Frame *frame);
63 void write(const agxData::Buffer *buffer, const agxData::Frame *frame);
64 void write(const agxData::Frame::PartialBuffer *buffer, const agxData::Frame *frame);
65 void write(const agxData::Frame::EntityStorage *storage, const agxData::Frame *frame);
66 void write(const agxData::Value *value, const agxData::Frame *frame);
67 void evaluateEventsPre(const agxData::Frame *frame);
68 void evaluateEventsPost(const agxData::Frame *frame);
69 void writeConstraintData(const agxData::Frame *frame);
70 bool writeFrameArchive(const agxData::Frame *frame);
71 agx::UInt64 writeKeyFrameArchive(const agxData::Buffer* keyFrameArchive, agxSDK::Assembly* renderAssembly );
72 void updateArrayBuffers();
73
74 void debugPrint(const agxData::Frame *frame);
75 void debugPrint(const agx::Component *component, const agxData::Frame *frame);
76 void debugPrint(const agxData::Frame::PartialBuffer *buffer, const agxData::Frame *frame);
77 void debugPrint(const agxData::Buffer *buffer, const agxData::Frame *frame);
78 void debugPrint(const agxData::EntityStorage *storage, const agxData::Frame *frame);
79 void debugPrint(const agxData::Value *value, const agxData::Frame *frame);
80
81 void setClock();
82
83 void handleGeometryRestore(agxCollide::Geometry* geometry);
84 void storeAndReplaceMaterialPtr(agxCollide::Geometry* geometry);
85 void storeTrimeshShallowCopyRefs(agxCollide::Geometry* geometry);
86
87 template <typename T>
88 T *getTarget(const Object *source);
89
90 template <typename T>
91 T *getTarget(agx::UInt32 id);
92
93 template <typename T>
94 agxData::EntityStorage *getEventStorage(T *event);
95
96 struct ArchiveObjectEntry {
97 agx::UInt32 id;
98 agxStream::Serializable* serializablePtr;
99 };
100
101 class IncrementalArchive : public agx::Observer
102 {
103 public:
104 IncrementalArchive();
105 virtual ~IncrementalArchive();
106
107 agxStream::InputArchive& createArchive(const agxData::Buffer *archiveData, bool binary = true);
108 // void attach(agxStream::OutputArchive *target);
109
110 std::stringstream& getStream();
111 void clear();
112 void detach();
113
114 private:
115 virtual void objectDeleted(void *target);
116 void restoreCallback(agx::UInt32 id, agxStream::Serializable *object, const std::string& className);
117
118 private:
119 std::unique_ptr<std::stringstream> m_stream;
126 };
127
128 agxData::EntityStorage *getStorage(agxData::EntityStorage *encodedPtr);
129 agxData::Buffer *getBuffer(agxData::Buffer *encodedPtr);
130 void rebuildObjectTable(const agx::Object *node);
131
132 private:
134 bool m_blocking;
135
136 agx::UInt m_frameIndex;
137 agx::Real m_timeStamp;
138 agx::Real m_timeStep;
139 bool m_needClockUpdate;
140
141 agx::TaskGroupRef m_updateTask;
142 bool m_forceFlush;
143 agx::Clock::TickEvent::CallbackType m_postTickCallback;
144
146 ObjectIdTable m_objectIdTable;
147 agxData::BufferRefVector m_arrayBuffers;
148 bool m_passive;
149 IncrementalArchive m_incrementalArchive;
150 agx::HashSet<agx::MaterialRef> m_incrementalJournalMaterials;
153 };
154
155}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
Abstract representation of a data buffer.
Definition Buffer.h:56
Data storage for a collection of entity instances of a specified EntityModel.
The FrameWriter writes frames to an external target.
Definition FrameIO.h:169
Abstract representation of a value.
Definition Value.h:49
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition Assembly.h:68
virtual void writeFrame(const agxData::Frame *frame) override
void writeFrameImpl(const agxData::Frame *frame)
SimulationFrameWriter(Simulation *simulation, bool passive=false)
virtual void forceFlush() override
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Class for reading a binary stream of serialized data.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
T CallbackType
Definition Event.h:37
Inheritance with partial specialization due to bug with ref_ptr containers.
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::Object is a refcounted object with a name.
Definition Object.h:59
A representation of a generic task.
Definition Task.h:58
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt64
Definition Integer.h:33
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42