forked from github/server
Potentielle Beschleunigung der Reporterzeugung, muss noch profiled werden.
This commit is contained in:
parent
7d927094dd
commit
eb5ef3b51b
|
@ -893,7 +893,7 @@ cr_find_address(FILE * F, const faction * uf, const faction_list * addresses)
|
||||||
static void
|
static void
|
||||||
cr_reportspell(FILE * F, spellid_t id, const struct locale * lang)
|
cr_reportspell(FILE * F, spellid_t id, const struct locale * lang)
|
||||||
{
|
{
|
||||||
int k, itemanz, res, costtyp;
|
int k;
|
||||||
spell *sp = find_spellbyid(id);
|
spell *sp = find_spellbyid(id);
|
||||||
const char * name = sp->sname;
|
const char * name = sp->sname;
|
||||||
if (sp->info==NULL) {
|
if (sp->info==NULL) {
|
||||||
|
@ -918,9 +918,9 @@ cr_reportspell(FILE * F, spellid_t id, const struct locale * lang)
|
||||||
fputs("KOMPONENTEN\n", F);
|
fputs("KOMPONENTEN\n", F);
|
||||||
|
|
||||||
for (k = 0; k < MAXINGREDIENT; k++) {
|
for (k = 0; k < MAXINGREDIENT; k++) {
|
||||||
res = sp->komponenten[k][0];
|
resource_t res = sp->komponenten[k][0];
|
||||||
itemanz = sp->komponenten[k][1];
|
int itemanz = sp->komponenten[k][1];
|
||||||
costtyp = sp->komponenten[k][2];
|
int costtyp = sp->komponenten[k][2];
|
||||||
if (itemanz > 0) {
|
if (itemanz > 0) {
|
||||||
const char * name = resname(res, 0);
|
const char * name = resname(res, 0);
|
||||||
fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR,
|
fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR,
|
||||||
|
@ -1006,15 +1006,16 @@ cr_borders(const region * r, const faction * f, int seemode, FILE * F)
|
||||||
|
|
||||||
/* main function of the creport. creates the header and traverses all regions */
|
/* main function of the creport. creates the header and traverses all regions */
|
||||||
void
|
void
|
||||||
report_computer(FILE * F, faction * f, const seen_region * seen,
|
report_computer(FILE * F, faction * f, const faction_list * addresses,
|
||||||
const faction_list * addresses, const time_t report_time)
|
const time_t report_time)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
region * r;
|
||||||
building *b;
|
building *b;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
unit *u;
|
unit *u;
|
||||||
const char * mailto = locale_string(f->locale, "mailto");
|
const char * mailto = locale_string(f->locale, "mailto");
|
||||||
const seen_region * sd = seen;
|
const region * last = lastregion(f);
|
||||||
const attrib * a;
|
const attrib * a;
|
||||||
|
|
||||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||||
|
@ -1131,13 +1132,12 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* traverse all regions */
|
/* traverse all regions */
|
||||||
while (sd!=NULL) {
|
for (r=firstregion(f);r!=last;r=r->next) {
|
||||||
int modifier = 0;
|
int modifier = 0;
|
||||||
const char * tname;
|
const char * tname;
|
||||||
unsigned char seemode = sd->mode;
|
const seen_region * sd = find_seen(r);
|
||||||
const region * r = sd->r;
|
|
||||||
unit * owner = region_owner(r);
|
if (sd==NULL) continue;
|
||||||
sd = sd->next;
|
|
||||||
|
|
||||||
if (!rplane(r)) {
|
if (!rplane(r)) {
|
||||||
if (opt_cr_absolute_coords) {
|
if (opt_cr_absolute_coords) {
|
||||||
|
@ -1162,7 +1162,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname)));
|
fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname)));
|
||||||
switch (seemode) {
|
switch (sd->mode) {
|
||||||
case see_far:
|
case see_far:
|
||||||
fputs("\"neighbourhood\";visibility\n", F);
|
fputs("\"neighbourhood\";visibility\n", F);
|
||||||
break;
|
break;
|
||||||
|
@ -1173,11 +1173,14 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
fputs("\"travel\";visibility\n", F);
|
fputs("\"travel\";visibility\n", F);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
unit * owner = region_owner(r);
|
||||||
if (owner) {
|
if (owner) {
|
||||||
fprintf(F, "%d;owner\n", owner->faction->no);
|
fprintf(F, "%d;owner\n", owner->faction->no);
|
||||||
}
|
}
|
||||||
if (seemode == see_neighbour) {
|
}
|
||||||
cr_borders(r, f, seemode, F);
|
if (sd->mode == see_neighbour) {
|
||||||
|
cr_borders(r, f, sd->mode, F);
|
||||||
} else {
|
} else {
|
||||||
#define RESOURCECOMPAT
|
#define RESOURCECOMPAT
|
||||||
char cbuf[8192], *pos = cbuf;
|
char cbuf[8192], *pos = cbuf;
|
||||||
|
@ -1221,7 +1224,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
}
|
}
|
||||||
fprintf(F, "%d;Pferde\n", rhorses(r));
|
fprintf(F, "%d;Pferde\n", rhorses(r));
|
||||||
|
|
||||||
if (seemode>=see_unit) {
|
if (sd->mode>=see_unit) {
|
||||||
struct demand * dmd = r->land->demands;
|
struct demand * dmd = r->land->demands;
|
||||||
#if NEW_RESOURCEGROWTH
|
#if NEW_RESOURCEGROWTH
|
||||||
struct rawmaterial * res = r->resources;
|
struct rawmaterial * res = r->resources;
|
||||||
|
@ -1306,8 +1309,8 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
}
|
}
|
||||||
if (pos!=cbuf) fputs(cbuf, F);
|
if (pos!=cbuf) fputs(cbuf, F);
|
||||||
}
|
}
|
||||||
cr_borders(r, f, seemode, F);
|
cr_borders(r, f, sd->mode, F);
|
||||||
if (seemode==see_unit && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
|
if (sd->mode==see_unit && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
|
||||||
{
|
{
|
||||||
/* Sonderbehandlung Teleport-Ebene */
|
/* Sonderbehandlung Teleport-Ebene */
|
||||||
regionlist *rl = allinhab_in_range(r_astral_to_standard(r),TP_RADIUS);
|
regionlist *rl = allinhab_in_range(r_astral_to_standard(r),TP_RADIUS);
|
||||||
|
@ -1382,7 +1385,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
/* visible units */
|
/* visible units */
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
boolean visible = true;
|
boolean visible = true;
|
||||||
switch (seemode) {
|
switch (sd->mode) {
|
||||||
case see_unit:
|
case see_unit:
|
||||||
modifier=0;
|
modifier=0;
|
||||||
break;
|
break;
|
||||||
|
@ -1397,7 +1400,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
|
||||||
visible=false;
|
visible=false;
|
||||||
}
|
}
|
||||||
if (u->building || u->ship || (visible && cansee(f, r, u, modifier)))
|
if (u->building || u->ship || (visible && cansee(f, r, u, modifier)))
|
||||||
cr_output_unit(F, r, f, u, seemode);
|
cr_output_unit(F, r, f, u, sd->mode);
|
||||||
}
|
}
|
||||||
} /* region traversal */
|
} /* region traversal */
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,7 @@ struct faction_list;
|
||||||
struct seen_region;
|
struct seen_region;
|
||||||
struct faction;
|
struct faction;
|
||||||
extern void report_computer(FILE * F, struct faction * f,
|
extern void report_computer(FILE * F, struct faction * f,
|
||||||
const struct seen_region * seen,
|
const struct faction_list * addresses, const time_t report_time);
|
||||||
const struct faction_list * addresses,
|
|
||||||
const time_t report_time);
|
|
||||||
extern void creport_cleanup(void);
|
extern void creport_cleanup(void);
|
||||||
extern void creport_init(void);
|
extern void creport_init(void);
|
||||||
|
|
||||||
|
|
|
@ -470,7 +470,8 @@ rparagraph(FILE *F, const char *s, int indent, char mark)
|
||||||
static void
|
static void
|
||||||
report_spell(FILE * F, spellid_t id, const struct locale * lang)
|
report_spell(FILE * F, spellid_t id, const struct locale * lang)
|
||||||
{
|
{
|
||||||
int k, itemanz, res, costtyp;
|
int k, itemanz, costtyp;
|
||||||
|
resource_t res;
|
||||||
int dh = 0;
|
int dh = 0;
|
||||||
spell *sp = find_spellbyid(id);
|
spell *sp = find_spellbyid(id);
|
||||||
|
|
||||||
|
@ -1962,6 +1963,7 @@ report(FILE *F, faction * f, const faction_list * addresses,
|
||||||
int dh;
|
int dh;
|
||||||
int anyunits;
|
int anyunits;
|
||||||
const struct region *r;
|
const struct region *r;
|
||||||
|
region * last = lastregion(f);
|
||||||
building *b;
|
building *b;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
@ -1969,7 +1971,6 @@ report(FILE *F, faction * f, const faction_list * addresses,
|
||||||
message * m;
|
message * m;
|
||||||
int wants_stats;
|
int wants_stats;
|
||||||
int wants_zugvorlage;
|
int wants_zugvorlage;
|
||||||
seen_region * sd;
|
|
||||||
int ix;
|
int ix;
|
||||||
unsigned char op;
|
unsigned char op;
|
||||||
char buf2[80];
|
char buf2[80];
|
||||||
|
@ -2202,10 +2203,12 @@ report(FILE *F, faction * f, const faction_list * addresses,
|
||||||
|
|
||||||
anyunits = 0;
|
anyunits = 0;
|
||||||
|
|
||||||
for (sd = seen; sd!=NULL; sd = sd->next) {
|
for (r=firstregion(f);r!=last;r=r->next) {
|
||||||
boolean unit_in_region = false;
|
boolean unit_in_region = false;
|
||||||
boolean durchgezogen_in_region = false;
|
boolean durchgezogen_in_region = false;
|
||||||
int turm_sieht_region = false;
|
int turm_sieht_region = false;
|
||||||
|
seen_region * sd = find_seen(r);
|
||||||
|
if (sd==NULL) continue;
|
||||||
|
|
||||||
switch (sd->mode) {
|
switch (sd->mode) {
|
||||||
case see_lighthouse:
|
case see_lighthouse:
|
||||||
|
@ -2632,24 +2635,31 @@ merian(FILE * out, faction * f)
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
seen_region * seen;
|
|
||||||
seen_region * reuse;
|
seen_region * reuse;
|
||||||
seen_region * last;
|
|
||||||
|
|
||||||
#define MAXSEEHASH 4095
|
#define MAXSEEHASH 4095
|
||||||
seen_region * seehash[MAXSEEHASH];
|
seen_region * seehash[MAXSEEHASH];
|
||||||
|
|
||||||
|
static void
|
||||||
|
seen_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0;i!=MAXSEEHASH;++i) {
|
||||||
|
seen_region * sd = seehash[i];
|
||||||
|
if (sd==NULL) continue;
|
||||||
|
while (sd->nextHash!=NULL) sd = sd->nextHash;
|
||||||
|
sd->nextHash = reuse;
|
||||||
|
reuse = seehash[i];
|
||||||
|
seehash[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
seen_done(void)
|
seen_done(void)
|
||||||
{
|
{
|
||||||
while (seen) {
|
seen_init();
|
||||||
seen_region * r = seen;
|
|
||||||
seen = seen->next;
|
|
||||||
free(r);
|
|
||||||
}
|
|
||||||
while (reuse) {
|
while (reuse) {
|
||||||
seen_region * r = reuse;
|
seen_region * r = reuse;
|
||||||
reuse = reuse->next;
|
reuse = reuse->nextHash;
|
||||||
free(r);
|
free(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2666,63 +2676,18 @@ find_seen(const region * r)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
seen_region * last;
|
|
||||||
static boolean
|
static boolean
|
||||||
add_seen(const struct region * r, unsigned char mode, boolean dis)
|
add_seen(const struct region * r, unsigned char mode, boolean dis)
|
||||||
{
|
{
|
||||||
seen_region * find = find_seen(r);
|
seen_region * find = find_seen(r);
|
||||||
if (find==NULL) {
|
if (find==NULL) {
|
||||||
seen_region * insert = NULL;
|
|
||||||
int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH;
|
int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH;
|
||||||
if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region));
|
if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region));
|
||||||
find = reuse;
|
find = reuse;
|
||||||
reuse = reuse->next;
|
reuse = reuse->nextHash;
|
||||||
find->nextHash = seehash[index];
|
find->nextHash = seehash[index];
|
||||||
seehash[index] = find;
|
seehash[index] = find;
|
||||||
find->r = r;
|
find->r = r;
|
||||||
|
|
||||||
/* first attempt: try to put it between previous insertion point and
|
|
||||||
* last region known so far. It's quite likely to be here. */
|
|
||||||
if (last) {
|
|
||||||
for (insert=last;insert->next;insert=insert->next) {
|
|
||||||
region * rl;
|
|
||||||
seen_region * inext = insert->next;
|
|
||||||
for (rl=insert->r->next;rl && rl!=inext->r;rl=rl->next) {
|
|
||||||
if (rl==r) break;
|
|
||||||
}
|
|
||||||
if (rl==r) break;
|
|
||||||
}
|
|
||||||
/* if we did not find it, and mode is not see_neighbour, it *still*
|
|
||||||
* belongs at the end. otherwise, search more: */
|
|
||||||
if (insert->next==NULL && mode==see_neighbour) {
|
|
||||||
const region * rl = NULL;
|
|
||||||
seen_region * sprev;
|
|
||||||
for(sprev=seen;sprev!=last;sprev=sprev->next) {
|
|
||||||
seen_region * snext = sprev->next;
|
|
||||||
for (rl=sprev->r->next;rl!=snext->r;rl=rl->next) {
|
|
||||||
if (rl==r) break;
|
|
||||||
}
|
|
||||||
if (rl==r) break;
|
|
||||||
}
|
|
||||||
/* search it after the insertion point, all the way to the end */
|
|
||||||
if (rl==r) insert = sprev;
|
|
||||||
else {
|
|
||||||
for (rl=insert->r->next;rl;rl=rl->next) {
|
|
||||||
if (rl==r) break;
|
|
||||||
}
|
|
||||||
if (rl!=r) insert=NULL; /* in front */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mode!=see_neighbour) last=find;
|
|
||||||
find->prev = insert;
|
|
||||||
if (insert!=0) {
|
|
||||||
find->next = insert->next;
|
|
||||||
insert->next = find;
|
|
||||||
} else {
|
|
||||||
find->next = seen;
|
|
||||||
seen = find;
|
|
||||||
}
|
|
||||||
} else if (find->mode >= mode) {
|
} else if (find->mode >= mode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2833,13 +2798,7 @@ prepare_report(faction * f)
|
||||||
{
|
{
|
||||||
region * r;
|
region * r;
|
||||||
region * end = lastregion(f);
|
region * end = lastregion(f);
|
||||||
seen_region ** append = &reuse;
|
seen_init();
|
||||||
|
|
||||||
while (*append) append = &(*append)->next;
|
|
||||||
*append = seen;
|
|
||||||
memset(seehash, 0, sizeof(seehash));
|
|
||||||
seen = NULL;
|
|
||||||
last = NULL;
|
|
||||||
for (r = firstregion(f); r != end; r = r->next) {
|
for (r = firstregion(f); r != end; r = r->next) {
|
||||||
attrib *ru;
|
attrib *ru;
|
||||||
unit * u;
|
unit * u;
|
||||||
|
@ -2967,7 +2926,7 @@ reports(void)
|
||||||
}
|
}
|
||||||
else printf("%s\n", factionname(f));
|
else printf("%s\n", factionname(f));
|
||||||
prepare_report(f);
|
prepare_report(f);
|
||||||
addresses = get_addresses(f, seen);
|
addresses = get_addresses(f);
|
||||||
if (!nonr && (f->options & wants_report))
|
if (!nonr && (f->options & wants_report))
|
||||||
{
|
{
|
||||||
sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f));
|
sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f));
|
||||||
|
@ -2983,7 +2942,7 @@ reports(void)
|
||||||
sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f));
|
sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f));
|
||||||
F = cfopen(buf, "wt");
|
F = cfopen(buf, "wt");
|
||||||
if (F) {
|
if (F) {
|
||||||
report_computer(F, f, seen, addresses, ltime);
|
report_computer(F, f, addresses, ltime);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
gotit = true;
|
gotit = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -852,7 +852,7 @@ tagbegin(struct xml_stack * stack)
|
||||||
a->flags = xml_ivalue(tag, "flags");
|
a->flags = xml_ivalue(tag, "flags");
|
||||||
} else if (strcmp(tag->name, "precombatspell") == 0) {
|
} else if (strcmp(tag->name, "precombatspell") == 0) {
|
||||||
race * rc = state->race;
|
race * rc = state->race;
|
||||||
rc->precombatspell = xml_ivalue(tag, "spell");
|
rc->precombatspell = (spellid_t)xml_ivalue(tag, "spell");
|
||||||
} else if (strcmp(tag->name, "function")==0) {
|
} else if (strcmp(tag->name, "function")==0) {
|
||||||
race * rc = state->race;
|
race * rc = state->race;
|
||||||
const char * name = xml_value(tag, "name");
|
const char * name = xml_value(tag, "name");
|
||||||
|
|
|
@ -854,16 +854,17 @@ visible_faction(const faction *f, const unit * u)
|
||||||
}
|
}
|
||||||
|
|
||||||
faction_list *
|
faction_list *
|
||||||
get_addresses(const faction * f, const seen_region * seenregions)
|
get_addresses(faction * f)
|
||||||
{
|
{
|
||||||
/* "TODO: travelthru" */
|
/* "TODO: travelthru" */
|
||||||
const seen_region * sr = seenregions;
|
region *r, *last = lastregion(f);
|
||||||
const faction * lastf = NULL;
|
const faction * lastf = NULL;
|
||||||
faction_list * flist = calloc(1, sizeof(faction_list));
|
faction_list * flist = calloc(1, sizeof(faction_list));
|
||||||
flist->data = findfaction(f->no);
|
flist->data = findfaction(f->no);
|
||||||
while (sr!=NULL) {
|
for (r=firstregion(f);r!=last;r=r->next) {
|
||||||
const region * r = sr->r;
|
|
||||||
const unit * u = r->units;
|
const unit * u = r->units;
|
||||||
|
const seen_region * sr = find_seen(r);
|
||||||
|
if (sr==NULL) continue;
|
||||||
while (u!=NULL) {
|
while (u!=NULL) {
|
||||||
faction * sf = visible_faction(f, u);
|
faction * sf = visible_faction(f, u);
|
||||||
boolean ballied = sf && sf!=f && sf!=lastf
|
boolean ballied = sf && sf!=f && sf!=lastf
|
||||||
|
@ -883,7 +884,6 @@ get_addresses(const faction * f, const seen_region * seenregions)
|
||||||
}
|
}
|
||||||
u = u->next;
|
u = u->next;
|
||||||
}
|
}
|
||||||
sr = sr->next;
|
|
||||||
}
|
}
|
||||||
#ifdef ALLIANCES
|
#ifdef ALLIANCES
|
||||||
if(f->alliance != NULL) {
|
if(f->alliance != NULL) {
|
||||||
|
|
|
@ -74,15 +74,12 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct seen_region {
|
typedef struct seen_region {
|
||||||
struct seen_region * next;
|
|
||||||
struct seen_region * prev;
|
|
||||||
struct seen_region * nextHash;
|
struct seen_region * nextHash;
|
||||||
const struct region *r;
|
const struct region *r;
|
||||||
unsigned char mode;
|
unsigned char mode;
|
||||||
boolean disbelieves;
|
boolean disbelieves;
|
||||||
} seen_region;
|
} seen_region;
|
||||||
|
|
||||||
extern struct seen_region * seen;
|
|
||||||
extern struct seen_region * find_seen(const struct region * r);
|
extern struct seen_region * find_seen(const struct region * r);
|
||||||
|
|
||||||
extern const char* resname(resource_t res, int i);
|
extern const char* resname(resource_t res, int i);
|
||||||
|
@ -108,7 +105,7 @@ extern const char *neue_gebiete[];
|
||||||
extern const char *coasts[];
|
extern const char *coasts[];
|
||||||
extern const char * reportpath(void);
|
extern const char * reportpath(void);
|
||||||
extern struct faction * visible_faction(const struct faction *f, const struct unit * u);
|
extern struct faction * visible_faction(const struct faction *f, const struct unit * u);
|
||||||
extern struct faction_list * get_addresses(const struct faction * f, const struct seen_region * seenregions);
|
extern struct faction_list * get_addresses(struct faction * f);
|
||||||
extern const char * trailinto(const struct region * r, const struct locale * lang);
|
extern const char * trailinto(const struct region * r, const struct locale * lang);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue