aboutsummaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2016-04-28 20:39:37 -0400
committerFranklin Wei <git@fwei.tk>2016-04-28 20:39:37 -0400
commit7f3ba14388a586a946d721a71eb3a9862f7f6c02 (patch)
tree05c96d39815a3719131ad966a73d1ba40fd96d75 /src/world.c
parent0db524c05e0e077c06c7d02eaa2921159df04313 (diff)
downloadnetcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.zip
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.gz
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.bz2
netcosm-7f3ba14388a586a946d721a71eb3a9862f7f6c02.tar.xz
fix build dependency checking, cleanup, simulation callback
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/world.c b/src/world.c
index d7c3590..d0e1711 100644
--- a/src/world.c
+++ b/src/world.c
@@ -35,6 +35,10 @@ size_t netcosm_obj_classes_sz;
const struct roomdata_t *netcosm_world;
size_t netcosm_world_sz;
+/* simulation callback */
+void (*netcosm_world_simulation_cb)(void) = NULL;
+unsigned netcosm_world_simulation_interval = 0;
+
const char *netcosm_world_name;
/* processed world data */
@@ -157,6 +161,16 @@ void world_save(const char *fname)
close(fd);
}
+static ev_timer *sim_timer = NULL;
+
+static void sim_cb(EV_P_ ev_timer *w, int revents)
+{
+ (void) EV_A;
+ (void) w;
+ (void) revents;
+ netcosm_world_simulation_cb();
+}
+
void world_free(void)
{
if(world)
@@ -174,6 +188,20 @@ void world_free(void)
free(world);
world = NULL;
}
+ if(sim_timer)
+ free(sim_timer);
+}
+
+static void start_sim_callback(void)
+{
+ /* start callback */
+ if(netcosm_world_simulation_cb && netcosm_world_simulation_interval)
+ {
+ sim_timer = calloc(1, sizeof(ev_timer));
+ ev_timer_init(sim_timer, sim_cb, netcosm_world_simulation_interval/1000.0,
+ netcosm_world_simulation_interval/1000.0);
+ ev_timer_start(EV_DEFAULT_ sim_timer);
+ }
}
/**
@@ -208,8 +236,8 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz
world_name = read_string(fd);
if(strcmp(name, world_name))
{
- free(world_name);
debugf("Incompatible world state (%s %s).\n", name, world_name);
+ free(world_name);
return false;
}
@@ -277,6 +305,9 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz
}
close(fd);
+
+ start_sim_callback();
+
return true;
}
@@ -385,6 +416,8 @@ void world_init(const struct roomdata_t *data, size_t sz, const char *name)
}
hash_free(dir_map);
+
+ start_sim_callback();
}
static void *verb_map = NULL;