forked from github/server
kill gc_add and gc_done, they were terrible ideas.
This commit is contained in:
parent
4e94a95835
commit
108a909131
|
@ -1647,17 +1647,16 @@ static void expandbuying(region * r, request * buyorders)
|
|||
const luxury_type *type;
|
||||
int number;
|
||||
int multi;
|
||||
} *trades, *trade;
|
||||
} trades[MAXLUXURIES], *trade;
|
||||
static int ntrades = 0;
|
||||
int i, j;
|
||||
const luxury_type *ltype;
|
||||
|
||||
if (ntrades == 0) {
|
||||
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
||||
++ntrades;
|
||||
trades = gc_add(calloc(sizeof(struct trade), ntrades));
|
||||
for (i = 0, ltype = luxurytypes; i != ntrades; ++i, ltype = ltype->next)
|
||||
trades[i].type = ltype;
|
||||
for (ntrades = 0, ltype = luxurytypes; ltype; ltype = ltype->next) {
|
||||
assert(ntrades < MAXLUXURIES);
|
||||
trades[ntrades++].type = ltype;
|
||||
}
|
||||
}
|
||||
for (i = 0; i != ntrades; ++i) {
|
||||
trades[i].number = 0;
|
||||
|
@ -1887,18 +1886,17 @@ static void expandselling(region * r, request * sellorders, int limit)
|
|||
building *b;
|
||||
unit *u;
|
||||
unit *hafenowner;
|
||||
static int *counter;
|
||||
static int counter[MAXLUXURIES];
|
||||
static int ncounter = 0;
|
||||
|
||||
if (ncounter == 0) {
|
||||
const luxury_type *ltype;
|
||||
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
||||
for (ltype = luxurytypes; ltype; ltype = ltype->next) {
|
||||
assert(ncounter < MAXLUXURIES);
|
||||
++ncounter;
|
||||
counter = (int *)gc_add(calloc(sizeof(int), ncounter));
|
||||
}
|
||||
else {
|
||||
memset(counter, 0, sizeof(int) * ncounter);
|
||||
}
|
||||
}
|
||||
memset(counter, 0, sizeof(int) * ncounter);
|
||||
|
||||
if (!sellorders) { /* NEIN, denn Insekten können in || !r->buildings) */
|
||||
return; /* Sümpfen und Wüsten auch so handeln */
|
||||
|
@ -1958,6 +1956,7 @@ static void expandselling(region * r, request * sellorders, int limit)
|
|||
int i;
|
||||
int use = 0;
|
||||
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
|
||||
// TODO: this is slow and lame!
|
||||
++i;
|
||||
}
|
||||
if (counter[i] >= limit)
|
||||
|
|
|
@ -916,36 +916,6 @@ int maxworkingpeasants(const struct region *r)
|
|||
return _max(size-treespace, _min(size / 10 , 200));
|
||||
}
|
||||
|
||||
void **blk_list[1024];
|
||||
int list_index;
|
||||
int blk_index;
|
||||
|
||||
static void gc_done(void)
|
||||
{
|
||||
int i, k;
|
||||
for (i = 0; i != list_index; ++i) {
|
||||
for (k = 0; k != 1024; ++k)
|
||||
free(blk_list[i][k]);
|
||||
free(blk_list[i]);
|
||||
}
|
||||
for (k = 0; k != blk_index; ++k)
|
||||
free(blk_list[list_index][k]);
|
||||
free(blk_list[list_index]);
|
||||
|
||||
}
|
||||
|
||||
void *gc_add(void *p)
|
||||
{
|
||||
if (blk_index == 0) {
|
||||
blk_list[list_index] = (void **)malloc(1024 * sizeof(void *));
|
||||
}
|
||||
blk_list[list_index][blk_index] = p;
|
||||
blk_index = (blk_index + 1) % 1024;
|
||||
if (!blk_index)
|
||||
++list_index;
|
||||
return p;
|
||||
}
|
||||
|
||||
static const char * parameter_key(int i)
|
||||
{
|
||||
assert(i < MAXPARAMS && i >= 0);
|
||||
|
@ -1173,7 +1143,6 @@ void kernel_done(void)
|
|||
* calling it is optional, e.g. a release server will most likely not do it.
|
||||
*/
|
||||
translation_done();
|
||||
gc_done();
|
||||
}
|
||||
|
||||
attrib_type at_germs = {
|
||||
|
@ -1186,9 +1155,6 @@ attrib_type at_germs = {
|
|||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
/*********************/
|
||||
/* at_guard */
|
||||
/*********************/
|
||||
attrib_type at_guard = {
|
||||
"guard",
|
||||
DEFAULT_INIT,
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
#ifndef MAXUNITS
|
||||
# define MAXUNITS 1048573 /* must be prime for hashing. 524287 was >90% full */
|
||||
#endif
|
||||
#define MAXLUXURIES 16 /* there must be no more than MAXLUXURIES kinds of luxury goods in any game */
|
||||
|
||||
#define TREESIZE (8) /* space used by trees (in #peasants) */
|
||||
|
||||
|
@ -183,9 +184,6 @@ extern "C" {
|
|||
bool idle(struct faction *f);
|
||||
bool unit_has_cursed_item(const struct unit *u);
|
||||
|
||||
/* simple garbage collection: */
|
||||
void *gc_add(void *p);
|
||||
|
||||
/* grammatik-flags: */
|
||||
#define GF_NONE 0
|
||||
/* singular, ohne was dran */
|
||||
|
|
1794
src/kernel/region.c
1794
src/kernel/region.c
File diff suppressed because it is too large
Load Diff
|
@ -1030,11 +1030,12 @@ void writeregion(struct gamedata *data, const region * r)
|
|||
WRITE_INT(data->store, rherbs(r));
|
||||
WRITE_INT(data->store, rpeasants(r));
|
||||
WRITE_INT(data->store, rmoney(r));
|
||||
if (r->land)
|
||||
if (r->land) {
|
||||
for (demand = r->land->demands; demand; demand = demand->next) {
|
||||
WRITE_TOK(data->store, resourcename(demand->type->itype->rtype, 0));
|
||||
WRITE_INT(data->store, demand->value);
|
||||
}
|
||||
}
|
||||
WRITE_TOK(data->store, "end");
|
||||
write_items(data->store, r->land->items);
|
||||
WRITE_SECTION(data->store);
|
||||
|
|
|
@ -644,7 +644,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
xmlFree(propValue);
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "value");
|
||||
wtype->damage[pos] = gc_add(_strdup((const char *)propValue));
|
||||
wtype->damage[pos] = _strdup((const char *)propValue); // TODO: this is a memory leak
|
||||
if (k == 0)
|
||||
wtype->damage[1 - pos] = wtype->damage[pos];
|
||||
xmlFree(propValue);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue