… | |
… | |
6 | #else |
6 | #else |
7 | # define is_constant(c) 0 |
7 | # define is_constant(c) 0 |
8 | #endif |
8 | #endif |
9 | |
9 | |
10 | #include <cstddef> |
10 | #include <cstddef> |
|
|
11 | #include <new> |
|
|
12 | #include <vector> |
11 | |
13 | |
12 | #include <glib.h> |
14 | #include <glib.h> |
|
|
15 | |
|
|
16 | #include <shstr.h> |
|
|
17 | #include <traits.h> |
13 | |
18 | |
14 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
19 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
15 | #define AUTODECL(var,expr) typeof(expr) var = (expr) |
20 | #define AUTODECL(var,expr) typeof(expr) var = (expr) |
16 | |
21 | |
17 | // makes dynamically allocated objects zero-initialised |
22 | // makes dynamically allocated objects zero-initialised |
… | |
… | |
120 | { |
125 | { |
121 | p->~Tp (); |
126 | p->~Tp (); |
122 | } |
127 | } |
123 | }; |
128 | }; |
124 | |
129 | |
125 | struct refcounted |
|
|
126 | { |
|
|
127 | refcounted () : refcnt (0) { } |
|
|
128 | // virtual ~refcounted (); |
|
|
129 | void refcnt_inc () { ++refcnt; } |
|
|
130 | void refcnt_dec () { --refcnt; } |
|
|
131 | bool dead () { return refcnt == 0; } |
|
|
132 | mutable int refcnt; |
|
|
133 | #if 0 |
|
|
134 | private: |
|
|
135 | static refcounted *rc_first; |
|
|
136 | refcounted *rc_next; |
|
|
137 | #endif |
|
|
138 | }; |
|
|
139 | |
|
|
140 | template<class T> |
130 | template<class T> |
141 | struct refptr |
131 | struct refptr |
142 | { |
132 | { |
143 | T *p; |
133 | T *p; |
144 | |
134 | |
… | |
… | |
165 | T &operator * () const { return *p; } |
155 | T &operator * () const { return *p; } |
166 | T *operator ->() const { return p; } |
156 | T *operator ->() const { return p; } |
167 | |
157 | |
168 | operator T *() const { return p; } |
158 | operator T *() const { return p; } |
169 | }; |
159 | }; |
|
|
160 | |
|
|
161 | typedef refptr<maptile> maptile_ptr; |
|
|
162 | typedef refptr<object> object_ptr; |
|
|
163 | typedef refptr<archetype> arch_ptr; |
|
|
164 | typedef refptr<client> client_ptr; |
|
|
165 | typedef refptr<player> player_ptr; |
170 | |
166 | |
171 | struct str_hash |
167 | struct str_hash |
172 | { |
168 | { |
173 | std::size_t operator ()(const char *s) const |
169 | std::size_t operator ()(const char *s) const |
174 | { |
170 | { |
… | |
… | |
200 | { |
196 | { |
201 | return !strcmp (a, b); |
197 | return !strcmp (a, b); |
202 | } |
198 | } |
203 | }; |
199 | }; |
204 | |
200 | |
205 | #include <vector> |
|
|
206 | |
|
|
207 | template<class obj> |
201 | template<class obj> |
208 | struct unordered_vector : std::vector<obj, slice_allocator<obj> > |
202 | struct unordered_vector : std::vector<obj, slice_allocator<obj> > |
209 | { |
203 | { |
210 | typedef typename unordered_vector::iterator iterator; |
204 | typedef typename unordered_vector::iterator iterator; |
211 | |
205 | |
… | |
… | |
242 | typedef double tstamp; |
236 | typedef double tstamp; |
243 | |
237 | |
244 | // return current time as timestampe |
238 | // return current time as timestampe |
245 | tstamp now (); |
239 | tstamp now (); |
246 | |
240 | |
|
|
241 | int similar_direction (int a, int b); |
|
|
242 | |
247 | #endif |
243 | #endif |
248 | |
244 | |