aboutsummaryrefslogtreecommitdiff
path: root/src/room.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2016-01-24 19:01:04 -0500
committerFranklin Wei <git@fwei.tk>2016-01-24 19:01:04 -0500
commit6e3d6b3186bc07003d17ad7c54bb013c9b5d6dcf (patch)
treec4edcb9e261dd8f819f52a992406749a7490eb7a /src/room.c
parentb346e948cb167c18efc33f32f0e7cfb21050fc96 (diff)
downloadnetcosm-6e3d6b3186bc07003d17ad7c54bb013c9b5d6dcf.zip
netcosm-6e3d6b3186bc07003d17ad7c54bb013c9b5d6dcf.tar.gz
netcosm-6e3d6b3186bc07003d17ad7c54bb013c9b5d6dcf.tar.bz2
netcosm-6e3d6b3186bc07003d17ad7c54bb013c9b5d6dcf.tar.xz
objects partially work, can't serialize yet
Diffstat (limited to 'src/room.c')
-rw-r--r--src/room.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/room.c b/src/room.c
index eaa8cf1..3e708f6 100644
--- a/src/room.c
+++ b/src/room.c
@@ -145,49 +145,36 @@ void world_free(void)
struct object_t *obj_new(void)
{
- struct object_t *new = calloc(1, sizeof(struct object_t));
+ struct object_t *obj = calloc(1, sizeof(struct object_t));
/* generate a unique 128-bit id for this object */
/* 64 bits are used to store a nanosecond-resolution timestamp */
/* 64 random bits are also used */
uint64_t timestamp;
struct timeval tv;
gettimeofday(&tv, NULL);
- timestamp = (obj_id)tv.tv_sec * (obj_id)1000000 + (obj_id)tv.tv_usec;
+ timestamp = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec;
uint64_t rand_bits;
arc4random_buf(&rand_bits, sizeof(rand_bits));
- new->id = ((obj_id)timestamp << 64) | (obj_id)rand_bits;
+ obj->id.halves[0] = timestamp;
+ obj->id.halves[1] = rand_bits;
- unsigned char bytes[16];
- memcpy(bytes, &new->id, sizeof(bytes));
- debugf("UUID: ");
- for(unsigned i = 0; i < sizeof(bytes); ++i)
- {
- if(i == 4 || i == 6 || i == 8 || i == 10)
- debugf("-");
- debugf("%02x", bytes[15 - i]);
- }
- debugf("\n");
-
- return new;
+ return obj;
}
bool obj_add(room_id room, struct object_t *obj)
{
- return !hash_insert(room_get(room)->objects, &obj->id, obj);
+ return !hash_insert(room_get(room)->objects, obj->name, obj);
}
-static SIMP_HASH(obj_id, obj_hash);
-static SIMP_EQUAL(obj_id, obj_equal);
-
#define OBJMAP_SIZE 8
/* initialize the room's hash tables */
static void room_init_maps(struct room_t *room)
{
room->users = hash_init((userdb_size() / 2) + 1, hash_djb, compare_strings);
- room->objects = hash_init(OBJMAP_SIZE, obj_hash, obj_equal);
+ room->objects = hash_init(OBJMAP_SIZE, hash_djb, compare_strings);
}
/**
@@ -349,3 +336,16 @@ void world_init(const struct roomdata_t *data, size_t sz, const char *name)
hash_free(map);
}
+
+struct object_t *room_obj_iterate(room_id room, void **save)
+{
+ if(room != ROOM_NONE)
+ return hash_iterate(room_get(room)->objects, save, NULL);
+ else
+ return hash_iterate(NULL, save, NULL);
+}
+
+struct object_t *room_obj_get(room_id room, const char *name)
+{
+ return hash_lookup(room_get(room)->objects, name);
+}