… | |
… | |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
20 | |
21 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at crossfire.de |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #ifndef OBJECT_H |
24 | #ifndef OBJECT_H |
25 | #define OBJECT_H |
25 | #define OBJECT_H |
26 | |
26 | |
… | |
… | |
59 | }; |
59 | }; |
60 | |
60 | |
61 | struct UUID |
61 | struct UUID |
62 | { |
62 | { |
63 | uint64 seq; |
63 | uint64 seq; |
|
|
64 | |
|
|
65 | UUID () { } |
|
|
66 | UUID (uint64 seq) : seq(seq) { } |
|
|
67 | operator uint64() { return seq; } |
|
|
68 | void operator =(uint64 seq) { this->seq = seq; } |
64 | }; |
69 | }; |
65 | |
70 | |
66 | extern void init_uuid (); |
71 | extern void init_uuid (); |
67 | extern UUID gen_uuid (); |
72 | extern UUID gen_uuid (); |
68 | extern const uint64 UUID_SKIP; |
73 | extern const uint64 UUID_SKIP; |
… | |
… | |
244 | static vector objects; // not used yet, use first->next->... |
249 | static vector objects; // not used yet, use first->next->... |
245 | static object *first; // will be replaced by "objects" |
250 | static object *first; // will be replaced by "objects" |
246 | |
251 | |
247 | static object *create (); |
252 | static object *create (); |
248 | void copy_to (object *dst); |
253 | void copy_to (object *dst); |
|
|
254 | object *clone (); // create + copy_to |
249 | void destroy (bool destroy_inventory = false); |
255 | void destroy (bool destroy_inventory = false); |
250 | void remove (); |
256 | void remove (); |
251 | object *insert (object *item); // insert into inventory |
257 | object *insert (object *item); // insert into inventory |
252 | |
258 | |
253 | static void free_mortals (); |
259 | static void free_mortals (); |
|
|
260 | static bool can_merge_slow (object *op1, object *op2); |
|
|
261 | |
|
|
262 | // this is often used in time-critical code, so optimise |
254 | static bool can_merge (object *op1, object *op2); |
263 | static bool can_merge (object *op1, object *op2) |
|
|
264 | { |
|
|
265 | return op1->value == op2->value |
|
|
266 | && op1->name == op2->name |
|
|
267 | && can_merge_slow (op1, op2); |
|
|
268 | } |
255 | |
269 | |
256 | void clear (); |
270 | void clear (); |
257 | |
271 | |
258 | bool destroyed () { return QUERY_FLAG (this, FLAG_FREED); } |
272 | bool destroyed () { return QUERY_FLAG (this, FLAG_FREED); } |
|
|
273 | |
|
|
274 | void set_owner (object *owner); |
259 | |
275 | |
260 | void instantiate () |
276 | void instantiate () |
261 | { |
277 | { |
262 | if (!uuid.seq) // HACK |
278 | if (!uuid.seq) // HACK |
263 | uuid = gen_uuid (); |
279 | uuid = gen_uuid (); |
264 | |
280 | |
265 | attachable<object>::instantiate (); |
281 | attachable<object>::instantiate (); |
266 | } |
282 | } |
267 | |
|
|
268 | void set_owner (object *owner); |
|
|
269 | |
283 | |
270 | // info must hold 256 * 3 bytes currently |
284 | // info must hold 256 * 3 bytes currently |
271 | const char *debug_desc (char *info) const; |
285 | const char *debug_desc (char *info) const; |
272 | const char *debug_desc () const; |
286 | const char *debug_desc () const; |
273 | |
287 | |
… | |
… | |
313 | void unlink (); |
327 | void unlink (); |
314 | |
328 | |
315 | object (); |
329 | object (); |
316 | ~object (); |
330 | ~object (); |
317 | }; |
331 | }; |
318 | |
|
|
319 | // compatibility functions/macros |
|
|
320 | #define clear_owner(op) (op)->owner = 0 |
|
|
321 | #define copy_owner(op,other) (op)->owner = (other)->owner |
|
|
322 | #define get_owner(op) (op)->owner |
|
|
323 | #define clear_object(op) (op)->clear () |
|
|
324 | |
|
|
325 | static inline void |
|
|
326 | set_owner (object *op, object *owner) |
|
|
327 | { |
|
|
328 | op->set_owner (owner); |
|
|
329 | } |
|
|
330 | |
|
|
331 | #define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2))) |
|
|
332 | |
332 | |
333 | typedef struct oblnk |
333 | typedef struct oblnk |
334 | { /* Used to link together several objects */ |
334 | { /* Used to link together several objects */ |
335 | object_ptr ob; |
335 | object_ptr ob; |
336 | struct oblnk *next; |
336 | struct oblnk *next; |