diff options
| author | Franklin Wei <git@fwei.tk> | 2016-02-12 21:54:42 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-02-16 20:42:49 -0500 |
| commit | b110e7e0c519cc9575f8d224f0f75aca0d73946f (patch) | |
| tree | c3f33326a5e4822f2251e8d7370294096ab2eba4 /src/obj.h | |
| parent | a006044fbcb3355f0fa063720e7c41f4971894a0 (diff) | |
| download | netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.zip netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.gz netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.bz2 netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.xz | |
support multiple objects sharing the same name
Diffstat (limited to 'src/obj.h')
| -rw-r--r-- | src/obj.h | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -54,18 +54,29 @@ struct obj_class_t { bool (*hook_drop)(struct object_t*, user_t *user); void (*hook_destroy)(struct object_t*); // free resources const char* (*hook_desc)(struct object_t*, user_t*); // get object description + + void *(*hook_dupdata)(struct object_t *obj); // duplicate the userdata pointer }; +typedef uint64_t obj_id; + +/* world modules should not instantiate this directly, use obj_new() instead */ +/* also, members marked with 'protected' should not be modified by the world module */ struct object_t { - char *name; /* no articles: "a", "an", "the", needs to be free()able */ + obj_id id; // protected - struct obj_class_t *class; + /* the object name needs to be freeable with free(), and should + * not be modified by the world module after being added to a + * room */ + char *name; - bool list; + struct obj_class_t *class; - unsigned refcount; + bool list; /* whether to list in room view */ void *userdata; + + unsigned refcount; // private }; /* returns a new object of class 'c' */ @@ -77,12 +88,21 @@ void obj_write(int fd, struct object_t *obj); /* deserialize an object */ struct object_t *obj_read(int fd); -/* this used to actually make a duplicate of an object... - * now it just increments its reference count */ +/* this adds a reference to an object, DOES NOT COPY */ struct object_t *obj_dup(struct object_t *obj); +/* makes a new object with a new ID, but same data fields as the original */ +struct object_t *obj_copy(struct object_t *obj); + /* this only frees the object if its reference count is zero */ void obj_free(void*); /* shut down the obj_* module */ void obj_shutdown(void); + +/* internal use */ +obj_id obj_get_idcounter(void); +void obj_set_idcounter(obj_id); + +/* compare two objects */ +int obj_compare(const void *a, const void *b); |