Newton Dynamics  4.00
ndModel.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_MODEL_H__
23 #define __ND_MODEL_H__
24 
25 #include "ndNewtonStdafx.h"
26 #include "ndModelList.h"
27 
28 class ndMultiBodyVehicle;
30 
31 D_MSV_NEWTON_ALIGN_32
32 class ndModel: public ndContainersFreeListAlloc<ndModel>
33 {
34  public:
35  template<class T>
36  class ndReferencedObjects : public ndList<ndSharedPtr<T>, ndContainersFreeListAlloc<ndSharedPtr<T>*>>
37  {
38  public:
41  {
42  }
43  };
44 
45  D_CLASS_REFLECTION(ndModel);
46 
47  ndModel();
48  D_NEWTON_API ndModel(const ndLoadSaveBase::ndLoadDescriptor& desc);
49  virtual ~ndModel ();
50 
51  virtual ndModel* GetAsModel();
52  virtual ndMultiBodyVehicle* GetAsMultiBodyVehicle();
53  virtual void Debug(ndConstraintDebugCallback& context) const;
54 
55  protected:
56  virtual void AddToWorld(ndWorld* const world);
57  virtual void RemoveFromToWorld();
58  D_NEWTON_API virtual void Save(const ndLoadSaveBase::ndSaveDescriptor& desc) const;
59 
60  virtual void Update(ndWorld* const world, ndFloat32 timestep);
61  virtual void PostUpdate(ndWorld* const world, ndFloat32 timestep);
62  virtual void PostTransformUpdate(ndWorld* const world, ndFloat32 timestep);
63 
64  ndWorld* m_world;
65  private:
66  ndModelList::ndNode* m_node;
67  ndInt8 m_markedForRemoved;
68 
69  friend class ndWorld;
70  friend class ndLoadSave;
71  friend class ndModelList;
72 } D_GCC_NEWTON_ALIGN_32;
73 
74 
75 inline ndModel::ndModel()
77  ,m_world(nullptr)
78  ,m_node(nullptr)
79  ,m_markedForRemoved(0)
80 {
81 }
82 
83 inline ndModel::~ndModel()
84 {
85  ndAssert(!m_node);
86 }
87 
88 inline ndModel* ndModel::GetAsModel()
89 {
90  return this;
91 }
92 
93 inline ndMultiBodyVehicle* ndModel::GetAsMultiBodyVehicle()
94 {
95  return nullptr;
96 }
97 
98 inline void ndModel::Debug(ndConstraintDebugCallback&) const
99 {
100 }
101 
102 inline void ndModel::Update(ndWorld* const, ndFloat32)
103 {
104 }
105 
106 inline void ndModel::PostUpdate(ndWorld* const, ndFloat32)
107 {
108 }
109 
110 inline void ndModel::PostTransformUpdate(ndWorld* const, ndFloat32)
111 {
112 }
113 
114 inline void ndModel::AddToWorld(ndWorld* const world)
115 {
116  m_world = world;
117 }
118 
119 inline void ndModel::RemoveFromToWorld()
120 {
121  m_world = nullptr;
122 }
123 
124 
125 #endif
126 
127 
ndModelList
Definition: ndModelList.h:30
ndMultiBodyVehicle
Definition: ndMultiBodyVehicle.h:41
ndModel
Definition: ndModel.h:33
ndLoadSave
Definition: ndLoadSave.h:56
ndConstraintDebugCallback
Definition: ndConstraint.h:42
ndList
Definition: ndList.h:33
ndModel::ndReferencedObjects
Definition: ndModel.h:37
ndContainersFreeListAlloc
Definition: ndContainersAlloc.h:60
ndLoadSaveBase::ndLoadDescriptor
Definition: ndSaveLoadSytem.h:59
ndLoadSaveBase::ndSaveDescriptor
Definition: ndSaveLoadSytem.h:93
ndWorld
Definition: ndWorld.h:47