Kiwano Engine v1.3.x
Contact.h
1// Copyright (c) 2018-2019 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano-physics/Global.h>
23
24namespace kiwano
25{
26namespace physics
27{
28
36class KGE_API ContactBeginEvent : public Event
37{
38public:
39 b2Contact* contact;
40
42 : ContactBeginEvent(nullptr)
43 {
44 }
45
46 ContactBeginEvent(b2Contact* contact)
47 : Event(KGE_EVENT(ContactBeginEvent))
48 , contact(contact)
49 {
50 }
51};
52
55class KGE_API ContactEndEvent : public Event
56{
57public:
58 b2Contact* contact;
59
61 : ContactEndEvent(nullptr)
62 {
63 }
64
65 ContactEndEvent(b2Contact* contact)
66 : Event(KGE_EVENT(ContactEndEvent))
67 , contact(contact)
68 {
69 }
70};
71
75{
76 template <typename _Ty>
77 class IteratorImpl
78 {
79 public:
80 using iterator_category = std::forward_iterator_tag;
81 using value_type = _Ty;
82 using pointer = _Ty*;
83 using reference = _Ty&;
84 using difference_type = ptrdiff_t;
85
86 IteratorImpl(const _Ty& elem)
87 : elem_(elem)
88 {
89 }
90
91 inline reference operator*() const
92 {
93 return const_cast<reference>(elem_);
94 }
95
96 inline pointer operator->() const
97 {
98 return std::pointer_traits<pointer>::pointer_to(**this);
99 }
100
101 inline IteratorImpl& operator++()
102 {
103 elem_ = elem_->GetNext();
104 return *this;
105 }
106
107 inline IteratorImpl operator++(int)
108 {
109 IteratorImpl old = *this;
110 operator++();
111 return old;
112 }
113
114 inline bool operator==(const IteratorImpl& rhs) const
115 {
116 return elem_ == rhs.elem_;
117 }
118
119 inline bool operator!=(const IteratorImpl& rhs) const
120 {
121 return !operator==(rhs);
122 }
123
124 private:
125 _Ty elem_;
126 };
127
128public:
129 using value_type = b2Contact*;
130 using iterator = IteratorImpl<value_type>;
131 using const_iterator = IteratorImpl<const value_type>;
132
133 inline ContactList() {}
134
135 inline ContactList(const value_type& first)
136 : first_(first)
137 {
138 }
139
140 inline const value_type& front() const
141 {
142 return first_;
143 }
144
145 inline value_type& front()
146 {
147 return first_;
148 }
149
150 inline iterator begin()
151 {
152 return iterator(first_);
153 }
154
155 inline const_iterator begin() const
156 {
157 return cbegin();
158 }
159
160 inline const_iterator cbegin() const
161 {
162 return const_iterator(first_);
163 }
164
165 inline iterator end()
166 {
167 return iterator(nullptr);
168 }
169
170 inline const_iterator end() const
171 {
172 return cend();
173 }
174
175 inline const_iterator cend() const
176 {
177 return const_iterator(nullptr);
178 }
179
180private:
181 value_type first_ = nullptr;
182};
183
187{
188 template <typename _Ty>
189 class IteratorImpl
190 {
191 public:
192 using iterator_category = std::forward_iterator_tag;
193 using value_type = _Ty;
194 using pointer = _Ty*;
195 using reference = _Ty&;
196 using difference_type = ptrdiff_t;
197
198 inline IteratorImpl(const _Ty& elem)
199 : elem_(elem)
200 {
201 }
202
203 inline reference operator*() const
204 {
205 return const_cast<reference>(elem_);
206 }
207
208 inline pointer operator->() const
209 {
210 return std::pointer_traits<pointer>::pointer_to(**this);
211 }
212
213 inline IteratorImpl& operator++()
214 {
215 elem_ = elem_->next;
216 return *this;
217 }
218
219 inline IteratorImpl operator++(int)
220 {
221 IteratorImpl old = *this;
222 operator++();
223 return old;
224 }
225
226 inline bool operator==(const IteratorImpl& rhs) const
227 {
228 return elem_ == rhs.elem_;
229 }
230
231 inline bool operator!=(const IteratorImpl& rhs) const
232 {
233 return !operator==(rhs);
234 }
235
236 private:
237 _Ty elem_;
238 };
239
240public:
241 using value_type = b2ContactEdge*;
242 using iterator = IteratorImpl<value_type>;
243 using const_iterator = IteratorImpl<const value_type>;
244
245 inline ContactEdgeList() {}
246
247 inline ContactEdgeList(const value_type& first)
248 : first_(first)
249 {
250 }
251
252 inline const value_type& front() const
253 {
254 return first_;
255 }
256
257 inline value_type& front()
258 {
259 return first_;
260 }
261
262 inline iterator begin()
263 {
264 return iterator(first_);
265 }
266
267 inline const_iterator begin() const
268 {
269 return cbegin();
270 }
271
272 inline const_iterator cbegin() const
273 {
274 return const_iterator(first_);
275 }
276
277 inline iterator end()
278 {
279 return iterator(nullptr);
280 }
281
282 inline const_iterator end() const
283 {
284 return cend();
285 }
286
287 inline const_iterator cend() const
288 {
289 return const_iterator(nullptr);
290 }
291
292private:
293 value_type first_;
294};
295
298} // namespace physics
299} // namespace kiwano
事件
Definition: Event.h:43
物理接触开始事件
Definition: Contact.h:37
b2Contact * contact
产生的接触
Definition: Contact.h:39
物理接触边列表
Definition: Contact.h:187
物理接触结束事件
Definition: Contact.h:56
b2Contact * contact
产生的接触
Definition: Contact.h:58
物理接触列表
Definition: Contact.h:75