bt_register is non-standard API, hide it.

factor out st_register for readability.
This commit is contained in:
Enno Rehling 2017-05-06 15:39:09 +02:00
parent 3eb89e93ae
commit b74d18b8c9
5 changed files with 18 additions and 18 deletions

View File

@ -98,7 +98,7 @@ bool bt_changed(int *cache)
return false;
}
void bt_register(building_type * btype)
static void bt_register(building_type * btype)
{
size_t len;
char data[64];

View File

@ -83,7 +83,6 @@ extern "C" {
bool bt_changed(int *cache);
const building_type *bt_find(const char *name);
void free_buildingtypes(void);
void bt_register(struct building_type *type);
int bt_effsize(const struct building_type *btype,
const struct building *b, int bsize);

View File

@ -21,14 +21,13 @@ static void test_register_building(CuTest * tc)
test_cleanup();
btype = (building_type *)calloc(sizeof(building_type), 1);
btype->_name = strdup("herp");
CuAssertIntEquals(tc, true, 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();
CuAssertIntEquals(tc, true, bt_changed(&cache));
test_cleanup();

View File

@ -107,21 +107,25 @@ const ship_type *st_find(const char *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 = st_find_i(name);
assert(!snames);
if (!st) {
size_t len;
char data[64];
st = (ship_type *)calloc(sizeof(ship_type), 1);
st->_name = strdup(name);
st->storm = 1.0;
selist_push(&shiptypes, (void *)st);
len = cb_new_kv(name, strlen(name), &st, sizeof(st), data);
assert(len <= sizeof(data));
cb_insert(&cb_shiptypes, data, len);
st_register(st);
}
return st;
}

View File

@ -43,9 +43,7 @@ static void test_market_curse(CuTest * tc)
config_set("rules.region_owners", "1");
btype = (building_type *)calloc(1, sizeof(building_type));
btype->_name = strdup("market");
bt_register(btype);
btype = bt_get_or_create("market");
terrain = get_terrain("plain");