aboutsummaryrefslogtreecommitdiff
path: root/src/obj.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/obj.h')
-rw-r--r--src/obj.h32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/obj.h b/src/obj.h
index ff26399..c591009 100644
--- a/src/obj.h
+++ b/src/obj.h
@@ -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);