forked from github/server
bt_register is non-standard API, hide it.
factor out st_register for readability.
This commit is contained in:
parent
3eb89e93ae
commit
b74d18b8c9
5 changed files with 18 additions and 18 deletions
|
@ -98,7 +98,7 @@ bool bt_changed(int *cache)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_register(building_type * btype)
|
static void bt_register(building_type * btype)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char data[64];
|
char data[64];
|
||||||
|
|
|
@ -83,7 +83,6 @@ extern "C" {
|
||||||
bool bt_changed(int *cache);
|
bool bt_changed(int *cache);
|
||||||
const building_type *bt_find(const char *name);
|
const building_type *bt_find(const char *name);
|
||||||
void free_buildingtypes(void);
|
void free_buildingtypes(void);
|
||||||
void bt_register(struct building_type *type);
|
|
||||||
int bt_effsize(const struct building_type *btype,
|
int bt_effsize(const struct building_type *btype,
|
||||||
const struct building *b, int bsize);
|
const struct building *b, int bsize);
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,13 @@ static void test_register_building(CuTest * tc)
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
||||||
btype = (building_type *)calloc(sizeof(building_type), 1);
|
|
||||||
btype->_name = strdup("herp");
|
|
||||||
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
||||||
CuAssertIntEquals(tc, false, bt_changed(&cache));
|
CuAssertIntEquals(tc, false, bt_changed(&cache));
|
||||||
bt_register(btype);
|
|
||||||
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
|
||||||
|
|
||||||
CuAssertPtrNotNull(tc, bt_find("herp"));
|
btype = bt_get_or_create("herp");
|
||||||
|
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
||||||
|
CuAssertPtrEquals(tc, btype, (void *)bt_find("herp"));
|
||||||
|
|
||||||
free_buildingtypes();
|
free_buildingtypes();
|
||||||
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
CuAssertIntEquals(tc, true, bt_changed(&cache));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -107,21 +107,25 @@ const ship_type *st_find(const char *name) {
|
||||||
return st_find_i(name);
|
return st_find_i(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void st_register(ship_type *stype) {
|
||||||
|
size_t len;
|
||||||
|
char data[64];
|
||||||
|
|
||||||
|
selist_push(&shiptypes, (void *)stype);
|
||||||
|
|
||||||
|
len = cb_new_kv(stype->_name, strlen(stype->_name), &stype, sizeof(stype), data);
|
||||||
|
assert(len <= sizeof(data));
|
||||||
|
cb_insert(&cb_shiptypes, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
ship_type *st_get_or_create(const char * name) {
|
ship_type *st_get_or_create(const char * name) {
|
||||||
ship_type * st = st_find_i(name);
|
ship_type * st = st_find_i(name);
|
||||||
assert(!snames);
|
assert(!snames);
|
||||||
if (!st) {
|
if (!st) {
|
||||||
size_t len;
|
|
||||||
char data[64];
|
|
||||||
|
|
||||||
st = (ship_type *)calloc(sizeof(ship_type), 1);
|
st = (ship_type *)calloc(sizeof(ship_type), 1);
|
||||||
st->_name = strdup(name);
|
st->_name = strdup(name);
|
||||||
st->storm = 1.0;
|
st->storm = 1.0;
|
||||||
selist_push(&shiptypes, (void *)st);
|
st_register(st);
|
||||||
|
|
||||||
len = cb_new_kv(name, strlen(name), &st, sizeof(st), data);
|
|
||||||
assert(len <= sizeof(data));
|
|
||||||
cb_insert(&cb_shiptypes, data, len);
|
|
||||||
}
|
}
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,7 @@ static void test_market_curse(CuTest * tc)
|
||||||
|
|
||||||
config_set("rules.region_owners", "1");
|
config_set("rules.region_owners", "1");
|
||||||
|
|
||||||
btype = (building_type *)calloc(1, sizeof(building_type));
|
btype = bt_get_or_create("market");
|
||||||
btype->_name = strdup("market");
|
|
||||||
bt_register(btype);
|
|
||||||
|
|
||||||
terrain = get_terrain("plain");
|
terrain = get_terrain("plain");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue