lastregion und firstregion sind m.M. buggy (Leuchttürme). ich disable die mal, und schaue wieviel sie für die performance überhaupt tun...

This commit is contained in:
Enno Rehling 2005-04-27 13:30:12 +00:00
parent faa6f211f5
commit c97d520bc6
10 changed files with 72 additions and 49 deletions

View File

@ -175,9 +175,9 @@ improve_all(faction * f, skill_t sk, int weeks)
region *r;
unit *u;
int n = 0;
region *last = f->last?f->last:lastregion(f);
region *last = lastregion(f);
for (r = f->first?f->first:firstregion(f); r != last; r = r->next) {
for (r = firstregion(f); r != last; r = r->next) {
for (u = r->units; u; u = u->next) {
if (u->faction == f && has_skill(u, sk)) {
for (n=0;n!=weeks;++n) {

View File

@ -1584,7 +1584,7 @@ order_template(FILE * F, faction * f)
{
region *r;
plane *pl;
region *last = f->last?f->last:lastregion(f);
region *last = lastregion(f);
rps_nowrap(F, "");
rnl(F);
@ -1605,7 +1605,7 @@ order_template(FILE * F, faction * f)
rps_nowrap(F, buf);
rnl(F);
for (r = f->first?f->first:firstregion(f); r != last; r = r->next) {
for (r = firstregion(f); r != last; r = r->next) {
unit *u;
int dh = 0;
@ -1989,7 +1989,7 @@ report(FILE *F, faction * f, const faction_list * addresses,
int dh;
int anyunits;
const struct region *r;
region * last = f->last?f->last:lastregion(f);
region * last = lastregion(f);
building *b;
ship *sh;
unit *u;
@ -2230,7 +2230,7 @@ report(FILE *F, faction * f, const faction_list * addresses,
anyunits = 0;
for (r=f->first?f->first:firstregion(f);r!=last;r=r->next) {
for (r=firstregion(f);r!=last;r=r->next) {
boolean unit_in_region = false;
boolean durchgezogen_in_region = false;
int turm_sieht_region = false;
@ -2598,9 +2598,9 @@ static void
prepare_report(faction * f)
{
region * r;
region * end = f->last?f->last:lastregion(f);
region * end = lastregion(f);
seen_init();
for (r = f->first?f->first:firstregion(f); r != end; r = r->next) {
for (r = firstregion(f); r != end; r = r->next) {
attrib *ru;
unit * u;
plane * p = rplane(r);
@ -2691,35 +2691,16 @@ write_reports(faction * f, time_t ltime)
boolean gotit = false;
faction_list * addresses;
char zTime[64];
static boolean dir_exists = false;
#ifdef HAVE_STAT
stat_type st;
if (!dir_exists && stat(reportpath(), &st)==-1) {
errno = 0;
makedir(reportpath(), 0700);
dir_exists = true;
}
#else
if (!dir_exists) {
if (makedir(reportpath(), 0700)!=0) {
if (errno!=EEXIST) {
perror("could not create reportpath");
return -1;
}
dir_exists = true;
}
#endif
strftime(zTime, sizeof(zTime), "%A, %d. %B %Y, %H:%M", localtime(&ltime));
printf("Reports für %s: \r", factionname(f));
printf("Reports for %s: \r", factionname(f));
fflush(stdout);
prepare_report(f);
addresses = get_addresses(f);
/* NR schreiben: */
if (!nonr && (f->options & REPORT_NR)) {
fprintf(stdout, "Reports für %s: NR\r", factionname(f));
fprintf(stdout, "Reports for %s: NR\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f));
@ -2733,7 +2714,7 @@ write_reports(faction * f, time_t ltime)
}
/* CR schreiben: */
if (!nocr && (f->options & REPORT_CR || f->age<3)) {
fprintf(stdout, "Reports für %s: CR\r", factionname(f));
fprintf(stdout, "Reports for %s: CR\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f));
@ -2747,7 +2728,7 @@ write_reports(faction * f, time_t ltime)
}
/* ZV schreiben: */
if (f->options & REPORT_ZV) {
fprintf(stdout, "Reports für %s: ZV\r", factionname(f));
fprintf(stdout, "Reports for %s: ZV\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.txt", reportpath(), turn, factionid(f));
@ -2758,16 +2739,36 @@ write_reports(faction * f, time_t ltime)
if (status!=0) return status; /* catch errors */
}
}
fprintf(stdout, "Reports for %s: DONE\n", factionname(f));
if (!gotit) {
log_error(("no report for faction %s!\n", factionid(f)));
log_error(("No report for faction %s!\n", factionid(f)));
}
freelist(addresses);
putc('\n', stdout);
return 0;
}
int
init_reports(void)
{
update_intervals();
#ifdef HAVE_STAT
{
stat_type st;
if (stat(reportpath(), &st)==0) return 0;
}
#endif
if (makedir(reportpath(), 0700)!=0) {
if (errno!=EEXIST) {
perror("could not create reportpath");
return -1;
}
}
return 0;
}
int
reports(void)
{
@ -2777,17 +2778,12 @@ reports(void)
const char * str;
int retval = 0;
nmr_warnings();
BAT = openbatch();
printf("\n");
nmr_warnings();
report_donations();
remove_empty_units();
log_printf("Updating region intervals\n");
update_intervals();
for (f = factions; f; f = f->next) {
BAT = openbatch();
for (f = factions; f; f = f->next) {
int error = write_reports(f, ltime);
if (error) retval = error;

View File

@ -572,9 +572,9 @@ count_skill(faction * f, skill_t sk)
int n = 0;
region *r;
unit *u;
region *last = f->last?f->last:lastregion(f);
region *last = lastregion(f);
for (r =f->first?f->first:firstregion(f); r != last; r = r->next) {
for (r =firstregion(f); r != last; r = r->next) {
for (u = r->units; u; u = u->next) {
if (u->faction == f && has_skill(u, sk)) {
if (!is_familiar(u)) n += u->number;
@ -2044,6 +2044,7 @@ check_leuchtturm(region * r, faction * f)
region *
lastregion (faction * f)
{
#ifdef SMART_INTERVALS
region *r = f->last;
if (r==NULL && f->units!=NULL) {
for (r = f->units->region; r; r = r->next) {
@ -2075,13 +2076,16 @@ lastregion (faction * f)
}
}
return f->last;
#else
return NULL;
#endif
}
void
update_intervals(void)
{
#ifdef SMART_INTERVALS
region *r;
for (r = regions; r; r = r->next) {
plane * p = rplane(r);
attrib *ru;
@ -2126,11 +2130,13 @@ update_intervals(void)
}
}
}
#endif
}
region *
firstregion (faction * f)
{
#ifdef SMART_INTERVALS
region *r;
if (f->first || !f->units)
return f->first;
@ -2160,6 +2166,9 @@ firstregion (faction * f)
}
}
return f->first = regions;
#else
return regions;
#endif
}
void ** blk_list[1024];

View File

@ -19,6 +19,8 @@ extern "C" {
struct player;
struct alliance;
#undef SMART_INTERVALS /* define to speed up finding the interval of regions that a faction is in */
#ifdef SHORTPWDS
typedef struct shortpwd {
struct shortpwd * next;
@ -42,8 +44,10 @@ typedef struct faction {
struct faction *nexthash;
struct player *owner;
#ifdef SMART_INTERVALS
struct region *first;
struct region *last;
#endif
int no;
int subscription;
unsigned int flags;

View File

@ -562,7 +562,8 @@ jihad_attacks(void)
ally *sf, **sfp;
for(f=factions; f; f=f->next) if(fspecial(f, FS_JIHAD)) {
for(r=f->first; r != f->last; r = r->next) if(rand()%1000 <= 1) {
region * last = lastregion(f);
for (r=firstregion(f); r != last; r = r->next) if (rand()%1000 <= 1) {
boolean doit = false;
for(u=r->units; u; u=u->next) if(jihad(f, u->race)) {

View File

@ -505,8 +505,10 @@ travelthru(const unit * u, region * r)
/* the first and last region of the faction gets reset, because travelthrough
* could be in regions that are located before the [first, last] interval,
* and recalculation is needed */
#ifdef SMART_INTERVALS
u->faction->first = 0;
u->faction->last = 0;
#endif
}
static void

View File

@ -867,12 +867,12 @@ faction_list *
get_addresses(faction * f)
{
/* "TODO: travelthru" */
region *r, *last = f->last?f->last:lastregion(f);
region *r, *last = lastregion(f);
const faction * lastf = NULL;
faction_list * flist = calloc(1, sizeof(faction_list));
flist->data = f;
for (r=f->first?f->first:firstregion(f);r!=last;r=r->next) {
for (r=firstregion(f);r!=last;r=r->next) {
const unit * u = r->units;
const seen_region * sr = find_seen(r);

View File

@ -48,6 +48,7 @@ extern void spunit(struct strlist ** SP, const struct faction * f, const struct
extern int reports(void);
extern int write_reports(struct faction * f, time_t ltime);
extern int init_reports(void);
extern const struct unit *ucansee(const struct faction *f, const struct unit *u, const struct unit *x);

View File

@ -665,8 +665,10 @@ move_unit(unit * u, region * r, unit ** ulist)
} else
addlist(ulist, u);
#ifdef SMART_INTERVALS
u->faction->first = 0;
u->faction->last = 0;
#endif
u->region = r;
/* keine automatische hp reduzierung bei bewegung */
/* if (maxhp>0) u->hp = u->hp * unit_max_hp(u) / maxhp; */

View File

@ -196,6 +196,13 @@ lua_writereport(faction * f)
return write_reports(f, ltime);
}
int
lua_writereports(void)
{
init_reports();
return reports();
}
void
bind_eressea(lua_State * L)
{
@ -205,7 +212,8 @@ bind_eressea(lua_State * L)
def("read_game", &read_game),
def("write_game", &write_game),
def("write_passwords", &writepasswd),
def("write_reports", &reports),
def("init_reports", &init_reports),
def("write_reports", &lua_writereports),
def("write_report", &lua_writereport),
def("init_summary", &init_summary),
def("write_summary", &write_summary),