forked from github/server
the report's address list is now a quicklist. A bit faster perhaps, and less memory? One less reason to have the faction_list struct, at least.
This commit is contained in:
parent
a538c52bc4
commit
831de3dd55
5 changed files with 40 additions and 22 deletions
|
@ -63,6 +63,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <util/nrmessage.h>
|
#include <util/nrmessage.h>
|
||||||
|
#include <util/quicklist.h>
|
||||||
|
|
||||||
#include <libxml/encoding.h>
|
#include <libxml/encoding.h>
|
||||||
|
|
||||||
|
@ -959,11 +960,12 @@ show_active_spells(const region * r)
|
||||||
|
|
||||||
/* this is a copy of laws.c->find_address output changed. */
|
/* this is a copy of laws.c->find_address output changed. */
|
||||||
static void
|
static void
|
||||||
cr_find_address(FILE * F, const faction * uf, const faction_list * addresses)
|
cr_find_address(FILE * F, const faction * uf, quicklist * addresses)
|
||||||
{
|
{
|
||||||
const faction_list * flist = addresses;
|
int i = 0;
|
||||||
while (flist!=NULL) {
|
quicklist * flist = addresses;
|
||||||
const faction * f = flist->data;
|
while (flist) {
|
||||||
|
const faction * f = (const faction *)ql_get(flist, i);
|
||||||
if (uf!=f) {
|
if (uf!=f) {
|
||||||
fprintf(F, "PARTEI %d\n", f->no);
|
fprintf(F, "PARTEI %d\n", f->no);
|
||||||
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
||||||
|
@ -974,7 +976,7 @@ cr_find_address(FILE * F, const faction * uf, const faction_list * addresses)
|
||||||
fprintf(F, "%d;alliance\n", f->alliance->id);
|
fprintf(F, "%d;alliance\n", f->alliance->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flist = flist->next;
|
ql_advance(&flist, &i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||||
|
|
|
@ -76,6 +76,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <util/nrmessage.h>
|
#include <util/nrmessage.h>
|
||||||
|
#include <util/quicklist.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
|
||||||
#include <libxml/encoding.h>
|
#include <libxml/encoding.h>
|
||||||
|
@ -1700,15 +1701,16 @@ rpline(FILE * F)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
list_address(FILE * F, const faction * uf, const faction_list * seenfactions)
|
list_address(FILE * F, const faction * uf, quicklist * seenfactions)
|
||||||
{
|
{
|
||||||
const faction_list *flist = seenfactions;
|
int qi = 0;
|
||||||
|
quicklist * flist = seenfactions;
|
||||||
|
|
||||||
centre(F, LOC(uf->locale, "nr_addresses"), false);
|
centre(F, LOC(uf->locale, "nr_addresses"), false);
|
||||||
rnl(F);
|
rnl(F);
|
||||||
|
|
||||||
while (flist!=NULL) {
|
while (flist!=NULL) {
|
||||||
const faction * f = flist->data;
|
const faction * f = (const faction *)ql_get(flist, qi);
|
||||||
if (!is_monsters(f)) {
|
if (!is_monsters(f)) {
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
char label = '-';
|
char label = '-';
|
||||||
|
@ -1720,7 +1722,7 @@ list_address(FILE * F, const faction * uf, const faction_list * seenfactions)
|
||||||
rparagraph(F, buf, 4, 0, label);
|
rparagraph(F, buf, 4, 0, label);
|
||||||
|
|
||||||
}
|
}
|
||||||
flist = flist->next;
|
ql_advance(&flist, &qi, 1);
|
||||||
}
|
}
|
||||||
rnl(F);
|
rnl(F);
|
||||||
rpline(F);
|
rpline(F);
|
||||||
|
|
|
@ -672,7 +672,8 @@ xml_region(report_context * ctx, seen_region * sr)
|
||||||
static xmlNodePtr
|
static xmlNodePtr
|
||||||
report_root(report_context * ctx)
|
report_root(report_context * ctx)
|
||||||
{
|
{
|
||||||
const faction_list * address;
|
int qi;
|
||||||
|
quicklist * address;
|
||||||
region * r = ctx->first, * rend = ctx->last;
|
region * r = ctx->first, * rend = ctx->last;
|
||||||
xml_context* xct = (xml_context*)ctx->userdata;
|
xml_context* xct = (xml_context*)ctx->userdata;
|
||||||
xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis");
|
xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis");
|
||||||
|
@ -697,9 +698,9 @@ report_root(report_context * ctx)
|
||||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *)zText);
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *)zText);
|
||||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *)itoab(turn, 10));
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *)itoab(turn, 10));
|
||||||
|
|
||||||
|
for (qi=0,address=ctx->addresses;address;ql_advance(&address, &qi, 1)) {
|
||||||
for (address=ctx->addresses;address;address=address->next) {
|
faction * f = (faction *)ql_get(address, qi);
|
||||||
xmlAddChild(xmlReport, xml_faction(ctx, address->data));
|
xmlAddChild(xmlReport, xml_faction(ctx, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;r!=rend;r=r->next) {
|
for (;r!=rend;r=r->next) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
#include <util/quicklist.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -899,6 +900,15 @@ stealth_modifier(int seen_mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void transfer_seen(quicklist ** dst, faction_list ** src) {
|
||||||
|
while (*src) {
|
||||||
|
faction_list * flist = *src;
|
||||||
|
ql_set_insert(dst, flist->data);
|
||||||
|
free(flist);
|
||||||
|
*src = flist->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_addresses(report_context * ctx)
|
get_addresses(report_context * ctx)
|
||||||
{
|
{
|
||||||
|
@ -906,18 +916,21 @@ get_addresses(report_context * ctx)
|
||||||
seen_region * sr = NULL;
|
seen_region * sr = NULL;
|
||||||
region *r;
|
region *r;
|
||||||
const faction * lastf = NULL;
|
const faction * lastf = NULL;
|
||||||
faction_list * flist = ctx->f->seen_factions;
|
quicklist * flist = 0;
|
||||||
|
|
||||||
|
transfer_seen(&flist, &ctx->f->seen_factions);
|
||||||
|
|
||||||
ctx->f->seen_factions = NULL; /* do not delete it twice */
|
ctx->f->seen_factions = NULL; /* do not delete it twice */
|
||||||
flist_add(&flist, ctx->f);
|
ql_push(&flist, ctx->f);
|
||||||
|
|
||||||
if (f_get_alliance(ctx->f)) {
|
if (f_get_alliance(ctx->f)) {
|
||||||
faction_list * member = ctx->f->alliance->members;
|
faction_list * member = ctx->f->alliance->members;
|
||||||
for (;member;member=member->next) {
|
for (;member;member=member->next) {
|
||||||
flist_add(&flist, member->data);
|
ql_set_insert(&flist, member->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* find the first region that this faction can see */
|
||||||
for (r=ctx->first;sr==NULL && r!=ctx->last;r=r->next) {
|
for (r=ctx->first;sr==NULL && r!=ctx->last;r=r->next) {
|
||||||
sr = find_seen(ctx->seen, r);
|
sr = find_seen(ctx->seen, r);
|
||||||
}
|
}
|
||||||
|
@ -931,7 +944,7 @@ get_addresses(report_context * ctx)
|
||||||
faction * sf = visible_faction(ctx->f, u);
|
faction * sf = visible_faction(ctx->f, u);
|
||||||
if (lastf!=sf) {
|
if (lastf!=sf) {
|
||||||
if (u->building || u->ship || (stealthmod>INT_MIN && cansee(ctx->f, r, u, stealthmod))) {
|
if (u->building || u->ship || (stealthmod>INT_MIN && cansee(ctx->f, r, u, stealthmod))) {
|
||||||
flist_add(&flist, sf);
|
ql_set_insert(&flist, sf);
|
||||||
lastf = sf;
|
lastf = sf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -947,7 +960,7 @@ get_addresses(report_context * ctx)
|
||||||
unit * u2 = (unit*)a->data.v;
|
unit * u2 = (unit*)a->data.v;
|
||||||
if (u2->faction==ctx->f) {
|
if (u2->faction==ctx->f) {
|
||||||
if (cansee_unit(u2, u, stealthmod)) {
|
if (cansee_unit(u2, u, stealthmod)) {
|
||||||
flist_add(&flist, sf);
|
ql_set_insert(&flist, sf);
|
||||||
lastf = sf;
|
lastf = sf;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -965,7 +978,7 @@ get_addresses(report_context * ctx)
|
||||||
boolean ballied = sf && sf!=ctx->f && sf!=lastf
|
boolean ballied = sf && sf!=ctx->f && sf!=lastf
|
||||||
&& !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod);
|
&& !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod);
|
||||||
if (ballied || ALLIED(ctx->f, sf)) {
|
if (ballied || ALLIED(ctx->f, sf)) {
|
||||||
flist_add(&flist, sf);
|
ql_set_insert(&flist, sf);
|
||||||
lastf = sf;
|
lastf = sf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -978,7 +991,7 @@ get_addresses(report_context * ctx)
|
||||||
faction *f2;
|
faction *f2;
|
||||||
for (f2 = factions; f2; f2 = f2->next) {
|
for (f2 = factions; f2; f2 = f2->next) {
|
||||||
if (f2->alliance == ctx->f->alliance) {
|
if (f2->alliance == ctx->f->alliance) {
|
||||||
flist_add(&flist, f2);
|
ql_set_insert(&flist, f2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1406,7 @@ write_reports(faction * f, time_t ltime)
|
||||||
if (!gotit) {
|
if (!gotit) {
|
||||||
log_warning(("No report for faction %s!\n", factionid(f)));
|
log_warning(("No report for faction %s!\n", factionid(f)));
|
||||||
}
|
}
|
||||||
freelist(ctx.addresses);
|
ql_free(ctx.addresses);
|
||||||
seen_done(ctx.seen);
|
seen_done(ctx.seen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ extern const char * visibility[];
|
||||||
|
|
||||||
typedef struct report_context {
|
typedef struct report_context {
|
||||||
struct faction * f;
|
struct faction * f;
|
||||||
struct faction_list * addresses;
|
struct quicklist * addresses;
|
||||||
struct seen_region ** seen;
|
struct seen_region ** seen;
|
||||||
struct region * first, * last;
|
struct region * first, * last;
|
||||||
void * userdata;
|
void * userdata;
|
||||||
|
|
Loading…
Reference in a new issue