Newton Dynamics  4.00
ndBodyListView.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_LIST_VIEW_H__
23 #define __ND_LIST_VIEW_H__
24 
25 #include "ndCollisionStdafx.h"
26 
27 class ndBody;
28 class ndBodyKinematic;
29 
30 template<class T>
31 class ndSpecialList : public ndList<T*, ndContainersFreeListAlloc<T*>>
32 {
33  public:
34  ndSpecialList();
35 };
36 
37 class ndBodyList : public ndList<ndSharedPtr<ndBody>, ndContainersFreeListAlloc<ndSharedPtr<ndBody>*>>
38 {
39  public:
40  ndBodyList()
42  {
43  }
44 };
45 
46 class ndBodyListView: public ndList<ndSharedPtr<ndBody>, ndContainersFreeListAlloc<ndSharedPtr<ndBody>*>>
47 {
48  public:
50  ndBodyListView(const ndBodyListView& src);
51 
52  ndArray<ndBodyKinematic*>& GetView();
53  const ndArray<ndBodyKinematic*>& GetView() const;
54 
55  bool UpdateView();
56  bool IsListDirty() const;
57  void RemoveItem(ndNode* const node);
58  ndNode* AddItem(ndSharedPtr<ndBody> item);
59 
61  ndUnsigned8 m_listIsDirty;
62 };
63 
64 template<class T>
67 {
68 }
69 
70 inline ndBodyListView::ndBodyListView()
72  ,m_view(1024)
73  ,m_listIsDirty(1)
74 {
75 }
76 
77 inline ndArray<ndBodyKinematic*>& ndBodyListView::GetView()
78 {
79  return m_view;
80 }
81 
82 inline const ndArray<ndBodyKinematic*>& ndBodyListView::GetView() const
83 {
84  return m_view;
85 }
86 
87 inline ndBodyListView::ndNode* ndBodyListView::AddItem(ndSharedPtr<ndBody> item)
88 {
89  m_listIsDirty = 1;
90  return Append(item);
91 }
92 
93 inline void ndBodyListView::RemoveItem(ndNode* const node)
94 {
95  m_listIsDirty = 1;
96  Remove(node);
97 }
98 
99 inline bool ndBodyListView::IsListDirty() const
100 {
101  ndAssert(0);
102  return m_listIsDirty ? true : false;
103 }
104 #endif
ndSharedPtr
Definition: ndSharedPtr.h:17
ndArray< ndBodyKinematic * >
ndBody
Definition: ndBody.h:43
ndBodyList
Definition: ndBodyListView.h:38
ndBodyKinematic
Definition: ndBodyKinematic.h:40
ndBodyListView
Definition: ndBodyListView.h:47
ndSpecialList
Definition: ndBodyListView.h:32
ndList
Definition: ndList.h:33
ndContainersFreeListAlloc
Definition: ndContainersAlloc.h:60